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},
66 { "afs_discon_lock", (char *)&afs_discon_lock},
67 { "afs_disconDirtyLock", (char *)&afs_disconDirtyLock},
68 { "afs_discon_vc_dirty", (char *)&afs_xvcdirty},
71 unsigned long lastCallBack_vnode;
72 unsigned int lastCallBack_dv;
73 osi_timeval_t lastCallBack_time;
75 /* these are for storing alternate interface addresses */
76 struct interfaceAddr afs_cb_interface;
78 /*------------------------------------------------------------------------
79 * EXPORTED SRXAFSCB_GetCE
82 * Routine called by the server-side callback RPC interface to
83 * implement pulling out the contents of the i'th cache entry.
86 * a_call : Ptr to Rx call on which this request came in.
87 * a_index : Index of desired cache entry.
88 * a_result : Ptr to a buffer for the given cache entry.
91 * 0 if everything went fine,
92 * 1 if we were given a bad index.
95 * Nothing interesting.
99 *------------------------------------------------------------------------*/
102 SRXAFSCB_GetCE(struct rx_call *a_call, afs_int32 a_index,
103 struct AFSDBCacheEntry *a_result)
106 register int i; /*Loop variable */
107 register struct vcache *tvc; /*Ptr to current cache entry */
108 int code; /*Return code */
113 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE);
115 AFS_STATCNT(SRXAFSCB_GetCE);
116 for (i = 0; i < VCSIZE; i++) {
117 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
121 } /*Zip through current hash chain */
122 } /*Zip through hash chains */
132 * Copy out the located entry.
134 a_result->addr = afs_data_pointer_to_int32(tvc);
135 a_result->cell = tvc->f.fid.Cell;
136 a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
137 a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
138 a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
139 a_result->lock.waitStates = tvc->lock.wait_states;
140 a_result->lock.exclLocked = tvc->lock.excl_locked;
141 a_result->lock.readersReading = tvc->lock.readers_reading;
142 a_result->lock.numWaiting = tvc->lock.num_waiting;
143 #if defined(INSTRUMENT_LOCKS)
144 a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
145 a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
146 a_result->lock.src_indicator = tvc->lock.src_indicator;
148 /* On osf20 , the vcache does not maintain these three fields */
149 a_result->lock.pid_last_reader = 0;
150 a_result->lock.pid_writer = 0;
151 a_result->lock.src_indicator = 0;
152 #endif /* INSTRUMENT_LOCKS */
153 #ifdef AFS_64BIT_CLIENT
154 a_result->Length = (afs_int32) tvc->f.m.Length & 0xffffffff;
155 #else /* AFS_64BIT_CLIENT */
156 a_result->Length = tvc->f.m.Length;
157 #endif /* AFS_64BIT_CLIENT */
158 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
159 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
160 a_result->cbExpires = tvc->cbExpires;
161 if (tvc->f.states & CVInit) {
162 a_result->refCount = 1;
164 #ifdef AFS_DARWIN80_ENV
165 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
167 a_result->refCount = VREFCOUNT(tvc);
170 a_result->opens = tvc->opens;
171 a_result->writers = tvc->execsOrWriters;
172 a_result->mvstat = tvc->mvstat;
173 a_result->states = tvc->f.states;
177 * Return our results.
186 } /*SRXAFSCB_GetCE */
189 SRXAFSCB_GetCE64(struct rx_call *a_call, afs_int32 a_index,
190 struct AFSDBCacheEntry64 *a_result)
192 register int i; /*Loop variable */
193 register struct vcache *tvc; /*Ptr to current cache entry */
194 int code; /*Return code */
199 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE);
201 AFS_STATCNT(SRXAFSCB_GetCE64);
202 for (i = 0; i < VCSIZE; i++) {
203 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
207 } /*Zip through current hash chain */
208 } /*Zip through hash chains */
218 * Copy out the located entry.
220 a_result->addr = afs_data_pointer_to_int32(tvc);
221 a_result->cell = tvc->f.fid.Cell;
222 a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
223 a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
224 a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
225 a_result->lock.waitStates = tvc->lock.wait_states;
226 a_result->lock.exclLocked = tvc->lock.excl_locked;
227 a_result->lock.readersReading = tvc->lock.readers_reading;
228 a_result->lock.numWaiting = tvc->lock.num_waiting;
229 #if defined(INSTRUMENT_LOCKS)
230 a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
231 a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
232 a_result->lock.src_indicator = tvc->lock.src_indicator;
234 /* On osf20 , the vcache does not maintain these three fields */
235 a_result->lock.pid_last_reader = 0;
236 a_result->lock.pid_writer = 0;
237 a_result->lock.src_indicator = 0;
238 #endif /* INSTRUMENT_LOCKS */
239 #if !defined(AFS_64BIT_ENV)
240 a_result->Length.high = 0;
241 a_result->Length.low = tvc->f.m.Length;
243 a_result->Length = tvc->f.m.Length;
245 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
246 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
247 a_result->cbExpires = tvc->cbExpires;
248 if (tvc->f.states & CVInit) {
249 a_result->refCount = 1;
251 #ifdef AFS_DARWIN80_ENV
252 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
254 a_result->refCount = VREFCOUNT(tvc);
257 a_result->opens = tvc->opens;
258 a_result->writers = tvc->execsOrWriters;
259 a_result->mvstat = tvc->mvstat;
260 a_result->states = tvc->f.states;
264 * Return our results.
273 } /*SRXAFSCB_GetCE64 */
276 /*------------------------------------------------------------------------
277 * EXPORTED SRXAFSCB_GetLock
280 * Routine called by the server-side callback RPC interface to
281 * implement pulling out the contents of a lock in the lock
285 * a_call : Ptr to Rx call on which this request came in.
286 * a_index : Index of desired lock.
287 * a_result : Ptr to a buffer for the given lock.
290 * 0 if everything went fine,
291 * 1 if we were given a bad index.
294 * Nothing interesting.
298 *------------------------------------------------------------------------*/
301 SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index,
302 struct AFSDBLock *a_result)
304 struct ltable *tl; /*Ptr to lock table entry */
305 int nentries; /*Num entries in table */
306 int code; /*Return code */
311 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETLOCK);
313 AFS_STATCNT(SRXAFSCB_GetLock);
314 nentries = sizeof(ltable) / sizeof(struct ltable);
315 if (a_index < 0 || a_index >= nentries+afs_cellindex) {
320 } else if (a_index >= nentries) {
321 struct cell *tc = afs_GetCellByIndex(a_index-nentries, 0);
322 strcpy(a_result->name, tc->cellName);
323 a_result->lock.waitStates =
324 ((struct afs_lock *)&(tc->lock))->wait_states;
325 a_result->lock.exclLocked =
326 ((struct afs_lock *)&(tc->lock))->excl_locked;
327 a_result->lock.readersReading =
328 ((struct afs_lock *)&(tc->lock))->readers_reading;
329 a_result->lock.numWaiting =
330 ((struct afs_lock *)&(tc->lock))->num_waiting;
331 #ifdef INSTRUMENT_LOCKS
332 a_result->lock.pid_last_reader =
333 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_last_reader);
334 a_result->lock.pid_writer =
335 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_writer);
336 a_result->lock.src_indicator =
337 ((struct afs_lock *)&(tc->lock))->src_indicator;
339 a_result->lock.pid_last_reader = 0;
340 a_result->lock.pid_writer = 0;
341 a_result->lock.src_indicator = 0;
346 * Found it - copy out its contents.
348 tl = <able[a_index];
349 strcpy(a_result->name, tl->name);
350 a_result->lock.waitStates =
351 ((struct afs_lock *)(tl->addr))->wait_states;
352 a_result->lock.exclLocked =
353 ((struct afs_lock *)(tl->addr))->excl_locked;
354 a_result->lock.readersReading =
355 ((struct afs_lock *)(tl->addr))->readers_reading;
356 a_result->lock.numWaiting =
357 ((struct afs_lock *)(tl->addr))->num_waiting;
358 #ifdef INSTRUMENT_LOCKS
359 a_result->lock.pid_last_reader =
360 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_last_reader);
361 a_result->lock.pid_writer =
362 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_writer);
363 a_result->lock.src_indicator =
364 ((struct afs_lock *)(tl->addr))->src_indicator;
366 a_result->lock.pid_last_reader = 0;
367 a_result->lock.pid_writer = 0;
368 a_result->lock.src_indicator = 0;
379 } /*SRXAFSCB_GetLock */
382 /*------------------------------------------------------------------------
383 * static ClearCallBack
386 * Clear out callback information for the specified file, or
387 * even a whole volume. Used to worry about callback was from
388 * within the particular cell or not. Now we don't bother with
389 * that anymore; it's not worth the time.
392 * a_conn : Ptr to Rx connection involved.
393 * a_fid : Ptr to AFS fid being cleared.
399 * Nothing interesting.
404 Appears to need to be called with GLOCK held, as the icl_Event4 stuff asserts otherwise
406 *------------------------------------------------------------------------*/
409 ClearCallBack(register struct rx_connection *a_conn,
410 register struct AFSFid *a_fid)
412 register struct vcache *tvc;
414 struct VenusFid localFid;
416 #ifdef AFS_DARWIN80_ENV
420 AFS_STATCNT(ClearCallBack);
425 * XXXX Don't hold any server locks here because of callback protocol XXX
428 localFid.Fid.Volume = a_fid->Volume;
429 localFid.Fid.Vnode = a_fid->Vnode;
430 localFid.Fid.Unique = a_fid->Unique;
433 * Volume ID of zero means don't do anything.
435 if (a_fid->Volume != 0) {
436 if (a_fid->Vnode == 0) {
437 struct afs_q *tq, *uq;
439 * Clear callback for the whole volume. Zip through the
440 * hash chain, nullifying entries whose volume ID matches.
443 ObtainReadLock(&afs_xvcache);
444 i = VCHashV(&localFid);
445 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
448 if (tvc->f.fid.Fid.Volume == a_fid->Volume) {
449 tvc->callback = NULL;
451 localFid.Cell = tvc->f.fid.Cell;
452 tvc->dchint = NULL; /* invalidate hints */
453 if (tvc->f.states & CVInit) {
454 ReleaseReadLock(&afs_xvcache);
455 afs_osi_Sleep(&tvc->f.states);
458 #ifdef AFS_DARWIN80_ENV
459 if (tvc->f.states & CDeadVnode) {
460 ReleaseReadLock(&afs_xvcache);
461 afs_osi_Sleep(&tvc->f.states);
465 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
466 VN_HOLD(AFSTOV(tvc));
468 #ifdef AFS_DARWIN80_ENV
479 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
482 VREFCOUNT_INC(tvc); /* AIX, apparently */
486 ReleaseReadLock(&afs_xvcache);
487 ObtainWriteLock(&afs_xcbhash, 449);
488 afs_DequeueCallback(tvc);
489 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
491 if (tvc->f.fid.Fid.Vnode & 1)
495 ReleaseWriteLock(&afs_xcbhash);
496 if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
497 osi_dnlc_purgedp(tvc);
498 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
499 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
500 tvc->f.states, ICL_TYPE_INT32,
502 #ifdef AFS_DARWIN80_ENV
503 vnode_put(AFSTOV(tvc));
505 ObtainReadLock(&afs_xvcache);
508 } else if ((tvc->f.states & CMValid)
509 && (tvc->mvid->Fid.Volume == a_fid->Volume)) {
510 tvc->f.states &= ~CMValid;
512 localFid.Cell = tvc->mvid->Cell;
515 ReleaseReadLock(&afs_xvcache);
518 * XXXX Don't hold any locks here XXXX
520 tv = afs_FindVolume(&localFid, 0);
522 afs_ResetVolumeInfo(tv);
523 afs_PutVolume(tv, 0);
524 /* invalidate mtpoint? */
526 } /*Clear callbacks for whole volume */
529 * Clear callbacks just for the one file.
533 if (a_fid->Vnode & 1)
534 afs_oddCBs++; /*Could do this on volume basis, too */
536 afs_evenCBs++; /*A particular fid was specified */
538 ObtainReadLock(&afs_xvcache);
539 i = VCHash(&localFid);
540 for (tvc = afs_vhashT[i]; tvc; tvc = uvc) {
542 if (tvc->f.fid.Fid.Vnode == a_fid->Vnode
543 && tvc->f.fid.Fid.Volume == a_fid->Volume
544 && tvc->f.fid.Fid.Unique == a_fid->Unique) {
545 tvc->callback = NULL;
546 tvc->dchint = NULL; /* invalidate hints */
547 if (tvc->f.states & CVInit) {
548 ReleaseReadLock(&afs_xvcache);
549 afs_osi_Sleep(&tvc->f.states);
552 #ifdef AFS_DARWIN80_ENV
553 if (tvc->f.states & CDeadVnode) {
554 ReleaseReadLock(&afs_xvcache);
555 afs_osi_Sleep(&tvc->f.states);
559 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
560 VN_HOLD(AFSTOV(tvc));
562 #ifdef AFS_DARWIN80_ENV
573 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
576 VREFCOUNT_INC(tvc); /* AIX, apparently */
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, register struct AFSCBFids *a_fids,
641 struct AFSCBs *a_callbacks)
643 register int i; /*Loop variable */
644 struct AFSFid *tfid; /*Ptr to current fid */
645 register 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)
738 register struct vcache *tvc;
739 register struct rx_connection *tconn;
740 register 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);
776 /* find any volumes residing on this server and flush their state */
778 register struct volume *tv;
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 register 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 memcpy((char *)dataBuffP, (char *)&afs_cmstats, dataBytes);
913 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
914 a_dataP->AFSCB_CollData_val = dataBuffP;
917 case AFSCB_XSTATSCOLL_PERF_INFO:
919 * Update and then pass back all the performance-related data.
920 * Note: the only performance fields that need to be computed
921 * at this time are the number of accesses for this collection
922 * and the current server record info.
924 * >>> We are forced to allocate a separate area in which to
925 * >>> put this stuff in by the RPC stub generator, since it
926 * >>> will be freed at the tail end of the server stub code.
928 afs_stats_cmperf.numPerfCalls++;
930 dataBytes = sizeof(afs_stats_cmperf);
931 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
932 memcpy((char *)dataBuffP, (char *)&afs_stats_cmperf, dataBytes);
933 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
934 a_dataP->AFSCB_CollData_val = dataBuffP;
937 case AFSCB_XSTATSCOLL_FULL_PERF_INFO:
939 * Pass back the full range of performance and statistical
940 * data available. We have to bring the normal performance
941 * data collection up to date, then copy that data into
942 * the full collection.
944 * >>> We are forced to allocate a separate area in which to
945 * >>> put this stuff in by the RPC stub generator, since it
946 * >>> will be freed at the tail end of the server stub code.
948 afs_stats_cmperf.numPerfCalls++;
950 memcpy((char *)(&(afs_stats_cmfullperf.perf)),
951 (char *)(&afs_stats_cmperf), sizeof(struct afs_stats_CMPerf));
952 afs_stats_cmfullperf.numFullPerfCalls++;
954 dataBytes = sizeof(afs_stats_cmfullperf);
955 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
956 memcpy((char *)dataBuffP, (char *)(&afs_stats_cmfullperf), dataBytes);
957 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
958 a_dataP->AFSCB_CollData_val = dataBuffP;
963 * Illegal collection number.
965 a_dataP->AFSCB_CollData_len = 0;
966 a_dataP->AFSCB_CollData_val = NULL;
968 } /*Switch on collection number */
969 #endif /* AFS_NOSTATS */
977 } /*SRXAFSCB_GetXStats */
980 /*------------------------------------------------------------------------
981 * EXPORTED afs_RXCallBackServer
984 * Body of the thread supporting callback services.
993 * Nothing interesting.
997 *------------------------------------------------------------------------*/
1000 afs_RXCallBackServer(void)
1002 AFS_STATCNT(afs_RXCallBackServer);
1007 afs_osi_Sleep(&afs_server);
1011 * Donate this process to Rx.
1013 rx_ServerProc(NULL);
1016 } /*afs_RXCallBackServer */
1019 /*------------------------------------------------------------------------
1020 * EXPORTED shutdown_CB
1023 * Zero out important Cache Manager data structures.
1032 * Nothing interesting.
1036 *------------------------------------------------------------------------*/
1041 AFS_STATCNT(shutdown_CB);
1043 if (afs_cold_shutdown) {
1044 afs_oddCBs = afs_evenCBs = afs_allCBs = afs_allZaps = afs_oddZaps =
1045 afs_evenZaps = afs_connectBacks = 0;
1052 /*------------------------------------------------------------------------
1053 * EXPORTED SRXAFSCB_InitCallBackState2
1056 * This routine was used in the AFS 3.5 beta release, but not anymore.
1057 * It has since been replaced by SRXAFSCB_InitCallBackState3.
1060 * a_call : Ptr to Rx call on which this request came in.
1063 * RXGEN_OPCODE (always).
1066 * Nothing interesting.
1070 *------------------------------------------------------------------------*/
1073 SRXAFSCB_InitCallBackState2(struct rx_call *a_call,
1074 struct interfaceAddr *addr)
1076 return RXGEN_OPCODE;
1079 /*------------------------------------------------------------------------
1080 * EXPORTED SRXAFSCB_WhoAreYou
1083 * Routine called by the server-side callback RPC interface to
1084 * obtain a unique identifier for the client. The server uses
1085 * this identifier to figure out whether or not two RX connections
1086 * are from the same client, and to find out which addresses go
1087 * with which clients.
1090 * a_call : Ptr to Rx call on which this request came in.
1091 * addr: Ptr to return the list of interfaces for this client.
1097 * Nothing interesting.
1101 *------------------------------------------------------------------------*/
1104 SRXAFSCB_WhoAreYou(struct rx_call *a_call, struct interfaceAddr *addr)
1111 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1113 memset(addr, 0, sizeof(*addr));
1115 ObtainReadLock(&afs_xinterface);
1117 /* return all network interface addresses */
1118 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1119 addr->uuid = afs_cb_interface.uuid;
1120 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1121 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1122 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1123 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1126 ReleaseReadLock(&afs_xinterface);
1134 /*------------------------------------------------------------------------
1135 * EXPORTED SRXAFSCB_InitCallBackState3
1138 * Routine called by the server-side callback RPC interface to
1139 * implement clearing all callbacks from this host.
1142 * a_call : Ptr to Rx call on which this request came in.
1148 * Nothing interesting.
1152 *------------------------------------------------------------------------*/
1155 SRXAFSCB_InitCallBackState3(struct rx_call *a_call, afsUUID * a_uuid)
1160 * TBD: Lookup the server by the UUID instead of its IP address.
1162 code = SRXAFSCB_InitCallBackState(a_call);
1168 /*------------------------------------------------------------------------
1169 * EXPORTED SRXAFSCB_ProbeUuid
1172 * Routine called by the server-side callback RPC interface to
1173 * implement ``probing'' the Cache Manager, just making sure it's
1174 * still there is still the same client it used to be.
1177 * a_call : Ptr to Rx call on which this request came in.
1178 * a_uuid : Ptr to UUID that must match the client's UUID.
1181 * 0 if a_uuid matches the UUID for this client
1182 * Non-zero otherwize
1185 * Nothing interesting.
1189 *------------------------------------------------------------------------*/
1192 SRXAFSCB_ProbeUuid(struct rx_call *a_call, afsUUID * a_uuid)
1198 AFS_STATCNT(SRXAFSCB_Probe);
1200 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
1201 if (!afs_uuid_equal(a_uuid, &afs_cb_interface.uuid))
1202 code = 1; /* failure */
1211 /*------------------------------------------------------------------------
1212 * EXPORTED SRXAFSCB_GetServerPrefs
1215 * Routine to list server preferences used by this client.
1218 * a_call : Ptr to Rx call on which this request came in.
1219 * a_index : Input server index
1220 * a_srvr_addr : Output server address in host byte order
1221 * (0xffffffff on last server)
1222 * a_srvr_rank : Output server rank
1228 * Nothing interesting.
1232 *------------------------------------------------------------------------*/
1235 SRXAFSCB_GetServerPrefs(struct rx_call *a_call, afs_int32 a_index,
1236 afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank)
1242 AFS_STATCNT(SRXAFSCB_GetServerPrefs);
1244 ObtainReadLock(&afs_xserver);
1246 /* Search the hash table for the server with this index */
1247 *a_srvr_addr = 0xffffffff;
1248 *a_srvr_rank = 0xffffffff;
1249 for (i = 0, j = 0; j < NSERVERS && i <= a_index; j++) {
1250 for (sa = afs_srvAddrs[j]; sa && i <= a_index; sa = sa->next_bkt, i++) {
1252 *a_srvr_addr = ntohl(sa->sa_ip);
1253 *a_srvr_rank = sa->sa_iprank;
1258 ReleaseReadLock(&afs_xserver);
1266 /*------------------------------------------------------------------------
1267 * EXPORTED SRXAFSCB_GetCellServDB
1270 * Routine to list cells configured for this client
1273 * a_call : Ptr to Rx call on which this request came in.
1274 * a_index : Input cell index
1275 * a_name : Output cell name ("" on last cell)
1276 * a_hosts : Output cell database servers in host byte order.
1282 * Nothing interesting.
1286 *------------------------------------------------------------------------*/
1289 SRXAFSCB_GetCellServDB(struct rx_call *a_call, afs_int32 a_index,
1290 char **a_name, serverList * a_hosts)
1294 char *t_name, *p_name = NULL;
1297 AFS_STATCNT(SRXAFSCB_GetCellServDB);
1299 tcell = afs_GetCellByIndex(a_index, READ_LOCK);
1303 a_hosts->serverList_val = 0;
1304 a_hosts->serverList_len = 0;
1306 p_name = tcell->cellName;
1307 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++);
1309 a_hosts->serverList_val =
1310 (afs_int32 *) afs_osi_Alloc(j * sizeof(afs_int32));
1311 a_hosts->serverList_len = j;
1312 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++)
1313 a_hosts->serverList_val[j] =
1314 ntohl(tcell->cellHosts[j]->addr->sa_ip);
1315 afs_PutCell(tcell, READ_LOCK);
1318 t_name = (char *)afs_osi_Alloc(i + 1);
1319 if (t_name == NULL) {
1320 afs_osi_Free(a_hosts->serverList_val, (j * sizeof(afs_int32)));
1327 memcpy(t_name, p_name, i);
1336 /*------------------------------------------------------------------------
1337 * EXPORTED SRXAFSCB_GetLocalCell
1340 * Routine to return name of client's local cell
1343 * a_call : Ptr to Rx call on which this request came in.
1344 * a_name : Output cell name
1350 * Nothing interesting.
1354 *------------------------------------------------------------------------*/
1357 SRXAFSCB_GetLocalCell(struct rx_call *a_call, char **a_name)
1361 char *t_name, *p_name = NULL;
1364 AFS_STATCNT(SRXAFSCB_GetLocalCell);
1366 /* Search the list for the primary cell. Cell number 1 is only
1367 * the primary cell is when no other cell is explicitly marked as
1368 * the primary cell. */
1369 tcell = afs_GetPrimaryCell(READ_LOCK);
1371 p_name = tcell->cellName;
1373 plen = strlen(p_name);
1376 t_name = (char *)afs_osi_Alloc(plen + 1);
1377 if (t_name == NULL) {
1379 afs_PutCell(tcell, READ_LOCK);
1384 t_name[plen] = '\0';
1386 memcpy(t_name, p_name, plen);
1392 afs_PutCell(tcell, READ_LOCK);
1398 * afs_MarshallCacheConfig - marshall client cache configuration
1402 * IN callerVersion - the rpc stat version of the caller.
1404 * IN config - client cache configuration.
1406 * OUT ptr - buffer where configuration is marshalled.
1413 afs_MarshallCacheConfig(afs_uint32 callerVersion, cm_initparams_v1 * config,
1416 AFS_STATCNT(afs_MarshallCacheConfig);
1418 * We currently only support version 1.
1420 *(ptr++) = config->nChunkFiles;
1421 *(ptr++) = config->nStatCaches;
1422 *(ptr++) = config->nDataCaches;
1423 *(ptr++) = config->nVolumeCaches;
1424 *(ptr++) = config->firstChunkSize;
1425 *(ptr++) = config->otherChunkSize;
1426 *(ptr++) = config->cacheSize;
1427 *(ptr++) = config->setTime;
1428 *(ptr++) = config->memCache;
1432 /*------------------------------------------------------------------------
1433 * EXPORTED SRXAFSCB_GetCacheConfig
1436 * Routine to return parameters used to initialize client cache.
1437 * Client may request any format version. Server may not return
1438 * format version greater than version requested by client.
1441 * a_call: Ptr to Rx call on which this request came in.
1442 * callerVersion: Data format version desired by the client.
1443 * serverVersion: Data format version of output data.
1444 * configCount: Number bytes allocated for output data.
1445 * config: Client cache configuration.
1451 * Nothing interesting.
1455 *------------------------------------------------------------------------*/
1458 SRXAFSCB_GetCacheConfig(struct rx_call *a_call, afs_uint32 callerVersion,
1459 afs_uint32 * serverVersion, afs_uint32 * configCount,
1460 cacheConfig * config)
1462 afs_uint32 *t_config;
1464 cm_initparams_v1 cm_config;
1467 AFS_STATCNT(SRXAFSCB_GetCacheConfig);
1470 * Currently only support version 1
1472 allocsize = sizeof(cm_initparams_v1);
1473 t_config = (afs_uint32 *) afs_osi_Alloc(allocsize);
1474 if (t_config == NULL) {
1479 cm_config.nChunkFiles = cm_initParams.cmi_nChunkFiles;
1480 cm_config.nStatCaches = cm_initParams.cmi_nStatCaches;
1481 cm_config.nDataCaches = cm_initParams.cmi_nDataCaches;
1482 cm_config.nVolumeCaches = cm_initParams.cmi_nVolumeCaches;
1483 cm_config.firstChunkSize = cm_initParams.cmi_firstChunkSize;
1484 cm_config.otherChunkSize = cm_initParams.cmi_otherChunkSize;
1485 cm_config.cacheSize = cm_initParams.cmi_cacheSize;
1486 cm_config.setTime = cm_initParams.cmi_setTime;
1487 cm_config.memCache = cm_initParams.cmi_memCache;
1489 afs_MarshallCacheConfig(callerVersion, &cm_config, t_config);
1491 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1492 *configCount = allocsize;
1493 config->cacheConfig_val = t_config;
1494 config->cacheConfig_len = allocsize / sizeof(afs_uint32);
1501 /*------------------------------------------------------------------------
1502 * EXPORTED SRXAFSCB_FetchData
1505 * Routine to do third party move from a remioserver to the original
1506 * issuer of an ArchiveData request. Presently supported only by the
1507 * "fs" command, not by the AFS client.
1510 * rxcall: Ptr to Rx call on which this request came in.
1511 * Fid: pointer to AFSFid structure.
1512 * Fd: File descriptor inside fs command.
1513 * Position: Offset in the file.
1514 * Length: Data length to transfer.
1515 * TotalLength: Pointer to total file length field
1521 * Nothing interesting.
1524 *------------------------------------------------------------------------*/
1526 SRXAFSCB_FetchData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1527 afs_int64 Position, afs_int64 Length,
1528 afs_int64 * TotalLength)
1533 /*------------------------------------------------------------------------
1534 * EXPORTED SRXAFSCB_StoreData
1537 * Routine to do third party move from a remioserver to the original
1538 * issuer of a RetrieveData request. Presently supported only by the
1539 * "fs" command, not by the AFS client.
1542 * rxcall: Ptr to Rx call on which this request came in.
1543 * Fid: pointer to AFSFid structure.
1544 * Fd: File descriptor inside fs command.
1545 * Position: Offset in the file.
1546 * Length: Data length to transfer.
1547 * TotalLength: Pointer to total file length field
1553 * Nothing interesting.
1557 *------------------------------------------------------------------------*/
1559 SRXAFSCB_StoreData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1560 afs_int64 Position, afs_int64 Length,
1561 afs_int64 * TotalLength)
1566 /*------------------------------------------------------------------------
1567 * EXPORTED SRXAFSCB_GetCellByNum
1570 * Routine to get information about a cell specified by its
1571 * cell number (returned by GetCE/GetCE64).
1574 * a_call : Ptr to Rx call on which this request came in.
1575 * a_cellnum : Input cell number
1576 * a_name : Output cell name (one zero byte when no such cell).
1577 * a_hosts : Output cell database servers in host byte order.
1583 * Nothing interesting.
1587 *------------------------------------------------------------------------*/
1590 SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum,
1591 char **a_name, serverList * a_hosts)
1597 AFS_STATCNT(SRXAFSCB_GetCellByNum);
1599 a_hosts->serverList_val = 0;
1600 a_hosts->serverList_len = 0;
1602 tcell = afs_GetCellStale(a_cellnum, READ_LOCK);
1604 *a_name = afs_strdup("");
1609 ObtainReadLock(&tcell->lock);
1610 *a_name = afs_strdup(tcell->cellName);
1612 for (sn = 0; sn < AFSMAXCELLHOSTS && tcell->cellHosts[sn]; sn++);
1613 a_hosts->serverList_len = sn;
1614 a_hosts->serverList_val =
1615 (afs_int32 *) afs_osi_Alloc(sn * sizeof(afs_int32));
1617 for (i = 0; i < sn; i++)
1618 a_hosts->serverList_val[i] = ntohl(tcell->cellHosts[i]->addr->sa_ip);
1619 ReleaseReadLock(&tcell->lock);
1620 afs_PutCell(tcell, READ_LOCK);
1627 SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call,
1628 struct interfaceAddr *addr,
1629 Capabilities * capabilities)
1633 afs_uint32 *dataBuffP;
1634 afs_int32 dataBytes;
1638 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1640 ObtainReadLock(&afs_xinterface);
1642 /* return all network interface addresses */
1643 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1644 addr->uuid = afs_cb_interface.uuid;
1645 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1646 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1647 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1648 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1651 ReleaseReadLock(&afs_xinterface);
1655 dataBytes = 1 * sizeof(afs_uint32);
1656 dataBuffP = (afs_uint32 *) afs_osi_Alloc(dataBytes);
1657 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1658 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1659 capabilities->Capabilities_val = dataBuffP;
1665 #if 0 && defined(AFS_LINUX24_ENV)
1666 extern struct vcache *afs_globalVp;
1668 int recurse_dcache_parent(parent, a_index, addr, inode, flags, time, fileName)
1669 struct dentry * parent;
1677 struct dentry *this_parent = parent;
1678 struct list_head *next;
1680 struct dentry *dentry;
1683 next = this_parent->d_subdirs.next;
1685 while (next != &this_parent->d_subdirs) {
1686 struct list_head *tmp = next;
1687 dentry = list_entry(tmp, struct dentry, d_child);
1693 * Descend a level if the d_subdirs list is non-empty.
1695 if (!list_empty(&dentry->d_subdirs)) {
1696 this_parent = dentry;
1701 * All done at this level ... ascend and resume the search.
1703 if (this_parent != parent) {
1704 next = this_parent->d_child.next;
1705 this_parent = this_parent->d_parent;
1711 if (d_unhashed(dentry))
1716 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1717 *inode = ITOAFS(dentry->d_inode);
1718 *addr = atomic_read(&(dentry)->d_count);
1719 *time = dentry->d_time;
1727 int SRXAFSCB_GetDE(struct rx_call *a_call, afs_int32 a_index, afs_int32 *addr,
1728 afs_int32 *inode, afs_int32 *flags, afs_int32 *time,
1730 { /*SRXAFSCB_GetDE*/
1731 int code = 0; /*Return code*/
1732 #if 0 && defined(AFS_LINUX24_ENV)
1733 register int i; /*Loop variable*/
1734 register struct vcache *tvc = afs_globalVp;
1735 struct dentry *dentry;
1736 struct list_head *cur, *head = &(AFSTOI(tvc))->i_dentry;
1738 #ifdef RX_ENABLE_LOCKS
1740 #endif /* RX_ENABLE_LOCKS */
1742 #if defined(AFS_LINUX24_ENV)
1743 spin_lock(&dcache_lock);
1747 while ((cur = cur->next) != head) {
1748 dentry = list_entry(cur, struct dentry, d_alias);
1750 dget_locked(dentry);
1752 #if defined(AFS_LINUX24_ENV)
1753 spin_unlock(&dcache_lock);
1759 if (recurse_dcache_parent(dentry, a_index, addr, inode, flags, time, fileName) == 0) {
1770 *fileName = afs_strdup("");
1774 if (d_unhashed(dentry))
1779 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1780 *inode = ITOAFS(dentry->d_inode);
1781 *addr = atomic_read(&(dentry)->d_count);
1782 *time = dentry->d_time;
1789 #ifdef RX_ENABLE_LOCKS
1791 #endif /* RX_ENABLE_LOCKS */
1795 } /*SRXAFSCB_GetDE*/