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)));
1006 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
1008 osi_Log1(afsd_logp, "InitCallbackState3 server %x", tsp);
1010 /* record the callback in the racing revokes structure. This
1011 * shouldn't be necessary, since we shouldn't be making callback
1012 * granting calls while we're going to get an initstate call,
1013 * but there probably are some obscure races, so better safe
1016 * We do this first since we don't hold the cm_scacheLock and vnode
1017 * locks over the entire callback scan operation below. The
1018 * big loop below is guaranteed to hit any callback already
1019 * processed. The call to RecordRacingRevoke is guaranteed
1020 * to kill any callback that is currently being returned.
1021 * Anything that sneaks past both must start
1022 * after the call to RecordRacingRevoke.
1027 fid.cell = cellp->cellID;
1028 fid.volume = fid.vnode = fid.unique = 0;
1030 cm_RecordRacingRevoke(&fid, CM_RACINGFLAG_CANCELALL);
1032 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
1035 /* now search all vnodes looking for guys with this callback, if we
1036 * found it, or guys with any callbacks, if we didn't find the server
1037 * (that's how multihomed machines will appear and how we'll handle
1038 * them, albeit a little inefficiently). That is, we're discarding all
1039 * callbacks from all hosts if we get an initstate call from an unknown
1040 * host. Since these calls are rare, and multihomed servers
1041 * are "rare," hopefully this won't be a problem.
1043 lock_ObtainWrite(&cm_scacheLock);
1044 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
1045 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
1046 cm_HoldSCacheNoLock(scp);
1047 lock_ReleaseWrite(&cm_scacheLock);
1048 lock_ObtainWrite(&scp->rw);
1050 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
1051 /* we have a callback, now decide if we should clear it */
1052 if (cm_ServerEqual(scp->cbServerp, tsp)) {
1053 osi_Log4(afsd_logp, "InitCallbackState3 Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1054 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1055 cm_DiscardSCache(scp);
1059 lock_ReleaseWrite(&scp->rw);
1061 cm_CallbackNotifyChange(scp);
1062 lock_ObtainWrite(&cm_scacheLock);
1063 cm_ReleaseSCacheNoLock(scp);
1065 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO)) {
1066 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1068 if (volp->cbExpiresRO != 0)
1069 volp->cbExpiresRO = 0;
1074 } /* search one hash bucket */
1075 } /* search all hash buckets */
1077 lock_ReleaseWrite(&cm_scacheLock);
1080 /* reset the No flags on the server */
1081 cm_SetServerNo64Bit(tsp, 0);
1082 cm_SetServerNoInlineBulk(tsp, 0);
1084 /* we're done with the server structure */
1091 /* debug interface */
1093 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1095 struct rx_connection *connp;
1096 struct rx_peer *peerp;
1097 unsigned long host = 0;
1098 unsigned short port = 0;
1105 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1106 host = rx_HostOf(peerp);
1107 port = rx_PortOf(peerp);
1110 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1111 UuidToString((UUID *)&cm_data.Uuid, &p);
1112 UuidToString((UUID *)clientUuid, &q);
1113 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1114 osi_LogSaveString(afsd_logp,p),
1115 osi_LogSaveString(afsd_logp,q),
1121 code = 1; /* failure */
1123 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1130 /* debug interface */
1132 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1136 cm_serverRef_t * serverRefp;
1138 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1140 *a_name = strdup("");
1144 lock_ObtainRead(&cm_serverLock);
1145 *a_name = strdup(cellp->name);
1147 for ( sn = 0, serverRefp = cellp->vlServersp;
1148 sn < AFSMAXCELLHOSTS && serverRefp;
1149 sn++, serverRefp = serverRefp->next);
1151 a_hosts->serverList_len = sn;
1152 a_hosts->serverList_val = (afs_int32 *)xdr_alloc(sn * sizeof(afs_int32));
1154 for ( sn = 0, serverRefp = cellp->vlServersp;
1155 sn < AFSMAXCELLHOSTS && serverRefp;
1156 sn++, serverRefp = serverRefp->next)
1158 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1161 lock_ReleaseRead(&cm_serverLock);
1165 /* debug interface */
1167 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1168 char **a_name, serverList *a_hosts)
1170 struct rx_connection *connp;
1171 struct rx_peer *peerp;
1172 unsigned long host = 0;
1173 unsigned short port = 0;
1179 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1180 host = rx_HostOf(peerp);
1181 port = rx_PortOf(peerp);
1184 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1185 a_cellnum, ntohl(host), ntohs(port));
1187 a_hosts->serverList_val = 0;
1188 a_hosts->serverList_len = 0;
1191 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1196 /* debug interface */
1198 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1199 struct interfaceAddr *addr,
1200 Capabilities * capabilities)
1203 afs_uint32 *dataBuffP;
1204 afs_int32 dataBytes;
1206 struct rx_connection *connp;
1207 struct rx_peer *peerp;
1208 unsigned long host = 0;
1209 unsigned short port = 0;
1214 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1215 host = rx_HostOf(peerp);
1216 port = rx_PortOf(peerp);
1219 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1223 lock_ObtainRead(&cm_syscfgLock);
1224 if (cm_LanAdapterChangeDetected) {
1225 lock_ConvertRToW(&cm_syscfgLock);
1226 if (cm_LanAdapterChangeDetected) {
1227 /* get network related info */
1228 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1229 code = syscfg_GetIFInfo(&cm_noIPAddr,
1230 cm_IPAddr, cm_SubnetMask,
1231 cm_NetMtu, cm_NetFlags);
1232 cm_LanAdapterChangeDetected = 0;
1234 lock_ConvertWToR(&cm_syscfgLock);
1237 /* return all network interface addresses */
1238 addr->numberOfInterfaces = cm_noIPAddr;
1239 addr->uuid = cm_data.Uuid;
1240 for ( i=0; i < cm_noIPAddr; i++ ) {
1241 addr->addr_in[i] = cm_IPAddr[i];
1242 addr->subnetmask[i] = cm_SubnetMask[i];
1243 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1244 cm_NetMtu[i] : rx_mtu;
1246 lock_ReleaseRead(&cm_syscfgLock);
1248 dataBytes = 1 * sizeof(afs_uint32);
1249 dataBuffP = (afs_uint32 *) xdr_alloc(dataBytes);
1250 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1251 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1252 capabilities->Capabilities_val = dataBuffP;
1257 /*------------------------------------------------------------------------
1258 * EXPORTED SRXAFSCB_GetServerPrefs
1261 * Routine to list server preferences used by this client.
1264 * a_call : Ptr to Rx call on which this request came in.
1265 * a_index : Input server index
1266 * a_srvr_addr : Output server address (0xffffffff on last server)
1267 * a_srvr_rank : Output server rank
1273 * Nothing interesting.
1277 *------------------------------------------------------------------------*/
1279 int SRXAFSCB_GetServerPrefs(
1280 struct rx_call *callp,
1282 afs_int32 *a_srvr_addr,
1283 afs_int32 *a_srvr_rank)
1285 struct rx_connection *connp;
1286 struct rx_peer *peerp;
1287 unsigned long host = 0;
1288 unsigned short port = 0;
1293 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1294 host = rx_HostOf(peerp);
1295 port = rx_PortOf(peerp);
1298 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1302 *a_srvr_addr = 0xffffffff;
1303 *a_srvr_rank = 0xffffffff;
1308 /*------------------------------------------------------------------------
1309 * EXPORTED SRXAFSCB_GetCellServDB
1312 * Routine to list cells configured for this client
1315 * a_call : Ptr to Rx call on which this request came in.
1316 * a_index : Input cell index
1317 * a_name : Output cell name ("" on last cell)
1318 * a_hosts : Output cell database servers
1324 * Nothing interesting.
1328 *------------------------------------------------------------------------*/
1330 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1331 serverList *a_hosts)
1333 struct rx_connection *connp;
1334 struct rx_peer *peerp;
1335 unsigned long host = 0;
1336 unsigned short port = 0;
1342 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1343 host = rx_HostOf(peerp);
1344 port = rx_PortOf(peerp);
1347 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1348 ntohl(host), ntohs(port));
1350 #ifdef AFS_FREELANCE_CLIENT
1351 if (cm_freelanceEnabled && index == 0) {
1352 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1356 rc = GetCellCommon(index+1, a_name, a_hosts);
1361 /*------------------------------------------------------------------------
1362 * EXPORTED SRXAFSCB_GetLocalCell
1365 * Routine to return name of client's local cell
1368 * a_call : Ptr to Rx call on which this request came in.
1369 * a_name : Output cell name
1375 * Nothing interesting.
1379 *------------------------------------------------------------------------*/
1381 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1384 struct rx_connection *connp;
1385 struct rx_peer *peerp;
1386 unsigned long host = 0;
1387 unsigned short port = 0;
1392 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1393 host = rx_HostOf(peerp);
1394 port = rx_PortOf(peerp);
1397 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1398 ntohl(host), ntohs(port));
1400 if (cm_data.rootCellp) {
1401 t_name = strdup(cm_data.rootCellp->name);
1403 t_name = (char *)malloc(1);
1413 * afs_MarshallCacheConfig - marshall client cache configuration
1417 * IN callerVersion - the rpc stat version of the caller.
1419 * IN config - client cache configuration.
1421 * OUT ptr - buffer where configuration is marshalled.
1427 static void afs_MarshallCacheConfig(
1428 afs_uint32 callerVersion,
1429 cm_initparams_v1 *config,
1433 * We currently only support version 1.
1435 *(ptr++) = config->nChunkFiles;
1436 *(ptr++) = config->nStatCaches;
1437 *(ptr++) = config->nDataCaches;
1438 *(ptr++) = config->nVolumeCaches;
1439 *(ptr++) = config->firstChunkSize;
1440 *(ptr++) = config->otherChunkSize;
1441 *(ptr++) = config->cacheSize;
1442 *(ptr++) = config->setTime;
1443 *(ptr++) = config->memCache;
1448 /*------------------------------------------------------------------------
1449 * EXPORTED SRXAFSCB_GetCacheConfig
1452 * Routine to return parameters used to initialize client cache.
1453 * Client may request any format version. Server may not return
1454 * format version greater than version requested by client.
1457 * a_call: Ptr to Rx call on which this request came in.
1458 * callerVersion: Data format version desired by the client.
1459 * serverVersion: Data format version of output data.
1460 * configCount: Number bytes allocated for output data.
1461 * config: Client cache configuration.
1467 * Nothing interesting.
1471 *------------------------------------------------------------------------*/
1473 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1474 afs_uint32 callerVersion,
1475 afs_uint32 *serverVersion,
1476 afs_uint32 *configCount,
1477 cacheConfig *config)
1479 afs_uint32 *t_config;
1481 extern cm_initparams_v1 cm_initParams;
1482 struct rx_connection *connp;
1483 struct rx_peer *peerp;
1484 unsigned long host = 0;
1485 unsigned short port = 0;
1490 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1491 host = rx_HostOf(peerp);
1492 port = rx_PortOf(peerp);
1495 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1496 ntohl(host), ntohs(port));
1499 * Currently only support version 1
1501 allocsize = sizeof(cm_initparams_v1);
1502 t_config = (afs_uint32 *)malloc(allocsize);
1504 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1506 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1509 #define SIZE_MAX UINT_MAX
1511 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1513 *configCount = (afs_uint32)allocsize;
1514 config->cacheConfig_val = t_config;
1515 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1520 /* called by afsd without any locks to initialize this module */
1521 void cm_InitCallback(void)
1523 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1524 cm_activeCallbackGrantingCalls = 0;
1527 /* called with locked scp; tells us whether we've got a callback.
1528 * Expirations are checked by a background daemon so as to make
1529 * this function as inexpensive as possible
1531 int cm_HaveCallback(cm_scache_t *scp)
1533 #ifdef AFS_FREELANCE_CLIENT
1534 // yj: we handle callbacks specially for callbacks on the root directory
1535 // Since it's local, we almost always say that we have callback on it
1536 // The only time we send back a 0 is if we're need to initialize or
1537 // reinitialize the fake directory
1539 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1540 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1541 // hence should return false. it's 0 otherwise
1542 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1543 // if the fake directory is loaded and this is the first time cm_HaveCallback
1544 // is called since then. We return false in this case to allow cm_GetCallback
1545 // to be called because cm_GetCallback has some initialization work to do.
1546 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1547 // good shape and we simply return true, provided no change is detected.
1550 if (cm_freelanceEnabled &&
1551 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1552 lock_ObtainMutex(&cm_Freelance_Lock);
1553 fdc = cm_fakeDirCallback;
1554 fgc = cm_fakeGettingCallback;
1555 lock_ReleaseMutex(&cm_Freelance_Lock);
1557 if (fdc==1) { // first call since init
1559 } else if (fdc==2 && !fgc) { // we're in good shape
1560 if (cm_getLocalMountPointChange()) { // check for changes
1561 cm_clearLocalMountPointChange(); // clear the changefile
1562 lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
1563 cm_reInitLocalMountPoints(); // start reinit
1564 lock_ObtainWrite(&scp->rw); // now get the lock back
1567 return (cm_data.fakeDirVersion == scp->dataVersion);
1573 if (scp->cbServerp != NULL) {
1575 } else if (cm_OfflineROIsValid) {
1576 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1578 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1594 /* need to detect a broken callback that races with our obtaining a callback.
1595 * Need to be able to do this even if we don't know the file ID of the file
1596 * we're breaking the callback on at the time we start the acquisition of the
1597 * callback (as in the case where we are creating a file).
1599 * So, we start by writing down the count of the # of callbacks we've received
1600 * so far, and bumping a global counter of the # of callback granting calls
1601 * outstanding (all done under cm_callbackLock).
1603 * When we're back from the call, we look at all of the callback revokes with
1604 * counter numbers greater than the one we recorded in our caller's structure,
1605 * and replay those that are higher than when we started the call.
1607 * We free all the structures in the queue when the count of the # of outstanding
1608 * callback-granting calls drops to zero.
1610 * We call this function with the scp locked, too, but in its current implementation,
1611 * this knowledge is not used.
1613 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1615 lock_ObtainWrite(&cm_callbackLock);
1616 cbrp->callbackCount = cm_callbackCount;
1617 cm_activeCallbackGrantingCalls++;
1618 cbrp->startTime = time(NULL);
1619 cbrp->serverp = NULL;
1620 lock_ReleaseWrite(&cm_callbackLock);
1623 /* Called at the end of a callback-granting call, to remove the callback
1624 * info from the scache entry, if necessary.
1626 * Called with scp write locked, so we can discard the callbacks easily with
1627 * this locking hierarchy.
1629 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1630 AFSCallBack *cbp, long flags)
1632 cm_racingRevokes_t *revp; /* where we are */
1633 cm_racingRevokes_t *nrevp; /* where we'll be next */
1635 cm_server_t * serverp = NULL;
1636 int discardScp = 0, discardVolCB = 0;
1638 lock_ObtainWrite(&cm_callbackLock);
1639 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1640 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1641 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1644 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1645 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1647 if (cm_activeCallbackGrantingCalls == 0)
1652 /* record the callback; we'll clear it below if we really lose it */
1655 if (!cm_ServerEqual(scp->cbServerp, cbrp->serverp)) {
1656 serverp = scp->cbServerp;
1658 cm_GetServer(cbrp->serverp);
1659 scp->cbServerp = cbrp->serverp;
1662 serverp = cbrp->serverp;
1664 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1667 serverp = cbrp->serverp;
1670 cbrp->serverp = NULL;
1673 /* a callback was actually revoked during our granting call, so
1674 * run down the list of revoked fids, looking for ours.
1675 * If activeCallbackGrantingCalls is zero, free the elements, too.
1677 * May need to go through entire list just to do the freeing.
1679 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1680 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1681 /* if this callback came in later than when we started the
1682 * callback-granting call, and if this fid is the right fid,
1683 * then clear the callback.
1685 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1686 && revp->callbackCount > cbrp->callbackCount
1687 && (( scp->fid.volume == revp->fid.volume &&
1688 scp->fid.vnode == revp->fid.vnode &&
1689 scp->fid.unique == revp->fid.unique)
1691 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1692 scp->fid.volume == revp->fid.volume)
1694 ((revp->flags & CM_RACINGFLAG_CANCELALL) &&
1695 (revp->fid.cell == 0 || scp->fid.cell == revp->fid.cell)))) {
1696 /* this one matches */
1698 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1700 cbrp->callbackCount, revp->callbackCount,
1703 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1704 (revp->flags & CM_RACINGFLAG_ALL)) {
1705 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1707 volp->cbExpiresRO = 0;
1716 /* if we freed the list, zap the pointer to it */
1718 cm_racingRevokesp = NULL;
1720 lock_ReleaseWrite(&cm_callbackLock);
1723 cm_DiscardSCache(scp);
1724 lock_ReleaseWrite(&scp->rw);
1725 cm_CallbackNotifyChange(scp);
1726 lock_ObtainWrite(&scp->rw);
1728 if (scp && scp->flags & CM_SCACHEFLAG_PURERO) {
1729 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1731 volp->cbExpiresRO = scp->cbExpires;
1732 if (volp->cbServerpRO != scp->cbServerp) {
1733 if (volp->cbServerpRO)
1734 cm_PutServer(volp->cbServerpRO);
1735 cm_GetServer(scp->cbServerp);
1736 volp->cbServerpRO = scp->cbServerp;
1744 lock_ObtainWrite(&cm_serverLock);
1745 cm_FreeServer(serverp);
1746 lock_ReleaseWrite(&cm_serverLock);
1750 /* if flags is 1, we want to force the code to make one call, anyway.
1751 * called with locked scp; returns with same.
1753 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1754 struct cm_req *reqp, long flags)
1757 cm_conn_t *connp = NULL;
1758 AFSFetchStatus afsStatus;
1760 AFSCallBack callback;
1762 cm_callbackRequest_t cbr;
1765 struct rx_connection * rxconnp = NULL;
1766 int syncop_done = 0;
1768 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1769 scp, scp->fid.cell, scp->fid.volume, flags);
1771 #ifdef AFS_FREELANCE_CLIENT
1772 // The case where a callback is needed on /afs is handled
1773 // specially. We need to fetch the status by calling
1774 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1775 if (cm_freelanceEnabled) {
1776 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1777 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1778 // Start by indicating that we're in the process
1779 // of fetching the callback
1780 lock_ObtainMutex(&cm_Freelance_Lock);
1781 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1782 cm_fakeGettingCallback = 1;
1783 lock_ReleaseMutex(&cm_Freelance_Lock);
1785 // Fetch the status info
1786 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1788 // Indicate that the callback is not done
1789 lock_ObtainMutex(&cm_Freelance_Lock);
1790 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1791 cm_fakeDirCallback = 2;
1793 // Indicate that we're no longer fetching the callback
1794 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1795 cm_fakeGettingCallback = 0;
1796 lock_ReleaseMutex(&cm_Freelance_Lock);
1801 #endif /* AFS_FREELANCE_CLIENT */
1803 mustCall = (flags & 1);
1804 cm_AFSFidFromFid(&tfid, &scp->fid);
1806 if (!mustCall && cm_HaveCallback(scp))
1809 /* turn off mustCall, since it has now forced us past the check above */
1812 /* otherwise, we have to make an RPC to get the status */
1814 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1815 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1820 cm_StartCallbackGrantingCall(scp, &cbr);
1822 lock_ReleaseWrite(&scp->rw);
1824 /* now make the RPC */
1825 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1826 scp, sfid.volume, sfid.vnode, sfid.unique);
1828 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1832 rxconnp = cm_GetRxConn(connp);
1833 code = RXAFS_FetchStatus(rxconnp, &tfid,
1834 &afsStatus, &callback, &volSync);
1835 rx_PutConnection(rxconnp);
1837 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1839 code = cm_MapRPCError(code, reqp);
1841 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1842 code, scp, scp->fid.volume, scp->fid.vnode);
1844 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1845 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1847 lock_ObtainWrite(&scp->rw);
1849 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1850 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1852 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1855 /* if we got an error, return to caller */
1861 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1864 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1865 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1866 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1868 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1869 scp, scp->fid.cell, scp->fid.volume);
1876 /* called with cm_scacheLock held */
1877 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1879 cm_vol_state_t *statep;
1881 afs_uint32 volID = scp->fid.volume;
1882 cm_serverRef_t *tsrp;
1887 if (scp->cbServerp == NULL)
1890 volp = cm_GetVolumeByFID(&scp->fid);
1894 statep = cm_VolumeStateByID(volp, volID);
1896 if (statep->state == vl_online)
1899 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1900 if (tsrp->status == srv_deleted)
1902 if (cm_ServerEqual(tsrp->server, scp->cbServerp))
1904 if (tsrp->server->downTime > *downTime)
1905 *downTime = tsrp->server->downTime;
1908 /* if the cbServerp does not match the current volume server list
1909 * we report the callback server as up so the callback can be
1912 return(found ? 0 : 1);
1915 /* called periodically by cm_daemon to shut down use of expired callbacks */
1916 void cm_CheckCBExpiration(void)
1920 time_t now, downTime;
1922 osi_Log0(afsd_logp, "CheckCBExpiration");
1925 lock_ObtainWrite(&cm_scacheLock);
1926 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1927 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1929 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1930 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1932 if (volp->cbExpiresRO > scp->cbExpires &&
1935 scp->cbExpires = volp->cbExpiresRO;
1936 if (volp->cbServerpRO != scp->cbServerp) {
1938 cm_PutServer(scp->cbServerp);
1939 cm_GetServer(volp->cbServerpRO);
1940 scp->cbServerp = volp->cbServerpRO;
1946 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1947 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1949 cm_HoldSCacheNoLock(scp);
1950 lock_ReleaseWrite(&cm_scacheLock);
1952 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1953 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1954 lock_ObtainWrite(&scp->rw);
1955 cm_DiscardSCache(scp);
1956 lock_ReleaseWrite(&scp->rw);
1957 cm_CallbackNotifyChange(scp);
1959 lock_ObtainWrite(&cm_scacheLock);
1960 cm_ReleaseSCacheNoLock(scp);
1964 lock_ReleaseWrite(&cm_scacheLock);
1966 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1971 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1975 struct rx_connection * rxconnp;
1977 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1979 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1981 rxconnp = cm_GetRxConn(connp);
1982 rx_SetConnDeadTime(rxconnp, 10);
1983 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1984 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1985 rx_PutConnection(rxconnp);
1989 cm_server_vols_t * tsrvp;
1993 cm_ForceNewConnections(tsp);
1995 lock_ObtainMutex(&tsp->mx);
1996 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1997 tsp->flags |= CM_SERVERFLAG_DOWN;
1998 tsp->downTime = time(NULL);
2000 /* Now update the volume status */
2001 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2002 for (i=0; i<NUM_SERVER_VOLS; i++) {
2003 if (tsrvp->ids[i] != 0) {
2007 lock_ReleaseMutex(&tsp->mx);
2008 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2009 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2010 lock_ObtainMutex(&tsp->mx);
2012 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2018 lock_ReleaseMutex(&tsp->mx);
2024 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
2028 if (!cm_giveUpAllCBs)
2031 lock_ObtainWrite(&cm_serverLock);
2032 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
2033 cm_GetServerNoLock(tsp);
2034 lock_ReleaseWrite(&cm_serverLock);
2035 cm_GiveUpAllCallbacks(tsp, markDown);
2036 lock_ObtainWrite(&cm_serverLock);
2037 cm_PutServerNoLock(tsp);
2039 lock_ReleaseWrite(&cm_serverLock);