2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
11 #include <afs/afs_args.h>
22 #include <rx_pthread.h>
24 #include <WINNT/syscfg.h>
25 #include <WINNT/afsreg.h>
26 #include <../afsrdr/kif.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 #ifdef AFS_FREELANCE_CLIENT
38 extern osi_mutex_t cm_Freelance_Lock;
41 /* count of # of callback breaking messages received by this CM so far. We use
42 * this count in determining whether there have been any callback breaks that
43 * apply to a call that returned a new callback. If the counter doesn't
44 * increase during a call, then we know that no callbacks were broken during
45 * that call, and thus that the callback that was just returned is still valid.
47 long cm_callbackCount;
49 /* count of number of RPCs potentially returning a callback executing now.
50 * When this counter hits zero, we can clear out the racing revokes list, since
51 * at that time, we know that none of the just-executed callback revokes will
52 * apply to any future call that returns a callback (since the latter hasn't
53 * even started execution yet).
55 long cm_activeCallbackGrantingCalls;
57 /* list of callbacks that have been broken recently. If a call returning a
58 * callback is executing and a callback revoke runs immediately after it at the
59 * server, the revoke may end up being processed before the response to the
60 * original callback granting call. We detect this by keeping a list of
61 * callback revokes that have been received since we *started* the callback
62 * granting call, and discarding any callbacks received for the same file ID,
63 * even if the callback revoke was received before the callback grant.
65 cm_racingRevokes_t *cm_racingRevokesp;
67 /* record a (potentially) racing revoke for this file ID; null means for all
68 * file IDs, and is used by InitCallBackState.
70 * The cancelFlags describe whether we're just discarding callbacks for the same
71 * file ID, the same volume, or all from the same server.
73 * Called with no locks held.
75 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
77 cm_racingRevokes_t *rp;
79 lock_ObtainWrite(&cm_callbackLock);
81 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
82 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
84 if (cm_activeCallbackGrantingCalls > 0) {
85 rp = malloc(sizeof(*rp));
86 memset(rp, 0, sizeof(*rp));
87 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
88 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
89 if (fidp) rp->fid = *fidp;
90 rp->callbackCount = ++cm_callbackCount;
92 lock_ReleaseWrite(&cm_callbackLock);
96 * When we lose a callback, may have to send change notification replies.
97 * Do not call with a lock on the scp.
99 void cm_CallbackNotifyChange(cm_scache_t *scp)
105 /* why does this have to query the registry each time? */
106 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
107 AFSREG_CLT_OPENAFS_SUBKEY,
109 KEY_READ|KEY_QUERY_VALUE,
110 &hKey) == ERROR_SUCCESS) {
112 dummyLen = sizeof(DWORD);
113 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
114 (BYTE *) &dwDelay, &dummyLen);
118 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
121 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
122 scp->fileType, scp->flags, dwDelay);
127 /* for directories, this sends a change notification on the dir itself */
128 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
129 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
131 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
132 scp, NULL, NULL, TRUE);
134 /* and for files, this sends a change notification on the file's parent dir */
138 cm_SetFid(&tfid, scp->fid.cell, scp->fid.volume, scp->parentVnode, scp->parentUnique);
139 dscp = cm_FindSCache(&tfid);
141 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
143 FILE_NOTIFY_GENERIC_FILE_FILTER,
144 dscp, NULL, NULL, TRUE);
146 cm_ReleaseSCache(dscp);
150 /* called with no locks held for every file ID that is revoked directly by
151 * a callback revoke call. Does not have to handle volume callback breaks,
152 * since those have already been split out.
154 * The callp parameter is currently unused.
156 void cm_RevokeCallback(struct rx_call *callp, cm_cell_t * cellp, AFSFid *fidp)
162 /* don't bother setting cell, since we won't be checking it (to aid
163 * in working with multi-homed servers: we don't know the cell if we
164 * don't recognize the IP address).
167 tfid.volume = fidp->Volume;
168 tfid.vnode = fidp->Vnode;
169 tfid.unique = fidp->Unique;
170 hash = CM_SCACHE_HASH(&tfid);
172 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
173 fidp->Volume, fidp->Vnode, fidp->Unique);
175 /* do this first, so that if we're executing a callback granting call
176 * at this moment, we kill it before it can be merged in. Otherwise,
177 * it could complete while we're doing the scan below, and get missed
178 * by both the scan and by this code.
180 cm_RecordRacingRevoke(&tfid, 0);
182 lock_ObtainWrite(&cm_scacheLock);
183 /* do all in the hash bucket, since we don't know how many we'll find with
186 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
187 if (scp->fid.volume == tfid.volume &&
188 scp->fid.vnode == tfid.vnode &&
189 scp->fid.unique == tfid.unique &&
190 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
191 scp->cbExpires > 0 &&
192 scp->cbServerp != NULL)
194 cm_HoldSCacheNoLock(scp);
195 lock_ReleaseWrite(&cm_scacheLock);
196 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
197 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
199 lock_ObtainWrite(&scp->rw);
200 cm_DiscardSCache(scp);
201 lock_ReleaseWrite(&scp->rw);
203 cm_CallbackNotifyChange(scp);
205 lock_ObtainWrite(&cm_scacheLock);
206 cm_ReleaseSCacheNoLock(scp);
209 lock_ReleaseWrite(&cm_scacheLock);
211 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
212 fidp->Volume, fidp->Vnode, fidp->Unique);
215 /* called to revoke a volume callback, which is typically issued when a volume
216 * is moved from one server to another.
218 * Called with no locks held.
220 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
226 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
228 /* do this first, so that if we're executing a callback granting call
229 * at this moment, we kill it before it can be merged in. Otherwise,
230 * it could complete while we're doing the scan below, and get missed
231 * by both the scan and by this code.
233 tfid.cell = tfid.vnode = tfid.unique = 0;
234 tfid.volume = fidp->Volume;
235 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
237 lock_ObtainWrite(&cm_scacheLock);
238 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
239 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
240 if (scp->fid.volume == fidp->Volume &&
241 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
242 scp->cbExpires > 0 &&
243 scp->cbServerp != NULL) {
244 cm_HoldSCacheNoLock(scp);
245 lock_ReleaseWrite(&cm_scacheLock);
247 lock_ObtainWrite(&scp->rw);
248 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
249 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
250 cm_DiscardSCache(scp);
251 lock_ReleaseWrite(&scp->rw);
253 cm_CallbackNotifyChange(scp);
254 lock_ObtainWrite(&cm_scacheLock);
255 cm_ReleaseSCacheNoLock(scp);
256 if (scp->flags & CM_SCACHEFLAG_PURERO) {
257 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
259 volp->cbExpiresRO = 0;
264 } /* search one hash bucket */
265 } /* search all hash buckets */
267 lock_ReleaseWrite(&cm_scacheLock);
269 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
273 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
274 * given data pointer, without triggering "cast truncates pointer"
275 * warnings. We use this where we explicitly don't care whether a
276 * pointer is truncated -- it loses information where a pointer is
277 * larger than an afs_int32.
281 afs_data_pointer_to_int32(const void *p)
284 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
288 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
293 /* used to determine the byte order of the system */
296 char c[sizeof(int) / sizeof(char)];
302 /* little-endian system */
305 /* big-endian system */
306 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
311 return ip.i32[i32_sub];
313 /*------------------------------------------------------------------------
314 * EXPORTED SRXAFSCB_CallBack
317 * Routine called by the server-side callback RPC interface to
318 * implement passing in callback information.
322 * rx_call : Ptr to Rx call on which this request came in.
323 * fidsArrayp : Ptr to array of fids involved.
324 * cbsArrayp : Ptr to matching callback info for the fids.
330 * Nothing interesting.
334 *------------------------------------------------------------------------*/
335 /* handle incoming RPC callback breaking message.
336 * Called with no locks held.
339 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
343 struct rx_connection *connp;
344 struct rx_peer *peerp;
345 unsigned long host = 0;
346 unsigned short port = 0;
347 cm_server_t *tsp = NULL;
348 cm_cell_t* cellp = NULL;
350 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
351 host = rx_HostOf(peerp);
352 port = rx_PortOf(peerp);
354 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
359 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
363 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
366 cellp->name /* does not need to be saved, doesn't change */);
368 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
372 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
373 tfidp = &fidsArrayp->AFSCBFids_val[i];
375 if (tfidp->Volume == 0)
376 continue; /* means don't do anything */
377 else if (tfidp->Vnode == 0)
378 cm_RevokeVolumeCallback(callp, cellp, tfidp);
380 cm_RevokeCallback(callp, cellp, tfidp);
385 /*------------------------------------------------------------------------
386 * EXPORTED SRXAFSCB_InitCallBackState
389 * Routine called by the server-side callback RPC interface to
390 * implement clearing all callbacks from this host.
393 * rx_call : Ptr to Rx call on which this request came in.
399 * Nothing interesting.
403 *------------------------------------------------------------------------*/
404 /* called with no locks by RPC system when a server indicates that it has never
405 * heard from us, or for other reasons has had to discard callbacks from us
406 * without telling us, e.g. a network partition.
409 SRXAFSCB_InitCallBackState(struct rx_call *callp)
411 struct sockaddr_in taddr;
416 struct rx_connection *connp;
417 struct rx_peer *peerp;
418 unsigned long host = 0;
419 unsigned short port = 0;
421 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
422 host = rx_HostOf(peerp);
423 port = rx_PortOf(peerp);
426 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
430 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
431 taddr.sin_family = AF_INET;
432 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
434 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
436 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
438 /* record the callback in the racing revokes structure. This
439 * shouldn't be necessary, since we shouldn't be making callback
440 * granting calls while we're going to get an initstate call,
441 * but there probably are some obscure races, so better safe
444 * We do this first since we don't hold the cm_scacheLock and vnode
445 * locks over the entire callback scan operation below. The
446 * big loop below is guaranteed to hit any callback already
447 * processed. The call to RecordRacingRevoke is guaranteed
448 * to kill any callback that is currently being returned.
449 * Anything that sneaks past both must start
450 * after the call to RecordRacingRevoke.
452 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
454 /* now search all vnodes looking for guys with this callback, if we
455 * found it, or guys with any callbacks, if we didn't find the server
456 * (that's how multihomed machines will appear and how we'll handle
457 * them, albeit a little inefficiently). That is, we're discarding all
458 * callbacks from all hosts if we get an initstate call from an unknown
459 * host. Since these calls are rare, and multihomed servers
460 * are "rare," hopefully this won't be a problem.
462 lock_ObtainWrite(&cm_scacheLock);
463 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
464 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
465 cm_HoldSCacheNoLock(scp);
466 lock_ReleaseWrite(&cm_scacheLock);
467 lock_ObtainWrite(&scp->rw);
469 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
470 /* we have a callback, now decide if we should clear it */
471 if (scp->cbServerp == tsp || tsp == NULL) {
472 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%p vol %u vn %u uniq %u",
473 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
474 cm_DiscardSCache(scp);
478 lock_ReleaseWrite(&scp->rw);
480 cm_CallbackNotifyChange(scp);
481 lock_ObtainWrite(&cm_scacheLock);
482 cm_ReleaseSCacheNoLock(scp);
484 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO)) {
485 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
487 if (volp->cbExpiresRO != 0)
488 volp->cbExpiresRO = 0;
493 } /* search one hash bucket */
494 } /* search all hash buckets */
496 lock_ReleaseWrite(&cm_scacheLock);
499 /* reset the No flags on the server */
500 cm_SetServerNo64Bit(tsp, 0);
501 cm_SetServerNoInlineBulk(tsp, 0);
503 /* we're done with the server structure */
510 /*------------------------------------------------------------------------
511 * EXPORTED SRXAFSCB_Probe
514 * Routine called by the server-side callback RPC interface to
515 * implement ``probing'' the Cache Manager, just making sure it's
519 * rx_call : Ptr to Rx call on which this request came in.
525 * Nothing interesting.
529 *------------------------------------------------------------------------*/
531 SRXAFSCB_Probe(struct rx_call *callp)
533 struct rx_connection *connp;
534 struct rx_peer *peerp;
535 unsigned long host = 0;
536 unsigned short port = 0;
538 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
539 host = rx_HostOf(peerp);
540 port = rx_PortOf(peerp);
543 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
550 /*------------------------------------------------------------------------
551 * EXPORTED SRXAFSCB_GetLock
554 * Routine called by the server-side callback RPC interface to
555 * implement pulling out the contents of a lock in the lock
559 * a_call : Ptr to Rx call on which this request came in.
560 * a_index : Index of desired lock.
561 * a_result : Ptr to a buffer for the given lock.
564 * 0 if everything went fine,
565 * 1 if we were given a bad index.
568 * Nothing interesting.
572 *------------------------------------------------------------------------*/
573 /* debug interface */
575 extern osi_rwlock_t cm_aclLock;
576 extern osi_rwlock_t buf_globalLock;
577 extern osi_rwlock_t cm_cellLock;
578 extern osi_rwlock_t cm_connLock;
579 extern osi_rwlock_t cm_daemonLock;
580 extern osi_rwlock_t cm_dnlcLock;
581 extern osi_rwlock_t cm_scacheLock;
582 extern osi_rwlock_t cm_serverLock;
583 extern osi_rwlock_t cm_syscfgLock;
584 extern osi_rwlock_t cm_userLock;
585 extern osi_rwlock_t cm_utilsLock;
586 extern osi_rwlock_t cm_volumeLock;
587 extern osi_rwlock_t smb_globalLock;
588 extern osi_rwlock_t smb_rctLock;
590 extern osi_mutex_t cm_Freelance_Lock;
591 extern osi_mutex_t cm_bufGetMutex;
592 extern osi_mutex_t cm_Afsdsbmt_Lock;
593 extern osi_mutex_t tokenEventLock;
594 extern osi_mutex_t smb_ListenerLock;
595 extern osi_mutex_t smb_RawBufLock;
596 extern osi_mutex_t smb_Dir_Watch_Lock;
598 #define LOCKTYPE_RW 1
599 #define LOCKTYPE_MUTEX 2
600 static struct _ltable {
605 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
606 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
607 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
608 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
609 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
610 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
611 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
612 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
613 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
614 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
615 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
616 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
617 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
618 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
619 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
620 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
621 {"cm_bufGetMutex", (char*)&cm_bufGetMutex, LOCKTYPE_MUTEX},
622 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
623 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
624 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
625 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
626 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
630 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
632 struct _ltable *tl; /*Ptr to lock table entry */
635 int nentries; /*Num entries in table */
636 int code; /*Return code */
637 struct rx_connection *connp;
638 struct rx_peer *peerp;
639 unsigned long host = 0;
640 unsigned short port = 0;
642 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
643 host = rx_HostOf(peerp);
644 port = rx_PortOf(peerp);
647 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
648 index, ntohl(host), ntohs(port));
650 nentries = sizeof(ltable) / sizeof(struct _ltable);
651 if (index < 0 || index >= nentries) {
658 * Found it - copy out its contents.
661 strncpy(lockp->name, tl->name, sizeof(lockp->name));
662 lockp->name[sizeof(lockp->name)-1] = '\0';
663 lockp->lock.waitStates = 0;
664 switch ( tl->type ) {
666 rwp = (osi_rwlock_t *)tl->addr;
667 lockp->lock.exclLocked = rwp->flags;
668 lockp->lock.readersReading = rwp->readers;
669 lockp->lock.numWaiting = rwp->waiters;
672 mtxp = (osi_mutex_t *)tl->addr;
673 lockp->lock.exclLocked = mtxp->flags;
674 lockp->lock.readersReading = 0;
675 lockp->lock.numWaiting = mtxp->waiters;
678 lockp->lock.pid_last_reader = 0;
679 lockp->lock.pid_writer = 0;
680 lockp->lock.src_indicator = 0;
687 /* debug interface */
689 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
694 struct rx_connection *connp;
695 struct rx_peer *peerp;
696 unsigned long host = 0;
697 unsigned short port = 0;
699 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
700 host = rx_HostOf(peerp);
701 port = rx_PortOf(peerp);
704 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
705 ntohl(host), ntohs(port));
707 lock_ObtainRead(&cm_scacheLock);
708 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
709 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
713 } /*Zip through current hash chain */
714 } /*Zip through hash chains */
724 * Copy out the located entry.
726 memset(cep, 0, sizeof(AFSDBCacheEntry));
727 cep->addr = afs_data_pointer_to_int32(scp);
728 cep->cell = scp->fid.cell;
729 cep->netFid.Volume = scp->fid.volume;
730 cep->netFid.Vnode = scp->fid.vnode;
731 cep->netFid.Unique = scp->fid.unique;
732 cep->lock.waitStates = 0;
733 cep->lock.exclLocked = scp->rw.flags;
734 cep->lock.readersReading = 0;
735 cep->lock.numWaiting = scp->rw.waiters;
736 cep->lock.pid_last_reader = 0;
737 cep->lock.pid_writer = 0;
738 cep->lock.src_indicator = 0;
739 cep->Length = scp->length.LowPart;
740 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
741 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
742 if (scp->flags & CM_SCACHEFLAG_PURERO) {
743 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
745 cep->cbExpires = volp->cbExpiresRO;
749 cep->cbExpires = scp->cbExpires;
750 cep->refCount = scp->refCount;
751 cep->opens = scp->openReads;
752 cep->writers = scp->openWrites;
753 switch (scp->fileType) {
754 case CM_SCACHETYPE_FILE:
757 case CM_SCACHETYPE_MOUNTPOINT:
760 case CM_SCACHETYPE_DIRECTORY:
761 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
766 case CM_SCACHETYPE_SYMLINK:
769 case CM_SCACHETYPE_DFSLINK:
772 case CM_SCACHETYPE_INVALID:
777 if (scp->flags & CM_SCACHEFLAG_STATD)
779 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
781 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
782 scp->mountPointStringp[0])
784 if (scp->flags & CM_SCACHEFLAG_WAITING)
789 * Return our results.
792 lock_ReleaseRead(&cm_scacheLock);
797 /* debug interface */
799 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
804 struct rx_connection *connp;
805 struct rx_peer *peerp;
806 unsigned long host = 0;
807 unsigned short port = 0;
809 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
810 host = rx_HostOf(peerp);
811 port = rx_PortOf(peerp);
814 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
815 ntohl(host), ntohs(port));
817 lock_ObtainRead(&cm_scacheLock);
818 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
819 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
823 } /*Zip through current hash chain */
824 } /*Zip through hash chains */
834 * Copy out the located entry.
836 memset(cep, 0, sizeof(AFSDBCacheEntry64));
837 cep->addr = afs_data_pointer_to_int32(scp);
838 cep->cell = scp->fid.cell;
839 cep->netFid.Volume = scp->fid.volume;
840 cep->netFid.Vnode = scp->fid.vnode;
841 cep->netFid.Unique = scp->fid.unique;
842 cep->lock.waitStates = 0;
843 cep->lock.exclLocked = scp->rw.flags;
844 cep->lock.readersReading = 0;
845 cep->lock.numWaiting = scp->rw.waiters;
846 cep->lock.pid_last_reader = 0;
847 cep->lock.pid_writer = 0;
848 cep->lock.src_indicator = 0;
849 #if !defined(AFS_64BIT_ENV)
850 cep->Length.high = scp->length.HighPart;
851 cep->Length.low = scp->length.LowPart;
853 cep->Length = (afs_int64) scp->length.QuadPart;
855 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
856 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
857 if (scp->flags & CM_SCACHEFLAG_PURERO) {
858 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
860 cep->cbExpires = volp->cbExpiresRO;
864 cep->cbExpires = scp->cbExpires;
865 cep->refCount = scp->refCount;
866 cep->opens = scp->openReads;
867 cep->writers = scp->openWrites;
868 switch (scp->fileType) {
869 case CM_SCACHETYPE_FILE:
872 case CM_SCACHETYPE_MOUNTPOINT:
875 case CM_SCACHETYPE_DIRECTORY:
876 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
881 case CM_SCACHETYPE_SYMLINK:
884 case CM_SCACHETYPE_DFSLINK:
887 case CM_SCACHETYPE_INVALID:
892 if (scp->flags & CM_SCACHEFLAG_STATD)
894 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
896 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
897 scp->mountPointStringp[0])
899 if (scp->flags & CM_SCACHEFLAG_WAITING)
904 * Return our results.
907 lock_ReleaseRead(&cm_scacheLock);
912 /* debug interface: not implemented */
914 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
916 struct rx_connection *connp;
917 struct rx_peer *peerp;
918 unsigned long host = 0;
919 unsigned short port = 0;
921 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
922 host = rx_HostOf(peerp);
923 port = rx_PortOf(peerp);
926 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
927 ntohl(host), ntohs(port));
933 /* debug interface: not implemented */
935 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
936 AFSCB_CollData *datap)
938 struct rx_connection *connp;
939 struct rx_peer *peerp;
940 unsigned long host = 0;
941 unsigned short port = 0;
943 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
944 host = rx_HostOf(peerp);
945 port = rx_PortOf(peerp);
948 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
949 ntohl(host), ntohs(port));
955 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
957 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
959 return SRXAFSCB_InitCallBackState(callp);
962 /* debug interface */
964 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
968 struct rx_connection *connp;
969 struct rx_peer *peerp;
970 unsigned long host = 0;
971 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_WhoAreYou from host 0x%x port %d",
982 lock_ObtainRead(&cm_syscfgLock);
983 if (cm_LanAdapterChangeDetected) {
984 lock_ConvertRToW(&cm_syscfgLock);
985 if (cm_LanAdapterChangeDetected) {
986 /* get network related info */
987 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
988 code = syscfg_GetIFInfo(&cm_noIPAddr,
989 cm_IPAddr, cm_SubnetMask,
990 cm_NetMtu, cm_NetFlags);
991 cm_LanAdapterChangeDetected = 0;
993 lock_ConvertWToR(&cm_syscfgLock);
996 /* return all network interface addresses */
997 addr->numberOfInterfaces = cm_noIPAddr;
998 addr->uuid = cm_data.Uuid;
999 for ( i=0; i < cm_noIPAddr; i++ ) {
1000 addr->addr_in[i] = cm_IPAddr[i];
1001 addr->subnetmask[i] = cm_SubnetMask[i];
1002 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1003 cm_NetMtu[i] : rx_mtu;
1006 lock_ReleaseRead(&cm_syscfgLock);
1012 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
1016 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
1017 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",osi_LogSaveString(afsd_logp,p));
1020 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1022 return SRXAFSCB_InitCallBackState(callp);
1025 /* debug interface */
1027 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1029 struct rx_connection *connp;
1030 struct rx_peer *peerp;
1031 unsigned long host = 0;
1032 unsigned short port = 0;
1036 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1037 host = rx_HostOf(peerp);
1038 port = rx_PortOf(peerp);
1041 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1042 UuidToString((UUID *)&cm_data.Uuid, &p);
1043 UuidToString((UUID *)clientUuid, &q);
1044 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1045 osi_LogSaveString(afsd_logp,p),
1046 osi_LogSaveString(afsd_logp,q),
1052 code = 1; /* failure */
1054 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1061 /* debug interface */
1063 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1067 cm_serverRef_t * serverRefp;
1069 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1071 *a_name = strdup("");
1075 lock_ObtainRead(&cm_serverLock);
1076 *a_name = strdup(cellp->name);
1078 for ( sn = 0, serverRefp = cellp->vlServersp;
1079 sn < AFSMAXCELLHOSTS && serverRefp;
1080 sn++, serverRefp = serverRefp->next);
1082 a_hosts->serverList_len = sn;
1083 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1085 for ( sn = 0, serverRefp = cellp->vlServersp;
1086 sn < AFSMAXCELLHOSTS && serverRefp;
1087 sn++, serverRefp = serverRefp->next)
1089 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1092 lock_ReleaseRead(&cm_serverLock);
1096 /* debug interface */
1098 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1099 char **a_name, serverList *a_hosts)
1101 struct rx_connection *connp;
1102 struct rx_peer *peerp;
1103 unsigned long host = 0;
1104 unsigned short port = 0;
1107 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1108 host = rx_HostOf(peerp);
1109 port = rx_PortOf(peerp);
1112 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1113 a_cellnum, ntohl(host), ntohs(port));
1115 a_hosts->serverList_val = 0;
1116 a_hosts->serverList_len = 0;
1119 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1124 /* debug interface */
1126 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1127 struct interfaceAddr *addr,
1128 Capabilities * capabilities)
1131 afs_int32 *dataBuffP;
1132 afs_int32 dataBytes;
1134 struct rx_connection *connp;
1135 struct rx_peer *peerp;
1136 unsigned long host = 0;
1137 unsigned short port = 0;
1139 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1140 host = rx_HostOf(peerp);
1141 port = rx_PortOf(peerp);
1144 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1148 lock_ObtainRead(&cm_syscfgLock);
1149 if (cm_LanAdapterChangeDetected) {
1150 lock_ConvertRToW(&cm_syscfgLock);
1151 if (cm_LanAdapterChangeDetected) {
1152 /* get network related info */
1153 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1154 code = syscfg_GetIFInfo(&cm_noIPAddr,
1155 cm_IPAddr, cm_SubnetMask,
1156 cm_NetMtu, cm_NetFlags);
1157 cm_LanAdapterChangeDetected = 0;
1159 lock_ConvertWToR(&cm_syscfgLock);
1162 /* return all network interface addresses */
1163 addr->numberOfInterfaces = cm_noIPAddr;
1164 addr->uuid = cm_data.Uuid;
1165 for ( i=0; i < cm_noIPAddr; i++ ) {
1166 addr->addr_in[i] = cm_IPAddr[i];
1167 addr->subnetmask[i] = cm_SubnetMask[i];
1168 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1169 cm_NetMtu[i] : rx_mtu;
1171 lock_ReleaseRead(&cm_syscfgLock);
1173 dataBytes = 1 * sizeof(afs_int32);
1174 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1175 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1176 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1177 capabilities->Capabilities_val = dataBuffP;
1182 /*------------------------------------------------------------------------
1183 * EXPORTED SRXAFSCB_GetServerPrefs
1186 * Routine to list server preferences used by this client.
1189 * a_call : Ptr to Rx call on which this request came in.
1190 * a_index : Input server index
1191 * a_srvr_addr : Output server address (0xffffffff on last server)
1192 * a_srvr_rank : Output server rank
1198 * Nothing interesting.
1202 *------------------------------------------------------------------------*/
1204 int SRXAFSCB_GetServerPrefs(
1205 struct rx_call *callp,
1207 afs_int32 *a_srvr_addr,
1208 afs_int32 *a_srvr_rank)
1210 struct rx_connection *connp;
1211 struct rx_peer *peerp;
1212 unsigned long host = 0;
1213 unsigned short port = 0;
1215 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1216 host = rx_HostOf(peerp);
1217 port = rx_PortOf(peerp);
1220 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1224 *a_srvr_addr = 0xffffffff;
1225 *a_srvr_rank = 0xffffffff;
1230 /*------------------------------------------------------------------------
1231 * EXPORTED SRXAFSCB_GetCellServDB
1234 * Routine to list cells configured for this client
1237 * a_call : Ptr to Rx call on which this request came in.
1238 * a_index : Input cell index
1239 * a_name : Output cell name ("" on last cell)
1240 * a_hosts : Output cell database servers
1246 * Nothing interesting.
1250 *------------------------------------------------------------------------*/
1252 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1253 serverList *a_hosts)
1255 struct rx_connection *connp;
1256 struct rx_peer *peerp;
1257 unsigned long host = 0;
1258 unsigned short port = 0;
1261 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1262 host = rx_HostOf(peerp);
1263 port = rx_PortOf(peerp);
1266 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1267 ntohl(host), ntohs(port));
1269 #ifdef AFS_FREELANCE_CLIENT
1270 if (cm_freelanceEnabled && index == 0) {
1271 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1275 rc = GetCellCommon(index+1, a_name, a_hosts);
1280 /*------------------------------------------------------------------------
1281 * EXPORTED SRXAFSCB_GetLocalCell
1284 * Routine to return name of client's local cell
1287 * a_call : Ptr to Rx call on which this request came in.
1288 * a_name : Output cell name
1294 * Nothing interesting.
1298 *------------------------------------------------------------------------*/
1300 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1303 struct rx_connection *connp;
1304 struct rx_peer *peerp;
1305 unsigned long host = 0;
1306 unsigned short port = 0;
1308 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1309 host = rx_HostOf(peerp);
1310 port = rx_PortOf(peerp);
1313 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1314 ntohl(host), ntohs(port));
1316 if (cm_data.rootCellp) {
1317 t_name = (char *)malloc(strlen(cm_data.rootCellp->name)+1);
1318 strcpy(t_name, cm_data.rootCellp->name);
1320 t_name = (char *)malloc(1);
1330 * afs_MarshallCacheConfig - marshall client cache configuration
1334 * IN callerVersion - the rpc stat version of the caller.
1336 * IN config - client cache configuration.
1338 * OUT ptr - buffer where configuration is marshalled.
1344 static void afs_MarshallCacheConfig(
1345 afs_uint32 callerVersion,
1346 cm_initparams_v1 *config,
1350 * We currently only support version 1.
1352 *(ptr++) = config->nChunkFiles;
1353 *(ptr++) = config->nStatCaches;
1354 *(ptr++) = config->nDataCaches;
1355 *(ptr++) = config->nVolumeCaches;
1356 *(ptr++) = config->firstChunkSize;
1357 *(ptr++) = config->otherChunkSize;
1358 *(ptr++) = config->cacheSize;
1359 *(ptr++) = config->setTime;
1360 *(ptr++) = config->memCache;
1365 /*------------------------------------------------------------------------
1366 * EXPORTED SRXAFSCB_GetCacheConfig
1369 * Routine to return parameters used to initialize client cache.
1370 * Client may request any format version. Server may not return
1371 * format version greater than version requested by client.
1374 * a_call: Ptr to Rx call on which this request came in.
1375 * callerVersion: Data format version desired by the client.
1376 * serverVersion: Data format version of output data.
1377 * configCount: Number bytes allocated for output data.
1378 * config: Client cache configuration.
1384 * Nothing interesting.
1388 *------------------------------------------------------------------------*/
1390 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1391 afs_uint32 callerVersion,
1392 afs_uint32 *serverVersion,
1393 afs_uint32 *configCount,
1394 cacheConfig *config)
1396 afs_uint32 *t_config;
1398 extern cm_initparams_v1 cm_initParams;
1399 struct rx_connection *connp;
1400 struct rx_peer *peerp;
1401 unsigned long host = 0;
1402 unsigned short port = 0;
1404 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1405 host = rx_HostOf(peerp);
1406 port = rx_PortOf(peerp);
1409 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1410 ntohl(host), ntohs(port));
1413 * Currently only support version 1
1415 allocsize = sizeof(cm_initparams_v1);
1416 t_config = (afs_uint32 *)malloc(allocsize);
1418 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1420 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1423 #define SIZE_MAX UINT_MAX
1425 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1427 *configCount = (afs_uint32)allocsize;
1428 config->cacheConfig_val = t_config;
1429 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1434 /* called by afsd without any locks to initialize this module */
1435 void cm_InitCallback(void)
1437 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
1438 cm_activeCallbackGrantingCalls = 0;
1441 /* called with locked scp; tells us whether we've got a callback.
1442 * Expirations are checked by a background daemon so as to make
1443 * this function as inexpensive as possible
1445 int cm_HaveCallback(cm_scache_t *scp)
1447 #ifdef AFS_FREELANCE_CLIENT
1448 // yj: we handle callbacks specially for callbacks on the root directory
1449 // Since it's local, we almost always say that we have callback on it
1450 // The only time we send back a 0 is if we're need to initialize or
1451 // reinitialize the fake directory
1453 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1454 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1455 // hence should return false. it's 0 otherwise
1456 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1457 // if the fake directory is loaded and this is the first time cm_HaveCallback
1458 // is called since then. We return false in this case to allow cm_GetCallback
1459 // to be called because cm_GetCallback has some initialization work to do.
1460 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1461 // good shape and we simply return true, provided no change is detected.
1464 if (cm_freelanceEnabled &&
1465 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1466 /* if it's something on /afs */
1467 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
1468 /* if it's not root.afs */
1472 lock_ObtainMutex(&cm_Freelance_Lock);
1473 fdc = cm_fakeDirCallback;
1474 fgc = cm_fakeGettingCallback;
1475 lock_ReleaseMutex(&cm_Freelance_Lock);
1477 if (fdc==1) { // first call since init
1479 } else if (fdc==2 && !fgc) { // we're in good shape
1480 if (cm_getLocalMountPointChange()) { // check for changes
1481 cm_clearLocalMountPointChange(); // clear the changefile
1482 lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
1483 cm_reInitLocalMountPoints(); // start reinit
1484 lock_ObtainWrite(&scp->rw); // now get the lock back
1487 return 1; // no change
1493 if (scp->cbServerp != NULL) {
1495 } else if (cm_OfflineROIsValid) {
1496 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1498 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1514 /* need to detect a broken callback that races with our obtaining a callback.
1515 * Need to be able to do this even if we don't know the file ID of the file
1516 * we're breaking the callback on at the time we start the acquisition of the
1517 * callback (as in the case where we are creating a file).
1519 * So, we start by writing down the count of the # of callbacks we've received
1520 * so far, and bumping a global counter of the # of callback granting calls
1521 * outstanding (all done under cm_callbackLock).
1523 * When we're back from the call, we look at all of the callback revokes with
1524 * counter numbers greater than the one we recorded in our caller's structure,
1525 * and replay those that are higher than when we started the call.
1527 * We free all the structures in the queue when the count of the # of outstanding
1528 * callback-granting calls drops to zero.
1530 * We call this function with the scp locked, too, but in its current implementation,
1531 * this knowledge is not used.
1533 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1535 lock_ObtainWrite(&cm_callbackLock);
1536 cbrp->callbackCount = cm_callbackCount;
1537 cm_activeCallbackGrantingCalls++;
1538 cbrp->startTime = time(NULL);
1539 cbrp->serverp = NULL;
1540 lock_ReleaseWrite(&cm_callbackLock);
1543 /* Called at the end of a callback-granting call, to remove the callback
1544 * info from the scache entry, if necessary.
1546 * Called with scp write locked, so we can discard the callbacks easily with
1547 * this locking hierarchy.
1549 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1550 AFSCallBack *cbp, long flags)
1552 cm_racingRevokes_t *revp; /* where we are */
1553 cm_racingRevokes_t *nrevp; /* where we'll be next */
1555 cm_server_t * serverp = NULL;
1556 int discardScp = 0, discardVolCB = 0;
1558 lock_ObtainWrite(&cm_callbackLock);
1559 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1560 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1561 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1564 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1565 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1567 if (cm_activeCallbackGrantingCalls == 0)
1572 /* record the callback; we'll clear it below if we really lose it */
1575 if (scp->cbServerp != cbrp->serverp) {
1576 serverp = scp->cbServerp;
1578 cm_GetServer(cbrp->serverp);
1579 scp->cbServerp = cbrp->serverp;
1582 serverp = cbrp->serverp;
1584 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1585 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1586 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1588 volp->cbExpiresRO = scp->cbExpires;
1594 serverp = cbrp->serverp;
1597 cbrp->serverp = NULL;
1600 /* a callback was actually revoked during our granting call, so
1601 * run down the list of revoked fids, looking for ours.
1602 * If activeCallbackGrantingCalls is zero, free the elements, too.
1604 * May need to go through entire list just to do the freeing.
1606 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1607 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1608 /* if this callback came in later than when we started the
1609 * callback-granting call, and if this fid is the right fid,
1610 * then clear the callback.
1612 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1613 && revp->callbackCount > cbrp->callbackCount
1614 && (( scp->fid.volume == revp->fid.volume &&
1615 scp->fid.vnode == revp->fid.vnode &&
1616 scp->fid.unique == revp->fid.unique)
1618 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1619 scp->fid.volume == revp->fid.volume)
1621 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1622 /* this one matches */
1624 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1626 cbrp->callbackCount, revp->callbackCount,
1629 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1630 (revp->flags & (CM_RACINGFLAG_CANCELVOL | CM_RACINGFLAG_CANCELALL))) {
1631 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1633 volp->cbExpiresRO = 0;
1642 /* if we freed the list, zap the pointer to it */
1644 cm_racingRevokesp = NULL;
1646 lock_ReleaseWrite(&cm_callbackLock);
1649 cm_DiscardSCache(scp);
1650 lock_ReleaseWrite(&scp->rw);
1651 cm_CallbackNotifyChange(scp);
1652 lock_ObtainWrite(&scp->rw);
1656 lock_ObtainWrite(&cm_serverLock);
1657 cm_FreeServer(serverp);
1658 lock_ReleaseWrite(&cm_serverLock);
1662 /* if flags is 1, we want to force the code to make one call, anyway.
1663 * called with locked scp; returns with same.
1665 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1666 struct cm_req *reqp, long flags)
1669 cm_conn_t *connp = NULL;
1670 AFSFetchStatus afsStatus;
1672 AFSCallBack callback;
1674 cm_callbackRequest_t cbr;
1677 struct rx_connection * callp = NULL;
1678 int syncop_done = 0;
1680 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1681 scp, scp->fid.cell, scp->fid.volume, flags);
1683 #ifdef AFS_FREELANCE_CLIENT
1684 // The case where a callback is needed on /afs is handled
1685 // specially. We need to fetch the status by calling
1686 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1687 if (cm_freelanceEnabled) {
1688 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1689 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1690 scp->fid.unique==0x1 &&
1691 scp->fid.vnode==0x1) {
1693 // Start by indicating that we're in the process
1694 // of fetching the callback
1695 lock_ObtainMutex(&cm_Freelance_Lock);
1696 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1697 cm_fakeGettingCallback = 1;
1698 lock_ReleaseMutex(&cm_Freelance_Lock);
1700 // Fetch the status info
1701 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1703 // Indicate that the callback is not done
1704 lock_ObtainMutex(&cm_Freelance_Lock);
1705 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1706 cm_fakeDirCallback = 2;
1708 // Indicate that we're no longer fetching the callback
1709 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1710 cm_fakeGettingCallback = 0;
1711 lock_ReleaseMutex(&cm_Freelance_Lock);
1716 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1717 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1720 #endif /* AFS_FREELANCE_CLIENT */
1722 mustCall = (flags & 1);
1723 cm_AFSFidFromFid(&tfid, &scp->fid);
1725 if (!mustCall && cm_HaveCallback(scp))
1728 /* turn off mustCall, since it has now forced us past the check above */
1731 /* otherwise, we have to make an RPC to get the status */
1733 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1734 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1739 cm_StartCallbackGrantingCall(scp, &cbr);
1741 lock_ReleaseWrite(&scp->rw);
1743 /* now make the RPC */
1744 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1745 scp, sfid.volume, sfid.vnode, sfid.unique);
1747 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1751 callp = cm_GetRxConn(connp);
1752 code = RXAFS_FetchStatus(callp, &tfid,
1753 &afsStatus, &callback, &volSync);
1754 rx_PutConnection(callp);
1756 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1758 code = cm_MapRPCError(code, reqp);
1760 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1761 code, scp, scp->fid.volume, scp->fid.vnode);
1763 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1764 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1766 lock_ObtainWrite(&scp->rw);
1768 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1769 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1771 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1774 /* if we got an error, return to caller */
1780 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1783 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1784 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1785 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1787 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1788 scp, scp->fid.cell, scp->fid.volume);
1795 /* called with cm_scacheLock held */
1796 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1798 cm_vol_state_t *statep;
1800 afs_uint32 volID = scp->fid.volume;
1801 cm_serverRef_t *tsrp;
1806 if (scp->cbServerp == NULL)
1809 volp = cm_GetVolumeByFID(&scp->fid);
1813 if (volp->rw.ID == volID) {
1815 } else if (volp->ro.ID == volID) {
1817 } else if (volp->bk.ID == volID) {
1821 if (statep->state == vl_online)
1824 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1825 if (tsrp->server == scp->cbServerp)
1827 if (tsrp->server->downTime > *downTime)
1828 *downTime = tsrp->server->downTime;
1831 /* if the cbServerp does not match the current volume server list
1832 * we report the callback server as up so the callback can be
1835 return(found ? 0 : 1);
1838 /* called periodically by cm_daemon to shut down use of expired callbacks */
1839 void cm_CheckCBExpiration(void)
1843 time_t now, downTime;
1845 osi_Log0(afsd_logp, "CheckCBExpiration");
1848 lock_ObtainWrite(&cm_scacheLock);
1849 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1850 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1852 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1853 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1855 if (volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1856 scp->cbExpires = volp->cbExpiresRO;
1860 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1861 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1863 cm_HoldSCacheNoLock(scp);
1864 lock_ReleaseWrite(&cm_scacheLock);
1866 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1867 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1868 lock_ObtainWrite(&scp->rw);
1869 cm_DiscardSCache(scp);
1870 lock_ReleaseWrite(&scp->rw);
1871 cm_CallbackNotifyChange(scp);
1873 lock_ObtainWrite(&cm_scacheLock);
1874 cm_ReleaseSCacheNoLock(scp);
1878 lock_ReleaseWrite(&cm_scacheLock);
1880 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1885 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1889 struct rx_connection * rxconnp;
1891 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1893 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1895 rxconnp = cm_GetRxConn(connp);
1896 rx_SetConnDeadTime(rxconnp, 10);
1897 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1898 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1899 rx_PutConnection(rxconnp);
1903 cm_server_vols_t * tsrvp;
1907 lock_ObtainMutex(&tsp->mx);
1908 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1909 tsp->flags |= CM_SERVERFLAG_DOWN;
1910 tsp->downTime = time(NULL);
1912 cm_ForceNewConnections(tsp);
1914 /* Now update the volume status */
1915 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
1916 for (i=0; i<NUM_SERVER_VOLS; i++) {
1917 if (tsrvp->ids[i] != 0) {
1922 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
1923 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
1925 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
1931 lock_ReleaseMutex(&tsp->mx);
1937 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
1941 if (!cm_giveUpAllCBs)
1944 lock_ObtainWrite(&cm_serverLock);
1945 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
1946 cm_GetServerNoLock(tsp);
1947 lock_ReleaseWrite(&cm_serverLock);
1948 cm_GiveUpAllCallbacks(tsp, markDown);
1949 lock_ObtainWrite(&cm_serverLock);
1950 cm_PutServerNoLock(tsp);
1952 lock_ReleaseWrite(&cm_serverLock);