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
10 #include <afs/param.h>
11 #include <afs/afs_args.h>
18 #include <sys/socket.h>
28 /*extern void afsi_log(char *pattern, ...);*/
30 /* read/write lock for all global storage in this module */
31 osi_rwlock_t cm_callbackLock;
33 #ifdef AFS_FREELANCE_CLIENT
34 extern osi_mutex_t cm_Freelance_Lock;
37 /* count of # of callback breaking messages received by this CM so far. We use
38 * this count in determining whether there have been any callback breaks that
39 * apply to a call that returned a new callback. If the counter doesn't
40 * increase during a call, then we know that no callbacks were broken during
41 * that call, and thus that the callback that was just returned is still valid.
43 long cm_callbackCount;
45 /* count of number of RPCs potentially returning a callback executing now.
46 * When this counter hits zero, we can clear out the racing revokes list, since
47 * at that time, we know that none of the just-executed callback revokes will
48 * apply to any future call that returns a callback (since the latter hasn't
49 * even started execution yet).
51 long cm_activeCallbackGrantingCalls;
53 /* list of callbacks that have been broken recently. If a call returning a
54 * callback is executing and a callback revoke runs immediately after it at the
55 * server, the revoke may end up being processed before the response to the
56 * original callback granting call. We detect this by keeping a list of
57 * callback revokes that have been received since we *started* the callback
58 * granting call, and discarding any callbacks received for the same file ID,
59 * even if the callback revoke was received before the callback grant.
61 cm_racingRevokes_t *cm_racingRevokesp;
63 /* record a (potentially) racing revoke for this file ID; null means for all
64 * file IDs, and is used by InitCallBackState.
66 * The cancelFlags describe whether we're just discarding callbacks for the same
67 * file ID, the same volume, or all from the same server.
69 * Called with no locks held.
71 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
73 cm_racingRevokes_t *rp;
75 lock_ObtainWrite(&cm_callbackLock);
77 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
78 fidp->volume, cancelFlags, cm_activeCallbackGrantingCalls);
80 if (cm_activeCallbackGrantingCalls > 0) {
81 rp = malloc(sizeof(*rp));
82 memset(rp, 0, sizeof(*rp));
83 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
84 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
85 if (fidp) rp->fid = *fidp;
86 rp->callbackCount = ++cm_callbackCount;
88 lock_ReleaseWrite(&cm_callbackLock);
92 * When we lose a callback, may have to send change notification replies.
93 * Do not call with a lock on the scp.
95 void cm_CallbackNotifyChange(cm_scache_t *scp)
97 osi_Log2(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX",
98 scp->fileType, scp->flags);
100 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
101 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
103 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
104 scp, NULL, NULL, TRUE);
109 tfid.cell = scp->fid.cell;
110 tfid.volume = scp->fid.volume;
111 tfid.vnode = scp->parentVnode;
112 tfid.unique = scp->parentUnique;
113 dscp = cm_FindSCache(&tfid);
115 dscp->flags & CM_SCACHEFLAG_ANYWATCH)
117 FILE_NOTIFY_GENERIC_FILE_FILTER,
118 dscp, NULL, NULL, TRUE);
119 if (dscp) cm_ReleaseSCache(dscp);
123 /* called with no locks held for every file ID that is revoked directly by
124 * a callback revoke call. Does not have to handle volume callback breaks,
125 * since those have already been split out.
127 * The callp parameter is currently unused.
129 void cm_RevokeCallback(struct rx_call *callp, AFSFid *fidp)
135 /* don't bother setting cell, since we won't be checking it (to aid
136 * in working with multi-homed servers: we don't know the cell if we
137 * don't recognize the IP address).
140 tfid.volume = fidp->Volume;
141 tfid.vnode = fidp->Vnode;
142 tfid.unique = fidp->Unique;
143 hash = CM_SCACHE_HASH(&tfid);
145 osi_Log3(afsd_logp, "RevokeCallback vol %d vn %d un %d",
146 fidp->Volume, fidp->Vnode, fidp->Unique);
148 /* do this first, so that if we're executing a callback granting call
149 * at this moment, we kill it before it can be merged in. Otherwise,
150 * it could complete while we're doing the scan below, and get missed
151 * by both the scan and by this code.
153 cm_RecordRacingRevoke(&tfid, 0);
155 lock_ObtainWrite(&cm_scacheLock);
156 /* do all in the hash bucket, since we don't know how many we'll find with
159 for(scp = cm_hashTablep[hash]; scp; scp=scp->nextp) {
160 if (scp->fid.volume == tfid.volume &&
161 scp->fid.vnode == tfid.vnode &&
162 scp->fid.unique == tfid.unique) {
164 lock_ReleaseWrite(&cm_scacheLock);
165 osi_Log1(afsd_logp, "Discarding SCache scp %x", scp);
166 lock_ObtainMutex(&scp->mx);
167 cm_DiscardSCache(scp);
168 lock_ReleaseMutex(&scp->mx);
169 cm_CallbackNotifyChange(scp);
170 lock_ObtainWrite(&cm_scacheLock);
174 lock_ReleaseWrite(&cm_scacheLock);
177 /* called to revoke a volume callback, which is typically issued when a volume
178 * is moved from one server to another.
180 * Called with no locks held.
182 void cm_RevokeVolumeCallback(struct rx_call *callp, AFSFid *fidp)
188 osi_Log1(afsd_logp, "RevokeVolumeCallback %d", fidp->Volume);
190 /* do this first, so that if we're executing a callback granting call
191 * at this moment, we kill it before it can be merged in. Otherwise,
192 * it could complete while we're doing the scan below, and get missed
193 * by both the scan and by this code.
195 tfid.cell = tfid.vnode = tfid.unique = 0;
196 tfid.volume = fidp->Volume;
197 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
200 lock_ObtainWrite(&cm_scacheLock);
201 for(hash = 0; hash < cm_hashTableSize; hash++) {
202 for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
203 if (scp->fid.volume == fidp->Volume) {
205 lock_ReleaseWrite(&cm_scacheLock);
206 lock_ObtainMutex(&scp->mx);
207 osi_Log1(afsd_logp, "Discarding SCache scp %x", scp);
208 cm_DiscardSCache(scp);
209 lock_ReleaseMutex(&scp->mx);
210 cm_CallbackNotifyChange(scp);
211 lock_ObtainWrite(&cm_scacheLock);
214 } /* search one hash bucket */
215 } /* search all hash buckets */
217 lock_ReleaseWrite(&cm_scacheLock);
220 /* handle incoming RPC callback breaking message.
221 * Called with no locks held.
223 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
228 osi_Log0(afsd_logp, "SRXAFSCB_CallBack");
230 for(i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
231 tfidp = &fidsArrayp->AFSCBFids_val[i];
233 if (tfidp->Volume == 0)
234 continue; /* means don't do anything */
235 else if (tfidp->Vnode == 0)
236 cm_RevokeVolumeCallback(callp, tfidp);
238 cm_RevokeCallback(callp, tfidp);
244 /* called with no locks by RPC system when a server indicates that it has never
245 * heard from us, or for other reasons has had to discard callbacks from us
246 * without telling us, e.g. a network partition.
248 SRXAFSCB_InitCallBackState(struct rx_call *callp)
250 struct sockaddr_in taddr;
256 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState");
258 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
259 taddr.sin_family = AF_INET;
260 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
262 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
264 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
266 /* record the callback in the racing revokes structure. This
267 * shouldn't be necessary, since we shouldn't be making callback
268 * granting calls while we're going to get an initstate call,
269 * but there probably are some obscure races, so better safe
272 * We do this first since we don't hold the cm_scacheLock and vnode
273 * locks over the entire callback scan operation below. The
274 * big loop below is guaranteed to hit any callback already
275 * processed. The call to RecordRacingRevoke is guaranteed
276 * to kill any callback that is currently being returned.
277 * Anything that sneaks past both must start
278 * after the call to RecordRacingRevoke.
280 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
282 /* now search all vnodes looking for guys with this callback, if we
283 * found it, or guys with any callbacks, if we didn't find the server
284 * (that's how multihomed machines will appear and how we'll handle
285 * them, albeit a little inefficiently). That is, we're discarding all
286 * callbacks from all hosts if we get an initstate call from an unknown
287 * host. Since these calls are rare, and multihomed servers
288 * are "rare," hopefully this won't be a problem.
290 lock_ObtainWrite(&cm_scacheLock);
291 for(hash = 0; hash < cm_hashTableSize; hash++) {
292 for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
294 lock_ReleaseWrite(&cm_scacheLock);
295 lock_ObtainMutex(&scp->mx);
297 if (scp->cbServerp != NULL) {
298 /* we have a callback, now decide if we should clear it */
299 if (scp->cbServerp == tsp || tsp == NULL) {
300 osi_Log1(afsd_logp, "Discarding SCache scp %x", scp);
301 cm_DiscardSCache(scp);
305 lock_ReleaseMutex(&scp->mx);
307 cm_CallbackNotifyChange(scp);
308 lock_ObtainWrite(&cm_scacheLock);
310 } /* search one hash bucket */
311 } /* search all hash buckets */
313 lock_ReleaseWrite(&cm_scacheLock);
315 /* we're done with the server structure */
316 if (tsp) cm_PutServer(tsp);
322 /* just returns if we're up */
323 SRXAFSCB_Probe(struct rx_call *callp)
325 osi_Log0(afsd_logp, "SRXAFSCB_Probe - not implemented");
329 /* debug interface: not implemented */
330 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
333 osi_Log0(afsd_logp, "SRXAFSCB_GetCE64 - not implemented");
337 /* debug interface: not implemented */
338 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
341 osi_Log0(afsd_logp, "SRXAFSCB_GetLock - not implemented");
345 /* debug interface: not implemented */
346 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
349 osi_Log0(afsd_logp, "SRXAFSCB_GetCE - not implemented");
353 /* debug interface: not implemented */
354 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
357 osi_Log0(afsd_logp, "SRXAFSCB_XStatsVersion - not implemented");
362 /* debug interface: not implemented */
363 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
364 AFSCB_CollData *datap)
367 osi_Log0(afsd_logp, "SRXAFSCB_GetXStats - not implemented");
371 /* debug interface: not implemented */
372 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
375 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 - not implemented");
379 /* debug interface: not implemented */
380 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
383 osi_Log0(afsd_logp, "SRXAFSCB_WhoAreYou - not implemented");
387 /* debug interface: not implemented */
388 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
391 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - not implemented");
395 /* debug interface: not implemented */
396 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
399 osi_Log0(afsd_logp, "SRXAFSCB_ProbeUuid - not implemented");
403 /*------------------------------------------------------------------------
404 * EXPORTED SRXAFSCB_GetServerPrefs
407 * Routine to list server preferences used by this client.
410 * a_call : Ptr to Rx call on which this request came in.
411 * a_index : Input server index
412 * a_srvr_addr : Output server address (0xffffffff on last server)
413 * a_srvr_rank : Output server rank
419 * Nothing interesting.
423 *------------------------------------------------------------------------*/
425 int SRXAFSCB_GetServerPrefs(
426 struct rx_call *a_call,
428 afs_int32 *a_srvr_addr,
429 afs_int32 *a_srvr_rank)
431 osi_Log0(afsd_logp, "SRXAFSCB_GetServerPrefs - not implemented");
433 *a_srvr_addr = 0xffffffff;
434 *a_srvr_rank = 0xffffffff;
438 /*------------------------------------------------------------------------
439 * EXPORTED SRXAFSCB_GetCellServDB
442 * Routine to list cells configured for this client
445 * a_call : Ptr to Rx call on which this request came in.
446 * a_index : Input cell index
447 * a_name : Output cell name ("" on last cell)
448 * a_hosts : Output cell database servers
454 * Nothing interesting.
458 *------------------------------------------------------------------------*/
460 int SRXAFSCB_GetCellServDB(
461 struct rx_call *a_call,
468 osi_Log0(afsd_logp, "SRXAFSCB_GetCellServDB - not implemented");
470 t_name = (char *)malloc(AFSNAMEMAX);
473 a_hosts->serverList_len = 0;
477 /*------------------------------------------------------------------------
478 * EXPORTED SRXAFSCB_GetLocalCell
481 * Routine to return name of client's local cell
484 * a_call : Ptr to Rx call on which this request came in.
485 * a_name : Output cell name
491 * Nothing interesting.
495 *------------------------------------------------------------------------*/
497 int SRXAFSCB_GetLocalCell(
498 struct rx_call *a_call,
503 osi_Log0(afsd_logp, "SRXAFSCB_GetLocalCell");
506 t_name = (char *)malloc(strlen(cm_rootCellp->namep)+1);
507 strcpy(t_name, cm_rootCellp->namep);
509 t_name = (char *)malloc(1);
518 * afs_MarshallCacheConfig - marshall client cache configuration
522 * IN callerVersion - the rpc stat version of the caller.
524 * IN config - client cache configuration.
526 * OUT ptr - buffer where configuration is marshalled.
532 static void afs_MarshallCacheConfig(
533 afs_uint32 callerVersion,
534 cm_initparams_v1 *config,
538 * We currently only support version 1.
540 *(ptr++) = config->nChunkFiles;
541 *(ptr++) = config->nStatCaches;
542 *(ptr++) = config->nDataCaches;
543 *(ptr++) = config->nVolumeCaches;
544 *(ptr++) = config->firstChunkSize;
545 *(ptr++) = config->otherChunkSize;
546 *(ptr++) = config->cacheSize;
547 *(ptr++) = config->setTime;
548 *(ptr++) = config->memCache;
553 /*------------------------------------------------------------------------
554 * EXPORTED SRXAFSCB_GetCacheConfig
557 * Routine to return parameters used to initialize client cache.
558 * Client may request any format version. Server may not return
559 * format version greater than version requested by client.
562 * a_call: Ptr to Rx call on which this request came in.
563 * callerVersion: Data format version desired by the client.
564 * serverVersion: Data format version of output data.
565 * configCount: Number bytes allocated for output data.
566 * config: Client cache configuration.
572 * Nothing interesting.
576 *------------------------------------------------------------------------*/
578 int SRXAFSCB_GetCacheConfig(a_call, callerVersion, serverVersion,
580 struct rx_call *a_call;
581 afs_uint32 callerVersion;
582 afs_uint32 *serverVersion;
583 afs_uint32 *configCount;
586 afs_uint32 *t_config;
588 extern cm_initparams_v1 cm_initParams;
590 osi_Log0(afsd_logp, "SRXAFSCB_GetCacheConfig - version 1 only");
593 * Currently only support version 1
595 allocsize = sizeof(cm_initparams_v1);
596 t_config = (afs_uint32 *)malloc(allocsize);
598 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
600 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
601 *configCount = allocsize;
602 config->cacheConfig_val = t_config;
603 config->cacheConfig_len = allocsize/sizeof(afs_uint32);
608 /* called by afsd without any locks to initialize this module */
609 void cm_InitCallback(void)
611 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
612 cm_activeCallbackGrantingCalls = 0;
615 /* called with locked scp; tells us whether we've got a callback.
616 * Expirations are checked by a background daemon so as to make
617 * this function as inexpensive as possible
619 int cm_HaveCallback(cm_scache_t *scp)
621 #ifdef AFS_FREELANCE_CLIENT
622 // yj: we handle callbacks specially for callbacks on the root directory
623 // Since it's local, we almost always say that we have callback on it
624 // The only time we send back a 0 is if we're need to initialize or
625 // reinitialize the fake directory
627 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
628 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
629 // hence should return false. it's 0 otherwise
630 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
631 // if the fake directory is loaded and this is the first time cm_HaveCallback
632 // is called since then. We return false in this case to allow cm_GetCallback
633 // to be called because cm_GetCallback has some initialization work to do.
634 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
635 // good shape and we simply return true, provided no change is detected.
638 if (cm_freelanceEnabled &&
639 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
640 /* if it's something on /afs */
641 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
642 /* if it's not root.afs */
646 lock_ObtainMutex(&cm_Freelance_Lock);
647 fdc = cm_fakeDirCallback;
648 fgc = cm_fakeGettingCallback;
649 lock_ReleaseMutex(&cm_Freelance_Lock);
651 if (fdc==1) { // first call since init
653 } else if (fdc==2 && !fgc) { // we're in good shape
654 if (cm_getLocalMountPointChange()) { // check for changes
655 cm_clearLocalMountPointChange(); // clear the changefile
656 lock_ReleaseMutex(&scp->mx); // this is re-locked in reInitLocalMountPoints
657 cm_reInitLocalMountPoints(); // start reinit
658 lock_ObtainMutex(&scp->mx); // now get the lock back
661 return 1; // no change
667 if (scp->cbServerp != NULL)
673 /* need to detect a broken callback that races with our obtaining a callback.
674 * Need to be able to do this even if we don't know the file ID of the file
675 * we're breaking the callback on at the time we start the acquisition of the
676 * callback (as in the case where we are creating a file).
678 * So, we start by writing down the count of the # of callbacks we've received
679 * so far, and bumping a global counter of the # of callback granting calls
680 * outstanding (all done under cm_callbackLock).
682 * When we're back from the call, we look at all of the callback revokes with
683 * counter numbers greater than the one we recorded in our caller's structure,
684 * and replay those that are higher than when we started the call.
686 * We free all the structures in the queue when the count of the # of outstanding
687 * callback-granting calls drops to zero.
689 * We call this function with the scp locked, too, but in its current implementation,
690 * this knowledge is not used.
692 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
694 lock_ObtainWrite(&cm_callbackLock);
695 cbrp->callbackCount = cm_callbackCount;
696 cm_activeCallbackGrantingCalls++;
697 cbrp->startTime = osi_Time();
698 cbrp->serverp = NULL;
699 lock_ReleaseWrite(&cm_callbackLock);
702 /* Called at the end of a callback-granting call, to remove the callback
703 * info from the scache entry, if necessary.
705 * Called with scp locked, so we can discard the callbacks easily with
706 * this locking hierarchy.
708 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
709 AFSCallBack *cbp, long flags)
711 cm_racingRevokes_t *revp; /* where we are */
712 cm_racingRevokes_t *nrevp; /* where we'll be next */
714 cm_server_t * serverp = 0;
716 lock_ObtainWrite(&cm_callbackLock);
717 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
718 osi_assert(cm_activeCallbackGrantingCalls > 0);
721 osi_assert(cm_activeCallbackGrantingCalls-- > 0);
723 if (cm_activeCallbackGrantingCalls == 0)
728 /* record the callback; we'll clear it below if we really lose it */
731 if (scp->cbServerp != cbrp->serverp) {
732 serverp = scp->cbServerp;
734 scp->cbServerp = cbrp->serverp;
735 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
737 serverp = cbrp->serverp;
739 cbrp->serverp = NULL;
742 /* a callback was actually revoked during our granting call, so
743 * run down the list of revoked fids, looking for ours.
744 * If activeCallbackGrantingCalls is zero, free the elements, too.
746 * May need to go through entire list just to do the freeing.
748 for(revp = cm_racingRevokesp; revp; revp = nrevp) {
749 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
750 /* if this callback came in later than when we started the
751 * callback-granting call, and if this fid is the right fid,
752 * then clear the callback.
754 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
755 && revp->callbackCount > cbrp->callbackCount
756 && (( scp->fid.volume == revp->fid.volume &&
757 scp->fid.vnode == revp->fid.vnode &&
758 scp->fid.unique == revp->fid.unique)
760 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
761 scp->fid.volume == revp->fid.volume)
763 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
764 /* this one matches */
766 "Racing revoke scp %x old cbc %d rev cbc %d cur cbc %d",
768 cbrp->callbackCount, revp->callbackCount,
770 cm_DiscardSCache(scp);
772 * Since we don't have a callback to preserve, it's
773 * OK to drop the lock and re-obtain it.
775 lock_ReleaseMutex(&scp->mx);
776 cm_CallbackNotifyChange(scp);
777 lock_ObtainMutex(&scp->mx);
779 if (freeFlag) free(revp);
782 /* if we freed the list, zap the pointer to it */
783 if (freeFlag) cm_racingRevokesp = NULL;
785 lock_ReleaseWrite(&cm_callbackLock);
788 lock_ObtainWrite(&cm_serverLock);
789 cm_FreeServer(serverp);
790 lock_ReleaseWrite(&cm_serverLock);
794 /* if flags is 1, we want to force the code to make one call, anyway.
795 * called with locked scp; returns with same.
797 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
798 struct cm_req *reqp, long flags)
802 AFSFetchStatus afsStatus;
804 AFSCallBack callback;
806 cm_callbackRequest_t cbr;
811 osi_Log2(afsd_logp, "GetCallback scp %x flags %lX", scp, flags);
813 #ifdef AFS_FREELANCE_CLIENT
814 // The case where a callback is needed on /afs is handled
815 // specially. We need to fetch the status by calling
816 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
817 if (cm_freelanceEnabled) {
818 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
819 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
820 scp->fid.unique==0x1 &&
821 scp->fid.vnode==0x1) {
823 // Start by indicating that we're in the process
824 // of fetching the callback
825 lock_ObtainMutex(&cm_Freelance_Lock);
826 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
827 cm_fakeGettingCallback = 1;
828 lock_ReleaseMutex(&cm_Freelance_Lock);
830 // Fetch the status info
831 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
833 // Indicate that the callback is not done
834 lock_ObtainMutex(&cm_Freelance_Lock);
835 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
836 cm_fakeDirCallback = 2;
838 // Indicate that we're no longer fetching the callback
839 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
840 cm_fakeGettingCallback = 0;
841 lock_ReleaseMutex(&cm_Freelance_Lock);
846 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
847 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
850 #endif /* AFS_FREELANCE_CLIENT */
852 mustCall = (flags & 1);
853 cm_AFSFidFromFid(&tfid, &scp->fid);
855 if (!mustCall && cm_HaveCallback(scp)) return 0;
857 /* turn off mustCall, since it has now forced us past the check above */
860 /* otherwise, we have to make an RPC to get the status */
861 sflags = CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK;
862 cm_SyncOp(scp, NULL, NULL, NULL, 0, sflags);
863 cm_StartCallbackGrantingCall(scp, &cbr);
865 lock_ReleaseMutex(&scp->mx);
867 /* now make the RPC */
868 osi_Log1(afsd_logp, "CALL FetchStatus vp %x", (long) scp);
870 code = cm_Conn(&sfid, userp, reqp, &connp);
873 code = RXAFS_FetchStatus(connp->callp, &tfid,
874 &afsStatus, &callback, &volSync);
876 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
878 code = cm_MapRPCError(code, reqp);
879 osi_Log0(afsd_logp, "CALL FetchStatus DONE");
881 lock_ObtainMutex(&scp->mx);
882 cm_SyncOpDone(scp, NULL, sflags);
884 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
885 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
888 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
890 /* now check to see if we got an error */
891 if (code) return code;
895 /* called periodically by cm_daemon to shut down use of expired callbacks */
896 void cm_CheckCBExpiration(void)
902 osi_Log0(afsd_logp, "CheckCBExpiration");
905 lock_ObtainWrite(&cm_scacheLock);
906 for(i=0; i<cm_hashTableSize; i++) {
907 for(scp = cm_hashTablep[i]; scp; scp=scp->nextp) {
909 lock_ReleaseWrite(&cm_scacheLock);
910 if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) {
911 osi_Log1(afsd_logp, "Callback Expiration Discarding SCache scp %x", scp);
912 cm_CallbackNotifyChange(scp);
913 lock_ObtainMutex(&scp->mx);
914 cm_DiscardSCache(scp);
915 lock_ReleaseMutex(&scp->mx);
917 lock_ObtainWrite(&cm_scacheLock);
918 osi_assert(scp->refCount-- > 0);
921 lock_ReleaseWrite(&cm_scacheLock);
924 /* debug interface: not implemented */
925 int SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum,
926 char **a_name, serverList *a_hosts)
929 osi_Log0(afsd_logp, "SRXAFSCB_GetCellByNum - not implemented");
933 /* debug interface: not implemented */
934 int SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call, afs_int32 a_cellnum,
935 char **a_name, serverList *a_hosts)
938 osi_Log0(afsd_logp, "SRXAFSCB_TellMeAboutYourself - not implemented");