2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
11 #include <afs/afs_args.h>
22 #include <rx_pthread.h>
24 #include <WINNT/syscfg.h>
25 #include <WINNT/afsreg.h>
27 /*extern void afsi_log(char *pattern, ...);*/
29 /* read/write lock for all global storage in this module */
30 osi_rwlock_t cm_callbackLock;
32 afs_int32 cm_OfflineROIsValid = 0;
34 afs_int32 cm_giveUpAllCBs = 0;
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 /* why does this have to query the registry each time? */
105 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
106 AFSREG_CLT_OPENAFS_SUBKEY,
108 KEY_READ|KEY_QUERY_VALUE,
109 &hKey) == ERROR_SUCCESS) {
111 dummyLen = sizeof(DWORD);
112 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
113 (BYTE *) &dwDelay, &dummyLen);
117 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
120 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
121 scp->fileType, scp->flags, dwDelay);
126 /* for directories, this sends a change notification on the dir itself */
127 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
128 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
130 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
131 scp, NULL, NULL, TRUE);
133 /* and for files, this sends a change notification on the file's parent dir */
137 cm_SetFid(&tfid, scp->fid.cell, scp->fid.volume, scp->parentVnode, 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, cm_cell_t * cellp, 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.scacheHashTablep[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 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
190 scp->cbExpires > 0 &&
191 scp->cbServerp != NULL)
193 cm_HoldSCacheNoLock(scp);
194 lock_ReleaseWrite(&cm_scacheLock);
195 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
196 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
198 lock_ObtainWrite(&scp->rw);
199 cm_DiscardSCache(scp);
200 lock_ReleaseWrite(&scp->rw);
202 cm_CallbackNotifyChange(scp);
204 lock_ObtainWrite(&cm_scacheLock);
205 cm_ReleaseSCacheNoLock(scp);
208 lock_ReleaseWrite(&cm_scacheLock);
210 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
211 fidp->Volume, fidp->Vnode, fidp->Unique);
214 /* called to revoke a volume callback, which is typically issued when a volume
215 * is moved from one server to another.
217 * Called with no locks held.
219 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
225 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
227 /* do this first, so that if we're executing a callback granting call
228 * at this moment, we kill it before it can be merged in. Otherwise,
229 * it could complete while we're doing the scan below, and get missed
230 * by both the scan and by this code.
232 tfid.cell = tfid.vnode = tfid.unique = 0;
233 tfid.volume = fidp->Volume;
234 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
236 lock_ObtainWrite(&cm_scacheLock);
237 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
238 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
239 if (scp->fid.volume == fidp->Volume &&
240 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
241 scp->cbExpires > 0 &&
242 scp->cbServerp != NULL) {
243 cm_HoldSCacheNoLock(scp);
244 lock_ReleaseWrite(&cm_scacheLock);
246 lock_ObtainWrite(&scp->rw);
247 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
248 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
249 cm_DiscardSCache(scp);
250 lock_ReleaseWrite(&scp->rw);
252 cm_CallbackNotifyChange(scp);
253 lock_ObtainWrite(&cm_scacheLock);
254 cm_ReleaseSCacheNoLock(scp);
255 if (scp->flags & CM_SCACHEFLAG_PURERO) {
256 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
258 volp->cbExpiresRO = 0;
263 } /* search one hash bucket */
264 } /* search all hash buckets */
266 lock_ReleaseWrite(&cm_scacheLock);
268 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
272 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
273 * given data pointer, without triggering "cast truncates pointer"
274 * warnings. We use this where we explicitly don't care whether a
275 * pointer is truncated -- it loses information where a pointer is
276 * larger than an afs_int32.
280 afs_data_pointer_to_int32(const void *p)
283 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
287 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
292 /* used to determine the byte order of the system */
295 char c[sizeof(int) / sizeof(char)];
301 /* little-endian system */
304 /* big-endian system */
305 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
310 return ip.i32[i32_sub];
312 /*------------------------------------------------------------------------
313 * EXPORTED SRXAFSCB_CallBack
316 * Routine called by the server-side callback RPC interface to
317 * implement passing in callback information.
321 * rx_call : Ptr to Rx call on which this request came in.
322 * fidsArrayp : Ptr to array of fids involved.
323 * cbsArrayp : Ptr to matching callback info for the fids.
329 * Nothing interesting.
333 *------------------------------------------------------------------------*/
334 /* handle incoming RPC callback breaking message.
335 * Called with no locks held.
338 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
342 struct rx_connection *connp;
343 struct rx_peer *peerp;
344 unsigned long host = 0;
345 unsigned short port = 0;
346 cm_server_t *tsp = NULL;
347 cm_cell_t* cellp = NULL;
349 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
350 host = rx_HostOf(peerp);
351 port = rx_PortOf(peerp);
353 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
358 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
362 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
365 cellp->name /* does not need to be saved, doesn't change */);
367 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
371 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
372 tfidp = &fidsArrayp->AFSCBFids_val[i];
374 if (tfidp->Volume == 0)
375 continue; /* means don't do anything */
376 else if (tfidp->Vnode == 0)
377 cm_RevokeVolumeCallback(callp, cellp, tfidp);
379 cm_RevokeCallback(callp, cellp, tfidp);
384 /*------------------------------------------------------------------------
385 * EXPORTED SRXAFSCB_InitCallBackState
388 * Routine called by the server-side callback RPC interface to
389 * implement clearing all callbacks from this host.
392 * rx_call : Ptr to Rx call on which this request came in.
398 * Nothing interesting.
402 *------------------------------------------------------------------------*/
403 /* called with no locks by RPC system when a server indicates that it has never
404 * heard from us, or for other reasons has had to discard callbacks from us
405 * without telling us, e.g. a network partition.
408 SRXAFSCB_InitCallBackState(struct rx_call *callp)
410 struct sockaddr_in taddr;
415 struct rx_connection *connp;
416 struct rx_peer *peerp;
417 unsigned long host = 0;
418 unsigned short port = 0;
420 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
421 host = rx_HostOf(peerp);
422 port = rx_PortOf(peerp);
425 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
429 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
430 taddr.sin_family = AF_INET;
431 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
433 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
435 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
437 /* record the callback in the racing revokes structure. This
438 * shouldn't be necessary, since we shouldn't be making callback
439 * granting calls while we're going to get an initstate call,
440 * but there probably are some obscure races, so better safe
443 * We do this first since we don't hold the cm_scacheLock and vnode
444 * locks over the entire callback scan operation below. The
445 * big loop below is guaranteed to hit any callback already
446 * processed. The call to RecordRacingRevoke is guaranteed
447 * to kill any callback that is currently being returned.
448 * Anything that sneaks past both must start
449 * after the call to RecordRacingRevoke.
451 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
453 /* now search all vnodes looking for guys with this callback, if we
454 * found it, or guys with any callbacks, if we didn't find the server
455 * (that's how multihomed machines will appear and how we'll handle
456 * them, albeit a little inefficiently). That is, we're discarding all
457 * callbacks from all hosts if we get an initstate call from an unknown
458 * host. Since these calls are rare, and multihomed servers
459 * are "rare," hopefully this won't be a problem.
461 lock_ObtainWrite(&cm_scacheLock);
462 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
463 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
464 cm_HoldSCacheNoLock(scp);
465 lock_ReleaseWrite(&cm_scacheLock);
466 lock_ObtainWrite(&scp->rw);
468 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
469 /* we have a callback, now decide if we should clear it */
470 if (scp->cbServerp == tsp || tsp == NULL) {
471 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%p vol %u vn %u uniq %u",
472 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
473 cm_DiscardSCache(scp);
477 lock_ReleaseWrite(&scp->rw);
479 cm_CallbackNotifyChange(scp);
480 lock_ObtainWrite(&cm_scacheLock);
481 cm_ReleaseSCacheNoLock(scp);
483 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO)) {
484 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
486 if (volp->cbExpiresRO != 0)
487 volp->cbExpiresRO = 0;
492 } /* search one hash bucket */
493 } /* search all hash buckets */
495 lock_ReleaseWrite(&cm_scacheLock);
498 /* reset the No flags on the server */
499 cm_SetServerNo64Bit(tsp, 0);
500 cm_SetServerNoInlineBulk(tsp, 0);
502 /* we're done with the server structure */
509 /*------------------------------------------------------------------------
510 * EXPORTED SRXAFSCB_Probe
513 * Routine called by the server-side callback RPC interface to
514 * implement ``probing'' the Cache Manager, just making sure it's
518 * rx_call : Ptr to Rx call on which this request came in.
524 * Nothing interesting.
528 *------------------------------------------------------------------------*/
530 SRXAFSCB_Probe(struct rx_call *callp)
532 struct rx_connection *connp;
533 struct rx_peer *peerp;
534 unsigned long host = 0;
535 unsigned short port = 0;
537 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
538 host = rx_HostOf(peerp);
539 port = rx_PortOf(peerp);
542 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
549 /*------------------------------------------------------------------------
550 * EXPORTED SRXAFSCB_GetLock
553 * Routine called by the server-side callback RPC interface to
554 * implement pulling out the contents of a lock in the lock
558 * a_call : Ptr to Rx call on which this request came in.
559 * a_index : Index of desired lock.
560 * a_result : Ptr to a buffer for the given lock.
563 * 0 if everything went fine,
564 * 1 if we were given a bad index.
567 * Nothing interesting.
571 *------------------------------------------------------------------------*/
572 /* debug interface */
574 extern osi_rwlock_t cm_aclLock;
575 extern osi_rwlock_t buf_globalLock;
576 extern osi_rwlock_t cm_cellLock;
577 extern osi_rwlock_t cm_connLock;
578 extern osi_rwlock_t cm_daemonLock;
579 extern osi_rwlock_t cm_dnlcLock;
580 extern osi_rwlock_t cm_scacheLock;
581 extern osi_rwlock_t cm_serverLock;
582 extern osi_rwlock_t cm_syscfgLock;
583 extern osi_rwlock_t cm_userLock;
584 extern osi_rwlock_t cm_utilsLock;
585 extern osi_rwlock_t cm_volumeLock;
586 extern osi_rwlock_t smb_globalLock;
587 extern osi_rwlock_t smb_rctLock;
589 extern osi_mutex_t cm_Freelance_Lock;
590 extern osi_mutex_t cm_bufGetMutex;
591 extern osi_mutex_t cm_Afsdsbmt_Lock;
592 extern osi_mutex_t tokenEventLock;
593 extern osi_mutex_t smb_ListenerLock;
594 extern osi_mutex_t smb_RawBufLock;
595 extern osi_mutex_t smb_Dir_Watch_Lock;
597 #define LOCKTYPE_RW 1
598 #define LOCKTYPE_MUTEX 2
599 static struct _ltable {
604 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
605 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
606 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
607 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
608 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
609 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
610 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
611 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
612 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
613 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
614 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
615 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
616 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
617 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
618 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
619 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
620 {"cm_bufGetMutex", (char*)&cm_bufGetMutex, LOCKTYPE_MUTEX},
621 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
622 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
623 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
624 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
625 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
629 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
631 struct _ltable *tl; /*Ptr to lock table entry */
634 int nentries; /*Num entries in table */
635 int code; /*Return code */
636 struct rx_connection *connp;
637 struct rx_peer *peerp;
638 unsigned long host = 0;
639 unsigned short port = 0;
641 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
642 host = rx_HostOf(peerp);
643 port = rx_PortOf(peerp);
646 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
647 index, ntohl(host), ntohs(port));
649 nentries = sizeof(ltable) / sizeof(struct _ltable);
650 if (index < 0 || index >= nentries) {
657 * Found it - copy out its contents.
660 strncpy(lockp->name, tl->name, sizeof(lockp->name));
661 lockp->name[sizeof(lockp->name)-1] = '\0';
662 lockp->lock.waitStates = 0;
663 switch ( tl->type ) {
665 rwp = (osi_rwlock_t *)tl->addr;
666 lockp->lock.exclLocked = rwp->flags;
667 lockp->lock.readersReading = rwp->readers;
668 lockp->lock.numWaiting = rwp->waiters;
671 mtxp = (osi_mutex_t *)tl->addr;
672 lockp->lock.exclLocked = mtxp->flags;
673 lockp->lock.readersReading = 0;
674 lockp->lock.numWaiting = mtxp->waiters;
677 lockp->lock.pid_last_reader = 0;
678 lockp->lock.pid_writer = 0;
679 lockp->lock.src_indicator = 0;
686 /* debug interface */
688 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
693 struct rx_connection *connp;
694 struct rx_peer *peerp;
695 unsigned long host = 0;
696 unsigned short port = 0;
698 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
699 host = rx_HostOf(peerp);
700 port = rx_PortOf(peerp);
703 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
704 ntohl(host), ntohs(port));
706 lock_ObtainRead(&cm_scacheLock);
707 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
708 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
712 } /*Zip through current hash chain */
713 } /*Zip through hash chains */
723 * Copy out the located entry.
725 memset(cep, 0, sizeof(AFSDBCacheEntry));
726 cep->addr = afs_data_pointer_to_int32(scp);
727 cep->cell = scp->fid.cell;
728 cep->netFid.Volume = scp->fid.volume;
729 cep->netFid.Vnode = scp->fid.vnode;
730 cep->netFid.Unique = scp->fid.unique;
731 cep->lock.waitStates = 0;
732 cep->lock.exclLocked = scp->rw.flags;
733 cep->lock.readersReading = 0;
734 cep->lock.numWaiting = scp->rw.waiters;
735 cep->lock.pid_last_reader = 0;
736 cep->lock.pid_writer = 0;
737 cep->lock.src_indicator = 0;
738 cep->Length = scp->length.LowPart;
739 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
740 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
741 if (scp->flags & CM_SCACHEFLAG_PURERO) {
742 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
744 cep->cbExpires = volp->cbExpiresRO;
748 cep->cbExpires = scp->cbExpires;
749 cep->refCount = scp->refCount;
750 cep->opens = scp->openReads;
751 cep->writers = scp->openWrites;
752 switch (scp->fileType) {
753 case CM_SCACHETYPE_FILE:
756 case CM_SCACHETYPE_MOUNTPOINT:
759 case CM_SCACHETYPE_DIRECTORY:
760 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
765 case CM_SCACHETYPE_SYMLINK:
768 case CM_SCACHETYPE_DFSLINK:
771 case CM_SCACHETYPE_INVALID:
776 if (scp->flags & CM_SCACHEFLAG_STATD)
778 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
780 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
781 scp->mountPointStringp[0])
783 if (scp->flags & CM_SCACHEFLAG_WAITING)
788 * Return our results.
791 lock_ReleaseRead(&cm_scacheLock);
796 /* debug interface */
798 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
803 struct rx_connection *connp;
804 struct rx_peer *peerp;
805 unsigned long host = 0;
806 unsigned short port = 0;
808 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
809 host = rx_HostOf(peerp);
810 port = rx_PortOf(peerp);
813 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
814 ntohl(host), ntohs(port));
816 lock_ObtainRead(&cm_scacheLock);
817 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
818 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
822 } /*Zip through current hash chain */
823 } /*Zip through hash chains */
833 * Copy out the located entry.
835 memset(cep, 0, sizeof(AFSDBCacheEntry64));
836 cep->addr = afs_data_pointer_to_int32(scp);
837 cep->cell = scp->fid.cell;
838 cep->netFid.Volume = scp->fid.volume;
839 cep->netFid.Vnode = scp->fid.vnode;
840 cep->netFid.Unique = scp->fid.unique;
841 cep->lock.waitStates = 0;
842 cep->lock.exclLocked = scp->rw.flags;
843 cep->lock.readersReading = 0;
844 cep->lock.numWaiting = scp->rw.waiters;
845 cep->lock.pid_last_reader = 0;
846 cep->lock.pid_writer = 0;
847 cep->lock.src_indicator = 0;
848 #if !defined(AFS_64BIT_ENV)
849 cep->Length.high = scp->length.HighPart;
850 cep->Length.low = scp->length.LowPart;
852 cep->Length = (afs_int64) scp->length.QuadPart;
854 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
855 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
856 if (scp->flags & CM_SCACHEFLAG_PURERO) {
857 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
859 cep->cbExpires = volp->cbExpiresRO;
863 cep->cbExpires = scp->cbExpires;
864 cep->refCount = scp->refCount;
865 cep->opens = scp->openReads;
866 cep->writers = scp->openWrites;
867 switch (scp->fileType) {
868 case CM_SCACHETYPE_FILE:
871 case CM_SCACHETYPE_MOUNTPOINT:
874 case CM_SCACHETYPE_DIRECTORY:
875 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
880 case CM_SCACHETYPE_SYMLINK:
883 case CM_SCACHETYPE_DFSLINK:
886 case CM_SCACHETYPE_INVALID:
891 if (scp->flags & CM_SCACHEFLAG_STATD)
893 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
895 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
896 scp->mountPointStringp[0])
898 if (scp->flags & CM_SCACHEFLAG_WAITING)
903 * Return our results.
906 lock_ReleaseRead(&cm_scacheLock);
911 /* debug interface: not implemented */
913 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
915 struct rx_connection *connp;
916 struct rx_peer *peerp;
917 unsigned long host = 0;
918 unsigned short port = 0;
920 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
921 host = rx_HostOf(peerp);
922 port = rx_PortOf(peerp);
925 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
926 ntohl(host), ntohs(port));
932 /* debug interface: not implemented */
934 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
935 AFSCB_CollData *datap)
937 struct rx_connection *connp;
938 struct rx_peer *peerp;
939 unsigned long host = 0;
940 unsigned short port = 0;
942 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
943 host = rx_HostOf(peerp);
944 port = rx_PortOf(peerp);
947 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
948 ntohl(host), ntohs(port));
954 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
956 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
958 return SRXAFSCB_InitCallBackState(callp);
961 /* debug interface */
963 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
967 struct rx_connection *connp;
968 struct rx_peer *peerp;
969 unsigned long host = 0;
970 unsigned short port = 0;
972 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
973 host = rx_HostOf(peerp);
974 port = rx_PortOf(peerp);
977 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
981 lock_ObtainRead(&cm_syscfgLock);
982 if (cm_LanAdapterChangeDetected) {
983 lock_ConvertRToW(&cm_syscfgLock);
984 if (cm_LanAdapterChangeDetected) {
985 /* get network related info */
986 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
987 code = syscfg_GetIFInfo(&cm_noIPAddr,
988 cm_IPAddr, cm_SubnetMask,
989 cm_NetMtu, cm_NetFlags);
990 cm_LanAdapterChangeDetected = 0;
992 lock_ConvertWToR(&cm_syscfgLock);
995 /* return all network interface addresses */
996 addr->numberOfInterfaces = cm_noIPAddr;
997 addr->uuid = cm_data.Uuid;
998 for ( i=0; i < cm_noIPAddr; i++ ) {
999 addr->addr_in[i] = cm_IPAddr[i];
1000 addr->subnetmask[i] = cm_SubnetMask[i];
1001 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1002 cm_NetMtu[i] : rx_mtu;
1005 lock_ReleaseRead(&cm_syscfgLock);
1011 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
1015 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
1016 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",osi_LogSaveString(afsd_logp,p));
1019 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1021 return SRXAFSCB_InitCallBackState(callp);
1024 /* debug interface */
1026 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1028 struct rx_connection *connp;
1029 struct rx_peer *peerp;
1030 unsigned long host = 0;
1031 unsigned short port = 0;
1035 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1036 host = rx_HostOf(peerp);
1037 port = rx_PortOf(peerp);
1040 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1041 UuidToString((UUID *)&cm_data.Uuid, &p);
1042 UuidToString((UUID *)clientUuid, &q);
1043 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1044 osi_LogSaveString(afsd_logp,p),
1045 osi_LogSaveString(afsd_logp,q),
1051 code = 1; /* failure */
1053 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1060 /* debug interface */
1062 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1066 cm_serverRef_t * serverRefp;
1068 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1070 *a_name = strdup("");
1074 lock_ObtainRead(&cm_serverLock);
1075 *a_name = strdup(cellp->name);
1077 for ( sn = 0, serverRefp = cellp->vlServersp;
1078 sn < AFSMAXCELLHOSTS && serverRefp;
1079 sn++, serverRefp = serverRefp->next);
1081 a_hosts->serverList_len = sn;
1082 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1084 for ( sn = 0, serverRefp = cellp->vlServersp;
1085 sn < AFSMAXCELLHOSTS && serverRefp;
1086 sn++, serverRefp = serverRefp->next)
1088 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1091 lock_ReleaseRead(&cm_serverLock);
1095 /* debug interface */
1097 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1098 char **a_name, serverList *a_hosts)
1100 struct rx_connection *connp;
1101 struct rx_peer *peerp;
1102 unsigned long host = 0;
1103 unsigned short port = 0;
1106 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1107 host = rx_HostOf(peerp);
1108 port = rx_PortOf(peerp);
1111 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1112 a_cellnum, ntohl(host), ntohs(port));
1114 a_hosts->serverList_val = 0;
1115 a_hosts->serverList_len = 0;
1118 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1123 /* debug interface */
1125 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1126 struct interfaceAddr *addr,
1127 Capabilities * capabilities)
1130 afs_int32 *dataBuffP;
1131 afs_int32 dataBytes;
1133 struct rx_connection *connp;
1134 struct rx_peer *peerp;
1135 unsigned long host = 0;
1136 unsigned short port = 0;
1138 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1139 host = rx_HostOf(peerp);
1140 port = rx_PortOf(peerp);
1143 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1147 lock_ObtainRead(&cm_syscfgLock);
1148 if (cm_LanAdapterChangeDetected) {
1149 lock_ConvertRToW(&cm_syscfgLock);
1150 if (cm_LanAdapterChangeDetected) {
1151 /* get network related info */
1152 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1153 code = syscfg_GetIFInfo(&cm_noIPAddr,
1154 cm_IPAddr, cm_SubnetMask,
1155 cm_NetMtu, cm_NetFlags);
1156 cm_LanAdapterChangeDetected = 0;
1158 lock_ConvertWToR(&cm_syscfgLock);
1161 /* return all network interface addresses */
1162 addr->numberOfInterfaces = cm_noIPAddr;
1163 addr->uuid = cm_data.Uuid;
1164 for ( i=0; i < cm_noIPAddr; i++ ) {
1165 addr->addr_in[i] = cm_IPAddr[i];
1166 addr->subnetmask[i] = cm_SubnetMask[i];
1167 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1168 cm_NetMtu[i] : rx_mtu;
1170 lock_ReleaseRead(&cm_syscfgLock);
1172 dataBytes = 1 * sizeof(afs_int32);
1173 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1174 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1175 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1176 capabilities->Capabilities_val = dataBuffP;
1181 /*------------------------------------------------------------------------
1182 * EXPORTED SRXAFSCB_GetServerPrefs
1185 * Routine to list server preferences used by this client.
1188 * a_call : Ptr to Rx call on which this request came in.
1189 * a_index : Input server index
1190 * a_srvr_addr : Output server address (0xffffffff on last server)
1191 * a_srvr_rank : Output server rank
1197 * Nothing interesting.
1201 *------------------------------------------------------------------------*/
1203 int SRXAFSCB_GetServerPrefs(
1204 struct rx_call *callp,
1206 afs_int32 *a_srvr_addr,
1207 afs_int32 *a_srvr_rank)
1209 struct rx_connection *connp;
1210 struct rx_peer *peerp;
1211 unsigned long host = 0;
1212 unsigned short port = 0;
1214 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1215 host = rx_HostOf(peerp);
1216 port = rx_PortOf(peerp);
1219 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1223 *a_srvr_addr = 0xffffffff;
1224 *a_srvr_rank = 0xffffffff;
1229 /*------------------------------------------------------------------------
1230 * EXPORTED SRXAFSCB_GetCellServDB
1233 * Routine to list cells configured for this client
1236 * a_call : Ptr to Rx call on which this request came in.
1237 * a_index : Input cell index
1238 * a_name : Output cell name ("" on last cell)
1239 * a_hosts : Output cell database servers
1245 * Nothing interesting.
1249 *------------------------------------------------------------------------*/
1251 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1252 serverList *a_hosts)
1254 struct rx_connection *connp;
1255 struct rx_peer *peerp;
1256 unsigned long host = 0;
1257 unsigned short port = 0;
1260 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1261 host = rx_HostOf(peerp);
1262 port = rx_PortOf(peerp);
1265 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1266 ntohl(host), ntohs(port));
1268 #ifdef AFS_FREELANCE_CLIENT
1269 if (cm_freelanceEnabled && index == 0) {
1270 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1274 rc = GetCellCommon(index+1, a_name, a_hosts);
1279 /*------------------------------------------------------------------------
1280 * EXPORTED SRXAFSCB_GetLocalCell
1283 * Routine to return name of client's local cell
1286 * a_call : Ptr to Rx call on which this request came in.
1287 * a_name : Output cell name
1293 * Nothing interesting.
1297 *------------------------------------------------------------------------*/
1299 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1302 struct rx_connection *connp;
1303 struct rx_peer *peerp;
1304 unsigned long host = 0;
1305 unsigned short port = 0;
1307 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1308 host = rx_HostOf(peerp);
1309 port = rx_PortOf(peerp);
1312 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1313 ntohl(host), ntohs(port));
1315 if (cm_data.rootCellp) {
1316 t_name = (char *)malloc(strlen(cm_data.rootCellp->name)+1);
1317 strcpy(t_name, cm_data.rootCellp->name);
1319 t_name = (char *)malloc(1);
1329 * afs_MarshallCacheConfig - marshall client cache configuration
1333 * IN callerVersion - the rpc stat version of the caller.
1335 * IN config - client cache configuration.
1337 * OUT ptr - buffer where configuration is marshalled.
1343 static void afs_MarshallCacheConfig(
1344 afs_uint32 callerVersion,
1345 cm_initparams_v1 *config,
1349 * We currently only support version 1.
1351 *(ptr++) = config->nChunkFiles;
1352 *(ptr++) = config->nStatCaches;
1353 *(ptr++) = config->nDataCaches;
1354 *(ptr++) = config->nVolumeCaches;
1355 *(ptr++) = config->firstChunkSize;
1356 *(ptr++) = config->otherChunkSize;
1357 *(ptr++) = config->cacheSize;
1358 *(ptr++) = config->setTime;
1359 *(ptr++) = config->memCache;
1364 /*------------------------------------------------------------------------
1365 * EXPORTED SRXAFSCB_GetCacheConfig
1368 * Routine to return parameters used to initialize client cache.
1369 * Client may request any format version. Server may not return
1370 * format version greater than version requested by client.
1373 * a_call: Ptr to Rx call on which this request came in.
1374 * callerVersion: Data format version desired by the client.
1375 * serverVersion: Data format version of output data.
1376 * configCount: Number bytes allocated for output data.
1377 * config: Client cache configuration.
1383 * Nothing interesting.
1387 *------------------------------------------------------------------------*/
1389 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1390 afs_uint32 callerVersion,
1391 afs_uint32 *serverVersion,
1392 afs_uint32 *configCount,
1393 cacheConfig *config)
1395 afs_uint32 *t_config;
1397 extern cm_initparams_v1 cm_initParams;
1398 struct rx_connection *connp;
1399 struct rx_peer *peerp;
1400 unsigned long host = 0;
1401 unsigned short port = 0;
1403 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1404 host = rx_HostOf(peerp);
1405 port = rx_PortOf(peerp);
1408 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1409 ntohl(host), ntohs(port));
1412 * Currently only support version 1
1414 allocsize = sizeof(cm_initparams_v1);
1415 t_config = (afs_uint32 *)malloc(allocsize);
1417 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1419 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1422 #define SIZE_MAX UINT_MAX
1424 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1426 *configCount = (afs_uint32)allocsize;
1427 config->cacheConfig_val = t_config;
1428 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1433 /* called by afsd without any locks to initialize this module */
1434 void cm_InitCallback(void)
1436 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
1437 cm_activeCallbackGrantingCalls = 0;
1440 /* called with locked scp; tells us whether we've got a callback.
1441 * Expirations are checked by a background daemon so as to make
1442 * this function as inexpensive as possible
1444 int cm_HaveCallback(cm_scache_t *scp)
1446 #ifdef AFS_FREELANCE_CLIENT
1447 // yj: we handle callbacks specially for callbacks on the root directory
1448 // Since it's local, we almost always say that we have callback on it
1449 // The only time we send back a 0 is if we're need to initialize or
1450 // reinitialize the fake directory
1452 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1453 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1454 // hence should return false. it's 0 otherwise
1455 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1456 // if the fake directory is loaded and this is the first time cm_HaveCallback
1457 // is called since then. We return false in this case to allow cm_GetCallback
1458 // to be called because cm_GetCallback has some initialization work to do.
1459 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1460 // good shape and we simply return true, provided no change is detected.
1463 if (cm_freelanceEnabled &&
1464 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1465 lock_ObtainMutex(&cm_Freelance_Lock);
1466 fdc = cm_fakeDirCallback;
1467 fgc = cm_fakeGettingCallback;
1468 lock_ReleaseMutex(&cm_Freelance_Lock);
1470 if (fdc==1) { // first call since init
1472 } else if (fdc==2 && !fgc) { // we're in good shape
1473 if (cm_getLocalMountPointChange()) { // check for changes
1474 cm_clearLocalMountPointChange(); // clear the changefile
1475 lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
1476 cm_reInitLocalMountPoints(); // start reinit
1477 lock_ObtainWrite(&scp->rw); // now get the lock back
1480 return 1; // no change
1486 if (scp->cbServerp != NULL) {
1488 } else if (cm_OfflineROIsValid) {
1489 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1491 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1507 /* need to detect a broken callback that races with our obtaining a callback.
1508 * Need to be able to do this even if we don't know the file ID of the file
1509 * we're breaking the callback on at the time we start the acquisition of the
1510 * callback (as in the case where we are creating a file).
1512 * So, we start by writing down the count of the # of callbacks we've received
1513 * so far, and bumping a global counter of the # of callback granting calls
1514 * outstanding (all done under cm_callbackLock).
1516 * When we're back from the call, we look at all of the callback revokes with
1517 * counter numbers greater than the one we recorded in our caller's structure,
1518 * and replay those that are higher than when we started the call.
1520 * We free all the structures in the queue when the count of the # of outstanding
1521 * callback-granting calls drops to zero.
1523 * We call this function with the scp locked, too, but in its current implementation,
1524 * this knowledge is not used.
1526 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1528 lock_ObtainWrite(&cm_callbackLock);
1529 cbrp->callbackCount = cm_callbackCount;
1530 cm_activeCallbackGrantingCalls++;
1531 cbrp->startTime = time(NULL);
1532 cbrp->serverp = NULL;
1533 lock_ReleaseWrite(&cm_callbackLock);
1536 /* Called at the end of a callback-granting call, to remove the callback
1537 * info from the scache entry, if necessary.
1539 * Called with scp write locked, so we can discard the callbacks easily with
1540 * this locking hierarchy.
1542 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1543 AFSCallBack *cbp, long flags)
1545 cm_racingRevokes_t *revp; /* where we are */
1546 cm_racingRevokes_t *nrevp; /* where we'll be next */
1548 cm_server_t * serverp = NULL;
1549 int discardScp = 0, discardVolCB = 0;
1551 lock_ObtainWrite(&cm_callbackLock);
1552 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1553 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1554 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1557 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1558 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1560 if (cm_activeCallbackGrantingCalls == 0)
1565 /* record the callback; we'll clear it below if we really lose it */
1568 if (scp->cbServerp != cbrp->serverp) {
1569 serverp = scp->cbServerp;
1571 cm_GetServer(cbrp->serverp);
1572 scp->cbServerp = cbrp->serverp;
1575 serverp = cbrp->serverp;
1577 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1578 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1579 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1581 volp->cbExpiresRO = scp->cbExpires;
1587 serverp = cbrp->serverp;
1590 cbrp->serverp = NULL;
1593 /* a callback was actually revoked during our granting call, so
1594 * run down the list of revoked fids, looking for ours.
1595 * If activeCallbackGrantingCalls is zero, free the elements, too.
1597 * May need to go through entire list just to do the freeing.
1599 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1600 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1601 /* if this callback came in later than when we started the
1602 * callback-granting call, and if this fid is the right fid,
1603 * then clear the callback.
1605 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1606 && revp->callbackCount > cbrp->callbackCount
1607 && (( scp->fid.volume == revp->fid.volume &&
1608 scp->fid.vnode == revp->fid.vnode &&
1609 scp->fid.unique == revp->fid.unique)
1611 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1612 scp->fid.volume == revp->fid.volume)
1614 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1615 /* this one matches */
1617 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1619 cbrp->callbackCount, revp->callbackCount,
1622 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1623 (revp->flags & (CM_RACINGFLAG_CANCELVOL | CM_RACINGFLAG_CANCELALL))) {
1624 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1626 volp->cbExpiresRO = 0;
1635 /* if we freed the list, zap the pointer to it */
1637 cm_racingRevokesp = NULL;
1639 lock_ReleaseWrite(&cm_callbackLock);
1642 cm_DiscardSCache(scp);
1643 lock_ReleaseWrite(&scp->rw);
1644 cm_CallbackNotifyChange(scp);
1645 lock_ObtainWrite(&scp->rw);
1649 lock_ObtainWrite(&cm_serverLock);
1650 cm_FreeServer(serverp);
1651 lock_ReleaseWrite(&cm_serverLock);
1655 /* if flags is 1, we want to force the code to make one call, anyway.
1656 * called with locked scp; returns with same.
1658 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1659 struct cm_req *reqp, long flags)
1662 cm_conn_t *connp = NULL;
1663 AFSFetchStatus afsStatus;
1665 AFSCallBack callback;
1667 cm_callbackRequest_t cbr;
1670 struct rx_connection * callp = NULL;
1671 int syncop_done = 0;
1673 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1674 scp, scp->fid.cell, scp->fid.volume, flags);
1676 #ifdef AFS_FREELANCE_CLIENT
1677 // The case where a callback is needed on /afs is handled
1678 // specially. We need to fetch the status by calling
1679 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1680 if (cm_freelanceEnabled) {
1681 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1682 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1683 scp->fid.unique==0x1 &&
1684 scp->fid.vnode==0x1) {
1686 // Start by indicating that we're in the process
1687 // of fetching the callback
1688 lock_ObtainMutex(&cm_Freelance_Lock);
1689 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1690 cm_fakeGettingCallback = 1;
1691 lock_ReleaseMutex(&cm_Freelance_Lock);
1693 // Fetch the status info
1694 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1696 // Indicate that the callback is not done
1697 lock_ObtainMutex(&cm_Freelance_Lock);
1698 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1699 cm_fakeDirCallback = 2;
1701 // Indicate that we're no longer fetching the callback
1702 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1703 cm_fakeGettingCallback = 0;
1704 lock_ReleaseMutex(&cm_Freelance_Lock);
1709 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1710 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1713 #endif /* AFS_FREELANCE_CLIENT */
1715 mustCall = (flags & 1);
1716 cm_AFSFidFromFid(&tfid, &scp->fid);
1718 if (!mustCall && cm_HaveCallback(scp))
1721 /* turn off mustCall, since it has now forced us past the check above */
1724 /* otherwise, we have to make an RPC to get the status */
1726 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1727 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1732 cm_StartCallbackGrantingCall(scp, &cbr);
1734 lock_ReleaseWrite(&scp->rw);
1736 /* now make the RPC */
1737 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1738 scp, sfid.volume, sfid.vnode, sfid.unique);
1740 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1744 callp = cm_GetRxConn(connp);
1745 code = RXAFS_FetchStatus(callp, &tfid,
1746 &afsStatus, &callback, &volSync);
1747 rx_PutConnection(callp);
1749 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1751 code = cm_MapRPCError(code, reqp);
1753 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1754 code, scp, scp->fid.volume, scp->fid.vnode);
1756 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1757 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1759 lock_ObtainWrite(&scp->rw);
1761 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1762 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1764 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1767 /* if we got an error, return to caller */
1773 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1776 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1777 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1778 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1780 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1781 scp, scp->fid.cell, scp->fid.volume);
1788 /* called with cm_scacheLock held */
1789 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1791 cm_vol_state_t *statep;
1793 afs_uint32 volID = scp->fid.volume;
1794 cm_serverRef_t *tsrp;
1799 if (scp->cbServerp == NULL)
1802 volp = cm_GetVolumeByFID(&scp->fid);
1806 if (volp->rw.ID == volID) {
1808 } else if (volp->ro.ID == volID) {
1810 } else if (volp->bk.ID == volID) {
1814 if (statep->state == vl_online)
1817 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1818 if (tsrp->server == scp->cbServerp)
1820 if (tsrp->server->downTime > *downTime)
1821 *downTime = tsrp->server->downTime;
1824 /* if the cbServerp does not match the current volume server list
1825 * we report the callback server as up so the callback can be
1828 return(found ? 0 : 1);
1831 /* called periodically by cm_daemon to shut down use of expired callbacks */
1832 void cm_CheckCBExpiration(void)
1836 time_t now, downTime;
1838 osi_Log0(afsd_logp, "CheckCBExpiration");
1841 lock_ObtainWrite(&cm_scacheLock);
1842 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1843 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1845 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1846 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1848 if (volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1849 scp->cbExpires = volp->cbExpiresRO;
1853 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1854 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1856 cm_HoldSCacheNoLock(scp);
1857 lock_ReleaseWrite(&cm_scacheLock);
1859 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1860 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1861 lock_ObtainWrite(&scp->rw);
1862 cm_DiscardSCache(scp);
1863 lock_ReleaseWrite(&scp->rw);
1864 cm_CallbackNotifyChange(scp);
1866 lock_ObtainWrite(&cm_scacheLock);
1867 cm_ReleaseSCacheNoLock(scp);
1871 lock_ReleaseWrite(&cm_scacheLock);
1873 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1878 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1882 struct rx_connection * rxconnp;
1884 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1886 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1888 rxconnp = cm_GetRxConn(connp);
1889 rx_SetConnDeadTime(rxconnp, 10);
1890 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1891 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1892 rx_PutConnection(rxconnp);
1896 cm_server_vols_t * tsrvp;
1900 lock_ObtainMutex(&tsp->mx);
1901 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1902 tsp->flags |= CM_SERVERFLAG_DOWN;
1903 tsp->downTime = time(NULL);
1905 cm_ForceNewConnections(tsp);
1907 /* Now update the volume status */
1908 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
1909 for (i=0; i<NUM_SERVER_VOLS; i++) {
1910 if (tsrvp->ids[i] != 0) {
1915 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
1916 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
1918 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
1924 lock_ReleaseMutex(&tsp->mx);
1930 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
1934 if (!cm_giveUpAllCBs)
1937 lock_ObtainWrite(&cm_serverLock);
1938 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
1939 cm_GetServerNoLock(tsp);
1940 lock_ReleaseWrite(&cm_serverLock);
1941 cm_GiveUpAllCallbacks(tsp, markDown);
1942 lock_ObtainWrite(&cm_serverLock);
1943 cm_PutServerNoLock(tsp);
1945 lock_ReleaseWrite(&cm_serverLock);