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>
34 #include <stdio.h> /*Standard I/O stuff */
37 #include <afs/afscbint.h> /*Callback interface defs */
38 #include <afs/afsutil.h>
40 int afs_cb_inited = 0;
41 struct interfaceAddr afs_cb_interface;
43 #define XSTAT_FS_CALLBACK_VERBOSE 0
46 * Initialize the callback interface structure
54 UuidCreate((UUID *)&afs_cb_interface.uuid);
56 afs_uuid_create(&afs_cb_interface.uuid);
58 count = rx_getAllAddr(&afs_cb_interface.addr_in, AFS_MAX_INTERFACE_ADDR);
60 afs_cb_interface.numberOfInterfaces = 0;
62 afs_cb_interface.numberOfInterfaces = count;
67 #if XSTAT_FS_CALLBACK_VERBOSE
68 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 *------------------------------------------------------------------------*/
94 SRXAFSCB_CallBack(struct rx_call *rxcall, AFSCBFids * Fids_Array,
95 AFSCBs * CallBack_Array)
96 { /*SRXAFSCB_CallBack */
98 #if XSTAT_FS_CALLBACK_VERBOSE
99 static char rn[] = "SRXAFSCB_CallBack"; /*Routine name */
100 char hostName[256]; /*Host name buffer */
101 char *hostNameResult; /*Ptr to static */
103 fprintf(stderr, "[%s:%s] Called\n", mn, rn);
105 if (rxcall != (struct rx_call *)0) {
107 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
108 strcpy(hostName, hostNameResult);
109 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
110 hostName, rxcall->conn->peer->port);
111 } /*Valid rxcall param */
112 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
115 * Return successfully.
119 } /*SRXAFSCB_CallBack */
121 /*------------------------------------------------------------------------
122 * SRXAFSCB_InitCallBackState
125 * Initialize callback state on this ``Cache Manager''.
128 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
132 * Error value otherwise.
135 * This will definitely be called by the File Server (exactly once),
136 * since it will think we are another new ``Cache Manager''.
140 *------------------------------------------------------------------------*/
143 SRXAFSCB_InitCallBackState(struct rx_call * rxcall)
144 { /*SRXAFSCB_InitCallBackState */
146 #if XSTAT_FS_CALLBACK_VERBOSE
147 static char rn[] = "SRXAFSCB_InitCallBackState"; /*Routine name */
148 char hostName[256]; /*Host name buffer */
149 char *hostNameResult; /*Ptr to static */
151 fprintf(stderr, "[%s:%s] Called\n", mn, rn);
153 if (rxcall != (struct rx_call *)0) {
155 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
156 strcpy(hostName, hostNameResult);
157 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
158 hostName, rxcall->conn->peer->port);
159 } /*Valid rxcall param */
160 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
163 * Return successfully.
167 } /*SRXAFSCB_InitCallBackState */
169 /*------------------------------------------------------------------------
173 * Respond to a probe from the File Server. If a File Server
174 * doesn't hear from you every so often, it will send you a probe
175 * to make sure you're there, just like any other ``Cache Manager''
176 * it's keeping track of.
179 * struct rx_call *rxcall : Ptr to the associated Rx call structure.
183 * Error value otherwise.
186 * This may be called by the File Server if we don't call it often
191 *------------------------------------------------------------------------*/
194 SRXAFSCB_Probe(struct rx_call * rxcall)
195 { /*SRXAFSCB_Probe */
197 #if XSTAT_FS_CALLBACK_VERBOSE
198 static char rn[] = "SRXAFSCB_Probe"; /*Routine name */
199 char hostName[256]; /*Host name buffer */
200 char *hostNameResult; /*Ptr to static */
202 fprintf(stderr, "[%s:%s] Called\n", mn, rn);
204 if (rxcall != (struct rx_call *)0) {
206 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
207 strcpy(hostName, hostNameResult);
208 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
209 hostName, rxcall->conn->peer->port);
210 } /*Valid rxcall param */
211 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
214 * Return successfully.
218 } /*SRXAFSCB_Probe */
221 /*------------------------------------------------------------------------
225 * Respond minimally to a request for returning the contents of
226 * a cache entry, since someone out there thinks you're a Cache
230 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
236 * Nothing interesting.
240 *------------------------------------------------------------------------*/
243 SRXAFSCB_GetCE64(struct rx_call * rxcall, afs_int32 index,
244 AFSDBCacheEntry64 * ce)
245 { /*SRXAFSCB_GetCE64 */
247 #if XSTAT_FS_CALLBACK_VERBOSE
248 static char rn[] = "SRXAFSCB_GetCE64"; /*Routine name */
249 char hostName[256]; /*Host name buffer */
250 char *hostNameResult; /*Ptr to static */
252 if (rxcall != (struct rx_call *)0) {
254 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
255 strcpy(hostName, hostNameResult);
256 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
257 hostName, rxcall->conn->peer->port);
258 } /*Valid rxcall param */
259 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
263 } /*SRXAFSCB_GetCE64 */
266 SRXAFSCB_GetCE(struct rx_call * rxcall, afs_int32 index, AFSDBCacheEntry * ce)
267 { /*SRXAFSCB_GetCE */
269 #if XSTAT_FS_CALLBACK_VERBOSE
270 static char rn[] = "SRXAFSCB_GetCE"; /*Routine name */
271 char hostName[256]; /*Host name buffer */
272 char *hostNameResult; /*Ptr to static */
274 if (rxcall != (struct rx_call *)0) {
276 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
277 strcpy(hostName, hostNameResult);
278 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
279 hostName, rxcall->conn->peer->port);
280 } /*Valid rxcall param */
281 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
285 } /*SRXAFSCB_GetCE */
288 /*------------------------------------------------------------------------
292 * Respond minimally to a request for returning the contents of
293 * a cache lock, since someone out there thinks you're a Cache
297 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
303 * Nothing interesting.
307 *------------------------------------------------------------------------*/
310 SRXAFSCB_GetLock(struct rx_call * rxcall, afs_int32 index, AFSDBLock * lock)
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", mn, rn,
323 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 *------------------------------------------------------------------------*/
354 SRXAFSCB_XStatsVersion(struct rx_call * rxcall, afs_int32 * versionNumberP)
355 { /*SRXAFSCB_XStatsVersion */
357 #if XSTAT_FS_CALLBACK_VERBOSE
358 static char rn[] = "SRXAFSCB_XStatsVersion"; /*Routine name */
359 char hostName[256]; /*Host name buffer */
360 char *hostNameResult; /*Ptr to static */
362 if (rxcall != (struct rx_call *)0) {
364 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
365 strcpy(hostName, hostNameResult);
366 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
367 hostName, rxcall->conn->peer->port);
368 } /*Valid rxcall param */
369 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
373 } /*SRXAFSCB_XStatsVersion */
376 /*------------------------------------------------------------------------
380 * Respond minimally to a request for returning extended
381 * statistics for a Cache Manager, since someone out there thinks
382 * you're a Cache Manager.
385 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
391 * Nothing interesting.
395 *------------------------------------------------------------------------*/
398 SRXAFSCB_GetXStats(struct rx_call * rxcall, afs_int32 clientVersionNumber,
399 afs_int32 collectionNumber, afs_int32 * srvVersionNumberP,
400 afs_int32 * timeP, AFSCB_CollData * dataP)
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", mn, rn,
413 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 *------------------------------------------------------------------------*/
442 SRXAFSCB_InitCallBackState2(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", mn, rn,
456 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 *------------------------------------------------------------------------*/
487 SRXAFSCB_WhoAreYou(struct rx_call * rxcall, struct interfaceAddr * addr)
489 #if XSTAT_FS_CALLBACK_VERBOSE
490 static char rn[] = "SRXAFSCB_WhoAreYou"; /*Routine name */
491 char hostName[256]; /*Host name buffer */
492 char *hostNameResult; /*Ptr to static */
494 if (rxcall != (struct rx_call *)0) {
496 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
497 strcpy(hostName, hostNameResult);
498 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
499 hostName, rxcall->conn->peer->port);
500 } /*Valid rxcall param */
501 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
503 if (rxcall && addr) {
506 *addr = afs_cb_interface;
510 * Return successfully.
516 /*------------------------------------------------------------------------
517 * EXPORTED SRXAFSCB_InitCallBackState3
520 * Routine called by the server-side callback RPC interface to
521 * implement clearing all callbacks from this host.
524 * rxcall : Ptr to Rx call on which this request came in.
530 * Nothing interesting.
534 *------------------------------------------------------------------------*/
537 SRXAFSCB_InitCallBackState3(struct rx_call * rxcall, afsUUID * uuidp)
539 #if XSTAT_FS_CALLBACK_VERBOSE
540 static char rn[] = "SRXAFSCB_InitCallBackState3"; /*Routine name */
541 char hostName[256]; /*Host name buffer */
542 char *hostNameResult; /*Ptr to static */
544 if (rxcall != (struct rx_call *)0) {
546 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
547 strcpy(hostName, hostNameResult);
548 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
549 hostName, rxcall->conn->peer->port);
550 } /*Valid rxcall param */
551 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
554 * Return successfully.
560 /*------------------------------------------------------------------------
561 * EXPORTED SRXAFSCB_ProbeUuid
564 * Routine called by the server-side callback RPC interface to
565 * implement ``probing'' the Cache Manager, just making sure it's
566 * still there is still the same client it used to be.
569 * rxcall : Ptr to Rx call on which this request came in.
570 * uuidp : Ptr to UUID that must match the client's UUID.
573 * 0 if uuidp matches the UUID for this client
577 * Nothing interesting.
581 *------------------------------------------------------------------------*/
584 SRXAFSCB_ProbeUuid(struct rx_call * rxcall, afsUUID * uuidp)
588 #if XSTAT_FS_CALLBACK_VERBOSE
589 static char rn[] = "SRXAFSCB_ProbeUuid"; /*Routine name */
590 char hostName[256]; /*Host name buffer */
591 char *hostNameResult; /*Ptr to static */
593 if (rxcall != (struct rx_call *)0) {
595 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
596 strcpy(hostName, hostNameResult);
597 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
598 hostName, rxcall->conn->peer->port);
599 } /*Valid rxcall param */
600 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
604 if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
605 code = 1; /* failure */
609 /*------------------------------------------------------------------------
610 * EXPORTED SRXAFSCB_GetServerPrefs
613 * Routine to list server preferences used by this client.
616 * a_call : Ptr to Rx call on which this request came in.
617 * a_index : Input server index
618 * a_srvr_addr : Output server address (0xffffffff on last server)
619 * a_srvr_rank : Output server rank
622 * RXGEN_OPCODE (always)
625 * Nothing interesting.
629 *------------------------------------------------------------------------*/
632 SRXAFSCB_GetServerPrefs(struct rx_call * a_call, afs_int32 a_index,
633 afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank)
638 /*------------------------------------------------------------------------
639 * EXPORTED SRXAFSCB_GetCellServDB
642 * Routine to list cells configured for this client
645 * a_call : Ptr to Rx call on which this request came in.
646 * a_index : Input cell index
647 * a_name : Output cell name ("" on last cell)
648 * a_hosts : Output cell database servers
654 * Nothing interesting.
658 *------------------------------------------------------------------------*/
661 SRXAFSCB_GetCellServDB(struct rx_call * a_call, afs_int32 a_index,
662 char **a_name, serverList * a_hosts)
669 SRXAFSCB_GetCellByNum(struct rx_call * a_call, afs_int32 a_cellnum,
670 char **a_name, serverList * a_hosts)
676 /*------------------------------------------------------------------------
677 * EXPORTED SRXAFSCB_GetLocalCell
680 * Routine to return name of client's local cell
683 * a_call : Ptr to Rx call on which this request came in.
684 * a_name : Output cell name
687 * RXGEN_OPCODE (always)
690 * Nothing interesting.
694 *------------------------------------------------------------------------*/
697 SRXAFSCB_GetLocalCell(struct rx_call * a_call, char **a_name)
701 t_name = (char *)malloc(AFSNAMEMAX);
704 strcpy(t_name, "This is xstat_fs");
710 /*------------------------------------------------------------------------
711 * EXPORTED SRXAFSCB_GetCacheConfig
714 * Routine to return parameters used to initialize client cache.
715 * Client may request any format version. Server may not return
716 * format version greater than version requested by client.
719 * a_call: Ptr to Rx call on which this request came in.
720 * callerVersion: Data format version desired by the client.
721 * serverVersion: Data format version of output data.
722 * configCount: Number bytes allocated for output data.
723 * config: Client cache configuration.
726 * RXGEN_OPCODE (always)
729 * Nothing interesting.
733 *------------------------------------------------------------------------*/
736 SRXAFSCB_GetCacheConfig(struct rx_call * a_call, afs_uint32 callerVersion,
737 afs_uint32 * serverVersion, afs_uint32 * configCount,
738 cacheConfig * config)
744 SRXAFSCB_TellMeAboutYourself(struct rx_call * rxcall,
745 struct interfaceAddr * addr,
746 Capabilities * capabilites)
748 #if XSTAT_FS_CALLBACK_VERBOSE
749 static char rn[] = "SRXAFSCB_TellMeAboutYourself"; /*Routine name */
750 char hostName[256]; /*Host name buffer */
751 char *hostNameResult; /*Ptr to static */
753 if (rxcall != (struct rx_call *)0) {
755 hostutil_GetNameByINet((afs_int32) (rxcall->conn->peer->host));
756 strcpy(hostName, hostNameResult);
757 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n", mn, rn,
758 hostName, rxcall->conn->peer->port);
759 } /*Valid rxcall param */
760 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
762 if (rxcall && addr) {
765 *addr = afs_cb_interface;
769 * Return successfully.
774 int SRXAFSCB_GetDE(struct rx_call *a_call, afs_int32 a_index, afs_int32 addr,
775 afs_int32 inode, afs_int32 flags, afs_int32 time,