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 */
323 /* just returns if we're up */
324 SRXAFSCB_Probe(struct rx_call *callp)
326 osi_Log0(afsd_logp, "SRXAFSCB_Probe - not implemented");
330 /* debug interface: not implemented */
331 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
334 osi_Log0(afsd_logp, "SRXAFSCB_GetCE64 - not implemented");
338 /* debug interface: not implemented */
339 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
342 osi_Log0(afsd_logp, "SRXAFSCB_GetLock - not implemented");
346 /* debug interface: not implemented */
347 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
350 osi_Log0(afsd_logp, "SRXAFSCB_GetCE - not implemented");
354 /* debug interface: not implemented */
355 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
358 osi_Log0(afsd_logp, "SRXAFSCB_XStatsVersion - not implemented");
363 /* debug interface: not implemented */
364 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
365 AFSCB_CollData *datap)
368 osi_Log0(afsd_logp, "SRXAFSCB_GetXStats - not implemented");
372 /* debug interface: not implemented */
373 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
376 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 - not implemented");
380 /* debug interface: not implemented */
381 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
384 osi_Log0(afsd_logp, "SRXAFSCB_WhoAreYou - not implemented");
388 /* debug interface: not implemented */
389 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
392 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - not implemented");
396 /* debug interface: not implemented */
397 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
400 osi_Log0(afsd_logp, "SRXAFSCB_ProbeUuid - not implemented");
404 /*------------------------------------------------------------------------
405 * EXPORTED SRXAFSCB_GetServerPrefs
408 * Routine to list server preferences used by this client.
411 * a_call : Ptr to Rx call on which this request came in.
412 * a_index : Input server index
413 * a_srvr_addr : Output server address (0xffffffff on last server)
414 * a_srvr_rank : Output server rank
420 * Nothing interesting.
424 *------------------------------------------------------------------------*/
426 int SRXAFSCB_GetServerPrefs(
427 struct rx_call *a_call,
429 afs_int32 *a_srvr_addr,
430 afs_int32 *a_srvr_rank)
432 osi_Log0(afsd_logp, "SRXAFSCB_GetServerPrefs - not implemented");
434 *a_srvr_addr = 0xffffffff;
435 *a_srvr_rank = 0xffffffff;
439 /*------------------------------------------------------------------------
440 * EXPORTED SRXAFSCB_GetCellServDB
443 * Routine to list cells configured for this client
446 * a_call : Ptr to Rx call on which this request came in.
447 * a_index : Input cell index
448 * a_name : Output cell name ("" on last cell)
449 * a_hosts : Output cell database servers
455 * Nothing interesting.
459 *------------------------------------------------------------------------*/
461 int SRXAFSCB_GetCellServDB(
462 struct rx_call *a_call,
469 osi_Log0(afsd_logp, "SRXAFSCB_GetCellServDB - not implemented");
471 t_name = (char *)malloc(AFSNAMEMAX);
474 a_hosts->serverList_len = 0;
478 /*------------------------------------------------------------------------
479 * EXPORTED SRXAFSCB_GetLocalCell
482 * Routine to return name of client's local cell
485 * a_call : Ptr to Rx call on which this request came in.
486 * a_name : Output cell name
492 * Nothing interesting.
496 *------------------------------------------------------------------------*/
498 int SRXAFSCB_GetLocalCell(
499 struct rx_call *a_call,
504 osi_Log0(afsd_logp, "SRXAFSCB_GetLocalCell");
507 t_name = (char *)malloc(strlen(cm_rootCellp->namep)+1);
508 strcpy(t_name, cm_rootCellp->namep);
510 t_name = (char *)malloc(1);
519 * afs_MarshallCacheConfig - marshall client cache configuration
523 * IN callerVersion - the rpc stat version of the caller.
525 * IN config - client cache configuration.
527 * OUT ptr - buffer where configuration is marshalled.
533 static void afs_MarshallCacheConfig(
534 afs_uint32 callerVersion,
535 cm_initparams_v1 *config,
539 * We currently only support version 1.
541 *(ptr++) = config->nChunkFiles;
542 *(ptr++) = config->nStatCaches;
543 *(ptr++) = config->nDataCaches;
544 *(ptr++) = config->nVolumeCaches;
545 *(ptr++) = config->firstChunkSize;
546 *(ptr++) = config->otherChunkSize;
547 *(ptr++) = config->cacheSize;
548 *(ptr++) = config->setTime;
549 *(ptr++) = config->memCache;
554 /*------------------------------------------------------------------------
555 * EXPORTED SRXAFSCB_GetCacheConfig
558 * Routine to return parameters used to initialize client cache.
559 * Client may request any format version. Server may not return
560 * format version greater than version requested by client.
563 * a_call: Ptr to Rx call on which this request came in.
564 * callerVersion: Data format version desired by the client.
565 * serverVersion: Data format version of output data.
566 * configCount: Number bytes allocated for output data.
567 * config: Client cache configuration.
573 * Nothing interesting.
577 *------------------------------------------------------------------------*/
579 int SRXAFSCB_GetCacheConfig(a_call, callerVersion, serverVersion,
581 struct rx_call *a_call;
582 afs_uint32 callerVersion;
583 afs_uint32 *serverVersion;
584 afs_uint32 *configCount;
587 afs_uint32 *t_config;
589 extern cm_initparams_v1 cm_initParams;
591 osi_Log0(afsd_logp, "SRXAFSCB_GetCacheConfig - version 1 only");
594 * Currently only support version 1
596 allocsize = sizeof(cm_initparams_v1);
597 t_config = (afs_uint32 *)malloc(allocsize);
599 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
601 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
602 *configCount = allocsize;
603 config->cacheConfig_val = t_config;
604 config->cacheConfig_len = allocsize/sizeof(afs_uint32);
609 /* called by afsd without any locks to initialize this module */
610 void cm_InitCallback(void)
612 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
613 cm_activeCallbackGrantingCalls = 0;
616 /* called with locked scp; tells us whether we've got a callback.
617 * Expirations are checked by a background daemon so as to make
618 * this function as inexpensive as possible
620 int cm_HaveCallback(cm_scache_t *scp)
622 #ifdef AFS_FREELANCE_CLIENT
623 // yj: we handle callbacks specially for callbacks on the root directory
624 // Since it's local, we almost always say that we have callback on it
625 // The only time we send back a 0 is if we're need to initialize or
626 // reinitialize the fake directory
628 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
629 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
630 // hence should return false. it's 0 otherwise
631 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
632 // if the fake directory is loaded and this is the first time cm_HaveCallback
633 // is called since then. We return false in this case to allow cm_GetCallback
634 // to be called because cm_GetCallback has some initialization work to do.
635 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
636 // good shape and we simply return true, provided no change is detected.
639 if (cm_freelanceEnabled &&
640 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
641 /* if it's something on /afs */
642 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
643 /* if it's not root.afs */
647 lock_ObtainMutex(&cm_Freelance_Lock);
648 fdc = cm_fakeDirCallback;
649 fgc = cm_fakeGettingCallback;
650 lock_ReleaseMutex(&cm_Freelance_Lock);
652 if (fdc==1) { // first call since init
654 } else if (fdc==2 && !fgc) { // we're in good shape
655 if (cm_getLocalMountPointChange()) { // check for changes
656 cm_clearLocalMountPointChange(); // clear the changefile
657 lock_ReleaseMutex(&scp->mx); // this is re-locked in reInitLocalMountPoints
658 cm_reInitLocalMountPoints(); // start reinit
659 lock_ObtainMutex(&scp->mx); // now get the lock back
662 return 1; // no change
668 if (scp->cbServerp != NULL)
674 /* need to detect a broken callback that races with our obtaining a callback.
675 * Need to be able to do this even if we don't know the file ID of the file
676 * we're breaking the callback on at the time we start the acquisition of the
677 * callback (as in the case where we are creating a file).
679 * So, we start by writing down the count of the # of callbacks we've received
680 * so far, and bumping a global counter of the # of callback granting calls
681 * outstanding (all done under cm_callbackLock).
683 * When we're back from the call, we look at all of the callback revokes with
684 * counter numbers greater than the one we recorded in our caller's structure,
685 * and replay those that are higher than when we started the call.
687 * We free all the structures in the queue when the count of the # of outstanding
688 * callback-granting calls drops to zero.
690 * We call this function with the scp locked, too, but in its current implementation,
691 * this knowledge is not used.
693 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
695 lock_ObtainWrite(&cm_callbackLock);
696 cbrp->callbackCount = cm_callbackCount;
697 cm_activeCallbackGrantingCalls++;
698 cbrp->startTime = osi_Time();
699 cbrp->serverp = NULL;
700 lock_ReleaseWrite(&cm_callbackLock);
703 /* Called at the end of a callback-granting call, to remove the callback
704 * info from the scache entry, if necessary.
706 * Called with scp locked, so we can discard the callbacks easily with
707 * this locking hierarchy.
709 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
710 AFSCallBack *cbp, long flags)
712 cm_racingRevokes_t *revp; /* where we are */
713 cm_racingRevokes_t *nrevp; /* where we'll be next */
715 cm_server_t * serverp = 0;
717 lock_ObtainWrite(&cm_callbackLock);
718 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
719 osi_assert(cm_activeCallbackGrantingCalls > 0);
722 osi_assert(cm_activeCallbackGrantingCalls-- > 0);
724 if (cm_activeCallbackGrantingCalls == 0)
729 /* record the callback; we'll clear it below if we really lose it */
732 if (scp->cbServerp != cbrp->serverp) {
733 serverp = scp->cbServerp;
735 scp->cbServerp = cbrp->serverp;
736 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
738 serverp = cbrp->serverp;
740 cbrp->serverp = NULL;
743 /* a callback was actually revoked during our granting call, so
744 * run down the list of revoked fids, looking for ours.
745 * If activeCallbackGrantingCalls is zero, free the elements, too.
747 * May need to go through entire list just to do the freeing.
749 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
750 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
751 /* if this callback came in later than when we started the
752 * callback-granting call, and if this fid is the right fid,
753 * then clear the callback.
755 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
756 && revp->callbackCount > cbrp->callbackCount
757 && (( scp->fid.volume == revp->fid.volume &&
758 scp->fid.vnode == revp->fid.vnode &&
759 scp->fid.unique == revp->fid.unique)
761 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
762 scp->fid.volume == revp->fid.volume)
764 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
765 /* this one matches */
767 "Racing revoke scp %x old cbc %d rev cbc %d cur cbc %d",
769 cbrp->callbackCount, revp->callbackCount,
771 cm_DiscardSCache(scp);
773 * Since we don't have a callback to preserve, it's
774 * OK to drop the lock and re-obtain it.
776 lock_ReleaseMutex(&scp->mx);
777 cm_CallbackNotifyChange(scp);
778 lock_ObtainMutex(&scp->mx);
780 if (freeFlag) free(revp);
783 /* if we freed the list, zap the pointer to it */
784 if (freeFlag) cm_racingRevokesp = NULL;
786 lock_ReleaseWrite(&cm_callbackLock);
789 lock_ObtainWrite(&cm_serverLock);
790 cm_FreeServer(serverp);
791 lock_ReleaseWrite(&cm_serverLock);
795 /* if flags is 1, we want to force the code to make one call, anyway.
796 * called with locked scp; returns with same.
798 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
799 struct cm_req *reqp, long flags)
803 AFSFetchStatus afsStatus;
805 AFSCallBack callback;
807 cm_callbackRequest_t cbr;
811 struct rx_connection * callp;
813 osi_Log2(afsd_logp, "GetCallback scp %x flags %lX", scp, flags);
815 #ifdef AFS_FREELANCE_CLIENT
816 // The case where a callback is needed on /afs is handled
817 // specially. We need to fetch the status by calling
818 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
819 if (cm_freelanceEnabled) {
820 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
821 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
822 scp->fid.unique==0x1 &&
823 scp->fid.vnode==0x1) {
825 // Start by indicating that we're in the process
826 // of fetching the callback
827 lock_ObtainMutex(&cm_Freelance_Lock);
828 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
829 cm_fakeGettingCallback = 1;
830 lock_ReleaseMutex(&cm_Freelance_Lock);
832 // Fetch the status info
833 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
835 // Indicate that the callback is not done
836 lock_ObtainMutex(&cm_Freelance_Lock);
837 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
838 cm_fakeDirCallback = 2;
840 // Indicate that we're no longer fetching the callback
841 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
842 cm_fakeGettingCallback = 0;
843 lock_ReleaseMutex(&cm_Freelance_Lock);
848 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
849 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
852 #endif /* AFS_FREELANCE_CLIENT */
854 mustCall = (flags & 1);
855 cm_AFSFidFromFid(&tfid, &scp->fid);
857 if (!mustCall && cm_HaveCallback(scp)) return 0;
859 /* turn off mustCall, since it has now forced us past the check above */
862 /* otherwise, we have to make an RPC to get the status */
863 sflags = CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK;
864 cm_SyncOp(scp, NULL, NULL, NULL, 0, sflags);
865 cm_StartCallbackGrantingCall(scp, &cbr);
867 lock_ReleaseMutex(&scp->mx);
869 /* now make the RPC */
870 osi_Log1(afsd_logp, "CALL FetchStatus vp %x", (long) scp);
872 code = cm_Conn(&sfid, userp, reqp, &connp);
875 callp = cm_GetRxConn(connp);
876 code = RXAFS_FetchStatus(callp, &tfid,
877 &afsStatus, &callback, &volSync);
878 rx_PutConnection(callp);
880 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
882 code = cm_MapRPCError(code, reqp);
883 osi_Log0(afsd_logp, "CALL FetchStatus DONE");
885 lock_ObtainMutex(&scp->mx);
886 cm_SyncOpDone(scp, NULL, sflags);
888 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
889 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
892 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
894 /* now check to see if we got an error */
895 if (code) return code;
899 /* called periodically by cm_daemon to shut down use of expired callbacks */
900 void cm_CheckCBExpiration(void)
906 osi_Log0(afsd_logp, "CheckCBExpiration");
909 lock_ObtainWrite(&cm_scacheLock);
910 for (i=0; i<cm_hashTableSize; i++) {
911 for (scp = cm_hashTablep[i]; scp; scp=scp->nextp) {
913 lock_ReleaseWrite(&cm_scacheLock);
914 if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) {
915 osi_Log1(afsd_logp, "Callback Expiration Discarding SCache scp %x", scp);
916 cm_CallbackNotifyChange(scp);
917 lock_ObtainMutex(&scp->mx);
918 cm_DiscardSCache(scp);
919 lock_ReleaseMutex(&scp->mx);
921 lock_ObtainWrite(&cm_scacheLock);
922 osi_assert(scp->refCount-- > 0);
925 lock_ReleaseWrite(&cm_scacheLock);
928 /* debug interface: not implemented */
929 int SRXAFSCB_GetCellByNum(struct rx_call *a_call, afs_int32 a_cellnum,
930 char **a_name, serverList *a_hosts)
933 osi_Log0(afsd_logp, "SRXAFSCB_GetCellByNum - not implemented");
937 /* debug interface: not implemented */
938 int SRXAFSCB_TellMeAboutYourself(struct rx_call *a_call, afs_int32 a_cellnum,
939 char **a_name, serverList *a_hosts)
942 osi_Log0(afsd_logp, "SRXAFSCB_TellMeAboutYourself - not implemented");