2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
12 * Implementation of the xstat_fs callback routines. These are the
13 * server-side functions that the File Server expects to invoke on
14 * the client machine via the afsint interface. In this case, the
15 * client process is acting as a callback listener, so it has to
16 * be prepared to answer these calls.
19 * The afsint server stubs expect the functions defined here to
20 * be provided. There is no .h file for this code, since the
21 * linker really does all the work for us, and these don't really
22 * need to be ``visible'' to anyone else.
23 *------------------------------------------------------------------------*/
25 #include <afsconfig.h>
26 #include <afs/param.h>
31 #include <stdio.h> /*Standard I/O stuff*/
32 #include <afs/afscbint.h> /*Callback interface defs*/
34 int afs_cb_inited = 0;
35 struct interfaceAddr afs_cb_interface;
37 #define XSTAT_FS_CALLBACK_VERBOSE 0
40 * Initialize the callback interface structure
42 static int init_afs_cb() {
45 afs_uuid_create(&afs_cb_interface.uuid);
46 count = rx_getAllAddr(&afs_cb_interface.addr_in, AFS_MAX_INTERFACE_ADDR);
48 afs_cb_interface.numberOfInterfaces = 0;
50 afs_cb_interface.numberOfInterfaces = count;
56 * Routines we need that don't have explicit include file definitions.
58 extern char *hostutil_GetNameByINet(); /*Host parsing utility*/
60 static char mn[] = "xstat_fs_callback"; /*Module name*/
62 /*------------------------------------------------------------------------
66 * Handle a set of callbacks from the File Server.
69 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
70 * AFSCBFids *Fids_Array : Ptr to the set of Fids.
71 * AFSCBs *CallBacks_Array : Ptr to the set of callbacks.
75 * Error value otherwise.
78 * Nothing interesting.
82 *------------------------------------------------------------------------*/
84 afs_int32 SRXAFSCB_CallBack(rxcall, Fids_Array, CallBack_Array)
85 struct rx_call *rxcall;
86 AFSCBFids *Fids_Array;
87 AFSCBs *CallBack_Array;
89 { /*SRXAFSCB_CallBack*/
91 #if XSTAT_FS_CALLBACK_VERBOSE
92 static char rn[] = "SRXAFSCB_CallBack"; /*Routine name*/
93 char hostName[256]; /*Host name buffer*/
94 char *hostNameResult; /*Ptr to static*/
96 fprintf(stderr, "[%s:%s] Called\n",
99 if (rxcall != (struct rx_call *)0) {
101 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
102 strcpy(hostName, hostNameResult);
103 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
104 mn, rn, hostName, rxcall->conn->peer->port);
105 } /*Valid rxcall param*/
106 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
109 * Return successfully.
113 } /*SRXAFSCB_CallBack*/
115 /*------------------------------------------------------------------------
116 * SRXAFSCB_InitCallBackState
119 * Initialize callback state on this ``Cache Manager''.
122 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
126 * Error value otherwise.
129 * This will definitely be called by the File Server (exactly once),
130 * since it will think we are another new ``Cache Manager''.
134 *------------------------------------------------------------------------*/
136 afs_int32 SRXAFSCB_InitCallBackState(rxcall)
137 struct rx_call *rxcall;
139 { /*SRXAFSCB_InitCallBackState*/
141 #if XSTAT_FS_CALLBACK_VERBOSE
142 static char rn[] = "SRXAFSCB_InitCallBackState"; /*Routine name*/
143 char hostName[256]; /*Host name buffer*/
144 char *hostNameResult; /*Ptr to static*/
146 fprintf(stderr, "[%s:%s] Called\n",
149 if (rxcall != (struct rx_call *)0) {
151 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
152 strcpy(hostName, hostNameResult);
153 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
154 mn, rn, hostName, rxcall->conn->peer->port);
155 } /*Valid rxcall param*/
156 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
159 * Return successfully.
163 } /*SRXAFSCB_InitCallBackState*/
165 /*------------------------------------------------------------------------
169 * Respond to a probe from the File Server. If a File Server
170 * doesn't hear from you every so often, it will send you a probe
171 * to make sure you're there, just like any other ``Cache Manager''
172 * it's keeping track of.
175 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
179 * Error value otherwise.
182 * This may be called by the File Server if we don't call it often
187 *------------------------------------------------------------------------*/
189 afs_int32 SRXAFSCB_Probe(rxcall)
190 struct rx_call *rxcall;
194 #if XSTAT_FS_CALLBACK_VERBOSE
195 static char rn[] = "SRXAFSCB_Probe"; /*Routine name*/
196 char hostName[256]; /*Host name buffer*/
197 char *hostNameResult; /*Ptr to static*/
199 fprintf(stderr, "[%s:%s] Called\n",
202 if (rxcall != (struct rx_call *)0) {
204 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
205 strcpy(hostName, hostNameResult);
206 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
207 mn, rn, hostName, rxcall->conn->peer->port);
208 } /*Valid rxcall param*/
209 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
212 * Return successfully.
219 /*------------------------------------------------------------------------
223 * Respond minimally to a request for returning the contents of
224 * a cache entry, since someone out there thinks you're a Cache
228 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
234 * Nothing interesting.
238 *------------------------------------------------------------------------*/
240 afs_int32 SRXAFSCB_GetCE64(rxcall)
241 struct rx_call *rxcall;
243 { /*SRXAFSCB_GetCE64*/
245 #if XSTAT_FS_CALLBACK_VERBOSE
246 static char rn[] = "SRXAFSCB_GetCE64"; /*Routine name*/
247 char hostName[256]; /*Host name buffer*/
248 char *hostNameResult; /*Ptr to static*/
250 if (rxcall != (struct rx_call *)0) {
252 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
253 strcpy(hostName, hostNameResult);
254 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
255 mn, rn, hostName, rxcall->conn->peer->port);
256 } /*Valid rxcall param*/
257 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
261 } /*SRXAFSCB_GetCE64*/
263 afs_int32 SRXAFSCB_GetCE(rxcall)
264 struct rx_call *rxcall;
268 #if XSTAT_FS_CALLBACK_VERBOSE
269 static char rn[] = "SRXAFSCB_GetCE"; /*Routine name*/
270 char hostName[256]; /*Host name buffer*/
271 char *hostNameResult; /*Ptr to static*/
273 if (rxcall != (struct rx_call *)0) {
275 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
276 strcpy(hostName, hostNameResult);
277 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
278 mn, rn, hostName, rxcall->conn->peer->port);
279 } /*Valid rxcall param*/
280 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
287 /*------------------------------------------------------------------------
291 * Respond minimally to a request for returning the contents of
292 * a cache lock, since someone out there thinks you're a Cache
296 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
302 * Nothing interesting.
306 *------------------------------------------------------------------------*/
308 afs_int32 SRXAFSCB_GetLock(rxcall)
309 struct rx_call *rxcall;
311 { /*SRXAFSCB_GetLock*/
313 #if XSTAT_FS_CALLBACK_VERBOSE
314 static char rn[] = "SRXAFSCB_GetLock"; /*Routine name*/
315 char hostName[256]; /*Host name buffer*/
316 char *hostNameResult; /*Ptr to static*/
318 if (rxcall != (struct rx_call *)0) {
320 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
321 strcpy(hostName, hostNameResult);
322 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
323 mn, rn, hostName, rxcall->conn->peer->port);
324 } /*Valid rxcall param*/
325 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
329 } /*SRXAFSCB_GetLock*/
332 /*------------------------------------------------------------------------
333 * SRXAFSCB_XStatsVersion
336 * Respond minimally to a request for fetching the version of
337 * extended Cache Manager statistics offered, since someone out
338 * there thinks you're a Cache Manager.
341 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
347 * Nothing interesting.
351 *------------------------------------------------------------------------*/
353 afs_int32 SRXAFSCB_XStatsVersion(rxcall)
354 struct rx_call *rxcall;
356 { /*SRXAFSCB_XStatsVersion*/
358 #if XSTAT_FS_CALLBACK_VERBOSE
359 static char rn[] = "SRXAFSCB_XStatsVersion"; /*Routine name*/
360 char hostName[256]; /*Host name buffer*/
361 char *hostNameResult; /*Ptr to static*/
363 if (rxcall != (struct rx_call *)0) {
365 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
366 strcpy(hostName, hostNameResult);
367 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
368 mn, rn, hostName, rxcall->conn->peer->port);
369 } /*Valid rxcall param*/
370 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
374 } /*SRXAFSCB_XStatsVersion*/
377 /*------------------------------------------------------------------------
381 * Respond minimally to a request for returning extended
382 * statistics for a Cache Manager, since someone out there thinks
383 * you're a Cache Manager.
386 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
392 * Nothing interesting.
396 *------------------------------------------------------------------------*/
398 afs_int32 SRXAFSCB_GetXStats(rxcall)
399 struct rx_call *rxcall;
401 { /*SRXAFSCB_GetXStats*/
403 #if XSTAT_FS_CALLBACK_VERBOSE
404 static char rn[] = "SRXAFSCB_GetXStats"; /*Routine name*/
405 char hostName[256]; /*Host name buffer*/
406 char *hostNameResult; /*Ptr to static*/
408 if (rxcall != (struct rx_call *)0) {
410 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
411 strcpy(hostName, hostNameResult);
412 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
413 mn, rn, hostName, rxcall->conn->peer->port);
414 } /*Valid rxcall param*/
415 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
419 } /*SRXAFSCB_GetXStats*/
421 /*------------------------------------------------------------------------
422 * EXPORTED SRXAFSCB_InitCallBackState2
425 * This routine was used in the AFS 3.5 beta release, but not anymore.
426 * It has since been replaced by SRXAFSCB_InitCallBackState3.
429 * rxcall : Ptr to Rx call on which this request came in.
432 * RXGEN_OPCODE (always).
435 * Nothing interesting.
439 *------------------------------------------------------------------------*/
441 int SRXAFSCB_InitCallBackState2(rxcall, addr)
442 struct rx_call *rxcall;
443 struct interfaceAddr * addr;
446 #if XSTAT_FS_CALLBACK_VERBOSE
447 static char rn[] = "SRXAFSCB_InitCallBackState2"; /*Routine name*/
448 char hostName[256]; /*Host name buffer*/
449 char *hostNameResult; /*Ptr to static*/
451 if (rxcall != (struct rx_call *)0) {
453 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
454 strcpy(hostName, hostNameResult);
455 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
456 mn, rn, hostName, rxcall->conn->peer->port);
457 } /*Valid rxcall param*/
458 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
462 /*------------------------------------------------------------------------
463 * EXPORTED SRXAFSCB_WhoAreYou
466 * Routine called by the server-side callback RPC interface to
467 * obtain a unique identifier for the client. The server uses
468 * this identifier to figure out whether or not two RX connections
469 * are from the same client, and to find out which addresses go
470 * with which clients.
473 * rxcall : Ptr to Rx call on which this request came in.
474 * addr: Ptr to return the list of interfaces for this client.
480 * Nothing interesting.
484 *------------------------------------------------------------------------*/
486 int SRXAFSCB_WhoAreYou(rxcall, addr)
487 struct rx_call *rxcall;
488 struct interfaceAddr *addr;
494 #if XSTAT_FS_CALLBACK_VERBOSE
495 static char rn[] = "SRXAFSCB_WhoAreYou"; /*Routine name*/
496 char hostName[256]; /*Host name buffer*/
497 char *hostNameResult; /*Ptr to static*/
499 if (rxcall != (struct rx_call *)0) {
501 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
502 strcpy(hostName, hostNameResult);
503 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
504 mn, rn, hostName, rxcall->conn->peer->port);
505 } /*Valid rxcall param*/
506 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
508 if ( rxcall && addr )
510 if (!afs_cb_inited) init_afs_cb();
511 *addr = afs_cb_interface;
515 * Return successfully.
521 /*------------------------------------------------------------------------
522 * EXPORTED SRXAFSCB_InitCallBackState3
525 * Routine called by the server-side callback RPC interface to
526 * implement clearing all callbacks from this host.
529 * rxcall : Ptr to Rx call on which this request came in.
535 * Nothing interesting.
539 *------------------------------------------------------------------------*/
541 int SRXAFSCB_InitCallBackState3(rxcall, uuidp)
542 struct rx_call *rxcall;
545 #if XSTAT_FS_CALLBACK_VERBOSE
546 static char rn[] = "SRXAFSCB_InitCallBackState3"; /*Routine name*/
547 char hostName[256]; /*Host name buffer*/
548 char *hostNameResult; /*Ptr to static*/
550 if (rxcall != (struct rx_call *)0) {
552 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
553 strcpy(hostName, hostNameResult);
554 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
555 mn, rn, hostName, rxcall->conn->peer->port);
556 } /*Valid rxcall param*/
557 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
560 * Return successfully.
566 /*------------------------------------------------------------------------
567 * EXPORTED SRXAFSCB_ProbeUuid
570 * Routine called by the server-side callback RPC interface to
571 * implement ``probing'' the Cache Manager, just making sure it's
572 * still there is still the same client it used to be.
575 * rxcall : Ptr to Rx call on which this request came in.
576 * uuidp : Ptr to UUID that must match the client's UUID.
579 * 0 if uuidp matches the UUID for this client
583 * Nothing interesting.
587 *------------------------------------------------------------------------*/
589 int SRXAFSCB_ProbeUuid(rxcall, uuidp)
590 struct rx_call *rxcall;
595 #if XSTAT_FS_CALLBACK_VERBOSE
596 static char rn[] = "SRXAFSCB_ProbeUuid"; /*Routine name*/
597 char hostName[256]; /*Host name buffer*/
598 char *hostNameResult; /*Ptr to static*/
600 if (rxcall != (struct rx_call *)0) {
602 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
603 strcpy(hostName, hostNameResult);
604 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
605 mn, rn, hostName, rxcall->conn->peer->port);
606 } /*Valid rxcall param*/
607 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
609 if (!afs_cb_inited) init_afs_cb();
610 if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
611 code = 1; /* failure */
615 /*------------------------------------------------------------------------
616 * EXPORTED SRXAFSCB_GetServerPrefs
619 * Routine to list server preferences used by this client.
622 * a_call : Ptr to Rx call on which this request came in.
623 * a_index : Input server index
624 * a_srvr_addr : Output server address (0xffffffff on last server)
625 * a_srvr_rank : Output server rank
628 * RXGEN_OPCODE (always)
631 * Nothing interesting.
635 *------------------------------------------------------------------------*/
637 int SRXAFSCB_GetServerPrefs(
638 struct rx_call *a_call,
640 afs_int32 *a_srvr_addr,
641 afs_int32 *a_srvr_rank)
646 /*------------------------------------------------------------------------
647 * EXPORTED SRXAFSCB_GetCellServDB
650 * Routine to list cells configured for this client
653 * a_call : Ptr to Rx call on which this request came in.
654 * a_index : Input cell index
655 * a_name : Output cell name ("" on last cell)
656 * a_hosts : Output cell database servers
662 * Nothing interesting.
666 *------------------------------------------------------------------------*/
668 int SRXAFSCB_GetCellServDB(
669 struct rx_call *a_call,
678 /*------------------------------------------------------------------------
679 * EXPORTED SRXAFSCB_GetLocalCell
682 * Routine to return name of client's local cell
685 * a_call : Ptr to Rx call on which this request came in.
686 * a_name : Output cell name
689 * RXGEN_OPCODE (always)
692 * Nothing interesting.
696 *------------------------------------------------------------------------*/
698 int SRXAFSCB_GetLocalCell(
699 struct rx_call *a_call,
704 t_name = (char *)malloc(AFSNAMEMAX);
707 strcpy(t_name, "This is xstat_fs");
713 /*------------------------------------------------------------------------
714 * EXPORTED SRXAFSCB_GetCacheConfig
717 * Routine to return parameters used to initialize client cache.
718 * Client may request any format version. Server may not return
719 * format version greater than version requested by client.
722 * a_call: Ptr to Rx call on which this request came in.
723 * callerVersion: Data format version desired by the client.
724 * serverVersion: Data format version of output data.
725 * configCount: Number bytes allocated for output data.
726 * config: Client cache configuration.
729 * RXGEN_OPCODE (always)
732 * Nothing interesting.
736 *------------------------------------------------------------------------*/
738 int SRXAFSCB_GetCacheConfig(
739 struct rx_call *a_call,
740 afs_uint32 callerVersion,
741 afs_uint32 *serverVersion,
742 afs_uint32 *configCount,