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},
56 "afs_xsrvAddr", (char *)&afs_xsrvAddr},
58 "afs_xvreclaim", (char *)&afs_xvreclaim},
59 { "afsdb_client_lock", (char *)&afsdb_client_lock},
60 { "afsdb_req_lock", (char *)&afsdb_req_lock},
61 { "afs_discon_lock", (char *)&afs_discon_lock},
62 { "afs_disconDirtyLock", (char *)&afs_disconDirtyLock},
63 { "afs_discon_vc_dirty", (char *)&afs_xvcdirty},
64 { "afs_dynrootDirLock", (char *)&afs_dynrootDirLock},
65 { "afs_dynSymlinkLock", (char *)&afs_dynSymlinkLock},
67 unsigned long lastCallBack_vnode;
68 unsigned int lastCallBack_dv;
69 osi_timeval32_t lastCallBack_time;
71 /* these are for storing alternate interface addresses */
72 struct interfaceAddr afs_cb_interface;
74 /*------------------------------------------------------------------------
75 * EXPORTED SRXAFSCB_GetCE
78 * Routine called by the server-side callback RPC interface to
79 * implement pulling out the contents of the i'th cache entry.
82 * a_call : Ptr to Rx call on which this request came in.
83 * a_index : Index of desired cache entry.
84 * a_result : Ptr to a buffer for the given cache entry.
87 * 0 if everything went fine,
88 * 1 if we were given a bad index.
91 * Nothing interesting.
95 *------------------------------------------------------------------------*/
98 SRXAFSCB_GetCE(struct rx_call *a_call, afs_int32 a_index,
99 struct AFSDBCacheEntry *a_result)
102 int i; /*Loop variable */
103 struct vcache *tvc; /*Ptr to current cache entry */
104 int code; /*Return code */
109 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE);
111 AFS_STATCNT(SRXAFSCB_GetCE);
112 for (i = 0; i < VCSIZE; i++) {
113 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
117 } /*Zip through current hash chain */
118 } /*Zip through hash chains */
128 * Copy out the located entry.
130 a_result->addr = afs_data_pointer_to_int32(tvc);
131 a_result->cell = tvc->f.fid.Cell;
132 a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
133 a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
134 a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
135 a_result->lock.waitStates = tvc->lock.wait_states;
136 a_result->lock.exclLocked = tvc->lock.excl_locked;
137 a_result->lock.readersReading = tvc->lock.readers_reading;
138 a_result->lock.numWaiting = tvc->lock.num_waiting;
139 #if defined(INSTRUMENT_LOCKS)
140 a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
141 a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
142 a_result->lock.src_indicator = tvc->lock.src_indicator;
144 /* On osf20 , the vcache does not maintain these three fields */
145 a_result->lock.pid_last_reader = 0;
146 a_result->lock.pid_writer = 0;
147 a_result->lock.src_indicator = 0;
148 #endif /* INSTRUMENT_LOCKS */
149 #ifdef AFS_64BIT_CLIENT
150 a_result->Length = (afs_int32) tvc->f.m.Length & 0xffffffff;
151 #else /* AFS_64BIT_CLIENT */
152 a_result->Length = tvc->f.m.Length;
153 #endif /* AFS_64BIT_CLIENT */
154 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
155 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
156 a_result->cbExpires = tvc->cbExpires;
157 if (tvc->f.states & CVInit) {
158 a_result->refCount = 1;
160 #ifdef AFS_DARWIN80_ENV
161 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
163 a_result->refCount = VREFCOUNT(tvc);
166 a_result->opens = tvc->opens;
167 a_result->writers = tvc->execsOrWriters;
168 a_result->mvstat = tvc->mvstat;
169 a_result->states = tvc->f.states;
173 * Return our results.
182 } /*SRXAFSCB_GetCE */
185 SRXAFSCB_GetCE64(struct rx_call *a_call, afs_int32 a_index,
186 struct AFSDBCacheEntry64 *a_result)
188 int i; /*Loop variable */
189 struct vcache *tvc; /*Ptr to current cache entry */
190 int code; /*Return code */
195 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETCE);
197 AFS_STATCNT(SRXAFSCB_GetCE64);
198 for (i = 0; i < VCSIZE; i++) {
199 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
203 } /*Zip through current hash chain */
204 } /*Zip through hash chains */
214 * Copy out the located entry.
216 a_result->addr = afs_data_pointer_to_int32(tvc);
217 a_result->cell = tvc->f.fid.Cell;
218 a_result->netFid.Volume = tvc->f.fid.Fid.Volume;
219 a_result->netFid.Vnode = tvc->f.fid.Fid.Vnode;
220 a_result->netFid.Unique = tvc->f.fid.Fid.Unique;
221 a_result->lock.waitStates = tvc->lock.wait_states;
222 a_result->lock.exclLocked = tvc->lock.excl_locked;
223 a_result->lock.readersReading = tvc->lock.readers_reading;
224 a_result->lock.numWaiting = tvc->lock.num_waiting;
225 #if defined(INSTRUMENT_LOCKS)
226 a_result->lock.pid_last_reader = MyPidxx2Pid(tvc->lock.pid_last_reader);
227 a_result->lock.pid_writer = MyPidxx2Pid(tvc->lock.pid_writer);
228 a_result->lock.src_indicator = tvc->lock.src_indicator;
230 /* On osf20 , the vcache does not maintain these three fields */
231 a_result->lock.pid_last_reader = 0;
232 a_result->lock.pid_writer = 0;
233 a_result->lock.src_indicator = 0;
234 #endif /* INSTRUMENT_LOCKS */
235 a_result->Length = tvc->f.m.Length;
236 a_result->DataVersion = hgetlo(tvc->f.m.DataVersion);
237 a_result->callback = afs_data_pointer_to_int32(tvc->callback); /* XXXX Now a pointer; change it XXXX */
238 a_result->cbExpires = tvc->cbExpires;
239 if (tvc->f.states & CVInit) {
240 a_result->refCount = 1;
242 #ifdef AFS_DARWIN80_ENV
243 a_result->refCount = vnode_isinuse(AFSTOV(tvc),0)?1:0; /* XXX fix */
245 a_result->refCount = VREFCOUNT(tvc);
248 a_result->opens = tvc->opens;
249 a_result->writers = tvc->execsOrWriters;
250 a_result->mvstat = tvc->mvstat;
251 a_result->states = tvc->f.states;
255 * Return our results.
264 } /*SRXAFSCB_GetCE64 */
267 /*------------------------------------------------------------------------
268 * EXPORTED SRXAFSCB_GetLock
271 * Routine called by the server-side callback RPC interface to
272 * implement pulling out the contents of a lock in the lock
276 * a_call : Ptr to Rx call on which this request came in.
277 * a_index : Index of desired lock.
278 * a_result : Ptr to a buffer for the given lock.
281 * 0 if everything went fine,
282 * 1 if we were given a bad index.
285 * Nothing interesting.
289 *------------------------------------------------------------------------*/
292 SRXAFSCB_GetLock(struct rx_call *a_call, afs_int32 a_index,
293 struct AFSDBLock *a_result)
295 struct ltable *tl; /*Ptr to lock table entry */
296 int nentries; /*Num entries in table */
297 int code; /*Return code */
302 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETLOCK);
304 AFS_STATCNT(SRXAFSCB_GetLock);
305 memset(a_result, 0, sizeof(*a_result));
306 nentries = sizeof(ltable) / sizeof(struct ltable);
307 if (a_index < 0 || a_index >= nentries+afs_cellindex) {
312 } else if (a_index >= nentries) {
313 struct cell *tc = afs_GetCellByIndex(a_index-nentries, 0);
314 strcpy(a_result->name, tc->cellName);
315 a_result->lock.waitStates =
316 ((struct afs_lock *)&(tc->lock))->wait_states;
317 a_result->lock.exclLocked =
318 ((struct afs_lock *)&(tc->lock))->excl_locked;
319 a_result->lock.readersReading =
320 ((struct afs_lock *)&(tc->lock))->readers_reading;
321 a_result->lock.numWaiting =
322 ((struct afs_lock *)&(tc->lock))->num_waiting;
323 #ifdef INSTRUMENT_LOCKS
324 a_result->lock.pid_last_reader =
325 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_last_reader);
326 a_result->lock.pid_writer =
327 MyPidxx2Pid(((struct afs_lock *)&(tc->lock))->pid_writer);
328 a_result->lock.src_indicator =
329 ((struct afs_lock *)&(tc->lock))->src_indicator;
331 a_result->lock.pid_last_reader = 0;
332 a_result->lock.pid_writer = 0;
333 a_result->lock.src_indicator = 0;
338 * Found it - copy out its contents.
340 tl = <able[a_index];
341 strcpy(a_result->name, tl->name);
342 a_result->lock.waitStates =
343 ((struct afs_lock *)(tl->addr))->wait_states;
344 a_result->lock.exclLocked =
345 ((struct afs_lock *)(tl->addr))->excl_locked;
346 a_result->lock.readersReading =
347 ((struct afs_lock *)(tl->addr))->readers_reading;
348 a_result->lock.numWaiting =
349 ((struct afs_lock *)(tl->addr))->num_waiting;
350 #ifdef INSTRUMENT_LOCKS
351 a_result->lock.pid_last_reader =
352 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_last_reader);
353 a_result->lock.pid_writer =
354 MyPidxx2Pid(((struct afs_lock *)(tl->addr))->pid_writer);
355 a_result->lock.src_indicator =
356 ((struct afs_lock *)(tl->addr))->src_indicator;
358 a_result->lock.pid_last_reader = 0;
359 a_result->lock.pid_writer = 0;
360 a_result->lock.src_indicator = 0;
371 } /*SRXAFSCB_GetLock */
374 /*------------------------------------------------------------------------
375 * static ClearCallBack
378 * Clear out callback information for the specified file, or
379 * even a whole volume. Used to worry about callback was from
380 * within the particular cell or not. Now we don't bother with
381 * that anymore; it's not worth the time.
384 * a_conn : Ptr to Rx connection involved.
385 * a_fid : Ptr to AFS fid being cleared.
391 * Nothing interesting.
396 Appears to need to be called with GLOCK held, as the icl_Event4 stuff asserts otherwise
398 *------------------------------------------------------------------------*/
401 ClearCallBack(struct rx_connection *a_conn,
402 struct AFSFid *a_fid)
406 struct VenusFid localFid;
408 #ifdef AFS_DARWIN80_ENV
412 AFS_STATCNT(ClearCallBack);
417 * XXXX Don't hold any server locks here because of callback protocol XXX
420 localFid.Fid.Volume = a_fid->Volume;
421 localFid.Fid.Vnode = a_fid->Vnode;
422 localFid.Fid.Unique = a_fid->Unique;
425 * Volume ID of zero means don't do anything.
427 if (a_fid->Volume != 0) {
428 if (a_fid->Vnode == 0) {
429 struct afs_q *tq, *uq;
431 * Clear callback for the whole volume. Zip through the
432 * hash chain, nullifying entries whose volume ID matches.
435 ObtainReadLock(&afs_xvcache);
436 i = VCHashV(&localFid);
437 for (tq = afs_vhashTV[i].prev; tq != &afs_vhashTV[i]; tq = uq) {
440 if (tvc->f.fid.Fid.Volume == a_fid->Volume) {
441 tvc->callback = NULL;
443 localFid.Cell = tvc->f.fid.Cell;
444 tvc->dchint = NULL; /* invalidate hints */
445 if (tvc->f.states & CVInit) {
446 ReleaseReadLock(&afs_xvcache);
447 afs_osi_Sleep(&tvc->f.states);
450 #ifdef AFS_DARWIN80_ENV
451 if (tvc->f.states & CDeadVnode) {
452 ReleaseReadLock(&afs_xvcache);
453 afs_osi_Sleep(&tvc->f.states);
466 if (osi_vnhold(tvc) != 0) {
470 ReleaseReadLock(&afs_xvcache);
471 afs_StaleVCacheFlags(tvc, 0, CUnique | CBulkFetching);
473 if (tvc->f.fid.Fid.Vnode & 1)
477 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
478 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
479 tvc->f.states, ICL_TYPE_INT32,
481 #ifdef AFS_DARWIN80_ENV
482 vnode_put(AFSTOV(tvc));
484 ObtainReadLock(&afs_xvcache);
487 } else if ((tvc->f.states & CMValid)
488 && (tvc->mvid.target_root->Fid.Volume == a_fid->Volume)) {
489 tvc->f.states &= ~CMValid;
491 localFid.Cell = tvc->mvid.target_root->Cell;
494 ReleaseReadLock(&afs_xvcache);
497 * XXXX Don't hold any locks here XXXX
499 tv = afs_FindVolume(&localFid, 0);
501 afs_ResetVolumeInfo(tv);
502 afs_PutVolume(tv, 0);
503 /* invalidate mtpoint? */
505 } /*Clear callbacks for whole volume */
508 * Clear callbacks just for the one file.
512 if (a_fid->Vnode & 1)
513 afs_oddCBs++; /*Could do this on volume basis, too */
515 afs_evenCBs++; /*A particular fid was specified */
517 ObtainReadLock(&afs_xvcache);
518 i = VCHash(&localFid);
519 for (tvc = afs_vhashT[i]; tvc; tvc = uvc) {
521 if (tvc->f.fid.Fid.Vnode == a_fid->Vnode
522 && tvc->f.fid.Fid.Volume == a_fid->Volume
523 && tvc->f.fid.Fid.Unique == a_fid->Unique) {
524 tvc->callback = NULL;
525 tvc->dchint = NULL; /* invalidate hints */
526 if (tvc->f.states & CVInit) {
527 ReleaseReadLock(&afs_xvcache);
528 afs_osi_Sleep(&tvc->f.states);
531 #ifdef AFS_DARWIN80_ENV
532 if (tvc->f.states & CDeadVnode) {
533 ReleaseReadLock(&afs_xvcache);
534 afs_osi_Sleep(&tvc->f.states);
547 if (osi_vnhold(tvc) != 0) {
551 ReleaseReadLock(&afs_xvcache);
552 afs_StaleVCacheFlags(tvc, 0, CUnique | CBulkFetching);
553 afs_Trace3(afs_iclSetp, CM_TRACE_CALLBACK,
554 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
555 tvc->f.states, ICL_TYPE_LONG, 0);
557 lastCallBack_vnode = afid->Vnode;
558 lastCallBack_dv = tvc->mstat.DataVersion.low;
559 osi_GetTime(&lastCallBack_time);
561 #ifdef AFS_DARWIN80_ENV
562 vnode_put(AFSTOV(tvc));
564 ObtainReadLock(&afs_xvcache);
568 } /*Walk through hash table */
569 ReleaseReadLock(&afs_xvcache);
570 } /*Clear callbacks for one file */
573 /*Fid has non-zero volume ID */
575 * Always return a predictable value.
582 /*------------------------------------------------------------------------
583 * EXPORTED SRXAFSCB_CallBack
586 * Routine called by the server-side callback RPC interface to
587 * implement passing in callback information.
591 * a_call : Ptr to Rx call on which this request came in.
592 * a_fids : Ptr to array of fids involved.
593 * a_callbacks : Ptr to matching callback info for the fids.
599 * Nothing interesting.
603 *------------------------------------------------------------------------*/
606 SRXAFSCB_CallBack(struct rx_call *a_call, struct AFSCBFids *a_fids,
607 struct AFSCBs *a_callbacks)
609 int i; /*Loop variable */
610 struct AFSFid *tfid; /*Ptr to current fid */
611 struct rx_connection *tconn; /*Call's connection */
617 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_CALLBACK);
619 AFS_STATCNT(SRXAFSCB_CallBack);
620 if (!(tconn = rx_ConnectionOf(a_call)))
622 tfid = (struct AFSFid *)a_fids->AFSCBFids_val;
625 * For now, we ignore callbacks, since the File Server only *breaks*
626 * callbacks at present.
628 for (i = 0; i < a_fids->AFSCBFids_len; i++)
629 ClearCallBack(tconn, &tfid[i]);
637 } /*SRXAFSCB_CallBack */
640 /*------------------------------------------------------------------------
641 * EXPORTED SRXAFSCB_Probe
644 * Routine called by the server-side callback RPC interface to
645 * implement ``probing'' the Cache Manager, just making sure it's
649 * a_call : Ptr to Rx call on which this request came in.
655 * Nothing interesting.
659 *------------------------------------------------------------------------*/
662 SRXAFSCB_Probe(struct rx_call *a_call)
668 AFS_STATCNT(SRXAFSCB_Probe);
670 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
677 } /*SRXAFSCB_Probe */
680 /*------------------------------------------------------------------------
681 * EXPORTED SRXAFSCB_InitCallBackState
684 * Routine called by the server-side callback RPC interface to
685 * implement clearing all callbacks from this host.
688 * a_call : Ptr to Rx call on which this request came in.
694 * Nothing interesting.
698 *------------------------------------------------------------------------*/
701 SRXAFSCB_InitCallBackState(struct rx_call *a_call)
705 struct rx_connection *tconn;
706 struct rx_peer *peer;
713 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_INITCALLBACKSTATE);
714 AFS_STATCNT(SRXAFSCB_InitCallBackState);
717 * Find the address of the host making this call
719 if ((tconn = rx_ConnectionOf(a_call)) && (peer = rx_PeerOf(tconn))) {
722 afs_oddCBs++; /*Including any missed via create race */
723 afs_evenCBs++; /*Including any missed via create race */
725 ts = afs_FindServer(rx_HostOf(peer), rx_PortOf(peer), (afsUUID *) 0,
728 for (i = 0; i < VCSIZE; i++)
729 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
730 if (tvc->callback == ts) {
731 afs_StaleVCacheFlags(tvc, AFS_STALEVC_NODNLC |
733 CUnique | CBulkFetching);
737 /* capabilities need be requested again */
738 ts->flags &= ~SCAPS_KNOWN;
743 /* find any volumes residing on this server and flush their state */
748 for (i = 0; i < NVOLS; i++)
749 for (tv = afs_volumes[i]; tv; tv = tv->next) {
750 for (j = 0; j < AFS_MAXHOSTS; j++)
751 if (tv->serverHost[j] == ts)
752 afs_ResetVolumeInfo(tv);
755 osi_dnlc_purge(); /* may be a little bit extreme */
764 } /*SRXAFSCB_InitCallBackState */
767 /*------------------------------------------------------------------------
768 * EXPORTED SRXAFSCB_XStatsVersion
771 * Routine called by the server-side callback RPC interface to
772 * implement pulling out the xstat version number for the Cache
776 * a_versionP : Ptr to the version number variable to set.
782 * Nothing interesting.
786 *------------------------------------------------------------------------*/
789 SRXAFSCB_XStatsVersion(struct rx_call *a_call, afs_int32 * a_versionP)
796 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_XSTATSVERSION);
798 *a_versionP = AFSCB_XSTAT_VERSION;
805 } /*SRXAFSCB_XStatsVersion */
808 /*------------------------------------------------------------------------
809 * EXPORTED SRXAFSCB_GetXStats
812 * Routine called by the server-side callback RPC interface to
813 * implement getting the given data collection from the extended
814 * Cache Manager statistics.
817 * a_call : Ptr to Rx call on which this request came in.
818 * a_clientVersionNum : Client version number.
819 * a_opCode : Desired operation.
820 * a_serverVersionNumP : Ptr to version number to set.
821 * a_timeP : Ptr to time value (seconds) to set.
822 * a_dataArray : Ptr to variable array structure to return
829 * Nothing interesting.
833 *------------------------------------------------------------------------*/
836 SRXAFSCB_GetXStats(struct rx_call *a_call, afs_int32 a_clientVersionNum,
837 afs_int32 a_collectionNumber, afs_int32 * a_srvVersionNumP,
838 afs_int32 * a_timeP, AFSCB_CollData * a_dataP)
840 int code; /*Return value */
841 afs_int32 *dataBuffP; /*Ptr to data to be returned */
842 afs_int32 dataBytes; /*Bytes in data buffer */
847 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_GETXSTATS);
850 * Record the time of day and the server version number.
852 *a_srvVersionNumP = AFSCB_XSTAT_VERSION;
853 *a_timeP = osi_Time();
856 * Stuff the appropriate data in there (assume victory)
862 * We're not keeping stats, so just return successfully with
865 a_dataP->AFSCB_CollData_len = 0;
866 a_dataP->AFSCB_CollData_val = NULL;
868 switch (a_collectionNumber) {
869 case AFSCB_XSTATSCOLL_CALL_INFO:
871 * Pass back all the call-count-related data.
873 * >>> We are forced to allocate a separate area in which to
874 * >>> put this stuff in by the RPC stub generator, since it
875 * >>> will be freed at the tail end of the server stub code.
877 dataBytes = sizeof(struct afs_CMStats);
878 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
879 osi_Assert(dataBuffP != NULL);
880 memcpy((char *)dataBuffP, (char *)&afs_cmstats, dataBytes);
881 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
882 a_dataP->AFSCB_CollData_val = dataBuffP;
885 case AFSCB_XSTATSCOLL_PERF_INFO:
887 * Update and then pass back all the performance-related data.
888 * Note: the only performance fields that need to be computed
889 * at this time are the number of accesses for this collection
890 * and the current server record info.
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 afs_stats_cmperf.numPerfCalls++;
898 dataBytes = sizeof(afs_stats_cmperf);
899 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
900 osi_Assert(dataBuffP != NULL);
901 memcpy((char *)dataBuffP, (char *)&afs_stats_cmperf, dataBytes);
902 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
903 a_dataP->AFSCB_CollData_val = dataBuffP;
906 case AFSCB_XSTATSCOLL_FULL_PERF_INFO:
908 * Pass back the full range of performance and statistical
909 * data available. We have to bring the normal performance
910 * data collection up to date, then copy that data into
911 * the full collection.
913 * >>> We are forced to allocate a separate area in which to
914 * >>> put this stuff in by the RPC stub generator, since it
915 * >>> will be freed at the tail end of the server stub code.
917 afs_stats_cmperf.numPerfCalls++;
919 memcpy((char *)(&(afs_stats_cmfullperf.perf)),
920 (char *)(&afs_stats_cmperf), sizeof(struct afs_stats_CMPerf));
921 afs_stats_cmfullperf.numFullPerfCalls++;
923 dataBytes = sizeof(afs_stats_cmfullperf);
924 dataBuffP = (afs_int32 *) afs_osi_Alloc(dataBytes);
925 osi_Assert(dataBuffP != NULL);
926 memcpy((char *)dataBuffP, (char *)(&afs_stats_cmfullperf), dataBytes);
927 a_dataP->AFSCB_CollData_len = dataBytes >> 2;
928 a_dataP->AFSCB_CollData_val = dataBuffP;
933 * Illegal collection number.
935 a_dataP->AFSCB_CollData_len = 0;
936 a_dataP->AFSCB_CollData_val = NULL;
938 } /*Switch on collection number */
939 #endif /* AFS_NOSTATS */
947 } /*SRXAFSCB_GetXStats */
950 /*------------------------------------------------------------------------
951 * EXPORTED afs_RXCallBackServer
954 * Body of the thread supporting callback services.
963 * Nothing interesting.
967 *------------------------------------------------------------------------*/
970 afs_RXCallBackServer(void)
972 AFS_STATCNT(afs_RXCallBackServer);
977 afs_osi_Sleep(&afs_server);
981 * Donate this process to Rx.
986 } /*afs_RXCallBackServer */
989 /*------------------------------------------------------------------------
990 * EXPORTED shutdown_CB
993 * Zero out important Cache Manager data structures.
1002 * Nothing interesting.
1006 *------------------------------------------------------------------------*/
1011 AFS_STATCNT(shutdown_CB);
1013 if (afs_cold_shutdown) {
1014 afs_oddCBs = afs_evenCBs = afs_allCBs = afs_allZaps = afs_oddZaps =
1015 afs_evenZaps = afs_connectBacks = 0;
1022 /*------------------------------------------------------------------------
1023 * EXPORTED SRXAFSCB_InitCallBackState2
1026 * This routine was used in the AFS 3.5 beta release, but not anymore.
1027 * It has since been replaced by SRXAFSCB_InitCallBackState3.
1030 * a_call : Ptr to Rx call on which this request came in.
1033 * RXGEN_OPCODE (always).
1036 * Nothing interesting.
1040 *------------------------------------------------------------------------*/
1043 SRXAFSCB_InitCallBackState2(struct rx_call *a_call,
1044 struct interfaceAddr *addr)
1046 return RXGEN_OPCODE;
1049 /*------------------------------------------------------------------------
1050 * EXPORTED SRXAFSCB_WhoAreYou
1053 * Routine called by the server-side callback RPC interface to
1054 * obtain a unique identifier for the client. The server uses
1055 * this identifier to figure out whether or not two RX connections
1056 * are from the same client, and to find out which addresses go
1057 * with which clients.
1060 * a_call : Ptr to Rx call on which this request came in.
1061 * addr: Ptr to return the list of interfaces for this client.
1067 * Nothing interesting.
1071 *------------------------------------------------------------------------*/
1074 SRXAFSCB_WhoAreYou(struct rx_call *a_call, struct interfaceAddr *addr)
1081 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1083 memset(addr, 0, sizeof(*addr));
1085 ObtainReadLock(&afs_xinterface);
1087 /* return all network interface addresses */
1088 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1089 addr->uuid = afs_cb_interface.uuid;
1090 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1091 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1092 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1093 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1096 ReleaseReadLock(&afs_xinterface);
1104 /*------------------------------------------------------------------------
1105 * EXPORTED SRXAFSCB_InitCallBackState3
1108 * Routine called by the server-side callback RPC interface to
1109 * implement clearing all callbacks from this host.
1112 * a_call : Ptr to Rx call on which this request came in.
1118 * Nothing interesting.
1122 *------------------------------------------------------------------------*/
1125 SRXAFSCB_InitCallBackState3(struct rx_call *a_call, afsUUID * a_uuid)
1130 * TBD: Lookup the server by the UUID instead of its IP address.
1132 code = SRXAFSCB_InitCallBackState(a_call);
1138 /*------------------------------------------------------------------------
1139 * EXPORTED SRXAFSCB_ProbeUuid
1142 * Routine called by the server-side callback RPC interface to
1143 * implement ``probing'' the Cache Manager, just making sure it's
1144 * still there is still the same client it used to be.
1147 * a_call : Ptr to Rx call on which this request came in.
1148 * a_uuid : Ptr to UUID that must match the client's UUID.
1151 * 0 if a_uuid matches the UUID for this client
1152 * Non-zero otherwize
1155 * Nothing interesting.
1159 *------------------------------------------------------------------------*/
1162 SRXAFSCB_ProbeUuid(struct rx_call *a_call, afsUUID * a_uuid)
1168 AFS_STATCNT(SRXAFSCB_Probe);
1170 XSTATS_START_CMTIME(AFS_STATS_CM_RPCIDX_PROBE);
1171 if (!afs_uuid_equal(a_uuid, &afs_cb_interface.uuid))
1172 code = 1; /* failure */
1181 /*------------------------------------------------------------------------
1182 * EXPORTED SRXAFSCB_GetServerPrefs
1185 * Routine to list server preferences used by this client.
1188 * a_call : Ptr to Rx call on which this request came in.
1189 * a_index : Input server index
1190 * a_srvr_addr : Output server address in host byte order
1191 * (0xffffffff on last server)
1192 * a_srvr_rank : Output server rank
1198 * Nothing interesting.
1202 *------------------------------------------------------------------------*/
1205 SRXAFSCB_GetServerPrefs(struct rx_call *a_call, afs_int32 a_index,
1206 afs_int32 * a_srvr_addr, afs_int32 * a_srvr_rank)
1212 AFS_STATCNT(SRXAFSCB_GetServerPrefs);
1214 ObtainReadLock(&afs_xserver);
1216 /* Search the hash table for the server with this index */
1217 *a_srvr_addr = 0xffffffff;
1218 *a_srvr_rank = 0xffffffff;
1219 for (i = 0, j = 0; j < NSERVERS && i <= a_index; j++) {
1220 for (sa = afs_srvAddrs[j]; sa && i <= a_index; sa = sa->next_bkt, i++) {
1222 *a_srvr_addr = ntohl(sa->sa_ip);
1223 *a_srvr_rank = sa->sa_iprank;
1228 ReleaseReadLock(&afs_xserver);
1236 /*------------------------------------------------------------------------
1237 * EXPORTED SRXAFSCB_GetCellServDB
1240 * Routine to list cells configured for this client
1243 * a_call : Ptr to Rx call on which this request came in.
1244 * a_index : Input cell index
1245 * a_name : Output cell name ("" on last cell)
1246 * a_hosts : Output cell database servers in host byte order.
1252 * Nothing interesting.
1256 *------------------------------------------------------------------------*/
1259 SRXAFSCB_GetCellServDB(struct rx_call *a_call, afs_int32 a_index,
1260 char **a_name, serverList * a_hosts)
1264 char *t_name, *p_name = NULL;
1267 AFS_STATCNT(SRXAFSCB_GetCellServDB);
1269 tcell = afs_GetCellByIndex(a_index, READ_LOCK);
1273 a_hosts->serverList_val = 0;
1274 a_hosts->serverList_len = 0;
1276 p_name = tcell->cellName;
1277 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++);
1279 a_hosts->serverList_val = afs_osi_Alloc(j * sizeof(afs_int32));
1280 osi_Assert(a_hosts->serverList_val != NULL);
1281 a_hosts->serverList_len = j;
1282 for (j = 0; j < AFSMAXCELLHOSTS && tcell->cellHosts[j]; j++)
1283 a_hosts->serverList_val[j] =
1284 ntohl(tcell->cellHosts[j]->addr->sa_ip);
1285 afs_PutCell(tcell, READ_LOCK);
1288 t_name = afs_osi_Alloc(i + 1);
1289 if (t_name == NULL) {
1291 afs_osi_Free(a_hosts->serverList_val, (j * sizeof(afs_int32)));
1298 memcpy(t_name, p_name, i);
1307 /*------------------------------------------------------------------------
1308 * EXPORTED SRXAFSCB_GetLocalCell
1311 * Routine to return name of client's local cell
1314 * a_call : Ptr to Rx call on which this request came in.
1315 * a_name : Output cell name
1321 * Nothing interesting.
1325 *------------------------------------------------------------------------*/
1328 SRXAFSCB_GetLocalCell(struct rx_call *a_call, char **a_name)
1332 char *t_name, *p_name = NULL;
1335 AFS_STATCNT(SRXAFSCB_GetLocalCell);
1337 /* Search the list for the primary cell. Cell number 1 is only
1338 * the primary cell is when no other cell is explicitly marked as
1339 * the primary cell. */
1340 tcell = afs_GetPrimaryCell(READ_LOCK);
1342 p_name = tcell->cellName;
1344 plen = strlen(p_name);
1347 t_name = afs_osi_Alloc(plen + 1);
1348 if (t_name == NULL) {
1350 afs_PutCell(tcell, READ_LOCK);
1355 t_name[plen] = '\0';
1357 memcpy(t_name, p_name, plen);
1363 afs_PutCell(tcell, READ_LOCK);
1369 * afs_MarshallCacheConfig - marshall client cache configuration
1373 * IN callerVersion - the rpc stat version of the caller.
1375 * IN config - client cache configuration.
1377 * OUT ptr - buffer where configuration is marshalled.
1384 afs_MarshallCacheConfig(afs_uint32 callerVersion, cm_initparams_v1 * config,
1387 AFS_STATCNT(afs_MarshallCacheConfig);
1389 * We currently only support version 1.
1391 *(ptr++) = config->nChunkFiles;
1392 *(ptr++) = config->nStatCaches;
1393 *(ptr++) = config->nDataCaches;
1394 *(ptr++) = config->nVolumeCaches;
1395 *(ptr++) = config->firstChunkSize;
1396 *(ptr++) = config->otherChunkSize;
1397 *(ptr++) = config->cacheSize;
1398 *(ptr++) = config->setTime;
1399 *(ptr++) = config->memCache;
1403 /*------------------------------------------------------------------------
1404 * EXPORTED SRXAFSCB_GetCacheConfig
1407 * Routine to return parameters used to initialize client cache.
1408 * Client may request any format version. Server may not return
1409 * format version greater than version requested by client.
1412 * a_call: Ptr to Rx call on which this request came in.
1413 * callerVersion: Data format version desired by the client.
1414 * serverVersion: Data format version of output data.
1415 * configCount: Number bytes allocated for output data.
1416 * config: Client cache configuration.
1422 * Nothing interesting.
1426 *------------------------------------------------------------------------*/
1429 SRXAFSCB_GetCacheConfig(struct rx_call *a_call, afs_uint32 callerVersion,
1430 afs_uint32 * serverVersion, afs_uint32 * configCount,
1431 cacheConfig * config)
1433 afs_uint32 *t_config;
1435 cm_initparams_v1 cm_config;
1438 AFS_STATCNT(SRXAFSCB_GetCacheConfig);
1441 * Currently only support version 1
1443 allocsize = sizeof(cm_initparams_v1);
1444 t_config = afs_osi_Alloc(allocsize);
1445 if (t_config == NULL) {
1450 cm_config.nChunkFiles = cm_initParams.cmi_nChunkFiles;
1451 cm_config.nStatCaches = cm_initParams.cmi_nStatCaches;
1452 cm_config.nDataCaches = cm_initParams.cmi_nDataCaches;
1453 cm_config.nVolumeCaches = cm_initParams.cmi_nVolumeCaches;
1454 cm_config.firstChunkSize = cm_initParams.cmi_firstChunkSize;
1455 cm_config.otherChunkSize = cm_initParams.cmi_otherChunkSize;
1456 cm_config.cacheSize = cm_initParams.cmi_cacheSize;
1457 cm_config.setTime = cm_initParams.cmi_setTime;
1458 cm_config.memCache = cm_initParams.cmi_memCache;
1460 afs_MarshallCacheConfig(callerVersion, &cm_config, t_config);
1462 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1463 *configCount = allocsize;
1464 config->cacheConfig_val = t_config;
1465 config->cacheConfig_len = allocsize / sizeof(afs_uint32);
1472 /*------------------------------------------------------------------------
1473 * EXPORTED SRXAFSCB_FetchData
1476 * Routine to do third party move from a remioserver to the original
1477 * issuer of an ArchiveData request. Presently supported only by the
1478 * "fs" command, not by the AFS client.
1481 * rxcall: Ptr to Rx call on which this request came in.
1482 * Fid: pointer to AFSFid structure.
1483 * Fd: File descriptor inside fs command.
1484 * Position: Offset in the file.
1485 * Length: Data length to transfer.
1486 * TotalLength: Pointer to total file length field
1492 * Nothing interesting.
1495 *------------------------------------------------------------------------*/
1497 SRXAFSCB_FetchData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1498 afs_int64 Position, afs_int64 Length,
1499 afs_int64 * TotalLength)
1504 /*------------------------------------------------------------------------
1505 * EXPORTED SRXAFSCB_StoreData
1508 * Routine to do third party move from a remioserver to the original
1509 * issuer of a RetrieveData request. Presently supported only by the
1510 * "fs" command, not by the AFS client.
1513 * rxcall: Ptr to Rx call on which this request came in.
1514 * Fid: pointer to AFSFid structure.
1515 * Fd: File descriptor inside fs command.
1516 * Position: Offset in the file.
1517 * Length: Data length to transfer.
1518 * TotalLength: Pointer to total file length field
1524 * Nothing interesting.
1528 *------------------------------------------------------------------------*/
1530 SRXAFSCB_StoreData(struct rx_call *rxcall, struct AFSFid *Fid, afs_int32 Fd,
1531 afs_int64 Position, afs_int64 Length,
1532 afs_int64 * TotalLength)
1537 /*------------------------------------------------------------------------
1538 * EXPORTED SRXAFSCB_GetCellByNum
1541 * Routine to get information about a cell specified by its
1542 * cell number (returned by GetCE/GetCE64).
1545 * a_call : Ptr to Rx call on which this request came in.
1546 * a_cellnum : Input cell number
1547 * a_name : Output cell name (one zero byte when no such cell).
1548 * a_hosts : Output cell database servers in host byte order.
1554 * Nothing interesting.
1558 *------------------------------------------------------------------------*/
1561 SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum,
1562 char **a_name, serverList * a_hosts)
1568 AFS_STATCNT(SRXAFSCB_GetCellByNum);
1570 a_hosts->serverList_val = 0;
1571 a_hosts->serverList_len = 0;
1573 tcell = afs_GetCellStale(a_cellnum, READ_LOCK);
1575 *a_name = afs_strdup("");
1580 ObtainReadLock(&tcell->lock);
1581 *a_name = afs_strdup(tcell->cellName);
1583 for (sn = 0; sn < AFSMAXCELLHOSTS && tcell->cellHosts[sn]; sn++);
1584 a_hosts->serverList_len = sn;
1585 a_hosts->serverList_val = afs_osi_Alloc(sn * sizeof(afs_int32));
1586 osi_Assert(a_hosts->serverList_val != NULL);
1588 for (i = 0; i < sn; i++)
1589 a_hosts->serverList_val[i] = ntohl(tcell->cellHosts[i]->addr->sa_ip);
1590 ReleaseReadLock(&tcell->lock);
1591 afs_PutCell(tcell, READ_LOCK);
1598 SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call,
1599 struct interfaceAddr *addr,
1600 Capabilities * capabilities)
1604 afs_uint32 *dataBuffP;
1605 afs_int32 dataBytes;
1609 AFS_STATCNT(SRXAFSCB_WhoAreYou);
1611 ObtainReadLock(&afs_xinterface);
1613 /* return all network interface addresses */
1614 memset(addr, 0, sizeof(*addr));
1615 addr->numberOfInterfaces = afs_cb_interface.numberOfInterfaces;
1616 addr->uuid = afs_cb_interface.uuid;
1617 for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
1618 addr->addr_in[i] = ntohl(afs_cb_interface.addr_in[i]);
1619 addr->subnetmask[i] = ntohl(afs_cb_interface.subnetmask[i]);
1620 addr->mtu[i] = ntohl(afs_cb_interface.mtu[i]);
1623 ReleaseReadLock(&afs_xinterface);
1627 dataBytes = 1 * sizeof(afs_uint32);
1628 dataBuffP = afs_osi_Alloc(dataBytes);
1629 osi_Assert(dataBuffP != NULL);
1630 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1631 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1632 capabilities->Capabilities_val = dataBuffP;