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>
36 #include <stdio.h> /*Standard I/O stuff */
46 #include <afs/afscbint.h> /*Callback interface defs */
48 int afs_cb_inited = 0;
49 struct interfaceAddr afs_cb_interface;
51 #define XSTAT_FS_CALLBACK_VERBOSE 0
54 * Initialize the callback interface structure
62 UuidCreate((UUID *)&afs_cb_interface.uuid);
64 afs_uuid_create(&afs_cb_interface.uuid);
66 count = rx_getAllAddr(&afs_cb_interface.addr_in, AFS_MAX_INTERFACE_ADDR);
68 afs_cb_interface.numberOfInterfaces = 0;
70 afs_cb_interface.numberOfInterfaces = count;
76 * Routines we need that don't have explicit include file definitions.
78 extern char *hostutil_GetNameByINet(); /*Host parsing utility */
80 static char mn[] = "xstat_fs_callback"; /*Module name */
82 /*------------------------------------------------------------------------
86 * Handle a set of callbacks from the File Server.
89 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
90 * AFSCBFids *Fids_Array : Ptr to the set of Fids.
91 * AFSCBs *CallBacks_Array : Ptr to the set of callbacks.
95 * Error value otherwise.
98 * Nothing interesting.
102 *------------------------------------------------------------------------*/
105 SRXAFSCB_CallBack(struct rx_call *rxcall, AFSCBFids * Fids_Array,
106 AFSCBs * CallBack_Array)
107 { /*SRXAFSCB_CallBack */
109 #if XSTAT_FS_CALLBACK_VERBOSE
110 static char rn[] = "SRXAFSCB_CallBack"; /*Routine name */
111 char hostName[256]; /*Host name buffer */
112 char *hostNameResult; /*Ptr to static */
114 fprintf(stderr, "[%s:%s] Called\n", mn, rn);
116 if (rxcall != (struct rx_call *)0) {
118 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
119 strcpy(hostName, hostNameResult);
120 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
121 hostName, rxcall->conn->peer->port);
122 } /*Valid rxcall param */
123 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
126 * Return successfully.
130 } /*SRXAFSCB_CallBack */
132 /*------------------------------------------------------------------------
133 * SRXAFSCB_InitCallBackState
136 * Initialize callback state on this ``Cache Manager''.
139 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
143 * Error value otherwise.
146 * This will definitely be called by the File Server (exactly once),
147 * since it will think we are another new ``Cache Manager''.
151 *------------------------------------------------------------------------*/
154 SRXAFSCB_InitCallBackState(struct rx_call * rxcall)
155 { /*SRXAFSCB_InitCallBackState */
157 #if XSTAT_FS_CALLBACK_VERBOSE
158 static char rn[] = "SRXAFSCB_InitCallBackState"; /*Routine name */
159 char hostName[256]; /*Host name buffer */
160 char *hostNameResult; /*Ptr to static */
162 fprintf(stderr, "[%s:%s] Called\n", mn, rn);
164 if (rxcall != (struct rx_call *)0) {
166 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
167 strcpy(hostName, hostNameResult);
168 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
169 hostName, rxcall->conn->peer->port);
170 } /*Valid rxcall param */
171 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
174 * Return successfully.
178 } /*SRXAFSCB_InitCallBackState */
180 /*------------------------------------------------------------------------
184 * Respond to a probe from the File Server. If a File Server
185 * doesn't hear from you every so often, it will send you a probe
186 * to make sure you're there, just like any other ``Cache Manager''
187 * it's keeping track of.
190 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
194 * Error value otherwise.
197 * This may be called by the File Server if we don't call it often
202 *------------------------------------------------------------------------*/
205 SRXAFSCB_Probe(struct rx_call * rxcall)
206 { /*SRXAFSCB_Probe */
208 #if XSTAT_FS_CALLBACK_VERBOSE
209 static char rn[] = "SRXAFSCB_Probe"; /*Routine name */
210 char hostName[256]; /*Host name buffer */
211 char *hostNameResult; /*Ptr to static */
213 fprintf(stderr, "[%s:%s] Called\n", mn, rn);
215 if (rxcall != (struct rx_call *)0) {
217 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
218 strcpy(hostName, hostNameResult);
219 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
220 hostName, rxcall->conn->peer->port);
221 } /*Valid rxcall param */
222 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
225 * Return successfully.
229 } /*SRXAFSCB_Probe */
232 /*------------------------------------------------------------------------
236 * Respond minimally to a request for returning the contents of
237 * a cache entry, since someone out there thinks you're a Cache
241 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
247 * Nothing interesting.
251 *------------------------------------------------------------------------*/
254 SRXAFSCB_GetCE64(struct rx_call * rxcall, afs_int32 index,
255 AFSDBCacheEntry64 * ce)
256 { /*SRXAFSCB_GetCE64 */
258 #if XSTAT_FS_CALLBACK_VERBOSE
259 static char rn[] = "SRXAFSCB_GetCE64"; /*Routine name */
260 char hostName[256]; /*Host name buffer */
261 char *hostNameResult; /*Ptr to static */
263 if (rxcall != (struct rx_call *)0) {
265 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
266 strcpy(hostName, hostNameResult);
267 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
268 hostName, rxcall->conn->peer->port);
269 } /*Valid rxcall param */
270 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
274 } /*SRXAFSCB_GetCE64 */
277 SRXAFSCB_GetCE(struct rx_call * rxcall, afs_int32 index, AFSDBCacheEntry * ce)
278 { /*SRXAFSCB_GetCE */
280 #if XSTAT_FS_CALLBACK_VERBOSE
281 static char rn[] = "SRXAFSCB_GetCE"; /*Routine name */
282 char hostName[256]; /*Host name buffer */
283 char *hostNameResult; /*Ptr to static */
285 if (rxcall != (struct rx_call *)0) {
287 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
288 strcpy(hostName, hostNameResult);
289 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
290 hostName, rxcall->conn->peer->port);
291 } /*Valid rxcall param */
292 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
296 } /*SRXAFSCB_GetCE */
299 /*------------------------------------------------------------------------
303 * Respond minimally to a request for returning the contents of
304 * a cache lock, since someone out there thinks you're a Cache
308 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
314 * Nothing interesting.
318 *------------------------------------------------------------------------*/
321 SRXAFSCB_GetLock(struct rx_call * rxcall, afs_int32 index, AFSDBLock * lock)
322 { /*SRXAFSCB_GetLock */
324 #if XSTAT_FS_CALLBACK_VERBOSE
325 static char rn[] = "SRXAFSCB_GetLock"; /*Routine name */
326 char hostName[256]; /*Host name buffer */
327 char *hostNameResult; /*Ptr to static */
329 if (rxcall != (struct rx_call *)0) {
331 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
332 strcpy(hostName, hostNameResult);
333 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
334 hostName, rxcall->conn->peer->port);
335 } /*Valid rxcall param */
336 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
340 } /*SRXAFSCB_GetLock */
343 /*------------------------------------------------------------------------
344 * SRXAFSCB_XStatsVersion
347 * Respond minimally to a request for fetching the version of
348 * extended Cache Manager statistics offered, since someone out
349 * there thinks you're a Cache Manager.
352 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
358 * Nothing interesting.
362 *------------------------------------------------------------------------*/
365 SRXAFSCB_XStatsVersion(struct rx_call * rxcall, afs_int32 * versionNumberP)
366 { /*SRXAFSCB_XStatsVersion */
368 #if XSTAT_FS_CALLBACK_VERBOSE
369 static char rn[] = "SRXAFSCB_XStatsVersion"; /*Routine name */
370 char hostName[256]; /*Host name buffer */
371 char *hostNameResult; /*Ptr to static */
373 if (rxcall != (struct rx_call *)0) {
375 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
376 strcpy(hostName, hostNameResult);
377 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
378 hostName, rxcall->conn->peer->port);
379 } /*Valid rxcall param */
380 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
384 } /*SRXAFSCB_XStatsVersion */
387 /*------------------------------------------------------------------------
391 * Respond minimally to a request for returning extended
392 * statistics for a Cache Manager, since someone out there thinks
393 * you're a Cache Manager.
396 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
402 * Nothing interesting.
406 *------------------------------------------------------------------------*/
409 SRXAFSCB_GetXStats(struct rx_call * rxcall, afs_int32 clientVersionNumber,
410 afs_int32 collectionNumber, afs_int32 * srvVersionNumberP,
411 afs_int32 * timeP, AFSCB_CollData * dataP)
412 { /*SRXAFSCB_GetXStats */
414 #if XSTAT_FS_CALLBACK_VERBOSE
415 static char rn[] = "SRXAFSCB_GetXStats"; /*Routine name */
416 char hostName[256]; /*Host name buffer */
417 char *hostNameResult; /*Ptr to static */
419 if (rxcall != (struct rx_call *)0) {
421 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
422 strcpy(hostName, hostNameResult);
423 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
424 hostName, rxcall->conn->peer->port);
425 } /*Valid rxcall param */
426 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
430 } /*SRXAFSCB_GetXStats */
432 /*------------------------------------------------------------------------
433 * EXPORTED SRXAFSCB_InitCallBackState2
436 * This routine was used in the AFS 3.5 beta release, but not anymore.
437 * It has since been replaced by SRXAFSCB_InitCallBackState3.
440 * rxcall : Ptr to Rx call on which this request came in.
443 * RXGEN_OPCODE (always).
446 * Nothing interesting.
450 *------------------------------------------------------------------------*/
453 SRXAFSCB_InitCallBackState2(struct rx_call * rxcall,
454 struct interfaceAddr * addr)
457 #if XSTAT_FS_CALLBACK_VERBOSE
458 static char rn[] = "SRXAFSCB_InitCallBackState2"; /*Routine name */
459 char hostName[256]; /*Host name buffer */
460 char *hostNameResult; /*Ptr to static */
462 if (rxcall != (struct rx_call *)0) {
464 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
465 strcpy(hostName, hostNameResult);
466 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
467 hostName, rxcall->conn->peer->port);
468 } /*Valid rxcall param */
469 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
473 /*------------------------------------------------------------------------
474 * EXPORTED SRXAFSCB_WhoAreYou
477 * Routine called by the server-side callback RPC interface to
478 * obtain a unique identifier for the client. The server uses
479 * this identifier to figure out whether or not two RX connections
480 * are from the same client, and to find out which addresses go
481 * with which clients.
484 * rxcall : Ptr to Rx call on which this request came in.
485 * addr: Ptr to return the list of interfaces for this client.
491 * Nothing interesting.
495 *------------------------------------------------------------------------*/
498 SRXAFSCB_WhoAreYou(struct rx_call * rxcall, struct interfaceAddr * addr)
504 #if XSTAT_FS_CALLBACK_VERBOSE
505 static char rn[] = "SRXAFSCB_WhoAreYou"; /*Routine name */
506 char hostName[256]; /*Host name buffer */
507 char *hostNameResult; /*Ptr to static */
509 if (rxcall != (struct rx_call *)0) {
511 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
512 strcpy(hostName, hostNameResult);
513 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
514 hostName, rxcall->conn->peer->port);
515 } /*Valid rxcall param */
516 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
518 if (rxcall && addr) {
521 *addr = afs_cb_interface;
525 * Return successfully.
531 /*------------------------------------------------------------------------
532 * EXPORTED SRXAFSCB_InitCallBackState3
535 * Routine called by the server-side callback RPC interface to
536 * implement clearing all callbacks from this host.
539 * rxcall : Ptr to Rx call on which this request came in.
545 * Nothing interesting.
549 *------------------------------------------------------------------------*/
552 SRXAFSCB_InitCallBackState3(struct rx_call * rxcall, afsUUID * uuidp)
554 #if XSTAT_FS_CALLBACK_VERBOSE
555 static char rn[] = "SRXAFSCB_InitCallBackState3"; /*Routine name */
556 char hostName[256]; /*Host name buffer */
557 char *hostNameResult; /*Ptr to static */
559 if (rxcall != (struct rx_call *)0) {
561 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
562 strcpy(hostName, hostNameResult);
563 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
564 hostName, rxcall->conn->peer->port);
565 } /*Valid rxcall param */
566 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
569 * Return successfully.
575 /*------------------------------------------------------------------------
576 * EXPORTED SRXAFSCB_ProbeUuid
579 * Routine called by the server-side callback RPC interface to
580 * implement ``probing'' the Cache Manager, just making sure it's
581 * still there is still the same client it used to be.
584 * rxcall : Ptr to Rx call on which this request came in.
585 * uuidp : Ptr to UUID that must match the client's UUID.
588 * 0 if uuidp matches the UUID for this client
592 * Nothing interesting.
596 *------------------------------------------------------------------------*/
599 SRXAFSCB_ProbeUuid(struct rx_call * rxcall, afsUUID * uuidp)
603 #if XSTAT_FS_CALLBACK_VERBOSE
604 static char rn[] = "SRXAFSCB_ProbeUuid"; /*Routine name */
605 char hostName[256]; /*Host name buffer */
606 char *hostNameResult; /*Ptr to static */
608 if (rxcall != (struct rx_call *)0) {
610 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
611 strcpy(hostName, hostNameResult);
612 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
613 hostName, rxcall->conn->peer->port);
614 } /*Valid rxcall param */
615 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
619 if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
620 code = 1; /* failure */
624 /*------------------------------------------------------------------------
625 * EXPORTED SRXAFSCB_GetServerPrefs
628 * Routine to list server preferences used by this client.
631 * a_call : Ptr to Rx call on which this request came in.
632 * a_index : Input server index
633 * a_srvr_addr : Output server address (0xffffffff on last server)
634 * a_srvr_rank : Output server rank
637 * RXGEN_OPCODE (always)
640 * Nothing interesting.
644 *------------------------------------------------------------------------*/
647 SRXAFSCB_GetServerPrefs(struct rx_call * a_call, afs_int32 a_index,
648 afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank)
653 /*------------------------------------------------------------------------
654 * EXPORTED SRXAFSCB_GetCellServDB
657 * Routine to list cells configured for this client
660 * a_call : Ptr to Rx call on which this request came in.
661 * a_index : Input cell index
662 * a_name : Output cell name ("" on last cell)
663 * a_hosts : Output cell database servers
669 * Nothing interesting.
673 *------------------------------------------------------------------------*/
676 SRXAFSCB_GetCellServDB(struct rx_call * a_call, afs_int32 a_index,
677 char **a_name, serverList * a_hosts)
684 SRXAFSCB_GetCellByNum(struct rx_call * a_call, afs_int32 a_cellnum,
685 char **a_name, serverList * a_hosts)
691 /*------------------------------------------------------------------------
692 * EXPORTED SRXAFSCB_GetLocalCell
695 * Routine to return name of client's local cell
698 * a_call : Ptr to Rx call on which this request came in.
699 * a_name : Output cell name
702 * RXGEN_OPCODE (always)
705 * Nothing interesting.
709 *------------------------------------------------------------------------*/
712 SRXAFSCB_GetLocalCell(struct rx_call * a_call, char **a_name)
716 t_name = (char *)malloc(AFSNAMEMAX);
719 strcpy(t_name, "This is xstat_fs");
725 /*------------------------------------------------------------------------
726 * EXPORTED SRXAFSCB_GetCacheConfig
729 * Routine to return parameters used to initialize client cache.
730 * Client may request any format version. Server may not return
731 * format version greater than version requested by client.
734 * a_call: Ptr to Rx call on which this request came in.
735 * callerVersion: Data format version desired by the client.
736 * serverVersion: Data format version of output data.
737 * configCount: Number bytes allocated for output data.
738 * config: Client cache configuration.
741 * RXGEN_OPCODE (always)
744 * Nothing interesting.
748 *------------------------------------------------------------------------*/
751 SRXAFSCB_GetCacheConfig(struct rx_call * a_call, afs_uint32 callerVersion,
752 afs_uint32 * serverVersion, afs_uint32 * configCount,
753 cacheConfig * config)
759 SRXAFSCB_TellMeAboutYourself(struct rx_call * rxcall,
760 struct interfaceAddr * addr,
761 Capabilities * capabilites)
767 #if XSTAT_FS_CALLBACK_VERBOSE
768 static char rn[] = "SRXAFSCB_TellMeAboutYourself"; /*Routine name */
769 char hostName[256]; /*Host name buffer */
770 char *hostNameResult; /*Ptr to static */
772 if (rxcall != (struct rx_call *)0) {
774 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
775 strcpy(hostName, hostNameResult);
776 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
777 hostName, rxcall->conn->peer->port);
778 } /*Valid rxcall param */
779 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
781 if (rxcall && addr) {
784 *addr = afs_cb_interface;
788 * Return successfully.
793 int SRXAFSCB_GetDE(a_call, a_index, addr, inode, flags, time, fileName)
794 struct rx_call *a_call;