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 <afsconfig.h>
11 #include <afs/param.h>
14 #include <afs/afs_args.h>
26 #include <rx_pthread.h>
28 #include <WINNT/syscfg.h>
29 #include <WINNT/afsreg.h>
32 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid);
34 /* read/write lock for all global storage in this module */
35 osi_rwlock_t cm_callbackLock;
37 afs_int32 cm_OfflineROIsValid = 0;
39 afs_int32 cm_giveUpAllCBs = 1;
41 afs_int32 cm_shutdown = 0;
43 #ifdef AFS_FREELANCE_CLIENT
44 extern osi_mutex_t cm_Freelance_Lock;
47 /* count of # of callback breaking messages received by this CM so far. We use
48 * this count in determining whether there have been any callback breaks that
49 * apply to a call that returned a new callback. If the counter doesn't
50 * increase during a call, then we know that no callbacks were broken during
51 * that call, and thus that the callback that was just returned is still valid.
53 long cm_callbackCount;
55 /* count of number of RPCs potentially returning a callback executing now.
56 * When this counter hits zero, we can clear out the racing revokes list, since
57 * at that time, we know that none of the just-executed callback revokes will
58 * apply to any future call that returns a callback (since the latter hasn't
59 * even started execution yet).
61 long cm_activeCallbackGrantingCalls;
63 /* list of callbacks that have been broken recently. If a call returning a
64 * callback is executing and a callback revoke runs immediately after it at the
65 * server, the revoke may end up being processed before the response to the
66 * original callback granting call. We detect this by keeping a list of
67 * callback revokes that have been received since we *started* the callback
68 * granting call, and discarding any callbacks received for the same file ID,
69 * even if the callback revoke was received before the callback grant.
71 cm_racingRevokes_t *cm_racingRevokesp;
73 /* record a (potentially) racing revoke for this file ID; null means for all
74 * file IDs, and is used by InitCallBackState.
76 * The cancelFlags describe whether we're just discarding callbacks for the same
77 * file ID, the same volume, or all from the same server.
79 * Called with no locks held.
81 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
83 cm_racingRevokes_t *rp;
85 lock_ObtainWrite(&cm_callbackLock);
87 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
88 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
90 if (cm_activeCallbackGrantingCalls > 0) {
91 rp = malloc(sizeof(*rp));
92 memset(rp, 0, sizeof(*rp));
93 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
94 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
95 if (fidp) rp->fid = *fidp;
96 rp->callbackCount = ++cm_callbackCount;
98 lock_ReleaseWrite(&cm_callbackLock);
102 * When we lose a callback, may have to send change notification replies.
103 * Do not call with a lock on the scp.
105 void cm_CallbackNotifyChange(cm_scache_t *scp)
111 /* why does this have to query the registry each time? */
112 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
113 AFSREG_CLT_OPENAFS_SUBKEY,
115 KEY_READ|KEY_QUERY_VALUE,
116 &hKey) == ERROR_SUCCESS) {
118 dummyLen = sizeof(DWORD);
119 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
120 (BYTE *) &dwDelay, &dummyLen);
124 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
127 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
128 scp->fileType, scp->flags, dwDelay);
133 /* for directories, this sends a change notification on the dir itself */
134 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
135 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
137 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
138 scp, NULL, NULL, TRUE);
140 /* and for files, this sends a change notification on the file's parent dir */
144 cm_SetFid(&tfid, scp->fid.cell, scp->fid.volume, scp->parentVnode, scp->parentUnique);
145 dscp = cm_FindSCache(&tfid);
147 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
149 FILE_NOTIFY_GENERIC_FILE_FILTER,
150 dscp, NULL, NULL, TRUE);
152 cm_ReleaseSCache(dscp);
156 /* called with no locks held for every file ID that is revoked directly by
157 * a callback revoke call. Does not have to handle volume callback breaks,
158 * since those have already been split out.
160 * The callp parameter is currently unused.
162 void cm_RevokeCallback(struct rx_call *callp, cm_cell_t * cellp, AFSFid *fidp)
168 tfid.cell = cellp ? cellp->cellID : 0;
169 tfid.volume = fidp->Volume;
170 tfid.vnode = fidp->Vnode;
171 tfid.unique = fidp->Unique;
172 hash = CM_SCACHE_HASH(&tfid);
174 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
175 fidp->Volume, fidp->Vnode, fidp->Unique);
177 /* do this first, so that if we're executing a callback granting call
178 * at this moment, we kill it before it can be merged in. Otherwise,
179 * it could complete while we're doing the scan below, and get missed
180 * by both the scan and by this code.
182 cm_RecordRacingRevoke(&tfid, 0);
184 lock_ObtainWrite(&cm_scacheLock);
185 /* do all in the hash bucket, since we don't know how many we'll find with
188 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
189 if (scp->fid.volume == tfid.volume &&
190 scp->fid.vnode == tfid.vnode &&
191 scp->fid.unique == tfid.unique &&
192 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
193 cm_HaveCallback(scp))
195 cm_HoldSCacheNoLock(scp);
196 lock_ReleaseWrite(&cm_scacheLock);
197 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
198 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
201 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
202 scp->fid.hash, scp->fileType, AFS_INVALIDATE_CALLBACK);
204 lock_ObtainWrite(&scp->rw);
205 cm_DiscardSCache(scp);
206 lock_ReleaseWrite(&scp->rw);
208 cm_CallbackNotifyChange(scp);
210 lock_ObtainWrite(&cm_scacheLock);
211 cm_ReleaseSCacheNoLock(scp);
214 lock_ReleaseWrite(&cm_scacheLock);
216 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
217 fidp->Volume, fidp->Vnode, fidp->Unique);
221 cm_callbackDiscardROVolumeByFID(cm_fid_t *fidp)
223 cm_volume_t *volp = cm_GetVolumeByFID(fidp);
226 if (volp->cbExpiresRO) {
227 volp->cbExpiresRO = 0;
228 if (volp->cbServerpRO) {
229 cm_PutServer(volp->cbServerpRO);
230 volp->cbServerpRO = NULL;
232 volp->creationDateRO = 0;
237 /* called to revoke a volume callback, which is typically issued when a volume
238 * is moved from one server to another.
240 * Called with no locks held.
242 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
248 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %u", fidp->Volume);
250 /* do this first, so that if we're executing a callback granting call
251 * at this moment, we kill it before it can be merged in. Otherwise,
252 * it could complete while we're doing the scan below, and get missed
253 * by both the scan and by this code.
255 tfid.cell = cellp ? cellp->cellID : 0;
256 tfid.volume = fidp->Volume;
257 tfid.vnode = tfid.unique = 0;
258 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
260 lock_ObtainWrite(&cm_scacheLock);
261 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
262 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
263 if (scp->fid.volume == fidp->Volume &&
264 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
265 scp->cbExpires > 0 &&
266 scp->cbServerp != NULL) {
267 cm_HoldSCacheNoLock(scp);
268 lock_ReleaseWrite(&cm_scacheLock);
270 lock_ObtainWrite(&scp->rw);
271 osi_Log5(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
272 scp, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
273 osi_Log2(afsd_logp, ".... dv 0x%x:%x",
274 (afs_uint32)((scp->dataVersion >> 32) & 0xFFFFFFFF),
275 (afs_uint32)(scp->dataVersion & 0xFFFFFFFF));
277 cm_DiscardSCache(scp);
278 lock_ReleaseWrite(&scp->rw);
281 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
282 scp->fid.hash, scp->fileType, AFS_INVALIDATE_CALLBACK);
284 cm_CallbackNotifyChange(scp);
285 lock_ObtainWrite(&cm_scacheLock);
286 cm_ReleaseSCacheNoLock(scp);
287 if (scp->flags & CM_SCACHEFLAG_PURERO)
288 cm_callbackDiscardROVolumeByFID(&scp->fid);
290 } /* search one hash bucket */
291 } /* search all hash buckets */
293 lock_ReleaseWrite(&cm_scacheLock);
295 if (cellp && RDR_Initialized)
296 RDR_InvalidateVolume(cellp->cellID, fidp->Volume, AFS_INVALIDATE_CALLBACK);
298 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
302 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
303 * given data pointer, without triggering "cast truncates pointer"
304 * warnings. We use this where we explicitly don't care whether a
305 * pointer is truncated -- it loses information where a pointer is
306 * larger than an afs_int32.
310 afs_data_pointer_to_int32(const void *p)
313 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
317 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
322 /* used to determine the byte order of the system */
325 char c[sizeof(int) / sizeof(char)];
331 /* little-endian system */
334 /* big-endian system */
335 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
340 return ip.i32[i32_sub];
342 /*------------------------------------------------------------------------
343 * EXPORTED SRXAFSCB_CallBack
346 * Routine called by the server-side callback RPC interface to
347 * implement passing in callback information.
351 * rx_call : Ptr to Rx call on which this request came in.
352 * fidsArrayp : Ptr to array of fids involved.
353 * cbsArrayp : Ptr to matching callback info for the fids.
359 * Nothing interesting.
363 *------------------------------------------------------------------------*/
364 /* handle incoming RPC callback breaking message.
365 * Called with no locks held.
368 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
372 struct rx_connection *connp;
373 struct rx_peer *peerp;
374 unsigned long host = 0;
375 unsigned short port = 0;
376 cm_server_t *tsp = NULL;
377 cm_cell_t* cellp = NULL;
382 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
383 host = rx_HostOf(peerp);
384 port = rx_PortOf(peerp);
386 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
393 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
397 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
400 cellp->name /* does not need to be saved, doesn't change */);
402 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
406 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
407 tfidp = &fidsArrayp->AFSCBFids_val[i];
409 if (tfidp->Volume == 0)
410 continue; /* means don't do anything */
411 else if (tfidp->Vnode == 0)
412 cm_RevokeVolumeCallback(callp, cellp, tfidp);
414 cm_RevokeCallback(callp, cellp, tfidp);
419 /*------------------------------------------------------------------------
420 * EXPORTED SRXAFSCB_InitCallBackState
423 * Routine called by the server-side callback RPC interface to
424 * implement clearing all callbacks from this host.
427 * rx_call : Ptr to Rx call on which this request came in.
433 * Nothing interesting.
437 *------------------------------------------------------------------------*/
438 /* called with no locks by RPC system when a server indicates that it has never
439 * heard from us, or for other reasons has had to discard callbacks from us
440 * without telling us, e.g. a network partition.
443 SRXAFSCB_InitCallBackState(struct rx_call *callp)
448 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState ->");
450 return SRXAFSCB_InitCallBackState3(callp, NULL);
453 /*------------------------------------------------------------------------
454 * EXPORTED SRXAFSCB_Probe
457 * Routine called by the server-side callback RPC interface to
458 * implement ``probing'' the Cache Manager, just making sure it's
462 * rx_call : Ptr to Rx call on which this request came in.
468 * Nothing interesting.
472 *------------------------------------------------------------------------*/
474 SRXAFSCB_Probe(struct rx_call *callp)
476 struct rx_connection *connp;
477 struct rx_peer *peerp;
478 unsigned long host = 0;
479 unsigned short port = 0;
484 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
485 host = rx_HostOf(peerp);
486 port = rx_PortOf(peerp);
489 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
496 /*------------------------------------------------------------------------
497 * EXPORTED SRXAFSCB_GetLock
500 * Routine called by the server-side callback RPC interface to
501 * implement pulling out the contents of a lock in the lock
505 * a_call : Ptr to Rx call on which this request came in.
506 * a_index : Index of desired lock.
507 * a_result : Ptr to a buffer for the given lock.
510 * 0 if everything went fine,
511 * 1 if we were given a bad index.
514 * Nothing interesting.
518 *------------------------------------------------------------------------*/
519 /* debug interface */
521 extern osi_rwlock_t cm_aclLock;
522 extern osi_rwlock_t buf_globalLock;
523 extern osi_rwlock_t cm_cellLock;
524 extern osi_rwlock_t cm_connLock;
525 extern osi_rwlock_t cm_daemonLock;
526 extern osi_rwlock_t cm_dnlcLock;
527 extern osi_rwlock_t cm_scacheLock;
528 extern osi_rwlock_t cm_serverLock;
529 extern osi_rwlock_t cm_syscfgLock;
530 extern osi_rwlock_t cm_userLock;
531 extern osi_rwlock_t cm_utilsLock;
532 extern osi_rwlock_t cm_volumeLock;
533 extern osi_rwlock_t smb_globalLock;
534 extern osi_rwlock_t smb_rctLock;
536 extern osi_mutex_t cm_Freelance_Lock;
537 extern osi_mutex_t cm_Afsdsbmt_Lock;
538 extern osi_mutex_t tokenEventLock;
539 extern osi_mutex_t smb_ListenerLock;
540 extern osi_mutex_t smb_RawBufLock;
541 extern osi_mutex_t smb_Dir_Watch_Lock;
543 #define LOCKTYPE_RW 1
544 #define LOCKTYPE_MUTEX 2
545 static struct _ltable {
550 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
551 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
552 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
553 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
554 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
555 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
556 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
557 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
558 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
559 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
560 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
561 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
562 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
563 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
564 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
565 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
566 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
567 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
568 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
569 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
570 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
574 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
576 struct _ltable *tl; /*Ptr to lock table entry */
579 int nentries; /*Num entries in table */
580 int code; /*Return code */
581 struct rx_connection *connp;
582 struct rx_peer *peerp;
583 unsigned long host = 0;
584 unsigned short port = 0;
589 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
590 host = rx_HostOf(peerp);
591 port = rx_PortOf(peerp);
594 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
595 index, ntohl(host), ntohs(port));
597 nentries = sizeof(ltable) / sizeof(struct _ltable);
598 if (index < 0 || index >= nentries) {
605 * Found it - copy out its contents.
608 strncpy(lockp->name, tl->name, sizeof(lockp->name));
609 lockp->name[sizeof(lockp->name)-1] = '\0';
610 lockp->lock.waitStates = 0;
611 switch ( tl->type ) {
613 rwp = (osi_rwlock_t *)tl->addr;
614 lockp->lock.exclLocked = rwp->flags;
615 lockp->lock.readersReading = rwp->readers;
616 lockp->lock.numWaiting = rwp->waiters;
619 mtxp = (osi_mutex_t *)tl->addr;
620 lockp->lock.exclLocked = mtxp->flags;
621 lockp->lock.readersReading = 0;
622 lockp->lock.numWaiting = mtxp->waiters;
625 lockp->lock.pid_last_reader = 0;
626 lockp->lock.pid_writer = 0;
627 lockp->lock.src_indicator = 0;
634 /* debug interface */
636 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
641 struct rx_connection *connp;
642 struct rx_peer *peerp;
643 unsigned long host = 0;
644 unsigned short port = 0;
649 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
650 host = rx_HostOf(peerp);
651 port = rx_PortOf(peerp);
654 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
655 ntohl(host), ntohs(port));
657 lock_ObtainRead(&cm_scacheLock);
658 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
659 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
663 } /*Zip through current hash chain */
664 } /*Zip through hash chains */
674 * Copy out the located entry.
676 memset(cep, 0, sizeof(AFSDBCacheEntry));
677 cep->addr = afs_data_pointer_to_int32(scp);
678 cep->cell = scp->fid.cell;
679 cep->netFid.Volume = scp->fid.volume;
680 cep->netFid.Vnode = scp->fid.vnode;
681 cep->netFid.Unique = scp->fid.unique;
682 cep->lock.waitStates = 0;
683 cep->lock.exclLocked = scp->rw.flags;
684 cep->lock.readersReading = 0;
685 cep->lock.numWaiting = scp->rw.waiters;
686 cep->lock.pid_last_reader = 0;
687 cep->lock.pid_writer = 0;
688 cep->lock.src_indicator = 0;
689 cep->Length = scp->length.LowPart;
690 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
691 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
692 if (scp->flags & CM_SCACHEFLAG_PURERO) {
693 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
695 cep->cbExpires = volp->cbExpiresRO;
699 /* TODO: deal with time_t below */
700 cep->cbExpires = (afs_int32) scp->cbExpires;
702 cep->refCount = scp->refCount;
703 cep->opens = scp->openReads;
704 cep->writers = scp->openWrites;
705 switch (scp->fileType) {
706 case CM_SCACHETYPE_FILE:
709 case CM_SCACHETYPE_MOUNTPOINT:
712 case CM_SCACHETYPE_DIRECTORY:
713 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
718 case CM_SCACHETYPE_SYMLINK:
721 case CM_SCACHETYPE_DFSLINK:
724 case CM_SCACHETYPE_INVALID:
729 if (scp->flags & CM_SCACHEFLAG_STATD)
731 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
733 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
734 scp->mountPointStringp[0])
736 if (scp->flags & CM_SCACHEFLAG_WAITING)
741 * Return our results.
744 lock_ReleaseRead(&cm_scacheLock);
749 /* debug interface */
751 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
756 struct rx_connection *connp;
757 struct rx_peer *peerp;
758 unsigned long host = 0;
759 unsigned short port = 0;
764 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
765 host = rx_HostOf(peerp);
766 port = rx_PortOf(peerp);
769 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
770 ntohl(host), ntohs(port));
772 lock_ObtainRead(&cm_scacheLock);
773 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
774 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
778 } /*Zip through current hash chain */
779 } /*Zip through hash chains */
789 * Copy out the located entry.
791 memset(cep, 0, sizeof(AFSDBCacheEntry64));
792 cep->addr = afs_data_pointer_to_int32(scp);
793 cep->cell = scp->fid.cell;
794 cep->netFid.Volume = scp->fid.volume;
795 cep->netFid.Vnode = scp->fid.vnode;
796 cep->netFid.Unique = scp->fid.unique;
797 cep->lock.waitStates = 0;
798 cep->lock.exclLocked = scp->rw.flags;
799 cep->lock.readersReading = 0;
800 cep->lock.numWaiting = scp->rw.waiters;
801 cep->lock.pid_last_reader = 0;
802 cep->lock.pid_writer = 0;
803 cep->lock.src_indicator = 0;
804 cep->Length = (afs_int64) scp->length.QuadPart;
805 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
806 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
807 if (scp->flags & CM_SCACHEFLAG_PURERO) {
808 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
810 cep->cbExpires = volp->cbExpiresRO;
814 /* TODO: handle time_t */
815 cep->cbExpires = (afs_int32) scp->cbExpires;
817 cep->refCount = scp->refCount;
818 cep->opens = scp->openReads;
819 cep->writers = scp->openWrites;
820 switch (scp->fileType) {
821 case CM_SCACHETYPE_FILE:
824 case CM_SCACHETYPE_MOUNTPOINT:
827 case CM_SCACHETYPE_DIRECTORY:
828 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
833 case CM_SCACHETYPE_SYMLINK:
836 case CM_SCACHETYPE_DFSLINK:
839 case CM_SCACHETYPE_INVALID:
844 if (scp->flags & CM_SCACHEFLAG_STATD)
846 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
848 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
849 scp->mountPointStringp[0])
851 if (scp->flags & CM_SCACHEFLAG_WAITING)
856 * Return our results.
859 lock_ReleaseRead(&cm_scacheLock);
864 /* debug interface: not implemented */
866 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
868 struct rx_connection *connp;
869 struct rx_peer *peerp;
870 unsigned long host = 0;
871 unsigned short port = 0;
876 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
877 host = rx_HostOf(peerp);
878 port = rx_PortOf(peerp);
881 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
882 ntohl(host), ntohs(port));
888 /* debug interface: not implemented */
890 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
891 AFSCB_CollData *datap)
893 struct rx_connection *connp;
894 struct rx_peer *peerp;
895 unsigned long host = 0;
896 unsigned short port = 0;
901 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
902 host = rx_HostOf(peerp);
903 port = rx_PortOf(peerp);
906 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
907 ntohl(host), ntohs(port));
913 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
918 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
920 return SRXAFSCB_InitCallBackState3(callp, NULL);
923 /* debug interface */
925 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
929 struct rx_connection *connp;
930 struct rx_peer *peerp;
931 unsigned long host = 0;
932 unsigned short port = 0;
937 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
938 host = rx_HostOf(peerp);
939 port = rx_PortOf(peerp);
942 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
946 lock_ObtainRead(&cm_syscfgLock);
947 if (cm_LanAdapterChangeDetected) {
948 lock_ConvertRToW(&cm_syscfgLock);
949 if (cm_LanAdapterChangeDetected) {
950 /* get network related info */
951 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
952 code = syscfg_GetIFInfo(&cm_noIPAddr,
953 cm_IPAddr, cm_SubnetMask,
954 cm_NetMtu, cm_NetFlags);
955 cm_LanAdapterChangeDetected = 0;
957 lock_ConvertWToR(&cm_syscfgLock);
960 /* return all network interface addresses */
961 addr->numberOfInterfaces = cm_noIPAddr;
962 addr->uuid = cm_data.Uuid;
963 for ( i=0; i < cm_noIPAddr; i++ ) {
964 addr->addr_in[i] = cm_IPAddr[i];
965 addr->subnetmask[i] = cm_SubnetMask[i];
966 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
967 cm_NetMtu[i] : rx_mtu;
970 lock_ReleaseRead(&cm_syscfgLock);
976 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
980 cm_server_t *tsp = NULL;
981 cm_scache_t *scp = NULL;
982 cm_cell_t* cellp = NULL;
985 struct rx_connection *connp;
986 struct rx_peer *peerp;
987 unsigned long host = 0;
988 unsigned short port = 0;
993 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
994 host = rx_HostOf(peerp);
995 port = rx_PortOf(peerp);
998 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
999 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 Uuid%s ->",osi_LogSaveString(afsd_logp,p));
1003 tsp = cm_FindServerByUuid(serverUuid, CM_SERVER_FILE, FALSE);
1006 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
1013 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d",
1017 osi_Log3(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d for cell %s",
1020 cellp->name /* does not need to be saved, doesn't change */);
1022 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 from unknown host");
1025 if (connp && peerp) {
1026 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
1028 osi_Log1(afsd_logp, "InitCallbackState3 server %x", tsp);
1030 /* record the callback in the racing revokes structure. This
1031 * shouldn't be necessary, since we shouldn't be making callback
1032 * granting calls while we're going to get an initstate call,
1033 * but there probably are some obscure races, so better safe
1036 * We do this first since we don't hold the cm_scacheLock and vnode
1037 * locks over the entire callback scan operation below. The
1038 * big loop below is guaranteed to hit any callback already
1039 * processed. The call to RecordRacingRevoke is guaranteed
1040 * to kill any callback that is currently being returned.
1041 * Anything that sneaks past both must start
1042 * after the call to RecordRacingRevoke.
1047 fid.cell = cellp->cellID;
1048 fid.volume = fid.vnode = fid.unique = 0;
1050 cm_RecordRacingRevoke(&fid, CM_RACINGFLAG_CANCELALL);
1052 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
1055 /* now search all vnodes looking for guys with this callback, if we
1056 * found it, or guys with any callbacks, if we didn't find the server
1057 * (that's how multihomed machines will appear and how we'll handle
1058 * them, albeit a little inefficiently). That is, we're discarding all
1059 * callbacks from all hosts if we get an initstate call from an unknown
1060 * host. Since these calls are rare, and multihomed servers
1061 * are "rare," hopefully this won't be a problem.
1063 lock_ObtainWrite(&cm_scacheLock);
1064 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
1065 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
1066 cm_HoldSCacheNoLock(scp);
1067 lock_ReleaseWrite(&cm_scacheLock);
1068 lock_ObtainWrite(&scp->rw);
1070 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
1071 /* we have a callback, now decide if we should clear it */
1072 if (cm_ServerEqual(scp->cbServerp, tsp)) {
1073 osi_Log4(afsd_logp, "InitCallbackState3 Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1074 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1075 cm_DiscardSCache(scp);
1079 lock_ReleaseWrite(&scp->rw);
1081 cm_CallbackNotifyChange(scp);
1082 if (RDR_Initialized)
1083 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
1084 scp->fid.hash, scp->fileType, AFS_INVALIDATE_EXPIRED);
1086 lock_ObtainWrite(&cm_scacheLock);
1087 cm_ReleaseSCacheNoLock(scp);
1089 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO))
1090 cm_callbackDiscardROVolumeByFID(&scp->fid);
1092 } /* search one hash bucket */
1093 } /* search all hash buckets */
1095 lock_ReleaseWrite(&cm_scacheLock);
1098 /* reset the No flags on the server */
1099 cm_SetServerNo64Bit(tsp, 0);
1100 cm_SetServerNoInlineBulk(tsp, 0);
1102 /* we're done with the server structure */
1109 /* debug interface */
1111 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1113 struct rx_connection *connp;
1114 struct rx_peer *peerp;
1115 unsigned long host = 0;
1116 unsigned short port = 0;
1123 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1124 host = rx_HostOf(peerp);
1125 port = rx_PortOf(peerp);
1128 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1129 UuidToString((UUID *)&cm_data.Uuid, &p);
1130 UuidToString((UUID *)clientUuid, &q);
1131 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1132 osi_LogSaveString(afsd_logp,p),
1133 osi_LogSaveString(afsd_logp,q),
1139 code = 1; /* failure */
1141 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1148 /* debug interface */
1150 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1154 cm_serverRef_t * serverRefp;
1156 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1158 *a_name = strdup("");
1162 lock_ObtainRead(&cm_serverLock);
1163 *a_name = strdup(cellp->name);
1165 for ( sn = 0, serverRefp = cellp->vlServersp;
1166 sn < AFSMAXCELLHOSTS && serverRefp;
1167 sn++, serverRefp = serverRefp->next);
1169 a_hosts->serverList_len = sn;
1170 a_hosts->serverList_val = (afs_int32 *)xdr_alloc(sn * sizeof(afs_int32));
1172 for ( sn = 0, serverRefp = cellp->vlServersp;
1173 sn < AFSMAXCELLHOSTS && serverRefp;
1174 sn++, serverRefp = serverRefp->next)
1176 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1179 lock_ReleaseRead(&cm_serverLock);
1183 /* debug interface */
1185 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1186 char **a_name, serverList *a_hosts)
1188 struct rx_connection *connp;
1189 struct rx_peer *peerp;
1190 unsigned long host = 0;
1191 unsigned short port = 0;
1197 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1198 host = rx_HostOf(peerp);
1199 port = rx_PortOf(peerp);
1202 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1203 a_cellnum, ntohl(host), ntohs(port));
1205 a_hosts->serverList_val = 0;
1206 a_hosts->serverList_len = 0;
1209 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1214 /* debug interface */
1216 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1217 struct interfaceAddr *addr,
1218 Capabilities * capabilities)
1221 afs_uint32 *dataBuffP;
1222 afs_int32 dataBytes;
1224 struct rx_connection *connp;
1225 struct rx_peer *peerp;
1226 unsigned long host = 0;
1227 unsigned short port = 0;
1232 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1233 host = rx_HostOf(peerp);
1234 port = rx_PortOf(peerp);
1237 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1241 lock_ObtainRead(&cm_syscfgLock);
1242 if (cm_LanAdapterChangeDetected) {
1243 lock_ConvertRToW(&cm_syscfgLock);
1244 if (cm_LanAdapterChangeDetected) {
1245 /* get network related info */
1246 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1247 code = syscfg_GetIFInfo(&cm_noIPAddr,
1248 cm_IPAddr, cm_SubnetMask,
1249 cm_NetMtu, cm_NetFlags);
1250 cm_LanAdapterChangeDetected = 0;
1252 lock_ConvertWToR(&cm_syscfgLock);
1255 /* return all network interface addresses */
1256 addr->numberOfInterfaces = cm_noIPAddr;
1257 addr->uuid = cm_data.Uuid;
1258 for ( i=0; i < cm_noIPAddr; i++ ) {
1259 addr->addr_in[i] = cm_IPAddr[i];
1260 addr->subnetmask[i] = cm_SubnetMask[i];
1261 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1262 cm_NetMtu[i] : rx_mtu;
1264 lock_ReleaseRead(&cm_syscfgLock);
1266 dataBytes = 1 * sizeof(afs_uint32);
1267 dataBuffP = (afs_uint32 *) xdr_alloc(dataBytes);
1268 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1269 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1270 capabilities->Capabilities_val = dataBuffP;
1275 /*------------------------------------------------------------------------
1276 * EXPORTED SRXAFSCB_GetServerPrefs
1279 * Routine to list server preferences used by this client.
1282 * a_call : Ptr to Rx call on which this request came in.
1283 * a_index : Input server index
1284 * a_srvr_addr : Output server address (0xffffffff on last server)
1285 * a_srvr_rank : Output server rank
1291 * Nothing interesting.
1295 *------------------------------------------------------------------------*/
1297 int SRXAFSCB_GetServerPrefs(
1298 struct rx_call *callp,
1300 afs_int32 *a_srvr_addr,
1301 afs_int32 *a_srvr_rank)
1303 struct rx_connection *connp;
1304 struct rx_peer *peerp;
1305 unsigned long host = 0;
1306 unsigned short port = 0;
1311 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1312 host = rx_HostOf(peerp);
1313 port = rx_PortOf(peerp);
1316 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1320 *a_srvr_addr = 0xffffffff;
1321 *a_srvr_rank = 0xffffffff;
1326 /*------------------------------------------------------------------------
1327 * EXPORTED SRXAFSCB_GetCellServDB
1330 * Routine to list cells configured for this client
1333 * a_call : Ptr to Rx call on which this request came in.
1334 * a_index : Input cell index
1335 * a_name : Output cell name ("" on last cell)
1336 * a_hosts : Output cell database servers
1342 * Nothing interesting.
1346 *------------------------------------------------------------------------*/
1348 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1349 serverList *a_hosts)
1351 struct rx_connection *connp;
1352 struct rx_peer *peerp;
1353 unsigned long host = 0;
1354 unsigned short port = 0;
1360 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1361 host = rx_HostOf(peerp);
1362 port = rx_PortOf(peerp);
1365 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1366 ntohl(host), ntohs(port));
1368 #ifdef AFS_FREELANCE_CLIENT
1369 if (cm_freelanceEnabled && index == 0) {
1370 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1374 rc = GetCellCommon(index+1, a_name, a_hosts);
1379 /*------------------------------------------------------------------------
1380 * EXPORTED SRXAFSCB_GetLocalCell
1383 * Routine to return name of client's local cell
1386 * a_call : Ptr to Rx call on which this request came in.
1387 * a_name : Output cell name
1393 * Nothing interesting.
1397 *------------------------------------------------------------------------*/
1399 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1402 struct rx_connection *connp;
1403 struct rx_peer *peerp;
1404 unsigned long host = 0;
1405 unsigned short port = 0;
1410 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1411 host = rx_HostOf(peerp);
1412 port = rx_PortOf(peerp);
1415 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1416 ntohl(host), ntohs(port));
1418 if (cm_data.rootCellp) {
1419 t_name = strdup(cm_data.rootCellp->name);
1421 t_name = (char *)xdr_alloc(1);
1431 * afs_MarshallCacheConfig - marshall client cache configuration
1435 * IN callerVersion - the rpc stat version of the caller.
1437 * IN config - client cache configuration.
1439 * OUT ptr - buffer where configuration is marshalled.
1445 static void afs_MarshallCacheConfig(
1446 afs_uint32 callerVersion,
1447 cm_initparams_v1 *config,
1451 * We currently only support version 1.
1453 *(ptr++) = config->nChunkFiles;
1454 *(ptr++) = config->nStatCaches;
1455 *(ptr++) = config->nDataCaches;
1456 *(ptr++) = config->nVolumeCaches;
1457 *(ptr++) = config->firstChunkSize;
1458 *(ptr++) = config->otherChunkSize;
1459 *(ptr++) = config->cacheSize;
1460 *(ptr++) = config->setTime;
1461 *(ptr++) = config->memCache;
1466 /*------------------------------------------------------------------------
1467 * EXPORTED SRXAFSCB_GetCacheConfig
1470 * Routine to return parameters used to initialize client cache.
1471 * Client may request any format version. Server may not return
1472 * format version greater than version requested by client.
1475 * a_call: Ptr to Rx call on which this request came in.
1476 * callerVersion: Data format version desired by the client.
1477 * serverVersion: Data format version of output data.
1478 * configCount: Number bytes allocated for output data.
1479 * config: Client cache configuration.
1485 * Nothing interesting.
1489 *------------------------------------------------------------------------*/
1491 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1492 afs_uint32 callerVersion,
1493 afs_uint32 *serverVersion,
1494 afs_uint32 *configCount,
1495 cacheConfig *config)
1497 afs_uint32 *t_config;
1499 extern cm_initparams_v1 cm_initParams;
1500 struct rx_connection *connp;
1501 struct rx_peer *peerp;
1502 unsigned long host = 0;
1503 unsigned short port = 0;
1508 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1509 host = rx_HostOf(peerp);
1510 port = rx_PortOf(peerp);
1513 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1514 ntohl(host), ntohs(port));
1517 * Currently only support version 1
1519 allocsize = sizeof(cm_initparams_v1);
1520 t_config = (afs_uint32 *)xdr_alloc(allocsize);
1522 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1524 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1527 #define SIZE_MAX UINT_MAX
1529 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1531 *configCount = (afs_uint32)allocsize;
1532 config->cacheConfig_val = t_config;
1533 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1538 /* called by afsd without any locks to initialize this module */
1539 void cm_InitCallback(void)
1541 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1542 cm_activeCallbackGrantingCalls = 0;
1545 /* called with locked scp; tells us whether we've got a callback.
1546 * Expirations are checked by a background daemon so as to make
1547 * this function as inexpensive as possible
1549 int cm_HaveCallback(cm_scache_t *scp)
1551 #ifdef AFS_FREELANCE_CLIENT
1552 if (cm_freelanceEnabled &&
1553 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1554 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1555 if (cm_getLocalMountPointChange()) {
1556 cm_clearLocalMountPointChange();
1557 lock_ReleaseWrite(&scp->rw);
1558 cm_reInitLocalMountPoints();
1559 lock_ObtainWrite(&scp->rw);
1561 return (cm_data.fakeDirVersion == scp->dataVersion);
1564 if (cm_readonlyVolumeVersioning &&
1565 (scp->flags & CM_SCACHEFLAG_PURERO)) {
1566 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1569 if (cm_OfflineROIsValid) {
1570 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1578 if (cm_readonlyVolumeVersioning &&
1580 volp->creationDateRO == scp->volumeCreationDate &&
1581 volp->cbServerpRO != NULL) {
1588 if (scp->cbServerp != NULL)
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, AFSVolSync *volSyncp, 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_callbackDiscardROVolumeByFID(&scp->fid);
1711 /* if we freed the list, zap the pointer to it */
1713 cm_racingRevokesp = NULL;
1715 lock_ReleaseWrite(&cm_callbackLock);
1718 cm_DiscardSCache(scp);
1719 lock_ReleaseWrite(&scp->rw);
1720 cm_CallbackNotifyChange(scp);
1721 if (RDR_Initialized)
1722 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
1723 scp->fid.hash, scp->fileType, AFS_INVALIDATE_CALLBACK);
1724 lock_ObtainWrite(&scp->rw);
1726 if (scp && scp->flags & CM_SCACHEFLAG_PURERO) {
1727 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1730 lock_ObtainWrite(&cm_scacheLock);
1731 volp->cbExpiresRO = scp->cbExpires;
1732 volp->creationDateRO = volSyncp->spare1;
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;
1739 lock_ReleaseWrite(&cm_scacheLock);
1747 lock_ObtainWrite(&cm_serverLock);
1748 cm_FreeServer(serverp);
1749 lock_ReleaseWrite(&cm_serverLock);
1753 /* if flags is 1, we want to force the code to make one call, anyway.
1754 * called with locked scp; returns with same.
1756 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1757 struct cm_req *reqp, long flags)
1760 cm_conn_t *connp = NULL;
1761 AFSFetchStatus afsStatus;
1763 AFSCallBack callback;
1765 cm_callbackRequest_t cbr;
1768 struct rx_connection * rxconnp = NULL;
1769 int syncop_done = 0;
1771 memset(&volSync, 0, sizeof(volSync));
1773 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1774 scp, scp->fid.cell, scp->fid.volume, flags);
1776 #ifdef AFS_FREELANCE_CLIENT
1777 // The case where a callback is needed on /afs is handled
1778 // specially. We need to fetch the status by calling
1780 if (cm_freelanceEnabled &&
1781 (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1782 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)) {
1784 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1785 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1790 if (scp->dataVersion != cm_data.fakeDirVersion) {
1791 memset(&afsStatus, 0, sizeof(afsStatus));
1792 memset(&volSync, 0, sizeof(volSync));
1793 InterlockedIncrement(&scp->activeRPCs);
1795 // Fetch the status info
1796 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1800 #endif /* AFS_FREELANCE_CLIENT */
1802 mustCall = (flags & 1);
1803 cm_AFSFidFromFid(&tfid, &scp->fid);
1805 if (!mustCall && cm_HaveCallback(scp))
1808 /* turn off mustCall, since it has now forced us past the check above */
1811 /* otherwise, we have to make an RPC to get the status */
1813 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1814 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1819 cm_StartCallbackGrantingCall(scp, &cbr);
1821 lock_ReleaseWrite(&scp->rw);
1823 /* now make the RPC */
1824 InterlockedIncrement(&scp->activeRPCs);
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, &volSync, 0);
1850 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1852 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, NULL, 0);
1853 InterlockedDecrement(&scp->activeRPCs);
1856 /* if we got an error, return to caller */
1863 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1866 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1867 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1868 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1870 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1871 scp, scp->fid.cell, scp->fid.volume);
1879 * cm_CBServersDownTime() returns 1 if the downTime parameter is valid.
1881 * Servers with multiple interfaces have multiple cm_server_t objects
1882 * which share the same UUID. If one interface is down but others are up,
1883 * the server should not be considered down. The returned downTime should
1884 * be the largest non-zero value if down or zero if up. If the cbServerp
1885 * is down, it is updated to refer to an interface that is up (if one exists).
1887 * called with cm_scacheLock held
1890 cm_CBServersDownTime(cm_scache_t *scp, cm_volume_t *volp, time_t * pdownTime)
1892 cm_vol_state_t *statep;
1893 cm_serverRef_t *tsrp;
1895 time_t downTime = 0;
1896 cm_server_t * upserver = NULL;
1897 cm_server_t * downserver;
1901 if (scp->cbServerp == NULL)
1904 if (!(scp->cbServerp->flags & CM_SERVERFLAG_DOWN))
1907 statep = cm_VolumeStateByID(volp, scp->fid.volume);
1909 for (tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1910 if (tsrp->status == srv_deleted)
1913 if (!cm_ServerEqual(tsrp->server, scp->cbServerp))
1916 if (!(tsrp->server->flags & CM_SERVERFLAG_DOWN)) {
1919 upserver = tsrp->server;
1920 cm_GetServer(upserver);
1924 if (tsrp->server->downTime > downTime)
1925 downTime = tsrp->server->downTime;
1928 downTime = scp->cbServerp->downTime;
1931 /* if the cbServerp does not match the current volume server list
1932 * we report the callback server as up so the callback can be
1937 *pdownTime = downTime;
1939 lock_ObtainWrite(&scp->rw);
1940 downserver = scp->cbServerp;
1941 scp->cbServerp = upserver;
1942 lock_ReleaseWrite(&scp->rw);
1943 cm_PutServer(downserver);
1948 /* called periodically by cm_daemon to shut down use of expired callbacks */
1949 void cm_CheckCBExpiration(void)
1954 enum volstatus volstate;
1955 time_t now, downTime;
1957 osi_Log0(afsd_logp, "CheckCBExpiration");
1960 lock_ObtainWrite(&cm_scacheLock);
1961 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1962 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1964 cm_HoldSCacheNoLock(scp);
1965 lock_ReleaseWrite(&cm_scacheLock);
1968 * If this is not a PURERO object and there is no callback
1969 * or it hasn't expired, there is nothing to do
1971 if (!(scp->flags & CM_SCACHEFLAG_PURERO) &&
1972 (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires))
1976 * Determine the volume state and update the callback info
1977 * to the latest if it is a PURERO object.
1979 volp = cm_GetVolumeByFID(&scp->fid);
1980 volstate = vl_unknown;
1983 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1984 volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1986 lock_ObtainWrite(&scp->rw);
1987 scp->cbExpires = volp->cbExpiresRO;
1988 if (volp->cbServerpRO != scp->cbServerp) {
1990 cm_PutServer(scp->cbServerp);
1991 cm_GetServer(volp->cbServerpRO);
1992 scp->cbServerp = volp->cbServerpRO;
1994 lock_ReleaseWrite(&scp->rw);
1996 volstate = cm_GetVolumeStatus(volp, scp->fid.volume);
1999 /* If there is no callback or it hasn't expired, there is nothing to do */
2000 if (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires)
2003 /* If the volume is known not to be online, do not expire the callback */
2004 if (volstate != vl_online)
2008 * If all the servers are down and the callback expired after the
2009 * issuing server went down, do not expire the callback
2011 if (cm_CBServersDownTime(scp, volp, &downTime) && downTime && downTime < scp->cbExpires)
2014 /* The callback has expired, discard the status info */
2015 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
2016 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
2017 lock_ObtainWrite(&scp->rw);
2018 cm_DiscardSCache(scp);
2019 lock_ReleaseWrite(&scp->rw);
2021 if (RDR_Initialized)
2022 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
2023 scp->fid.hash, scp->fileType, AFS_INVALIDATE_EXPIRED);
2025 cm_CallbackNotifyChange(scp);
2031 lock_ObtainWrite(&cm_scacheLock);
2032 cm_ReleaseSCacheNoLock(scp);
2035 lock_ReleaseWrite(&cm_scacheLock);
2037 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
2042 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
2046 struct rx_connection * rxconnp;
2048 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
2050 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
2052 rxconnp = cm_GetRxConn(connp);
2053 rx_SetConnDeadTime(rxconnp, 10);
2054 code = RXAFS_GiveUpAllCallBacks(rxconnp);
2055 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
2056 rx_PutConnection(rxconnp);
2060 cm_server_vols_t * tsrvp;
2064 cm_ForceNewConnections(tsp);
2066 lock_ObtainMutex(&tsp->mx);
2067 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
2068 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
2069 tsp->downTime = time(NULL);
2071 /* Now update the volume status */
2072 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2073 for (i=0; i<NUM_SERVER_VOLS; i++) {
2074 if (tsrvp->ids[i] != 0) {
2078 lock_ReleaseMutex(&tsp->mx);
2079 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2080 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2081 lock_ObtainMutex(&tsp->mx);
2083 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2089 lock_ReleaseMutex(&tsp->mx);
2095 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
2099 if (!cm_giveUpAllCBs)
2102 lock_ObtainRead(&cm_serverLock);
2103 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
2104 cm_GetServerNoLock(tsp);
2105 lock_ReleaseRead(&cm_serverLock);
2106 cm_GiveUpAllCallbacks(tsp, markDown);
2107 lock_ObtainRead(&cm_serverLock);
2108 cm_PutServerNoLock(tsp);
2110 lock_ReleaseRead(&cm_serverLock);
2114 cm_GiveUpAllCallbacksAllServersMulti(afs_int32 markDown)
2117 cm_conn_t **conns = NULL;
2118 struct rx_connection **rxconns = NULL;
2119 afs_int32 i, nconns = 0, maxconns;
2120 cm_server_t ** serversp, *tsp;
2122 time_t start, *deltas;
2124 maxconns = cm_numFileServers;
2128 conns = (cm_conn_t **)malloc(maxconns * sizeof(cm_conn_t *));
2129 rxconns = (struct rx_connection **)malloc(maxconns * sizeof(struct rx_connection *));
2130 deltas = (time_t *)malloc(maxconns * sizeof (time_t));
2131 results = (afs_int32 *)malloc(maxconns * sizeof (afs_int32));
2132 serversp = (cm_server_t **)malloc(maxconns * sizeof(cm_server_t *));
2134 lock_ObtainRead(&cm_serverLock);
2135 for (nconns=0, tsp = cm_allServersp; tsp && nconns < maxconns; tsp = tsp->allNextp) {
2136 if (tsp->type != CM_SERVER_FILE ||
2137 (tsp->flags & CM_SERVERFLAG_DOWN) ||
2138 tsp->cellp == NULL /* SetPrefs only */)
2141 cm_GetServerNoLock(tsp);
2142 lock_ReleaseRead(&cm_serverLock);
2144 serversp[nconns] = tsp;
2145 code = cm_ConnByServer(tsp, cm_rootUserp, &conns[nconns]);
2147 lock_ObtainRead(&cm_serverLock);
2148 cm_PutServerNoLock(tsp);
2151 lock_ObtainRead(&cm_serverLock);
2152 rxconns[nconns] = cm_GetRxConn(conns[nconns]);
2153 rx_SetConnDeadTime(rxconns[nconns], 10);
2157 lock_ReleaseRead(&cm_serverLock);
2160 /* Perform the multi call */
2162 multi_Rx(rxconns,nconns)
2164 multi_RXAFS_GiveUpAllCallBacks();
2165 results[multi_i]=multi_error;
2169 /* Process results of servers that support RXAFS_GetCapabilities */
2170 for (i=0; i<nconns; i++) {
2171 rx_SetConnDeadTime(rxconns[i], ConnDeadtimeout);
2172 rx_PutConnection(rxconns[i]);
2173 cm_PutConn(conns[i]);
2176 cm_GCConnections(tsp);
2179 cm_server_vols_t * tsrvp;
2183 cm_ForceNewConnections(tsp);
2185 lock_ObtainMutex(&tsp->mx);
2186 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
2187 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
2188 tsp->downTime = time(NULL);
2190 /* Now update the volume status */
2191 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2192 for (i=0; i<NUM_SERVER_VOLS; i++) {
2193 if (tsrvp->ids[i] != 0) {
2197 lock_ReleaseMutex(&tsp->mx);
2198 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2199 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2200 lock_ObtainMutex(&tsp->mx);
2202 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2208 lock_ReleaseMutex(&tsp->mx);