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 #if !defined(AFS_64BIT_ENV)
238 a_result->Length.high = 0;
239 a_result->Length.low = tvc->f.m.Length;
241 a_result->Length = tvc->f.m.Length;
243 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
244 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
245 a_result->cbExpires = tvc->cbExpires;
246 if (tvc->f.states & CVInit) {
247 a_result->refCount = 1;
249 #ifdef AFS_DARWIN80_ENV
250 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
252 a_result->refCount = VREFCOUNT(tvc);
255 a_result->opens = tvc->opens;
256 a_result->writers = tvc->execsOrWriters;
257 a_result->mvstat = tvc->mvstat;
258 a_result->states = tvc->f.states;
262 * Return our results.
271 } /*SRXAFSCB_GetCE64 */
274 /*------------------------------------------------------------------------
275 * EXPORTED SRXAFSCB_GetLock
278 * Routine called by the server-side callback RPC interface to
279 * implement pulling out the contents of a lock in the lock
283 * a_call : Ptr to Rx call on which this request came in.
284 * a_index : Index of desired lock.
285 * a_result : Ptr to a buffer for the given lock.
288 * 0 if everything went fine,
289 * 1 if we were given a bad index.
292 * Nothing interesting.
296 *------------------------------------------------------------------------*/
299 SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index,
300 struct AFSDBLock *a_result)
302 struct ltable *tl; /*Ptr to lock table entry */
303 int nentries; /*Num entries in table */
304 int code; /*Return code */
309 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETLOCK);
311 AFS_STATCNT(SRXAFSCB_GetLock);
312 nentries = sizeof(ltable) / sizeof(struct ltable);
313 if (a_index < 0 || a_index >= nentries+afs_cellindex) {
318 } else if (a_index >= nentries) {
319 struct cell *tc = afs_GetCellByIndex(a_index-nentries, 0);
320 strcpy(a_result->name, tc->cellName);
321 a_result->lock.waitStates =
322 ((struct afs_lock *)&(tc->lock))->wait_states;
323 a_result->lock.exclLocked =
324 ((struct afs_lock *)&(tc->lock))->excl_locked;
325 a_result->lock.readersReading =
326 ((struct afs_lock *)&(tc->lock))->readers_reading;
327 a_result->lock.numWaiting =
328 ((struct afs_lock *)&(tc->lock))->num_waiting;
329 #ifdef INSTRUMENT_LOCKS
330 a_result->lock.pid_last_reader =
331 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_last_reader);
332 a_result->lock.pid_writer =
333 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_writer);
334 a_result->lock.src_indicator =
335 ((struct afs_lock *)&(tc->lock))->src_indicator;
337 a_result->lock.pid_last_reader = 0;
338 a_result->lock.pid_writer = 0;
339 a_result->lock.src_indicator = 0;
344 * Found it - copy out its contents.
346 tl = <able[a_index];
347 strcpy(a_result->name, tl->name);
348 a_result->lock.waitStates =
349 ((struct afs_lock *)(tl->addr))->wait_states;
350 a_result->lock.exclLocked =
351 ((struct afs_lock *)(tl->addr))->excl_locked;
352 a_result->lock.readersReading =
353 ((struct afs_lock *)(tl->addr))->readers_reading;
354 a_result->lock.numWaiting =
355 ((struct afs_lock *)(tl->addr))->num_waiting;
356 #ifdef INSTRUMENT_LOCKS
357 a_result->lock.pid_last_reader =
358 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_last_reader);
359 a_result->lock.pid_writer =
360 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_writer);
361 a_result->lock.src_indicator =
362 ((struct afs_lock *)(tl->addr))->src_indicator;
364 a_result->lock.pid_last_reader = 0;
365 a_result->lock.pid_writer = 0;
366 a_result->lock.src_indicator = 0;
377 } /*SRXAFSCB_GetLock */
380 /*------------------------------------------------------------------------
381 * static ClearCallBack
384 * Clear out callback information for the specified file, or
385 * even a whole volume. Used to worry about callback was from
386 * within the particular cell or not. Now we don't bother with
387 * that anymore; it's not worth the time.
390 * a_conn : Ptr to Rx connection involved.
391 * a_fid : Ptr to AFS fid being cleared.
397 * Nothing interesting.
402 Appears to need to be called with GLOCK held, as the icl_Event4 stuff asserts otherwise
404 *------------------------------------------------------------------------*/
407 ClearCallBack(struct rx_connection *a_conn,
408 struct AFSFid *a_fid)
412 struct VenusFid localFid;
414 #ifdef AFS_DARWIN80_ENV
418 AFS_STATCNT(ClearCallBack);
423 * XXXX Don't hold any server locks here because of callback protocol XXX
426 localFid.Fid.Volume = a_fid->Volume;
427 localFid.Fid.Vnode = a_fid->Vnode;
428 localFid.Fid.Unique = a_fid->Unique;
431 * Volume ID of zero means don't do anything.
433 if (a_fid->Volume != 0) {
434 if (a_fid->Vnode == 0) {
435 struct afs_q *tq, *uq;
437 * Clear callback for the whole volume. Zip through the
438 * hash chain, nullifying entries whose volume ID matches.
441 ObtainReadLock(&afs_xvcache);
442 i = VCHashV(&localFid);
443 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
446 if (tvc->f.fid.Fid.Volume == a_fid->Volume) {
447 tvc->callback = NULL;
449 localFid.Cell = tvc->f.fid.Cell;
450 tvc->dchint = NULL; /* invalidate hints */
451 if (tvc->f.states & CVInit) {
452 ReleaseReadLock(&afs_xvcache);
453 afs_osi_Sleep(&tvc->f.states);
456 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
459 #ifdef AFS_DARWIN80_ENV
460 if (tvc->f.states & CDeadVnode) {
461 if (!(tvc->f.states & CBulkFetching)) {
462 ReleaseReadLock(&afs_xvcache);
463 afs_osi_Sleep(&tvc->f.states);
476 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
478 vnode_recycle(AFSTOV(tvc));
485 ReleaseReadLock(&afs_xvcache);
486 ObtainWriteLock(&afs_xcbhash, 449);
487 afs_DequeueCallback(tvc);
488 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
490 if (tvc->f.fid.Fid.Vnode & 1)
494 ReleaseWriteLock(&afs_xcbhash);
495 if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
496 osi_dnlc_purgedp(tvc);
497 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
498 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
499 tvc->f.states, ICL_TYPE_INT32,
501 #ifdef AFS_DARWIN80_ENV
502 vnode_put(AFSTOV(tvc));
504 ObtainReadLock(&afs_xvcache);
507 } else if ((tvc->f.states & CMValid)
508 && (tvc->mvid->Fid.Volume == a_fid->Volume)) {
509 tvc->f.states &= ~CMValid;
511 localFid.Cell = tvc->mvid->Cell;
514 ReleaseReadLock(&afs_xvcache);
517 * XXXX Don't hold any locks here XXXX
519 tv = afs_FindVolume(&localFid, 0);
521 afs_ResetVolumeInfo(tv);
522 afs_PutVolume(tv, 0);
523 /* invalidate mtpoint? */
525 } /*Clear callbacks for whole volume */
528 * Clear callbacks just for the one file.
532 if (a_fid->Vnode & 1)
533 afs_oddCBs++; /*Could do this on volume basis, too */
535 afs_evenCBs++; /*A particular fid was specified */
537 ObtainReadLock(&afs_xvcache);
538 i = VCHash(&localFid);
539 for (tvc = afs_vhashT[i]; tvc; tvc = uvc) {
541 if (tvc->f.fid.Fid.Vnode == a_fid->Vnode
542 && tvc->f.fid.Fid.Volume == a_fid->Volume
543 && tvc->f.fid.Fid.Unique == a_fid->Unique) {
544 tvc->callback = NULL;
545 tvc->dchint = NULL; /* invalidate hints */
546 if (tvc->f.states & CVInit) {
547 ReleaseReadLock(&afs_xvcache);
548 afs_osi_Sleep(&tvc->f.states);
551 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
554 #ifdef AFS_DARWIN80_ENV
555 if (tvc->f.states & CDeadVnode) {
556 if (!(tvc->f.states & CBulkFetching)) {
557 ReleaseReadLock(&afs_xvcache);
558 afs_osi_Sleep(&tvc->f.states);
571 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
573 vnode_recycle(AFSTOV(tvc));
580 ReleaseReadLock(&afs_xvcache);
581 ObtainWriteLock(&afs_xcbhash, 450);
582 afs_DequeueCallback(tvc);
583 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
584 ReleaseWriteLock(&afs_xcbhash);
585 if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
586 osi_dnlc_purgedp(tvc);
587 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
588 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
589 tvc->f.states, ICL_TYPE_LONG, 0);
591 lastCallBack_vnode = afid->Vnode;
592 lastCallBack_dv = tvc->mstat.DataVersion.low;
593 osi_GetuTime(&lastCallBack_time);
595 #ifdef AFS_DARWIN80_ENV
596 vnode_put(AFSTOV(tvc));
598 ObtainReadLock(&afs_xvcache);
602 } /*Walk through hash table */
603 ReleaseReadLock(&afs_xvcache);
604 } /*Clear callbacks for one file */
607 /*Fid has non-zero volume ID */
609 * Always return a predictable value.
616 /*------------------------------------------------------------------------
617 * EXPORTED SRXAFSCB_CallBack
620 * Routine called by the server-side callback RPC interface to
621 * implement passing in callback information.
625 * a_call : Ptr to Rx call on which this request came in.
626 * a_fids : Ptr to array of fids involved.
627 * a_callbacks : Ptr to matching callback info for the fids.
633 * Nothing interesting.
637 *------------------------------------------------------------------------*/
640 SRXAFSCB_CallBack(struct rx_call *a_call, struct AFSCBFids *a_fids,
641 struct AFSCBs *a_callbacks)
643 int i; /*Loop variable */
644 struct AFSFid *tfid; /*Ptr to current fid */
645 struct rx_connection *tconn; /*Call's connection */
651 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_CALLBACK);
653 AFS_STATCNT(SRXAFSCB_CallBack);
654 if (!(tconn = rx_ConnectionOf(a_call)))
656 tfid = (struct AFSFid *)a_fids->AFSCBFids_val;
659 * For now, we ignore callbacks, since the File Server only *breaks*
660 * callbacks at present.
662 for (i = 0; i < a_fids->AFSCBFids_len; i++)
663 ClearCallBack(tconn, &tfid[i]);
671 } /*SRXAFSCB_CallBack */
674 /*------------------------------------------------------------------------
675 * EXPORTED SRXAFSCB_Probe
678 * Routine called by the server-side callback RPC interface to
679 * implement ``probing'' the Cache Manager, just making sure it's
683 * a_call : Ptr to Rx call on which this request came in.
689 * Nothing interesting.
693 *------------------------------------------------------------------------*/
696 SRXAFSCB_Probe(struct rx_call *a_call)
702 AFS_STATCNT(SRXAFSCB_Probe);
704 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
711 } /*SRXAFSCB_Probe */
714 /*------------------------------------------------------------------------
715 * EXPORTED SRXAFSCB_InitCallBackState
718 * Routine called by the server-side callback RPC interface to
719 * implement clearing all callbacks from this host.
722 * a_call : Ptr to Rx call on which this request came in.
728 * Nothing interesting.
732 *------------------------------------------------------------------------*/
735 SRXAFSCB_InitCallBackState(struct rx_call *a_call)
739 struct rx_connection *tconn;
740 struct rx_peer *peer;
747 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_INITCALLBACKSTATE);
748 AFS_STATCNT(SRXAFSCB_InitCallBackState);
751 * Find the address of the host making this call
753 if ((tconn = rx_ConnectionOf(a_call)) && (peer = rx_PeerOf(tconn))) {
756 afs_oddCBs++; /*Including any missed via create race */
757 afs_evenCBs++; /*Including any missed via create race */
759 ts = afs_FindServer(rx_HostOf(peer), rx_PortOf(peer), (afsUUID *) 0,
762 for (i = 0; i < VCSIZE; i++)
763 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
764 if (tvc->callback == ts) {
765 ObtainWriteLock(&afs_xcbhash, 451);
766 afs_DequeueCallback(tvc);
767 tvc->callback = NULL;
768 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
769 ReleaseWriteLock(&afs_xcbhash);
773 /* capabilities need be requested again */
774 ObtainWriteLock(&afs_xserver, 877);
775 ts->flags &= ~SCAPS_KNOWN;
776 ReleaseWriteLock(&afs_xserver);
781 /* find any volumes residing on this server and flush their state */
786 for (i = 0; i < NVOLS; i++)
787 for (tv = afs_volumes[i]; tv; tv = tv->next) {
788 for (j = 0; j < AFS_MAXHOSTS; j++)
789 if (tv->serverHost[j] == ts)
790 afs_ResetVolumeInfo(tv);
793 osi_dnlc_purge(); /* may be a little bit extreme */
802 } /*SRXAFSCB_InitCallBackState */
805 /*------------------------------------------------------------------------
806 * EXPORTED SRXAFSCB_XStatsVersion
809 * Routine called by the server-side callback RPC interface to
810 * implement pulling out the xstat version number for the Cache
814 * a_versionP : Ptr to the version number variable to set.
820 * Nothing interesting.
824 *------------------------------------------------------------------------*/
827 SRXAFSCB_XStatsVersion(struct rx_call *a_call, afs_int32 * a_versionP)
834 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_XSTATSVERSION);
836 *a_versionP = AFSCB_XSTAT_VERSION;
843 } /*SRXAFSCB_XStatsVersion */
846 /*------------------------------------------------------------------------
847 * EXPORTED SRXAFSCB_GetXStats
850 * Routine called by the server-side callback RPC interface to
851 * implement getting the given data collection from the extended
852 * Cache Manager statistics.
855 * a_call : Ptr to Rx call on which this request came in.
856 * a_clientVersionNum : Client version number.
857 * a_opCode : Desired operation.
858 * a_serverVersionNumP : Ptr to version number to set.
859 * a_timeP : Ptr to time value (seconds) to set.
860 * a_dataArray : Ptr to variable array structure to return
867 * Nothing interesting.
871 *------------------------------------------------------------------------*/
874 SRXAFSCB_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
875 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
876 afs_int32 * a_timeP, AFSCB_CollData * a_dataP)
878 int code; /*Return value */
879 afs_int32 *dataBuffP; /*Ptr to data to be returned */
880 afs_int32 dataBytes; /*Bytes in data buffer */
885 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETXSTATS);
888 * Record the time of day and the server version number.
890 *a_srvVersionNumP = AFSCB_XSTAT_VERSION;
891 *a_timeP = osi_Time();
894 * Stuff the appropriate data in there (assume victory)
900 * We're not keeping stats, so just return successfully with
903 a_dataP->AFSCB_CollData_len = 0;
904 a_dataP->AFSCB_CollData_val = NULL;
906 switch (a_collectionNumber) {
907 case AFSCB_XSTATSCOLL_CALL_INFO:
909 * Pass back all the call-count-related data.
911 * >>> We are forced to allocate a separate area in which to
912 * >>> put this stuff in by the RPC stub generator, since it
913 * >>> will be freed at the tail end of the server stub code.
915 dataBytes = sizeof(struct afs_CMStats);
916 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
917 memcpy((char *)dataBuffP, (char *)&afs_cmstats, dataBytes);
918 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
919 a_dataP->AFSCB_CollData_val = dataBuffP;
922 case AFSCB_XSTATSCOLL_PERF_INFO:
924 * Update and then pass back all the performance-related data.
925 * Note: the only performance fields that need to be computed
926 * at this time are the number of accesses for this collection
927 * and the current server record info.
929 * >>> We are forced to allocate a separate area in which to
930 * >>> put this stuff in by the RPC stub generator, since it
931 * >>> will be freed at the tail end of the server stub code.
933 afs_stats_cmperf.numPerfCalls++;
935 dataBytes = sizeof(afs_stats_cmperf);
936 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
937 memcpy((char *)dataBuffP, (char *)&afs_stats_cmperf, dataBytes);
938 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
939 a_dataP->AFSCB_CollData_val = dataBuffP;
942 case AFSCB_XSTATSCOLL_FULL_PERF_INFO:
944 * Pass back the full range of performance and statistical
945 * data available. We have to bring the normal performance
946 * data collection up to date, then copy that data into
947 * the full collection.
949 * >>> We are forced to allocate a separate area in which to
950 * >>> put this stuff in by the RPC stub generator, since it
951 * >>> will be freed at the tail end of the server stub code.
953 afs_stats_cmperf.numPerfCalls++;
955 memcpy((char *)(&(afs_stats_cmfullperf.perf)),
956 (char *)(&afs_stats_cmperf), sizeof(struct afs_stats_CMPerf));
957 afs_stats_cmfullperf.numFullPerfCalls++;
959 dataBytes = sizeof(afs_stats_cmfullperf);
960 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
961 memcpy((char *)dataBuffP, (char *)(&afs_stats_cmfullperf), dataBytes);
962 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
963 a_dataP->AFSCB_CollData_val = dataBuffP;
968 * Illegal collection number.
970 a_dataP->AFSCB_CollData_len = 0;
971 a_dataP->AFSCB_CollData_val = NULL;
973 } /*Switch on collection number */
974 #endif /* AFS_NOSTATS */
982 } /*SRXAFSCB_GetXStats */
985 /*------------------------------------------------------------------------
986 * EXPORTED afs_RXCallBackServer
989 * Body of the thread supporting callback services.
998 * Nothing interesting.
1002 *------------------------------------------------------------------------*/
1005 afs_RXCallBackServer(void)
1007 AFS_STATCNT(afs_RXCallBackServer);
1012 afs_osi_Sleep(&afs_server);
1016 * Donate this process to Rx.
1018 rx_ServerProc(NULL);
1021 } /*afs_RXCallBackServer */
1024 /*------------------------------------------------------------------------
1025 * EXPORTED shutdown_CB
1028 * Zero out important Cache Manager data structures.
1037 * Nothing interesting.
1041 *------------------------------------------------------------------------*/
1046 AFS_STATCNT(shutdown_CB);
1048 if (afs_cold_shutdown) {
1049 afs_oddCBs = afs_evenCBs = afs_allCBs = afs_allZaps = afs_oddZaps =
1050 afs_evenZaps = afs_connectBacks = 0;
1057 /*------------------------------------------------------------------------
1058 * EXPORTED SRXAFSCB_InitCallBackState2
1061 * This routine was used in the AFS 3.5 beta release, but not anymore.
1062 * It has since been replaced by SRXAFSCB_InitCallBackState3.
1065 * a_call : Ptr to Rx call on which this request came in.
1068 * RXGEN_OPCODE (always).
1071 * Nothing interesting.
1075 *------------------------------------------------------------------------*/
1078 SRXAFSCB_InitCallBackState2(struct rx_call *a_call,
1079 struct interfaceAddr *addr)
1081 return RXGEN_OPCODE;
1084 /*------------------------------------------------------------------------
1085 * EXPORTED SRXAFSCB_WhoAreYou
1088 * Routine called by the server-side callback RPC interface to
1089 * obtain a unique identifier for the client. The server uses
1090 * this identifier to figure out whether or not two RX connections
1091 * are from the same client, and to find out which addresses go
1092 * with which clients.
1095 * a_call : Ptr to Rx call on which this request came in.
1096 * addr: Ptr to return the list of interfaces for this client.
1102 * Nothing interesting.
1106 *------------------------------------------------------------------------*/
1109 SRXAFSCB_WhoAreYou(struct rx_call *a_call, struct interfaceAddr *addr)
1116 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1118 memset(addr, 0, sizeof(*addr));
1120 ObtainReadLock(&afs_xinterface);
1122 /* return all network interface addresses */
1123 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1124 addr->uuid = afs_cb_interface.uuid;
1125 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1126 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1127 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1128 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1131 ReleaseReadLock(&afs_xinterface);
1139 /*------------------------------------------------------------------------
1140 * EXPORTED SRXAFSCB_InitCallBackState3
1143 * Routine called by the server-side callback RPC interface to
1144 * implement clearing all callbacks from this host.
1147 * a_call : Ptr to Rx call on which this request came in.
1153 * Nothing interesting.
1157 *------------------------------------------------------------------------*/
1160 SRXAFSCB_InitCallBackState3(struct rx_call *a_call, afsUUID * a_uuid)
1165 * TBD: Lookup the server by the UUID instead of its IP address.
1167 code = SRXAFSCB_InitCallBackState(a_call);
1173 /*------------------------------------------------------------------------
1174 * EXPORTED SRXAFSCB_ProbeUuid
1177 * Routine called by the server-side callback RPC interface to
1178 * implement ``probing'' the Cache Manager, just making sure it's
1179 * still there is still the same client it used to be.
1182 * a_call : Ptr to Rx call on which this request came in.
1183 * a_uuid : Ptr to UUID that must match the client's UUID.
1186 * 0 if a_uuid matches the UUID for this client
1187 * Non-zero otherwize
1190 * Nothing interesting.
1194 *------------------------------------------------------------------------*/
1197 SRXAFSCB_ProbeUuid(struct rx_call *a_call, afsUUID * a_uuid)
1203 AFS_STATCNT(SRXAFSCB_Probe);
1205 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
1206 if (!afs_uuid_equal(a_uuid, &afs_cb_interface.uuid))
1207 code = 1; /* failure */
1216 /*------------------------------------------------------------------------
1217 * EXPORTED SRXAFSCB_GetServerPrefs
1220 * Routine to list server preferences used by this client.
1223 * a_call : Ptr to Rx call on which this request came in.
1224 * a_index : Input server index
1225 * a_srvr_addr : Output server address in host byte order
1226 * (0xffffffff on last server)
1227 * a_srvr_rank : Output server rank
1233 * Nothing interesting.
1237 *------------------------------------------------------------------------*/
1240 SRXAFSCB_GetServerPrefs(struct rx_call *a_call, afs_int32 a_index,
1241 afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank)
1247 AFS_STATCNT(SRXAFSCB_GetServerPrefs);
1249 ObtainReadLock(&afs_xserver);
1251 /* Search the hash table for the server with this index */
1252 *a_srvr_addr = 0xffffffff;
1253 *a_srvr_rank = 0xffffffff;
1254 for (i = 0, j = 0; j < NSERVERS && i <= a_index; j++) {
1255 for (sa = afs_srvAddrs[j]; sa && i <= a_index; sa = sa->next_bkt, i++) {
1257 *a_srvr_addr = ntohl(sa->sa_ip);
1258 *a_srvr_rank = sa->sa_iprank;
1263 ReleaseReadLock(&afs_xserver);
1271 /*------------------------------------------------------------------------
1272 * EXPORTED SRXAFSCB_GetCellServDB
1275 * Routine to list cells configured for this client
1278 * a_call : Ptr to Rx call on which this request came in.
1279 * a_index : Input cell index
1280 * a_name : Output cell name ("" on last cell)
1281 * a_hosts : Output cell database servers in host byte order.
1287 * Nothing interesting.
1291 *------------------------------------------------------------------------*/
1294 SRXAFSCB_GetCellServDB(struct rx_call *a_call, afs_int32 a_index,
1295 char **a_name, serverList * a_hosts)
1299 char *t_name, *p_name = NULL;
1302 AFS_STATCNT(SRXAFSCB_GetCellServDB);
1304 tcell = afs_GetCellByIndex(a_index, READ_LOCK);
1308 a_hosts->serverList_val = 0;
1309 a_hosts->serverList_len = 0;
1311 p_name = tcell->cellName;
1312 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++);
1314 a_hosts->serverList_val =
1315 (afs_int32 *) afs_osi_Alloc(j * sizeof(afs_int32));
1316 a_hosts->serverList_len = j;
1317 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++)
1318 a_hosts->serverList_val[j] =
1319 ntohl(tcell->cellHosts[j]->addr->sa_ip);
1320 afs_PutCell(tcell, READ_LOCK);
1323 t_name = (char *)afs_osi_Alloc(i + 1);
1324 if (t_name == NULL) {
1325 afs_osi_Free(a_hosts->serverList_val, (j * sizeof(afs_int32)));
1332 memcpy(t_name, p_name, i);
1341 /*------------------------------------------------------------------------
1342 * EXPORTED SRXAFSCB_GetLocalCell
1345 * Routine to return name of client's local cell
1348 * a_call : Ptr to Rx call on which this request came in.
1349 * a_name : Output cell name
1355 * Nothing interesting.
1359 *------------------------------------------------------------------------*/
1362 SRXAFSCB_GetLocalCell(struct rx_call *a_call, char **a_name)
1366 char *t_name, *p_name = NULL;
1369 AFS_STATCNT(SRXAFSCB_GetLocalCell);
1371 /* Search the list for the primary cell. Cell number 1 is only
1372 * the primary cell is when no other cell is explicitly marked as
1373 * the primary cell. */
1374 tcell = afs_GetPrimaryCell(READ_LOCK);
1376 p_name = tcell->cellName;
1378 plen = strlen(p_name);
1381 t_name = (char *)afs_osi_Alloc(plen + 1);
1382 if (t_name == NULL) {
1384 afs_PutCell(tcell, READ_LOCK);
1389 t_name[plen] = '\0';
1391 memcpy(t_name, p_name, plen);
1397 afs_PutCell(tcell, READ_LOCK);
1403 * afs_MarshallCacheConfig - marshall client cache configuration
1407 * IN callerVersion - the rpc stat version of the caller.
1409 * IN config - client cache configuration.
1411 * OUT ptr - buffer where configuration is marshalled.
1418 afs_MarshallCacheConfig(afs_uint32 callerVersion, cm_initparams_v1 * config,
1421 AFS_STATCNT(afs_MarshallCacheConfig);
1423 * We currently only support version 1.
1425 *(ptr++) = config->nChunkFiles;
1426 *(ptr++) = config->nStatCaches;
1427 *(ptr++) = config->nDataCaches;
1428 *(ptr++) = config->nVolumeCaches;
1429 *(ptr++) = config->firstChunkSize;
1430 *(ptr++) = config->otherChunkSize;
1431 *(ptr++) = config->cacheSize;
1432 *(ptr++) = config->setTime;
1433 *(ptr++) = config->memCache;
1437 /*------------------------------------------------------------------------
1438 * EXPORTED SRXAFSCB_GetCacheConfig
1441 * Routine to return parameters used to initialize client cache.
1442 * Client may request any format version. Server may not return
1443 * format version greater than version requested by client.
1446 * a_call: Ptr to Rx call on which this request came in.
1447 * callerVersion: Data format version desired by the client.
1448 * serverVersion: Data format version of output data.
1449 * configCount: Number bytes allocated for output data.
1450 * config: Client cache configuration.
1456 * Nothing interesting.
1460 *------------------------------------------------------------------------*/
1463 SRXAFSCB_GetCacheConfig(struct rx_call *a_call, afs_uint32 callerVersion,
1464 afs_uint32 * serverVersion, afs_uint32 * configCount,
1465 cacheConfig * config)
1467 afs_uint32 *t_config;
1469 cm_initparams_v1 cm_config;
1472 AFS_STATCNT(SRXAFSCB_GetCacheConfig);
1475 * Currently only support version 1
1477 allocsize = sizeof(cm_initparams_v1);
1478 t_config = (afs_uint32 *) afs_osi_Alloc(allocsize);
1479 if (t_config == NULL) {
1484 cm_config.nChunkFiles = cm_initParams.cmi_nChunkFiles;
1485 cm_config.nStatCaches = cm_initParams.cmi_nStatCaches;
1486 cm_config.nDataCaches = cm_initParams.cmi_nDataCaches;
1487 cm_config.nVolumeCaches = cm_initParams.cmi_nVolumeCaches;
1488 cm_config.firstChunkSize = cm_initParams.cmi_firstChunkSize;
1489 cm_config.otherChunkSize = cm_initParams.cmi_otherChunkSize;
1490 cm_config.cacheSize = cm_initParams.cmi_cacheSize;
1491 cm_config.setTime = cm_initParams.cmi_setTime;
1492 cm_config.memCache = cm_initParams.cmi_memCache;
1494 afs_MarshallCacheConfig(callerVersion, &cm_config, t_config);
1496 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1497 *configCount = allocsize;
1498 config->cacheConfig_val = t_config;
1499 config->cacheConfig_len = allocsize / sizeof(afs_uint32);
1506 /*------------------------------------------------------------------------
1507 * EXPORTED SRXAFSCB_FetchData
1510 * Routine to do third party move from a remioserver to the original
1511 * issuer of an ArchiveData request. Presently supported only by the
1512 * "fs" command, not by the AFS client.
1515 * rxcall: Ptr to Rx call on which this request came in.
1516 * Fid: pointer to AFSFid structure.
1517 * Fd: File descriptor inside fs command.
1518 * Position: Offset in the file.
1519 * Length: Data length to transfer.
1520 * TotalLength: Pointer to total file length field
1526 * Nothing interesting.
1529 *------------------------------------------------------------------------*/
1531 SRXAFSCB_FetchData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1532 afs_int64 Position, afs_int64 Length,
1533 afs_int64 * TotalLength)
1538 /*------------------------------------------------------------------------
1539 * EXPORTED SRXAFSCB_StoreData
1542 * Routine to do third party move from a remioserver to the original
1543 * issuer of a RetrieveData request. Presently supported only by the
1544 * "fs" command, not by the AFS client.
1547 * rxcall: Ptr to Rx call on which this request came in.
1548 * Fid: pointer to AFSFid structure.
1549 * Fd: File descriptor inside fs command.
1550 * Position: Offset in the file.
1551 * Length: Data length to transfer.
1552 * TotalLength: Pointer to total file length field
1558 * Nothing interesting.
1562 *------------------------------------------------------------------------*/
1564 SRXAFSCB_StoreData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1565 afs_int64 Position, afs_int64 Length,
1566 afs_int64 * TotalLength)
1571 /*------------------------------------------------------------------------
1572 * EXPORTED SRXAFSCB_GetCellByNum
1575 * Routine to get information about a cell specified by its
1576 * cell number (returned by GetCE/GetCE64).
1579 * a_call : Ptr to Rx call on which this request came in.
1580 * a_cellnum : Input cell number
1581 * a_name : Output cell name (one zero byte when no such cell).
1582 * a_hosts : Output cell database servers in host byte order.
1588 * Nothing interesting.
1592 *------------------------------------------------------------------------*/
1595 SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum,
1596 char **a_name, serverList * a_hosts)
1602 AFS_STATCNT(SRXAFSCB_GetCellByNum);
1604 a_hosts->serverList_val = 0;
1605 a_hosts->serverList_len = 0;
1607 tcell = afs_GetCellStale(a_cellnum, READ_LOCK);
1609 *a_name = afs_strdup("");
1614 ObtainReadLock(&tcell->lock);
1615 *a_name = afs_strdup(tcell->cellName);
1617 for (sn = 0; sn < AFSMAXCELLHOSTS && tcell->cellHosts[sn]; sn++);
1618 a_hosts->serverList_len = sn;
1619 a_hosts->serverList_val =
1620 (afs_int32 *) afs_osi_Alloc(sn * sizeof(afs_int32));
1622 for (i = 0; i < sn; i++)
1623 a_hosts->serverList_val[i] = ntohl(tcell->cellHosts[i]->addr->sa_ip);
1624 ReleaseReadLock(&tcell->lock);
1625 afs_PutCell(tcell, READ_LOCK);
1632 SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call,
1633 struct interfaceAddr *addr,
1634 Capabilities * capabilities)
1638 afs_uint32 *dataBuffP;
1639 afs_int32 dataBytes;
1643 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1645 ObtainReadLock(&afs_xinterface);
1647 /* return all network interface addresses */
1648 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1649 addr->uuid = afs_cb_interface.uuid;
1650 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1651 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1652 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1653 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1656 ReleaseReadLock(&afs_xinterface);
1660 dataBytes = 1 * sizeof(afs_uint32);
1661 dataBuffP = (afs_uint32 *) afs_osi_Alloc(dataBytes);
1662 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1663 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1664 capabilities->Capabilities_val = dataBuffP;
1670 #if 0 && defined(AFS_LINUX24_ENV)
1671 extern struct vcache *afs_globalVp;
1673 int recurse_dcache_parent(parent, a_index, addr, inode, flags, time, fileName)
1674 struct dentry * parent;
1682 struct dentry *this_parent = parent;
1683 struct list_head *next;
1685 struct dentry *dentry;
1688 next = this_parent->d_subdirs.next;
1690 while (next != &this_parent->d_subdirs) {
1691 struct list_head *tmp = next;
1692 dentry = list_entry(tmp, struct dentry, d_child);
1698 * Descend a level if the d_subdirs list is non-empty.
1700 if (!list_empty(&dentry->d_subdirs)) {
1701 this_parent = dentry;
1706 * All done at this level ... ascend and resume the search.
1708 if (this_parent != parent) {
1709 next = this_parent->d_child.next;
1710 this_parent = this_parent->d_parent;
1716 if (d_unhashed(dentry))
1721 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1722 *inode = ITOAFS(dentry->d_inode);
1723 *addr = atomic_read(&(dentry)->d_count);
1724 *time = dentry->d_time;
1733 SRXAFSCB_GetDE(struct rx_call *a_call, afs_int32 a_index, afs_int32 *addr,
1734 afs_int32 *inode, afs_int32 *flags, afs_int32 *time,
1736 { /*SRXAFSCB_GetDE*/
1737 int code = 0; /*Return code*/
1738 #if 0 && defined(AFS_LINUX24_ENV)
1739 int i; /*Loop variable*/
1740 struct vcache *tvc = afs_globalVp;
1741 struct dentry *dentry;
1742 struct list_head *cur, *head = &(AFSTOI(tvc))->i_dentry;
1744 #ifdef RX_ENABLE_LOCKS
1746 #endif /* RX_ENABLE_LOCKS */
1748 #if defined(AFS_LINUX24_ENV)
1749 spin_lock(&dcache_lock);
1753 while ((cur = cur->next) != head) {
1754 dentry = list_entry(cur, struct dentry, d_alias);
1756 dget_locked(dentry);
1758 #if defined(AFS_LINUX24_ENV)
1759 spin_unlock(&dcache_lock);
1765 if (recurse_dcache_parent(dentry, a_index, addr, inode, flags, time, fileName) == 0) {
1776 *fileName = afs_strdup("");
1780 if (d_unhashed(dentry))
1785 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1786 *inode = ITOAFS(dentry->d_inode);
1787 *addr = atomic_read(&(dentry)->d_count);
1788 *time = dentry->d_time;
1795 #ifdef RX_ENABLE_LOCKS
1797 #endif /* RX_ENABLE_LOCKS */
1801 } /*SRXAFSCB_GetDE*/