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 #define BUF_FILEHASH(fidp) ((((fidp)->vnode+((fidp)->unique << 13) + ((fidp)->unique >> (32-13)) \
96 +(fidp)->volume+(fidp)->cell) \
101 * When we lose a callback, may have to send change notification replies.
102 * Do not call with a lock on the scp.
104 void cm_CallbackNotifyChange(cm_scache_t *scp)
110 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
111 AFSREG_CLT_OPENAFS_SUBKEY,
113 KEY_READ|KEY_QUERY_VALUE,
114 &hKey) == ERROR_SUCCESS) {
116 dummyLen = sizeof(DWORD);
117 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
118 (BYTE *) &dwDelay, &dummyLen);
122 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
125 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
126 scp->fileType, scp->flags, dwDelay);
131 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
133 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
135 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
136 scp, NULL, NULL, TRUE);
138 dc_break_callback(BUF_FILEHASH(&scp->fid));
144 tfid.cell = scp->fid.cell;
145 tfid.volume = scp->fid.volume;
146 tfid.vnode = scp->parentVnode;
147 tfid.unique = scp->parentUnique;
148 dscp = cm_FindSCache(&tfid);
151 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
153 FILE_NOTIFY_GENERIC_FILE_FILTER,
154 dscp, NULL, NULL, TRUE);
157 dc_break_callback(BUF_FILEHASH(&dscp->fid));
160 cm_ReleaseSCache(dscp);
164 /* called with no locks held for every file ID that is revoked directly by
165 * a callback revoke call. Does not have to handle volume callback breaks,
166 * since those have already been split out.
168 * The callp parameter is currently unused.
170 void cm_RevokeCallback(struct rx_call *callp, AFSFid *fidp)
176 /* don't bother setting cell, since we won't be checking it (to aid
177 * in working with multi-homed servers: we don't know the cell if we
178 * don't recognize the IP address).
181 tfid.volume = fidp->Volume;
182 tfid.vnode = fidp->Vnode;
183 tfid.unique = fidp->Unique;
184 hash = CM_SCACHE_HASH(&tfid);
186 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
187 fidp->Volume, fidp->Vnode, fidp->Unique);
189 /* do this first, so that if we're executing a callback granting call
190 * at this moment, we kill it before it can be merged in. Otherwise,
191 * it could complete while we're doing the scan below, and get missed
192 * by both the scan and by this code.
194 cm_RecordRacingRevoke(&tfid, 0);
196 lock_ObtainWrite(&cm_scacheLock);
197 /* do all in the hash bucket, since we don't know how many we'll find with
200 for (scp = cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
201 if (scp->fid.volume == tfid.volume &&
202 scp->fid.vnode == tfid.vnode &&
203 scp->fid.unique == tfid.unique &&
204 scp->cbExpires > 0 &&
205 scp->cbServerp != NULL)
207 cm_HoldSCacheNoLock(scp);
208 lock_ReleaseWrite(&cm_scacheLock);
209 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%x vol %u vn %u uniq %u",
210 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
211 lock_ObtainMutex(&scp->mx);
212 cm_DiscardSCache(scp);
213 lock_ReleaseMutex(&scp->mx);
214 cm_CallbackNotifyChange(scp);
215 lock_ObtainWrite(&cm_scacheLock);
216 cm_ReleaseSCacheNoLock(scp);
219 lock_ReleaseWrite(&cm_scacheLock);
221 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
222 fidp->Volume, fidp->Vnode, fidp->Unique);
225 /* called to revoke a volume callback, which is typically issued when a volume
226 * is moved from one server to another.
228 * Called with no locks held.
230 void cm_RevokeVolumeCallback(struct rx_call *callp, AFSFid *fidp)
236 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
238 /* do this first, so that if we're executing a callback granting call
239 * at this moment, we kill it before it can be merged in. Otherwise,
240 * it could complete while we're doing the scan below, and get missed
241 * by both the scan and by this code.
243 tfid.cell = tfid.vnode = tfid.unique = 0;
244 tfid.volume = fidp->Volume;
245 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
248 lock_ObtainWrite(&cm_scacheLock);
249 for (hash = 0; hash < cm_data.hashTableSize; hash++) {
250 for(scp=cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
251 if (scp->fid.volume == fidp->Volume &&
252 scp->cbExpires > 0 &&
253 scp->cbServerp != NULL) {
254 cm_HoldSCacheNoLock(scp);
255 lock_ReleaseWrite(&cm_scacheLock);
256 lock_ObtainMutex(&scp->mx);
257 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%x vol %u vn %u uniq %u",
258 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
259 cm_DiscardSCache(scp);
260 lock_ReleaseMutex(&scp->mx);
261 cm_CallbackNotifyChange(scp);
262 lock_ObtainWrite(&cm_scacheLock);
263 cm_ReleaseSCacheNoLock(scp);
265 } /* search one hash bucket */
266 } /* search all hash buckets */
268 lock_ReleaseWrite(&cm_scacheLock);
270 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
274 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
275 * given data pointer, without triggering "cast truncates pointer"
276 * warnings. We use this where we explicitly don't care whether a
277 * pointer is truncated -- it loses information where a pointer is
278 * larger than an afs_int32.
282 afs_data_pointer_to_int32(const void *p)
285 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
289 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
294 /* used to determine the byte order of the system */
297 char c[sizeof(int) / sizeof(char)];
303 /* little-endian system */
306 /* big-endian system */
307 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
312 return ip.i32[i32_sub];
314 /*------------------------------------------------------------------------
315 * EXPORTED SRXAFSCB_CallBack
318 * Routine called by the server-side callback RPC interface to
319 * implement passing in callback information.
323 * rx_call : Ptr to Rx call on which this request came in.
324 * fidsArrayp : Ptr to array of fids involved.
325 * cbsArrayp : Ptr to matching callback info for the fids.
331 * Nothing interesting.
335 *------------------------------------------------------------------------*/
336 /* handle incoming RPC callback breaking message.
337 * Called with no locks held.
340 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
344 struct rx_connection *connp;
345 struct rx_peer *peerp;
346 unsigned long host = 0;
347 unsigned short port = 0;
349 MUTEX_ENTER(&callp->lock);
351 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
352 host = rx_HostOf(peerp);
353 port = rx_PortOf(peerp);
356 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
360 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
361 tfidp = &fidsArrayp->AFSCBFids_val[i];
363 if (tfidp->Volume == 0)
364 continue; /* means don't do anything */
365 else if (tfidp->Vnode == 0)
366 cm_RevokeVolumeCallback(callp, tfidp);
368 cm_RevokeCallback(callp, tfidp);
371 MUTEX_EXIT(&callp->lock);
375 /*------------------------------------------------------------------------
376 * EXPORTED SRXAFSCB_InitCallBackState
379 * Routine called by the server-side callback RPC interface to
380 * implement clearing all callbacks from this host.
383 * rx_call : Ptr to Rx call on which this request came in.
389 * Nothing interesting.
393 *------------------------------------------------------------------------*/
394 /* called with no locks by RPC system when a server indicates that it has never
395 * heard from us, or for other reasons has had to discard callbacks from us
396 * without telling us, e.g. a network partition.
399 SRXAFSCB_InitCallBackState(struct rx_call *callp)
401 struct sockaddr_in taddr;
406 struct rx_connection *connp;
407 struct rx_peer *peerp;
408 unsigned long host = 0;
409 unsigned short port = 0;
411 MUTEX_ENTER(&callp->lock);
413 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
414 host = rx_HostOf(peerp);
415 port = rx_PortOf(peerp);
418 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
422 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
423 taddr.sin_family = AF_INET;
424 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
426 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
428 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
430 /* record the callback in the racing revokes structure. This
431 * shouldn't be necessary, since we shouldn't be making callback
432 * granting calls while we're going to get an initstate call,
433 * but there probably are some obscure races, so better safe
436 * We do this first since we don't hold the cm_scacheLock and vnode
437 * locks over the entire callback scan operation below. The
438 * big loop below is guaranteed to hit any callback already
439 * processed. The call to RecordRacingRevoke is guaranteed
440 * to kill any callback that is currently being returned.
441 * Anything that sneaks past both must start
442 * after the call to RecordRacingRevoke.
444 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
446 /* now search all vnodes looking for guys with this callback, if we
447 * found it, or guys with any callbacks, if we didn't find the server
448 * (that's how multihomed machines will appear and how we'll handle
449 * them, albeit a little inefficiently). That is, we're discarding all
450 * callbacks from all hosts if we get an initstate call from an unknown
451 * host. Since these calls are rare, and multihomed servers
452 * are "rare," hopefully this won't be a problem.
454 lock_ObtainWrite(&cm_scacheLock);
455 for (hash = 0; hash < cm_data.hashTableSize; hash++) {
456 for (scp=cm_data.hashTablep[hash]; scp; scp=scp->nextp) {
457 cm_HoldSCacheNoLock(scp);
458 lock_ReleaseWrite(&cm_scacheLock);
459 lock_ObtainMutex(&scp->mx);
461 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
462 /* we have a callback, now decide if we should clear it */
463 if (scp->cbServerp == tsp || tsp == NULL) {
464 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%x vol %u vn %u uniq %u",
465 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
466 cm_DiscardSCache(scp);
470 lock_ReleaseMutex(&scp->mx);
472 cm_CallbackNotifyChange(scp);
473 lock_ObtainWrite(&cm_scacheLock);
474 cm_ReleaseSCacheNoLock(scp);
475 } /* search one hash bucket */
476 } /* search all hash buckets */
478 lock_ReleaseWrite(&cm_scacheLock);
480 /* we're done with the server structure */
484 MUTEX_EXIT(&callp->lock);
488 /*------------------------------------------------------------------------
489 * EXPORTED SRXAFSCB_Probe
492 * Routine called by the server-side callback RPC interface to
493 * implement ``probing'' the Cache Manager, just making sure it's
497 * rx_call : Ptr to Rx call on which this request came in.
503 * Nothing interesting.
507 *------------------------------------------------------------------------*/
509 SRXAFSCB_Probe(struct rx_call *callp)
511 struct rx_connection *connp;
512 struct rx_peer *peerp;
513 unsigned long host = 0;
514 unsigned short port = 0;
516 MUTEX_ENTER(&callp->lock);
518 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
519 host = rx_HostOf(peerp);
520 port = rx_PortOf(peerp);
523 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
527 MUTEX_EXIT(&callp->lock);
531 /*------------------------------------------------------------------------
532 * EXPORTED SRXAFSCB_GetLock
535 * Routine called by the server-side callback RPC interface to
536 * implement pulling out the contents of a lock in the lock
540 * a_call : Ptr to Rx call on which this request came in.
541 * a_index : Index of desired lock.
542 * a_result : Ptr to a buffer for the given lock.
545 * 0 if everything went fine,
546 * 1 if we were given a bad index.
549 * Nothing interesting.
553 *------------------------------------------------------------------------*/
554 /* debug interface */
556 extern osi_rwlock_t cm_aclLock;
557 extern osi_rwlock_t buf_globalLock;
558 extern osi_rwlock_t cm_callbackLock;
559 extern osi_rwlock_t cm_cellLock;
560 extern osi_rwlock_t cm_connLock;
561 extern osi_rwlock_t cm_daemonLock;
562 extern osi_rwlock_t cm_dnlcLock;
563 extern osi_rwlock_t cm_scacheLock;
564 extern osi_rwlock_t cm_serverLock;
565 extern osi_rwlock_t cm_userLock;
566 extern osi_rwlock_t cm_utilsLock;
567 extern osi_rwlock_t cm_volumeLock;
568 extern osi_rwlock_t smb_globalLock;
569 extern osi_rwlock_t smb_rctLock;
571 extern osi_mutex_t cm_Freelance_Lock;
572 extern osi_mutex_t cm_bufGetMutex;
573 extern osi_mutex_t cm_Afsdsbmt_Lock;
574 extern osi_mutex_t tokenEventLock;
575 extern osi_mutex_t smb_ListenerLock;
576 extern osi_mutex_t smb_RawBufLock;
577 extern osi_mutex_t smb_Dir_Watch_Lock;
579 #define LOCKTYPE_RW 1
580 #define LOCKTYPE_MUTEX 2
581 static struct _ltable {
586 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
587 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
588 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
589 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
590 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
591 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
592 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
593 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
594 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
595 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
596 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
597 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
598 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
599 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
600 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
601 {"cm_bufGetMutex", (char*)&cm_bufGetMutex, LOCKTYPE_MUTEX},
602 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
603 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
604 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
605 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
606 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
610 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
612 struct _ltable *tl; /*Ptr to lock table entry */
615 int nentries; /*Num entries in table */
616 int code; /*Return code */
617 struct rx_connection *connp;
618 struct rx_peer *peerp;
619 unsigned long host = 0;
620 unsigned short port = 0;
622 MUTEX_ENTER(&callp->lock);
624 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
625 host = rx_HostOf(peerp);
626 port = rx_PortOf(peerp);
629 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
630 index, ntohl(host), ntohs(port));
632 nentries = sizeof(ltable) / sizeof(struct _ltable);
633 if (index < 0 || index >= nentries) {
640 * Found it - copy out its contents.
643 strncpy(lockp->name, tl->name, sizeof(lockp->name));
644 lockp->name[sizeof(lockp->name)-1] = '\0';
645 lockp->lock.waitStates = 0;
646 switch ( tl->type ) {
648 rwp = (osi_rwlock_t *)tl->addr;
649 lockp->lock.exclLocked = rwp->flags;
650 lockp->lock.readersReading = rwp->readers;
651 lockp->lock.numWaiting = rwp->waiters;
654 mtxp = (osi_mutex_t *)tl->addr;
655 lockp->lock.exclLocked = mtxp->flags;
656 lockp->lock.readersReading = 0;
657 lockp->lock.numWaiting = mtxp->waiters;
660 lockp->lock.pid_last_reader = 0;
661 lockp->lock.pid_writer = 0;
662 lockp->lock.src_indicator = 0;
666 MUTEX_EXIT(&callp->lock);
670 /* debug interface */
672 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
677 struct rx_connection *connp;
678 struct rx_peer *peerp;
679 unsigned long host = 0;
680 unsigned short port = 0;
682 MUTEX_ENTER(&callp->lock);
684 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
685 host = rx_HostOf(peerp);
686 port = rx_PortOf(peerp);
689 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
690 ntohl(host), ntohs(port));
692 lock_ObtainRead(&cm_scacheLock);
693 for (i = 0; i < cm_data.hashTableSize; i++) {
694 for (scp = cm_data.hashTablep[i]; scp; scp = scp->nextp) {
698 } /*Zip through current hash chain */
699 } /*Zip through hash chains */
709 * Copy out the located entry.
711 memset(cep, 0, sizeof(AFSDBCacheEntry));
712 cep->addr = afs_data_pointer_to_int32(scp);
713 cep->cell = scp->fid.cell;
714 cep->netFid.Volume = scp->fid.volume;
715 cep->netFid.Vnode = scp->fid.vnode;
716 cep->netFid.Unique = scp->fid.unique;
717 cep->lock.waitStates = 0;
718 cep->lock.exclLocked = scp->mx.flags;
719 cep->lock.readersReading = 0;
720 cep->lock.numWaiting = scp->mx.waiters;
721 cep->lock.pid_last_reader = 0;
722 cep->lock.pid_writer = 0;
723 cep->lock.src_indicator = 0;
724 cep->Length = scp->length.LowPart;
725 cep->DataVersion = scp->dataVersion;
726 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
727 cep->cbExpires = scp->cbExpires;
728 cep->refCount = scp->refCount;
729 cep->opens = scp->openReads;
730 cep->writers = scp->openWrites;
731 switch (scp->fileType) {
732 case CM_SCACHETYPE_FILE:
735 case CM_SCACHETYPE_MOUNTPOINT:
738 case CM_SCACHETYPE_DIRECTORY:
739 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
744 case CM_SCACHETYPE_SYMLINK:
747 case CM_SCACHETYPE_DFSLINK:
750 case CM_SCACHETYPE_INVALID:
755 if (scp->flags & CM_SCACHEFLAG_STATD)
757 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
759 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
760 scp->mountPointStringp[0])
762 if (scp->flags & CM_SCACHEFLAG_WAITING)
767 * Return our results.
770 lock_ReleaseRead(&cm_scacheLock);
772 MUTEX_EXIT(&callp->lock);
776 /* debug interface */
778 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
783 struct rx_connection *connp;
784 struct rx_peer *peerp;
785 unsigned long host = 0;
786 unsigned short port = 0;
788 MUTEX_ENTER(&callp->lock);
790 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
791 host = rx_HostOf(peerp);
792 port = rx_PortOf(peerp);
795 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
796 ntohl(host), ntohs(port));
798 lock_ObtainRead(&cm_scacheLock);
799 for (i = 0; i < cm_data.hashTableSize; i++) {
800 for (scp = cm_data.hashTablep[i]; scp; scp = scp->nextp) {
804 } /*Zip through current hash chain */
805 } /*Zip through hash chains */
815 * Copy out the located entry.
817 memset(cep, 0, sizeof(AFSDBCacheEntry64));
818 cep->addr = afs_data_pointer_to_int32(scp);
819 cep->cell = scp->fid.cell;
820 cep->netFid.Volume = scp->fid.volume;
821 cep->netFid.Vnode = scp->fid.vnode;
822 cep->netFid.Unique = scp->fid.unique;
823 cep->lock.waitStates = 0;
824 cep->lock.exclLocked = scp->mx.flags;
825 cep->lock.readersReading = 0;
826 cep->lock.numWaiting = scp->mx.waiters;
827 cep->lock.pid_last_reader = 0;
828 cep->lock.pid_writer = 0;
829 cep->lock.src_indicator = 0;
830 #if !defined(AFS_64BIT_ENV)
831 cep->Length.high = scp->length.HighPart;
832 cep->Length.low = scp->length.LowPart;
834 cep->Length = ((afs_int64)scp->length.HighPart)<<32 | scp->length.LowPart;
836 cep->DataVersion = scp->dataVersion;
837 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
838 cep->cbExpires = scp->cbExpires;
839 cep->refCount = scp->refCount;
840 cep->opens = scp->openReads;
841 cep->writers = scp->openWrites;
842 switch (scp->fileType) {
843 case CM_SCACHETYPE_FILE:
846 case CM_SCACHETYPE_MOUNTPOINT:
849 case CM_SCACHETYPE_DIRECTORY:
850 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
855 case CM_SCACHETYPE_SYMLINK:
858 case CM_SCACHETYPE_DFSLINK:
861 case CM_SCACHETYPE_INVALID:
866 if (scp->flags & CM_SCACHEFLAG_STATD)
868 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
870 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
871 scp->mountPointStringp[0])
873 if (scp->flags & CM_SCACHEFLAG_WAITING)
878 * Return our results.
881 lock_ReleaseRead(&cm_scacheLock);
883 MUTEX_EXIT(&callp->lock);
887 /* debug interface: not implemented */
889 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
891 struct rx_connection *connp;
892 struct rx_peer *peerp;
893 unsigned long host = 0;
894 unsigned short port = 0;
896 MUTEX_ENTER(&callp->lock);
898 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
899 host = rx_HostOf(peerp);
900 port = rx_PortOf(peerp);
903 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
904 ntohl(host), ntohs(port));
907 MUTEX_EXIT(&callp->lock);
911 /* debug interface: not implemented */
913 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
914 AFSCB_CollData *datap)
916 struct rx_connection *connp;
917 struct rx_peer *peerp;
918 unsigned long host = 0;
919 unsigned short port = 0;
921 MUTEX_ENTER(&callp->lock);
923 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
924 host = rx_HostOf(peerp);
925 port = rx_PortOf(peerp);
928 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
929 ntohl(host), ntohs(port));
931 MUTEX_EXIT(&callp->lock);
936 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
938 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
940 return SRXAFSCB_InitCallBackState(callp);
943 /* debug interface */
945 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
948 int cm_noIPAddr; /* number of client network interfaces */
949 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
950 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
951 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
952 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
954 struct rx_connection *connp;
955 struct rx_peer *peerp;
956 unsigned long host = 0;
957 unsigned short port = 0;
959 MUTEX_ENTER(&callp->lock);
961 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
962 host = rx_HostOf(peerp);
963 port = rx_PortOf(peerp);
966 /* get network related info */
967 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
968 code = syscfg_GetIFInfo(&cm_noIPAddr,
969 cm_IPAddr, cm_SubnetMask,
970 cm_NetMtu, cm_NetFlags);
972 /* return all network interface addresses */
973 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
977 addr->numberOfInterfaces = cm_noIPAddr;
978 addr->uuid = cm_data.Uuid;
979 for ( i=0; i < cm_noIPAddr; i++ ) {
980 addr->addr_in[i] = cm_IPAddr[i];
981 addr->subnetmask[i] = cm_SubnetMask[i];
982 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
983 cm_NetMtu[i] : rx_mtu;
986 MUTEX_EXIT(&callp->lock);
991 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
995 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
996 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",p);
999 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1001 return SRXAFSCB_InitCallBackState(callp);
1004 /* debug interface */
1006 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1008 struct rx_connection *connp;
1009 struct rx_peer *peerp;
1010 unsigned long host = 0;
1011 unsigned short port = 0;
1015 MUTEX_ENTER(&callp->lock);
1017 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1018 host = rx_HostOf(peerp);
1019 port = rx_PortOf(peerp);
1022 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1023 UuidToString((UUID *)&cm_data.Uuid, &p);
1024 UuidToString((UUID *)clientUuid, &q);
1025 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1026 osi_LogSaveString(afsd_logp,p),
1027 osi_LogSaveString(afsd_logp,q),
1033 code = 1; /* failure */
1035 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1039 MUTEX_EXIT(&callp->lock);
1043 /* debug interface */
1045 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1046 char **a_name, serverList *a_hosts)
1050 cm_serverRef_t * serverRefp;
1051 struct rx_connection *connp;
1052 struct rx_peer *peerp;
1053 unsigned long host = 0;
1054 unsigned short port = 0;
1056 MUTEX_ENTER(&callp->lock);
1058 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1059 host = rx_HostOf(peerp);
1060 port = rx_PortOf(peerp);
1063 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1064 a_cellnum, ntohl(host), ntohs(port));
1066 a_hosts->serverList_val = 0;
1067 a_hosts->serverList_len = 0;
1069 cellp = cm_FindCellByID(a_cellnum);
1071 *a_name = strdup("");
1072 MUTEX_EXIT(&callp->lock);
1076 lock_ObtainRead(&cm_serverLock);
1077 *a_name = strdup(cellp->name);
1079 for ( sn = 0, serverRefp = cellp->vlServersp;
1080 sn < AFSMAXCELLHOSTS && serverRefp;
1081 sn++, serverRefp = serverRefp->next);
1083 a_hosts->serverList_len = sn;
1084 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1086 for ( sn = 0, serverRefp = cellp->vlServersp;
1087 sn < AFSMAXCELLHOSTS && serverRefp;
1088 sn++, serverRefp = serverRefp->next)
1090 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1093 lock_ReleaseRead(&cm_serverLock);
1094 MUTEX_EXIT(&callp->lock);
1098 /* debug interface */
1100 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1101 struct interfaceAddr *addr,
1102 Capabilities * capabilities)
1105 afs_int32 *dataBuffP;
1106 afs_int32 dataBytes;
1107 int cm_noIPAddr; /* number of client network interfaces */
1108 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
1109 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
1110 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
1111 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
1113 struct rx_connection *connp;
1114 struct rx_peer *peerp;
1115 unsigned long host = 0;
1116 unsigned short port = 0;
1118 MUTEX_ENTER(&callp->lock);
1120 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1121 host = rx_HostOf(peerp);
1122 port = rx_PortOf(peerp);
1125 /* get network related info */
1126 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1127 code = syscfg_GetIFInfo(&cm_noIPAddr,
1128 cm_IPAddr, cm_SubnetMask,
1129 cm_NetMtu, cm_NetFlags);
1131 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1135 /* return all network interface addresses */
1136 addr->numberOfInterfaces = cm_noIPAddr;
1137 addr->uuid = cm_data.Uuid;
1138 for ( i=0; i < cm_noIPAddr; i++ ) {
1139 addr->addr_in[i] = cm_IPAddr[i];
1140 addr->subnetmask[i] = cm_SubnetMask[i];
1141 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1142 cm_NetMtu[i] : rx_mtu;
1145 dataBytes = 1 * sizeof(afs_int32);
1146 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1147 dataBuffP[0] = CAPABILITY_ERRORTRANS;
1148 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1149 capabilities->Capabilities_val = dataBuffP;
1151 MUTEX_EXIT(&callp->lock);
1155 /*------------------------------------------------------------------------
1156 * EXPORTED SRXAFSCB_GetServerPrefs
1159 * Routine to list server preferences used by this client.
1162 * a_call : Ptr to Rx call on which this request came in.
1163 * a_index : Input server index
1164 * a_srvr_addr : Output server address (0xffffffff on last server)
1165 * a_srvr_rank : Output server rank
1171 * Nothing interesting.
1175 *------------------------------------------------------------------------*/
1177 int SRXAFSCB_GetServerPrefs(
1178 struct rx_call *callp,
1180 afs_int32 *a_srvr_addr,
1181 afs_int32 *a_srvr_rank)
1183 struct rx_connection *connp;
1184 struct rx_peer *peerp;
1185 unsigned long host = 0;
1186 unsigned short port = 0;
1188 MUTEX_ENTER(&callp->lock);
1190 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1191 host = rx_HostOf(peerp);
1192 port = rx_PortOf(peerp);
1195 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1199 *a_srvr_addr = 0xffffffff;
1200 *a_srvr_rank = 0xffffffff;
1202 MUTEX_EXIT(&callp->lock);
1206 /*------------------------------------------------------------------------
1207 * EXPORTED SRXAFSCB_GetCellServDB
1210 * Routine to list cells configured for this client
1213 * a_call : Ptr to Rx call on which this request came in.
1214 * a_index : Input cell index
1215 * a_name : Output cell name ("" on last cell)
1216 * a_hosts : Output cell database servers
1222 * Nothing interesting.
1226 *------------------------------------------------------------------------*/
1228 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1229 serverList *a_hosts)
1232 struct rx_connection *connp;
1233 struct rx_peer *peerp;
1234 unsigned long host = 0;
1235 unsigned short port = 0;
1237 MUTEX_ENTER(&callp->lock);
1239 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1240 host = rx_HostOf(peerp);
1241 port = rx_PortOf(peerp);
1244 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1245 ntohl(host), ntohs(port));
1247 t_name = (char *)malloc(AFSNAMEMAX);
1250 a_hosts->serverList_len = 0;
1252 MUTEX_EXIT(&callp->lock);
1256 /*------------------------------------------------------------------------
1257 * EXPORTED SRXAFSCB_GetLocalCell
1260 * Routine to return name of client's local cell
1263 * a_call : Ptr to Rx call on which this request came in.
1264 * a_name : Output cell name
1270 * Nothing interesting.
1274 *------------------------------------------------------------------------*/
1276 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1279 struct rx_connection *connp;
1280 struct rx_peer *peerp;
1281 unsigned long host = 0;
1282 unsigned short port = 0;
1284 MUTEX_ENTER(&callp->lock);
1286 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1287 host = rx_HostOf(peerp);
1288 port = rx_PortOf(peerp);
1291 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1292 ntohl(host), ntohs(port));
1294 if (cm_data.rootCellp) {
1295 t_name = (char *)malloc(strlen(cm_data.rootCellp->name)+1);
1296 strcpy(t_name, cm_data.rootCellp->name);
1298 t_name = (char *)malloc(1);
1303 MUTEX_EXIT(&callp->lock);
1309 * afs_MarshallCacheConfig - marshall client cache configuration
1313 * IN callerVersion - the rpc stat version of the caller.
1315 * IN config - client cache configuration.
1317 * OUT ptr - buffer where configuration is marshalled.
1323 static void afs_MarshallCacheConfig(
1324 afs_uint32 callerVersion,
1325 cm_initparams_v1 *config,
1329 * We currently only support version 1.
1331 *(ptr++) = config->nChunkFiles;
1332 *(ptr++) = config->nStatCaches;
1333 *(ptr++) = config->nDataCaches;
1334 *(ptr++) = config->nVolumeCaches;
1335 *(ptr++) = config->firstChunkSize;
1336 *(ptr++) = config->otherChunkSize;
1337 *(ptr++) = config->cacheSize;
1338 *(ptr++) = config->setTime;
1339 *(ptr++) = config->memCache;
1344 /*------------------------------------------------------------------------
1345 * EXPORTED SRXAFSCB_GetCacheConfig
1348 * Routine to return parameters used to initialize client cache.
1349 * Client may request any format version. Server may not return
1350 * format version greater than version requested by client.
1353 * a_call: Ptr to Rx call on which this request came in.
1354 * callerVersion: Data format version desired by the client.
1355 * serverVersion: Data format version of output data.
1356 * configCount: Number bytes allocated for output data.
1357 * config: Client cache configuration.
1363 * Nothing interesting.
1367 *------------------------------------------------------------------------*/
1369 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1370 afs_uint32 callerVersion,
1371 afs_uint32 *serverVersion,
1372 afs_uint32 *configCount,
1373 cacheConfig *config)
1375 afs_uint32 *t_config;
1377 extern cm_initparams_v1 cm_initParams;
1378 struct rx_connection *connp;
1379 struct rx_peer *peerp;
1380 unsigned long host = 0;
1381 unsigned short port = 0;
1383 MUTEX_ENTER(&callp->lock);
1385 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1386 host = rx_HostOf(peerp);
1387 port = rx_PortOf(peerp);
1390 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1391 ntohl(host), ntohs(port));
1394 * Currently only support version 1
1396 allocsize = sizeof(cm_initparams_v1);
1397 t_config = (afs_uint32 *)malloc(allocsize);
1399 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1401 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1402 *configCount = allocsize;
1403 config->cacheConfig_val = t_config;
1404 config->cacheConfig_len = allocsize/sizeof(afs_uint32);
1406 MUTEX_EXIT(&callp->lock);
1410 /* called by afsd without any locks to initialize this module */
1411 void cm_InitCallback(void)
1413 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
1414 cm_activeCallbackGrantingCalls = 0;
1417 /* called with locked scp; tells us whether we've got a callback.
1418 * Expirations are checked by a background daemon so as to make
1419 * this function as inexpensive as possible
1421 int cm_HaveCallback(cm_scache_t *scp)
1423 #ifdef AFS_FREELANCE_CLIENT
1424 // yj: we handle callbacks specially for callbacks on the root directory
1425 // Since it's local, we almost always say that we have callback on it
1426 // The only time we send back a 0 is if we're need to initialize or
1427 // reinitialize the fake directory
1429 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1430 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1431 // hence should return false. it's 0 otherwise
1432 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1433 // if the fake directory is loaded and this is the first time cm_HaveCallback
1434 // is called since then. We return false in this case to allow cm_GetCallback
1435 // to be called because cm_GetCallback has some initialization work to do.
1436 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1437 // good shape and we simply return true, provided no change is detected.
1440 if (cm_freelanceEnabled &&
1441 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1442 /* if it's something on /afs */
1443 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
1444 /* if it's not root.afs */
1448 lock_ObtainMutex(&cm_Freelance_Lock);
1449 fdc = cm_fakeDirCallback;
1450 fgc = cm_fakeGettingCallback;
1451 lock_ReleaseMutex(&cm_Freelance_Lock);
1453 if (fdc==1) { // first call since init
1455 } else if (fdc==2 && !fgc) { // we're in good shape
1456 if (cm_getLocalMountPointChange()) { // check for changes
1457 cm_clearLocalMountPointChange(); // clear the changefile
1458 lock_ReleaseMutex(&scp->mx); // this is re-locked in reInitLocalMountPoints
1459 cm_reInitLocalMountPoints(); // start reinit
1460 lock_ObtainMutex(&scp->mx); // now get the lock back
1463 return 1; // no change
1469 if (scp->cbServerp != NULL)
1475 /* need to detect a broken callback that races with our obtaining a callback.
1476 * Need to be able to do this even if we don't know the file ID of the file
1477 * we're breaking the callback on at the time we start the acquisition of the
1478 * callback (as in the case where we are creating a file).
1480 * So, we start by writing down the count of the # of callbacks we've received
1481 * so far, and bumping a global counter of the # of callback granting calls
1482 * outstanding (all done under cm_callbackLock).
1484 * When we're back from the call, we look at all of the callback revokes with
1485 * counter numbers greater than the one we recorded in our caller's structure,
1486 * and replay those that are higher than when we started the call.
1488 * We free all the structures in the queue when the count of the # of outstanding
1489 * callback-granting calls drops to zero.
1491 * We call this function with the scp locked, too, but in its current implementation,
1492 * this knowledge is not used.
1494 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1496 lock_ObtainWrite(&cm_callbackLock);
1497 cbrp->callbackCount = cm_callbackCount;
1498 cm_activeCallbackGrantingCalls++;
1499 cbrp->startTime = osi_Time();
1500 cbrp->serverp = NULL;
1501 lock_ReleaseWrite(&cm_callbackLock);
1504 /* Called at the end of a callback-granting call, to remove the callback
1505 * info from the scache entry, if necessary.
1507 * Called with scp locked, so we can discard the callbacks easily with
1508 * this locking hierarchy.
1510 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1511 AFSCallBack *cbp, long flags)
1513 cm_racingRevokes_t *revp; /* where we are */
1514 cm_racingRevokes_t *nrevp; /* where we'll be next */
1516 cm_server_t * serverp = 0;
1519 lock_ObtainWrite(&cm_callbackLock);
1520 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1521 osi_assert(cm_activeCallbackGrantingCalls > 0);
1524 osi_assert(cm_activeCallbackGrantingCalls-- > 0);
1526 if (cm_activeCallbackGrantingCalls == 0)
1531 /* record the callback; we'll clear it below if we really lose it */
1534 if (scp->cbServerp != cbrp->serverp) {
1535 serverp = scp->cbServerp;
1537 cm_GetServer(cbrp->serverp);
1538 scp->cbServerp = cbrp->serverp;
1541 serverp = cbrp->serverp;
1543 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1546 serverp = cbrp->serverp;
1549 cbrp->serverp = NULL;
1552 /* a callback was actually revoked during our granting call, so
1553 * run down the list of revoked fids, looking for ours.
1554 * If activeCallbackGrantingCalls is zero, free the elements, too.
1556 * May need to go through entire list just to do the freeing.
1558 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1559 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1560 /* if this callback came in later than when we started the
1561 * callback-granting call, and if this fid is the right fid,
1562 * then clear the callback.
1564 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1565 && revp->callbackCount > cbrp->callbackCount
1566 && (( scp->fid.volume == revp->fid.volume &&
1567 scp->fid.vnode == revp->fid.vnode &&
1568 scp->fid.unique == revp->fid.unique)
1570 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1571 scp->fid.volume == revp->fid.volume)
1573 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1574 /* this one matches */
1576 "Racing revoke scp 0x%x old cbc %d rev cbc %d cur cbc %d",
1578 cbrp->callbackCount, revp->callbackCount,
1586 /* if we freed the list, zap the pointer to it */
1588 cm_racingRevokesp = NULL;
1590 lock_ReleaseWrite(&cm_callbackLock);
1593 cm_DiscardSCache(scp);
1594 lock_ReleaseMutex(&scp->mx);
1595 cm_CallbackNotifyChange(scp);
1596 lock_ObtainMutex(&scp->mx);
1600 lock_ObtainWrite(&cm_serverLock);
1601 cm_FreeServer(serverp);
1602 lock_ReleaseWrite(&cm_serverLock);
1606 /* if flags is 1, we want to force the code to make one call, anyway.
1607 * called with locked scp; returns with same.
1609 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1610 struct cm_req *reqp, long flags)
1614 AFSFetchStatus afsStatus;
1616 AFSCallBack callback;
1618 cm_callbackRequest_t cbr;
1622 struct rx_connection * callp;
1624 osi_Log4(afsd_logp, "GetCallback scp 0x%x cell %d vol %d flags %lX",
1625 scp, scp->fid.cell, scp->fid.volume, flags);
1627 #ifdef AFS_FREELANCE_CLIENT
1628 // The case where a callback is needed on /afs is handled
1629 // specially. We need to fetch the status by calling
1630 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1631 if (cm_freelanceEnabled) {
1632 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1633 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1634 scp->fid.unique==0x1 &&
1635 scp->fid.vnode==0x1) {
1637 // Start by indicating that we're in the process
1638 // of fetching the callback
1639 lock_ObtainMutex(&cm_Freelance_Lock);
1640 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1641 cm_fakeGettingCallback = 1;
1642 lock_ReleaseMutex(&cm_Freelance_Lock);
1644 // Fetch the status info
1645 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
1647 // Indicate that the callback is not done
1648 lock_ObtainMutex(&cm_Freelance_Lock);
1649 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1650 cm_fakeDirCallback = 2;
1652 // Indicate that we're no longer fetching the callback
1653 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1654 cm_fakeGettingCallback = 0;
1655 lock_ReleaseMutex(&cm_Freelance_Lock);
1660 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1661 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1664 #endif /* AFS_FREELANCE_CLIENT */
1666 mustCall = (flags & 1);
1667 cm_AFSFidFromFid(&tfid, &scp->fid);
1669 if (!mustCall && cm_HaveCallback(scp)) {
1670 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%x cell %d vol %d",
1671 scp, scp->fid.cell, scp->fid.volume);
1675 /* turn off mustCall, since it has now forced us past the check above */
1678 /* otherwise, we have to make an RPC to get the status */
1679 sflags = CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK;
1680 cm_SyncOp(scp, NULL, NULL, NULL, 0, sflags);
1681 cm_StartCallbackGrantingCall(scp, &cbr);
1683 lock_ReleaseMutex(&scp->mx);
1685 /* now make the RPC */
1686 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%x cell %d vol %d uniq %d",
1687 (long) scp, scp->fid.cell, scp->fid.volume, scp->fid.unique);
1689 code = cm_Conn(&sfid, userp, reqp, &connp);
1693 callp = cm_GetRxConn(connp);
1694 code = RXAFS_FetchStatus(callp, &tfid,
1695 &afsStatus, &callback, &volSync);
1696 rx_PutConnection(callp);
1698 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1700 code = cm_MapRPCError(code, reqp);
1702 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%x cell %d vol %d",
1703 code, (long) scp, scp->fid.cell, scp->fid.volume);
1705 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%x cell %d vol %d uniq %d",
1706 (long) scp, scp->fid.cell, scp->fid.volume, scp->fid.unique);
1708 lock_ObtainMutex(&scp->mx);
1710 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1711 cm_MergeStatus(scp, &afsStatus, &volSync, userp, 0);
1713 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1715 cm_SyncOpDone(scp, NULL, sflags);
1717 /* now check to see if we got an error */
1719 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%x -->",code, scp);
1720 osi_Log4(afsd_logp, " cell %d vol %d vn %d uniq %d",
1721 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1727 /* called periodically by cm_daemon to shut down use of expired callbacks */
1728 void cm_CheckCBExpiration(void)
1734 osi_Log0(afsd_logp, "CheckCBExpiration");
1737 lock_ObtainWrite(&cm_scacheLock);
1738 for (i=0; i<cm_data.hashTableSize; i++) {
1739 for (scp = cm_data.hashTablep[i]; scp; scp=scp->nextp) {
1740 cm_HoldSCacheNoLock(scp);
1741 if (scp->cbExpires > 0 && (scp->cbServerp == NULL || now > scp->cbExpires)) {
1742 lock_ReleaseWrite(&cm_scacheLock);
1743 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%x vol %u vn %u uniq %u",
1744 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1745 lock_ObtainMutex(&scp->mx);
1746 cm_DiscardSCache(scp);
1747 lock_ReleaseMutex(&scp->mx);
1748 cm_CallbackNotifyChange(scp);
1749 lock_ObtainWrite(&cm_scacheLock);
1751 cm_ReleaseSCacheNoLock(scp);
1754 lock_ReleaseWrite(&cm_scacheLock);
1756 osi_Log0(afsd_logp, "CheckCBExpiration Complete");