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>
23 #include <rx_pthread.h>
25 #include <WINNT/syscfg.h>
26 #include <WINNT/afsreg.h>
28 /*extern void afsi_log(char *pattern, ...);*/
30 /* read/write lock for all global storage in this module */
31 osi_rwlock_t cm_callbackLock;
33 afs_int32 cm_OfflineROIsValid = 0;
35 afs_int32 cm_giveUpAllCBs = 0;
37 afs_int32 cm_shutdown = 0;
39 #ifdef AFS_FREELANCE_CLIENT
40 extern osi_mutex_t cm_Freelance_Lock;
43 /* count of # of callback breaking messages received by this CM so far. We use
44 * this count in determining whether there have been any callback breaks that
45 * apply to a call that returned a new callback. If the counter doesn't
46 * increase during a call, then we know that no callbacks were broken during
47 * that call, and thus that the callback that was just returned is still valid.
49 long cm_callbackCount;
51 /* count of number of RPCs potentially returning a callback executing now.
52 * When this counter hits zero, we can clear out the racing revokes list, since
53 * at that time, we know that none of the just-executed callback revokes will
54 * apply to any future call that returns a callback (since the latter hasn't
55 * even started execution yet).
57 long cm_activeCallbackGrantingCalls;
59 /* list of callbacks that have been broken recently. If a call returning a
60 * callback is executing and a callback revoke runs immediately after it at the
61 * server, the revoke may end up being processed before the response to the
62 * original callback granting call. We detect this by keeping a list of
63 * callback revokes that have been received since we *started* the callback
64 * granting call, and discarding any callbacks received for the same file ID,
65 * even if the callback revoke was received before the callback grant.
67 cm_racingRevokes_t *cm_racingRevokesp;
69 /* record a (potentially) racing revoke for this file ID; null means for all
70 * file IDs, and is used by InitCallBackState.
72 * The cancelFlags describe whether we're just discarding callbacks for the same
73 * file ID, the same volume, or all from the same server.
75 * Called with no locks held.
77 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
79 cm_racingRevokes_t *rp;
81 lock_ObtainWrite(&cm_callbackLock);
83 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
84 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
86 if (cm_activeCallbackGrantingCalls > 0) {
87 rp = malloc(sizeof(*rp));
88 memset(rp, 0, sizeof(*rp));
89 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
90 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
91 if (fidp) rp->fid = *fidp;
92 rp->callbackCount = ++cm_callbackCount;
94 lock_ReleaseWrite(&cm_callbackLock);
98 * When we lose a callback, may have to send change notification replies.
99 * Do not call with a lock on the scp.
101 void cm_CallbackNotifyChange(cm_scache_t *scp)
107 /* why does this have to query the registry each time? */
108 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
109 AFSREG_CLT_OPENAFS_SUBKEY,
111 KEY_READ|KEY_QUERY_VALUE,
112 &hKey) == ERROR_SUCCESS) {
114 dummyLen = sizeof(DWORD);
115 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
116 (BYTE *) &dwDelay, &dummyLen);
120 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
123 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
124 scp->fileType, scp->flags, dwDelay);
129 /* for directories, this sends a change notification on the dir itself */
130 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
131 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
133 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
134 scp, NULL, NULL, TRUE);
136 /* and for files, this sends a change notification on the file's parent dir */
140 cm_SetFid(&tfid, scp->fid.cell, scp->fid.volume, scp->parentVnode, scp->parentUnique);
141 dscp = cm_FindSCache(&tfid);
143 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
145 FILE_NOTIFY_GENERIC_FILE_FILTER,
146 dscp, NULL, NULL, TRUE);
148 cm_ReleaseSCache(dscp);
152 /* called with no locks held for every file ID that is revoked directly by
153 * a callback revoke call. Does not have to handle volume callback breaks,
154 * since those have already been split out.
156 * The callp parameter is currently unused.
158 void cm_RevokeCallback(struct rx_call *callp, cm_cell_t * cellp, AFSFid *fidp)
164 /* don't bother setting cell, since we won't be checking it (to aid
165 * in working with multi-homed servers: we don't know the cell if we
166 * don't recognize the IP address).
169 tfid.volume = fidp->Volume;
170 tfid.vnode = fidp->Vnode;
171 tfid.unique = fidp->Unique;
172 hash = CM_SCACHE_HASH(&tfid);
174 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
175 fidp->Volume, fidp->Vnode, fidp->Unique);
177 /* do this first, so that if we're executing a callback granting call
178 * at this moment, we kill it before it can be merged in. Otherwise,
179 * it could complete while we're doing the scan below, and get missed
180 * by both the scan and by this code.
182 cm_RecordRacingRevoke(&tfid, 0);
184 lock_ObtainWrite(&cm_scacheLock);
185 /* do all in the hash bucket, since we don't know how many we'll find with
188 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
189 if (scp->fid.volume == tfid.volume &&
190 scp->fid.vnode == tfid.vnode &&
191 scp->fid.unique == tfid.unique &&
192 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
193 scp->cbExpires > 0 &&
194 scp->cbServerp != NULL)
196 cm_HoldSCacheNoLock(scp);
197 lock_ReleaseWrite(&cm_scacheLock);
198 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
199 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
201 lock_ObtainWrite(&scp->rw);
202 cm_DiscardSCache(scp);
203 lock_ReleaseWrite(&scp->rw);
205 cm_CallbackNotifyChange(scp);
207 lock_ObtainWrite(&cm_scacheLock);
208 cm_ReleaseSCacheNoLock(scp);
211 lock_ReleaseWrite(&cm_scacheLock);
213 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
214 fidp->Volume, fidp->Vnode, fidp->Unique);
217 /* called to revoke a volume callback, which is typically issued when a volume
218 * is moved from one server to another.
220 * Called with no locks held.
222 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
228 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
230 /* do this first, so that if we're executing a callback granting call
231 * at this moment, we kill it before it can be merged in. Otherwise,
232 * it could complete while we're doing the scan below, and get missed
233 * by both the scan and by this code.
235 tfid.cell = tfid.vnode = tfid.unique = 0;
236 tfid.volume = fidp->Volume;
237 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
239 lock_ObtainWrite(&cm_scacheLock);
240 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
241 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
242 if (scp->fid.volume == fidp->Volume &&
243 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
244 scp->cbExpires > 0 &&
245 scp->cbServerp != NULL) {
246 cm_HoldSCacheNoLock(scp);
247 lock_ReleaseWrite(&cm_scacheLock);
249 lock_ObtainWrite(&scp->rw);
250 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
251 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
252 cm_DiscardSCache(scp);
253 lock_ReleaseWrite(&scp->rw);
255 cm_CallbackNotifyChange(scp);
256 lock_ObtainWrite(&cm_scacheLock);
257 cm_ReleaseSCacheNoLock(scp);
258 if (scp->flags & CM_SCACHEFLAG_PURERO) {
259 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
261 volp->cbExpiresRO = 0;
266 } /* search one hash bucket */
267 } /* search all hash buckets */
269 lock_ReleaseWrite(&cm_scacheLock);
271 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
275 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
276 * given data pointer, without triggering "cast truncates pointer"
277 * warnings. We use this where we explicitly don't care whether a
278 * pointer is truncated -- it loses information where a pointer is
279 * larger than an afs_int32.
283 afs_data_pointer_to_int32(const void *p)
286 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
290 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
295 /* used to determine the byte order of the system */
298 char c[sizeof(int) / sizeof(char)];
304 /* little-endian system */
307 /* big-endian system */
308 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
313 return ip.i32[i32_sub];
315 /*------------------------------------------------------------------------
316 * EXPORTED SRXAFSCB_CallBack
319 * Routine called by the server-side callback RPC interface to
320 * implement passing in callback information.
324 * rx_call : Ptr to Rx call on which this request came in.
325 * fidsArrayp : Ptr to array of fids involved.
326 * cbsArrayp : Ptr to matching callback info for the fids.
332 * Nothing interesting.
336 *------------------------------------------------------------------------*/
337 /* handle incoming RPC callback breaking message.
338 * Called with no locks held.
341 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
345 struct rx_connection *connp;
346 struct rx_peer *peerp;
347 unsigned long host = 0;
348 unsigned short port = 0;
349 cm_server_t *tsp = NULL;
350 cm_cell_t* cellp = NULL;
355 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
356 host = rx_HostOf(peerp);
357 port = rx_PortOf(peerp);
359 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
366 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
370 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
373 cellp->name /* does not need to be saved, doesn't change */);
375 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
379 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
380 tfidp = &fidsArrayp->AFSCBFids_val[i];
382 if (tfidp->Volume == 0)
383 continue; /* means don't do anything */
384 else if (tfidp->Vnode == 0)
385 cm_RevokeVolumeCallback(callp, cellp, tfidp);
387 cm_RevokeCallback(callp, cellp, tfidp);
392 /*------------------------------------------------------------------------
393 * EXPORTED SRXAFSCB_InitCallBackState
396 * Routine called by the server-side callback RPC interface to
397 * implement clearing all callbacks from this host.
400 * rx_call : Ptr to Rx call on which this request came in.
406 * Nothing interesting.
410 *------------------------------------------------------------------------*/
411 /* called with no locks by RPC system when a server indicates that it has never
412 * heard from us, or for other reasons has had to discard callbacks from us
413 * without telling us, e.g. a network partition.
416 SRXAFSCB_InitCallBackState(struct rx_call *callp)
418 struct sockaddr_in taddr;
423 struct rx_connection *connp;
424 struct rx_peer *peerp;
425 unsigned long host = 0;
426 unsigned short port = 0;
431 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
432 host = rx_HostOf(peerp);
433 port = rx_PortOf(peerp);
436 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
440 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
441 taddr.sin_family = AF_INET;
442 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
444 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
446 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
448 /* record the callback in the racing revokes structure. This
449 * shouldn't be necessary, since we shouldn't be making callback
450 * granting calls while we're going to get an initstate call,
451 * but there probably are some obscure races, so better safe
454 * We do this first since we don't hold the cm_scacheLock and vnode
455 * locks over the entire callback scan operation below. The
456 * big loop below is guaranteed to hit any callback already
457 * processed. The call to RecordRacingRevoke is guaranteed
458 * to kill any callback that is currently being returned.
459 * Anything that sneaks past both must start
460 * after the call to RecordRacingRevoke.
462 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
464 /* now search all vnodes looking for guys with this callback, if we
465 * found it, or guys with any callbacks, if we didn't find the server
466 * (that's how multihomed machines will appear and how we'll handle
467 * them, albeit a little inefficiently). That is, we're discarding all
468 * callbacks from all hosts if we get an initstate call from an unknown
469 * host. Since these calls are rare, and multihomed servers
470 * are "rare," hopefully this won't be a problem.
472 lock_ObtainWrite(&cm_scacheLock);
473 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
474 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
475 cm_HoldSCacheNoLock(scp);
476 lock_ReleaseWrite(&cm_scacheLock);
477 lock_ObtainWrite(&scp->rw);
479 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
480 /* we have a callback, now decide if we should clear it */
481 if (scp->cbServerp == tsp || tsp == NULL) {
482 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%p vol %u vn %u uniq %u",
483 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
484 cm_DiscardSCache(scp);
488 lock_ReleaseWrite(&scp->rw);
490 cm_CallbackNotifyChange(scp);
491 lock_ObtainWrite(&cm_scacheLock);
492 cm_ReleaseSCacheNoLock(scp);
494 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO)) {
495 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
497 if (volp->cbExpiresRO != 0)
498 volp->cbExpiresRO = 0;
503 } /* search one hash bucket */
504 } /* search all hash buckets */
506 lock_ReleaseWrite(&cm_scacheLock);
509 /* reset the No flags on the server */
510 cm_SetServerNo64Bit(tsp, 0);
511 cm_SetServerNoInlineBulk(tsp, 0);
513 /* we're done with the server structure */
520 /*------------------------------------------------------------------------
521 * EXPORTED SRXAFSCB_Probe
524 * Routine called by the server-side callback RPC interface to
525 * implement ``probing'' the Cache Manager, just making sure it's
529 * rx_call : Ptr to Rx call on which this request came in.
535 * Nothing interesting.
539 *------------------------------------------------------------------------*/
541 SRXAFSCB_Probe(struct rx_call *callp)
543 struct rx_connection *connp;
544 struct rx_peer *peerp;
545 unsigned long host = 0;
546 unsigned short port = 0;
551 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
552 host = rx_HostOf(peerp);
553 port = rx_PortOf(peerp);
556 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
563 /*------------------------------------------------------------------------
564 * EXPORTED SRXAFSCB_GetLock
567 * Routine called by the server-side callback RPC interface to
568 * implement pulling out the contents of a lock in the lock
572 * a_call : Ptr to Rx call on which this request came in.
573 * a_index : Index of desired lock.
574 * a_result : Ptr to a buffer for the given lock.
577 * 0 if everything went fine,
578 * 1 if we were given a bad index.
581 * Nothing interesting.
585 *------------------------------------------------------------------------*/
586 /* debug interface */
588 extern osi_rwlock_t cm_aclLock;
589 extern osi_rwlock_t buf_globalLock;
590 extern osi_rwlock_t cm_cellLock;
591 extern osi_rwlock_t cm_connLock;
592 extern osi_rwlock_t cm_daemonLock;
593 extern osi_rwlock_t cm_dnlcLock;
594 extern osi_rwlock_t cm_scacheLock;
595 extern osi_rwlock_t cm_serverLock;
596 extern osi_rwlock_t cm_syscfgLock;
597 extern osi_rwlock_t cm_userLock;
598 extern osi_rwlock_t cm_utilsLock;
599 extern osi_rwlock_t cm_volumeLock;
600 extern osi_rwlock_t smb_globalLock;
601 extern osi_rwlock_t smb_rctLock;
603 extern osi_mutex_t cm_Freelance_Lock;
604 extern osi_mutex_t cm_Afsdsbmt_Lock;
605 extern osi_mutex_t tokenEventLock;
606 extern osi_mutex_t smb_ListenerLock;
607 extern osi_mutex_t smb_RawBufLock;
608 extern osi_mutex_t smb_Dir_Watch_Lock;
610 #define LOCKTYPE_RW 1
611 #define LOCKTYPE_MUTEX 2
612 static struct _ltable {
617 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
618 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
619 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
620 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
621 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
622 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
623 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
624 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
625 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
626 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
627 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
628 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
629 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
630 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
631 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
632 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
633 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
634 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
635 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
636 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
637 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
641 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
643 struct _ltable *tl; /*Ptr to lock table entry */
646 int nentries; /*Num entries in table */
647 int code; /*Return code */
648 struct rx_connection *connp;
649 struct rx_peer *peerp;
650 unsigned long host = 0;
651 unsigned short port = 0;
656 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
657 host = rx_HostOf(peerp);
658 port = rx_PortOf(peerp);
661 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
662 index, ntohl(host), ntohs(port));
664 nentries = sizeof(ltable) / sizeof(struct _ltable);
665 if (index < 0 || index >= nentries) {
672 * Found it - copy out its contents.
675 strncpy(lockp->name, tl->name, sizeof(lockp->name));
676 lockp->name[sizeof(lockp->name)-1] = '\0';
677 lockp->lock.waitStates = 0;
678 switch ( tl->type ) {
680 rwp = (osi_rwlock_t *)tl->addr;
681 lockp->lock.exclLocked = rwp->flags;
682 lockp->lock.readersReading = rwp->readers;
683 lockp->lock.numWaiting = rwp->waiters;
686 mtxp = (osi_mutex_t *)tl->addr;
687 lockp->lock.exclLocked = mtxp->flags;
688 lockp->lock.readersReading = 0;
689 lockp->lock.numWaiting = mtxp->waiters;
692 lockp->lock.pid_last_reader = 0;
693 lockp->lock.pid_writer = 0;
694 lockp->lock.src_indicator = 0;
701 /* debug interface */
703 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
708 struct rx_connection *connp;
709 struct rx_peer *peerp;
710 unsigned long host = 0;
711 unsigned short port = 0;
716 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
717 host = rx_HostOf(peerp);
718 port = rx_PortOf(peerp);
721 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
722 ntohl(host), ntohs(port));
724 lock_ObtainRead(&cm_scacheLock);
725 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
726 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
730 } /*Zip through current hash chain */
731 } /*Zip through hash chains */
741 * Copy out the located entry.
743 memset(cep, 0, sizeof(AFSDBCacheEntry));
744 cep->addr = afs_data_pointer_to_int32(scp);
745 cep->cell = scp->fid.cell;
746 cep->netFid.Volume = scp->fid.volume;
747 cep->netFid.Vnode = scp->fid.vnode;
748 cep->netFid.Unique = scp->fid.unique;
749 cep->lock.waitStates = 0;
750 cep->lock.exclLocked = scp->rw.flags;
751 cep->lock.readersReading = 0;
752 cep->lock.numWaiting = scp->rw.waiters;
753 cep->lock.pid_last_reader = 0;
754 cep->lock.pid_writer = 0;
755 cep->lock.src_indicator = 0;
756 cep->Length = scp->length.LowPart;
757 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
758 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
759 if (scp->flags & CM_SCACHEFLAG_PURERO) {
760 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
762 cep->cbExpires = volp->cbExpiresRO;
766 /* TODO: deal with time_t below */
767 cep->cbExpires = (afs_int32) scp->cbExpires;
769 cep->refCount = scp->refCount;
770 cep->opens = scp->openReads;
771 cep->writers = scp->openWrites;
772 switch (scp->fileType) {
773 case CM_SCACHETYPE_FILE:
776 case CM_SCACHETYPE_MOUNTPOINT:
779 case CM_SCACHETYPE_DIRECTORY:
780 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
785 case CM_SCACHETYPE_SYMLINK:
788 case CM_SCACHETYPE_DFSLINK:
791 case CM_SCACHETYPE_INVALID:
796 if (scp->flags & CM_SCACHEFLAG_STATD)
798 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
800 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
801 scp->mountPointStringp[0])
803 if (scp->flags & CM_SCACHEFLAG_WAITING)
808 * Return our results.
811 lock_ReleaseRead(&cm_scacheLock);
816 /* debug interface */
818 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
823 struct rx_connection *connp;
824 struct rx_peer *peerp;
825 unsigned long host = 0;
826 unsigned short port = 0;
831 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
832 host = rx_HostOf(peerp);
833 port = rx_PortOf(peerp);
836 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
837 ntohl(host), ntohs(port));
839 lock_ObtainRead(&cm_scacheLock);
840 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
841 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
845 } /*Zip through current hash chain */
846 } /*Zip through hash chains */
856 * Copy out the located entry.
858 memset(cep, 0, sizeof(AFSDBCacheEntry64));
859 cep->addr = afs_data_pointer_to_int32(scp);
860 cep->cell = scp->fid.cell;
861 cep->netFid.Volume = scp->fid.volume;
862 cep->netFid.Vnode = scp->fid.vnode;
863 cep->netFid.Unique = scp->fid.unique;
864 cep->lock.waitStates = 0;
865 cep->lock.exclLocked = scp->rw.flags;
866 cep->lock.readersReading = 0;
867 cep->lock.numWaiting = scp->rw.waiters;
868 cep->lock.pid_last_reader = 0;
869 cep->lock.pid_writer = 0;
870 cep->lock.src_indicator = 0;
871 #if !defined(AFS_64BIT_ENV)
872 cep->Length.high = scp->length.HighPart;
873 cep->Length.low = scp->length.LowPart;
875 cep->Length = (afs_int64) scp->length.QuadPart;
877 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
878 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
879 if (scp->flags & CM_SCACHEFLAG_PURERO) {
880 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
882 cep->cbExpires = volp->cbExpiresRO;
886 /* TODO: handle time_t */
887 cep->cbExpires = (afs_int32) scp->cbExpires;
889 cep->refCount = scp->refCount;
890 cep->opens = scp->openReads;
891 cep->writers = scp->openWrites;
892 switch (scp->fileType) {
893 case CM_SCACHETYPE_FILE:
896 case CM_SCACHETYPE_MOUNTPOINT:
899 case CM_SCACHETYPE_DIRECTORY:
900 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
905 case CM_SCACHETYPE_SYMLINK:
908 case CM_SCACHETYPE_DFSLINK:
911 case CM_SCACHETYPE_INVALID:
916 if (scp->flags & CM_SCACHEFLAG_STATD)
918 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
920 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
921 scp->mountPointStringp[0])
923 if (scp->flags & CM_SCACHEFLAG_WAITING)
928 * Return our results.
931 lock_ReleaseRead(&cm_scacheLock);
936 /* debug interface: not implemented */
938 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
940 struct rx_connection *connp;
941 struct rx_peer *peerp;
942 unsigned long host = 0;
943 unsigned short port = 0;
948 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
949 host = rx_HostOf(peerp);
950 port = rx_PortOf(peerp);
953 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
954 ntohl(host), ntohs(port));
960 /* debug interface: not implemented */
962 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
963 AFSCB_CollData *datap)
965 struct rx_connection *connp;
966 struct rx_peer *peerp;
967 unsigned long host = 0;
968 unsigned short port = 0;
973 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
974 host = rx_HostOf(peerp);
975 port = rx_PortOf(peerp);
978 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
979 ntohl(host), ntohs(port));
985 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
990 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
992 return SRXAFSCB_InitCallBackState(callp);
995 /* debug interface */
997 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
1001 struct rx_connection *connp;
1002 struct rx_peer *peerp;
1003 unsigned long host = 0;
1004 unsigned short port = 0;
1009 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1010 host = rx_HostOf(peerp);
1011 port = rx_PortOf(peerp);
1014 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
1018 lock_ObtainRead(&cm_syscfgLock);
1019 if (cm_LanAdapterChangeDetected) {
1020 lock_ConvertRToW(&cm_syscfgLock);
1021 if (cm_LanAdapterChangeDetected) {
1022 /* get network related info */
1023 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1024 code = syscfg_GetIFInfo(&cm_noIPAddr,
1025 cm_IPAddr, cm_SubnetMask,
1026 cm_NetMtu, cm_NetFlags);
1027 cm_LanAdapterChangeDetected = 0;
1029 lock_ConvertWToR(&cm_syscfgLock);
1032 /* return all network interface addresses */
1033 addr->numberOfInterfaces = cm_noIPAddr;
1034 addr->uuid = cm_data.Uuid;
1035 for ( i=0; i < cm_noIPAddr; i++ ) {
1036 addr->addr_in[i] = cm_IPAddr[i];
1037 addr->subnetmask[i] = cm_SubnetMask[i];
1038 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1039 cm_NetMtu[i] : rx_mtu;
1042 lock_ReleaseRead(&cm_syscfgLock);
1048 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
1055 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
1056 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",osi_LogSaveString(afsd_logp,p));
1059 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1061 return SRXAFSCB_InitCallBackState(callp);
1064 /* debug interface */
1066 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1068 struct rx_connection *connp;
1069 struct rx_peer *peerp;
1070 unsigned long host = 0;
1071 unsigned short port = 0;
1078 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1079 host = rx_HostOf(peerp);
1080 port = rx_PortOf(peerp);
1083 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1084 UuidToString((UUID *)&cm_data.Uuid, &p);
1085 UuidToString((UUID *)clientUuid, &q);
1086 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1087 osi_LogSaveString(afsd_logp,p),
1088 osi_LogSaveString(afsd_logp,q),
1094 code = 1; /* failure */
1096 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1103 /* debug interface */
1105 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1109 cm_serverRef_t * serverRefp;
1111 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1113 *a_name = strdup("");
1117 lock_ObtainRead(&cm_serverLock);
1118 *a_name = strdup(cellp->name);
1120 for ( sn = 0, serverRefp = cellp->vlServersp;
1121 sn < AFSMAXCELLHOSTS && serverRefp;
1122 sn++, serverRefp = serverRefp->next);
1124 a_hosts->serverList_len = sn;
1125 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1127 for ( sn = 0, serverRefp = cellp->vlServersp;
1128 sn < AFSMAXCELLHOSTS && serverRefp;
1129 sn++, serverRefp = serverRefp->next)
1131 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1134 lock_ReleaseRead(&cm_serverLock);
1138 /* debug interface */
1140 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1141 char **a_name, serverList *a_hosts)
1143 struct rx_connection *connp;
1144 struct rx_peer *peerp;
1145 unsigned long host = 0;
1146 unsigned short port = 0;
1152 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1153 host = rx_HostOf(peerp);
1154 port = rx_PortOf(peerp);
1157 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1158 a_cellnum, ntohl(host), ntohs(port));
1160 a_hosts->serverList_val = 0;
1161 a_hosts->serverList_len = 0;
1164 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1169 /* debug interface */
1171 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1172 struct interfaceAddr *addr,
1173 Capabilities * capabilities)
1176 afs_int32 *dataBuffP;
1177 afs_int32 dataBytes;
1179 struct rx_connection *connp;
1180 struct rx_peer *peerp;
1181 unsigned long host = 0;
1182 unsigned short port = 0;
1187 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1188 host = rx_HostOf(peerp);
1189 port = rx_PortOf(peerp);
1192 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1196 lock_ObtainRead(&cm_syscfgLock);
1197 if (cm_LanAdapterChangeDetected) {
1198 lock_ConvertRToW(&cm_syscfgLock);
1199 if (cm_LanAdapterChangeDetected) {
1200 /* get network related info */
1201 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1202 code = syscfg_GetIFInfo(&cm_noIPAddr,
1203 cm_IPAddr, cm_SubnetMask,
1204 cm_NetMtu, cm_NetFlags);
1205 cm_LanAdapterChangeDetected = 0;
1207 lock_ConvertWToR(&cm_syscfgLock);
1210 /* return all network interface addresses */
1211 addr->numberOfInterfaces = cm_noIPAddr;
1212 addr->uuid = cm_data.Uuid;
1213 for ( i=0; i < cm_noIPAddr; i++ ) {
1214 addr->addr_in[i] = cm_IPAddr[i];
1215 addr->subnetmask[i] = cm_SubnetMask[i];
1216 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1217 cm_NetMtu[i] : rx_mtu;
1219 lock_ReleaseRead(&cm_syscfgLock);
1221 dataBytes = 1 * sizeof(afs_int32);
1222 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1223 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1224 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1225 capabilities->Capabilities_val = dataBuffP;
1230 /*------------------------------------------------------------------------
1231 * EXPORTED SRXAFSCB_GetServerPrefs
1234 * Routine to list server preferences used by this client.
1237 * a_call : Ptr to Rx call on which this request came in.
1238 * a_index : Input server index
1239 * a_srvr_addr : Output server address (0xffffffff on last server)
1240 * a_srvr_rank : Output server rank
1246 * Nothing interesting.
1250 *------------------------------------------------------------------------*/
1252 int SRXAFSCB_GetServerPrefs(
1253 struct rx_call *callp,
1255 afs_int32 *a_srvr_addr,
1256 afs_int32 *a_srvr_rank)
1258 struct rx_connection *connp;
1259 struct rx_peer *peerp;
1260 unsigned long host = 0;
1261 unsigned short port = 0;
1266 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1267 host = rx_HostOf(peerp);
1268 port = rx_PortOf(peerp);
1271 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1275 *a_srvr_addr = 0xffffffff;
1276 *a_srvr_rank = 0xffffffff;
1281 /*------------------------------------------------------------------------
1282 * EXPORTED SRXAFSCB_GetCellServDB
1285 * Routine to list cells configured for this client
1288 * a_call : Ptr to Rx call on which this request came in.
1289 * a_index : Input cell index
1290 * a_name : Output cell name ("" on last cell)
1291 * a_hosts : Output cell database servers
1297 * Nothing interesting.
1301 *------------------------------------------------------------------------*/
1303 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1304 serverList *a_hosts)
1306 struct rx_connection *connp;
1307 struct rx_peer *peerp;
1308 unsigned long host = 0;
1309 unsigned short port = 0;
1315 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1316 host = rx_HostOf(peerp);
1317 port = rx_PortOf(peerp);
1320 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1321 ntohl(host), ntohs(port));
1323 #ifdef AFS_FREELANCE_CLIENT
1324 if (cm_freelanceEnabled && index == 0) {
1325 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1329 rc = GetCellCommon(index+1, a_name, a_hosts);
1334 /*------------------------------------------------------------------------
1335 * EXPORTED SRXAFSCB_GetLocalCell
1338 * Routine to return name of client's local cell
1341 * a_call : Ptr to Rx call on which this request came in.
1342 * a_name : Output cell name
1348 * Nothing interesting.
1352 *------------------------------------------------------------------------*/
1354 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1357 struct rx_connection *connp;
1358 struct rx_peer *peerp;
1359 unsigned long host = 0;
1360 unsigned short port = 0;
1365 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1366 host = rx_HostOf(peerp);
1367 port = rx_PortOf(peerp);
1370 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1371 ntohl(host), ntohs(port));
1373 if (cm_data.rootCellp) {
1374 t_name = strdup(cm_data.rootCellp->name);
1376 t_name = (char *)malloc(1);
1386 * afs_MarshallCacheConfig - marshall client cache configuration
1390 * IN callerVersion - the rpc stat version of the caller.
1392 * IN config - client cache configuration.
1394 * OUT ptr - buffer where configuration is marshalled.
1400 static void afs_MarshallCacheConfig(
1401 afs_uint32 callerVersion,
1402 cm_initparams_v1 *config,
1406 * We currently only support version 1.
1408 *(ptr++) = config->nChunkFiles;
1409 *(ptr++) = config->nStatCaches;
1410 *(ptr++) = config->nDataCaches;
1411 *(ptr++) = config->nVolumeCaches;
1412 *(ptr++) = config->firstChunkSize;
1413 *(ptr++) = config->otherChunkSize;
1414 *(ptr++) = config->cacheSize;
1415 *(ptr++) = config->setTime;
1416 *(ptr++) = config->memCache;
1421 /*------------------------------------------------------------------------
1422 * EXPORTED SRXAFSCB_GetCacheConfig
1425 * Routine to return parameters used to initialize client cache.
1426 * Client may request any format version. Server may not return
1427 * format version greater than version requested by client.
1430 * a_call: Ptr to Rx call on which this request came in.
1431 * callerVersion: Data format version desired by the client.
1432 * serverVersion: Data format version of output data.
1433 * configCount: Number bytes allocated for output data.
1434 * config: Client cache configuration.
1440 * Nothing interesting.
1444 *------------------------------------------------------------------------*/
1446 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1447 afs_uint32 callerVersion,
1448 afs_uint32 *serverVersion,
1449 afs_uint32 *configCount,
1450 cacheConfig *config)
1452 afs_uint32 *t_config;
1454 extern cm_initparams_v1 cm_initParams;
1455 struct rx_connection *connp;
1456 struct rx_peer *peerp;
1457 unsigned long host = 0;
1458 unsigned short port = 0;
1463 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1464 host = rx_HostOf(peerp);
1465 port = rx_PortOf(peerp);
1468 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1469 ntohl(host), ntohs(port));
1472 * Currently only support version 1
1474 allocsize = sizeof(cm_initparams_v1);
1475 t_config = (afs_uint32 *)malloc(allocsize);
1477 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1479 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1482 #define SIZE_MAX UINT_MAX
1484 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1486 *configCount = (afs_uint32)allocsize;
1487 config->cacheConfig_val = t_config;
1488 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1493 /* called by afsd without any locks to initialize this module */
1494 void cm_InitCallback(void)
1496 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1497 cm_activeCallbackGrantingCalls = 0;
1500 /* called with locked scp; tells us whether we've got a callback.
1501 * Expirations are checked by a background daemon so as to make
1502 * this function as inexpensive as possible
1504 int cm_HaveCallback(cm_scache_t *scp)
1506 #ifdef AFS_FREELANCE_CLIENT
1507 // yj: we handle callbacks specially for callbacks on the root directory
1508 // Since it's local, we almost always say that we have callback on it
1509 // The only time we send back a 0 is if we're need to initialize or
1510 // reinitialize the fake directory
1512 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1513 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1514 // hence should return false. it's 0 otherwise
1515 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1516 // if the fake directory is loaded and this is the first time cm_HaveCallback
1517 // is called since then. We return false in this case to allow cm_GetCallback
1518 // to be called because cm_GetCallback has some initialization work to do.
1519 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1520 // good shape and we simply return true, provided no change is detected.
1523 if (cm_freelanceEnabled &&
1524 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1525 lock_ObtainMutex(&cm_Freelance_Lock);
1526 fdc = cm_fakeDirCallback;
1527 fgc = cm_fakeGettingCallback;
1528 lock_ReleaseMutex(&cm_Freelance_Lock);
1530 if (fdc==1) { // first call since init
1532 } else if (fdc==2 && !fgc) { // we're in good shape
1533 if (cm_getLocalMountPointChange()) { // check for changes
1534 cm_clearLocalMountPointChange(); // clear the changefile
1535 lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
1536 cm_reInitLocalMountPoints(); // start reinit
1537 lock_ObtainWrite(&scp->rw); // now get the lock back
1540 return 1; // no change
1546 if (scp->cbServerp != NULL) {
1548 } else if (cm_OfflineROIsValid) {
1549 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1551 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1567 /* need to detect a broken callback that races with our obtaining a callback.
1568 * Need to be able to do this even if we don't know the file ID of the file
1569 * we're breaking the callback on at the time we start the acquisition of the
1570 * callback (as in the case where we are creating a file).
1572 * So, we start by writing down the count of the # of callbacks we've received
1573 * so far, and bumping a global counter of the # of callback granting calls
1574 * outstanding (all done under cm_callbackLock).
1576 * When we're back from the call, we look at all of the callback revokes with
1577 * counter numbers greater than the one we recorded in our caller's structure,
1578 * and replay those that are higher than when we started the call.
1580 * We free all the structures in the queue when the count of the # of outstanding
1581 * callback-granting calls drops to zero.
1583 * We call this function with the scp locked, too, but in its current implementation,
1584 * this knowledge is not used.
1586 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1588 lock_ObtainWrite(&cm_callbackLock);
1589 cbrp->callbackCount = cm_callbackCount;
1590 cm_activeCallbackGrantingCalls++;
1591 cbrp->startTime = time(NULL);
1592 cbrp->serverp = NULL;
1593 lock_ReleaseWrite(&cm_callbackLock);
1596 /* Called at the end of a callback-granting call, to remove the callback
1597 * info from the scache entry, if necessary.
1599 * Called with scp write locked, so we can discard the callbacks easily with
1600 * this locking hierarchy.
1602 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1603 AFSCallBack *cbp, long flags)
1605 cm_racingRevokes_t *revp; /* where we are */
1606 cm_racingRevokes_t *nrevp; /* where we'll be next */
1608 cm_server_t * serverp = NULL;
1609 int discardScp = 0, discardVolCB = 0;
1611 lock_ObtainWrite(&cm_callbackLock);
1612 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1613 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1614 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1617 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1618 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1620 if (cm_activeCallbackGrantingCalls == 0)
1625 /* record the callback; we'll clear it below if we really lose it */
1628 if (scp->cbServerp != cbrp->serverp) {
1629 serverp = scp->cbServerp;
1631 cm_GetServer(cbrp->serverp);
1632 scp->cbServerp = cbrp->serverp;
1635 serverp = cbrp->serverp;
1637 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1638 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1639 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1641 volp->cbExpiresRO = scp->cbExpires;
1647 serverp = cbrp->serverp;
1650 cbrp->serverp = NULL;
1653 /* a callback was actually revoked during our granting call, so
1654 * run down the list of revoked fids, looking for ours.
1655 * If activeCallbackGrantingCalls is zero, free the elements, too.
1657 * May need to go through entire list just to do the freeing.
1659 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1660 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1661 /* if this callback came in later than when we started the
1662 * callback-granting call, and if this fid is the right fid,
1663 * then clear the callback.
1665 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1666 && revp->callbackCount > cbrp->callbackCount
1667 && (( scp->fid.volume == revp->fid.volume &&
1668 scp->fid.vnode == revp->fid.vnode &&
1669 scp->fid.unique == revp->fid.unique)
1671 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1672 scp->fid.volume == revp->fid.volume)
1674 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1675 /* this one matches */
1677 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1679 cbrp->callbackCount, revp->callbackCount,
1682 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1683 (revp->flags & (CM_RACINGFLAG_CANCELVOL | CM_RACINGFLAG_CANCELALL))) {
1684 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1686 volp->cbExpiresRO = 0;
1695 /* if we freed the list, zap the pointer to it */
1697 cm_racingRevokesp = NULL;
1699 lock_ReleaseWrite(&cm_callbackLock);
1702 cm_DiscardSCache(scp);
1703 lock_ReleaseWrite(&scp->rw);
1704 cm_CallbackNotifyChange(scp);
1705 lock_ObtainWrite(&scp->rw);
1709 lock_ObtainWrite(&cm_serverLock);
1710 cm_FreeServer(serverp);
1711 lock_ReleaseWrite(&cm_serverLock);
1715 /* if flags is 1, we want to force the code to make one call, anyway.
1716 * called with locked scp; returns with same.
1718 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1719 struct cm_req *reqp, long flags)
1722 cm_conn_t *connp = NULL;
1723 AFSFetchStatus afsStatus;
1725 AFSCallBack callback;
1727 cm_callbackRequest_t cbr;
1730 struct rx_connection * rxconnp = NULL;
1731 int syncop_done = 0;
1733 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1734 scp, scp->fid.cell, scp->fid.volume, flags);
1736 #ifdef AFS_FREELANCE_CLIENT
1737 // The case where a callback is needed on /afs is handled
1738 // specially. We need to fetch the status by calling
1739 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1740 if (cm_freelanceEnabled) {
1741 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1742 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1743 scp->fid.unique==0x1 &&
1744 scp->fid.vnode==0x1) {
1746 // Start by indicating that we're in the process
1747 // of fetching the callback
1748 lock_ObtainMutex(&cm_Freelance_Lock);
1749 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1750 cm_fakeGettingCallback = 1;
1751 lock_ReleaseMutex(&cm_Freelance_Lock);
1753 // Fetch the status info
1754 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1756 // Indicate that the callback is not done
1757 lock_ObtainMutex(&cm_Freelance_Lock);
1758 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1759 cm_fakeDirCallback = 2;
1761 // Indicate that we're no longer fetching the callback
1762 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1763 cm_fakeGettingCallback = 0;
1764 lock_ReleaseMutex(&cm_Freelance_Lock);
1769 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1770 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1773 #endif /* AFS_FREELANCE_CLIENT */
1775 mustCall = (flags & 1);
1776 cm_AFSFidFromFid(&tfid, &scp->fid);
1778 if (!mustCall && cm_HaveCallback(scp))
1781 /* turn off mustCall, since it has now forced us past the check above */
1784 /* otherwise, we have to make an RPC to get the status */
1786 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1787 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1792 cm_StartCallbackGrantingCall(scp, &cbr);
1794 lock_ReleaseWrite(&scp->rw);
1796 /* now make the RPC */
1797 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1798 scp, sfid.volume, sfid.vnode, sfid.unique);
1800 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1804 rxconnp = cm_GetRxConn(connp);
1805 code = RXAFS_FetchStatus(rxconnp, &tfid,
1806 &afsStatus, &callback, &volSync);
1807 rx_PutConnection(rxconnp);
1809 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1811 code = cm_MapRPCError(code, reqp);
1813 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1814 code, scp, scp->fid.volume, scp->fid.vnode);
1816 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1817 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1819 lock_ObtainWrite(&scp->rw);
1821 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1822 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1824 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1827 /* if we got an error, return to caller */
1833 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1836 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1837 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1838 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1840 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1841 scp, scp->fid.cell, scp->fid.volume);
1848 /* called with cm_scacheLock held */
1849 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1851 cm_vol_state_t *statep;
1853 afs_uint32 volID = scp->fid.volume;
1854 cm_serverRef_t *tsrp;
1859 if (scp->cbServerp == NULL)
1862 volp = cm_GetVolumeByFID(&scp->fid);
1866 statep = cm_VolumeStateByID(volp, volID);
1868 if (statep->state == vl_online)
1871 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1872 if (tsrp->status == srv_deleted)
1874 if (tsrp->server == scp->cbServerp)
1876 if (tsrp->server->downTime > *downTime)
1877 *downTime = tsrp->server->downTime;
1880 /* if the cbServerp does not match the current volume server list
1881 * we report the callback server as up so the callback can be
1884 return(found ? 0 : 1);
1887 /* called periodically by cm_daemon to shut down use of expired callbacks */
1888 void cm_CheckCBExpiration(void)
1892 time_t now, downTime;
1894 osi_Log0(afsd_logp, "CheckCBExpiration");
1897 lock_ObtainWrite(&cm_scacheLock);
1898 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1899 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1901 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1902 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1904 if (volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1905 scp->cbExpires = volp->cbExpiresRO;
1909 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1910 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1912 cm_HoldSCacheNoLock(scp);
1913 lock_ReleaseWrite(&cm_scacheLock);
1915 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1916 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1917 lock_ObtainWrite(&scp->rw);
1918 cm_DiscardSCache(scp);
1919 lock_ReleaseWrite(&scp->rw);
1920 cm_CallbackNotifyChange(scp);
1922 lock_ObtainWrite(&cm_scacheLock);
1923 cm_ReleaseSCacheNoLock(scp);
1927 lock_ReleaseWrite(&cm_scacheLock);
1929 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1934 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1938 struct rx_connection * rxconnp;
1940 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1942 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1944 rxconnp = cm_GetRxConn(connp);
1945 rx_SetConnDeadTime(rxconnp, 10);
1946 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1947 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1948 rx_PutConnection(rxconnp);
1952 cm_server_vols_t * tsrvp;
1956 cm_ForceNewConnections(tsp);
1958 lock_ObtainMutex(&tsp->mx);
1959 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1960 tsp->flags |= CM_SERVERFLAG_DOWN;
1961 tsp->downTime = time(NULL);
1963 /* Now update the volume status */
1964 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
1965 for (i=0; i<NUM_SERVER_VOLS; i++) {
1966 if (tsrvp->ids[i] != 0) {
1970 lock_ReleaseMutex(&tsp->mx);
1971 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
1972 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
1973 lock_ObtainMutex(&tsp->mx);
1975 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
1981 lock_ReleaseMutex(&tsp->mx);
1987 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
1991 if (!cm_giveUpAllCBs)
1994 lock_ObtainWrite(&cm_serverLock);
1995 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
1996 cm_GetServerNoLock(tsp);
1997 lock_ReleaseWrite(&cm_serverLock);
1998 cm_GiveUpAllCallbacks(tsp, markDown);
1999 lock_ObtainWrite(&cm_serverLock);
2000 cm_PutServerNoLock(tsp);
2002 lock_ReleaseWrite(&cm_serverLock);