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>
22 #include <rx_pthread.h>
24 #include <WINNT/syscfg.h>
25 #include <WINNT/afsreg.h>
26 #include <../afsrdr/kif.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 ? fidp->volume : 0, 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)
101 /* why does this have to query the registry each time? */
102 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
103 AFSREG_CLT_OPENAFS_SUBKEY,
105 KEY_READ|KEY_QUERY_VALUE,
106 &hKey) == ERROR_SUCCESS) {
108 dummyLen = sizeof(DWORD);
109 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
110 (BYTE *) &dwDelay, &dummyLen);
114 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
117 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
118 scp->fileType, scp->flags, dwDelay);
123 /* for directories, this sends a change notification on the dir itself */
124 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
126 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
128 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
129 scp, NULL, NULL, TRUE);
131 dc_break_callback(FID_HASH_FN(&scp->fid));
134 /* and for files, this sends a change notification on the file's parent dir */
138 tfid.cell = scp->fid.cell;
139 tfid.volume = scp->fid.volume;
140 tfid.vnode = scp->parentVnode;
141 tfid.unique = scp->parentUnique;
142 dscp = cm_FindSCache(&tfid);
145 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
147 FILE_NOTIFY_GENERIC_FILE_FILTER,
148 dscp, NULL, NULL, TRUE);
151 dc_break_callback(FID_HASH_FN(&dscp->fid));
154 cm_ReleaseSCache(dscp);
158 /* called with no locks held for every file ID that is revoked directly by
159 * a callback revoke call. Does not have to handle volume callback breaks,
160 * since those have already been split out.
162 * The callp parameter is currently unused.
164 void cm_RevokeCallback(struct rx_call *callp, AFSFid *fidp)
170 /* don't bother setting cell, since we won't be checking it (to aid
171 * in working with multi-homed servers: we don't know the cell if we
172 * don't recognize the IP address).
175 tfid.volume = fidp->Volume;
176 tfid.vnode = fidp->Vnode;
177 tfid.unique = fidp->Unique;
178 hash = CM_SCACHE_HASH(&tfid);
180 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
181 fidp->Volume, fidp->Vnode, fidp->Unique);
183 /* do this first, so that if we're executing a callback granting call
184 * at this moment, we kill it before it can be merged in. Otherwise,
185 * it could complete while we're doing the scan below, and get missed
186 * by both the scan and by this code.
188 cm_RecordRacingRevoke(&tfid, 0);
190 lock_ObtainWrite(&cm_scacheLock);
191 /* do all in the hash bucket, since we don't know how many we'll find with
194 for (scp = cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
195 if (scp->fid.volume == tfid.volume &&
196 scp->fid.vnode == tfid.vnode &&
197 scp->fid.unique == tfid.unique &&
198 scp->cbExpires > 0 &&
199 scp->cbServerp != NULL)
201 cm_HoldSCacheNoLock(scp);
202 lock_ReleaseWrite(&cm_scacheLock);
203 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
204 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
205 lock_ObtainMutex(&scp->mx);
206 cm_DiscardSCache(scp);
207 lock_ReleaseMutex(&scp->mx);
208 cm_CallbackNotifyChange(scp);
209 lock_ObtainWrite(&cm_scacheLock);
210 cm_ReleaseSCacheNoLock(scp);
213 lock_ReleaseWrite(&cm_scacheLock);
215 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
216 fidp->Volume, fidp->Vnode, fidp->Unique);
219 /* called to revoke a volume callback, which is typically issued when a volume
220 * is moved from one server to another.
222 * Called with no locks held.
224 void cm_RevokeVolumeCallback(struct rx_call *callp, AFSFid *fidp)
230 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
232 /* do this first, so that if we're executing a callback granting call
233 * at this moment, we kill it before it can be merged in. Otherwise,
234 * it could complete while we're doing the scan below, and get missed
235 * by both the scan and by this code.
237 tfid.cell = tfid.vnode = tfid.unique = 0;
238 tfid.volume = fidp->Volume;
239 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
242 lock_ObtainWrite(&cm_scacheLock);
243 for (hash = 0; hash < cm_data.hashTableSize; hash++) {
244 for(scp=cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
245 if (scp->fid.volume == fidp->Volume &&
246 scp->cbExpires > 0 &&
247 scp->cbServerp != NULL) {
248 cm_HoldSCacheNoLock(scp);
249 lock_ReleaseWrite(&cm_scacheLock);
250 lock_ObtainMutex(&scp->mx);
251 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
252 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
253 cm_DiscardSCache(scp);
254 lock_ReleaseMutex(&scp->mx);
255 cm_CallbackNotifyChange(scp);
256 lock_ObtainWrite(&cm_scacheLock);
257 cm_ReleaseSCacheNoLock(scp);
259 } /* search one hash bucket */
260 } /* search all hash buckets */
262 lock_ReleaseWrite(&cm_scacheLock);
264 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
268 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
269 * given data pointer, without triggering "cast truncates pointer"
270 * warnings. We use this where we explicitly don't care whether a
271 * pointer is truncated -- it loses information where a pointer is
272 * larger than an afs_int32.
276 afs_data_pointer_to_int32(const void *p)
279 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
283 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
288 /* used to determine the byte order of the system */
291 char c[sizeof(int) / sizeof(char)];
297 /* little-endian system */
300 /* big-endian system */
301 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
306 return ip.i32[i32_sub];
308 /*------------------------------------------------------------------------
309 * EXPORTED SRXAFSCB_CallBack
312 * Routine called by the server-side callback RPC interface to
313 * implement passing in callback information.
317 * rx_call : Ptr to Rx call on which this request came in.
318 * fidsArrayp : Ptr to array of fids involved.
319 * cbsArrayp : Ptr to matching callback info for the fids.
325 * Nothing interesting.
329 *------------------------------------------------------------------------*/
330 /* handle incoming RPC callback breaking message.
331 * Called with no locks held.
334 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
338 struct rx_connection *connp;
339 struct rx_peer *peerp;
340 unsigned long host = 0;
341 unsigned short port = 0;
343 MUTEX_ENTER(&callp->lock);
345 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
346 host = rx_HostOf(peerp);
347 port = rx_PortOf(peerp);
350 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
354 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
355 tfidp = &fidsArrayp->AFSCBFids_val[i];
357 if (tfidp->Volume == 0)
358 continue; /* means don't do anything */
359 else if (tfidp->Vnode == 0)
360 cm_RevokeVolumeCallback(callp, tfidp);
362 cm_RevokeCallback(callp, tfidp);
365 MUTEX_EXIT(&callp->lock);
369 /*------------------------------------------------------------------------
370 * EXPORTED SRXAFSCB_InitCallBackState
373 * Routine called by the server-side callback RPC interface to
374 * implement clearing all callbacks from this host.
377 * rx_call : Ptr to Rx call on which this request came in.
383 * Nothing interesting.
387 *------------------------------------------------------------------------*/
388 /* called with no locks by RPC system when a server indicates that it has never
389 * heard from us, or for other reasons has had to discard callbacks from us
390 * without telling us, e.g. a network partition.
393 SRXAFSCB_InitCallBackState(struct rx_call *callp)
395 struct sockaddr_in taddr;
400 struct rx_connection *connp;
401 struct rx_peer *peerp;
402 unsigned long host = 0;
403 unsigned short port = 0;
405 MUTEX_ENTER(&callp->lock);
407 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
408 host = rx_HostOf(peerp);
409 port = rx_PortOf(peerp);
412 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
416 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
417 taddr.sin_family = AF_INET;
418 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
420 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
422 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
424 /* record the callback in the racing revokes structure. This
425 * shouldn't be necessary, since we shouldn't be making callback
426 * granting calls while we're going to get an initstate call,
427 * but there probably are some obscure races, so better safe
430 * We do this first since we don't hold the cm_scacheLock and vnode
431 * locks over the entire callback scan operation below. The
432 * big loop below is guaranteed to hit any callback already
433 * processed. The call to RecordRacingRevoke is guaranteed
434 * to kill any callback that is currently being returned.
435 * Anything that sneaks past both must start
436 * after the call to RecordRacingRevoke.
438 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
440 /* now search all vnodes looking for guys with this callback, if we
441 * found it, or guys with any callbacks, if we didn't find the server
442 * (that's how multihomed machines will appear and how we'll handle
443 * them, albeit a little inefficiently). That is, we're discarding all
444 * callbacks from all hosts if we get an initstate call from an unknown
445 * host. Since these calls are rare, and multihomed servers
446 * are "rare," hopefully this won't be a problem.
448 lock_ObtainWrite(&cm_scacheLock);
449 for (hash = 0; hash < cm_data.hashTableSize; hash++) {
450 for (scp=cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
451 cm_HoldSCacheNoLock(scp);
452 lock_ReleaseWrite(&cm_scacheLock);
453 lock_ObtainMutex(&scp->mx);
455 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
456 /* we have a callback, now decide if we should clear it */
457 if (scp->cbServerp == tsp || tsp == NULL) {
458 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%p vol %u vn %u uniq %u",
459 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
460 cm_DiscardSCache(scp);
464 lock_ReleaseMutex(&scp->mx);
466 cm_CallbackNotifyChange(scp);
467 lock_ObtainWrite(&cm_scacheLock);
468 cm_ReleaseSCacheNoLock(scp);
469 } /* search one hash bucket */
470 } /* search all hash buckets */
472 lock_ReleaseWrite(&cm_scacheLock);
475 /* reset the No flags on the server */
476 cm_SetServerNo64Bit(tsp, 0);
477 cm_SetServerNoInlineBulk(tsp, 0);
479 /* we're done with the server structure */
483 MUTEX_EXIT(&callp->lock);
487 /*------------------------------------------------------------------------
488 * EXPORTED SRXAFSCB_Probe
491 * Routine called by the server-side callback RPC interface to
492 * implement ``probing'' the Cache Manager, just making sure it's
496 * rx_call : Ptr to Rx call on which this request came in.
502 * Nothing interesting.
506 *------------------------------------------------------------------------*/
508 SRXAFSCB_Probe(struct rx_call *callp)
510 struct rx_connection *connp;
511 struct rx_peer *peerp;
512 unsigned long host = 0;
513 unsigned short port = 0;
515 MUTEX_ENTER(&callp->lock);
517 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
518 host = rx_HostOf(peerp);
519 port = rx_PortOf(peerp);
522 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
526 MUTEX_EXIT(&callp->lock);
530 /*------------------------------------------------------------------------
531 * EXPORTED SRXAFSCB_GetLock
534 * Routine called by the server-side callback RPC interface to
535 * implement pulling out the contents of a lock in the lock
539 * a_call : Ptr to Rx call on which this request came in.
540 * a_index : Index of desired lock.
541 * a_result : Ptr to a buffer for the given lock.
544 * 0 if everything went fine,
545 * 1 if we were given a bad index.
548 * Nothing interesting.
552 *------------------------------------------------------------------------*/
553 /* debug interface */
555 extern osi_rwlock_t cm_aclLock;
556 extern osi_rwlock_t buf_globalLock;
557 extern osi_rwlock_t cm_callbackLock;
558 extern osi_rwlock_t cm_cellLock;
559 extern osi_rwlock_t cm_connLock;
560 extern osi_rwlock_t cm_daemonLock;
561 extern osi_rwlock_t cm_dnlcLock;
562 extern osi_rwlock_t cm_scacheLock;
563 extern osi_rwlock_t cm_serverLock;
564 extern osi_rwlock_t cm_userLock;
565 extern osi_rwlock_t cm_utilsLock;
566 extern osi_rwlock_t cm_volumeLock;
567 extern osi_rwlock_t smb_globalLock;
568 extern osi_rwlock_t smb_rctLock;
570 extern osi_mutex_t cm_Freelance_Lock;
571 extern osi_mutex_t cm_bufGetMutex;
572 extern osi_mutex_t cm_Afsdsbmt_Lock;
573 extern osi_mutex_t tokenEventLock;
574 extern osi_mutex_t smb_ListenerLock;
575 extern osi_mutex_t smb_RawBufLock;
576 extern osi_mutex_t smb_Dir_Watch_Lock;
578 #define LOCKTYPE_RW 1
579 #define LOCKTYPE_MUTEX 2
580 static struct _ltable {
585 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
586 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
587 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
588 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
589 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
590 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
591 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
592 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
593 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
594 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
595 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
596 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
597 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
598 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
599 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
600 {"cm_bufGetMutex", (char*)&cm_bufGetMutex, LOCKTYPE_MUTEX},
601 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
602 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
603 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
604 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
605 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
609 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
611 struct _ltable *tl; /*Ptr to lock table entry */
614 int nentries; /*Num entries in table */
615 int code; /*Return code */
616 struct rx_connection *connp;
617 struct rx_peer *peerp;
618 unsigned long host = 0;
619 unsigned short port = 0;
621 MUTEX_ENTER(&callp->lock);
623 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
624 host = rx_HostOf(peerp);
625 port = rx_PortOf(peerp);
628 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
629 index, ntohl(host), ntohs(port));
631 nentries = sizeof(ltable) / sizeof(struct _ltable);
632 if (index < 0 || index >= nentries) {
639 * Found it - copy out its contents.
642 strncpy(lockp->name, tl->name, sizeof(lockp->name));
643 lockp->name[sizeof(lockp->name)-1] = '\0';
644 lockp->lock.waitStates = 0;
645 switch ( tl->type ) {
647 rwp = (osi_rwlock_t *)tl->addr;
648 lockp->lock.exclLocked = rwp->flags;
649 lockp->lock.readersReading = rwp->readers;
650 lockp->lock.numWaiting = rwp->waiters;
653 mtxp = (osi_mutex_t *)tl->addr;
654 lockp->lock.exclLocked = mtxp->flags;
655 lockp->lock.readersReading = 0;
656 lockp->lock.numWaiting = mtxp->waiters;
659 lockp->lock.pid_last_reader = 0;
660 lockp->lock.pid_writer = 0;
661 lockp->lock.src_indicator = 0;
665 MUTEX_EXIT(&callp->lock);
669 /* debug interface */
671 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
676 struct rx_connection *connp;
677 struct rx_peer *peerp;
678 unsigned long host = 0;
679 unsigned short port = 0;
681 MUTEX_ENTER(&callp->lock);
683 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
684 host = rx_HostOf(peerp);
685 port = rx_PortOf(peerp);
688 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
689 ntohl(host), ntohs(port));
691 lock_ObtainRead(&cm_scacheLock);
692 for (i = 0; i < cm_data.hashTableSize; i++) {
693 for (scp = cm_data.hashTablep[i]; scp; scp = scp->nextp) {
697 } /*Zip through current hash chain */
698 } /*Zip through hash chains */
708 * Copy out the located entry.
710 memset(cep, 0, sizeof(AFSDBCacheEntry));
711 cep->addr = afs_data_pointer_to_int32(scp);
712 cep->cell = scp->fid.cell;
713 cep->netFid.Volume = scp->fid.volume;
714 cep->netFid.Vnode = scp->fid.vnode;
715 cep->netFid.Unique = scp->fid.unique;
716 cep->lock.waitStates = 0;
717 cep->lock.exclLocked = scp->mx.flags;
718 cep->lock.readersReading = 0;
719 cep->lock.numWaiting = scp->mx.waiters;
720 cep->lock.pid_last_reader = 0;
721 cep->lock.pid_writer = 0;
722 cep->lock.src_indicator = 0;
723 cep->Length = scp->length.LowPart;
724 cep->DataVersion = scp->dataVersion;
725 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
726 cep->cbExpires = scp->cbExpires;
727 cep->refCount = scp->refCount;
728 cep->opens = scp->openReads;
729 cep->writers = scp->openWrites;
730 switch (scp->fileType) {
731 case CM_SCACHETYPE_FILE:
734 case CM_SCACHETYPE_MOUNTPOINT:
737 case CM_SCACHETYPE_DIRECTORY:
738 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
743 case CM_SCACHETYPE_SYMLINK:
746 case CM_SCACHETYPE_DFSLINK:
749 case CM_SCACHETYPE_INVALID:
754 if (scp->flags & CM_SCACHEFLAG_STATD)
756 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
758 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
759 scp->mountPointStringp[0])
761 if (scp->flags & CM_SCACHEFLAG_WAITING)
766 * Return our results.
769 lock_ReleaseRead(&cm_scacheLock);
771 MUTEX_EXIT(&callp->lock);
775 /* debug interface */
777 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
782 struct rx_connection *connp;
783 struct rx_peer *peerp;
784 unsigned long host = 0;
785 unsigned short port = 0;
787 MUTEX_ENTER(&callp->lock);
789 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
790 host = rx_HostOf(peerp);
791 port = rx_PortOf(peerp);
794 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
795 ntohl(host), ntohs(port));
797 lock_ObtainRead(&cm_scacheLock);
798 for (i = 0; i < cm_data.hashTableSize; i++) {
799 for (scp = cm_data.hashTablep[i]; scp; scp = scp->nextp) {
803 } /*Zip through current hash chain */
804 } /*Zip through hash chains */
814 * Copy out the located entry.
816 memset(cep, 0, sizeof(AFSDBCacheEntry64));
817 cep->addr = afs_data_pointer_to_int32(scp);
818 cep->cell = scp->fid.cell;
819 cep->netFid.Volume = scp->fid.volume;
820 cep->netFid.Vnode = scp->fid.vnode;
821 cep->netFid.Unique = scp->fid.unique;
822 cep->lock.waitStates = 0;
823 cep->lock.exclLocked = scp->mx.flags;
824 cep->lock.readersReading = 0;
825 cep->lock.numWaiting = scp->mx.waiters;
826 cep->lock.pid_last_reader = 0;
827 cep->lock.pid_writer = 0;
828 cep->lock.src_indicator = 0;
829 #if !defined(AFS_64BIT_ENV)
830 cep->Length.high = scp->length.HighPart;
831 cep->Length.low = scp->length.LowPart;
833 cep->Length = (afs_int64) scp->length.QuadPart;
835 cep->DataVersion = scp->dataVersion;
836 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
837 cep->cbExpires = scp->cbExpires;
838 cep->refCount = scp->refCount;
839 cep->opens = scp->openReads;
840 cep->writers = scp->openWrites;
841 switch (scp->fileType) {
842 case CM_SCACHETYPE_FILE:
845 case CM_SCACHETYPE_MOUNTPOINT:
848 case CM_SCACHETYPE_DIRECTORY:
849 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
854 case CM_SCACHETYPE_SYMLINK:
857 case CM_SCACHETYPE_DFSLINK:
860 case CM_SCACHETYPE_INVALID:
865 if (scp->flags & CM_SCACHEFLAG_STATD)
867 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
869 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
870 scp->mountPointStringp[0])
872 if (scp->flags & CM_SCACHEFLAG_WAITING)
877 * Return our results.
880 lock_ReleaseRead(&cm_scacheLock);
882 MUTEX_EXIT(&callp->lock);
886 /* debug interface: not implemented */
888 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
890 struct rx_connection *connp;
891 struct rx_peer *peerp;
892 unsigned long host = 0;
893 unsigned short port = 0;
895 MUTEX_ENTER(&callp->lock);
897 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
898 host = rx_HostOf(peerp);
899 port = rx_PortOf(peerp);
902 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
903 ntohl(host), ntohs(port));
906 MUTEX_EXIT(&callp->lock);
910 /* debug interface: not implemented */
912 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
913 AFSCB_CollData *datap)
915 struct rx_connection *connp;
916 struct rx_peer *peerp;
917 unsigned long host = 0;
918 unsigned short port = 0;
920 MUTEX_ENTER(&callp->lock);
922 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
923 host = rx_HostOf(peerp);
924 port = rx_PortOf(peerp);
927 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
928 ntohl(host), ntohs(port));
930 MUTEX_EXIT(&callp->lock);
935 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
937 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
939 return SRXAFSCB_InitCallBackState(callp);
942 /* debug interface */
944 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
947 int cm_noIPAddr; /* number of client network interfaces */
948 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
949 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
950 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
951 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
953 struct rx_connection *connp;
954 struct rx_peer *peerp;
955 unsigned long host = 0;
956 unsigned short port = 0;
958 MUTEX_ENTER(&callp->lock);
960 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
961 host = rx_HostOf(peerp);
962 port = rx_PortOf(peerp);
965 /* get network related info */
966 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
967 code = syscfg_GetIFInfo(&cm_noIPAddr,
968 cm_IPAddr, cm_SubnetMask,
969 cm_NetMtu, cm_NetFlags);
971 /* return all network interface addresses */
972 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
976 addr->numberOfInterfaces = cm_noIPAddr;
977 addr->uuid = cm_data.Uuid;
978 for ( i=0; i < cm_noIPAddr; i++ ) {
979 addr->addr_in[i] = cm_IPAddr[i];
980 addr->subnetmask[i] = cm_SubnetMask[i];
981 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
982 cm_NetMtu[i] : rx_mtu;
985 MUTEX_EXIT(&callp->lock);
990 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
994 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
995 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",p);
998 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1000 return SRXAFSCB_InitCallBackState(callp);
1003 /* debug interface */
1005 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1007 struct rx_connection *connp;
1008 struct rx_peer *peerp;
1009 unsigned long host = 0;
1010 unsigned short port = 0;
1014 MUTEX_ENTER(&callp->lock);
1016 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1017 host = rx_HostOf(peerp);
1018 port = rx_PortOf(peerp);
1021 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1022 UuidToString((UUID *)&cm_data.Uuid, &p);
1023 UuidToString((UUID *)clientUuid, &q);
1024 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1025 osi_LogSaveString(afsd_logp,p),
1026 osi_LogSaveString(afsd_logp,q),
1032 code = 1; /* failure */
1034 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1038 MUTEX_EXIT(&callp->lock);
1042 /* debug interface */
1044 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1045 char **a_name, serverList *a_hosts)
1049 cm_serverRef_t * serverRefp;
1050 struct rx_connection *connp;
1051 struct rx_peer *peerp;
1052 unsigned long host = 0;
1053 unsigned short port = 0;
1055 MUTEX_ENTER(&callp->lock);
1057 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1058 host = rx_HostOf(peerp);
1059 port = rx_PortOf(peerp);
1062 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1063 a_cellnum, ntohl(host), ntohs(port));
1065 a_hosts->serverList_val = 0;
1066 a_hosts->serverList_len = 0;
1068 cellp = cm_FindCellByID(a_cellnum);
1070 *a_name = strdup("");
1071 MUTEX_EXIT(&callp->lock);
1075 lock_ObtainRead(&cm_serverLock);
1076 *a_name = strdup(cellp->name);
1078 for ( sn = 0, serverRefp = cellp->vlServersp;
1079 sn < AFSMAXCELLHOSTS && serverRefp;
1080 sn++, serverRefp = serverRefp->next);
1082 a_hosts->serverList_len = sn;
1083 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1085 for ( sn = 0, serverRefp = cellp->vlServersp;
1086 sn < AFSMAXCELLHOSTS && serverRefp;
1087 sn++, serverRefp = serverRefp->next)
1089 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1092 lock_ReleaseRead(&cm_serverLock);
1093 MUTEX_EXIT(&callp->lock);
1097 /* debug interface */
1099 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1100 struct interfaceAddr *addr,
1101 Capabilities * capabilities)
1104 afs_int32 *dataBuffP;
1105 afs_int32 dataBytes;
1106 int cm_noIPAddr; /* number of client network interfaces */
1107 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
1108 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
1109 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
1110 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
1112 struct rx_connection *connp;
1113 struct rx_peer *peerp;
1114 unsigned long host = 0;
1115 unsigned short port = 0;
1117 MUTEX_ENTER(&callp->lock);
1119 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1120 host = rx_HostOf(peerp);
1121 port = rx_PortOf(peerp);
1124 /* get network related info */
1125 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1126 code = syscfg_GetIFInfo(&cm_noIPAddr,
1127 cm_IPAddr, cm_SubnetMask,
1128 cm_NetMtu, cm_NetFlags);
1130 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1134 /* return all network interface addresses */
1135 addr->numberOfInterfaces = cm_noIPAddr;
1136 addr->uuid = cm_data.Uuid;
1137 for ( i=0; i < cm_noIPAddr; i++ ) {
1138 addr->addr_in[i] = cm_IPAddr[i];
1139 addr->subnetmask[i] = cm_SubnetMask[i];
1140 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1141 cm_NetMtu[i] : rx_mtu;
1144 dataBytes = 1 * sizeof(afs_int32);
1145 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1146 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1147 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1148 capabilities->Capabilities_val = dataBuffP;
1150 MUTEX_EXIT(&callp->lock);
1154 /*------------------------------------------------------------------------
1155 * EXPORTED SRXAFSCB_GetServerPrefs
1158 * Routine to list server preferences used by this client.
1161 * a_call : Ptr to Rx call on which this request came in.
1162 * a_index : Input server index
1163 * a_srvr_addr : Output server address (0xffffffff on last server)
1164 * a_srvr_rank : Output server rank
1170 * Nothing interesting.
1174 *------------------------------------------------------------------------*/
1176 int SRXAFSCB_GetServerPrefs(
1177 struct rx_call *callp,
1179 afs_int32 *a_srvr_addr,
1180 afs_int32 *a_srvr_rank)
1182 struct rx_connection *connp;
1183 struct rx_peer *peerp;
1184 unsigned long host = 0;
1185 unsigned short port = 0;
1187 MUTEX_ENTER(&callp->lock);
1189 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1190 host = rx_HostOf(peerp);
1191 port = rx_PortOf(peerp);
1194 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1198 *a_srvr_addr = 0xffffffff;
1199 *a_srvr_rank = 0xffffffff;
1201 MUTEX_EXIT(&callp->lock);
1205 /*------------------------------------------------------------------------
1206 * EXPORTED SRXAFSCB_GetCellServDB
1209 * Routine to list cells configured for this client
1212 * a_call : Ptr to Rx call on which this request came in.
1213 * a_index : Input cell index
1214 * a_name : Output cell name ("" on last cell)
1215 * a_hosts : Output cell database servers
1221 * Nothing interesting.
1225 *------------------------------------------------------------------------*/
1227 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1228 serverList *a_hosts)
1231 struct rx_connection *connp;
1232 struct rx_peer *peerp;
1233 unsigned long host = 0;
1234 unsigned short port = 0;
1236 MUTEX_ENTER(&callp->lock);
1238 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1239 host = rx_HostOf(peerp);
1240 port = rx_PortOf(peerp);
1243 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1244 ntohl(host), ntohs(port));
1246 t_name = (char *)malloc(AFSNAMEMAX);
1249 a_hosts->serverList_len = 0;
1251 MUTEX_EXIT(&callp->lock);
1255 /*------------------------------------------------------------------------
1256 * EXPORTED SRXAFSCB_GetLocalCell
1259 * Routine to return name of client's local cell
1262 * a_call : Ptr to Rx call on which this request came in.
1263 * a_name : Output cell name
1269 * Nothing interesting.
1273 *------------------------------------------------------------------------*/
1275 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1278 struct rx_connection *connp;
1279 struct rx_peer *peerp;
1280 unsigned long host = 0;
1281 unsigned short port = 0;
1283 MUTEX_ENTER(&callp->lock);
1285 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1286 host = rx_HostOf(peerp);
1287 port = rx_PortOf(peerp);
1290 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1291 ntohl(host), ntohs(port));
1293 if (cm_data.rootCellp) {
1294 t_name = (char *)malloc(strlen(cm_data.rootCellp->name)+1);
1295 strcpy(t_name, cm_data.rootCellp->name);
1297 t_name = (char *)malloc(1);
1302 MUTEX_EXIT(&callp->lock);
1308 * afs_MarshallCacheConfig - marshall client cache configuration
1312 * IN callerVersion - the rpc stat version of the caller.
1314 * IN config - client cache configuration.
1316 * OUT ptr - buffer where configuration is marshalled.
1322 static void afs_MarshallCacheConfig(
1323 afs_uint32 callerVersion,
1324 cm_initparams_v1 *config,
1328 * We currently only support version 1.
1330 *(ptr++) = config->nChunkFiles;
1331 *(ptr++) = config->nStatCaches;
1332 *(ptr++) = config->nDataCaches;
1333 *(ptr++) = config->nVolumeCaches;
1334 *(ptr++) = config->firstChunkSize;
1335 *(ptr++) = config->otherChunkSize;
1336 *(ptr++) = config->cacheSize;
1337 *(ptr++) = config->setTime;
1338 *(ptr++) = config->memCache;
1343 /*------------------------------------------------------------------------
1344 * EXPORTED SRXAFSCB_GetCacheConfig
1347 * Routine to return parameters used to initialize client cache.
1348 * Client may request any format version. Server may not return
1349 * format version greater than version requested by client.
1352 * a_call: Ptr to Rx call on which this request came in.
1353 * callerVersion: Data format version desired by the client.
1354 * serverVersion: Data format version of output data.
1355 * configCount: Number bytes allocated for output data.
1356 * config: Client cache configuration.
1362 * Nothing interesting.
1366 *------------------------------------------------------------------------*/
1368 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1369 afs_uint32 callerVersion,
1370 afs_uint32 *serverVersion,
1371 afs_uint32 *configCount,
1372 cacheConfig *config)
1374 afs_uint32 *t_config;
1376 extern cm_initparams_v1 cm_initParams;
1377 struct rx_connection *connp;
1378 struct rx_peer *peerp;
1379 unsigned long host = 0;
1380 unsigned short port = 0;
1382 MUTEX_ENTER(&callp->lock);
1384 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1385 host = rx_HostOf(peerp);
1386 port = rx_PortOf(peerp);
1389 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1390 ntohl(host), ntohs(port));
1393 * Currently only support version 1
1395 allocsize = sizeof(cm_initparams_v1);
1396 t_config = (afs_uint32 *)malloc(allocsize);
1398 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1400 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1403 #define SIZE_MAX UINT_MAX
1405 osi_assert(allocsize < SIZE_MAX);
1407 *configCount = (afs_uint32)allocsize;
1408 config->cacheConfig_val = t_config;
1409 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1411 MUTEX_EXIT(&callp->lock);
1415 /* called by afsd without any locks to initialize this module */
1416 void cm_InitCallback(void)
1418 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
1419 cm_activeCallbackGrantingCalls = 0;
1422 /* called with locked scp; tells us whether we've got a callback.
1423 * Expirations are checked by a background daemon so as to make
1424 * this function as inexpensive as possible
1426 int cm_HaveCallback(cm_scache_t *scp)
1428 #ifdef AFS_FREELANCE_CLIENT
1429 // yj: we handle callbacks specially for callbacks on the root directory
1430 // Since it's local, we almost always say that we have callback on it
1431 // The only time we send back a 0 is if we're need to initialize or
1432 // reinitialize the fake directory
1434 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1435 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1436 // hence should return false. it's 0 otherwise
1437 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1438 // if the fake directory is loaded and this is the first time cm_HaveCallback
1439 // is called since then. We return false in this case to allow cm_GetCallback
1440 // to be called because cm_GetCallback has some initialization work to do.
1441 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1442 // good shape and we simply return true, provided no change is detected.
1445 if (cm_freelanceEnabled &&
1446 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1447 /* if it's something on /afs */
1448 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
1449 /* if it's not root.afs */
1453 lock_ObtainMutex(&cm_Freelance_Lock);
1454 fdc = cm_fakeDirCallback;
1455 fgc = cm_fakeGettingCallback;
1456 lock_ReleaseMutex(&cm_Freelance_Lock);
1458 if (fdc==1) { // first call since init
1460 } else if (fdc==2 && !fgc) { // we're in good shape
1461 if (cm_getLocalMountPointChange()) { // check for changes
1462 cm_clearLocalMountPointChange(); // clear the changefile
1463 lock_ReleaseMutex(&scp->mx); // this is re-locked in reInitLocalMountPoints
1464 cm_reInitLocalMountPoints(); // start reinit
1465 lock_ObtainMutex(&scp->mx); // now get the lock back
1468 return 1; // no change
1474 if (scp->cbServerp != NULL)
1480 /* need to detect a broken callback that races with our obtaining a callback.
1481 * Need to be able to do this even if we don't know the file ID of the file
1482 * we're breaking the callback on at the time we start the acquisition of the
1483 * callback (as in the case where we are creating a file).
1485 * So, we start by writing down the count of the # of callbacks we've received
1486 * so far, and bumping a global counter of the # of callback granting calls
1487 * outstanding (all done under cm_callbackLock).
1489 * When we're back from the call, we look at all of the callback revokes with
1490 * counter numbers greater than the one we recorded in our caller's structure,
1491 * and replay those that are higher than when we started the call.
1493 * We free all the structures in the queue when the count of the # of outstanding
1494 * callback-granting calls drops to zero.
1496 * We call this function with the scp locked, too, but in its current implementation,
1497 * this knowledge is not used.
1499 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1501 lock_ObtainWrite(&cm_callbackLock);
1502 cbrp->callbackCount = cm_callbackCount;
1503 cm_activeCallbackGrantingCalls++;
1504 cbrp->startTime = osi_Time();
1505 cbrp->serverp = NULL;
1506 lock_ReleaseWrite(&cm_callbackLock);
1509 /* Called at the end of a callback-granting call, to remove the callback
1510 * info from the scache entry, if necessary.
1512 * Called with scp locked, so we can discard the callbacks easily with
1513 * this locking hierarchy.
1515 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1516 AFSCallBack *cbp, long flags)
1518 cm_racingRevokes_t *revp; /* where we are */
1519 cm_racingRevokes_t *nrevp; /* where we'll be next */
1521 cm_server_t * serverp = 0;
1524 lock_ObtainWrite(&cm_callbackLock);
1525 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1526 osi_assert(cm_activeCallbackGrantingCalls > 0);
1529 osi_assert(cm_activeCallbackGrantingCalls-- > 0);
1531 if (cm_activeCallbackGrantingCalls == 0)
1536 /* record the callback; we'll clear it below if we really lose it */
1539 if (scp->cbServerp != cbrp->serverp) {
1540 serverp = scp->cbServerp;
1542 cm_GetServer(cbrp->serverp);
1543 scp->cbServerp = cbrp->serverp;
1546 serverp = cbrp->serverp;
1548 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1551 serverp = cbrp->serverp;
1554 cbrp->serverp = NULL;
1557 /* a callback was actually revoked during our granting call, so
1558 * run down the list of revoked fids, looking for ours.
1559 * If activeCallbackGrantingCalls is zero, free the elements, too.
1561 * May need to go through entire list just to do the freeing.
1563 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1564 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1565 /* if this callback came in later than when we started the
1566 * callback-granting call, and if this fid is the right fid,
1567 * then clear the callback.
1569 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1570 && revp->callbackCount > cbrp->callbackCount
1571 && (( scp->fid.volume == revp->fid.volume &&
1572 scp->fid.vnode == revp->fid.vnode &&
1573 scp->fid.unique == revp->fid.unique)
1575 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1576 scp->fid.volume == revp->fid.volume)
1578 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1579 /* this one matches */
1581 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1583 cbrp->callbackCount, revp->callbackCount,
1591 /* if we freed the list, zap the pointer to it */
1593 cm_racingRevokesp = NULL;
1595 lock_ReleaseWrite(&cm_callbackLock);
1598 cm_DiscardSCache(scp);
1599 lock_ReleaseMutex(&scp->mx);
1600 cm_CallbackNotifyChange(scp);
1601 lock_ObtainMutex(&scp->mx);
1605 lock_ObtainWrite(&cm_serverLock);
1606 cm_FreeServer(serverp);
1607 lock_ReleaseWrite(&cm_serverLock);
1611 /* if flags is 1, we want to force the code to make one call, anyway.
1612 * called with locked scp; returns with same.
1614 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1615 struct cm_req *reqp, long flags)
1618 cm_conn_t *connp = NULL;
1619 AFSFetchStatus afsStatus;
1621 AFSCallBack callback;
1623 cm_callbackRequest_t cbr;
1627 struct rx_connection * callp = NULL;
1629 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1630 scp, scp->fid.cell, scp->fid.volume, flags);
1632 #ifdef AFS_FREELANCE_CLIENT
1633 // The case where a callback is needed on /afs is handled
1634 // specially. We need to fetch the status by calling
1635 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1636 if (cm_freelanceEnabled) {
1637 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1638 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1639 scp->fid.unique==0x1 &&
1640 scp->fid.vnode==0x1) {
1642 // Start by indicating that we're in the process
1643 // of fetching the callback
1644 lock_ObtainMutex(&cm_Freelance_Lock);
1645 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1646 cm_fakeGettingCallback = 1;
1647 lock_ReleaseMutex(&cm_Freelance_Lock);
1649 // Fetch the status info
1650 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
1652 // Indicate that the callback is not done
1653 lock_ObtainMutex(&cm_Freelance_Lock);
1654 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1655 cm_fakeDirCallback = 2;
1657 // Indicate that we're no longer fetching the callback
1658 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1659 cm_fakeGettingCallback = 0;
1660 lock_ReleaseMutex(&cm_Freelance_Lock);
1665 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1666 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1669 #endif /* AFS_FREELANCE_CLIENT */
1671 mustCall = (flags & 1);
1672 cm_AFSFidFromFid(&tfid, &scp->fid);
1674 if (!mustCall && cm_HaveCallback(scp)) {
1675 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1676 scp, scp->fid.cell, scp->fid.volume);
1680 /* turn off mustCall, since it has now forced us past the check above */
1683 /* otherwise, we have to make an RPC to get the status */
1684 sflags = CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK;
1685 cm_SyncOp(scp, NULL, userp, reqp, 0, sflags);
1686 cm_StartCallbackGrantingCall(scp, &cbr);
1688 lock_ReleaseMutex(&scp->mx);
1690 /* now make the RPC */
1691 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1692 scp, sfid.volume, sfid.vnode, sfid.unique);
1694 code = cm_Conn(&sfid, userp, reqp, &connp);
1698 callp = cm_GetRxConn(connp);
1699 code = RXAFS_FetchStatus(callp, &tfid,
1700 &afsStatus, &callback, &volSync);
1701 rx_PutConnection(callp);
1703 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1705 code = cm_MapRPCError(code, reqp);
1707 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1708 code, scp, scp->fid.volume, scp->fid.vnode);
1710 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1711 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1713 lock_ObtainMutex(&scp->mx);
1715 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1716 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
1718 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1720 cm_SyncOpDone(scp, NULL, sflags);
1722 /* now check to see if we got an error */
1724 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1725 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1726 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1732 /* called periodically by cm_daemon to shut down use of expired callbacks */
1733 void cm_CheckCBExpiration(void)
1739 osi_Log0(afsd_logp, "CheckCBExpiration");
1742 lock_ObtainWrite(&cm_scacheLock);
1743 for (i=0; i<cm_data.hashTableSize; i++) {
1744 for (scp = cm_data.hashTablep[i]; scp; scp=scp->nextp) {
1745 cm_HoldSCacheNoLock(scp);
1746 if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) {
1747 lock_ReleaseWrite(&cm_scacheLock);
1748 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1749 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1750 lock_ObtainMutex(&scp->mx);
1751 cm_DiscardSCache(scp);
1752 lock_ReleaseMutex(&scp->mx);
1753 cm_CallbackNotifyChange(scp);
1754 lock_ObtainWrite(&cm_scacheLock);
1756 cm_ReleaseSCacheNoLock(scp);
1759 lock_ReleaseWrite(&cm_scacheLock);
1761 osi_Log0(afsd_logp, "CheckCBExpiration Complete");