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},
68 { "afs_dynrootDirLock", (char *)&afs_dynrootDirLock},
69 { "afs_dynSymlinkLock", (char *)&afs_dynSymlinkLock},
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 int i; /*Loop variable */
107 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 int i; /*Loop variable */
193 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 a_result->Length = tvc->f.m.Length;
240 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
241 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
242 a_result->cbExpires = tvc->cbExpires;
243 if (tvc->f.states & CVInit) {
244 a_result->refCount = 1;
246 #ifdef AFS_DARWIN80_ENV
247 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
249 a_result->refCount = VREFCOUNT(tvc);
252 a_result->opens = tvc->opens;
253 a_result->writers = tvc->execsOrWriters;
254 a_result->mvstat = tvc->mvstat;
255 a_result->states = tvc->f.states;
259 * Return our results.
268 } /*SRXAFSCB_GetCE64 */
271 /*------------------------------------------------------------------------
272 * EXPORTED SRXAFSCB_GetLock
275 * Routine called by the server-side callback RPC interface to
276 * implement pulling out the contents of a lock in the lock
280 * a_call : Ptr to Rx call on which this request came in.
281 * a_index : Index of desired lock.
282 * a_result : Ptr to a buffer for the given lock.
285 * 0 if everything went fine,
286 * 1 if we were given a bad index.
289 * Nothing interesting.
293 *------------------------------------------------------------------------*/
296 SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index,
297 struct AFSDBLock *a_result)
299 struct ltable *tl; /*Ptr to lock table entry */
300 int nentries; /*Num entries in table */
301 int code; /*Return code */
306 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETLOCK);
308 AFS_STATCNT(SRXAFSCB_GetLock);
309 nentries = sizeof(ltable) / sizeof(struct ltable);
310 if (a_index < 0 || a_index >= nentries+afs_cellindex) {
315 } else if (a_index >= nentries) {
316 struct cell *tc = afs_GetCellByIndex(a_index-nentries, 0);
317 strcpy(a_result->name, tc->cellName);
318 a_result->lock.waitStates =
319 ((struct afs_lock *)&(tc->lock))->wait_states;
320 a_result->lock.exclLocked =
321 ((struct afs_lock *)&(tc->lock))->excl_locked;
322 a_result->lock.readersReading =
323 ((struct afs_lock *)&(tc->lock))->readers_reading;
324 a_result->lock.numWaiting =
325 ((struct afs_lock *)&(tc->lock))->num_waiting;
326 #ifdef INSTRUMENT_LOCKS
327 a_result->lock.pid_last_reader =
328 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_last_reader);
329 a_result->lock.pid_writer =
330 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_writer);
331 a_result->lock.src_indicator =
332 ((struct afs_lock *)&(tc->lock))->src_indicator;
334 a_result->lock.pid_last_reader = 0;
335 a_result->lock.pid_writer = 0;
336 a_result->lock.src_indicator = 0;
341 * Found it - copy out its contents.
343 tl = <able[a_index];
344 strcpy(a_result->name, tl->name);
345 a_result->lock.waitStates =
346 ((struct afs_lock *)(tl->addr))->wait_states;
347 a_result->lock.exclLocked =
348 ((struct afs_lock *)(tl->addr))->excl_locked;
349 a_result->lock.readersReading =
350 ((struct afs_lock *)(tl->addr))->readers_reading;
351 a_result->lock.numWaiting =
352 ((struct afs_lock *)(tl->addr))->num_waiting;
353 #ifdef INSTRUMENT_LOCKS
354 a_result->lock.pid_last_reader =
355 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_last_reader);
356 a_result->lock.pid_writer =
357 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_writer);
358 a_result->lock.src_indicator =
359 ((struct afs_lock *)(tl->addr))->src_indicator;
361 a_result->lock.pid_last_reader = 0;
362 a_result->lock.pid_writer = 0;
363 a_result->lock.src_indicator = 0;
374 } /*SRXAFSCB_GetLock */
377 /*------------------------------------------------------------------------
378 * static ClearCallBack
381 * Clear out callback information for the specified file, or
382 * even a whole volume. Used to worry about callback was from
383 * within the particular cell or not. Now we don't bother with
384 * that anymore; it's not worth the time.
387 * a_conn : Ptr to Rx connection involved.
388 * a_fid : Ptr to AFS fid being cleared.
394 * Nothing interesting.
399 Appears to need to be called with GLOCK held, as the icl_Event4 stuff asserts otherwise
401 *------------------------------------------------------------------------*/
404 ClearCallBack(struct rx_connection *a_conn,
405 struct AFSFid *a_fid)
409 struct VenusFid localFid;
411 #ifdef AFS_DARWIN80_ENV
415 AFS_STATCNT(ClearCallBack);
420 * XXXX Don't hold any server locks here because of callback protocol XXX
423 localFid.Fid.Volume = a_fid->Volume;
424 localFid.Fid.Vnode = a_fid->Vnode;
425 localFid.Fid.Unique = a_fid->Unique;
428 * Volume ID of zero means don't do anything.
430 if (a_fid->Volume != 0) {
431 if (a_fid->Vnode == 0) {
432 struct afs_q *tq, *uq;
434 * Clear callback for the whole volume. Zip through the
435 * hash chain, nullifying entries whose volume ID matches.
438 ObtainReadLock(&afs_xvcache);
439 i = VCHashV(&localFid);
440 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
443 if (tvc->f.fid.Fid.Volume == a_fid->Volume) {
444 tvc->callback = NULL;
446 localFid.Cell = tvc->f.fid.Cell;
447 tvc->dchint = NULL; /* invalidate hints */
448 if (tvc->f.states & CVInit) {
449 ReleaseReadLock(&afs_xvcache);
450 afs_osi_Sleep(&tvc->f.states);
453 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
456 #ifdef AFS_DARWIN80_ENV
457 if (tvc->f.states & CDeadVnode) {
458 ReleaseReadLock(&afs_xvcache);
459 afs_osi_Sleep(&tvc->f.states);
475 ReleaseReadLock(&afs_xvcache);
476 ObtainWriteLock(&afs_xcbhash, 449);
477 afs_DequeueCallback(tvc);
478 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
480 if (tvc->f.fid.Fid.Vnode & 1)
484 ReleaseWriteLock(&afs_xcbhash);
485 if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
486 osi_dnlc_purgedp(tvc);
487 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
488 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
489 tvc->f.states, ICL_TYPE_INT32,
491 #ifdef AFS_DARWIN80_ENV
492 vnode_put(AFSTOV(tvc));
494 ObtainReadLock(&afs_xvcache);
497 } else if ((tvc->f.states & CMValid)
498 && (tvc->mvid->Fid.Volume == a_fid->Volume)) {
499 tvc->f.states &= ~CMValid;
501 localFid.Cell = tvc->mvid->Cell;
504 ReleaseReadLock(&afs_xvcache);
507 * XXXX Don't hold any locks here XXXX
509 tv = afs_FindVolume(&localFid, 0);
511 afs_ResetVolumeInfo(tv);
512 afs_PutVolume(tv, 0);
513 /* invalidate mtpoint? */
515 } /*Clear callbacks for whole volume */
518 * Clear callbacks just for the one file.
522 if (a_fid->Vnode & 1)
523 afs_oddCBs++; /*Could do this on volume basis, too */
525 afs_evenCBs++; /*A particular fid was specified */
527 ObtainReadLock(&afs_xvcache);
528 i = VCHash(&localFid);
529 for (tvc = afs_vhashT[i]; tvc; tvc = uvc) {
531 if (tvc->f.fid.Fid.Vnode == a_fid->Vnode
532 && tvc->f.fid.Fid.Volume == a_fid->Volume
533 && tvc->f.fid.Fid.Unique == a_fid->Unique) {
534 tvc->callback = NULL;
535 tvc->dchint = NULL; /* invalidate hints */
536 if (tvc->f.states & CVInit) {
537 ReleaseReadLock(&afs_xvcache);
538 afs_osi_Sleep(&tvc->f.states);
541 #if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_HPUX_ENV) || defined(AFS_LINUX20_ENV)
544 #ifdef AFS_DARWIN80_ENV
545 if (tvc->f.states & CDeadVnode) {
546 ReleaseReadLock(&afs_xvcache);
547 afs_osi_Sleep(&tvc->f.states);
563 ReleaseReadLock(&afs_xvcache);
564 ObtainWriteLock(&afs_xcbhash, 450);
565 afs_DequeueCallback(tvc);
566 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
567 ReleaseWriteLock(&afs_xcbhash);
568 if ((tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR)))
569 osi_dnlc_purgedp(tvc);
570 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
571 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
572 tvc->f.states, ICL_TYPE_LONG, 0);
574 lastCallBack_vnode = afid->Vnode;
575 lastCallBack_dv = tvc->mstat.DataVersion.low;
576 osi_GetuTime(&lastCallBack_time);
578 #ifdef AFS_DARWIN80_ENV
579 vnode_put(AFSTOV(tvc));
581 ObtainReadLock(&afs_xvcache);
585 } /*Walk through hash table */
586 ReleaseReadLock(&afs_xvcache);
587 } /*Clear callbacks for one file */
590 /*Fid has non-zero volume ID */
592 * Always return a predictable value.
599 /*------------------------------------------------------------------------
600 * EXPORTED SRXAFSCB_CallBack
603 * Routine called by the server-side callback RPC interface to
604 * implement passing in callback information.
608 * a_call : Ptr to Rx call on which this request came in.
609 * a_fids : Ptr to array of fids involved.
610 * a_callbacks : Ptr to matching callback info for the fids.
616 * Nothing interesting.
620 *------------------------------------------------------------------------*/
623 SRXAFSCB_CallBack(struct rx_call *a_call, struct AFSCBFids *a_fids,
624 struct AFSCBs *a_callbacks)
626 int i; /*Loop variable */
627 struct AFSFid *tfid; /*Ptr to current fid */
628 struct rx_connection *tconn; /*Call's connection */
634 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_CALLBACK);
636 AFS_STATCNT(SRXAFSCB_CallBack);
637 if (!(tconn = rx_ConnectionOf(a_call)))
639 tfid = (struct AFSFid *)a_fids->AFSCBFids_val;
642 * For now, we ignore callbacks, since the File Server only *breaks*
643 * callbacks at present.
645 for (i = 0; i < a_fids->AFSCBFids_len; i++)
646 ClearCallBack(tconn, &tfid[i]);
654 } /*SRXAFSCB_CallBack */
657 /*------------------------------------------------------------------------
658 * EXPORTED SRXAFSCB_Probe
661 * Routine called by the server-side callback RPC interface to
662 * implement ``probing'' the Cache Manager, just making sure it's
666 * a_call : Ptr to Rx call on which this request came in.
672 * Nothing interesting.
676 *------------------------------------------------------------------------*/
679 SRXAFSCB_Probe(struct rx_call *a_call)
685 AFS_STATCNT(SRXAFSCB_Probe);
687 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
694 } /*SRXAFSCB_Probe */
697 /*------------------------------------------------------------------------
698 * EXPORTED SRXAFSCB_InitCallBackState
701 * Routine called by the server-side callback RPC interface to
702 * implement clearing all callbacks from this host.
705 * a_call : Ptr to Rx call on which this request came in.
711 * Nothing interesting.
715 *------------------------------------------------------------------------*/
718 SRXAFSCB_InitCallBackState(struct rx_call *a_call)
722 struct rx_connection *tconn;
723 struct rx_peer *peer;
730 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_INITCALLBACKSTATE);
731 AFS_STATCNT(SRXAFSCB_InitCallBackState);
734 * Find the address of the host making this call
736 if ((tconn = rx_ConnectionOf(a_call)) && (peer = rx_PeerOf(tconn))) {
739 afs_oddCBs++; /*Including any missed via create race */
740 afs_evenCBs++; /*Including any missed via create race */
742 ts = afs_FindServer(rx_HostOf(peer), rx_PortOf(peer), (afsUUID *) 0,
745 for (i = 0; i < VCSIZE; i++)
746 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
747 if (tvc->callback == ts) {
748 ObtainWriteLock(&afs_xcbhash, 451);
749 afs_DequeueCallback(tvc);
750 tvc->callback = NULL;
751 tvc->f.states &= ~(CStatd | CUnique | CBulkFetching);
752 ReleaseWriteLock(&afs_xcbhash);
756 /* capabilities need be requested again */
757 ts->flags &= ~SCAPS_KNOWN;
762 /* find any volumes residing on this server and flush their state */
767 for (i = 0; i < NVOLS; i++)
768 for (tv = afs_volumes[i]; tv; tv = tv->next) {
769 for (j = 0; j < AFS_MAXHOSTS; j++)
770 if (tv->serverHost[j] == ts)
771 afs_ResetVolumeInfo(tv);
774 osi_dnlc_purge(); /* may be a little bit extreme */
783 } /*SRXAFSCB_InitCallBackState */
786 /*------------------------------------------------------------------------
787 * EXPORTED SRXAFSCB_XStatsVersion
790 * Routine called by the server-side callback RPC interface to
791 * implement pulling out the xstat version number for the Cache
795 * a_versionP : Ptr to the version number variable to set.
801 * Nothing interesting.
805 *------------------------------------------------------------------------*/
808 SRXAFSCB_XStatsVersion(struct rx_call *a_call, afs_int32 * a_versionP)
815 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_XSTATSVERSION);
817 *a_versionP = AFSCB_XSTAT_VERSION;
824 } /*SRXAFSCB_XStatsVersion */
827 /*------------------------------------------------------------------------
828 * EXPORTED SRXAFSCB_GetXStats
831 * Routine called by the server-side callback RPC interface to
832 * implement getting the given data collection from the extended
833 * Cache Manager statistics.
836 * a_call : Ptr to Rx call on which this request came in.
837 * a_clientVersionNum : Client version number.
838 * a_opCode : Desired operation.
839 * a_serverVersionNumP : Ptr to version number to set.
840 * a_timeP : Ptr to time value (seconds) to set.
841 * a_dataArray : Ptr to variable array structure to return
848 * Nothing interesting.
852 *------------------------------------------------------------------------*/
855 SRXAFSCB_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
856 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
857 afs_int32 * a_timeP, AFSCB_CollData * a_dataP)
859 int code; /*Return value */
860 afs_int32 *dataBuffP; /*Ptr to data to be returned */
861 afs_int32 dataBytes; /*Bytes in data buffer */
866 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETXSTATS);
869 * Record the time of day and the server version number.
871 *a_srvVersionNumP = AFSCB_XSTAT_VERSION;
872 *a_timeP = osi_Time();
875 * Stuff the appropriate data in there (assume victory)
881 * We're not keeping stats, so just return successfully with
884 a_dataP->AFSCB_CollData_len = 0;
885 a_dataP->AFSCB_CollData_val = NULL;
887 switch (a_collectionNumber) {
888 case AFSCB_XSTATSCOLL_CALL_INFO:
890 * Pass back all the call-count-related data.
892 * >>> We are forced to allocate a separate area in which to
893 * >>> put this stuff in by the RPC stub generator, since it
894 * >>> will be freed at the tail end of the server stub code.
896 dataBytes = sizeof(struct afs_CMStats);
897 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
898 osi_Assert(dataBuffP != NULL);
899 memcpy((char *)dataBuffP, (char *)&afs_cmstats, dataBytes);
900 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
901 a_dataP->AFSCB_CollData_val = dataBuffP;
904 case AFSCB_XSTATSCOLL_PERF_INFO:
906 * Update and then pass back all the performance-related data.
907 * Note: the only performance fields that need to be computed
908 * at this time are the number of accesses for this collection
909 * and the current server record info.
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 afs_stats_cmperf.numPerfCalls++;
917 dataBytes = sizeof(afs_stats_cmperf);
918 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
919 osi_Assert(dataBuffP != NULL);
920 memcpy((char *)dataBuffP, (char *)&afs_stats_cmperf, dataBytes);
921 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
922 a_dataP->AFSCB_CollData_val = dataBuffP;
925 case AFSCB_XSTATSCOLL_FULL_PERF_INFO:
927 * Pass back the full range of performance and statistical
928 * data available. We have to bring the normal performance
929 * data collection up to date, then copy that data into
930 * the full collection.
932 * >>> We are forced to allocate a separate area in which to
933 * >>> put this stuff in by the RPC stub generator, since it
934 * >>> will be freed at the tail end of the server stub code.
936 afs_stats_cmperf.numPerfCalls++;
938 memcpy((char *)(&(afs_stats_cmfullperf.perf)),
939 (char *)(&afs_stats_cmperf), sizeof(struct afs_stats_CMPerf));
940 afs_stats_cmfullperf.numFullPerfCalls++;
942 dataBytes = sizeof(afs_stats_cmfullperf);
943 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
944 osi_Assert(dataBuffP != NULL);
945 memcpy((char *)dataBuffP, (char *)(&afs_stats_cmfullperf), dataBytes);
946 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
947 a_dataP->AFSCB_CollData_val = dataBuffP;
952 * Illegal collection number.
954 a_dataP->AFSCB_CollData_len = 0;
955 a_dataP->AFSCB_CollData_val = NULL;
957 } /*Switch on collection number */
958 #endif /* AFS_NOSTATS */
966 } /*SRXAFSCB_GetXStats */
969 /*------------------------------------------------------------------------
970 * EXPORTED afs_RXCallBackServer
973 * Body of the thread supporting callback services.
982 * Nothing interesting.
986 *------------------------------------------------------------------------*/
989 afs_RXCallBackServer(void)
991 AFS_STATCNT(afs_RXCallBackServer);
996 afs_osi_Sleep(&afs_server);
1000 * Donate this process to Rx.
1002 rx_ServerProc(NULL);
1005 } /*afs_RXCallBackServer */
1008 /*------------------------------------------------------------------------
1009 * EXPORTED shutdown_CB
1012 * Zero out important Cache Manager data structures.
1021 * Nothing interesting.
1025 *------------------------------------------------------------------------*/
1030 AFS_STATCNT(shutdown_CB);
1032 if (afs_cold_shutdown) {
1033 afs_oddCBs = afs_evenCBs = afs_allCBs = afs_allZaps = afs_oddZaps =
1034 afs_evenZaps = afs_connectBacks = 0;
1041 /*------------------------------------------------------------------------
1042 * EXPORTED SRXAFSCB_InitCallBackState2
1045 * This routine was used in the AFS 3.5 beta release, but not anymore.
1046 * It has since been replaced by SRXAFSCB_InitCallBackState3.
1049 * a_call : Ptr to Rx call on which this request came in.
1052 * RXGEN_OPCODE (always).
1055 * Nothing interesting.
1059 *------------------------------------------------------------------------*/
1062 SRXAFSCB_InitCallBackState2(struct rx_call *a_call,
1063 struct interfaceAddr *addr)
1065 return RXGEN_OPCODE;
1068 /*------------------------------------------------------------------------
1069 * EXPORTED SRXAFSCB_WhoAreYou
1072 * Routine called by the server-side callback RPC interface to
1073 * obtain a unique identifier for the client. The server uses
1074 * this identifier to figure out whether or not two RX connections
1075 * are from the same client, and to find out which addresses go
1076 * with which clients.
1079 * a_call : Ptr to Rx call on which this request came in.
1080 * addr: Ptr to return the list of interfaces for this client.
1086 * Nothing interesting.
1090 *------------------------------------------------------------------------*/
1093 SRXAFSCB_WhoAreYou(struct rx_call *a_call, struct interfaceAddr *addr)
1100 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1102 memset(addr, 0, sizeof(*addr));
1104 ObtainReadLock(&afs_xinterface);
1106 /* return all network interface addresses */
1107 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1108 addr->uuid = afs_cb_interface.uuid;
1109 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1110 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1111 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1112 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1115 ReleaseReadLock(&afs_xinterface);
1123 /*------------------------------------------------------------------------
1124 * EXPORTED SRXAFSCB_InitCallBackState3
1127 * Routine called by the server-side callback RPC interface to
1128 * implement clearing all callbacks from this host.
1131 * a_call : Ptr to Rx call on which this request came in.
1137 * Nothing interesting.
1141 *------------------------------------------------------------------------*/
1144 SRXAFSCB_InitCallBackState3(struct rx_call *a_call, afsUUID * a_uuid)
1149 * TBD: Lookup the server by the UUID instead of its IP address.
1151 code = SRXAFSCB_InitCallBackState(a_call);
1157 /*------------------------------------------------------------------------
1158 * EXPORTED SRXAFSCB_ProbeUuid
1161 * Routine called by the server-side callback RPC interface to
1162 * implement ``probing'' the Cache Manager, just making sure it's
1163 * still there is still the same client it used to be.
1166 * a_call : Ptr to Rx call on which this request came in.
1167 * a_uuid : Ptr to UUID that must match the client's UUID.
1170 * 0 if a_uuid matches the UUID for this client
1171 * Non-zero otherwize
1174 * Nothing interesting.
1178 *------------------------------------------------------------------------*/
1181 SRXAFSCB_ProbeUuid(struct rx_call *a_call, afsUUID * a_uuid)
1187 AFS_STATCNT(SRXAFSCB_Probe);
1189 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
1190 if (!afs_uuid_equal(a_uuid, &afs_cb_interface.uuid))
1191 code = 1; /* failure */
1200 /*------------------------------------------------------------------------
1201 * EXPORTED SRXAFSCB_GetServerPrefs
1204 * Routine to list server preferences used by this client.
1207 * a_call : Ptr to Rx call on which this request came in.
1208 * a_index : Input server index
1209 * a_srvr_addr : Output server address in host byte order
1210 * (0xffffffff on last server)
1211 * a_srvr_rank : Output server rank
1217 * Nothing interesting.
1221 *------------------------------------------------------------------------*/
1224 SRXAFSCB_GetServerPrefs(struct rx_call *a_call, afs_int32 a_index,
1225 afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank)
1231 AFS_STATCNT(SRXAFSCB_GetServerPrefs);
1233 ObtainReadLock(&afs_xserver);
1235 /* Search the hash table for the server with this index */
1236 *a_srvr_addr = 0xffffffff;
1237 *a_srvr_rank = 0xffffffff;
1238 for (i = 0, j = 0; j < NSERVERS && i <= a_index; j++) {
1239 for (sa = afs_srvAddrs[j]; sa && i <= a_index; sa = sa->next_bkt, i++) {
1241 *a_srvr_addr = ntohl(sa->sa_ip);
1242 *a_srvr_rank = sa->sa_iprank;
1247 ReleaseReadLock(&afs_xserver);
1255 /*------------------------------------------------------------------------
1256 * EXPORTED SRXAFSCB_GetCellServDB
1259 * Routine to list cells configured for this client
1262 * a_call : Ptr to Rx call on which this request came in.
1263 * a_index : Input cell index
1264 * a_name : Output cell name ("" on last cell)
1265 * a_hosts : Output cell database servers in host byte order.
1271 * Nothing interesting.
1275 *------------------------------------------------------------------------*/
1278 SRXAFSCB_GetCellServDB(struct rx_call *a_call, afs_int32 a_index,
1279 char **a_name, serverList * a_hosts)
1283 char *t_name, *p_name = NULL;
1286 AFS_STATCNT(SRXAFSCB_GetCellServDB);
1288 tcell = afs_GetCellByIndex(a_index, READ_LOCK);
1292 a_hosts->serverList_val = 0;
1293 a_hosts->serverList_len = 0;
1295 p_name = tcell->cellName;
1296 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++);
1298 a_hosts->serverList_val = afs_osi_Alloc(j * sizeof(afs_int32));
1299 osi_Assert(a_hosts->serverList_val != NULL);
1300 a_hosts->serverList_len = j;
1301 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++)
1302 a_hosts->serverList_val[j] =
1303 ntohl(tcell->cellHosts[j]->addr->sa_ip);
1304 afs_PutCell(tcell, READ_LOCK);
1307 t_name = afs_osi_Alloc(i + 1);
1308 if (t_name == NULL) {
1310 afs_osi_Free(a_hosts->serverList_val, (j * sizeof(afs_int32)));
1317 memcpy(t_name, p_name, i);
1326 /*------------------------------------------------------------------------
1327 * EXPORTED SRXAFSCB_GetLocalCell
1330 * Routine to return name of client's local cell
1333 * a_call : Ptr to Rx call on which this request came in.
1334 * a_name : Output cell name
1340 * Nothing interesting.
1344 *------------------------------------------------------------------------*/
1347 SRXAFSCB_GetLocalCell(struct rx_call *a_call, char **a_name)
1351 char *t_name, *p_name = NULL;
1354 AFS_STATCNT(SRXAFSCB_GetLocalCell);
1356 /* Search the list for the primary cell. Cell number 1 is only
1357 * the primary cell is when no other cell is explicitly marked as
1358 * the primary cell. */
1359 tcell = afs_GetPrimaryCell(READ_LOCK);
1361 p_name = tcell->cellName;
1363 plen = strlen(p_name);
1366 t_name = afs_osi_Alloc(plen + 1);
1367 if (t_name == NULL) {
1369 afs_PutCell(tcell, READ_LOCK);
1374 t_name[plen] = '\0';
1376 memcpy(t_name, p_name, plen);
1382 afs_PutCell(tcell, READ_LOCK);
1388 * afs_MarshallCacheConfig - marshall client cache configuration
1392 * IN callerVersion - the rpc stat version of the caller.
1394 * IN config - client cache configuration.
1396 * OUT ptr - buffer where configuration is marshalled.
1403 afs_MarshallCacheConfig(afs_uint32 callerVersion, cm_initparams_v1 * config,
1406 AFS_STATCNT(afs_MarshallCacheConfig);
1408 * We currently only support version 1.
1410 *(ptr++) = config->nChunkFiles;
1411 *(ptr++) = config->nStatCaches;
1412 *(ptr++) = config->nDataCaches;
1413 *(ptr++) = config->nVolumeCaches;
1414 *(ptr++) = config->firstChunkSize;
1415 *(ptr++) = config->otherChunkSize;
1416 *(ptr++) = config->cacheSize;
1417 *(ptr++) = config->setTime;
1418 *(ptr++) = config->memCache;
1422 /*------------------------------------------------------------------------
1423 * EXPORTED SRXAFSCB_GetCacheConfig
1426 * Routine to return parameters used to initialize client cache.
1427 * Client may request any format version. Server may not return
1428 * format version greater than version requested by client.
1431 * a_call: Ptr to Rx call on which this request came in.
1432 * callerVersion: Data format version desired by the client.
1433 * serverVersion: Data format version of output data.
1434 * configCount: Number bytes allocated for output data.
1435 * config: Client cache configuration.
1441 * Nothing interesting.
1445 *------------------------------------------------------------------------*/
1448 SRXAFSCB_GetCacheConfig(struct rx_call *a_call, afs_uint32 callerVersion,
1449 afs_uint32 * serverVersion, afs_uint32 * configCount,
1450 cacheConfig * config)
1452 afs_uint32 *t_config;
1454 cm_initparams_v1 cm_config;
1457 AFS_STATCNT(SRXAFSCB_GetCacheConfig);
1460 * Currently only support version 1
1462 allocsize = sizeof(cm_initparams_v1);
1463 t_config = afs_osi_Alloc(allocsize);
1464 if (t_config == NULL) {
1469 cm_config.nChunkFiles = cm_initParams.cmi_nChunkFiles;
1470 cm_config.nStatCaches = cm_initParams.cmi_nStatCaches;
1471 cm_config.nDataCaches = cm_initParams.cmi_nDataCaches;
1472 cm_config.nVolumeCaches = cm_initParams.cmi_nVolumeCaches;
1473 cm_config.firstChunkSize = cm_initParams.cmi_firstChunkSize;
1474 cm_config.otherChunkSize = cm_initParams.cmi_otherChunkSize;
1475 cm_config.cacheSize = cm_initParams.cmi_cacheSize;
1476 cm_config.setTime = cm_initParams.cmi_setTime;
1477 cm_config.memCache = cm_initParams.cmi_memCache;
1479 afs_MarshallCacheConfig(callerVersion, &cm_config, t_config);
1481 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1482 *configCount = allocsize;
1483 config->cacheConfig_val = t_config;
1484 config->cacheConfig_len = allocsize / sizeof(afs_uint32);
1491 /*------------------------------------------------------------------------
1492 * EXPORTED SRXAFSCB_FetchData
1495 * Routine to do third party move from a remioserver to the original
1496 * issuer of an ArchiveData request. Presently supported only by the
1497 * "fs" command, not by the AFS client.
1500 * rxcall: Ptr to Rx call on which this request came in.
1501 * Fid: pointer to AFSFid structure.
1502 * Fd: File descriptor inside fs command.
1503 * Position: Offset in the file.
1504 * Length: Data length to transfer.
1505 * TotalLength: Pointer to total file length field
1511 * Nothing interesting.
1514 *------------------------------------------------------------------------*/
1516 SRXAFSCB_FetchData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1517 afs_int64 Position, afs_int64 Length,
1518 afs_int64 * TotalLength)
1523 /*------------------------------------------------------------------------
1524 * EXPORTED SRXAFSCB_StoreData
1527 * Routine to do third party move from a remioserver to the original
1528 * issuer of a RetrieveData request. Presently supported only by the
1529 * "fs" command, not by the AFS client.
1532 * rxcall: Ptr to Rx call on which this request came in.
1533 * Fid: pointer to AFSFid structure.
1534 * Fd: File descriptor inside fs command.
1535 * Position: Offset in the file.
1536 * Length: Data length to transfer.
1537 * TotalLength: Pointer to total file length field
1543 * Nothing interesting.
1547 *------------------------------------------------------------------------*/
1549 SRXAFSCB_StoreData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1550 afs_int64 Position, afs_int64 Length,
1551 afs_int64 * TotalLength)
1556 /*------------------------------------------------------------------------
1557 * EXPORTED SRXAFSCB_GetCellByNum
1560 * Routine to get information about a cell specified by its
1561 * cell number (returned by GetCE/GetCE64).
1564 * a_call : Ptr to Rx call on which this request came in.
1565 * a_cellnum : Input cell number
1566 * a_name : Output cell name (one zero byte when no such cell).
1567 * a_hosts : Output cell database servers in host byte order.
1573 * Nothing interesting.
1577 *------------------------------------------------------------------------*/
1580 SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum,
1581 char **a_name, serverList * a_hosts)
1587 AFS_STATCNT(SRXAFSCB_GetCellByNum);
1589 a_hosts->serverList_val = 0;
1590 a_hosts->serverList_len = 0;
1592 tcell = afs_GetCellStale(a_cellnum, READ_LOCK);
1594 *a_name = afs_strdup("");
1599 ObtainReadLock(&tcell->lock);
1600 *a_name = afs_strdup(tcell->cellName);
1602 for (sn = 0; sn < AFSMAXCELLHOSTS && tcell->cellHosts[sn]; sn++);
1603 a_hosts->serverList_len = sn;
1604 a_hosts->serverList_val = afs_osi_Alloc(sn * sizeof(afs_int32));
1605 osi_Assert(a_hosts->serverList_val != NULL);
1607 for (i = 0; i < sn; i++)
1608 a_hosts->serverList_val[i] = ntohl(tcell->cellHosts[i]->addr->sa_ip);
1609 ReleaseReadLock(&tcell->lock);
1610 afs_PutCell(tcell, READ_LOCK);
1617 SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call,
1618 struct interfaceAddr *addr,
1619 Capabilities * capabilities)
1623 afs_uint32 *dataBuffP;
1624 afs_int32 dataBytes;
1628 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1630 ObtainReadLock(&afs_xinterface);
1632 /* return all network interface addresses */
1633 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1634 addr->uuid = afs_cb_interface.uuid;
1635 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1636 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1637 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1638 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1641 ReleaseReadLock(&afs_xinterface);
1645 dataBytes = 1 * sizeof(afs_uint32);
1646 dataBuffP = afs_osi_Alloc(dataBytes);
1647 osi_Assert(dataBuffP != NULL);
1648 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1649 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1650 capabilities->Capabilities_val = dataBuffP;
1656 #if 0 && defined(AFS_LINUX24_ENV)
1657 extern struct vcache *afs_globalVp;
1659 int recurse_dcache_parent(parent, a_index, addr, inode, flags, time, fileName)
1660 struct dentry * parent;
1668 struct dentry *this_parent = parent;
1669 struct list_head *next;
1671 struct dentry *dentry;
1674 next = this_parent->d_subdirs.next;
1676 while (next != &this_parent->d_subdirs) {
1677 struct list_head *tmp = next;
1678 dentry = list_entry(tmp, struct dentry, d_child);
1684 * Descend a level if the d_subdirs list is non-empty.
1686 if (!list_empty(&dentry->d_subdirs)) {
1687 this_parent = dentry;
1692 * All done at this level ... ascend and resume the search.
1694 if (this_parent != parent) {
1695 next = this_parent->d_child.next;
1696 this_parent = this_parent->d_parent;
1702 if (d_unhashed(dentry))
1707 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1708 *inode = ITOAFS(dentry->d_inode);
1709 *addr = atomic_read(&(dentry)->d_count);
1710 *time = dentry->d_time;
1719 SRXAFSCB_GetDE(struct rx_call *a_call, afs_int32 a_index, afs_int32 *addr,
1720 afs_int32 *inode, afs_int32 *flags, afs_int32 *time,
1722 { /*SRXAFSCB_GetDE*/
1723 int code = 0; /*Return code*/
1724 #if 0 && defined(AFS_LINUX24_ENV)
1725 int i; /*Loop variable*/
1726 struct vcache *tvc = afs_globalVp;
1727 struct dentry *dentry;
1728 struct list_head *cur, *head = &(AFSTOI(tvc))->i_dentry;
1730 #ifdef RX_ENABLE_LOCKS
1732 #endif /* RX_ENABLE_LOCKS */
1734 #if defined(AFS_LINUX24_ENV)
1735 spin_lock(&dcache_lock);
1739 while ((cur = cur->next) != head) {
1740 dentry = list_entry(cur, struct dentry, d_alias);
1742 dget_locked(dentry);
1744 #if defined(AFS_LINUX24_ENV)
1745 spin_unlock(&dcache_lock);
1751 if (recurse_dcache_parent(dentry, a_index, addr, inode, flags, time, fileName) == 0) {
1762 *fileName = afs_strdup("");
1766 if (d_unhashed(dentry))
1771 *fileName = afs_strdup(dentry->d_name.name?dentry->d_name.name:"");
1772 *inode = ITOAFS(dentry->d_inode);
1773 *addr = atomic_read(&(dentry)->d_count);
1774 *time = dentry->d_time;
1781 #ifdef RX_ENABLE_LOCKS
1783 #endif /* RX_ENABLE_LOCKS */
1787 } /*SRXAFSCB_GetDE*/