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 * Exported routines (and their private support) to implement
13 * the callback RPC interface.
16 #include <afsconfig.h>
17 #include "afs/param.h"
20 #include "afs/sysincludes.h" /*Standard vendor system headers */
21 #include "afsincludes.h" /*AFS-based standard headers */
22 #include "afs/afs_stats.h" /*Cache Manager stats */
23 #include "afs/afs_args.h"
25 afs_int32 afs_allCBs = 0; /*Break callbacks on all objects */
26 afs_int32 afs_oddCBs = 0; /*Break callbacks on dirs */
27 afs_int32 afs_evenCBs = 0; /*Break callbacks received on files */
28 afs_int32 afs_allZaps = 0; /*Objects entries deleted */
29 afs_int32 afs_oddZaps = 0; /*Dir cache entries deleted */
30 afs_int32 afs_evenZaps = 0; /*File cache entries deleted */
31 afs_int32 afs_connectBacks = 0;
34 * Some debugging aids.
36 static struct ltable {
41 "afs_xvcache", (char *)&afs_xvcache}, {
42 "afs_xdcache", (char *)&afs_xdcache}, {
43 "afs_xserver", (char *)&afs_xserver}, {
44 "afs_xvcb", (char *)&afs_xvcb}, {
45 "afs_xbrs", (char *)&afs_xbrs}, {
46 "afs_xcell", (char *)&afs_xcell}, {
47 "afs_xconn", (char *)&afs_xconn}, {
48 "afs_xuser", (char *)&afs_xuser}, {
49 "afs_xvolume", (char *)&afs_xvolume}, {
50 "puttofile", (char *)&afs_puttofileLock}, {
51 "afs_ftf", (char *)&afs_ftf}, {
52 "afs_xcbhash", (char *)&afs_xcbhash}, {
53 "afs_xaxs", (char *)&afs_xaxs}, {
54 "afs_xinterface", (char *)&afs_xinterface},
57 "afs_xosi", (char *)&afs_xosi},
60 "afs_xsrvAddr", (char *)&afs_xsrvAddr},
62 "afs_xvreclaim", (char *)&afs_xvreclaim},
63 { "afsdb_client_lock", (char *)&afsdb_client_lock},
64 { "afsdb_req_lock", (char *)&afsdb_req_lock},
65 { "afs_discon_lock", (char *)&afs_discon_lock},
66 { "afs_disconDirtyLock", (char *)&afs_disconDirtyLock},
67 { "afs_discon_vc_dirty", (char *)&afs_xvcdirty},
69 unsigned long lastCallBack_vnode;
70 unsigned int lastCallBack_dv;
71 osi_timeval_t lastCallBack_time;
73 /* these are for storing alternate interface addresses */
74 struct interfaceAddr afs_cb_interface;
76 /*------------------------------------------------------------------------
77 * EXPORTED SRXAFSCB_GetCE
80 * Routine called by the server-side callback RPC interface to
81 * implement pulling out the contents of the i'th cache entry.
84 * a_call : Ptr to Rx call on which this request came in.
85 * a_index : Index of desired cache entry.
86 * a_result : Ptr to a buffer for the given cache entry.
89 * 0 if everything went fine,
90 * 1 if we were given a bad index.
93 * Nothing interesting.
97 *------------------------------------------------------------------------*/
100 SRXAFSCB_GetCE(struct rx_call *a_call, afs_int32 a_index,
101 struct AFSDBCacheEntry *a_result)
104 int i; /*Loop variable */
105 struct vcache *tvc; /*Ptr to current cache entry */
106 int code; /*Return code */
111 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE);
113 AFS_STATCNT(SRXAFSCB_GetCE);
114 for (i = 0; i < VCSIZE; i++) {
115 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
119 } /*Zip through current hash chain */
120 } /*Zip through hash chains */
130 * Copy out the located entry.
132 a_result->addr = afs_data_pointer_to_int32(tvc);
133 a_result->cell = tvc->f.fid.Cell;
134 a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
135 a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
136 a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
137 a_result->lock.waitStates = tvc->lock.wait_states;
138 a_result->lock.exclLocked = tvc->lock.excl_locked;
139 a_result->lock.readersReading = tvc->lock.readers_reading;
140 a_result->lock.numWaiting = tvc->lock.num_waiting;
141 #if defined(INSTRUMENT_LOCKS)
142 a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
143 a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
144 a_result->lock.src_indicator = tvc->lock.src_indicator;
146 /* On osf20 , the vcache does not maintain these three fields */
147 a_result->lock.pid_last_reader = 0;
148 a_result->lock.pid_writer = 0;
149 a_result->lock.src_indicator = 0;
150 #endif /* INSTRUMENT_LOCKS */
151 #ifdef AFS_64BIT_CLIENT
152 a_result->Length = (afs_int32) tvc->f.m.Length & 0xffffffff;
153 #else /* AFS_64BIT_CLIENT */
154 a_result->Length = tvc->f.m.Length;
155 #endif /* AFS_64BIT_CLIENT */
156 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
157 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
158 a_result->cbExpires = tvc->cbExpires;
159 if (tvc->f.states & CVInit) {
160 a_result->refCount = 1;
162 #ifdef AFS_DARWIN80_ENV
163 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
165 a_result->refCount = VREFCOUNT(tvc);
168 a_result->opens = tvc->opens;
169 a_result->writers = tvc->execsOrWriters;
170 a_result->mvstat = tvc->mvstat;
171 a_result->states = tvc->f.states;
175 * Return our results.
184 } /*SRXAFSCB_GetCE */
187 SRXAFSCB_GetCE64(struct rx_call *a_call, afs_int32 a_index,
188 struct AFSDBCacheEntry64 *a_result)
190 int i; /*Loop variable */
191 struct vcache *tvc; /*Ptr to current cache entry */
192 int code; /*Return code */
197 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE);
199 AFS_STATCNT(SRXAFSCB_GetCE64);
200 for (i = 0; i < VCSIZE; i++) {
201 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
205 } /*Zip through current hash chain */
206 } /*Zip through hash chains */
216 * Copy out the located entry.
218 a_result->addr = afs_data_pointer_to_int32(tvc);
219 a_result->cell = tvc->f.fid.Cell;
220 a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
221 a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
222 a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
223 a_result->lock.waitStates = tvc->lock.wait_states;
224 a_result->lock.exclLocked = tvc->lock.excl_locked;
225 a_result->lock.readersReading = tvc->lock.readers_reading;
226 a_result->lock.numWaiting = tvc->lock.num_waiting;
227 #if defined(INSTRUMENT_LOCKS)
228 a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
229 a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
230 a_result->lock.src_indicator = tvc->lock.src_indicator;
232 /* On osf20 , the vcache does not maintain these three fields */
233 a_result->lock.pid_last_reader = 0;
234 a_result->lock.pid_writer = 0;
235 a_result->lock.src_indicator = 0;
236 #endif /* INSTRUMENT_LOCKS */
237 a_result->Length = tvc->f.m.Length;
238 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
239 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
240 a_result->cbExpires = tvc->cbExpires;
241 if (tvc->f.states & CVInit) {
242 a_result->refCount = 1;
244 #ifdef AFS_DARWIN80_ENV
245 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
247 a_result->refCount = VREFCOUNT(tvc);
250 a_result->opens = tvc->opens;
251 a_result->writers = tvc->execsOrWriters;
252 a_result->mvstat = tvc->mvstat;
253 a_result->states = tvc->f.states;
257 * Return our results.
266 } /*SRXAFSCB_GetCE64 */
269 /*------------------------------------------------------------------------
270 * EXPORTED SRXAFSCB_GetLock
273 * Routine called by the server-side callback RPC interface to
274 * implement pulling out the contents of a lock in the lock
278 * a_call : Ptr to Rx call on which this request came in.
279 * a_index : Index of desired lock.
280 * a_result : Ptr to a buffer for the given lock.
283 * 0 if everything went fine,
284 * 1 if we were given a bad index.
287 * Nothing interesting.
291 *------------------------------------------------------------------------*/
294 SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index,
295 struct AFSDBLock *a_result)
297 struct ltable *tl; /*Ptr to lock table entry */
298 int nentries; /*Num entries in table */
299 int code; /*Return code */
304 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETLOCK);
306 AFS_STATCNT(SRXAFSCB_GetLock);
307 nentries = sizeof(ltable) / sizeof(struct ltable);
308 if (a_index < 0 || a_index >= nentries+afs_cellindex) {
313 } else if (a_index >= nentries) {
314 struct cell *tc = afs_GetCellByIndex(a_index-nentries, 0);
315 strcpy(a_result->name, tc->cellName);
316 a_result->lock.waitStates =
317 ((struct afs_lock *)&(tc->lock))->wait_states;
318 a_result->lock.exclLocked =
319 ((struct afs_lock *)&(tc->lock))->excl_locked;
320 a_result->lock.readersReading =
321 ((struct afs_lock *)&(tc->lock))->readers_reading;
322 a_result->lock.numWaiting =
323 ((struct afs_lock *)&(tc->lock))->num_waiting;
324 #ifdef INSTRUMENT_LOCKS
325 a_result->lock.pid_last_reader =
326 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_last_reader);
327 a_result->lock.pid_writer =
328 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_writer);
329 a_result->lock.src_indicator =
330 ((struct afs_lock *)&(tc->lock))->src_indicator;
332 a_result->lock.pid_last_reader = 0;
333 a_result->lock.pid_writer = 0;
334 a_result->lock.src_indicator = 0;
339 * Found it - copy out its contents.
341 tl = <able[a_index];
342 strcpy(a_result->name, tl->name);
343 a_result->lock.waitStates =
344 ((struct afs_lock *)(tl->addr))->wait_states;
345 a_result->lock.exclLocked =
346 ((struct afs_lock *)(tl->addr))->excl_locked;
347 a_result->lock.readersReading =
348 ((struct afs_lock *)(tl->addr))->readers_reading;
349 a_result->lock.numWaiting =
350 ((struct afs_lock *)(tl->addr))->num_waiting;
351 #ifdef INSTRUMENT_LOCKS
352 a_result->lock.pid_last_reader =
353 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_last_reader);
354 a_result->lock.pid_writer =
355 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_writer);
356 a_result->lock.src_indicator =
357 ((struct afs_lock *)(tl->addr))->src_indicator;
359 a_result->lock.pid_last_reader = 0;
360 a_result->lock.pid_writer = 0;
361 a_result->lock.src_indicator = 0;
372 } /*SRXAFSCB_GetLock */
375 /*------------------------------------------------------------------------
376 * static ClearCallBack
379 * Clear out callback information for the specified file, or
380 * even a whole volume. Used to worry about callback was from
381 * within the particular cell or not. Now we don't bother with
382 * that anymore; it's not worth the time.
385 * a_conn : Ptr to Rx connection involved.
386 * a_fid : Ptr to AFS fid being cleared.
392 * Nothing interesting.
397 Appears to need to be called with GLOCK held, as the icl_Event4 stuff asserts otherwise
399 *------------------------------------------------------------------------*/
402 ClearCallBack(struct rx_connection *a_conn,
403 struct AFSFid *a_fid)
407 struct VenusFid localFid;
409 #ifdef AFS_DARWIN80_ENV
413 AFS_STATCNT(ClearCallBack);
418 * XXXX Don't hold any server locks here because of callback protocol XXX
421 localFid.Fid.Volume = a_fid->Volume;
422 localFid.Fid.Vnode = a_fid->Vnode;
423 localFid.Fid.Unique = a_fid->Unique;
426 * Volume ID of zero means don't do anything.
428 if (a_fid->Volume != 0) {
429 if (a_fid->Vnode == 0) {
430 struct afs_q *tq, *uq;
432 * Clear callback for the whole volume. Zip through the
433 * hash chain, nullifying entries whose volume ID matches.
436 ObtainReadLock(&afs_xvcache);
437 i = VCHashV(&localFid);
438 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
441 if (tvc->f.fid.Fid.Volume == a_fid->Volume) {
442 tvc->callback = NULL;
444 localFid.Cell = tvc->f.fid.Cell;
445 tvc->dchint = NULL; /* invalidate hints */
446 if (tvc->f.states & CVInit) {
447 ReleaseReadLock(&afs_xvcache);
448 afs_osi_Sleep(&tvc->f.states);
451 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
454 #ifdef AFS_DARWIN80_ENV
455 if (tvc->f.states & CDeadVnode) {
456 if (!(tvc->f.states & CBulkFetching)) {
457 ReleaseReadLock(&afs_xvcache);
458 afs_osi_Sleep(&tvc->f.states);
471 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
473 vnode_recycle(AFSTOV(tvc));
480 ReleaseReadLock(&afs_xvcache);
481 ObtainWriteLock(&afs_xcbhash, 449);
482 afs_DequeueCallback(tvc);
483 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
485 if (tvc->f.fid.Fid.Vnode & 1)
489 ReleaseWriteLock(&afs_xcbhash);
490 if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
491 osi_dnlc_purgedp(tvc);
492 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
493 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
494 tvc->f.states, ICL_TYPE_INT32,
496 #ifdef AFS_DARWIN80_ENV
497 vnode_put(AFSTOV(tvc));
499 ObtainReadLock(&afs_xvcache);
502 } else if ((tvc->f.states & CMValid)
503 && (tvc->mvid->Fid.Volume == a_fid->Volume)) {
504 tvc->f.states &= ~CMValid;
506 localFid.Cell = tvc->mvid->Cell;
509 ReleaseReadLock(&afs_xvcache);
512 * XXXX Don't hold any locks here XXXX
514 tv = afs_FindVolume(&localFid, 0);
516 afs_ResetVolumeInfo(tv);
517 afs_PutVolume(tv, 0);
518 /* invalidate mtpoint? */
520 } /*Clear callbacks for whole volume */
523 * Clear callbacks just for the one file.
527 if (a_fid->Vnode & 1)
528 afs_oddCBs++; /*Could do this on volume basis, too */
530 afs_evenCBs++; /*A particular fid was specified */
532 ObtainReadLock(&afs_xvcache);
533 i = VCHash(&localFid);
534 for (tvc = afs_vhashT[i]; tvc; tvc = uvc) {
536 if (tvc->f.fid.Fid.Vnode == a_fid->Vnode
537 && tvc->f.fid.Fid.Volume == a_fid->Volume
538 && tvc->f.fid.Fid.Unique == a_fid->Unique) {
539 tvc->callback = NULL;
540 tvc->dchint = NULL; /* invalidate hints */
541 if (tvc->f.states & CVInit) {
542 ReleaseReadLock(&afs_xvcache);
543 afs_osi_Sleep(&tvc->f.states);
546 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
549 #ifdef AFS_DARWIN80_ENV
550 if (tvc->f.states & CDeadVnode) {
551 if (!(tvc->f.states & CBulkFetching)) {
552 ReleaseReadLock(&afs_xvcache);
553 afs_osi_Sleep(&tvc->f.states);
566 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
568 vnode_recycle(AFSTOV(tvc));
575 ReleaseReadLock(&afs_xvcache);
576 ObtainWriteLock(&afs_xcbhash, 450);
577 afs_DequeueCallback(tvc);
578 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
579 ReleaseWriteLock(&afs_xcbhash);
580 if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
581 osi_dnlc_purgedp(tvc);
582 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
583 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
584 tvc->f.states, ICL_TYPE_LONG, 0);
586 lastCallBack_vnode = afid->Vnode;
587 lastCallBack_dv = tvc->mstat.DataVersion.low;
588 osi_GetuTime(&lastCallBack_time);
590 #ifdef AFS_DARWIN80_ENV
591 vnode_put(AFSTOV(tvc));
593 ObtainReadLock(&afs_xvcache);
597 } /*Walk through hash table */
598 ReleaseReadLock(&afs_xvcache);
599 } /*Clear callbacks for one file */
602 /*Fid has non-zero volume ID */
604 * Always return a predictable value.
611 /*------------------------------------------------------------------------
612 * EXPORTED SRXAFSCB_CallBack
615 * Routine called by the server-side callback RPC interface to
616 * implement passing in callback information.
620 * a_call : Ptr to Rx call on which this request came in.
621 * a_fids : Ptr to array of fids involved.
622 * a_callbacks : Ptr to matching callback info for the fids.
628 * Nothing interesting.
632 *------------------------------------------------------------------------*/
635 SRXAFSCB_CallBack(struct rx_call *a_call, struct AFSCBFids *a_fids,
636 struct AFSCBs *a_callbacks)
638 int i; /*Loop variable */
639 struct AFSFid *tfid; /*Ptr to current fid */
640 struct rx_connection *tconn; /*Call's connection */
646 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_CALLBACK);
648 AFS_STATCNT(SRXAFSCB_CallBack);
649 if (!(tconn = rx_ConnectionOf(a_call)))
651 tfid = (struct AFSFid *)a_fids->AFSCBFids_val;
654 * For now, we ignore callbacks, since the File Server only *breaks*
655 * callbacks at present.
657 for (i = 0; i < a_fids->AFSCBFids_len; i++)
658 ClearCallBack(tconn, &tfid[i]);
666 } /*SRXAFSCB_CallBack */
669 /*------------------------------------------------------------------------
670 * EXPORTED SRXAFSCB_Probe
673 * Routine called by the server-side callback RPC interface to
674 * implement ``probing'' the Cache Manager, just making sure it's
678 * a_call : Ptr to Rx call on which this request came in.
684 * Nothing interesting.
688 *------------------------------------------------------------------------*/
691 SRXAFSCB_Probe(struct rx_call *a_call)
697 AFS_STATCNT(SRXAFSCB_Probe);
699 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
706 } /*SRXAFSCB_Probe */
709 /*------------------------------------------------------------------------
710 * EXPORTED SRXAFSCB_InitCallBackState
713 * Routine called by the server-side callback RPC interface to
714 * implement clearing all callbacks from this host.
717 * a_call : Ptr to Rx call on which this request came in.
723 * Nothing interesting.
727 *------------------------------------------------------------------------*/
730 SRXAFSCB_InitCallBackState(struct rx_call *a_call)
734 struct rx_connection *tconn;
735 struct rx_peer *peer;
742 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_INITCALLBACKSTATE);
743 AFS_STATCNT(SRXAFSCB_InitCallBackState);
746 * Find the address of the host making this call
748 if ((tconn = rx_ConnectionOf(a_call)) && (peer = rx_PeerOf(tconn))) {
751 afs_oddCBs++; /*Including any missed via create race */
752 afs_evenCBs++; /*Including any missed via create race */
754 ts = afs_FindServer(rx_HostOf(peer), rx_PortOf(peer), (afsUUID *) 0,
757 for (i = 0; i < VCSIZE; i++)
758 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
759 if (tvc->callback == ts) {
760 ObtainWriteLock(&afs_xcbhash, 451);
761 afs_DequeueCallback(tvc);
762 tvc->callback = NULL;
763 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
764 ReleaseWriteLock(&afs_xcbhash);
768 /* capabilities need be requested again */
769 ObtainWriteLock(&afs_xserver, 877);
770 ts->flags &= ~SCAPS_KNOWN;
771 ReleaseWriteLock(&afs_xserver);
776 /* find any volumes residing on this server and flush their state */
781 for (i = 0; i < NVOLS; i++)
782 for (tv = afs_volumes[i]; tv; tv = tv->next) {
783 for (j = 0; j < AFS_MAXHOSTS; j++)
784 if (tv->serverHost[j] == ts)
785 afs_ResetVolumeInfo(tv);
788 osi_dnlc_purge(); /* may be a little bit extreme */
797 } /*SRXAFSCB_InitCallBackState */
800 /*------------------------------------------------------------------------
801 * EXPORTED SRXAFSCB_XStatsVersion
804 * Routine called by the server-side callback RPC interface to
805 * implement pulling out the xstat version number for the Cache
809 * a_versionP : Ptr to the version number variable to set.
815 * Nothing interesting.
819 *------------------------------------------------------------------------*/
822 SRXAFSCB_XStatsVersion(struct rx_call *a_call, afs_int32 * a_versionP)
829 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_XSTATSVERSION);
831 *a_versionP = AFSCB_XSTAT_VERSION;
838 } /*SRXAFSCB_XStatsVersion */
841 /*------------------------------------------------------------------------
842 * EXPORTED SRXAFSCB_GetXStats
845 * Routine called by the server-side callback RPC interface to
846 * implement getting the given data collection from the extended
847 * Cache Manager statistics.
850 * a_call : Ptr to Rx call on which this request came in.
851 * a_clientVersionNum : Client version number.
852 * a_opCode : Desired operation.
853 * a_serverVersionNumP : Ptr to version number to set.
854 * a_timeP : Ptr to time value (seconds) to set.
855 * a_dataArray : Ptr to variable array structure to return
862 * Nothing interesting.
866 *------------------------------------------------------------------------*/
869 SRXAFSCB_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
870 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
871 afs_int32 * a_timeP, AFSCB_CollData * a_dataP)
873 int code; /*Return value */
874 afs_int32 *dataBuffP; /*Ptr to data to be returned */
875 afs_int32 dataBytes; /*Bytes in data buffer */
880 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETXSTATS);
883 * Record the time of day and the server version number.
885 *a_srvVersionNumP = AFSCB_XSTAT_VERSION;
886 *a_timeP = osi_Time();
889 * Stuff the appropriate data in there (assume victory)
895 * We're not keeping stats, so just return successfully with
898 a_dataP->AFSCB_CollData_len = 0;
899 a_dataP->AFSCB_CollData_val = NULL;
901 switch (a_collectionNumber) {
902 case AFSCB_XSTATSCOLL_CALL_INFO:
904 * Pass back all the call-count-related data.
906 * >>> We are forced to allocate a separate area in which to
907 * >>> put this stuff in by the RPC stub generator, since it
908 * >>> will be freed at the tail end of the server stub code.
910 dataBytes = sizeof(struct afs_CMStats);
911 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
912 osi_Assert(dataBuffP != NULL);
913 memcpy((char *)dataBuffP, (char *)&afs_cmstats, dataBytes);
914 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
915 a_dataP->AFSCB_CollData_val = dataBuffP;
918 case AFSCB_XSTATSCOLL_PERF_INFO:
920 * Update and then pass back all the performance-related data.
921 * Note: the only performance fields that need to be computed
922 * at this time are the number of accesses for this collection
923 * and the current server record info.
925 * >>> We are forced to allocate a separate area in which to
926 * >>> put this stuff in by the RPC stub generator, since it
927 * >>> will be freed at the tail end of the server stub code.
929 afs_stats_cmperf.numPerfCalls++;
931 dataBytes = sizeof(afs_stats_cmperf);
932 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
933 osi_Assert(dataBuffP != NULL);
934 memcpy((char *)dataBuffP, (char *)&afs_stats_cmperf, dataBytes);
935 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
936 a_dataP->AFSCB_CollData_val = dataBuffP;
939 case AFSCB_XSTATSCOLL_FULL_PERF_INFO:
941 * Pass back the full range of performance and statistical
942 * data available. We have to bring the normal performance
943 * data collection up to date, then copy that data into
944 * the full collection.
946 * >>> We are forced to allocate a separate area in which to
947 * >>> put this stuff in by the RPC stub generator, since it
948 * >>> will be freed at the tail end of the server stub code.
950 afs_stats_cmperf.numPerfCalls++;
952 memcpy((char *)(&(afs_stats_cmfullperf.perf)),
953 (char *)(&afs_stats_cmperf), sizeof(struct afs_stats_CMPerf));
954 afs_stats_cmfullperf.numFullPerfCalls++;
956 dataBytes = sizeof(afs_stats_cmfullperf);
957 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
958 osi_Assert(dataBuffP != NULL);
959 memcpy((char *)dataBuffP, (char *)(&afs_stats_cmfullperf), dataBytes);
960 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
961 a_dataP->AFSCB_CollData_val = dataBuffP;
966 * Illegal collection number.
968 a_dataP->AFSCB_CollData_len = 0;
969 a_dataP->AFSCB_CollData_val = NULL;
971 } /*Switch on collection number */
972 #endif /* AFS_NOSTATS */
980 } /*SRXAFSCB_GetXStats */
983 /*------------------------------------------------------------------------
984 * EXPORTED afs_RXCallBackServer
987 * Body of the thread supporting callback services.
996 * Nothing interesting.
1000 *------------------------------------------------------------------------*/
1003 afs_RXCallBackServer(void)
1005 AFS_STATCNT(afs_RXCallBackServer);
1010 afs_osi_Sleep(&afs_server);
1014 * Donate this process to Rx.
1016 rx_ServerProc(NULL);
1019 } /*afs_RXCallBackServer */
1022 /*------------------------------------------------------------------------
1023 * EXPORTED shutdown_CB
1026 * Zero out important Cache Manager data structures.
1035 * Nothing interesting.
1039 *------------------------------------------------------------------------*/
1044 AFS_STATCNT(shutdown_CB);
1046 if (afs_cold_shutdown) {
1047 afs_oddCBs = afs_evenCBs = afs_allCBs = afs_allZaps = afs_oddZaps =
1048 afs_evenZaps = afs_connectBacks = 0;
1055 /*------------------------------------------------------------------------
1056 * EXPORTED SRXAFSCB_InitCallBackState2
1059 * This routine was used in the AFS 3.5 beta release, but not anymore.
1060 * It has since been replaced by SRXAFSCB_InitCallBackState3.
1063 * a_call : Ptr to Rx call on which this request came in.
1066 * RXGEN_OPCODE (always).
1069 * Nothing interesting.
1073 *------------------------------------------------------------------------*/
1076 SRXAFSCB_InitCallBackState2(struct rx_call *a_call,
1077 struct interfaceAddr *addr)
1079 return RXGEN_OPCODE;
1082 /*------------------------------------------------------------------------
1083 * EXPORTED SRXAFSCB_WhoAreYou
1086 * Routine called by the server-side callback RPC interface to
1087 * obtain a unique identifier for the client. The server uses
1088 * this identifier to figure out whether or not two RX connections
1089 * are from the same client, and to find out which addresses go
1090 * with which clients.
1093 * a_call : Ptr to Rx call on which this request came in.
1094 * addr: Ptr to return the list of interfaces for this client.
1100 * Nothing interesting.
1104 *------------------------------------------------------------------------*/
1107 SRXAFSCB_WhoAreYou(struct rx_call *a_call, struct interfaceAddr *addr)
1114 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1116 memset(addr, 0, sizeof(*addr));
1118 ObtainReadLock(&afs_xinterface);
1120 /* return all network interface addresses */
1121 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1122 addr->uuid = afs_cb_interface.uuid;
1123 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1124 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1125 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1126 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1129 ReleaseReadLock(&afs_xinterface);
1137 /*------------------------------------------------------------------------
1138 * EXPORTED SRXAFSCB_InitCallBackState3
1141 * Routine called by the server-side callback RPC interface to
1142 * implement clearing all callbacks from this host.
1145 * a_call : Ptr to Rx call on which this request came in.
1151 * Nothing interesting.
1155 *------------------------------------------------------------------------*/
1158 SRXAFSCB_InitCallBackState3(struct rx_call *a_call, afsUUID * a_uuid)
1163 * TBD: Lookup the server by the UUID instead of its IP address.
1165 code = SRXAFSCB_InitCallBackState(a_call);
1171 /*------------------------------------------------------------------------
1172 * EXPORTED SRXAFSCB_ProbeUuid
1175 * Routine called by the server-side callback RPC interface to
1176 * implement ``probing'' the Cache Manager, just making sure it's
1177 * still there is still the same client it used to be.
1180 * a_call : Ptr to Rx call on which this request came in.
1181 * a_uuid : Ptr to UUID that must match the client's UUID.
1184 * 0 if a_uuid matches the UUID for this client
1185 * Non-zero otherwize
1188 * Nothing interesting.
1192 *------------------------------------------------------------------------*/
1195 SRXAFSCB_ProbeUuid(struct rx_call *a_call, afsUUID * a_uuid)
1201 AFS_STATCNT(SRXAFSCB_Probe);
1203 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
1204 if (!afs_uuid_equal(a_uuid, &afs_cb_interface.uuid))
1205 code = 1; /* failure */
1214 /*------------------------------------------------------------------------
1215 * EXPORTED SRXAFSCB_GetServerPrefs
1218 * Routine to list server preferences used by this client.
1221 * a_call : Ptr to Rx call on which this request came in.
1222 * a_index : Input server index
1223 * a_srvr_addr : Output server address in host byte order
1224 * (0xffffffff on last server)
1225 * a_srvr_rank : Output server rank
1231 * Nothing interesting.
1235 *------------------------------------------------------------------------*/
1238 SRXAFSCB_GetServerPrefs(struct rx_call *a_call, afs_int32 a_index,
1239 afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank)
1245 AFS_STATCNT(SRXAFSCB_GetServerPrefs);
1247 ObtainReadLock(&afs_xserver);
1249 /* Search the hash table for the server with this index */
1250 *a_srvr_addr = 0xffffffff;
1251 *a_srvr_rank = 0xffffffff;
1252 for (i = 0, j = 0; j < NSERVERS && i <= a_index; j++) {
1253 for (sa = afs_srvAddrs[j]; sa && i <= a_index; sa = sa->next_bkt, i++) {
1255 *a_srvr_addr = ntohl(sa->sa_ip);
1256 *a_srvr_rank = sa->sa_iprank;
1261 ReleaseReadLock(&afs_xserver);
1269 /*------------------------------------------------------------------------
1270 * EXPORTED SRXAFSCB_GetCellServDB
1273 * Routine to list cells configured for this client
1276 * a_call : Ptr to Rx call on which this request came in.
1277 * a_index : Input cell index
1278 * a_name : Output cell name ("" on last cell)
1279 * a_hosts : Output cell database servers in host byte order.
1285 * Nothing interesting.
1289 *------------------------------------------------------------------------*/
1292 SRXAFSCB_GetCellServDB(struct rx_call *a_call, afs_int32 a_index,
1293 char **a_name, serverList * a_hosts)
1297 char *t_name, *p_name = NULL;
1300 AFS_STATCNT(SRXAFSCB_GetCellServDB);
1302 tcell = afs_GetCellByIndex(a_index, READ_LOCK);
1306 a_hosts->serverList_val = 0;
1307 a_hosts->serverList_len = 0;
1309 p_name = tcell->cellName;
1310 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++);
1312 a_hosts->serverList_val = afs_osi_Alloc(j * sizeof(afs_int32));
1313 osi_Assert(a_hosts->serverList_val != NULL);
1314 a_hosts->serverList_len = j;
1315 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++)
1316 a_hosts->serverList_val[j] =
1317 ntohl(tcell->cellHosts[j]->addr->sa_ip);
1318 afs_PutCell(tcell, READ_LOCK);
1321 t_name = afs_osi_Alloc(i + 1);
1322 if (t_name == NULL) {
1323 afs_osi_Free(a_hosts->serverList_val, (j * sizeof(afs_int32)));
1330 memcpy(t_name, p_name, i);
1339 /*------------------------------------------------------------------------
1340 * EXPORTED SRXAFSCB_GetLocalCell
1343 * Routine to return name of client's local cell
1346 * a_call : Ptr to Rx call on which this request came in.
1347 * a_name : Output cell name
1353 * Nothing interesting.
1357 *------------------------------------------------------------------------*/
1360 SRXAFSCB_GetLocalCell(struct rx_call *a_call, char **a_name)
1364 char *t_name, *p_name = NULL;
1367 AFS_STATCNT(SRXAFSCB_GetLocalCell);
1369 /* Search the list for the primary cell. Cell number 1 is only
1370 * the primary cell is when no other cell is explicitly marked as
1371 * the primary cell. */
1372 tcell = afs_GetPrimaryCell(READ_LOCK);
1374 p_name = tcell->cellName;
1376 plen = strlen(p_name);
1379 t_name = afs_osi_Alloc(plen + 1);
1380 if (t_name == NULL) {
1382 afs_PutCell(tcell, READ_LOCK);
1387 t_name[plen] = '\0';
1389 memcpy(t_name, p_name, plen);
1395 afs_PutCell(tcell, READ_LOCK);
1401 * afs_MarshallCacheConfig - marshall client cache configuration
1405 * IN callerVersion - the rpc stat version of the caller.
1407 * IN config - client cache configuration.
1409 * OUT ptr - buffer where configuration is marshalled.
1416 afs_MarshallCacheConfig(afs_uint32 callerVersion, cm_initparams_v1 * config,
1419 AFS_STATCNT(afs_MarshallCacheConfig);
1421 * We currently only support version 1.
1423 *(ptr++) = config->nChunkFiles;
1424 *(ptr++) = config->nStatCaches;
1425 *(ptr++) = config->nDataCaches;
1426 *(ptr++) = config->nVolumeCaches;
1427 *(ptr++) = config->firstChunkSize;
1428 *(ptr++) = config->otherChunkSize;
1429 *(ptr++) = config->cacheSize;
1430 *(ptr++) = config->setTime;
1431 *(ptr++) = config->memCache;
1435 /*------------------------------------------------------------------------
1436 * EXPORTED SRXAFSCB_GetCacheConfig
1439 * Routine to return parameters used to initialize client cache.
1440 * Client may request any format version. Server may not return
1441 * format version greater than version requested by client.
1444 * a_call: Ptr to Rx call on which this request came in.
1445 * callerVersion: Data format version desired by the client.
1446 * serverVersion: Data format version of output data.
1447 * configCount: Number bytes allocated for output data.
1448 * config: Client cache configuration.
1454 * Nothing interesting.
1458 *------------------------------------------------------------------------*/
1461 SRXAFSCB_GetCacheConfig(struct rx_call *a_call, afs_uint32 callerVersion,
1462 afs_uint32 * serverVersion, afs_uint32 * configCount,
1463 cacheConfig * config)
1465 afs_uint32 *t_config;
1467 cm_initparams_v1 cm_config;
1470 AFS_STATCNT(SRXAFSCB_GetCacheConfig);
1473 * Currently only support version 1
1475 allocsize = sizeof(cm_initparams_v1);
1476 t_config = afs_osi_Alloc(allocsize);
1477 if (t_config == NULL) {
1482 cm_config.nChunkFiles = cm_initParams.cmi_nChunkFiles;
1483 cm_config.nStatCaches = cm_initParams.cmi_nStatCaches;
1484 cm_config.nDataCaches = cm_initParams.cmi_nDataCaches;
1485 cm_config.nVolumeCaches = cm_initParams.cmi_nVolumeCaches;
1486 cm_config.firstChunkSize = cm_initParams.cmi_firstChunkSize;
1487 cm_config.otherChunkSize = cm_initParams.cmi_otherChunkSize;
1488 cm_config.cacheSize = cm_initParams.cmi_cacheSize;
1489 cm_config.setTime = cm_initParams.cmi_setTime;
1490 cm_config.memCache = cm_initParams.cmi_memCache;
1492 afs_MarshallCacheConfig(callerVersion, &cm_config, t_config);
1494 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1495 *configCount = allocsize;
1496 config->cacheConfig_val = t_config;
1497 config->cacheConfig_len = allocsize / sizeof(afs_uint32);
1504 /*------------------------------------------------------------------------
1505 * EXPORTED SRXAFSCB_FetchData
1508 * Routine to do third party move from a remioserver to the original
1509 * issuer of an ArchiveData request. Presently supported only by the
1510 * "fs" command, not by the AFS client.
1513 * rxcall: Ptr to Rx call on which this request came in.
1514 * Fid: pointer to AFSFid structure.
1515 * Fd: File descriptor inside fs command.
1516 * Position: Offset in the file.
1517 * Length: Data length to transfer.
1518 * TotalLength: Pointer to total file length field
1524 * Nothing interesting.
1527 *------------------------------------------------------------------------*/
1529 SRXAFSCB_FetchData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1530 afs_int64 Position, afs_int64 Length,
1531 afs_int64 * TotalLength)
1536 /*------------------------------------------------------------------------
1537 * EXPORTED SRXAFSCB_StoreData
1540 * Routine to do third party move from a remioserver to the original
1541 * issuer of a RetrieveData request. Presently supported only by the
1542 * "fs" command, not by the AFS client.
1545 * rxcall: Ptr to Rx call on which this request came in.
1546 * Fid: pointer to AFSFid structure.
1547 * Fd: File descriptor inside fs command.
1548 * Position: Offset in the file.
1549 * Length: Data length to transfer.
1550 * TotalLength: Pointer to total file length field
1556 * Nothing interesting.
1560 *------------------------------------------------------------------------*/
1562 SRXAFSCB_StoreData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1563 afs_int64 Position, afs_int64 Length,
1564 afs_int64 * TotalLength)
1569 /*------------------------------------------------------------------------
1570 * EXPORTED SRXAFSCB_GetCellByNum
1573 * Routine to get information about a cell specified by its
1574 * cell number (returned by GetCE/GetCE64).
1577 * a_call : Ptr to Rx call on which this request came in.
1578 * a_cellnum : Input cell number
1579 * a_name : Output cell name (one zero byte when no such cell).
1580 * a_hosts : Output cell database servers in host byte order.
1586 * Nothing interesting.
1590 *------------------------------------------------------------------------*/
1593 SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum,
1594 char **a_name, serverList * a_hosts)
1600 AFS_STATCNT(SRXAFSCB_GetCellByNum);
1602 a_hosts->serverList_val = 0;
1603 a_hosts->serverList_len = 0;
1605 tcell = afs_GetCellStale(a_cellnum, READ_LOCK);
1607 *a_name = afs_strdup("");
1612 ObtainReadLock(&tcell->lock);
1613 *a_name = afs_strdup(tcell->cellName);
1615 for (sn = 0; sn < AFSMAXCELLHOSTS && tcell->cellHosts[sn]; sn++);
1616 a_hosts->serverList_len = sn;
1617 a_hosts->serverList_val = afs_osi_Alloc(sn * sizeof(afs_int32));
1618 osi_Assert(a_hosts->serverList_val != NULL);
1620 for (i = 0; i < sn; i++)
1621 a_hosts->serverList_val[i] = ntohl(tcell->cellHosts[i]->addr->sa_ip);
1622 ReleaseReadLock(&tcell->lock);
1623 afs_PutCell(tcell, READ_LOCK);
1630 SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call,
1631 struct interfaceAddr *addr,
1632 Capabilities * capabilities)
1636 afs_uint32 *dataBuffP;
1637 afs_int32 dataBytes;
1641 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1643 ObtainReadLock(&afs_xinterface);
1645 /* return all network interface addresses */
1646 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1647 addr->uuid = afs_cb_interface.uuid;
1648 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1649 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1650 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1651 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1654 ReleaseReadLock(&afs_xinterface);
1658 dataBytes = 1 * sizeof(afs_uint32);
1659 dataBuffP = afs_osi_Alloc(dataBytes);
1660 osi_Assert(dataBuffP != NULL);
1661 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1662 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1663 capabilities->Capabilities_val = dataBuffP;
1669 #if 0 && defined(AFS_LINUX24_ENV)
1670 extern struct vcache *afs_globalVp;
1672 int recurse_dcache_parent(parent, a_index, addr, inode, flags, time, fileName)
1673 struct dentry * parent;
1681 struct dentry *this_parent = parent;
1682 struct list_head *next;
1684 struct dentry *dentry;
1687 next = this_parent->d_subdirs.next;
1689 while (next != &this_parent->d_subdirs) {
1690 struct list_head *tmp = next;
1691 dentry = list_entry(tmp, struct dentry, d_child);
1697 * Descend a level if the d_subdirs list is non-empty.
1699 if (!list_empty(&dentry->d_subdirs)) {
1700 this_parent = dentry;
1705 * All done at this level ... ascend and resume the search.
1707 if (this_parent != parent) {
1708 next = this_parent->d_child.next;
1709 this_parent = this_parent->d_parent;
1715 if (d_unhashed(dentry))
1720 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1721 *inode = ITOAFS(dentry->d_inode);
1722 *addr = atomic_read(&(dentry)->d_count);
1723 *time = dentry->d_time;
1732 SRXAFSCB_GetDE(struct rx_call *a_call, afs_int32 a_index, afs_int32 *addr,
1733 afs_int32 *inode, afs_int32 *flags, afs_int32 *time,
1735 { /*SRXAFSCB_GetDE*/
1736 int code = 0; /*Return code*/
1737 #if 0 && defined(AFS_LINUX24_ENV)
1738 int i; /*Loop variable*/
1739 struct vcache *tvc = afs_globalVp;
1740 struct dentry *dentry;
1741 struct list_head *cur, *head = &(AFSTOI(tvc))->i_dentry;
1743 #ifdef RX_ENABLE_LOCKS
1745 #endif /* RX_ENABLE_LOCKS */
1747 #if defined(AFS_LINUX24_ENV)
1748 spin_lock(&dcache_lock);
1752 while ((cur = cur->next) != head) {
1753 dentry = list_entry(cur, struct dentry, d_alias);
1755 dget_locked(dentry);
1757 #if defined(AFS_LINUX24_ENV)
1758 spin_unlock(&dcache_lock);
1764 if (recurse_dcache_parent(dentry, a_index, addr, inode, flags, time, fileName) == 0) {
1775 *fileName = afs_strdup("");
1779 if (d_unhashed(dentry))
1784 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1785 *inode = ITOAFS(dentry->d_inode);
1786 *addr = atomic_read(&(dentry)->d_count);
1787 *time = dentry->d_time;
1794 #ifdef RX_ENABLE_LOCKS
1796 #endif /* RX_ENABLE_LOCKS */
1800 } /*SRXAFSCB_GetDE*/