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);
364 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
368 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
371 cellp->name /* does not need to be saved, doesn't change */);
373 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
377 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
378 tfidp = &fidsArrayp->AFSCBFids_val[i];
380 if (tfidp->Volume == 0)
381 continue; /* means don't do anything */
382 else if (tfidp->Vnode == 0)
383 cm_RevokeVolumeCallback(callp, cellp, tfidp);
385 cm_RevokeCallback(callp, cellp, tfidp);
390 /*------------------------------------------------------------------------
391 * EXPORTED SRXAFSCB_InitCallBackState
394 * Routine called by the server-side callback RPC interface to
395 * implement clearing all callbacks from this host.
398 * rx_call : Ptr to Rx call on which this request came in.
404 * Nothing interesting.
408 *------------------------------------------------------------------------*/
409 /* called with no locks by RPC system when a server indicates that it has never
410 * heard from us, or for other reasons has had to discard callbacks from us
411 * without telling us, e.g. a network partition.
414 SRXAFSCB_InitCallBackState(struct rx_call *callp)
416 struct sockaddr_in taddr;
421 struct rx_connection *connp;
422 struct rx_peer *peerp;
423 unsigned long host = 0;
424 unsigned short port = 0;
429 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
430 host = rx_HostOf(peerp);
431 port = rx_PortOf(peerp);
434 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
438 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
439 taddr.sin_family = AF_INET;
440 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
442 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
444 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
446 /* record the callback in the racing revokes structure. This
447 * shouldn't be necessary, since we shouldn't be making callback
448 * granting calls while we're going to get an initstate call,
449 * but there probably are some obscure races, so better safe
452 * We do this first since we don't hold the cm_scacheLock and vnode
453 * locks over the entire callback scan operation below. The
454 * big loop below is guaranteed to hit any callback already
455 * processed. The call to RecordRacingRevoke is guaranteed
456 * to kill any callback that is currently being returned.
457 * Anything that sneaks past both must start
458 * after the call to RecordRacingRevoke.
460 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
462 /* now search all vnodes looking for guys with this callback, if we
463 * found it, or guys with any callbacks, if we didn't find the server
464 * (that's how multihomed machines will appear and how we'll handle
465 * them, albeit a little inefficiently). That is, we're discarding all
466 * callbacks from all hosts if we get an initstate call from an unknown
467 * host. Since these calls are rare, and multihomed servers
468 * are "rare," hopefully this won't be a problem.
470 lock_ObtainWrite(&cm_scacheLock);
471 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
472 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
473 cm_HoldSCacheNoLock(scp);
474 lock_ReleaseWrite(&cm_scacheLock);
475 lock_ObtainWrite(&scp->rw);
477 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
478 /* we have a callback, now decide if we should clear it */
479 if (scp->cbServerp == tsp || tsp == NULL) {
480 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%p vol %u vn %u uniq %u",
481 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
482 cm_DiscardSCache(scp);
486 lock_ReleaseWrite(&scp->rw);
488 cm_CallbackNotifyChange(scp);
489 lock_ObtainWrite(&cm_scacheLock);
490 cm_ReleaseSCacheNoLock(scp);
492 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO)) {
493 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
495 if (volp->cbExpiresRO != 0)
496 volp->cbExpiresRO = 0;
501 } /* search one hash bucket */
502 } /* search all hash buckets */
504 lock_ReleaseWrite(&cm_scacheLock);
507 /* reset the No flags on the server */
508 cm_SetServerNo64Bit(tsp, 0);
509 cm_SetServerNoInlineBulk(tsp, 0);
511 /* we're done with the server structure */
518 /*------------------------------------------------------------------------
519 * EXPORTED SRXAFSCB_Probe
522 * Routine called by the server-side callback RPC interface to
523 * implement ``probing'' the Cache Manager, just making sure it's
527 * rx_call : Ptr to Rx call on which this request came in.
533 * Nothing interesting.
537 *------------------------------------------------------------------------*/
539 SRXAFSCB_Probe(struct rx_call *callp)
541 struct rx_connection *connp;
542 struct rx_peer *peerp;
543 unsigned long host = 0;
544 unsigned short port = 0;
549 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
550 host = rx_HostOf(peerp);
551 port = rx_PortOf(peerp);
554 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
561 /*------------------------------------------------------------------------
562 * EXPORTED SRXAFSCB_GetLock
565 * Routine called by the server-side callback RPC interface to
566 * implement pulling out the contents of a lock in the lock
570 * a_call : Ptr to Rx call on which this request came in.
571 * a_index : Index of desired lock.
572 * a_result : Ptr to a buffer for the given lock.
575 * 0 if everything went fine,
576 * 1 if we were given a bad index.
579 * Nothing interesting.
583 *------------------------------------------------------------------------*/
584 /* debug interface */
586 extern osi_rwlock_t cm_aclLock;
587 extern osi_rwlock_t buf_globalLock;
588 extern osi_rwlock_t cm_cellLock;
589 extern osi_rwlock_t cm_connLock;
590 extern osi_rwlock_t cm_daemonLock;
591 extern osi_rwlock_t cm_dnlcLock;
592 extern osi_rwlock_t cm_scacheLock;
593 extern osi_rwlock_t cm_serverLock;
594 extern osi_rwlock_t cm_syscfgLock;
595 extern osi_rwlock_t cm_userLock;
596 extern osi_rwlock_t cm_utilsLock;
597 extern osi_rwlock_t cm_volumeLock;
598 extern osi_rwlock_t smb_globalLock;
599 extern osi_rwlock_t smb_rctLock;
601 extern osi_mutex_t cm_Freelance_Lock;
602 extern osi_mutex_t cm_Afsdsbmt_Lock;
603 extern osi_mutex_t tokenEventLock;
604 extern osi_mutex_t smb_ListenerLock;
605 extern osi_mutex_t smb_RawBufLock;
606 extern osi_mutex_t smb_Dir_Watch_Lock;
608 #define LOCKTYPE_RW 1
609 #define LOCKTYPE_MUTEX 2
610 static struct _ltable {
615 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
616 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
617 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
618 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
619 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
620 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
621 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
622 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
623 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
624 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
625 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
626 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
627 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
628 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
629 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
630 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
631 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
632 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
633 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
634 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
635 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
639 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
641 struct _ltable *tl; /*Ptr to lock table entry */
644 int nentries; /*Num entries in table */
645 int code; /*Return code */
646 struct rx_connection *connp;
647 struct rx_peer *peerp;
648 unsigned long host = 0;
649 unsigned short port = 0;
654 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
655 host = rx_HostOf(peerp);
656 port = rx_PortOf(peerp);
659 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
660 index, ntohl(host), ntohs(port));
662 nentries = sizeof(ltable) / sizeof(struct _ltable);
663 if (index < 0 || index >= nentries) {
670 * Found it - copy out its contents.
673 strncpy(lockp->name, tl->name, sizeof(lockp->name));
674 lockp->name[sizeof(lockp->name)-1] = '\0';
675 lockp->lock.waitStates = 0;
676 switch ( tl->type ) {
678 rwp = (osi_rwlock_t *)tl->addr;
679 lockp->lock.exclLocked = rwp->flags;
680 lockp->lock.readersReading = rwp->readers;
681 lockp->lock.numWaiting = rwp->waiters;
684 mtxp = (osi_mutex_t *)tl->addr;
685 lockp->lock.exclLocked = mtxp->flags;
686 lockp->lock.readersReading = 0;
687 lockp->lock.numWaiting = mtxp->waiters;
690 lockp->lock.pid_last_reader = 0;
691 lockp->lock.pid_writer = 0;
692 lockp->lock.src_indicator = 0;
699 /* debug interface */
701 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
706 struct rx_connection *connp;
707 struct rx_peer *peerp;
708 unsigned long host = 0;
709 unsigned short port = 0;
714 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
715 host = rx_HostOf(peerp);
716 port = rx_PortOf(peerp);
719 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
720 ntohl(host), ntohs(port));
722 lock_ObtainRead(&cm_scacheLock);
723 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
724 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
728 } /*Zip through current hash chain */
729 } /*Zip through hash chains */
739 * Copy out the located entry.
741 memset(cep, 0, sizeof(AFSDBCacheEntry));
742 cep->addr = afs_data_pointer_to_int32(scp);
743 cep->cell = scp->fid.cell;
744 cep->netFid.Volume = scp->fid.volume;
745 cep->netFid.Vnode = scp->fid.vnode;
746 cep->netFid.Unique = scp->fid.unique;
747 cep->lock.waitStates = 0;
748 cep->lock.exclLocked = scp->rw.flags;
749 cep->lock.readersReading = 0;
750 cep->lock.numWaiting = scp->rw.waiters;
751 cep->lock.pid_last_reader = 0;
752 cep->lock.pid_writer = 0;
753 cep->lock.src_indicator = 0;
754 cep->Length = scp->length.LowPart;
755 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
756 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
757 if (scp->flags & CM_SCACHEFLAG_PURERO) {
758 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
760 cep->cbExpires = volp->cbExpiresRO;
764 /* TODO: deal with time_t below */
765 cep->cbExpires = (afs_int32) scp->cbExpires;
767 cep->refCount = scp->refCount;
768 cep->opens = scp->openReads;
769 cep->writers = scp->openWrites;
770 switch (scp->fileType) {
771 case CM_SCACHETYPE_FILE:
774 case CM_SCACHETYPE_MOUNTPOINT:
777 case CM_SCACHETYPE_DIRECTORY:
778 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
783 case CM_SCACHETYPE_SYMLINK:
786 case CM_SCACHETYPE_DFSLINK:
789 case CM_SCACHETYPE_INVALID:
794 if (scp->flags & CM_SCACHEFLAG_STATD)
796 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
798 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
799 scp->mountPointStringp[0])
801 if (scp->flags & CM_SCACHEFLAG_WAITING)
806 * Return our results.
809 lock_ReleaseRead(&cm_scacheLock);
814 /* debug interface */
816 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
821 struct rx_connection *connp;
822 struct rx_peer *peerp;
823 unsigned long host = 0;
824 unsigned short port = 0;
829 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
830 host = rx_HostOf(peerp);
831 port = rx_PortOf(peerp);
834 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
835 ntohl(host), ntohs(port));
837 lock_ObtainRead(&cm_scacheLock);
838 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
839 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
843 } /*Zip through current hash chain */
844 } /*Zip through hash chains */
854 * Copy out the located entry.
856 memset(cep, 0, sizeof(AFSDBCacheEntry64));
857 cep->addr = afs_data_pointer_to_int32(scp);
858 cep->cell = scp->fid.cell;
859 cep->netFid.Volume = scp->fid.volume;
860 cep->netFid.Vnode = scp->fid.vnode;
861 cep->netFid.Unique = scp->fid.unique;
862 cep->lock.waitStates = 0;
863 cep->lock.exclLocked = scp->rw.flags;
864 cep->lock.readersReading = 0;
865 cep->lock.numWaiting = scp->rw.waiters;
866 cep->lock.pid_last_reader = 0;
867 cep->lock.pid_writer = 0;
868 cep->lock.src_indicator = 0;
869 #if !defined(AFS_64BIT_ENV)
870 cep->Length.high = scp->length.HighPart;
871 cep->Length.low = scp->length.LowPart;
873 cep->Length = (afs_int64) scp->length.QuadPart;
875 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
876 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
877 if (scp->flags & CM_SCACHEFLAG_PURERO) {
878 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
880 cep->cbExpires = volp->cbExpiresRO;
884 /* TODO: handle time_t */
885 cep->cbExpires = (afs_int32) scp->cbExpires;
887 cep->refCount = scp->refCount;
888 cep->opens = scp->openReads;
889 cep->writers = scp->openWrites;
890 switch (scp->fileType) {
891 case CM_SCACHETYPE_FILE:
894 case CM_SCACHETYPE_MOUNTPOINT:
897 case CM_SCACHETYPE_DIRECTORY:
898 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
903 case CM_SCACHETYPE_SYMLINK:
906 case CM_SCACHETYPE_DFSLINK:
909 case CM_SCACHETYPE_INVALID:
914 if (scp->flags & CM_SCACHEFLAG_STATD)
916 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
918 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
919 scp->mountPointStringp[0])
921 if (scp->flags & CM_SCACHEFLAG_WAITING)
926 * Return our results.
929 lock_ReleaseRead(&cm_scacheLock);
934 /* debug interface: not implemented */
936 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
938 struct rx_connection *connp;
939 struct rx_peer *peerp;
940 unsigned long host = 0;
941 unsigned short port = 0;
946 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
947 host = rx_HostOf(peerp);
948 port = rx_PortOf(peerp);
951 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
952 ntohl(host), ntohs(port));
958 /* debug interface: not implemented */
960 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
961 AFSCB_CollData *datap)
963 struct rx_connection *connp;
964 struct rx_peer *peerp;
965 unsigned long host = 0;
966 unsigned short port = 0;
971 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
972 host = rx_HostOf(peerp);
973 port = rx_PortOf(peerp);
976 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
977 ntohl(host), ntohs(port));
983 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
988 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
990 return SRXAFSCB_InitCallBackState(callp);
993 /* debug interface */
995 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
999 struct rx_connection *connp;
1000 struct rx_peer *peerp;
1001 unsigned long host = 0;
1002 unsigned short port = 0;
1007 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1008 host = rx_HostOf(peerp);
1009 port = rx_PortOf(peerp);
1012 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
1016 lock_ObtainRead(&cm_syscfgLock);
1017 if (cm_LanAdapterChangeDetected) {
1018 lock_ConvertRToW(&cm_syscfgLock);
1019 if (cm_LanAdapterChangeDetected) {
1020 /* get network related info */
1021 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1022 code = syscfg_GetIFInfo(&cm_noIPAddr,
1023 cm_IPAddr, cm_SubnetMask,
1024 cm_NetMtu, cm_NetFlags);
1025 cm_LanAdapterChangeDetected = 0;
1027 lock_ConvertWToR(&cm_syscfgLock);
1030 /* return all network interface addresses */
1031 addr->numberOfInterfaces = cm_noIPAddr;
1032 addr->uuid = cm_data.Uuid;
1033 for ( i=0; i < cm_noIPAddr; i++ ) {
1034 addr->addr_in[i] = cm_IPAddr[i];
1035 addr->subnetmask[i] = cm_SubnetMask[i];
1036 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1037 cm_NetMtu[i] : rx_mtu;
1040 lock_ReleaseRead(&cm_syscfgLock);
1046 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
1053 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
1054 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",osi_LogSaveString(afsd_logp,p));
1057 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1059 return SRXAFSCB_InitCallBackState(callp);
1062 /* debug interface */
1064 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1066 struct rx_connection *connp;
1067 struct rx_peer *peerp;
1068 unsigned long host = 0;
1069 unsigned short port = 0;
1076 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1077 host = rx_HostOf(peerp);
1078 port = rx_PortOf(peerp);
1081 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1082 UuidToString((UUID *)&cm_data.Uuid, &p);
1083 UuidToString((UUID *)clientUuid, &q);
1084 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1085 osi_LogSaveString(afsd_logp,p),
1086 osi_LogSaveString(afsd_logp,q),
1092 code = 1; /* failure */
1094 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1101 /* debug interface */
1103 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1107 cm_serverRef_t * serverRefp;
1109 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1111 *a_name = strdup("");
1115 lock_ObtainRead(&cm_serverLock);
1116 *a_name = strdup(cellp->name);
1118 for ( sn = 0, serverRefp = cellp->vlServersp;
1119 sn < AFSMAXCELLHOSTS && serverRefp;
1120 sn++, serverRefp = serverRefp->next);
1122 a_hosts->serverList_len = sn;
1123 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1125 for ( sn = 0, serverRefp = cellp->vlServersp;
1126 sn < AFSMAXCELLHOSTS && serverRefp;
1127 sn++, serverRefp = serverRefp->next)
1129 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1132 lock_ReleaseRead(&cm_serverLock);
1136 /* debug interface */
1138 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1139 char **a_name, serverList *a_hosts)
1141 struct rx_connection *connp;
1142 struct rx_peer *peerp;
1143 unsigned long host = 0;
1144 unsigned short port = 0;
1150 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1151 host = rx_HostOf(peerp);
1152 port = rx_PortOf(peerp);
1155 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1156 a_cellnum, ntohl(host), ntohs(port));
1158 a_hosts->serverList_val = 0;
1159 a_hosts->serverList_len = 0;
1162 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1167 /* debug interface */
1169 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1170 struct interfaceAddr *addr,
1171 Capabilities * capabilities)
1174 afs_int32 *dataBuffP;
1175 afs_int32 dataBytes;
1177 struct rx_connection *connp;
1178 struct rx_peer *peerp;
1179 unsigned long host = 0;
1180 unsigned short port = 0;
1185 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1186 host = rx_HostOf(peerp);
1187 port = rx_PortOf(peerp);
1190 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1194 lock_ObtainRead(&cm_syscfgLock);
1195 if (cm_LanAdapterChangeDetected) {
1196 lock_ConvertRToW(&cm_syscfgLock);
1197 if (cm_LanAdapterChangeDetected) {
1198 /* get network related info */
1199 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1200 code = syscfg_GetIFInfo(&cm_noIPAddr,
1201 cm_IPAddr, cm_SubnetMask,
1202 cm_NetMtu, cm_NetFlags);
1203 cm_LanAdapterChangeDetected = 0;
1205 lock_ConvertWToR(&cm_syscfgLock);
1208 /* return all network interface addresses */
1209 addr->numberOfInterfaces = cm_noIPAddr;
1210 addr->uuid = cm_data.Uuid;
1211 for ( i=0; i < cm_noIPAddr; i++ ) {
1212 addr->addr_in[i] = cm_IPAddr[i];
1213 addr->subnetmask[i] = cm_SubnetMask[i];
1214 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1215 cm_NetMtu[i] : rx_mtu;
1217 lock_ReleaseRead(&cm_syscfgLock);
1219 dataBytes = 1 * sizeof(afs_int32);
1220 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1221 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1222 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1223 capabilities->Capabilities_val = dataBuffP;
1228 /*------------------------------------------------------------------------
1229 * EXPORTED SRXAFSCB_GetServerPrefs
1232 * Routine to list server preferences used by this client.
1235 * a_call : Ptr to Rx call on which this request came in.
1236 * a_index : Input server index
1237 * a_srvr_addr : Output server address (0xffffffff on last server)
1238 * a_srvr_rank : Output server rank
1244 * Nothing interesting.
1248 *------------------------------------------------------------------------*/
1250 int SRXAFSCB_GetServerPrefs(
1251 struct rx_call *callp,
1253 afs_int32 *a_srvr_addr,
1254 afs_int32 *a_srvr_rank)
1256 struct rx_connection *connp;
1257 struct rx_peer *peerp;
1258 unsigned long host = 0;
1259 unsigned short port = 0;
1264 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1265 host = rx_HostOf(peerp);
1266 port = rx_PortOf(peerp);
1269 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1273 *a_srvr_addr = 0xffffffff;
1274 *a_srvr_rank = 0xffffffff;
1279 /*------------------------------------------------------------------------
1280 * EXPORTED SRXAFSCB_GetCellServDB
1283 * Routine to list cells configured for this client
1286 * a_call : Ptr to Rx call on which this request came in.
1287 * a_index : Input cell index
1288 * a_name : Output cell name ("" on last cell)
1289 * a_hosts : Output cell database servers
1295 * Nothing interesting.
1299 *------------------------------------------------------------------------*/
1301 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1302 serverList *a_hosts)
1304 struct rx_connection *connp;
1305 struct rx_peer *peerp;
1306 unsigned long host = 0;
1307 unsigned short port = 0;
1313 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1314 host = rx_HostOf(peerp);
1315 port = rx_PortOf(peerp);
1318 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1319 ntohl(host), ntohs(port));
1321 #ifdef AFS_FREELANCE_CLIENT
1322 if (cm_freelanceEnabled && index == 0) {
1323 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1327 rc = GetCellCommon(index+1, a_name, a_hosts);
1332 /*------------------------------------------------------------------------
1333 * EXPORTED SRXAFSCB_GetLocalCell
1336 * Routine to return name of client's local cell
1339 * a_call : Ptr to Rx call on which this request came in.
1340 * a_name : Output cell name
1346 * Nothing interesting.
1350 *------------------------------------------------------------------------*/
1352 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1355 struct rx_connection *connp;
1356 struct rx_peer *peerp;
1357 unsigned long host = 0;
1358 unsigned short port = 0;
1363 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1364 host = rx_HostOf(peerp);
1365 port = rx_PortOf(peerp);
1368 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1369 ntohl(host), ntohs(port));
1371 if (cm_data.rootCellp) {
1372 t_name = strdup(cm_data.rootCellp->name);
1374 t_name = (char *)malloc(1);
1384 * afs_MarshallCacheConfig - marshall client cache configuration
1388 * IN callerVersion - the rpc stat version of the caller.
1390 * IN config - client cache configuration.
1392 * OUT ptr - buffer where configuration is marshalled.
1398 static void afs_MarshallCacheConfig(
1399 afs_uint32 callerVersion,
1400 cm_initparams_v1 *config,
1404 * We currently only support version 1.
1406 *(ptr++) = config->nChunkFiles;
1407 *(ptr++) = config->nStatCaches;
1408 *(ptr++) = config->nDataCaches;
1409 *(ptr++) = config->nVolumeCaches;
1410 *(ptr++) = config->firstChunkSize;
1411 *(ptr++) = config->otherChunkSize;
1412 *(ptr++) = config->cacheSize;
1413 *(ptr++) = config->setTime;
1414 *(ptr++) = config->memCache;
1419 /*------------------------------------------------------------------------
1420 * EXPORTED SRXAFSCB_GetCacheConfig
1423 * Routine to return parameters used to initialize client cache.
1424 * Client may request any format version. Server may not return
1425 * format version greater than version requested by client.
1428 * a_call: Ptr to Rx call on which this request came in.
1429 * callerVersion: Data format version desired by the client.
1430 * serverVersion: Data format version of output data.
1431 * configCount: Number bytes allocated for output data.
1432 * config: Client cache configuration.
1438 * Nothing interesting.
1442 *------------------------------------------------------------------------*/
1444 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1445 afs_uint32 callerVersion,
1446 afs_uint32 *serverVersion,
1447 afs_uint32 *configCount,
1448 cacheConfig *config)
1450 afs_uint32 *t_config;
1452 extern cm_initparams_v1 cm_initParams;
1453 struct rx_connection *connp;
1454 struct rx_peer *peerp;
1455 unsigned long host = 0;
1456 unsigned short port = 0;
1461 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1462 host = rx_HostOf(peerp);
1463 port = rx_PortOf(peerp);
1466 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1467 ntohl(host), ntohs(port));
1470 * Currently only support version 1
1472 allocsize = sizeof(cm_initparams_v1);
1473 t_config = (afs_uint32 *)malloc(allocsize);
1475 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1477 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1480 #define SIZE_MAX UINT_MAX
1482 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1484 *configCount = (afs_uint32)allocsize;
1485 config->cacheConfig_val = t_config;
1486 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1491 /* called by afsd without any locks to initialize this module */
1492 void cm_InitCallback(void)
1494 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1495 cm_activeCallbackGrantingCalls = 0;
1498 /* called with locked scp; tells us whether we've got a callback.
1499 * Expirations are checked by a background daemon so as to make
1500 * this function as inexpensive as possible
1502 int cm_HaveCallback(cm_scache_t *scp)
1504 #ifdef AFS_FREELANCE_CLIENT
1505 // yj: we handle callbacks specially for callbacks on the root directory
1506 // Since it's local, we almost always say that we have callback on it
1507 // The only time we send back a 0 is if we're need to initialize or
1508 // reinitialize the fake directory
1510 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1511 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1512 // hence should return false. it's 0 otherwise
1513 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1514 // if the fake directory is loaded and this is the first time cm_HaveCallback
1515 // is called since then. We return false in this case to allow cm_GetCallback
1516 // to be called because cm_GetCallback has some initialization work to do.
1517 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1518 // good shape and we simply return true, provided no change is detected.
1521 if (cm_freelanceEnabled &&
1522 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1523 lock_ObtainMutex(&cm_Freelance_Lock);
1524 fdc = cm_fakeDirCallback;
1525 fgc = cm_fakeGettingCallback;
1526 lock_ReleaseMutex(&cm_Freelance_Lock);
1528 if (fdc==1) { // first call since init
1530 } else if (fdc==2 && !fgc) { // we're in good shape
1531 if (cm_getLocalMountPointChange()) { // check for changes
1532 cm_clearLocalMountPointChange(); // clear the changefile
1533 lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
1534 cm_reInitLocalMountPoints(); // start reinit
1535 lock_ObtainWrite(&scp->rw); // now get the lock back
1538 return 1; // no change
1544 if (scp->cbServerp != NULL) {
1546 } else if (cm_OfflineROIsValid) {
1547 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1549 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1565 /* need to detect a broken callback that races with our obtaining a callback.
1566 * Need to be able to do this even if we don't know the file ID of the file
1567 * we're breaking the callback on at the time we start the acquisition of the
1568 * callback (as in the case where we are creating a file).
1570 * So, we start by writing down the count of the # of callbacks we've received
1571 * so far, and bumping a global counter of the # of callback granting calls
1572 * outstanding (all done under cm_callbackLock).
1574 * When we're back from the call, we look at all of the callback revokes with
1575 * counter numbers greater than the one we recorded in our caller's structure,
1576 * and replay those that are higher than when we started the call.
1578 * We free all the structures in the queue when the count of the # of outstanding
1579 * callback-granting calls drops to zero.
1581 * We call this function with the scp locked, too, but in its current implementation,
1582 * this knowledge is not used.
1584 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1586 lock_ObtainWrite(&cm_callbackLock);
1587 cbrp->callbackCount = cm_callbackCount;
1588 cm_activeCallbackGrantingCalls++;
1589 cbrp->startTime = time(NULL);
1590 cbrp->serverp = NULL;
1591 lock_ReleaseWrite(&cm_callbackLock);
1594 /* Called at the end of a callback-granting call, to remove the callback
1595 * info from the scache entry, if necessary.
1597 * Called with scp write locked, so we can discard the callbacks easily with
1598 * this locking hierarchy.
1600 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1601 AFSCallBack *cbp, long flags)
1603 cm_racingRevokes_t *revp; /* where we are */
1604 cm_racingRevokes_t *nrevp; /* where we'll be next */
1606 cm_server_t * serverp = NULL;
1607 int discardScp = 0, discardVolCB = 0;
1609 lock_ObtainWrite(&cm_callbackLock);
1610 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1611 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1612 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1615 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1616 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1618 if (cm_activeCallbackGrantingCalls == 0)
1623 /* record the callback; we'll clear it below if we really lose it */
1626 if (scp->cbServerp != cbrp->serverp) {
1627 serverp = scp->cbServerp;
1629 cm_GetServer(cbrp->serverp);
1630 scp->cbServerp = cbrp->serverp;
1633 serverp = cbrp->serverp;
1635 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1636 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1637 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1639 volp->cbExpiresRO = scp->cbExpires;
1645 serverp = cbrp->serverp;
1648 cbrp->serverp = NULL;
1651 /* a callback was actually revoked during our granting call, so
1652 * run down the list of revoked fids, looking for ours.
1653 * If activeCallbackGrantingCalls is zero, free the elements, too.
1655 * May need to go through entire list just to do the freeing.
1657 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1658 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1659 /* if this callback came in later than when we started the
1660 * callback-granting call, and if this fid is the right fid,
1661 * then clear the callback.
1663 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1664 && revp->callbackCount > cbrp->callbackCount
1665 && (( scp->fid.volume == revp->fid.volume &&
1666 scp->fid.vnode == revp->fid.vnode &&
1667 scp->fid.unique == revp->fid.unique)
1669 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1670 scp->fid.volume == revp->fid.volume)
1672 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1673 /* this one matches */
1675 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1677 cbrp->callbackCount, revp->callbackCount,
1680 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1681 (revp->flags & (CM_RACINGFLAG_CANCELVOL | CM_RACINGFLAG_CANCELALL))) {
1682 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1684 volp->cbExpiresRO = 0;
1693 /* if we freed the list, zap the pointer to it */
1695 cm_racingRevokesp = NULL;
1697 lock_ReleaseWrite(&cm_callbackLock);
1700 cm_DiscardSCache(scp);
1701 lock_ReleaseWrite(&scp->rw);
1702 cm_CallbackNotifyChange(scp);
1703 lock_ObtainWrite(&scp->rw);
1707 lock_ObtainWrite(&cm_serverLock);
1708 cm_FreeServer(serverp);
1709 lock_ReleaseWrite(&cm_serverLock);
1713 /* if flags is 1, we want to force the code to make one call, anyway.
1714 * called with locked scp; returns with same.
1716 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1717 struct cm_req *reqp, long flags)
1720 cm_conn_t *connp = NULL;
1721 AFSFetchStatus afsStatus;
1723 AFSCallBack callback;
1725 cm_callbackRequest_t cbr;
1728 struct rx_connection * rxconnp = NULL;
1729 int syncop_done = 0;
1731 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1732 scp, scp->fid.cell, scp->fid.volume, flags);
1734 #ifdef AFS_FREELANCE_CLIENT
1735 // The case where a callback is needed on /afs is handled
1736 // specially. We need to fetch the status by calling
1737 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1738 if (cm_freelanceEnabled) {
1739 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1740 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1741 scp->fid.unique==0x1 &&
1742 scp->fid.vnode==0x1) {
1744 // Start by indicating that we're in the process
1745 // of fetching the callback
1746 lock_ObtainMutex(&cm_Freelance_Lock);
1747 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1748 cm_fakeGettingCallback = 1;
1749 lock_ReleaseMutex(&cm_Freelance_Lock);
1751 // Fetch the status info
1752 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1754 // Indicate that the callback is not done
1755 lock_ObtainMutex(&cm_Freelance_Lock);
1756 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1757 cm_fakeDirCallback = 2;
1759 // Indicate that we're no longer fetching the callback
1760 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1761 cm_fakeGettingCallback = 0;
1762 lock_ReleaseMutex(&cm_Freelance_Lock);
1767 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1768 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1771 #endif /* AFS_FREELANCE_CLIENT */
1773 mustCall = (flags & 1);
1774 cm_AFSFidFromFid(&tfid, &scp->fid);
1776 if (!mustCall && cm_HaveCallback(scp))
1779 /* turn off mustCall, since it has now forced us past the check above */
1782 /* otherwise, we have to make an RPC to get the status */
1784 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1785 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1790 cm_StartCallbackGrantingCall(scp, &cbr);
1792 lock_ReleaseWrite(&scp->rw);
1794 /* now make the RPC */
1795 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1796 scp, sfid.volume, sfid.vnode, sfid.unique);
1798 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1802 rxconnp = cm_GetRxConn(connp);
1803 code = RXAFS_FetchStatus(rxconnp, &tfid,
1804 &afsStatus, &callback, &volSync);
1805 rx_PutConnection(rxconnp);
1807 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1809 code = cm_MapRPCError(code, reqp);
1811 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1812 code, scp, scp->fid.volume, scp->fid.vnode);
1814 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1815 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1817 lock_ObtainWrite(&scp->rw);
1819 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1820 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1822 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1825 /* if we got an error, return to caller */
1831 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1834 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1835 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1836 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1838 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1839 scp, scp->fid.cell, scp->fid.volume);
1846 /* called with cm_scacheLock held */
1847 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1849 cm_vol_state_t *statep;
1851 afs_uint32 volID = scp->fid.volume;
1852 cm_serverRef_t *tsrp;
1857 if (scp->cbServerp == NULL)
1860 volp = cm_GetVolumeByFID(&scp->fid);
1864 statep = cm_VolumeStateByID(volp, volID);
1866 if (statep->state == vl_online)
1869 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1870 if (tsrp->server == scp->cbServerp)
1872 if (tsrp->server->downTime > *downTime)
1873 *downTime = tsrp->server->downTime;
1876 /* if the cbServerp does not match the current volume server list
1877 * we report the callback server as up so the callback can be
1880 return(found ? 0 : 1);
1883 /* called periodically by cm_daemon to shut down use of expired callbacks */
1884 void cm_CheckCBExpiration(void)
1888 time_t now, downTime;
1890 osi_Log0(afsd_logp, "CheckCBExpiration");
1893 lock_ObtainWrite(&cm_scacheLock);
1894 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1895 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1897 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1898 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1900 if (volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1901 scp->cbExpires = volp->cbExpiresRO;
1905 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1906 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1908 cm_HoldSCacheNoLock(scp);
1909 lock_ReleaseWrite(&cm_scacheLock);
1911 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1912 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1913 lock_ObtainWrite(&scp->rw);
1914 cm_DiscardSCache(scp);
1915 lock_ReleaseWrite(&scp->rw);
1916 cm_CallbackNotifyChange(scp);
1918 lock_ObtainWrite(&cm_scacheLock);
1919 cm_ReleaseSCacheNoLock(scp);
1923 lock_ReleaseWrite(&cm_scacheLock);
1925 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1930 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1934 struct rx_connection * rxconnp;
1936 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1938 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1940 rxconnp = cm_GetRxConn(connp);
1941 rx_SetConnDeadTime(rxconnp, 10);
1942 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1943 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1944 rx_PutConnection(rxconnp);
1948 cm_server_vols_t * tsrvp;
1952 cm_ForceNewConnections(tsp);
1954 lock_ObtainMutex(&tsp->mx);
1955 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1956 tsp->flags |= CM_SERVERFLAG_DOWN;
1957 tsp->downTime = time(NULL);
1959 /* Now update the volume status */
1960 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
1961 for (i=0; i<NUM_SERVER_VOLS; i++) {
1962 if (tsrvp->ids[i] != 0) {
1966 lock_ReleaseMutex(&tsp->mx);
1967 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
1968 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
1969 lock_ObtainMutex(&tsp->mx);
1971 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
1977 lock_ReleaseMutex(&tsp->mx);
1983 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
1987 if (!cm_giveUpAllCBs)
1990 lock_ObtainWrite(&cm_serverLock);
1991 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
1992 cm_GetServerNoLock(tsp);
1993 lock_ReleaseWrite(&cm_serverLock);
1994 cm_GiveUpAllCallbacks(tsp, markDown);
1995 lock_ObtainWrite(&cm_serverLock);
1996 cm_PutServerNoLock(tsp);
1998 lock_ReleaseWrite(&cm_serverLock);