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*/
41 #include <afs/afscbint.h> /*Callback interface defs*/
43 int afs_cb_inited = 0;
44 struct interfaceAddr afs_cb_interface;
46 #define XSTAT_FS_CALLBACK_VERBOSE 0
49 * Initialize the callback interface structure
51 static int init_afs_cb() {
54 afs_uuid_create(&afs_cb_interface.uuid);
55 count = rx_getAllAddr(&afs_cb_interface.addr_in, AFS_MAX_INTERFACE_ADDR);
57 afs_cb_interface.numberOfInterfaces = 0;
59 afs_cb_interface.numberOfInterfaces = count;
65 * Routines we need that don't have explicit include file definitions.
67 extern char *hostutil_GetNameByINet(); /*Host parsing utility*/
69 static char mn[] = "xstat_fs_callback"; /*Module name*/
71 /*------------------------------------------------------------------------
75 * Handle a set of callbacks from the File Server.
78 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
79 * AFSCBFids *Fids_Array : Ptr to the set of Fids.
80 * AFSCBs *CallBacks_Array : Ptr to the set of callbacks.
84 * Error value otherwise.
87 * Nothing interesting.
91 *------------------------------------------------------------------------*/
93 afs_int32 SRXAFSCB_CallBack(rxcall, Fids_Array, CallBack_Array)
94 struct rx_call *rxcall;
95 AFSCBFids *Fids_Array;
96 AFSCBs *CallBack_Array;
98 { /*SRXAFSCB_CallBack*/
100 #if XSTAT_FS_CALLBACK_VERBOSE
101 static char rn[] = "SRXAFSCB_CallBack"; /*Routine name*/
102 char hostName[256]; /*Host name buffer*/
103 char *hostNameResult; /*Ptr to static*/
105 fprintf(stderr, "[%s:%s] Called\n",
108 if (rxcall != (struct rx_call *)0) {
110 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
111 strcpy(hostName, hostNameResult);
112 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
113 mn, rn, hostName, rxcall->conn->peer->port);
114 } /*Valid rxcall param*/
115 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
118 * Return successfully.
122 } /*SRXAFSCB_CallBack*/
124 /*------------------------------------------------------------------------
125 * SRXAFSCB_InitCallBackState
128 * Initialize callback state on this ``Cache Manager''.
131 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
135 * Error value otherwise.
138 * This will definitely be called by the File Server (exactly once),
139 * since it will think we are another new ``Cache Manager''.
143 *------------------------------------------------------------------------*/
145 afs_int32 SRXAFSCB_InitCallBackState(rxcall)
146 struct rx_call *rxcall;
148 { /*SRXAFSCB_InitCallBackState*/
150 #if XSTAT_FS_CALLBACK_VERBOSE
151 static char rn[] = "SRXAFSCB_InitCallBackState"; /*Routine name*/
152 char hostName[256]; /*Host name buffer*/
153 char *hostNameResult; /*Ptr to static*/
155 fprintf(stderr, "[%s:%s] Called\n",
158 if (rxcall != (struct rx_call *)0) {
160 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
161 strcpy(hostName, hostNameResult);
162 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
163 mn, rn, hostName, rxcall->conn->peer->port);
164 } /*Valid rxcall param*/
165 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
168 * Return successfully.
172 } /*SRXAFSCB_InitCallBackState*/
174 /*------------------------------------------------------------------------
178 * Respond to a probe from the File Server. If a File Server
179 * doesn't hear from you every so often, it will send you a probe
180 * to make sure you're there, just like any other ``Cache Manager''
181 * it's keeping track of.
184 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
188 * Error value otherwise.
191 * This may be called by the File Server if we don't call it often
196 *------------------------------------------------------------------------*/
198 afs_int32 SRXAFSCB_Probe(rxcall)
199 struct rx_call *rxcall;
203 #if XSTAT_FS_CALLBACK_VERBOSE
204 static char rn[] = "SRXAFSCB_Probe"; /*Routine name*/
205 char hostName[256]; /*Host name buffer*/
206 char *hostNameResult; /*Ptr to static*/
208 fprintf(stderr, "[%s:%s] Called\n",
211 if (rxcall != (struct rx_call *)0) {
213 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
214 strcpy(hostName, hostNameResult);
215 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
216 mn, rn, hostName, rxcall->conn->peer->port);
217 } /*Valid rxcall param*/
218 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
221 * Return successfully.
228 /*------------------------------------------------------------------------
232 * Respond minimally to a request for returning the contents of
233 * a cache entry, since someone out there thinks you're a Cache
237 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
243 * Nothing interesting.
247 *------------------------------------------------------------------------*/
249 afs_int32 SRXAFSCB_GetCE64(rxcall, index, ce)
250 struct rx_call *rxcall;
252 AFSDBCacheEntry64 *ce;
254 { /*SRXAFSCB_GetCE64*/
256 #if XSTAT_FS_CALLBACK_VERBOSE
257 static char rn[] = "SRXAFSCB_GetCE64"; /*Routine name*/
258 char hostName[256]; /*Host name buffer*/
259 char *hostNameResult; /*Ptr to static*/
261 if (rxcall != (struct rx_call *)0) {
263 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
264 strcpy(hostName, hostNameResult);
265 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
266 mn, rn, hostName, rxcall->conn->peer->port);
267 } /*Valid rxcall param*/
268 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
272 } /*SRXAFSCB_GetCE64*/
274 afs_int32 SRXAFSCB_GetCE(rxcall, index, ce)
275 struct rx_call *rxcall;
281 #if XSTAT_FS_CALLBACK_VERBOSE
282 static char rn[] = "SRXAFSCB_GetCE"; /*Routine name*/
283 char hostName[256]; /*Host name buffer*/
284 char *hostNameResult; /*Ptr to static*/
286 if (rxcall != (struct rx_call *)0) {
288 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
289 strcpy(hostName, hostNameResult);
290 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
291 mn, rn, hostName, rxcall->conn->peer->port);
292 } /*Valid rxcall param*/
293 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
300 /*------------------------------------------------------------------------
304 * Respond minimally to a request for returning the contents of
305 * a cache lock, since someone out there thinks you're a Cache
309 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
315 * Nothing interesting.
319 *------------------------------------------------------------------------*/
321 afs_int32 SRXAFSCB_GetLock(rxcall, index, lock)
322 struct rx_call *rxcall;
326 { /*SRXAFSCB_GetLock*/
328 #if XSTAT_FS_CALLBACK_VERBOSE
329 static char rn[] = "SRXAFSCB_GetLock"; /*Routine name*/
330 char hostName[256]; /*Host name buffer*/
331 char *hostNameResult; /*Ptr to static*/
333 if (rxcall != (struct rx_call *)0) {
335 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
336 strcpy(hostName, hostNameResult);
337 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
338 mn, rn, hostName, rxcall->conn->peer->port);
339 } /*Valid rxcall param*/
340 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
344 } /*SRXAFSCB_GetLock*/
347 /*------------------------------------------------------------------------
348 * SRXAFSCB_XStatsVersion
351 * Respond minimally to a request for fetching the version of
352 * extended Cache Manager statistics offered, since someone out
353 * there thinks you're a Cache Manager.
356 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
362 * Nothing interesting.
366 *------------------------------------------------------------------------*/
368 afs_int32 SRXAFSCB_XStatsVersion(rxcall, versionNumberP)
369 struct rx_call *rxcall;
370 afs_int32 *versionNumberP;
372 { /*SRXAFSCB_XStatsVersion*/
374 #if XSTAT_FS_CALLBACK_VERBOSE
375 static char rn[] = "SRXAFSCB_XStatsVersion"; /*Routine name*/
376 char hostName[256]; /*Host name buffer*/
377 char *hostNameResult; /*Ptr to static*/
379 if (rxcall != (struct rx_call *)0) {
381 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
382 strcpy(hostName, hostNameResult);
383 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
384 mn, rn, hostName, rxcall->conn->peer->port);
385 } /*Valid rxcall param*/
386 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
390 } /*SRXAFSCB_XStatsVersion*/
393 /*------------------------------------------------------------------------
397 * Respond minimally to a request for returning extended
398 * statistics for a Cache Manager, since someone out there thinks
399 * you're a Cache Manager.
402 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
408 * Nothing interesting.
412 *------------------------------------------------------------------------*/
414 afs_int32 SRXAFSCB_GetXStats(rxcall, clientVersionNumber, collectionNumber,
415 srvVersionNumberP, timeP, dataP)
416 struct rx_call *rxcall;
417 afs_int32 clientVersionNumber;
418 afs_int32 collectionNumber;
419 afs_int32 *srvVersionNumberP;
421 AFSCB_CollData *dataP;
423 { /*SRXAFSCB_GetXStats*/
425 #if XSTAT_FS_CALLBACK_VERBOSE
426 static char rn[] = "SRXAFSCB_GetXStats"; /*Routine name*/
427 char hostName[256]; /*Host name buffer*/
428 char *hostNameResult; /*Ptr to static*/
430 if (rxcall != (struct rx_call *)0) {
432 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
433 strcpy(hostName, hostNameResult);
434 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
435 mn, rn, hostName, rxcall->conn->peer->port);
436 } /*Valid rxcall param*/
437 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
441 } /*SRXAFSCB_GetXStats*/
443 /*------------------------------------------------------------------------
444 * EXPORTED SRXAFSCB_InitCallBackState2
447 * This routine was used in the AFS 3.5 beta release, but not anymore.
448 * It has since been replaced by SRXAFSCB_InitCallBackState3.
451 * rxcall : Ptr to Rx call on which this request came in.
454 * RXGEN_OPCODE (always).
457 * Nothing interesting.
461 *------------------------------------------------------------------------*/
463 afs_int32 SRXAFSCB_InitCallBackState2(rxcall, addr)
464 struct rx_call *rxcall;
465 struct interfaceAddr * addr;
468 #if XSTAT_FS_CALLBACK_VERBOSE
469 static char rn[] = "SRXAFSCB_InitCallBackState2"; /*Routine name*/
470 char hostName[256]; /*Host name buffer*/
471 char *hostNameResult; /*Ptr to static*/
473 if (rxcall != (struct rx_call *)0) {
475 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
476 strcpy(hostName, hostNameResult);
477 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
478 mn, rn, hostName, rxcall->conn->peer->port);
479 } /*Valid rxcall param*/
480 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
484 /*------------------------------------------------------------------------
485 * EXPORTED SRXAFSCB_WhoAreYou
488 * Routine called by the server-side callback RPC interface to
489 * obtain a unique identifier for the client. The server uses
490 * this identifier to figure out whether or not two RX connections
491 * are from the same client, and to find out which addresses go
492 * with which clients.
495 * rxcall : Ptr to Rx call on which this request came in.
496 * addr: Ptr to return the list of interfaces for this client.
502 * Nothing interesting.
506 *------------------------------------------------------------------------*/
508 afs_int32 SRXAFSCB_WhoAreYou(rxcall, addr)
509 struct rx_call *rxcall;
510 struct interfaceAddr *addr;
516 #if XSTAT_FS_CALLBACK_VERBOSE
517 static char rn[] = "SRXAFSCB_WhoAreYou"; /*Routine name*/
518 char hostName[256]; /*Host name buffer*/
519 char *hostNameResult; /*Ptr to static*/
521 if (rxcall != (struct rx_call *)0) {
523 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
524 strcpy(hostName, hostNameResult);
525 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
526 mn, rn, hostName, rxcall->conn->peer->port);
527 } /*Valid rxcall param*/
528 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
530 if ( rxcall && addr )
532 if (!afs_cb_inited) init_afs_cb();
533 *addr = afs_cb_interface;
537 * Return successfully.
543 /*------------------------------------------------------------------------
544 * EXPORTED SRXAFSCB_InitCallBackState3
547 * Routine called by the server-side callback RPC interface to
548 * implement clearing all callbacks from this host.
551 * rxcall : Ptr to Rx call on which this request came in.
557 * Nothing interesting.
561 *------------------------------------------------------------------------*/
563 afs_int32 SRXAFSCB_InitCallBackState3(rxcall, uuidp)
564 struct rx_call *rxcall;
567 #if XSTAT_FS_CALLBACK_VERBOSE
568 static char rn[] = "SRXAFSCB_InitCallBackState3"; /*Routine name*/
569 char hostName[256]; /*Host name buffer*/
570 char *hostNameResult; /*Ptr to static*/
572 if (rxcall != (struct rx_call *)0) {
574 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
575 strcpy(hostName, hostNameResult);
576 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
577 mn, rn, hostName, rxcall->conn->peer->port);
578 } /*Valid rxcall param*/
579 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
582 * Return successfully.
588 /*------------------------------------------------------------------------
589 * EXPORTED SRXAFSCB_ProbeUuid
592 * Routine called by the server-side callback RPC interface to
593 * implement ``probing'' the Cache Manager, just making sure it's
594 * still there is still the same client it used to be.
597 * rxcall : Ptr to Rx call on which this request came in.
598 * uuidp : Ptr to UUID that must match the client's UUID.
601 * 0 if uuidp matches the UUID for this client
605 * Nothing interesting.
609 *------------------------------------------------------------------------*/
611 afs_int32 SRXAFSCB_ProbeUuid(rxcall, uuidp)
612 struct rx_call *rxcall;
617 #if XSTAT_FS_CALLBACK_VERBOSE
618 static char rn[] = "SRXAFSCB_ProbeUuid"; /*Routine name*/
619 char hostName[256]; /*Host name buffer*/
620 char *hostNameResult; /*Ptr to static*/
622 if (rxcall != (struct rx_call *)0) {
624 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
625 strcpy(hostName, hostNameResult);
626 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
627 mn, rn, hostName, rxcall->conn->peer->port);
628 } /*Valid rxcall param*/
629 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
631 if (!afs_cb_inited) init_afs_cb();
632 if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
633 code = 1; /* failure */
637 /*------------------------------------------------------------------------
638 * EXPORTED SRXAFSCB_GetServerPrefs
641 * Routine to list server preferences used by this client.
644 * a_call : Ptr to Rx call on which this request came in.
645 * a_index : Input server index
646 * a_srvr_addr : Output server address (0xffffffff on last server)
647 * a_srvr_rank : Output server rank
650 * RXGEN_OPCODE (always)
653 * Nothing interesting.
657 *------------------------------------------------------------------------*/
659 afs_int32 SRXAFSCB_GetServerPrefs(
660 struct rx_call *a_call,
662 afs_int32 *a_srvr_addr,
663 afs_int32 *a_srvr_rank)
668 /*------------------------------------------------------------------------
669 * EXPORTED SRXAFSCB_GetCellServDB
672 * Routine to list cells configured for this client
675 * a_call : Ptr to Rx call on which this request came in.
676 * a_index : Input cell index
677 * a_name : Output cell name ("" on last cell)
678 * a_hosts : Output cell database servers
684 * Nothing interesting.
688 *------------------------------------------------------------------------*/
690 afs_int32 SRXAFSCB_GetCellServDB(
691 struct rx_call *a_call,
700 afs_int32 SRXAFSCB_GetCellByNum(
701 struct rx_call *a_call,
710 /*------------------------------------------------------------------------
711 * EXPORTED SRXAFSCB_GetLocalCell
714 * Routine to return name of client's local cell
717 * a_call : Ptr to Rx call on which this request came in.
718 * a_name : Output cell name
721 * RXGEN_OPCODE (always)
724 * Nothing interesting.
728 *------------------------------------------------------------------------*/
730 afs_int32 SRXAFSCB_GetLocalCell(
731 struct rx_call *a_call,
736 t_name = (char *)malloc(AFSNAMEMAX);
739 strcpy(t_name, "This is xstat_fs");
745 /*------------------------------------------------------------------------
746 * EXPORTED SRXAFSCB_GetCacheConfig
749 * Routine to return parameters used to initialize client cache.
750 * Client may request any format version. Server may not return
751 * format version greater than version requested by client.
754 * a_call: Ptr to Rx call on which this request came in.
755 * callerVersion: Data format version desired by the client.
756 * serverVersion: Data format version of output data.
757 * configCount: Number bytes allocated for output data.
758 * config: Client cache configuration.
761 * RXGEN_OPCODE (always)
764 * Nothing interesting.
768 *------------------------------------------------------------------------*/
770 afs_int32 SRXAFSCB_GetCacheConfig(
771 struct rx_call *a_call,
772 afs_uint32 callerVersion,
773 afs_uint32 *serverVersion,
774 afs_uint32 *configCount,