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>
29 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid);
31 /* read/write lock for all global storage in this module */
32 osi_rwlock_t cm_callbackLock;
34 afs_int32 cm_OfflineROIsValid = 0;
36 afs_int32 cm_giveUpAllCBs = 0;
38 afs_int32 cm_shutdown = 0;
40 #ifdef AFS_FREELANCE_CLIENT
41 extern osi_mutex_t cm_Freelance_Lock;
44 /* count of # of callback breaking messages received by this CM so far. We use
45 * this count in determining whether there have been any callback breaks that
46 * apply to a call that returned a new callback. If the counter doesn't
47 * increase during a call, then we know that no callbacks were broken during
48 * that call, and thus that the callback that was just returned is still valid.
50 long cm_callbackCount;
52 /* count of number of RPCs potentially returning a callback executing now.
53 * When this counter hits zero, we can clear out the racing revokes list, since
54 * at that time, we know that none of the just-executed callback revokes will
55 * apply to any future call that returns a callback (since the latter hasn't
56 * even started execution yet).
58 long cm_activeCallbackGrantingCalls;
60 /* list of callbacks that have been broken recently. If a call returning a
61 * callback is executing and a callback revoke runs immediately after it at the
62 * server, the revoke may end up being processed before the response to the
63 * original callback granting call. We detect this by keeping a list of
64 * callback revokes that have been received since we *started* the callback
65 * granting call, and discarding any callbacks received for the same file ID,
66 * even if the callback revoke was received before the callback grant.
68 cm_racingRevokes_t *cm_racingRevokesp;
70 /* record a (potentially) racing revoke for this file ID; null means for all
71 * file IDs, and is used by InitCallBackState.
73 * The cancelFlags describe whether we're just discarding callbacks for the same
74 * file ID, the same volume, or all from the same server.
76 * Called with no locks held.
78 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
80 cm_racingRevokes_t *rp;
82 lock_ObtainWrite(&cm_callbackLock);
84 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
85 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
87 if (cm_activeCallbackGrantingCalls > 0) {
88 rp = malloc(sizeof(*rp));
89 memset(rp, 0, sizeof(*rp));
90 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
91 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
92 if (fidp) rp->fid = *fidp;
93 rp->callbackCount = ++cm_callbackCount;
95 lock_ReleaseWrite(&cm_callbackLock);
99 * When we lose a callback, may have to send change notification replies.
100 * Do not call with a lock on the scp.
102 void cm_CallbackNotifyChange(cm_scache_t *scp)
108 /* why does this have to query the registry each time? */
109 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
110 AFSREG_CLT_OPENAFS_SUBKEY,
112 KEY_READ|KEY_QUERY_VALUE,
113 &hKey) == ERROR_SUCCESS) {
115 dummyLen = sizeof(DWORD);
116 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
117 (BYTE *) &dwDelay, &dummyLen);
121 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
124 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
125 scp->fileType, scp->flags, dwDelay);
130 /* for directories, this sends a change notification on the dir itself */
131 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
132 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
134 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
135 scp, NULL, NULL, TRUE);
137 /* and for files, this sends a change notification on the file's parent dir */
141 cm_SetFid(&tfid, scp->fid.cell, scp->fid.volume, scp->parentVnode, scp->parentUnique);
142 dscp = cm_FindSCache(&tfid);
144 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
146 FILE_NOTIFY_GENERIC_FILE_FILTER,
147 dscp, NULL, NULL, TRUE);
149 cm_ReleaseSCache(dscp);
153 /* called with no locks held for every file ID that is revoked directly by
154 * a callback revoke call. Does not have to handle volume callback breaks,
155 * since those have already been split out.
157 * The callp parameter is currently unused.
159 void cm_RevokeCallback(struct rx_call *callp, cm_cell_t * cellp, AFSFid *fidp)
165 tfid.cell = cellp ? cellp->cellID : 0;
166 tfid.volume = fidp->Volume;
167 tfid.vnode = fidp->Vnode;
168 tfid.unique = fidp->Unique;
169 hash = CM_SCACHE_HASH(&tfid);
171 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
172 fidp->Volume, fidp->Vnode, fidp->Unique);
174 /* do this first, so that if we're executing a callback granting call
175 * at this moment, we kill it before it can be merged in. Otherwise,
176 * it could complete while we're doing the scan below, and get missed
177 * by both the scan and by this code.
179 cm_RecordRacingRevoke(&tfid, 0);
181 lock_ObtainWrite(&cm_scacheLock);
182 /* do all in the hash bucket, since we don't know how many we'll find with
185 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
186 if (scp->fid.volume == tfid.volume &&
187 scp->fid.vnode == tfid.vnode &&
188 scp->fid.unique == tfid.unique &&
189 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
190 cm_HaveCallback(scp))
192 cm_HoldSCacheNoLock(scp);
193 lock_ReleaseWrite(&cm_scacheLock);
194 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
195 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
197 lock_ObtainWrite(&scp->rw);
198 cm_DiscardSCache(scp);
199 lock_ReleaseWrite(&scp->rw);
201 cm_CallbackNotifyChange(scp);
203 lock_ObtainWrite(&cm_scacheLock);
204 cm_ReleaseSCacheNoLock(scp);
207 lock_ReleaseWrite(&cm_scacheLock);
209 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
210 fidp->Volume, fidp->Vnode, fidp->Unique);
213 /* called to revoke a volume callback, which is typically issued when a volume
214 * is moved from one server to another.
216 * Called with no locks held.
218 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
224 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
226 /* do this first, so that if we're executing a callback granting call
227 * at this moment, we kill it before it can be merged in. Otherwise,
228 * it could complete while we're doing the scan below, and get missed
229 * by both the scan and by this code.
231 tfid.cell = cellp ? cellp->cellID : 0;
232 tfid.volume = fidp->Volume;
233 tfid.vnode = tfid.unique = 0;
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;
353 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
354 host = rx_HostOf(peerp);
355 port = rx_PortOf(peerp);
357 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)
419 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState ->");
421 return SRXAFSCB_InitCallBackState3(callp, NULL);
424 /*------------------------------------------------------------------------
425 * EXPORTED SRXAFSCB_Probe
428 * Routine called by the server-side callback RPC interface to
429 * implement ``probing'' the Cache Manager, just making sure it's
433 * rx_call : Ptr to Rx call on which this request came in.
439 * Nothing interesting.
443 *------------------------------------------------------------------------*/
445 SRXAFSCB_Probe(struct rx_call *callp)
447 struct rx_connection *connp;
448 struct rx_peer *peerp;
449 unsigned long host = 0;
450 unsigned short port = 0;
455 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
456 host = rx_HostOf(peerp);
457 port = rx_PortOf(peerp);
460 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
467 /*------------------------------------------------------------------------
468 * EXPORTED SRXAFSCB_GetLock
471 * Routine called by the server-side callback RPC interface to
472 * implement pulling out the contents of a lock in the lock
476 * a_call : Ptr to Rx call on which this request came in.
477 * a_index : Index of desired lock.
478 * a_result : Ptr to a buffer for the given lock.
481 * 0 if everything went fine,
482 * 1 if we were given a bad index.
485 * Nothing interesting.
489 *------------------------------------------------------------------------*/
490 /* debug interface */
492 extern osi_rwlock_t cm_aclLock;
493 extern osi_rwlock_t buf_globalLock;
494 extern osi_rwlock_t cm_cellLock;
495 extern osi_rwlock_t cm_connLock;
496 extern osi_rwlock_t cm_daemonLock;
497 extern osi_rwlock_t cm_dnlcLock;
498 extern osi_rwlock_t cm_scacheLock;
499 extern osi_rwlock_t cm_serverLock;
500 extern osi_rwlock_t cm_syscfgLock;
501 extern osi_rwlock_t cm_userLock;
502 extern osi_rwlock_t cm_utilsLock;
503 extern osi_rwlock_t cm_volumeLock;
504 extern osi_rwlock_t smb_globalLock;
505 extern osi_rwlock_t smb_rctLock;
507 extern osi_mutex_t cm_Freelance_Lock;
508 extern osi_mutex_t cm_Afsdsbmt_Lock;
509 extern osi_mutex_t tokenEventLock;
510 extern osi_mutex_t smb_ListenerLock;
511 extern osi_mutex_t smb_RawBufLock;
512 extern osi_mutex_t smb_Dir_Watch_Lock;
514 #define LOCKTYPE_RW 1
515 #define LOCKTYPE_MUTEX 2
516 static struct _ltable {
521 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
522 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
523 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
524 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
525 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
526 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
527 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
528 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
529 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
530 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
531 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
532 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
533 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
534 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
535 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
536 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
537 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
538 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
539 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
540 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
541 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
545 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
547 struct _ltable *tl; /*Ptr to lock table entry */
550 int nentries; /*Num entries in table */
551 int code; /*Return code */
552 struct rx_connection *connp;
553 struct rx_peer *peerp;
554 unsigned long host = 0;
555 unsigned short port = 0;
560 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
561 host = rx_HostOf(peerp);
562 port = rx_PortOf(peerp);
565 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
566 index, ntohl(host), ntohs(port));
568 nentries = sizeof(ltable) / sizeof(struct _ltable);
569 if (index < 0 || index >= nentries) {
576 * Found it - copy out its contents.
579 strncpy(lockp->name, tl->name, sizeof(lockp->name));
580 lockp->name[sizeof(lockp->name)-1] = '\0';
581 lockp->lock.waitStates = 0;
582 switch ( tl->type ) {
584 rwp = (osi_rwlock_t *)tl->addr;
585 lockp->lock.exclLocked = rwp->flags;
586 lockp->lock.readersReading = rwp->readers;
587 lockp->lock.numWaiting = rwp->waiters;
590 mtxp = (osi_mutex_t *)tl->addr;
591 lockp->lock.exclLocked = mtxp->flags;
592 lockp->lock.readersReading = 0;
593 lockp->lock.numWaiting = mtxp->waiters;
596 lockp->lock.pid_last_reader = 0;
597 lockp->lock.pid_writer = 0;
598 lockp->lock.src_indicator = 0;
605 /* debug interface */
607 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
612 struct rx_connection *connp;
613 struct rx_peer *peerp;
614 unsigned long host = 0;
615 unsigned short port = 0;
620 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
621 host = rx_HostOf(peerp);
622 port = rx_PortOf(peerp);
625 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
626 ntohl(host), ntohs(port));
628 lock_ObtainRead(&cm_scacheLock);
629 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
630 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
634 } /*Zip through current hash chain */
635 } /*Zip through hash chains */
645 * Copy out the located entry.
647 memset(cep, 0, sizeof(AFSDBCacheEntry));
648 cep->addr = afs_data_pointer_to_int32(scp);
649 cep->cell = scp->fid.cell;
650 cep->netFid.Volume = scp->fid.volume;
651 cep->netFid.Vnode = scp->fid.vnode;
652 cep->netFid.Unique = scp->fid.unique;
653 cep->lock.waitStates = 0;
654 cep->lock.exclLocked = scp->rw.flags;
655 cep->lock.readersReading = 0;
656 cep->lock.numWaiting = scp->rw.waiters;
657 cep->lock.pid_last_reader = 0;
658 cep->lock.pid_writer = 0;
659 cep->lock.src_indicator = 0;
660 cep->Length = scp->length.LowPart;
661 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
662 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
663 if (scp->flags & CM_SCACHEFLAG_PURERO) {
664 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
666 cep->cbExpires = volp->cbExpiresRO;
670 /* TODO: deal with time_t below */
671 cep->cbExpires = (afs_int32) scp->cbExpires;
673 cep->refCount = scp->refCount;
674 cep->opens = scp->openReads;
675 cep->writers = scp->openWrites;
676 switch (scp->fileType) {
677 case CM_SCACHETYPE_FILE:
680 case CM_SCACHETYPE_MOUNTPOINT:
683 case CM_SCACHETYPE_DIRECTORY:
684 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
689 case CM_SCACHETYPE_SYMLINK:
692 case CM_SCACHETYPE_DFSLINK:
695 case CM_SCACHETYPE_INVALID:
700 if (scp->flags & CM_SCACHEFLAG_STATD)
702 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
704 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
705 scp->mountPointStringp[0])
707 if (scp->flags & CM_SCACHEFLAG_WAITING)
712 * Return our results.
715 lock_ReleaseRead(&cm_scacheLock);
720 /* debug interface */
722 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
727 struct rx_connection *connp;
728 struct rx_peer *peerp;
729 unsigned long host = 0;
730 unsigned short port = 0;
735 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
736 host = rx_HostOf(peerp);
737 port = rx_PortOf(peerp);
740 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
741 ntohl(host), ntohs(port));
743 lock_ObtainRead(&cm_scacheLock);
744 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
745 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
749 } /*Zip through current hash chain */
750 } /*Zip through hash chains */
760 * Copy out the located entry.
762 memset(cep, 0, sizeof(AFSDBCacheEntry64));
763 cep->addr = afs_data_pointer_to_int32(scp);
764 cep->cell = scp->fid.cell;
765 cep->netFid.Volume = scp->fid.volume;
766 cep->netFid.Vnode = scp->fid.vnode;
767 cep->netFid.Unique = scp->fid.unique;
768 cep->lock.waitStates = 0;
769 cep->lock.exclLocked = scp->rw.flags;
770 cep->lock.readersReading = 0;
771 cep->lock.numWaiting = scp->rw.waiters;
772 cep->lock.pid_last_reader = 0;
773 cep->lock.pid_writer = 0;
774 cep->lock.src_indicator = 0;
775 #if !defined(AFS_64BIT_ENV)
776 cep->Length.high = scp->length.HighPart;
777 cep->Length.low = scp->length.LowPart;
779 cep->Length = (afs_int64) scp->length.QuadPart;
781 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
782 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
783 if (scp->flags & CM_SCACHEFLAG_PURERO) {
784 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
786 cep->cbExpires = volp->cbExpiresRO;
790 /* TODO: handle time_t */
791 cep->cbExpires = (afs_int32) scp->cbExpires;
793 cep->refCount = scp->refCount;
794 cep->opens = scp->openReads;
795 cep->writers = scp->openWrites;
796 switch (scp->fileType) {
797 case CM_SCACHETYPE_FILE:
800 case CM_SCACHETYPE_MOUNTPOINT:
803 case CM_SCACHETYPE_DIRECTORY:
804 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
809 case CM_SCACHETYPE_SYMLINK:
812 case CM_SCACHETYPE_DFSLINK:
815 case CM_SCACHETYPE_INVALID:
820 if (scp->flags & CM_SCACHEFLAG_STATD)
822 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
824 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
825 scp->mountPointStringp[0])
827 if (scp->flags & CM_SCACHEFLAG_WAITING)
832 * Return our results.
835 lock_ReleaseRead(&cm_scacheLock);
840 /* debug interface: not implemented */
842 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
844 struct rx_connection *connp;
845 struct rx_peer *peerp;
846 unsigned long host = 0;
847 unsigned short port = 0;
852 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
853 host = rx_HostOf(peerp);
854 port = rx_PortOf(peerp);
857 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
858 ntohl(host), ntohs(port));
864 /* debug interface: not implemented */
866 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
867 AFSCB_CollData *datap)
869 struct rx_connection *connp;
870 struct rx_peer *peerp;
871 unsigned long host = 0;
872 unsigned short port = 0;
877 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
878 host = rx_HostOf(peerp);
879 port = rx_PortOf(peerp);
882 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
883 ntohl(host), ntohs(port));
889 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
894 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
896 return SRXAFSCB_InitCallBackState3(callp, NULL);
899 /* debug interface */
901 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
905 struct rx_connection *connp;
906 struct rx_peer *peerp;
907 unsigned long host = 0;
908 unsigned short port = 0;
913 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
914 host = rx_HostOf(peerp);
915 port = rx_PortOf(peerp);
918 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
922 lock_ObtainRead(&cm_syscfgLock);
923 if (cm_LanAdapterChangeDetected) {
924 lock_ConvertRToW(&cm_syscfgLock);
925 if (cm_LanAdapterChangeDetected) {
926 /* get network related info */
927 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
928 code = syscfg_GetIFInfo(&cm_noIPAddr,
929 cm_IPAddr, cm_SubnetMask,
930 cm_NetMtu, cm_NetFlags);
931 cm_LanAdapterChangeDetected = 0;
933 lock_ConvertWToR(&cm_syscfgLock);
936 /* return all network interface addresses */
937 addr->numberOfInterfaces = cm_noIPAddr;
938 addr->uuid = cm_data.Uuid;
939 for ( i=0; i < cm_noIPAddr; i++ ) {
940 addr->addr_in[i] = cm_IPAddr[i];
941 addr->subnetmask[i] = cm_SubnetMask[i];
942 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
943 cm_NetMtu[i] : rx_mtu;
946 lock_ReleaseRead(&cm_syscfgLock);
952 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
956 struct sockaddr_in taddr;
957 cm_server_t *tsp = NULL;
958 cm_scache_t *scp = NULL;
959 cm_cell_t* cellp = NULL;
962 struct rx_connection *connp;
963 struct rx_peer *peerp;
964 unsigned long host = 0;
965 unsigned short port = 0;
970 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
971 host = rx_HostOf(peerp);
972 port = rx_PortOf(peerp);
975 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
976 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 Uuid%s ->",osi_LogSaveString(afsd_logp,p));
980 tsp = cm_FindServerByUuid(serverUuid, CM_SERVER_FILE);
983 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
990 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d",
994 osi_Log3(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d for cell %s",
997 cellp->name /* does not need to be saved, doesn't change */);
999 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 from unknown host");
1002 if (connp && peerp) {
1003 taddr.sin_family = AF_INET;
1004 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
1005 taddr.sin_port = rx_PortOf(rx_PeerOf(rx_ConnectionOf(callp)));
1007 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
1009 osi_Log1(afsd_logp, "InitCallbackState3 server %x", tsp);
1011 /* record the callback in the racing revokes structure. This
1012 * shouldn't be necessary, since we shouldn't be making callback
1013 * granting calls while we're going to get an initstate call,
1014 * but there probably are some obscure races, so better safe
1017 * We do this first since we don't hold the cm_scacheLock and vnode
1018 * locks over the entire callback scan operation below. The
1019 * big loop below is guaranteed to hit any callback already
1020 * processed. The call to RecordRacingRevoke is guaranteed
1021 * to kill any callback that is currently being returned.
1022 * Anything that sneaks past both must start
1023 * after the call to RecordRacingRevoke.
1028 fid.cell = cellp->cellID;
1029 fid.volume = fid.vnode = fid.unique = 0;
1031 cm_RecordRacingRevoke(&fid, CM_RACINGFLAG_CANCELALL);
1033 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
1036 /* now search all vnodes looking for guys with this callback, if we
1037 * found it, or guys with any callbacks, if we didn't find the server
1038 * (that's how multihomed machines will appear and how we'll handle
1039 * them, albeit a little inefficiently). That is, we're discarding all
1040 * callbacks from all hosts if we get an initstate call from an unknown
1041 * host. Since these calls are rare, and multihomed servers
1042 * are "rare," hopefully this won't be a problem.
1044 lock_ObtainWrite(&cm_scacheLock);
1045 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
1046 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
1047 cm_HoldSCacheNoLock(scp);
1048 lock_ReleaseWrite(&cm_scacheLock);
1049 lock_ObtainWrite(&scp->rw);
1051 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
1052 /* we have a callback, now decide if we should clear it */
1053 if (cm_ServerEqual(scp->cbServerp, tsp)) {
1054 osi_Log4(afsd_logp, "InitCallbackState3 Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1055 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1056 cm_DiscardSCache(scp);
1060 lock_ReleaseWrite(&scp->rw);
1062 cm_CallbackNotifyChange(scp);
1063 lock_ObtainWrite(&cm_scacheLock);
1064 cm_ReleaseSCacheNoLock(scp);
1066 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO)) {
1067 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1069 if (volp->cbExpiresRO != 0)
1070 volp->cbExpiresRO = 0;
1075 } /* search one hash bucket */
1076 } /* search all hash buckets */
1078 lock_ReleaseWrite(&cm_scacheLock);
1081 /* reset the No flags on the server */
1082 cm_SetServerNo64Bit(tsp, 0);
1083 cm_SetServerNoInlineBulk(tsp, 0);
1085 /* we're done with the server structure */
1092 /* debug interface */
1094 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1096 struct rx_connection *connp;
1097 struct rx_peer *peerp;
1098 unsigned long host = 0;
1099 unsigned short port = 0;
1106 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1107 host = rx_HostOf(peerp);
1108 port = rx_PortOf(peerp);
1111 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1112 UuidToString((UUID *)&cm_data.Uuid, &p);
1113 UuidToString((UUID *)clientUuid, &q);
1114 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1115 osi_LogSaveString(afsd_logp,p),
1116 osi_LogSaveString(afsd_logp,q),
1122 code = 1; /* failure */
1124 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1131 /* debug interface */
1133 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1137 cm_serverRef_t * serverRefp;
1139 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1141 *a_name = strdup("");
1145 lock_ObtainRead(&cm_serverLock);
1146 *a_name = strdup(cellp->name);
1148 for ( sn = 0, serverRefp = cellp->vlServersp;
1149 sn < AFSMAXCELLHOSTS && serverRefp;
1150 sn++, serverRefp = serverRefp->next);
1152 a_hosts->serverList_len = sn;
1153 a_hosts->serverList_val = (afs_int32 *)xdr_alloc(sn * sizeof(afs_int32));
1155 for ( sn = 0, serverRefp = cellp->vlServersp;
1156 sn < AFSMAXCELLHOSTS && serverRefp;
1157 sn++, serverRefp = serverRefp->next)
1159 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1162 lock_ReleaseRead(&cm_serverLock);
1166 /* debug interface */
1168 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1169 char **a_name, serverList *a_hosts)
1171 struct rx_connection *connp;
1172 struct rx_peer *peerp;
1173 unsigned long host = 0;
1174 unsigned short port = 0;
1180 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1181 host = rx_HostOf(peerp);
1182 port = rx_PortOf(peerp);
1185 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1186 a_cellnum, ntohl(host), ntohs(port));
1188 a_hosts->serverList_val = 0;
1189 a_hosts->serverList_len = 0;
1192 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1197 /* debug interface */
1199 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1200 struct interfaceAddr *addr,
1201 Capabilities * capabilities)
1204 afs_uint32 *dataBuffP;
1205 afs_int32 dataBytes;
1207 struct rx_connection *connp;
1208 struct rx_peer *peerp;
1209 unsigned long host = 0;
1210 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_TellMeAboutYourself from host 0x%x port %d",
1224 lock_ObtainRead(&cm_syscfgLock);
1225 if (cm_LanAdapterChangeDetected) {
1226 lock_ConvertRToW(&cm_syscfgLock);
1227 if (cm_LanAdapterChangeDetected) {
1228 /* get network related info */
1229 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1230 code = syscfg_GetIFInfo(&cm_noIPAddr,
1231 cm_IPAddr, cm_SubnetMask,
1232 cm_NetMtu, cm_NetFlags);
1233 cm_LanAdapterChangeDetected = 0;
1235 lock_ConvertWToR(&cm_syscfgLock);
1238 /* return all network interface addresses */
1239 addr->numberOfInterfaces = cm_noIPAddr;
1240 addr->uuid = cm_data.Uuid;
1241 for ( i=0; i < cm_noIPAddr; i++ ) {
1242 addr->addr_in[i] = cm_IPAddr[i];
1243 addr->subnetmask[i] = cm_SubnetMask[i];
1244 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1245 cm_NetMtu[i] : rx_mtu;
1247 lock_ReleaseRead(&cm_syscfgLock);
1249 dataBytes = 1 * sizeof(afs_uint32);
1250 dataBuffP = (afs_uint32 *) xdr_alloc(dataBytes);
1251 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1252 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1253 capabilities->Capabilities_val = dataBuffP;
1258 /*------------------------------------------------------------------------
1259 * EXPORTED SRXAFSCB_GetServerPrefs
1262 * Routine to list server preferences used by this client.
1265 * a_call : Ptr to Rx call on which this request came in.
1266 * a_index : Input server index
1267 * a_srvr_addr : Output server address (0xffffffff on last server)
1268 * a_srvr_rank : Output server rank
1274 * Nothing interesting.
1278 *------------------------------------------------------------------------*/
1280 int SRXAFSCB_GetServerPrefs(
1281 struct rx_call *callp,
1283 afs_int32 *a_srvr_addr,
1284 afs_int32 *a_srvr_rank)
1286 struct rx_connection *connp;
1287 struct rx_peer *peerp;
1288 unsigned long host = 0;
1289 unsigned short port = 0;
1294 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1295 host = rx_HostOf(peerp);
1296 port = rx_PortOf(peerp);
1299 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1303 *a_srvr_addr = 0xffffffff;
1304 *a_srvr_rank = 0xffffffff;
1309 /*------------------------------------------------------------------------
1310 * EXPORTED SRXAFSCB_GetCellServDB
1313 * Routine to list cells configured for this client
1316 * a_call : Ptr to Rx call on which this request came in.
1317 * a_index : Input cell index
1318 * a_name : Output cell name ("" on last cell)
1319 * a_hosts : Output cell database servers
1325 * Nothing interesting.
1329 *------------------------------------------------------------------------*/
1331 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1332 serverList *a_hosts)
1334 struct rx_connection *connp;
1335 struct rx_peer *peerp;
1336 unsigned long host = 0;
1337 unsigned short port = 0;
1343 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1344 host = rx_HostOf(peerp);
1345 port = rx_PortOf(peerp);
1348 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1349 ntohl(host), ntohs(port));
1351 #ifdef AFS_FREELANCE_CLIENT
1352 if (cm_freelanceEnabled && index == 0) {
1353 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1357 rc = GetCellCommon(index+1, a_name, a_hosts);
1362 /*------------------------------------------------------------------------
1363 * EXPORTED SRXAFSCB_GetLocalCell
1366 * Routine to return name of client's local cell
1369 * a_call : Ptr to Rx call on which this request came in.
1370 * a_name : Output cell name
1376 * Nothing interesting.
1380 *------------------------------------------------------------------------*/
1382 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1385 struct rx_connection *connp;
1386 struct rx_peer *peerp;
1387 unsigned long host = 0;
1388 unsigned short port = 0;
1393 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1394 host = rx_HostOf(peerp);
1395 port = rx_PortOf(peerp);
1398 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1399 ntohl(host), ntohs(port));
1401 if (cm_data.rootCellp) {
1402 t_name = strdup(cm_data.rootCellp->name);
1404 t_name = (char *)malloc(1);
1414 * afs_MarshallCacheConfig - marshall client cache configuration
1418 * IN callerVersion - the rpc stat version of the caller.
1420 * IN config - client cache configuration.
1422 * OUT ptr - buffer where configuration is marshalled.
1428 static void afs_MarshallCacheConfig(
1429 afs_uint32 callerVersion,
1430 cm_initparams_v1 *config,
1434 * We currently only support version 1.
1436 *(ptr++) = config->nChunkFiles;
1437 *(ptr++) = config->nStatCaches;
1438 *(ptr++) = config->nDataCaches;
1439 *(ptr++) = config->nVolumeCaches;
1440 *(ptr++) = config->firstChunkSize;
1441 *(ptr++) = config->otherChunkSize;
1442 *(ptr++) = config->cacheSize;
1443 *(ptr++) = config->setTime;
1444 *(ptr++) = config->memCache;
1449 /*------------------------------------------------------------------------
1450 * EXPORTED SRXAFSCB_GetCacheConfig
1453 * Routine to return parameters used to initialize client cache.
1454 * Client may request any format version. Server may not return
1455 * format version greater than version requested by client.
1458 * a_call: Ptr to Rx call on which this request came in.
1459 * callerVersion: Data format version desired by the client.
1460 * serverVersion: Data format version of output data.
1461 * configCount: Number bytes allocated for output data.
1462 * config: Client cache configuration.
1468 * Nothing interesting.
1472 *------------------------------------------------------------------------*/
1474 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1475 afs_uint32 callerVersion,
1476 afs_uint32 *serverVersion,
1477 afs_uint32 *configCount,
1478 cacheConfig *config)
1480 afs_uint32 *t_config;
1482 extern cm_initparams_v1 cm_initParams;
1483 struct rx_connection *connp;
1484 struct rx_peer *peerp;
1485 unsigned long host = 0;
1486 unsigned short port = 0;
1491 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1492 host = rx_HostOf(peerp);
1493 port = rx_PortOf(peerp);
1496 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1497 ntohl(host), ntohs(port));
1500 * Currently only support version 1
1502 allocsize = sizeof(cm_initparams_v1);
1503 t_config = (afs_uint32 *)malloc(allocsize);
1505 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1507 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1510 #define SIZE_MAX UINT_MAX
1512 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1514 *configCount = (afs_uint32)allocsize;
1515 config->cacheConfig_val = t_config;
1516 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1521 /* called by afsd without any locks to initialize this module */
1522 void cm_InitCallback(void)
1524 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1525 cm_activeCallbackGrantingCalls = 0;
1528 /* called with locked scp; tells us whether we've got a callback.
1529 * Expirations are checked by a background daemon so as to make
1530 * this function as inexpensive as possible
1532 int cm_HaveCallback(cm_scache_t *scp)
1534 #ifdef AFS_FREELANCE_CLIENT
1535 // yj: we handle callbacks specially for callbacks on the root directory
1536 // Since it's local, we almost always say that we have callback on it
1537 // The only time we send back a 0 is if we're need to initialize or
1538 // reinitialize the fake directory
1540 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1541 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1542 // hence should return false. it's 0 otherwise
1543 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1544 // if the fake directory is loaded and this is the first time cm_HaveCallback
1545 // is called since then. We return false in this case to allow cm_GetCallback
1546 // to be called because cm_GetCallback has some initialization work to do.
1547 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1548 // good shape and we simply return true, provided no change is detected.
1551 if (cm_freelanceEnabled &&
1552 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1553 lock_ObtainMutex(&cm_Freelance_Lock);
1554 fdc = cm_fakeDirCallback;
1555 fgc = cm_fakeGettingCallback;
1556 lock_ReleaseMutex(&cm_Freelance_Lock);
1558 if (fdc==1) { // first call since init
1560 } else if (fdc==2 && !fgc) { // we're in good shape
1561 if (cm_getLocalMountPointChange()) { // check for changes
1562 cm_clearLocalMountPointChange(); // clear the changefile
1563 lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
1564 cm_reInitLocalMountPoints(); // start reinit
1565 lock_ObtainWrite(&scp->rw); // now get the lock back
1568 return (cm_data.fakeDirVersion == scp->dataVersion);
1574 if (scp->cbServerp != NULL) {
1576 } else if (cm_OfflineROIsValid) {
1577 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1579 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1595 /* need to detect a broken callback that races with our obtaining a callback.
1596 * Need to be able to do this even if we don't know the file ID of the file
1597 * we're breaking the callback on at the time we start the acquisition of the
1598 * callback (as in the case where we are creating a file).
1600 * So, we start by writing down the count of the # of callbacks we've received
1601 * so far, and bumping a global counter of the # of callback granting calls
1602 * outstanding (all done under cm_callbackLock).
1604 * When we're back from the call, we look at all of the callback revokes with
1605 * counter numbers greater than the one we recorded in our caller's structure,
1606 * and replay those that are higher than when we started the call.
1608 * We free all the structures in the queue when the count of the # of outstanding
1609 * callback-granting calls drops to zero.
1611 * We call this function with the scp locked, too, but in its current implementation,
1612 * this knowledge is not used.
1614 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1616 lock_ObtainWrite(&cm_callbackLock);
1617 cbrp->callbackCount = cm_callbackCount;
1618 cm_activeCallbackGrantingCalls++;
1619 cbrp->startTime = time(NULL);
1620 cbrp->serverp = NULL;
1621 lock_ReleaseWrite(&cm_callbackLock);
1624 /* Called at the end of a callback-granting call, to remove the callback
1625 * info from the scache entry, if necessary.
1627 * Called with scp write locked, so we can discard the callbacks easily with
1628 * this locking hierarchy.
1630 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1631 AFSCallBack *cbp, long flags)
1633 cm_racingRevokes_t *revp; /* where we are */
1634 cm_racingRevokes_t *nrevp; /* where we'll be next */
1636 cm_server_t * serverp = NULL;
1637 int discardScp = 0, discardVolCB = 0;
1639 lock_ObtainWrite(&cm_callbackLock);
1640 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1641 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1642 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1645 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1646 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1648 if (cm_activeCallbackGrantingCalls == 0)
1653 /* record the callback; we'll clear it below if we really lose it */
1656 if (!cm_ServerEqual(scp->cbServerp, cbrp->serverp)) {
1657 serverp = scp->cbServerp;
1659 cm_GetServer(cbrp->serverp);
1660 scp->cbServerp = cbrp->serverp;
1663 serverp = cbrp->serverp;
1665 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1668 serverp = cbrp->serverp;
1671 cbrp->serverp = NULL;
1674 /* a callback was actually revoked during our granting call, so
1675 * run down the list of revoked fids, looking for ours.
1676 * If activeCallbackGrantingCalls is zero, free the elements, too.
1678 * May need to go through entire list just to do the freeing.
1680 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1681 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1682 /* if this callback came in later than when we started the
1683 * callback-granting call, and if this fid is the right fid,
1684 * then clear the callback.
1686 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1687 && revp->callbackCount > cbrp->callbackCount
1688 && (( scp->fid.volume == revp->fid.volume &&
1689 scp->fid.vnode == revp->fid.vnode &&
1690 scp->fid.unique == revp->fid.unique)
1692 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1693 scp->fid.volume == revp->fid.volume)
1695 ((revp->flags & CM_RACINGFLAG_CANCELALL) &&
1696 (revp->fid.cell == 0 || scp->fid.cell == revp->fid.cell)))) {
1697 /* this one matches */
1699 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1701 cbrp->callbackCount, revp->callbackCount,
1704 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1705 (revp->flags & CM_RACINGFLAG_ALL)) {
1706 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1708 volp->cbExpiresRO = 0;
1717 /* if we freed the list, zap the pointer to it */
1719 cm_racingRevokesp = NULL;
1721 lock_ReleaseWrite(&cm_callbackLock);
1724 cm_DiscardSCache(scp);
1725 lock_ReleaseWrite(&scp->rw);
1726 cm_CallbackNotifyChange(scp);
1727 lock_ObtainWrite(&scp->rw);
1729 if (scp && scp->flags & CM_SCACHEFLAG_PURERO) {
1730 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1732 volp->cbExpiresRO = scp->cbExpires;
1733 if (volp->cbServerpRO != scp->cbServerp) {
1734 if (volp->cbServerpRO)
1735 cm_PutServer(volp->cbServerpRO);
1736 cm_GetServer(scp->cbServerp);
1737 volp->cbServerpRO = scp->cbServerp;
1745 lock_ObtainWrite(&cm_serverLock);
1746 cm_FreeServer(serverp);
1747 lock_ReleaseWrite(&cm_serverLock);
1751 /* if flags is 1, we want to force the code to make one call, anyway.
1752 * called with locked scp; returns with same.
1754 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1755 struct cm_req *reqp, long flags)
1758 cm_conn_t *connp = NULL;
1759 AFSFetchStatus afsStatus;
1761 AFSCallBack callback;
1763 cm_callbackRequest_t cbr;
1766 struct rx_connection * rxconnp = NULL;
1767 int syncop_done = 0;
1769 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1770 scp, scp->fid.cell, scp->fid.volume, flags);
1772 #ifdef AFS_FREELANCE_CLIENT
1773 // The case where a callback is needed on /afs is handled
1774 // specially. We need to fetch the status by calling
1775 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1776 if (cm_freelanceEnabled &&
1777 (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1778 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)) {
1780 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1781 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1786 if (cm_fakeDirCallback != 2) {
1787 // Start by indicating that we're in the process
1788 // of fetching the callback
1789 lock_ObtainMutex(&cm_Freelance_Lock);
1790 osi_Log0(afsd_logp,"GetCallback Freelance fakeGettingCallback=1");
1791 cm_fakeGettingCallback = 1;
1792 lock_ReleaseMutex(&cm_Freelance_Lock);
1794 memset(&afsStatus, 0, sizeof(afsStatus));
1795 memset(&volSync, 0, sizeof(volSync));
1797 // Fetch the status info
1798 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1800 // Indicate that the callback is not done
1801 lock_ObtainMutex(&cm_Freelance_Lock);
1802 osi_Log0(afsd_logp,"GetCallback Freelance fakeDirCallback=2");
1803 cm_fakeDirCallback = 2;
1805 // Indicate that we're no longer fetching the callback
1806 osi_Log0(afsd_logp,"GetCallback Freelance fakeGettingCallback=0");
1807 cm_fakeGettingCallback = 0;
1808 lock_ReleaseMutex(&cm_Freelance_Lock);
1812 #endif /* AFS_FREELANCE_CLIENT */
1814 mustCall = (flags & 1);
1815 cm_AFSFidFromFid(&tfid, &scp->fid);
1817 if (!mustCall && cm_HaveCallback(scp))
1820 /* turn off mustCall, since it has now forced us past the check above */
1823 /* otherwise, we have to make an RPC to get the status */
1825 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1826 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1831 cm_StartCallbackGrantingCall(scp, &cbr);
1833 lock_ReleaseWrite(&scp->rw);
1835 /* now make the RPC */
1836 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1837 scp, sfid.volume, sfid.vnode, sfid.unique);
1839 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1843 rxconnp = cm_GetRxConn(connp);
1844 code = RXAFS_FetchStatus(rxconnp, &tfid,
1845 &afsStatus, &callback, &volSync);
1846 rx_PutConnection(rxconnp);
1848 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1850 code = cm_MapRPCError(code, reqp);
1852 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1853 code, scp, scp->fid.volume, scp->fid.vnode);
1855 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1856 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1858 lock_ObtainWrite(&scp->rw);
1860 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1861 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1863 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1866 /* if we got an error, return to caller */
1873 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1876 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1877 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1878 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1880 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1881 scp, scp->fid.cell, scp->fid.volume);
1888 /* called with cm_scacheLock held */
1889 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1891 cm_vol_state_t *statep;
1893 afs_uint32 volID = scp->fid.volume;
1894 cm_serverRef_t *tsrp;
1899 if (scp->cbServerp == NULL)
1902 volp = cm_GetVolumeByFID(&scp->fid);
1906 statep = cm_VolumeStateByID(volp, volID);
1908 if (statep->state == vl_online)
1911 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1912 if (tsrp->status == srv_deleted)
1914 if (cm_ServerEqual(tsrp->server, scp->cbServerp))
1916 if (tsrp->server->downTime > *downTime)
1917 *downTime = tsrp->server->downTime;
1920 /* if the cbServerp does not match the current volume server list
1921 * we report the callback server as up so the callback can be
1924 return(found ? 0 : 1);
1927 /* called periodically by cm_daemon to shut down use of expired callbacks */
1928 void cm_CheckCBExpiration(void)
1932 time_t now, downTime;
1934 osi_Log0(afsd_logp, "CheckCBExpiration");
1937 lock_ObtainWrite(&cm_scacheLock);
1938 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1939 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1941 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1942 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1944 if (volp->cbExpiresRO > scp->cbExpires &&
1947 scp->cbExpires = volp->cbExpiresRO;
1948 if (volp->cbServerpRO != scp->cbServerp) {
1950 cm_PutServer(scp->cbServerp);
1951 cm_GetServer(volp->cbServerpRO);
1952 scp->cbServerp = volp->cbServerpRO;
1958 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1959 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1961 cm_HoldSCacheNoLock(scp);
1962 lock_ReleaseWrite(&cm_scacheLock);
1964 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1965 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1966 lock_ObtainWrite(&scp->rw);
1967 cm_DiscardSCache(scp);
1968 lock_ReleaseWrite(&scp->rw);
1969 cm_CallbackNotifyChange(scp);
1971 lock_ObtainWrite(&cm_scacheLock);
1972 cm_ReleaseSCacheNoLock(scp);
1976 lock_ReleaseWrite(&cm_scacheLock);
1978 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1983 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1987 struct rx_connection * rxconnp;
1989 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1991 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1993 rxconnp = cm_GetRxConn(connp);
1994 rx_SetConnDeadTime(rxconnp, 10);
1995 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1996 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1997 rx_PutConnection(rxconnp);
2001 cm_server_vols_t * tsrvp;
2005 cm_ForceNewConnections(tsp);
2007 lock_ObtainMutex(&tsp->mx);
2008 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
2009 tsp->flags |= CM_SERVERFLAG_DOWN;
2010 tsp->downTime = time(NULL);
2012 /* Now update the volume status */
2013 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2014 for (i=0; i<NUM_SERVER_VOLS; i++) {
2015 if (tsrvp->ids[i] != 0) {
2019 lock_ReleaseMutex(&tsp->mx);
2020 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2021 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2022 lock_ObtainMutex(&tsp->mx);
2024 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2030 lock_ReleaseMutex(&tsp->mx);
2036 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
2040 if (!cm_giveUpAllCBs)
2043 lock_ObtainWrite(&cm_serverLock);
2044 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
2045 cm_GetServerNoLock(tsp);
2046 lock_ReleaseWrite(&cm_serverLock);
2047 cm_GiveUpAllCallbacks(tsp, markDown);
2048 lock_ObtainWrite(&cm_serverLock);
2049 cm_PutServerNoLock(tsp);
2051 lock_ReleaseWrite(&cm_serverLock);