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_GetCE(rxcall)
241 struct rx_call *rxcall;
245 #if XSTAT_FS_CALLBACK_VERBOSE
246 static char rn[] = "SRXAFSCB_GetCE"; /*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 */
264 /*------------------------------------------------------------------------
268 * Respond minimally to a request for returning the contents of
269 * a cache lock, since someone out there thinks you're a Cache
273 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
279 * Nothing interesting.
283 *------------------------------------------------------------------------*/
285 afs_int32 SRXAFSCB_GetLock(rxcall)
286 struct rx_call *rxcall;
288 { /*SRXAFSCB_GetLock*/
290 #if XSTAT_FS_CALLBACK_VERBOSE
291 static char rn[] = "SRXAFSCB_GetLock"; /*Routine name*/
292 char hostName[256]; /*Host name buffer*/
293 char *hostNameResult; /*Ptr to static*/
295 if (rxcall != (struct rx_call *)0) {
297 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
298 strcpy(hostName, hostNameResult);
299 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
300 mn, rn, hostName, rxcall->conn->peer->port);
301 } /*Valid rxcall param*/
302 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
306 } /*SRXAFSCB_GetLock*/
309 /*------------------------------------------------------------------------
310 * SRXAFSCB_XStatsVersion
313 * Respond minimally to a request for fetching the version of
314 * extended Cache Manager statistics offered, since someone out
315 * there thinks you're a Cache Manager.
318 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
324 * Nothing interesting.
328 *------------------------------------------------------------------------*/
330 afs_int32 SRXAFSCB_XStatsVersion(rxcall)
331 struct rx_call *rxcall;
333 { /*SRXAFSCB_XStatsVersion*/
335 #if XSTAT_FS_CALLBACK_VERBOSE
336 static char rn[] = "SRXAFSCB_XStatsVersion"; /*Routine name*/
337 char hostName[256]; /*Host name buffer*/
338 char *hostNameResult; /*Ptr to static*/
340 if (rxcall != (struct rx_call *)0) {
342 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
343 strcpy(hostName, hostNameResult);
344 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
345 mn, rn, hostName, rxcall->conn->peer->port);
346 } /*Valid rxcall param*/
347 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
351 } /*SRXAFSCB_XStatsVersion*/
354 /*------------------------------------------------------------------------
358 * Respond minimally to a request for returning extended
359 * statistics for a Cache Manager, since someone out there thinks
360 * you're a Cache Manager.
363 * struct rx_call *rxcall: Ptr to the associated Rx call structure.
369 * Nothing interesting.
373 *------------------------------------------------------------------------*/
375 afs_int32 SRXAFSCB_GetXStats(rxcall)
376 struct rx_call *rxcall;
378 { /*SRXAFSCB_GetXStats*/
380 #if XSTAT_FS_CALLBACK_VERBOSE
381 static char rn[] = "SRXAFSCB_GetXStats"; /*Routine name*/
382 char hostName[256]; /*Host name buffer*/
383 char *hostNameResult; /*Ptr to static*/
385 if (rxcall != (struct rx_call *)0) {
387 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
388 strcpy(hostName, hostNameResult);
389 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
390 mn, rn, hostName, rxcall->conn->peer->port);
391 } /*Valid rxcall param*/
392 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
396 } /*SRXAFSCB_GetXStats*/
398 /*------------------------------------------------------------------------
399 * EXPORTED SRXAFSCB_InitCallBackState2
402 * This routine was used in the AFS 3.5 beta release, but not anymore.
403 * It has since been replaced by SRXAFSCB_InitCallBackState3.
406 * rxcall : Ptr to Rx call on which this request came in.
409 * RXGEN_OPCODE (always).
412 * Nothing interesting.
416 *------------------------------------------------------------------------*/
418 int SRXAFSCB_InitCallBackState2(rxcall, addr)
419 struct rx_call *rxcall;
420 struct interfaceAddr * addr;
423 #if XSTAT_FS_CALLBACK_VERBOSE
424 static char rn[] = "SRXAFSCB_InitCallBackState2"; /*Routine name*/
425 char hostName[256]; /*Host name buffer*/
426 char *hostNameResult; /*Ptr to static*/
428 if (rxcall != (struct rx_call *)0) {
430 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
431 strcpy(hostName, hostNameResult);
432 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
433 mn, rn, hostName, rxcall->conn->peer->port);
434 } /*Valid rxcall param*/
435 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
439 /*------------------------------------------------------------------------
440 * EXPORTED SRXAFSCB_WhoAreYou
443 * Routine called by the server-side callback RPC interface to
444 * obtain a unique identifier for the client. The server uses
445 * this identifier to figure out whether or not two RX connections
446 * are from the same client, and to find out which addresses go
447 * with which clients.
450 * rxcall : Ptr to Rx call on which this request came in.
451 * addr: Ptr to return the list of interfaces for this client.
457 * Nothing interesting.
461 *------------------------------------------------------------------------*/
463 int SRXAFSCB_WhoAreYou(rxcall, addr)
464 struct rx_call *rxcall;
465 struct interfaceAddr *addr;
471 #if XSTAT_FS_CALLBACK_VERBOSE
472 static char rn[] = "SRXAFSCB_WhoAreYou"; /*Routine name*/
473 char hostName[256]; /*Host name buffer*/
474 char *hostNameResult; /*Ptr to static*/
476 if (rxcall != (struct rx_call *)0) {
478 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
479 strcpy(hostName, hostNameResult);
480 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
481 mn, rn, hostName, rxcall->conn->peer->port);
482 } /*Valid rxcall param*/
483 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
485 if ( rxcall && addr )
487 if (!afs_cb_inited) init_afs_cb();
488 *addr = afs_cb_interface;
492 * Return successfully.
498 /*------------------------------------------------------------------------
499 * EXPORTED SRXAFSCB_InitCallBackState3
502 * Routine called by the server-side callback RPC interface to
503 * implement clearing all callbacks from this host.
506 * rxcall : Ptr to Rx call on which this request came in.
512 * Nothing interesting.
516 *------------------------------------------------------------------------*/
518 int SRXAFSCB_InitCallBackState3(rxcall, uuidp)
519 struct rx_call *rxcall;
522 #if XSTAT_FS_CALLBACK_VERBOSE
523 static char rn[] = "SRXAFSCB_InitCallBackState3"; /*Routine name*/
524 char hostName[256]; /*Host name buffer*/
525 char *hostNameResult; /*Ptr to static*/
527 if (rxcall != (struct rx_call *)0) {
529 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
530 strcpy(hostName, hostNameResult);
531 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
532 mn, rn, hostName, rxcall->conn->peer->port);
533 } /*Valid rxcall param*/
534 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
537 * Return successfully.
543 /*------------------------------------------------------------------------
544 * EXPORTED SRXAFSCB_ProbeUuid
547 * Routine called by the server-side callback RPC interface to
548 * implement ``probing'' the Cache Manager, just making sure it's
549 * still there is still the same client it used to be.
552 * rxcall : Ptr to Rx call on which this request came in.
553 * uuidp : Ptr to UUID that must match the client's UUID.
556 * 0 if uuidp matches the UUID for this client
560 * Nothing interesting.
564 *------------------------------------------------------------------------*/
566 int SRXAFSCB_ProbeUuid(rxcall, uuidp)
567 struct rx_call *rxcall;
572 #if XSTAT_FS_CALLBACK_VERBOSE
573 static char rn[] = "SRXAFSCB_ProbeUuid"; /*Routine name*/
574 char hostName[256]; /*Host name buffer*/
575 char *hostNameResult; /*Ptr to static*/
577 if (rxcall != (struct rx_call *)0) {
579 hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
580 strcpy(hostName, hostNameResult);
581 fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
582 mn, rn, hostName, rxcall->conn->peer->port);
583 } /*Valid rxcall param*/
584 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
586 if (!afs_cb_inited) init_afs_cb();
587 if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
588 code = 1; /* failure */
592 /*------------------------------------------------------------------------
593 * EXPORTED SRXAFSCB_GetServerPrefs
596 * Routine to list server preferences used by this client.
599 * a_call : Ptr to Rx call on which this request came in.
600 * a_index : Input server index
601 * a_srvr_addr : Output server address (0xffffffff on last server)
602 * a_srvr_rank : Output server rank
605 * RXGEN_OPCODE (always)
608 * Nothing interesting.
612 *------------------------------------------------------------------------*/
614 int SRXAFSCB_GetServerPrefs(
615 struct rx_call *a_call,
617 afs_int32 *a_srvr_addr,
618 afs_int32 *a_srvr_rank)
623 /*------------------------------------------------------------------------
624 * EXPORTED SRXAFSCB_GetCellServDB
627 * Routine to list cells configured for this client
630 * a_call : Ptr to Rx call on which this request came in.
631 * a_index : Input cell index
632 * a_name : Output cell name ("" on last cell)
633 * a_hosts : Output cell database servers
639 * Nothing interesting.
643 *------------------------------------------------------------------------*/
645 int SRXAFSCB_GetCellServDB(
646 struct rx_call *a_call,
655 /*------------------------------------------------------------------------
656 * EXPORTED SRXAFSCB_GetLocalCell
659 * Routine to return name of client's local cell
662 * a_call : Ptr to Rx call on which this request came in.
663 * a_name : Output cell name
666 * RXGEN_OPCODE (always)
669 * Nothing interesting.
673 *------------------------------------------------------------------------*/
675 int SRXAFSCB_GetLocalCell(
676 struct rx_call *a_call,
681 t_name = (char *)malloc(AFSNAMEMAX);
684 strcpy(t_name, "This is xstat_fs");
690 /*------------------------------------------------------------------------
691 * EXPORTED SRXAFSCB_GetCacheConfig
694 * Routine to return parameters used to initialize client cache.
695 * Client may request any format version. Server may not return
696 * format version greater than version requested by client.
699 * a_call: Ptr to Rx call on which this request came in.
700 * callerVersion: Data format version desired by the client.
701 * serverVersion: Data format version of output data.
702 * configCount: Number bytes allocated for output data.
703 * config: Client cache configuration.
706 * RXGEN_OPCODE (always)
709 * Nothing interesting.
713 *------------------------------------------------------------------------*/
715 int SRXAFSCB_GetCacheConfig(
716 struct rx_call *a_call,
717 afs_uint32 callerVersion,
718 afs_uint32 *serverVersion,
719 afs_uint32 *configCount,