a66e30b2e74f94343b0ae708b02fa03114364db7
[openafs.git] / src / xstat / xstat_fs_callback.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /*
11  * Description:
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.
17  *
18  * Environment:
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  *------------------------------------------------------------------------*/
24
25 #include <afsconfig.h>
26 #include <afs/param.h>
27
28 RCSID("$Header$");
29
30 #include <errno.h>
31 #include <stdio.h>                      /*Standard I/O stuff*/
32 #include <afs/afscbint.h>               /*Callback interface defs*/
33
34 int afs_cb_inited = 0;
35 struct interfaceAddr afs_cb_interface;
36
37 #define XSTAT_FS_CALLBACK_VERBOSE 0
38
39 /*
40  * Initialize the callback interface structure
41  */
42 static int init_afs_cb() {
43     int count;
44
45     afs_uuid_create(&afs_cb_interface.uuid);
46     count = rx_getAllAddr(&afs_cb_interface.addr_in, AFS_MAX_INTERFACE_ADDR);
47     if ( count <= 0 )
48         afs_cb_interface.numberOfInterfaces = 0;
49     else
50         afs_cb_interface.numberOfInterfaces = count;
51     afs_cb_inited = 1;
52     return 0;
53 }
54
55 /*
56  * Routines we need that don't have explicit include file definitions.
57  */
58 extern char *hostutil_GetNameByINet();  /*Host parsing utility*/
59
60 static char mn[] = "xstat_fs_callback"; /*Module name*/
61
62 /*------------------------------------------------------------------------
63  * SRXAFSCB_CallBack
64  *
65  * Description:
66  *      Handle a set of callbacks from the File Server.
67  *
68  * Arguments:
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.
72  *
73  * Returns:
74  *      0 on success,
75  *      Error value otherwise.
76  *
77  * Environment:
78  *      Nothing interesting.
79  *
80  * Side Effects:
81  *      As advertised.
82  *------------------------------------------------------------------------*/
83
84 afs_int32 SRXAFSCB_CallBack(rxcall, Fids_Array, CallBack_Array)
85     struct rx_call *rxcall;
86     AFSCBFids *Fids_Array;
87     AFSCBs *CallBack_Array;
88
89 { /*SRXAFSCB_CallBack*/
90
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*/
95
96     fprintf(stderr, "[%s:%s] Called\n",
97             mn, rn);
98
99     if (rxcall != (struct rx_call *)0) {
100         hostNameResult =
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 */
107
108     /*
109      * Return successfully.
110      */
111     return(0);
112
113 } /*SRXAFSCB_CallBack*/
114
115 /*------------------------------------------------------------------------
116  * SRXAFSCB_InitCallBackState
117  *
118  * Description:
119  *      Initialize callback state on this ``Cache Manager''.
120  *
121  * Arguments:
122  *      struct rx_call *rxcall  : Ptr to the associated Rx call structure.
123  *
124  * Returns:
125  *      0 on success,
126  *      Error value otherwise.
127  *
128  * Environment:
129  *      This will definitely be called by the File Server (exactly once),
130  *      since it will think we are another new ``Cache Manager''.
131  *
132  * Side Effects:
133  *      As advertised.
134  *------------------------------------------------------------------------*/
135
136 afs_int32 SRXAFSCB_InitCallBackState(rxcall)
137     struct rx_call *rxcall;
138
139 { /*SRXAFSCB_InitCallBackState*/
140
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*/
145
146     fprintf(stderr, "[%s:%s] Called\n",
147             mn, rn);
148
149     if (rxcall != (struct rx_call *)0) {
150         hostNameResult =
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 */
157
158     /*
159      * Return successfully.
160      */
161     return(0);
162
163 } /*SRXAFSCB_InitCallBackState*/
164
165 /*------------------------------------------------------------------------
166  * SRXAFSCB_Probe
167  *
168  * Description:
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.
173  *
174  * Arguments:
175  *      struct rx_call *rxcall  : Ptr to the associated Rx call structure.
176  *
177  * Returns:
178  *      0 on success,
179  *      Error value otherwise.
180  *
181  * Environment:
182  *      This may be called by the File Server if we don't call it often
183  *      enough.
184  *
185  * Side Effects:
186  *      As advertised.
187  *------------------------------------------------------------------------*/
188
189 afs_int32 SRXAFSCB_Probe(rxcall)
190         struct rx_call *rxcall;
191
192 { /*SRXAFSCB_Probe*/
193
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*/
198
199     fprintf(stderr, "[%s:%s] Called\n",
200             mn, rn);
201
202     if (rxcall != (struct rx_call *)0) {
203         hostNameResult =
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 */
210
211     /*
212      * Return successfully.
213      */
214     return(0);
215
216 } /*SRXAFSCB_Probe*/
217
218
219 /*------------------------------------------------------------------------
220  * SRXAFSCB_GetCE
221  *
222  * Description:
223  *      Respond minimally to a request for returning the contents of
224  *      a cache entry, since someone out there thinks you're a Cache
225  *      Manager.
226  *
227  * Arguments:
228  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
229  *
230  * Returns:
231  *      0 (always)
232  *
233  * Environment:
234  *      Nothing interesting.
235  *
236  * Side Effects:
237  *      As advertised.
238  *------------------------------------------------------------------------*/
239
240 afs_int32 SRXAFSCB_GetCE(rxcall)
241     struct rx_call *rxcall;
242
243 { /*SRXAFSCB_GetCE*/
244
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*/
249
250     if (rxcall != (struct rx_call *)0) {
251         hostNameResult =
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 */
258
259     return(0);
260
261 } /*SRXAFSCB_GetCE*/
262
263
264 /*------------------------------------------------------------------------
265  * SRXAFSCB_GetLock
266  *
267  * Description:
268  *      Respond minimally to a request for returning the contents of
269  *      a cache lock, since someone out there thinks you're a Cache
270  *      Manager.
271  *
272  * Arguments:
273  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
274  *
275  * Returns:
276  *      0 (always)
277  *
278  * Environment:
279  *      Nothing interesting.
280  *
281  * Side Effects:
282  *      As advertised.
283  *------------------------------------------------------------------------*/
284
285 afs_int32 SRXAFSCB_GetLock(rxcall)
286     struct rx_call *rxcall;
287
288 { /*SRXAFSCB_GetLock*/
289
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*/
294
295     if (rxcall != (struct rx_call *)0) {
296         hostNameResult =
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 */
303
304     return(0);
305
306 } /*SRXAFSCB_GetLock*/
307
308
309 /*------------------------------------------------------------------------
310  * SRXAFSCB_XStatsVersion
311  *
312  * Description:
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.
316  *
317  * Arguments:
318  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
319  *
320  * Returns:
321  *      0 (always)
322  *
323  * Environment:
324  *      Nothing interesting.
325  *
326  * Side Effects:
327  *      As advertised.
328  *------------------------------------------------------------------------*/
329
330 afs_int32 SRXAFSCB_XStatsVersion(rxcall)
331     struct rx_call *rxcall;
332
333 { /*SRXAFSCB_XStatsVersion*/
334
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*/
339
340     if (rxcall != (struct rx_call *)0) {
341         hostNameResult =
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 */
348
349     return(0);
350
351 } /*SRXAFSCB_XStatsVersion*/
352
353
354 /*------------------------------------------------------------------------
355  * SRXAFSCB_GetXStats
356  *
357  * Description:
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.
361  *
362  * Arguments:
363  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
364  *
365  * Returns:
366  *      0 (always)
367  *
368  * Environment:
369  *      Nothing interesting.
370  *
371  * Side Effects:
372  *      As advertised.
373  *------------------------------------------------------------------------*/
374
375 afs_int32 SRXAFSCB_GetXStats(rxcall)
376     struct rx_call *rxcall;
377
378 { /*SRXAFSCB_GetXStats*/
379
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*/
384
385     if (rxcall != (struct rx_call *)0) {
386         hostNameResult =
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 */
393
394     return(0);
395
396 } /*SRXAFSCB_GetXStats*/
397
398 /*------------------------------------------------------------------------
399  * EXPORTED SRXAFSCB_InitCallBackState2
400  *
401  * Description:
402  *      This routine was used in the AFS 3.5 beta release, but not anymore.
403  *      It has since been replaced by SRXAFSCB_InitCallBackState3.
404  *
405  * Arguments:
406  *      rxcall : Ptr to Rx call on which this request came in.
407  *
408  * Returns:
409  *      RXGEN_OPCODE (always). 
410  *
411  * Environment:
412  *      Nothing interesting.
413  *
414  * Side Effects:
415  *      None
416  *------------------------------------------------------------------------*/
417
418 int SRXAFSCB_InitCallBackState2(rxcall, addr)
419 struct rx_call *rxcall;
420 struct interfaceAddr * addr;
421 {
422
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*/
427
428     if (rxcall != (struct rx_call *)0) {
429       hostNameResult =
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 */
436     return RXGEN_OPCODE;
437 }
438
439 /*------------------------------------------------------------------------
440  * EXPORTED SRXAFSCB_WhoAreYou
441  *
442  * Description:
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.
448  *
449  * Arguments:
450  *      rxcall : Ptr to Rx call on which this request came in.
451  *      addr: Ptr to return the list of interfaces for this client.
452  *
453  * Returns:
454  *      0 (Always)
455  *
456  * Environment:
457  *      Nothing interesting.
458  *
459  * Side Effects:
460  *      As advertised.
461  *------------------------------------------------------------------------*/
462
463 int SRXAFSCB_WhoAreYou(rxcall, addr)
464 struct rx_call *rxcall;
465 struct interfaceAddr *addr;
466 {
467     int i;
468     int code = 0;
469     int         count;
470
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*/
475
476     if (rxcall != (struct rx_call *)0) {
477       hostNameResult =
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 */
484
485     if ( rxcall && addr )
486     {
487         if (!afs_cb_inited) init_afs_cb();
488         *addr = afs_cb_interface;
489     }
490
491     /*
492      * Return successfully.
493      */
494     return(0);
495 }
496
497
498 /*------------------------------------------------------------------------
499  * EXPORTED SRXAFSCB_InitCallBackState3
500  *
501  * Description:
502  *      Routine called by the server-side callback RPC interface to
503  *      implement clearing all callbacks from this host.
504  *
505  * Arguments:
506  *      rxcall : Ptr to Rx call on which this request came in.
507  *
508  * Returns:
509  *      0 (always).
510  *
511  * Environment:
512  *      Nothing interesting.
513  *
514  * Side Effects:
515  *      As advertised.
516  *------------------------------------------------------------------------*/
517
518 int SRXAFSCB_InitCallBackState3(rxcall, uuidp)
519 struct rx_call *rxcall;
520 afsUUID *uuidp;
521 {
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*/
526
527     if (rxcall != (struct rx_call *)0) {
528       hostNameResult =
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 */
535
536     /*
537      * Return successfully.
538      */
539     return(0);
540 }
541  
542
543 /*------------------------------------------------------------------------
544  * EXPORTED SRXAFSCB_ProbeUuid
545  *
546  * Description:
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.
550  *
551  * Arguments:
552  *      rxcall : Ptr to Rx call on which this request came in.
553  *      uuidp : Ptr to UUID that must match the client's UUID.
554  *
555  * Returns:
556  *      0 if uuidp matches the UUID for this client
557  *      Non-zero otherwize
558  *
559  * Environment:
560  *      Nothing interesting.
561  *
562  * Side Effects:
563  *      As advertised.
564  *------------------------------------------------------------------------*/
565
566 int SRXAFSCB_ProbeUuid(rxcall, uuidp)
567 struct rx_call *rxcall;
568 afsUUID *uuidp;
569 {
570     int code = 0;
571
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*/
576
577     if (rxcall != (struct rx_call *)0) {
578       hostNameResult =
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 */
585
586     if (!afs_cb_inited) init_afs_cb();
587     if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
588         code = 1; /* failure */
589     return code;
590 }
591
592 /*------------------------------------------------------------------------
593  * EXPORTED SRXAFSCB_GetServerPrefs
594  *
595  * Description:
596  *      Routine to list server preferences used by this client.
597  *
598  * Arguments:
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
603  *
604  * Returns:
605  *      RXGEN_OPCODE   (always)
606  *
607  * Environment:
608  *      Nothing interesting.
609  *
610  * Side Effects:
611  *      As advertised.
612  *------------------------------------------------------------------------*/
613
614 int SRXAFSCB_GetServerPrefs(
615     struct rx_call *a_call,
616     afs_int32 a_index,
617     afs_int32 *a_srvr_addr,
618     afs_int32 *a_srvr_rank)
619 {
620     return RXGEN_OPCODE;
621 }
622
623 /*------------------------------------------------------------------------
624  * EXPORTED SRXAFSCB_GetCellServDB
625  *
626  * Description:
627  *      Routine to list cells configured for this client
628  *
629  * Arguments:
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
634  *
635  * Returns:
636  *      0 on success
637  *
638  * Environment:
639  *      Nothing interesting.
640  *
641  * Side Effects:
642  *      As advertised.
643  *------------------------------------------------------------------------*/
644
645 int SRXAFSCB_GetCellServDB(
646     struct rx_call *a_call,
647     afs_int32 a_index,
648     char **a_name,
649     afs_int32 *a_hosts)
650 {
651     return RXGEN_OPCODE;
652 }
653
654
655 /*------------------------------------------------------------------------
656  * EXPORTED SRXAFSCB_GetLocalCell
657  *
658  * Description:
659  *      Routine to return name of client's local cell
660  *
661  * Arguments:
662  *      a_call  : Ptr to Rx call on which this request came in.
663  *      a_name  : Output cell name
664  *
665  * Returns:
666  *      RXGEN_OPCODE   (always)
667  *
668  * Environment:
669  *      Nothing interesting.
670  *
671  * Side Effects:
672  *      As advertised.
673  *------------------------------------------------------------------------*/
674
675 int SRXAFSCB_GetLocalCell(
676     struct rx_call *a_call,
677     char **a_name)
678 {
679     char *t_name;
680
681     t_name = (char *)malloc(AFSNAMEMAX);
682     if (!t_name)
683         return ENOMEM;
684     strcpy(t_name, "This is xstat_fs");
685     *a_name = t_name;
686     return 0;
687 }
688
689
690 /*------------------------------------------------------------------------
691  * EXPORTED SRXAFSCB_GetCacheConfig
692  *
693  * Description:
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.
697  *
698  * Arguments:
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.
704  *
705  * Returns:
706  *      RXGEN_OPCODE   (always)
707  *
708  * Environment:
709  *      Nothing interesting.
710  *
711  * Side Effects:
712  *      As advertised.
713  *------------------------------------------------------------------------*/
714
715 int SRXAFSCB_GetCacheConfig(
716     struct rx_call *a_call,
717     afs_uint32 callerVersion,
718     afs_uint32 *serverVersion,
719     afs_uint32 *configCount,
720     cacheConfig *config)
721 {
722     return RXGEN_OPCODE;
723 }