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>
25 #include <rx_pthread.h>
28 #include <WINNT/syscfg.h>
29 #include <WINNT/afsreg.h>
31 /*extern void afsi_log(char *pattern, ...);*/
33 /* read/write lock for all global storage in this module */
34 osi_rwlock_t cm_callbackLock;
36 #ifdef AFS_FREELANCE_CLIENT
37 extern osi_mutex_t cm_Freelance_Lock;
40 /* count of # of callback breaking messages received by this CM so far. We use
41 * this count in determining whether there have been any callback breaks that
42 * apply to a call that returned a new callback. If the counter doesn't
43 * increase during a call, then we know that no callbacks were broken during
44 * that call, and thus that the callback that was just returned is still valid.
46 long cm_callbackCount;
48 /* count of number of RPCs potentially returning a callback executing now.
49 * When this counter hits zero, we can clear out the racing revokes list, since
50 * at that time, we know that none of the just-executed callback revokes will
51 * apply to any future call that returns a callback (since the latter hasn't
52 * even started execution yet).
54 long cm_activeCallbackGrantingCalls;
56 /* list of callbacks that have been broken recently. If a call returning a
57 * callback is executing and a callback revoke runs immediately after it at the
58 * server, the revoke may end up being processed before the response to the
59 * original callback granting call. We detect this by keeping a list of
60 * callback revokes that have been received since we *started* the callback
61 * granting call, and discarding any callbacks received for the same file ID,
62 * even if the callback revoke was received before the callback grant.
64 cm_racingRevokes_t *cm_racingRevokesp;
66 /* record a (potentially) racing revoke for this file ID; null means for all
67 * file IDs, and is used by InitCallBackState.
69 * The cancelFlags describe whether we're just discarding callbacks for the same
70 * file ID, the same volume, or all from the same server.
72 * Called with no locks held.
74 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
76 cm_racingRevokes_t *rp;
78 lock_ObtainWrite(&cm_callbackLock);
80 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
81 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
83 if (cm_activeCallbackGrantingCalls > 0) {
84 rp = malloc(sizeof(*rp));
85 memset(rp, 0, sizeof(*rp));
86 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
87 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
88 if (fidp) rp->fid = *fidp;
89 rp->callbackCount = ++cm_callbackCount;
91 lock_ReleaseWrite(&cm_callbackLock);
95 * When we lose a callback, may have to send change notification replies.
96 * Do not call with a lock on the scp.
98 void cm_CallbackNotifyChange(cm_scache_t *scp)
104 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
105 AFSREG_CLT_OPENAFS_SUBKEY,
107 KEY_READ|KEY_QUERY_VALUE,
108 &hKey) == ERROR_SUCCESS) {
110 dummyLen = sizeof(DWORD);
111 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
112 (BYTE *) &dwDelay, &dummyLen);
116 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
119 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
120 scp->fileType, scp->flags, dwDelay);
125 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
126 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
128 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
129 scp, NULL, NULL, TRUE);
134 tfid.cell = scp->fid.cell;
135 tfid.volume = scp->fid.volume;
136 tfid.vnode = scp->parentVnode;
137 tfid.unique = scp->parentUnique;
138 dscp = cm_FindSCache(&tfid);
140 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
142 FILE_NOTIFY_GENERIC_FILE_FILTER,
143 dscp, NULL, NULL, TRUE);
145 cm_ReleaseSCache(dscp);
149 /* called with no locks held for every file ID that is revoked directly by
150 * a callback revoke call. Does not have to handle volume callback breaks,
151 * since those have already been split out.
153 * The callp parameter is currently unused.
155 void cm_RevokeCallback(struct rx_call *callp, AFSFid *fidp)
161 /* don't bother setting cell, since we won't be checking it (to aid
162 * in working with multi-homed servers: we don't know the cell if we
163 * don't recognize the IP address).
166 tfid.volume = fidp->Volume;
167 tfid.vnode = fidp->Vnode;
168 tfid.unique = fidp->Unique;
169 hash = CM_SCACHE_HASH(&tfid);
171 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
172 fidp->Volume, fidp->Vnode, fidp->Unique);
174 /* do this first, so that if we're executing a callback granting call
175 * at this moment, we kill it before it can be merged in. Otherwise,
176 * it could complete while we're doing the scan below, and get missed
177 * by both the scan and by this code.
179 cm_RecordRacingRevoke(&tfid, 0);
181 lock_ObtainWrite(&cm_scacheLock);
182 /* do all in the hash bucket, since we don't know how many we'll find with
185 for (scp = cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
186 if (scp->fid.volume == tfid.volume &&
187 scp->fid.vnode == tfid.vnode &&
188 scp->fid.unique == tfid.unique &&
189 scp->cbExpires > 0 &&
190 scp->cbServerp != NULL)
192 cm_HoldSCacheNoLock(scp);
193 lock_ReleaseWrite(&cm_scacheLock);
194 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%x vol %u vn %u uniq %u",
195 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
196 lock_ObtainMutex(&scp->mx);
197 cm_DiscardSCache(scp);
198 lock_ReleaseMutex(&scp->mx);
199 cm_CallbackNotifyChange(scp);
200 lock_ObtainWrite(&cm_scacheLock);
201 cm_ReleaseSCacheNoLock(scp);
204 lock_ReleaseWrite(&cm_scacheLock);
206 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
207 fidp->Volume, fidp->Vnode, fidp->Unique);
210 /* called to revoke a volume callback, which is typically issued when a volume
211 * is moved from one server to another.
213 * Called with no locks held.
215 void cm_RevokeVolumeCallback(struct rx_call *callp, AFSFid *fidp)
221 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
223 /* do this first, so that if we're executing a callback granting call
224 * at this moment, we kill it before it can be merged in. Otherwise,
225 * it could complete while we're doing the scan below, and get missed
226 * by both the scan and by this code.
228 tfid.cell = tfid.vnode = tfid.unique = 0;
229 tfid.volume = fidp->Volume;
230 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
233 lock_ObtainWrite(&cm_scacheLock);
234 for (hash = 0; hash < cm_data.hashTableSize; hash++) {
235 for(scp=cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
236 if (scp->fid.volume == fidp->Volume &&
237 scp->cbExpires > 0 &&
238 scp->cbServerp != NULL) {
239 cm_HoldSCacheNoLock(scp);
240 lock_ReleaseWrite(&cm_scacheLock);
241 lock_ObtainMutex(&scp->mx);
242 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%x vol %u vn %u uniq %u",
243 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
244 cm_DiscardSCache(scp);
245 lock_ReleaseMutex(&scp->mx);
246 cm_CallbackNotifyChange(scp);
247 lock_ObtainWrite(&cm_scacheLock);
248 cm_ReleaseSCacheNoLock(scp);
250 } /* search one hash bucket */
251 } /* search all hash buckets */
253 lock_ReleaseWrite(&cm_scacheLock);
255 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
259 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
260 * given data pointer, without triggering "cast truncates pointer"
261 * warnings. We use this where we explicitly don't care whether a
262 * pointer is truncated -- it loses information where a pointer is
263 * larger than an afs_int32.
267 afs_data_pointer_to_int32(const void *p)
270 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
274 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
279 /* used to determine the byte order of the system */
282 char c[sizeof(int) / sizeof(char)];
288 /* little-endian system */
291 /* big-endian system */
292 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
297 return ip.i32[i32_sub];
299 /*------------------------------------------------------------------------
300 * EXPORTED SRXAFSCB_CallBack
303 * Routine called by the server-side callback RPC interface to
304 * implement passing in callback information.
308 * rx_call : Ptr to Rx call on which this request came in.
309 * fidsArrayp : Ptr to array of fids involved.
310 * cbsArrayp : Ptr to matching callback info for the fids.
316 * Nothing interesting.
320 *------------------------------------------------------------------------*/
321 /* handle incoming RPC callback breaking message.
322 * Called with no locks held.
325 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
329 struct rx_connection *connp;
330 struct rx_peer *peerp;
331 unsigned long host = 0;
332 unsigned short port = 0;
334 MUTEX_ENTER(&callp->lock);
336 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
337 host = rx_HostOf(peerp);
338 port = rx_PortOf(peerp);
341 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
345 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
346 tfidp = &fidsArrayp->AFSCBFids_val[i];
348 if (tfidp->Volume == 0)
349 continue; /* means don't do anything */
350 else if (tfidp->Vnode == 0)
351 cm_RevokeVolumeCallback(callp, tfidp);
353 cm_RevokeCallback(callp, tfidp);
356 MUTEX_EXIT(&callp->lock);
360 /*------------------------------------------------------------------------
361 * EXPORTED SRXAFSCB_InitCallBackState
364 * Routine called by the server-side callback RPC interface to
365 * implement clearing all callbacks from this host.
368 * rx_call : Ptr to Rx call on which this request came in.
374 * Nothing interesting.
378 *------------------------------------------------------------------------*/
379 /* called with no locks by RPC system when a server indicates that it has never
380 * heard from us, or for other reasons has had to discard callbacks from us
381 * without telling us, e.g. a network partition.
384 SRXAFSCB_InitCallBackState(struct rx_call *callp)
386 struct sockaddr_in taddr;
391 struct rx_connection *connp;
392 struct rx_peer *peerp;
393 unsigned long host = 0;
394 unsigned short port = 0;
396 MUTEX_ENTER(&callp->lock);
398 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
399 host = rx_HostOf(peerp);
400 port = rx_PortOf(peerp);
403 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
407 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
408 taddr.sin_family = AF_INET;
409 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
411 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
413 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
415 /* record the callback in the racing revokes structure. This
416 * shouldn't be necessary, since we shouldn't be making callback
417 * granting calls while we're going to get an initstate call,
418 * but there probably are some obscure races, so better safe
421 * We do this first since we don't hold the cm_scacheLock and vnode
422 * locks over the entire callback scan operation below. The
423 * big loop below is guaranteed to hit any callback already
424 * processed. The call to RecordRacingRevoke is guaranteed
425 * to kill any callback that is currently being returned.
426 * Anything that sneaks past both must start
427 * after the call to RecordRacingRevoke.
429 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
431 /* now search all vnodes looking for guys with this callback, if we
432 * found it, or guys with any callbacks, if we didn't find the server
433 * (that's how multihomed machines will appear and how we'll handle
434 * them, albeit a little inefficiently). That is, we're discarding all
435 * callbacks from all hosts if we get an initstate call from an unknown
436 * host. Since these calls are rare, and multihomed servers
437 * are "rare," hopefully this won't be a problem.
439 lock_ObtainWrite(&cm_scacheLock);
440 for (hash = 0; hash < cm_data.hashTableSize; hash++) {
441 for (scp=cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
442 cm_HoldSCacheNoLock(scp);
443 lock_ReleaseWrite(&cm_scacheLock);
444 lock_ObtainMutex(&scp->mx);
446 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
447 /* we have a callback, now decide if we should clear it */
448 if (scp->cbServerp == tsp || tsp == NULL) {
449 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%x vol %u vn %u uniq %u",
450 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
451 cm_DiscardSCache(scp);
455 lock_ReleaseMutex(&scp->mx);
457 cm_CallbackNotifyChange(scp);
458 lock_ObtainWrite(&cm_scacheLock);
459 cm_ReleaseSCacheNoLock(scp);
460 } /* search one hash bucket */
461 } /* search all hash buckets */
463 lock_ReleaseWrite(&cm_scacheLock);
465 /* we're done with the server structure */
469 MUTEX_EXIT(&callp->lock);
473 /*------------------------------------------------------------------------
474 * EXPORTED SRXAFSCB_Probe
477 * Routine called by the server-side callback RPC interface to
478 * implement ``probing'' the Cache Manager, just making sure it's
482 * rx_call : Ptr to Rx call on which this request came in.
488 * Nothing interesting.
492 *------------------------------------------------------------------------*/
494 SRXAFSCB_Probe(struct rx_call *callp)
496 struct rx_connection *connp;
497 struct rx_peer *peerp;
498 unsigned long host = 0;
499 unsigned short port = 0;
501 MUTEX_ENTER(&callp->lock);
503 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
504 host = rx_HostOf(peerp);
505 port = rx_PortOf(peerp);
508 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
512 MUTEX_EXIT(&callp->lock);
516 /*------------------------------------------------------------------------
517 * EXPORTED SRXAFSCB_GetLock
520 * Routine called by the server-side callback RPC interface to
521 * implement pulling out the contents of a lock in the lock
525 * a_call : Ptr to Rx call on which this request came in.
526 * a_index : Index of desired lock.
527 * a_result : Ptr to a buffer for the given lock.
530 * 0 if everything went fine,
531 * 1 if we were given a bad index.
534 * Nothing interesting.
538 *------------------------------------------------------------------------*/
539 /* debug interface */
541 extern osi_rwlock_t cm_aclLock;
542 extern osi_rwlock_t buf_globalLock;
543 extern osi_rwlock_t cm_callbackLock;
544 extern osi_rwlock_t cm_cellLock;
545 extern osi_rwlock_t cm_connLock;
546 extern osi_rwlock_t cm_daemonLock;
547 extern osi_rwlock_t cm_dnlcLock;
548 extern osi_rwlock_t cm_scacheLock;
549 extern osi_rwlock_t cm_serverLock;
550 extern osi_rwlock_t cm_userLock;
551 extern osi_rwlock_t cm_utilsLock;
552 extern osi_rwlock_t cm_volumeLock;
553 extern osi_rwlock_t smb_globalLock;
554 extern osi_rwlock_t smb_rctLock;
556 extern osi_mutex_t cm_Freelance_Lock;
557 extern osi_mutex_t cm_bufGetMutex;
558 extern osi_mutex_t cm_Afsdsbmt_Lock;
559 extern osi_mutex_t tokenEventLock;
560 extern osi_mutex_t smb_ListenerLock;
561 extern osi_mutex_t smb_RawBufLock;
562 extern osi_mutex_t smb_Dir_Watch_Lock;
564 #define LOCKTYPE_RW 1
565 #define LOCKTYPE_MUTEX 2
566 static struct _ltable {
571 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
572 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
573 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
574 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
575 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
576 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
577 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
578 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
579 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
580 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
581 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
582 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
583 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
584 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
585 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
586 {"cm_bufGetMutex", (char*)&cm_bufGetMutex, LOCKTYPE_MUTEX},
587 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
588 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
589 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
590 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
591 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
595 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
597 struct _ltable *tl; /*Ptr to lock table entry */
600 int nentries; /*Num entries in table */
601 int code; /*Return code */
602 struct rx_connection *connp;
603 struct rx_peer *peerp;
604 unsigned long host = 0;
605 unsigned short port = 0;
607 MUTEX_ENTER(&callp->lock);
609 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
610 host = rx_HostOf(peerp);
611 port = rx_PortOf(peerp);
614 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
615 index, ntohl(host), ntohs(port));
617 nentries = sizeof(ltable) / sizeof(struct _ltable);
618 if (index < 0 || index >= nentries) {
625 * Found it - copy out its contents.
628 strncpy(lockp->name, tl->name, sizeof(lockp->name));
629 lockp->name[sizeof(lockp->name)-1] = '\0';
630 lockp->lock.waitStates = 0;
631 switch ( tl->type ) {
633 rwp = (osi_rwlock_t *)tl->addr;
634 lockp->lock.exclLocked = rwp->flags;
635 lockp->lock.readersReading = rwp->readers;
636 lockp->lock.numWaiting = rwp->waiters;
639 mtxp = (osi_mutex_t *)tl->addr;
640 lockp->lock.exclLocked = mtxp->flags;
641 lockp->lock.readersReading = 0;
642 lockp->lock.numWaiting = mtxp->waiters;
645 lockp->lock.pid_last_reader = 0;
646 lockp->lock.pid_writer = 0;
647 lockp->lock.src_indicator = 0;
651 MUTEX_EXIT(&callp->lock);
655 /* debug interface */
657 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
662 struct rx_connection *connp;
663 struct rx_peer *peerp;
664 unsigned long host = 0;
665 unsigned short port = 0;
667 MUTEX_ENTER(&callp->lock);
669 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
670 host = rx_HostOf(peerp);
671 port = rx_PortOf(peerp);
674 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
675 ntohl(host), ntohs(port));
677 lock_ObtainRead(&cm_scacheLock);
678 for (i = 0; i < cm_data.hashTableSize; i++) {
679 for (scp = cm_data.hashTablep[i]; scp; scp = scp->nextp) {
683 } /*Zip through current hash chain */
684 } /*Zip through hash chains */
694 * Copy out the located entry.
696 memset(cep, 0, sizeof(AFSDBCacheEntry));
697 cep->addr = afs_data_pointer_to_int32(scp);
698 cep->cell = scp->fid.cell;
699 cep->netFid.Volume = scp->fid.volume;
700 cep->netFid.Vnode = scp->fid.vnode;
701 cep->netFid.Unique = scp->fid.unique;
702 cep->lock.waitStates = 0;
703 cep->lock.exclLocked = scp->mx.flags;
704 cep->lock.readersReading = 0;
705 cep->lock.numWaiting = scp->mx.waiters;
706 cep->lock.pid_last_reader = 0;
707 cep->lock.pid_writer = 0;
708 cep->lock.src_indicator = 0;
709 cep->Length = scp->length.LowPart;
710 cep->DataVersion = scp->dataVersion;
711 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
712 cep->cbExpires = scp->cbExpires;
713 cep->refCount = scp->refCount;
714 cep->opens = scp->openReads;
715 cep->writers = scp->openWrites;
716 switch (scp->fileType) {
717 case CM_SCACHETYPE_FILE:
720 case CM_SCACHETYPE_MOUNTPOINT:
723 case CM_SCACHETYPE_DIRECTORY:
724 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
729 case CM_SCACHETYPE_SYMLINK:
732 case CM_SCACHETYPE_DFSLINK:
735 case CM_SCACHETYPE_INVALID:
740 if (scp->flags & CM_SCACHEFLAG_STATD)
742 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
744 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
745 scp->mountPointStringp[0])
747 if (scp->flags & CM_SCACHEFLAG_WAITING)
752 * Return our results.
755 lock_ReleaseRead(&cm_scacheLock);
757 MUTEX_EXIT(&callp->lock);
761 /* debug interface */
763 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
768 struct rx_connection *connp;
769 struct rx_peer *peerp;
770 unsigned long host = 0;
771 unsigned short port = 0;
773 MUTEX_ENTER(&callp->lock);
775 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
776 host = rx_HostOf(peerp);
777 port = rx_PortOf(peerp);
780 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
781 ntohl(host), ntohs(port));
783 lock_ObtainRead(&cm_scacheLock);
784 for (i = 0; i < cm_data.hashTableSize; i++) {
785 for (scp = cm_data.hashTablep[i]; scp; scp = scp->nextp) {
789 } /*Zip through current hash chain */
790 } /*Zip through hash chains */
800 * Copy out the located entry.
802 memset(cep, 0, sizeof(AFSDBCacheEntry64));
803 cep->addr = afs_data_pointer_to_int32(scp);
804 cep->cell = scp->fid.cell;
805 cep->netFid.Volume = scp->fid.volume;
806 cep->netFid.Vnode = scp->fid.vnode;
807 cep->netFid.Unique = scp->fid.unique;
808 cep->lock.waitStates = 0;
809 cep->lock.exclLocked = scp->mx.flags;
810 cep->lock.readersReading = 0;
811 cep->lock.numWaiting = scp->mx.waiters;
812 cep->lock.pid_last_reader = 0;
813 cep->lock.pid_writer = 0;
814 cep->lock.src_indicator = 0;
815 #if !defined(AFS_64BIT_ENV)
816 cep->Length.high = scp->length.HighPart;
817 cep->Length.low = scp->length.LowPart;
819 cep->Length = ((afs_int64)scp->length.HighPart)<<32 | scp->length.LowPart;
821 cep->DataVersion = scp->dataVersion;
822 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
823 cep->cbExpires = scp->cbExpires;
824 cep->refCount = scp->refCount;
825 cep->opens = scp->openReads;
826 cep->writers = scp->openWrites;
827 switch (scp->fileType) {
828 case CM_SCACHETYPE_FILE:
831 case CM_SCACHETYPE_MOUNTPOINT:
834 case CM_SCACHETYPE_DIRECTORY:
835 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
840 case CM_SCACHETYPE_SYMLINK:
843 case CM_SCACHETYPE_DFSLINK:
846 case CM_SCACHETYPE_INVALID:
851 if (scp->flags & CM_SCACHEFLAG_STATD)
853 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
855 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
856 scp->mountPointStringp[0])
858 if (scp->flags & CM_SCACHEFLAG_WAITING)
863 * Return our results.
866 lock_ReleaseRead(&cm_scacheLock);
868 MUTEX_EXIT(&callp->lock);
872 /* debug interface: not implemented */
874 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
876 struct rx_connection *connp;
877 struct rx_peer *peerp;
878 unsigned long host = 0;
879 unsigned short port = 0;
881 MUTEX_ENTER(&callp->lock);
883 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
884 host = rx_HostOf(peerp);
885 port = rx_PortOf(peerp);
888 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
889 ntohl(host), ntohs(port));
892 MUTEX_EXIT(&callp->lock);
896 /* debug interface: not implemented */
898 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
899 AFSCB_CollData *datap)
901 struct rx_connection *connp;
902 struct rx_peer *peerp;
903 unsigned long host = 0;
904 unsigned short port = 0;
906 MUTEX_ENTER(&callp->lock);
908 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
909 host = rx_HostOf(peerp);
910 port = rx_PortOf(peerp);
913 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
914 ntohl(host), ntohs(port));
916 MUTEX_EXIT(&callp->lock);
921 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
923 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
925 return SRXAFSCB_InitCallBackState(callp);
928 /* debug interface */
930 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
933 int cm_noIPAddr; /* number of client network interfaces */
934 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
935 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
936 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
937 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
939 struct rx_connection *connp;
940 struct rx_peer *peerp;
941 unsigned long host = 0;
942 unsigned short port = 0;
944 MUTEX_ENTER(&callp->lock);
946 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
947 host = rx_HostOf(peerp);
948 port = rx_PortOf(peerp);
951 /* get network related info */
952 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
953 code = syscfg_GetIFInfo(&cm_noIPAddr,
954 cm_IPAddr, cm_SubnetMask,
955 cm_NetMtu, cm_NetFlags);
957 /* return all network interface addresses */
958 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
962 addr->numberOfInterfaces = cm_noIPAddr;
963 addr->uuid = cm_data.Uuid;
964 for ( i=0; i < cm_noIPAddr; i++ ) {
965 addr->addr_in[i] = cm_IPAddr[i];
966 addr->subnetmask[i] = cm_SubnetMask[i];
967 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
968 cm_NetMtu[i] : rx_mtu;
971 MUTEX_EXIT(&callp->lock);
976 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
980 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
981 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",p);
984 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
986 return SRXAFSCB_InitCallBackState(callp);
989 /* debug interface */
991 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
993 struct rx_connection *connp;
994 struct rx_peer *peerp;
995 unsigned long host = 0;
996 unsigned short port = 0;
1000 MUTEX_ENTER(&callp->lock);
1002 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1003 host = rx_HostOf(peerp);
1004 port = rx_PortOf(peerp);
1007 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1008 UuidToString((UUID *)&cm_data.Uuid, &p);
1009 UuidToString((UUID *)clientUuid, &q);
1010 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1011 osi_LogSaveString(afsd_logp,p),
1012 osi_LogSaveString(afsd_logp,q),
1018 code = 1; /* failure */
1020 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1024 MUTEX_EXIT(&callp->lock);
1028 /* debug interface */
1030 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1031 char **a_name, serverList *a_hosts)
1035 cm_serverRef_t * serverRefp;
1036 struct rx_connection *connp;
1037 struct rx_peer *peerp;
1038 unsigned long host = 0;
1039 unsigned short port = 0;
1041 MUTEX_ENTER(&callp->lock);
1043 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1044 host = rx_HostOf(peerp);
1045 port = rx_PortOf(peerp);
1048 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1049 a_cellnum, ntohl(host), ntohs(port));
1051 a_hosts->serverList_val = 0;
1052 a_hosts->serverList_len = 0;
1054 cellp = cm_FindCellByID(a_cellnum);
1056 *a_name = strdup("");
1057 MUTEX_EXIT(&callp->lock);
1061 lock_ObtainRead(&cm_serverLock);
1062 *a_name = strdup(cellp->name);
1064 for ( sn = 0, serverRefp = cellp->vlServersp;
1065 sn < AFSMAXCELLHOSTS && serverRefp;
1066 sn++, serverRefp = serverRefp->next);
1068 a_hosts->serverList_len = sn;
1069 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1071 for ( sn = 0, serverRefp = cellp->vlServersp;
1072 sn < AFSMAXCELLHOSTS && serverRefp;
1073 sn++, serverRefp = serverRefp->next)
1075 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1078 lock_ReleaseRead(&cm_serverLock);
1079 MUTEX_EXIT(&callp->lock);
1083 /* debug interface */
1085 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1086 struct interfaceAddr *addr,
1087 Capabilities * capabilities)
1090 afs_int32 *dataBuffP;
1091 afs_int32 dataBytes;
1092 int cm_noIPAddr; /* number of client network interfaces */
1093 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
1094 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
1095 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
1096 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
1098 struct rx_connection *connp;
1099 struct rx_peer *peerp;
1100 unsigned long host = 0;
1101 unsigned short port = 0;
1103 MUTEX_ENTER(&callp->lock);
1105 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1106 host = rx_HostOf(peerp);
1107 port = rx_PortOf(peerp);
1110 /* get network related info */
1111 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1112 code = syscfg_GetIFInfo(&cm_noIPAddr,
1113 cm_IPAddr, cm_SubnetMask,
1114 cm_NetMtu, cm_NetFlags);
1116 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1120 /* return all network interface addresses */
1121 addr->numberOfInterfaces = cm_noIPAddr;
1122 addr->uuid = cm_data.Uuid;
1123 for ( i=0; i < cm_noIPAddr; i++ ) {
1124 addr->addr_in[i] = cm_IPAddr[i];
1125 addr->subnetmask[i] = cm_SubnetMask[i];
1126 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1127 cm_NetMtu[i] : rx_mtu;
1130 dataBytes = 1 * sizeof(afs_int32);
1131 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1132 dataBuffP[0] = CAPABILITY_ERRORTRANS;
1133 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1134 capabilities->Capabilities_val = dataBuffP;
1136 MUTEX_EXIT(&callp->lock);
1140 /*------------------------------------------------------------------------
1141 * EXPORTED SRXAFSCB_GetServerPrefs
1144 * Routine to list server preferences used by this client.
1147 * a_call : Ptr to Rx call on which this request came in.
1148 * a_index : Input server index
1149 * a_srvr_addr : Output server address (0xffffffff on last server)
1150 * a_srvr_rank : Output server rank
1156 * Nothing interesting.
1160 *------------------------------------------------------------------------*/
1162 int SRXAFSCB_GetServerPrefs(
1163 struct rx_call *callp,
1165 afs_int32 *a_srvr_addr,
1166 afs_int32 *a_srvr_rank)
1168 struct rx_connection *connp;
1169 struct rx_peer *peerp;
1170 unsigned long host = 0;
1171 unsigned short port = 0;
1173 MUTEX_ENTER(&callp->lock);
1175 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1176 host = rx_HostOf(peerp);
1177 port = rx_PortOf(peerp);
1180 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1184 *a_srvr_addr = 0xffffffff;
1185 *a_srvr_rank = 0xffffffff;
1187 MUTEX_EXIT(&callp->lock);
1191 /*------------------------------------------------------------------------
1192 * EXPORTED SRXAFSCB_GetCellServDB
1195 * Routine to list cells configured for this client
1198 * a_call : Ptr to Rx call on which this request came in.
1199 * a_index : Input cell index
1200 * a_name : Output cell name ("" on last cell)
1201 * a_hosts : Output cell database servers
1207 * Nothing interesting.
1211 *------------------------------------------------------------------------*/
1213 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1214 serverList *a_hosts)
1217 struct rx_connection *connp;
1218 struct rx_peer *peerp;
1219 unsigned long host = 0;
1220 unsigned short port = 0;
1222 MUTEX_ENTER(&callp->lock);
1224 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1225 host = rx_HostOf(peerp);
1226 port = rx_PortOf(peerp);
1229 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1230 ntohl(host), ntohs(port));
1232 t_name = (char *)malloc(AFSNAMEMAX);
1235 a_hosts->serverList_len = 0;
1237 MUTEX_EXIT(&callp->lock);
1241 /*------------------------------------------------------------------------
1242 * EXPORTED SRXAFSCB_GetLocalCell
1245 * Routine to return name of client's local cell
1248 * a_call : Ptr to Rx call on which this request came in.
1249 * a_name : Output cell name
1255 * Nothing interesting.
1259 *------------------------------------------------------------------------*/
1261 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1264 struct rx_connection *connp;
1265 struct rx_peer *peerp;
1266 unsigned long host = 0;
1267 unsigned short port = 0;
1269 MUTEX_ENTER(&callp->lock);
1271 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1272 host = rx_HostOf(peerp);
1273 port = rx_PortOf(peerp);
1276 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1277 ntohl(host), ntohs(port));
1279 if (cm_data.rootCellp) {
1280 t_name = (char *)malloc(strlen(cm_data.rootCellp->name)+1);
1281 strcpy(t_name, cm_data.rootCellp->name);
1283 t_name = (char *)malloc(1);
1288 MUTEX_EXIT(&callp->lock);
1294 * afs_MarshallCacheConfig - marshall client cache configuration
1298 * IN callerVersion - the rpc stat version of the caller.
1300 * IN config - client cache configuration.
1302 * OUT ptr - buffer where configuration is marshalled.
1308 static void afs_MarshallCacheConfig(
1309 afs_uint32 callerVersion,
1310 cm_initparams_v1 *config,
1314 * We currently only support version 1.
1316 *(ptr++) = config->nChunkFiles;
1317 *(ptr++) = config->nStatCaches;
1318 *(ptr++) = config->nDataCaches;
1319 *(ptr++) = config->nVolumeCaches;
1320 *(ptr++) = config->firstChunkSize;
1321 *(ptr++) = config->otherChunkSize;
1322 *(ptr++) = config->cacheSize;
1323 *(ptr++) = config->setTime;
1324 *(ptr++) = config->memCache;
1329 /*------------------------------------------------------------------------
1330 * EXPORTED SRXAFSCB_GetCacheConfig
1333 * Routine to return parameters used to initialize client cache.
1334 * Client may request any format version. Server may not return
1335 * format version greater than version requested by client.
1338 * a_call: Ptr to Rx call on which this request came in.
1339 * callerVersion: Data format version desired by the client.
1340 * serverVersion: Data format version of output data.
1341 * configCount: Number bytes allocated for output data.
1342 * config: Client cache configuration.
1348 * Nothing interesting.
1352 *------------------------------------------------------------------------*/
1354 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1355 afs_uint32 callerVersion,
1356 afs_uint32 *serverVersion,
1357 afs_uint32 *configCount,
1358 cacheConfig *config)
1360 afs_uint32 *t_config;
1362 extern cm_initparams_v1 cm_initParams;
1363 struct rx_connection *connp;
1364 struct rx_peer *peerp;
1365 unsigned long host = 0;
1366 unsigned short port = 0;
1368 MUTEX_ENTER(&callp->lock);
1370 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1371 host = rx_HostOf(peerp);
1372 port = rx_PortOf(peerp);
1375 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1376 ntohl(host), ntohs(port));
1379 * Currently only support version 1
1381 allocsize = sizeof(cm_initparams_v1);
1382 t_config = (afs_uint32 *)malloc(allocsize);
1384 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1386 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1387 *configCount = allocsize;
1388 config->cacheConfig_val = t_config;
1389 config->cacheConfig_len = allocsize/sizeof(afs_uint32);
1391 MUTEX_EXIT(&callp->lock);
1395 /* called by afsd without any locks to initialize this module */
1396 void cm_InitCallback(void)
1398 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
1399 cm_activeCallbackGrantingCalls = 0;
1402 /* called with locked scp; tells us whether we've got a callback.
1403 * Expirations are checked by a background daemon so as to make
1404 * this function as inexpensive as possible
1406 int cm_HaveCallback(cm_scache_t *scp)
1408 #ifdef AFS_FREELANCE_CLIENT
1409 // yj: we handle callbacks specially for callbacks on the root directory
1410 // Since it's local, we almost always say that we have callback on it
1411 // The only time we send back a 0 is if we're need to initialize or
1412 // reinitialize the fake directory
1414 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1415 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1416 // hence should return false. it's 0 otherwise
1417 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1418 // if the fake directory is loaded and this is the first time cm_HaveCallback
1419 // is called since then. We return false in this case to allow cm_GetCallback
1420 // to be called because cm_GetCallback has some initialization work to do.
1421 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1422 // good shape and we simply return true, provided no change is detected.
1425 if (cm_freelanceEnabled &&
1426 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1427 /* if it's something on /afs */
1428 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
1429 /* if it's not root.afs */
1433 lock_ObtainMutex(&cm_Freelance_Lock);
1434 fdc = cm_fakeDirCallback;
1435 fgc = cm_fakeGettingCallback;
1436 lock_ReleaseMutex(&cm_Freelance_Lock);
1438 if (fdc==1) { // first call since init
1440 } else if (fdc==2 && !fgc) { // we're in good shape
1441 if (cm_getLocalMountPointChange()) { // check for changes
1442 cm_clearLocalMountPointChange(); // clear the changefile
1443 lock_ReleaseMutex(&scp->mx); // this is re-locked in reInitLocalMountPoints
1444 cm_reInitLocalMountPoints(); // start reinit
1445 lock_ObtainMutex(&scp->mx); // now get the lock back
1448 return 1; // no change
1454 if (scp->cbServerp != NULL)
1460 /* need to detect a broken callback that races with our obtaining a callback.
1461 * Need to be able to do this even if we don't know the file ID of the file
1462 * we're breaking the callback on at the time we start the acquisition of the
1463 * callback (as in the case where we are creating a file).
1465 * So, we start by writing down the count of the # of callbacks we've received
1466 * so far, and bumping a global counter of the # of callback granting calls
1467 * outstanding (all done under cm_callbackLock).
1469 * When we're back from the call, we look at all of the callback revokes with
1470 * counter numbers greater than the one we recorded in our caller's structure,
1471 * and replay those that are higher than when we started the call.
1473 * We free all the structures in the queue when the count of the # of outstanding
1474 * callback-granting calls drops to zero.
1476 * We call this function with the scp locked, too, but in its current implementation,
1477 * this knowledge is not used.
1479 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1481 lock_ObtainWrite(&cm_callbackLock);
1482 cbrp->callbackCount = cm_callbackCount;
1483 cm_activeCallbackGrantingCalls++;
1484 cbrp->startTime = osi_Time();
1485 cbrp->serverp = NULL;
1486 lock_ReleaseWrite(&cm_callbackLock);
1489 /* Called at the end of a callback-granting call, to remove the callback
1490 * info from the scache entry, if necessary.
1492 * Called with scp locked, so we can discard the callbacks easily with
1493 * this locking hierarchy.
1495 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1496 AFSCallBack *cbp, long flags)
1498 cm_racingRevokes_t *revp; /* where we are */
1499 cm_racingRevokes_t *nrevp; /* where we'll be next */
1501 cm_server_t * serverp = 0;
1503 lock_ObtainWrite(&cm_callbackLock);
1504 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1505 osi_assert(cm_activeCallbackGrantingCalls > 0);
1508 osi_assert(cm_activeCallbackGrantingCalls-- > 0);
1510 if (cm_activeCallbackGrantingCalls == 0)
1515 /* record the callback; we'll clear it below if we really lose it */
1518 if (scp->cbServerp != cbrp->serverp) {
1519 serverp = scp->cbServerp;
1521 cm_GetServer(cbrp->serverp);
1522 scp->cbServerp = cbrp->serverp;
1525 serverp = cbrp->serverp;
1527 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1530 serverp = cbrp->serverp;
1533 cbrp->serverp = NULL;
1536 /* a callback was actually revoked during our granting call, so
1537 * run down the list of revoked fids, looking for ours.
1538 * If activeCallbackGrantingCalls is zero, free the elements, too.
1540 * May need to go through entire list just to do the freeing.
1542 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1543 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1544 /* if this callback came in later than when we started the
1545 * callback-granting call, and if this fid is the right fid,
1546 * then clear the callback.
1548 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1549 && revp->callbackCount > cbrp->callbackCount
1550 && (( scp->fid.volume == revp->fid.volume &&
1551 scp->fid.vnode == revp->fid.vnode &&
1552 scp->fid.unique == revp->fid.unique)
1554 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1555 scp->fid.volume == revp->fid.volume)
1557 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1558 /* this one matches */
1560 "Racing revoke scp 0x%x old cbc %d rev cbc %d cur cbc %d",
1562 cbrp->callbackCount, revp->callbackCount,
1564 cm_DiscardSCache(scp);
1566 * Since we don't have a callback to preserve, it's
1567 * OK to drop the lock and re-obtain it.
1569 lock_ReleaseMutex(&scp->mx);
1570 lock_ReleaseWrite(&cm_callbackLock);
1571 cm_CallbackNotifyChange(scp);
1572 lock_ObtainMutex(&scp->mx);
1573 lock_ObtainWrite(&cm_callbackLock);
1579 /* if we freed the list, zap the pointer to it */
1581 cm_racingRevokesp = NULL;
1583 lock_ReleaseWrite(&cm_callbackLock);
1586 lock_ObtainWrite(&cm_serverLock);
1587 cm_FreeServer(serverp);
1588 lock_ReleaseWrite(&cm_serverLock);
1592 /* if flags is 1, we want to force the code to make one call, anyway.
1593 * called with locked scp; returns with same.
1595 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1596 struct cm_req *reqp, long flags)
1600 AFSFetchStatus afsStatus;
1602 AFSCallBack callback;
1604 cm_callbackRequest_t cbr;
1608 struct rx_connection * callp;
1610 osi_Log4(afsd_logp, "GetCallback scp 0x%x cell %d vol %d flags %lX",
1611 scp, scp->fid.cell, scp->fid.volume, flags);
1613 #ifdef AFS_FREELANCE_CLIENT
1614 // The case where a callback is needed on /afs is handled
1615 // specially. We need to fetch the status by calling
1616 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1617 if (cm_freelanceEnabled) {
1618 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1619 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1620 scp->fid.unique==0x1 &&
1621 scp->fid.vnode==0x1) {
1623 // Start by indicating that we're in the process
1624 // of fetching the callback
1625 lock_ObtainMutex(&cm_Freelance_Lock);
1626 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1627 cm_fakeGettingCallback = 1;
1628 lock_ReleaseMutex(&cm_Freelance_Lock);
1630 // Fetch the status info
1631 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
1633 // Indicate that the callback is not done
1634 lock_ObtainMutex(&cm_Freelance_Lock);
1635 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1636 cm_fakeDirCallback = 2;
1638 // Indicate that we're no longer fetching the callback
1639 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1640 cm_fakeGettingCallback = 0;
1641 lock_ReleaseMutex(&cm_Freelance_Lock);
1646 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1647 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1650 #endif /* AFS_FREELANCE_CLIENT */
1652 mustCall = (flags & 1);
1653 cm_AFSFidFromFid(&tfid, &scp->fid);
1655 if (!mustCall && cm_HaveCallback(scp)) {
1656 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%x cell %d vol %d",
1657 scp, scp->fid.cell, scp->fid.volume);
1661 /* turn off mustCall, since it has now forced us past the check above */
1664 /* otherwise, we have to make an RPC to get the status */
1665 sflags = CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK;
1666 cm_SyncOp(scp, NULL, NULL, NULL, 0, sflags);
1667 cm_StartCallbackGrantingCall(scp, &cbr);
1669 lock_ReleaseMutex(&scp->mx);
1671 /* now make the RPC */
1672 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%x cell %d vol %d uniq %d",
1673 (long) scp, scp->fid.cell, scp->fid.volume, scp->fid.unique);
1675 code = cm_Conn(&sfid, userp, reqp, &connp);
1679 callp = cm_GetRxConn(connp);
1680 code = RXAFS_FetchStatus(callp, &tfid,
1681 &afsStatus, &callback, &volSync);
1682 rx_PutConnection(callp);
1684 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1686 code = cm_MapRPCError(code, reqp);
1688 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%x cell %d vol %d",
1689 code, (long) scp, scp->fid.cell, scp->fid.volume);
1691 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%x cell %d vol %d uniq %d",
1692 (long) scp, scp->fid.cell, scp->fid.volume, scp->fid.unique);
1694 lock_ObtainMutex(&scp->mx);
1696 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1697 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
1699 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1701 cm_SyncOpDone(scp, NULL, sflags);
1703 /* now check to see if we got an error */
1705 osi_Log4(afsd_logp, "GetCallback Failed code 0x%x scp 0x%x cell %d vol %d",
1706 code, scp, scp->fid.cell, scp->fid.volume);
1712 /* called periodically by cm_daemon to shut down use of expired callbacks */
1713 void cm_CheckCBExpiration(void)
1719 osi_Log0(afsd_logp, "CheckCBExpiration");
1722 lock_ObtainWrite(&cm_scacheLock);
1723 for (i=0; i<cm_data.hashTableSize; i++) {
1724 for (scp = cm_data.hashTablep[i]; scp; scp=scp->nextp) {
1725 cm_HoldSCacheNoLock(scp);
1726 if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) {
1727 lock_ReleaseWrite(&cm_scacheLock);
1728 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%x vol %u vn %u uniq %u",
1729 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1730 lock_ObtainMutex(&scp->mx);
1731 cm_DiscardSCache(scp);
1732 lock_ReleaseMutex(&scp->mx);
1733 cm_CallbackNotifyChange(scp);
1734 lock_ObtainWrite(&cm_scacheLock);
1736 cm_ReleaseSCacheNoLock(scp);
1739 lock_ReleaseWrite(&cm_scacheLock);
1741 osi_Log0(afsd_logp, "CheckCBExpiration Complete");