fd9ef0fe346f414d3abd11545ab2522355cb8985
[openafs.git] / src / fsprobe / fsprobe_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 fsprobe callback routines.  These are the
13  *      server-side functions that the FileServer expects to invoke on
14  *      the client machine via the afsint interface.  In this case, the
15  *      client workstation is acting as a callback listener.
16  *
17  * Environment:
18  *      The afsint server stubs expect the functions defined here to
19  *      be provided.  There is no .h file for this code, since the
20  *      linker really does all the work for us, and these don't really
21  *      need to be ``visible'' to anyone else.
22  *------------------------------------------------------------------------*/
23
24 #include <afsconfig.h>
25 #include <afs/param.h>
26
27 RCSID("$Header$");
28
29 #include <errno.h>
30 #include <stdio.h>                      /*Standard I/O stuff*/
31 #include <afs/afscbint.h>               /*Callback interface defs*/
32
33 #define FSPROBE_CALLBACK_VERBOSE 0
34
35 int afs_cb_inited = 0;
36 struct interfaceAddr afs_cb_interface;
37
38 /*
39  * Routines we need that don't have explicit include file definitions.
40  */
41 extern char *hostutil_GetNameByINet();  /*Host parsing utility*/
42
43 static char mn[] = "fsprobe_callback";  /*Module name*/
44
45 /*
46  * Initialize the callback interface structure
47  */
48 static int init_afs_cb() {
49     int count;
50
51     afs_uuid_create(&afs_cb_interface.uuid);
52     count = rx_getAllAddr(&afs_cb_interface.addr_in, AFS_MAX_INTERFACE_ADDR);
53     if ( count <= 0 )
54         afs_cb_interface.numberOfInterfaces = 0;
55     else
56         afs_cb_interface.numberOfInterfaces = count;
57     afs_cb_inited = 1;
58     return 0;
59 }
60
61
62 /*------------------------------------------------------------------------
63  * SRXAFSCB_CallBack
64  *
65  * Description:
66  *      Handle a set of callbacks from the FileServer.
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 FSPROBE_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     if (rxcall != (struct rx_call *)0) {
97       hostNameResult =
98           hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
99       strcpy(hostName, hostNameResult);
100       fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
101               mn, rn, hostName, rxcall->conn->peer->port);
102     } /*Valid rxcall param*/
103 #endif /* FSPROBE_CALLBACK_VERBOSE */
104
105     /*
106      * Return successfully.
107      */
108     return(0);
109
110 } /*SRXAFSCB_CallBack*/
111
112
113 /*------------------------------------------------------------------------
114  * SRXAFSCB_InitCallBackState
115  *
116  * Description:
117  *      Initialize callback state on this ``Cache Manager''.
118  *
119  * Arguments:
120  *      struct rx_call *rxcall  : Ptr to the associated Rx call structure.
121  *
122  * Returns:
123  *      0 on success,
124  *      Error value otherwise.
125  *
126  * Environment:
127  *      This will definitely be called by the FileServer (exactly once),
128  *      since it will think we are another new ``Cache Manager''.
129  *
130  * Side Effects:
131  *      As advertised.
132  *------------------------------------------------------------------------*/
133
134 afs_int32 SRXAFSCB_InitCallBackState(rxcall)
135     struct rx_call *rxcall;
136
137 { /*SRXAFSCB_InitCallBackState*/
138
139 #if FSPROBE_CALLBACK_VERBOSE
140     static char rn[] = "SRXAFSCB_InitCallBackState";    /*Routine name*/
141     char hostName[256];                                 /*Host name buffer*/
142     char *hostNameResult;                               /*Ptr to static*/
143
144     if (rxcall != (struct rx_call *)0) {
145       hostNameResult =
146           hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
147       strcpy(hostName, hostNameResult);
148       fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
149               mn, rn, hostName, rxcall->conn->peer->port);
150     } /*Valid rxcall param*/
151 #endif /* FSPROBE_CALLBACK_VERBOSE */
152
153     /*
154      * Return successfully.
155      */
156     return(0);
157
158 } /*SRXAFSCB_InitCallBackState*/
159
160
161 /*------------------------------------------------------------------------
162  * SRXAFSCB_Probe
163  *
164  * Description:
165  *      Respond to a probe from the FileServer.  If a FileServer doesn't
166  *      hear from you every so often, it will send you a probe to make
167  *      sure you're there, just like any other ``Cache Manager'' it's
168  *      keeping track of.
169  *
170  * Arguments:
171  *      struct rx_call *rxcall  : Ptr to the associated Rx call structure.
172  *
173  * Returns:
174  *      0 on success,
175  *      Error value otherwise.
176  *
177  * Environment:
178  *      This may be called by the FileServer if we don't call it often
179  *      enough.
180  *
181  * Side Effects:
182  *      As advertised.
183  *------------------------------------------------------------------------*/
184
185 afs_int32 SRXAFSCB_Probe(rxcall)
186         struct rx_call *rxcall;
187
188 { /*SRXAFSCB_Probe*/
189
190 #if FSPROBE_CALLBACK_VERBOSE
191     static char rn[] = "SRXAFSCB_Probe";        /*Routine name*/
192     char hostName[256];                         /*Host name buffer*/
193     char *hostNameResult;                       /*Ptr to static*/
194
195     if (rxcall != (struct rx_call *)0) {
196       hostNameResult =
197           hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
198       strcpy(hostName, hostNameResult);
199       fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
200               mn, rn, hostName, rxcall->conn->peer->port);
201     } /*Valid rxcall param*/
202 #endif /* FSPROBE_CALLBACK_VERBOSE */
203
204     /*
205      * Return successfully.
206      */
207     return(0);
208
209 } /*SRXAFSCB_Probe*/
210
211
212 /*------------------------------------------------------------------------
213  * SRXAFSCB_GetCE
214  *
215  * Description:
216  *      Respond minimally to a request for returning the contents of
217  *      a cache entry, since someone out there thinks you're a Cache
218  *      Manager.
219  *
220  * Arguments:
221  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
222  *
223  * Returns:
224  *      0 (always)
225  *
226  * Environment:
227  *      Nothing interesting.
228  *
229  * Side Effects:
230  *      As advertised.
231  *------------------------------------------------------------------------*/
232
233 afs_int32 SRXAFSCB_GetCE(rxcall)
234     struct rx_call *rxcall;
235
236 { /*SRXAFSCB_GetCE*/
237
238 #if XSTAT_FS_CALLBACK_VERBOSE
239     static char rn[] = "SRXAFSCB_GetCE";                /*Routine name*/
240     char hostName[256];                         /*Host name buffer*/
241     char *hostNameResult;                       /*Ptr to static*/
242
243     if (rxcall != (struct rx_call *)0) {
244         hostNameResult =
245             hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
246         strcpy(hostName, hostNameResult);
247         fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
248                 mn, rn, hostName, rxcall->conn->peer->port);
249     } /*Valid rxcall param*/
250 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
251
252     return(0);
253
254 } /*SRXAFSCB_GetCE*/
255
256
257 /*------------------------------------------------------------------------
258  * SRXAFSCB_GetLock
259  *
260  * Description:
261  *      Respond minimally to a request for returning the contents of
262  *      a cache lock, since someone out there thinks you're a Cache
263  *      Manager.
264  *
265  * Arguments:
266  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
267  *
268  * Returns:
269  *      0 (always)
270  *
271  * Environment:
272  *      Nothing interesting.
273  *
274  * Side Effects:
275  *      As advertised.
276  *------------------------------------------------------------------------*/
277
278 afs_int32 SRXAFSCB_GetLock(rxcall)
279     struct rx_call *rxcall;
280
281 { /*SRXAFSCB_GetLock*/
282
283 #if XSTAT_FS_CALLBACK_VERBOSE
284     static char rn[] = "SRXAFSCB_GetLock";      /*Routine name*/
285     char hostName[256];                         /*Host name buffer*/
286     char *hostNameResult;                       /*Ptr to static*/
287
288     if (rxcall != (struct rx_call *)0) {
289         hostNameResult =
290             hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
291         strcpy(hostName, hostNameResult);
292         fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
293                 mn, rn, hostName, rxcall->conn->peer->port);
294     } /*Valid rxcall param*/
295 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
296
297     return(0);
298
299 } /*SRXAFSCB_GetLock*/
300
301
302 /*------------------------------------------------------------------------
303  * SRXAFSCB_XStatsVersion
304  *
305  * Description:
306  *      Respond minimally to a request for fetching the version of
307  *      extended Cache Manager statistics offered, since someone out
308  *      there thinks you're a Cache Manager.
309  *
310  * Arguments:
311  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
312  *
313  * Returns:
314  *      0 (always)
315  *
316  * Environment:
317  *      Nothing interesting.
318  *
319  * Side Effects:
320  *      As advertised.
321  *------------------------------------------------------------------------*/
322
323 afs_int32 SRXAFSCB_XStatsVersion(rxcall)
324     struct rx_call *rxcall;
325
326 { /*SRXAFSCB_XStatsVersion*/
327
328 #if XSTAT_FS_CALLBACK_VERBOSE
329     static char rn[] = "SRXAFSCB_XStatsVersion"; /*Routine name*/
330     char hostName[256];                          /*Host name buffer*/
331     char *hostNameResult;                        /*Ptr to static*/
332
333     if (rxcall != (struct rx_call *)0) {
334         hostNameResult =
335             hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
336         strcpy(hostName, hostNameResult);
337         fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
338                 mn, rn, hostName, rxcall->conn->peer->port);
339     } /*Valid rxcall param*/
340 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
341
342     return(0);
343
344 } /*SRXAFSCB_XStatsVersion*/
345
346
347 /*------------------------------------------------------------------------
348  * SRXAFSCB_GetXStats
349  *
350  * Description:
351  *      Respond minimally to a request for returning extended
352  *      statistics for a Cache Manager, since someone out there thinks
353  *      you're a Cache Manager.
354  *
355  * Arguments:
356  *      struct rx_call *rxcall: Ptr to the associated Rx call structure.
357  *
358  * Returns:
359  *      0 (always)
360  *
361  * Environment:
362  *      Nothing interesting.
363  *
364  * Side Effects:
365  *      As advertised.
366  *------------------------------------------------------------------------*/
367
368 afs_int32 SRXAFSCB_GetXStats(rxcall)
369     struct rx_call *rxcall;
370
371 { /*SRXAFSCB_GetXStats*/
372
373 #if XSTAT_FS_CALLBACK_VERBOSE
374     static char rn[] = "SRXAFSCB_GetXStats";    /*Routine name*/
375     char hostName[256];                         /*Host name buffer*/
376     char *hostNameResult;                       /*Ptr to static*/
377
378     if (rxcall != (struct rx_call *)0) {
379         hostNameResult =
380             hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
381         strcpy(hostName, hostNameResult);
382         fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
383                 mn, rn, hostName, rxcall->conn->peer->port);
384     } /*Valid rxcall param*/
385 #endif /* XSTAT_FS_CALLBACK_VERBOSE */
386
387     return(0);
388
389 } /*SRXAFSCB_GetXStats*/
390
391 /*------------------------------------------------------------------------
392  * EXPORTED SRXAFSCB_InitCallBackState2
393  *
394  * Description:
395  *      This routine was used in the AFS 3.5 beta release, but not anymore.
396  *      It has since been replaced by SRXAFSCB_InitCallBackState3.
397  *
398  * Arguments:
399  *      rxcall : Ptr to Rx call on which this request came in.
400  *
401  * Returns:
402  *      RXGEN_OPCODE (always). 
403  *
404  * Environment:
405  *      Nothing interesting.
406  *
407  * Side Effects:
408  *      None
409  *------------------------------------------------------------------------*/
410
411 int SRXAFSCB_InitCallBackState2(rxcall, addr)
412 struct rx_call *rxcall;
413 struct interfaceAddr * addr;
414 {
415
416 #if FSPROBE_CALLBACK_VERBOSE
417     static char rn[] = "SRXAFSCB_InitCallBackState2";   /*Routine name*/
418     char hostName[256];                                 /*Host name buffer*/
419     char *hostNameResult;                               /*Ptr to static*/
420
421     if (rxcall != (struct rx_call *)0) {
422       hostNameResult =
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 /* FSPROBE_CALLBACK_VERBOSE */
429     return RXGEN_OPCODE;
430 }
431
432 /*------------------------------------------------------------------------
433  * EXPORTED SRXAFSCB_WhoAreYou
434  *
435  * Description:
436  *      Routine called by the server-side callback RPC interface to
437  *      obtain a unique identifier for the client. The server uses
438  *      this identifier to figure out whether or not two RX connections
439  *      are from the same client, and to find out which addresses go
440  *      with which clients.
441  *
442  * Arguments:
443  *      rxcall : Ptr to Rx call on which this request came in.
444  *      addr: Ptr to return the list of interfaces for this client.
445  *
446  * Returns:
447  *      0 (Always)
448  *
449  * Environment:
450  *      Nothing interesting.
451  *
452  * Side Effects:
453  *      As advertised.
454  *------------------------------------------------------------------------*/
455
456 int SRXAFSCB_WhoAreYou(rxcall, addr)
457 struct rx_call *rxcall;
458 struct interfaceAddr *addr;
459 {
460     int i;
461     int code = 0;
462     int         count;
463
464 #if FSPROBE_CALLBACK_VERBOSE
465     static char rn[] = "SRXAFSCB_WhoAreYou";            /*Routine name*/
466     char hostName[256];                                 /*Host name buffer*/
467     char *hostNameResult;                               /*Ptr to static*/
468
469     if (rxcall != (struct rx_call *)0) {
470       hostNameResult =
471           hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
472       strcpy(hostName, hostNameResult);
473       fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
474               mn, rn, hostName, rxcall->conn->peer->port);
475     } /*Valid rxcall param*/
476 #endif /* FSPROBE_CALLBACK_VERBOSE */
477
478     if ( rxcall && addr )
479     {
480         if (!afs_cb_inited) init_afs_cb();
481         *addr = afs_cb_interface;
482     }
483
484     /*
485      * Return successfully.
486      */
487     return(0);
488 }
489
490
491 /*------------------------------------------------------------------------
492  * EXPORTED SRXAFSCB_InitCallBackState3
493  *
494  * Description:
495  *      Routine called by the server-side callback RPC interface to
496  *      implement clearing all callbacks from this host.
497  *
498  * Arguments:
499  *      rxcall : Ptr to Rx call on which this request came in.
500  *
501  * Returns:
502  *      0 (always).
503  *
504  * Environment:
505  *      Nothing interesting.
506  *
507  * Side Effects:
508  *      As advertised.
509  *------------------------------------------------------------------------*/
510
511 int SRXAFSCB_InitCallBackState3(rxcall, uuidp)
512 struct rx_call *rxcall;
513 afsUUID *uuidp;
514 {
515 #if FSPROBE_CALLBACK_VERBOSE
516     static char rn[] = "SRXAFSCB_InitCallBackState2";   /*Routine name*/
517     char hostName[256];                                 /*Host name buffer*/
518     char *hostNameResult;                               /*Ptr to static*/
519
520     if (rxcall != (struct rx_call *)0) {
521       hostNameResult =
522           hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
523       strcpy(hostName, hostNameResult);
524       fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
525               mn, rn, hostName, rxcall->conn->peer->port);
526     } /*Valid rxcall param*/
527 #endif /* FSPROBE_CALLBACK_VERBOSE */
528
529     /*
530      * Return successfully.
531      */
532     return(0);
533 }
534  
535
536 /*------------------------------------------------------------------------
537  * EXPORTED SRXAFSCB_ProbeUuid
538  *
539  * Description:
540  *      Routine called by the server-side callback RPC interface to
541  *      implement ``probing'' the Cache Manager, just making sure it's
542  *      still there is still the same client it used to be.
543  *
544  * Arguments:
545  *      rxcall : Ptr to Rx call on which this request came in.
546  *      uuidp : Ptr to UUID that must match the client's UUID.
547  *
548  * Returns:
549  *      0 if uuidp matches the UUID for this client
550  *      Non-zero otherwize
551  *
552  * Environment:
553  *      Nothing interesting.
554  *
555  * Side Effects:
556  *      As advertised.
557  *------------------------------------------------------------------------*/
558
559 int SRXAFSCB_ProbeUuid(rxcall, uuidp)
560 struct rx_call *rxcall;
561 afsUUID *uuidp;
562 {
563     int code = 0;
564
565 #if FSPROBE_CALLBACK_VERBOSE
566     static char rn[] = "SRXAFSCB_ProbeUuid";            /*Routine name*/
567     char hostName[256];                                 /*Host name buffer*/
568     char *hostNameResult;                               /*Ptr to static*/
569
570     if (rxcall != (struct rx_call *)0) {
571       hostNameResult =
572           hostutil_GetNameByINet((afs_int32)(rxcall->conn->peer->host));
573       strcpy(hostName, hostNameResult);
574       fprintf(stderr, "[%s:%s] Called from host %s, port %d\n",
575               mn, rn, hostName, rxcall->conn->peer->port);
576     } /*Valid rxcall param*/
577 #endif /* FSPROBE_CALLBACK_VERBOSE */
578
579     if (!afs_cb_inited) init_afs_cb();
580     if (!afs_uuid_equal(uuidp, &afs_cb_interface.uuid))
581         code = 1; /* failure */
582     return code;
583 }
584
585 /*------------------------------------------------------------------------
586  * EXPORTED SRXAFSCB_GetServerPrefs
587  *
588  * Description:
589  *      Routine to list server preferences used by this client.
590  *
591  * Arguments:
592  *      a_call  : Ptr to Rx call on which this request came in.
593  *      a_index : Input server index
594  *      a_srvr_addr  : Output server address (0xffffffff on last server)
595  *      a_srvr_rank  : Output server rank
596  *
597  * Returns:
598  *      0 on success
599  *
600  * Environment:
601  *      Nothing interesting.
602  *
603  * Side Effects:
604  *      As advertised.
605  *------------------------------------------------------------------------*/
606
607 int SRXAFSCB_GetServerPrefs(
608     struct rx_call *a_call,
609     afs_int32 a_index,
610     afs_int32 *a_srvr_addr,
611     afs_int32 *a_srvr_rank)
612 {
613     *a_srvr_addr = 0xffffffff;
614     *a_srvr_rank = 0xffffffff;
615     return 0;
616 }
617
618 /*------------------------------------------------------------------------
619  * EXPORTED SRXAFSCB_GetCellServDB
620  *
621  * Description:
622  *      Routine to list cells configured for this client
623  *
624  * Arguments:
625  *      a_call  : Ptr to Rx call on which this request came in.
626  *      a_index : Input cell index
627  *      a_name  : Output cell name ("" on last cell)
628  *      a_hosts : Output cell database servers
629  *
630  * Returns:
631  *      RXGEN_OPCODE   (always)
632  *
633  * Environment:
634  *      Nothing interesting.
635  *
636  * Side Effects:
637  *      As advertised.
638  *------------------------------------------------------------------------*/
639
640 int SRXAFSCB_GetCellServDB(
641     struct rx_call *a_call,
642     afs_int32 a_index,
643     char **a_name,
644     afs_int32 *a_hosts)
645 {
646     return RXGEN_OPCODE;
647 }
648
649 /*------------------------------------------------------------------------
650  * EXPORTED SRXAFSCB_GetLocalCell
651  *
652  * Description:
653  *      Routine to return name of client's local cell
654  *
655  * Arguments:
656  *      a_call  : Ptr to Rx call on which this request came in.
657  *      a_name  : Output cell name
658  *
659  * Returns:
660  *      RXGEN_OPCODE   (always)
661  *
662  * Environment:
663  *      Nothing interesting.
664  *
665  * Side Effects:
666  *      As advertised.
667  *------------------------------------------------------------------------*/
668
669 int SRXAFSCB_GetLocalCell(
670     struct rx_call *a_call,
671     char **a_name)
672 {
673     return RXGEN_OPCODE;
674 }
675
676
677 /*------------------------------------------------------------------------
678  * EXPORTED SRXAFSCB_GetCacheConfig
679  *
680  * Description:
681  *      Routine to return parameters used to initialize client cache.
682  *      Client may request any format version. Server may not return
683  *      format version greater than version requested by client.
684  *
685  * Arguments:
686  *      a_call:        Ptr to Rx call on which this request came in.
687  *      callerVersion: Data format version desired by the client.
688  *      serverVersion: Data format version of output data.
689  *      configCount:   Number bytes allocated for output data.
690  *      config:        Client cache configuration.
691  *
692  * Returns:
693  *      RXGEN_OPCODE   (always)
694  *
695  * Environment:
696  *      Nothing interesting.
697  *
698  * Side Effects:
699  *      As advertised.
700  *------------------------------------------------------------------------*/
701
702 int SRXAFSCB_GetCacheConfig(
703     struct rx_call *a_call,
704     afs_uint32 callerVersion,
705     afs_uint32 *serverVersion,
706     afs_uint32 *configCount,
707     cacheConfig *config)
708 {
709     return RXGEN_OPCODE;
710 }