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, index, ce)
241 struct rx_call *rxcall;
243 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",
257 mn, rn, hostName, rxcall->conn->peer->port);
258 } /*Valid rxcall param*/
259 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
263 } /*SRXAFSCB_GetCE64*/
265 afs_int32 SRXAFSCB_GetCE(rxcall, index, ce)
266 struct rx_call *rxcall;
272 #if XSTAT_FS_CALLBACK_VERBOSE
273 static char rn[] = "SRXAFSCB_GetCE"; /*Routine name*/
274 char hostName[256]; /*Host name buffer*/
275 char *hostNameResult; /*Ptr to static*/
277 if (rxcall != (struct rx_call *)0) {
279 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
280 strcpy(hostName, hostNameResult);
281 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
282 mn, rn, hostName, rxcall->conn->peer->port);
283 } /*Valid rxcall param*/
284 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
291 /*------------------------------------------------------------------------
295 * Respond minimally to a request for returning the contents of
296 * a cache lock, since someone out there thinks you're a Cache
300 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
306 * Nothing interesting.
310 *------------------------------------------------------------------------*/
312 afs_int32 SRXAFSCB_GetLock(rxcall, index, lock)
313 struct rx_call *rxcall;
317 { /*SRXAFSCB_GetLock*/
319 #if XSTAT_FS_CALLBACK_VERBOSE
320 static char rn[] = "SRXAFSCB_GetLock"; /*Routine name*/
321 char hostName[256]; /*Host name buffer*/
322 char *hostNameResult; /*Ptr to static*/
324 if (rxcall != (struct rx_call *)0) {
326 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
327 strcpy(hostName, hostNameResult);
328 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
329 mn, rn, hostName, rxcall->conn->peer->port);
330 } /*Valid rxcall param*/
331 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
335 } /*SRXAFSCB_GetLock*/
338 /*------------------------------------------------------------------------
339 * SRXAFSCB_XStatsVersion
342 * Respond minimally to a request for fetching the version of
343 * extended Cache Manager statistics offered, since someone out
344 * there thinks you're a Cache Manager.
347 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
353 * Nothing interesting.
357 *------------------------------------------------------------------------*/
359 afs_int32 SRXAFSCB_XStatsVersion(rxcall, versionNumberP)
360 struct rx_call *rxcall;
361 afs_int32 *versionNumberP;
363 { /*SRXAFSCB_XStatsVersion*/
365 #if XSTAT_FS_CALLBACK_VERBOSE
366 static char rn[] = "SRXAFSCB_XStatsVersion"; /*Routine name*/
367 char hostName[256]; /*Host name buffer*/
368 char *hostNameResult; /*Ptr to static*/
370 if (rxcall != (struct rx_call *)0) {
372 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
373 strcpy(hostName, hostNameResult);
374 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
375 mn, rn, hostName, rxcall->conn->peer->port);
376 } /*Valid rxcall param*/
377 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
381 } /*SRXAFSCB_XStatsVersion*/
384 /*------------------------------------------------------------------------
388 * Respond minimally to a request for returning extended
389 * statistics for a Cache Manager, since someone out there thinks
390 * you're a Cache Manager.
393 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
399 * Nothing interesting.
403 *------------------------------------------------------------------------*/
405 afs_int32 SRXAFSCB_GetXStats(rxcall, clientVersionNumber, collectionNumber,
406 srvVersionNumberP, timeP, dataP)
407 struct rx_call *rxcall;
408 afs_int32 clientVersionNumber;
409 afs_int32 collectionNumber;
410 afs_int32 *srvVersionNumberP;
412 AFSCB_CollData *dataP;
414 { /*SRXAFSCB_GetXStats*/
416 #if XSTAT_FS_CALLBACK_VERBOSE
417 static char rn[] = "SRXAFSCB_GetXStats"; /*Routine name*/
418 char hostName[256]; /*Host name buffer*/
419 char *hostNameResult; /*Ptr to static*/
421 if (rxcall != (struct rx_call *)0) {
423 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
424 strcpy(hostName, hostNameResult);
425 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
426 mn, rn, hostName, rxcall->conn->peer->port);
427 } /*Valid rxcall param*/
428 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
432 } /*SRXAFSCB_GetXStats*/
434 /*------------------------------------------------------------------------
435 * EXPORTED SRXAFSCB_InitCallBackState2
438 * This routine was used in the AFS 3.5 beta release, but not anymore.
439 * It has since been replaced by SRXAFSCB_InitCallBackState3.
442 * rxcall : Ptr to Rx call on which this request came in.
445 * RXGEN_OPCODE (always).
448 * Nothing interesting.
452 *------------------------------------------------------------------------*/
454 int SRXAFSCB_InitCallBackState2(rxcall, addr)
455 struct rx_call *rxcall;
456 struct interfaceAddr * addr;
459 #if XSTAT_FS_CALLBACK_VERBOSE
460 static char rn[] = "SRXAFSCB_InitCallBackState2"; /*Routine name*/
461 char hostName[256]; /*Host name buffer*/
462 char *hostNameResult; /*Ptr to static*/
464 if (rxcall != (struct rx_call *)0) {
466 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
467 strcpy(hostName, hostNameResult);
468 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
469 mn, rn, hostName, rxcall->conn->peer->port);
470 } /*Valid rxcall param*/
471 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
475 /*------------------------------------------------------------------------
476 * EXPORTED SRXAFSCB_WhoAreYou
479 * Routine called by the server-side callback RPC interface to
480 * obtain a unique identifier for the client. The server uses
481 * this identifier to figure out whether or not two RX connections
482 * are from the same client, and to find out which addresses go
483 * with which clients.
486 * rxcall : Ptr to Rx call on which this request came in.
487 * addr: Ptr to return the list of interfaces for this client.
493 * Nothing interesting.
497 *------------------------------------------------------------------------*/
499 int SRXAFSCB_WhoAreYou(rxcall, addr)
500 struct rx_call *rxcall;
501 struct interfaceAddr *addr;
507 #if XSTAT_FS_CALLBACK_VERBOSE
508 static char rn[] = "SRXAFSCB_WhoAreYou"; /*Routine name*/
509 char hostName[256]; /*Host name buffer*/
510 char *hostNameResult; /*Ptr to static*/
512 if (rxcall != (struct rx_call *)0) {
514 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
515 strcpy(hostName, hostNameResult);
516 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
517 mn, rn, hostName, rxcall->conn->peer->port);
518 } /*Valid rxcall param*/
519 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
521 if ( rxcall && addr )
523 if (!afs_cb_inited) init_afs_cb();
524 *addr = afs_cb_interface;
528 * Return successfully.
534 /*------------------------------------------------------------------------
535 * EXPORTED SRXAFSCB_InitCallBackState3
538 * Routine called by the server-side callback RPC interface to
539 * implement clearing all callbacks from this host.
542 * rxcall : Ptr to Rx call on which this request came in.
548 * Nothing interesting.
552 *------------------------------------------------------------------------*/
554 int SRXAFSCB_InitCallBackState3(rxcall, uuidp)
555 struct rx_call *rxcall;
558 #if XSTAT_FS_CALLBACK_VERBOSE
559 static char rn[] = "SRXAFSCB_InitCallBackState3"; /*Routine name*/
560 char hostName[256]; /*Host name buffer*/
561 char *hostNameResult; /*Ptr to static*/
563 if (rxcall != (struct rx_call *)0) {
565 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
566 strcpy(hostName, hostNameResult);
567 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
568 mn, rn, hostName, rxcall->conn->peer->port);
569 } /*Valid rxcall param*/
570 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
573 * Return successfully.
579 /*------------------------------------------------------------------------
580 * EXPORTED SRXAFSCB_ProbeUuid
583 * Routine called by the server-side callback RPC interface to
584 * implement ``probing'' the Cache Manager, just making sure it's
585 * still there is still the same client it used to be.
588 * rxcall : Ptr to Rx call on which this request came in.
589 * uuidp : Ptr to UUID that must match the client's UUID.
592 * 0 if uuidp matches the UUID for this client
596 * Nothing interesting.
600 *------------------------------------------------------------------------*/
602 int SRXAFSCB_ProbeUuid(rxcall, uuidp)
603 struct rx_call *rxcall;
608 #if XSTAT_FS_CALLBACK_VERBOSE
609 static char rn[] = "SRXAFSCB_ProbeUuid"; /*Routine name*/
610 char hostName[256]; /*Host name buffer*/
611 char *hostNameResult; /*Ptr to static*/
613 if (rxcall != (struct rx_call *)0) {
615 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
616 strcpy(hostName, hostNameResult);
617 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
618 mn, rn, hostName, rxcall->conn->peer->port);
619 } /*Valid rxcall param*/
620 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
622 if (!afs_cb_inited) init_afs_cb();
623 if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
624 code = 1; /* failure */
628 /*------------------------------------------------------------------------
629 * EXPORTED SRXAFSCB_GetServerPrefs
632 * Routine to list server preferences used by this client.
635 * a_call : Ptr to Rx call on which this request came in.
636 * a_index : Input server index
637 * a_srvr_addr : Output server address (0xffffffff on last server)
638 * a_srvr_rank : Output server rank
641 * RXGEN_OPCODE (always)
644 * Nothing interesting.
648 *------------------------------------------------------------------------*/
650 int SRXAFSCB_GetServerPrefs(
651 struct rx_call *a_call,
653 afs_int32 *a_srvr_addr,
654 afs_int32 *a_srvr_rank)
659 /*------------------------------------------------------------------------
660 * EXPORTED SRXAFSCB_GetCellServDB
663 * Routine to list cells configured for this client
666 * a_call : Ptr to Rx call on which this request came in.
667 * a_index : Input cell index
668 * a_name : Output cell name ("" on last cell)
669 * a_hosts : Output cell database servers
675 * Nothing interesting.
679 *------------------------------------------------------------------------*/
681 int SRXAFSCB_GetCellServDB(
682 struct rx_call *a_call,
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 *------------------------------------------------------------------------*/
711 int SRXAFSCB_GetLocalCell(
712 struct rx_call *a_call,
717 t_name = (char *)malloc(AFSNAMEMAX);
720 strcpy(t_name, "This is xstat_fs");
726 /*------------------------------------------------------------------------
727 * EXPORTED SRXAFSCB_GetCacheConfig
730 * Routine to return parameters used to initialize client cache.
731 * Client may request any format version. Server may not return
732 * format version greater than version requested by client.
735 * a_call: Ptr to Rx call on which this request came in.
736 * callerVersion: Data format version desired by the client.
737 * serverVersion: Data format version of output data.
738 * configCount: Number bytes allocated for output data.
739 * config: Client cache configuration.
742 * RXGEN_OPCODE (always)
745 * Nothing interesting.
749 *------------------------------------------------------------------------*/
751 int SRXAFSCB_GetCacheConfig(
752 struct rx_call *a_call,
753 afs_uint32 callerVersion,
754 afs_uint32 *serverVersion,
755 afs_uint32 *configCount,