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 CM_FID_GEN_HASH(&tfid);
173 hash = CM_SCACHE_HASH(&tfid);
175 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
176 fidp->Volume, fidp->Vnode, fidp->Unique);
178 /* do this first, so that if we're executing a callback granting call
179 * at this moment, we kill it before it can be merged in. Otherwise,
180 * it could complete while we're doing the scan below, and get missed
181 * by both the scan and by this code.
183 cm_RecordRacingRevoke(&tfid, 0);
185 lock_ObtainWrite(&cm_scacheLock);
186 /* do all in the hash bucket, since we don't know how many we'll find with
189 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
190 if (scp->fid.volume == tfid.volume &&
191 scp->fid.vnode == tfid.vnode &&
192 scp->fid.unique == tfid.unique &&
193 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
194 cm_HaveCallback(scp))
196 cm_HoldSCacheNoLock(scp);
197 lock_ReleaseWrite(&cm_scacheLock);
198 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
199 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
202 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
203 scp->fid.hash, scp->fileType, AFS_INVALIDATE_CALLBACK);
205 lock_ObtainWrite(&scp->rw);
206 cm_DiscardSCache(scp);
207 lock_ReleaseWrite(&scp->rw);
209 cm_CallbackNotifyChange(scp);
211 lock_ObtainWrite(&cm_scacheLock);
212 cm_ReleaseSCacheNoLock(scp);
215 lock_ReleaseWrite(&cm_scacheLock);
217 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
218 fidp->Volume, fidp->Vnode, fidp->Unique);
222 cm_callbackDiscardROVolumeByFID(cm_fid_t *fidp)
224 cm_volume_t *volp = cm_GetVolumeByFID(fidp);
227 if (volp->cbExpiresRO) {
228 volp->cbExpiresRO = 0;
229 if (volp->cbServerpRO) {
230 cm_PutServer(volp->cbServerpRO);
231 volp->cbServerpRO = NULL;
233 volp->creationDateRO = 0;
238 /* called to revoke a volume callback, which is typically issued when a volume
239 * is moved from one server to another.
241 * Called with no locks held.
243 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
249 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %u", fidp->Volume);
251 /* do this first, so that if we're executing a callback granting call
252 * at this moment, we kill it before it can be merged in. Otherwise,
253 * it could complete while we're doing the scan below, and get missed
254 * by both the scan and by this code.
256 tfid.cell = cellp ? cellp->cellID : 0;
257 tfid.volume = fidp->Volume;
258 tfid.vnode = tfid.unique = 0;
259 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
261 lock_ObtainWrite(&cm_scacheLock);
262 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
263 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
264 if (scp->fid.volume == fidp->Volume &&
265 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
266 scp->cbExpires > 0 &&
267 scp->cbServerp != NULL) {
268 cm_HoldSCacheNoLock(scp);
269 lock_ReleaseWrite(&cm_scacheLock);
271 lock_ObtainWrite(&scp->rw);
272 osi_Log5(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
273 scp, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
274 osi_Log2(afsd_logp, ".... dv 0x%x:%x",
275 (afs_uint32)((scp->dataVersion >> 32) & 0xFFFFFFFF),
276 (afs_uint32)(scp->dataVersion & 0xFFFFFFFF));
278 cm_DiscardSCache(scp);
279 lock_ReleaseWrite(&scp->rw);
282 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
283 scp->fid.hash, scp->fileType, AFS_INVALIDATE_CALLBACK);
285 cm_CallbackNotifyChange(scp);
286 lock_ObtainWrite(&cm_scacheLock);
287 cm_ReleaseSCacheNoLock(scp);
288 if (scp->flags & CM_SCACHEFLAG_PURERO)
289 cm_callbackDiscardROVolumeByFID(&scp->fid);
291 } /* search one hash bucket */
292 } /* search all hash buckets */
294 lock_ReleaseWrite(&cm_scacheLock);
296 if (cellp && RDR_Initialized)
297 RDR_InvalidateVolume(cellp->cellID, fidp->Volume, AFS_INVALIDATE_CALLBACK);
299 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
303 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
304 * given data pointer, without triggering "cast truncates pointer"
305 * warnings. We use this where we explicitly don't care whether a
306 * pointer is truncated -- it loses information where a pointer is
307 * larger than an afs_int32.
311 afs_data_pointer_to_int32(const void *p)
314 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
318 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
323 /* used to determine the byte order of the system */
326 char c[sizeof(int) / sizeof(char)];
332 /* little-endian system */
335 /* big-endian system */
336 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
341 return ip.i32[i32_sub];
343 /*------------------------------------------------------------------------
344 * EXPORTED SRXAFSCB_CallBack
347 * Routine called by the server-side callback RPC interface to
348 * implement passing in callback information.
352 * rx_call : Ptr to Rx call on which this request came in.
353 * fidsArrayp : Ptr to array of fids involved.
354 * cbsArrayp : Ptr to matching callback info for the fids.
360 * Nothing interesting.
364 *------------------------------------------------------------------------*/
365 /* handle incoming RPC callback breaking message.
366 * Called with no locks held.
369 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
373 struct rx_connection *connp;
374 struct rx_peer *peerp;
375 unsigned long host = 0;
376 unsigned short port = 0;
377 cm_server_t *tsp = NULL;
378 cm_cell_t* cellp = NULL;
383 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
384 host = rx_HostOf(peerp);
385 port = rx_PortOf(peerp);
387 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
394 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
398 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
401 cellp->name /* does not need to be saved, doesn't change */);
403 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
407 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
408 tfidp = &fidsArrayp->AFSCBFids_val[i];
410 if (tfidp->Volume == 0)
411 continue; /* means don't do anything */
412 else if (tfidp->Vnode == 0)
413 cm_RevokeVolumeCallback(callp, cellp, tfidp);
415 cm_RevokeCallback(callp, cellp, tfidp);
420 /*------------------------------------------------------------------------
421 * EXPORTED SRXAFSCB_InitCallBackState
424 * Routine called by the server-side callback RPC interface to
425 * implement clearing all callbacks from this host.
428 * rx_call : Ptr to Rx call on which this request came in.
434 * Nothing interesting.
438 *------------------------------------------------------------------------*/
439 /* called with no locks by RPC system when a server indicates that it has never
440 * heard from us, or for other reasons has had to discard callbacks from us
441 * without telling us, e.g. a network partition.
444 SRXAFSCB_InitCallBackState(struct rx_call *callp)
449 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState ->");
451 return SRXAFSCB_InitCallBackState3(callp, NULL);
454 /*------------------------------------------------------------------------
455 * EXPORTED SRXAFSCB_Probe
458 * Routine called by the server-side callback RPC interface to
459 * implement ``probing'' the Cache Manager, just making sure it's
463 * rx_call : Ptr to Rx call on which this request came in.
469 * Nothing interesting.
473 *------------------------------------------------------------------------*/
475 SRXAFSCB_Probe(struct rx_call *callp)
477 struct rx_connection *connp;
478 struct rx_peer *peerp;
479 unsigned long host = 0;
480 unsigned short port = 0;
485 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
486 host = rx_HostOf(peerp);
487 port = rx_PortOf(peerp);
490 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
497 /*------------------------------------------------------------------------
498 * EXPORTED SRXAFSCB_GetLock
501 * Routine called by the server-side callback RPC interface to
502 * implement pulling out the contents of a lock in the lock
506 * a_call : Ptr to Rx call on which this request came in.
507 * a_index : Index of desired lock.
508 * a_result : Ptr to a buffer for the given lock.
511 * 0 if everything went fine,
512 * 1 if we were given a bad index.
515 * Nothing interesting.
519 *------------------------------------------------------------------------*/
520 /* debug interface */
522 extern osi_rwlock_t cm_aclLock;
523 extern osi_rwlock_t buf_globalLock;
524 extern osi_rwlock_t cm_cellLock;
525 extern osi_rwlock_t cm_connLock;
526 extern osi_rwlock_t cm_daemonLock;
527 extern osi_rwlock_t cm_dnlcLock;
528 extern osi_rwlock_t cm_scacheLock;
529 extern osi_rwlock_t cm_serverLock;
530 extern osi_rwlock_t cm_syscfgLock;
531 extern osi_rwlock_t cm_userLock;
532 extern osi_rwlock_t cm_utilsLock;
533 extern osi_rwlock_t cm_volumeLock;
534 extern osi_rwlock_t smb_globalLock;
535 extern osi_rwlock_t smb_rctLock;
537 extern osi_mutex_t cm_Freelance_Lock;
538 extern osi_mutex_t cm_Afsdsbmt_Lock;
539 extern osi_mutex_t tokenEventLock;
540 extern osi_mutex_t smb_ListenerLock;
541 extern osi_mutex_t smb_RawBufLock;
542 extern osi_mutex_t smb_Dir_Watch_Lock;
544 #define LOCKTYPE_RW 1
545 #define LOCKTYPE_MUTEX 2
546 static struct _ltable {
551 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
552 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
553 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
554 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
555 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
556 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
557 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
558 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
559 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
560 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
561 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
562 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
563 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
564 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
565 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
566 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
567 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
568 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
569 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
570 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
571 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
575 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
577 struct _ltable *tl; /*Ptr to lock table entry */
580 int nentries; /*Num entries in table */
581 int code; /*Return code */
582 struct rx_connection *connp;
583 struct rx_peer *peerp;
584 unsigned long host = 0;
585 unsigned short port = 0;
590 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
591 host = rx_HostOf(peerp);
592 port = rx_PortOf(peerp);
595 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
596 index, ntohl(host), ntohs(port));
598 nentries = sizeof(ltable) / sizeof(struct _ltable);
599 if (index < 0 || index >= nentries) {
606 * Found it - copy out its contents.
609 strncpy(lockp->name, tl->name, sizeof(lockp->name));
610 lockp->name[sizeof(lockp->name)-1] = '\0';
611 lockp->lock.waitStates = 0;
612 switch ( tl->type ) {
614 rwp = (osi_rwlock_t *)tl->addr;
615 lockp->lock.exclLocked = rwp->flags;
616 lockp->lock.readersReading = rwp->readers;
617 lockp->lock.numWaiting = rwp->waiters;
620 mtxp = (osi_mutex_t *)tl->addr;
621 lockp->lock.exclLocked = mtxp->flags;
622 lockp->lock.readersReading = 0;
623 lockp->lock.numWaiting = mtxp->waiters;
626 lockp->lock.pid_last_reader = 0;
627 lockp->lock.pid_writer = 0;
628 lockp->lock.src_indicator = 0;
635 /* debug interface */
637 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
642 struct rx_connection *connp;
643 struct rx_peer *peerp;
644 unsigned long host = 0;
645 unsigned short port = 0;
650 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
651 host = rx_HostOf(peerp);
652 port = rx_PortOf(peerp);
655 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
656 ntohl(host), ntohs(port));
658 lock_ObtainRead(&cm_scacheLock);
659 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
660 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
664 } /*Zip through current hash chain */
665 } /*Zip through hash chains */
675 * Copy out the located entry.
677 memset(cep, 0, sizeof(AFSDBCacheEntry));
678 cep->addr = afs_data_pointer_to_int32(scp);
679 cep->cell = scp->fid.cell;
680 cep->netFid.Volume = scp->fid.volume;
681 cep->netFid.Vnode = scp->fid.vnode;
682 cep->netFid.Unique = scp->fid.unique;
683 cep->lock.waitStates = 0;
684 cep->lock.exclLocked = scp->rw.flags;
685 cep->lock.readersReading = 0;
686 cep->lock.numWaiting = scp->rw.waiters;
687 cep->lock.pid_last_reader = 0;
688 cep->lock.pid_writer = 0;
689 cep->lock.src_indicator = 0;
690 cep->Length = scp->length.LowPart;
691 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
692 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
693 if (scp->flags & CM_SCACHEFLAG_PURERO) {
694 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
696 cep->cbExpires = volp->cbExpiresRO;
700 /* TODO: deal with time_t below */
701 cep->cbExpires = (afs_int32) scp->cbExpires;
703 cep->refCount = scp->refCount;
704 cep->opens = scp->openReads;
705 cep->writers = scp->openWrites;
706 switch (scp->fileType) {
707 case CM_SCACHETYPE_FILE:
710 case CM_SCACHETYPE_MOUNTPOINT:
713 case CM_SCACHETYPE_DIRECTORY:
714 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
719 case CM_SCACHETYPE_SYMLINK:
722 case CM_SCACHETYPE_DFSLINK:
725 case CM_SCACHETYPE_INVALID:
730 if (scp->flags & CM_SCACHEFLAG_STATD)
732 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
734 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
735 scp->mountPointStringp[0])
737 if (scp->flags & CM_SCACHEFLAG_WAITING)
742 * Return our results.
745 lock_ReleaseRead(&cm_scacheLock);
750 /* debug interface */
752 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
757 struct rx_connection *connp;
758 struct rx_peer *peerp;
759 unsigned long host = 0;
760 unsigned short port = 0;
765 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
766 host = rx_HostOf(peerp);
767 port = rx_PortOf(peerp);
770 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
771 ntohl(host), ntohs(port));
773 lock_ObtainRead(&cm_scacheLock);
774 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
775 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
779 } /*Zip through current hash chain */
780 } /*Zip through hash chains */
790 * Copy out the located entry.
792 memset(cep, 0, sizeof(AFSDBCacheEntry64));
793 cep->addr = afs_data_pointer_to_int32(scp);
794 cep->cell = scp->fid.cell;
795 cep->netFid.Volume = scp->fid.volume;
796 cep->netFid.Vnode = scp->fid.vnode;
797 cep->netFid.Unique = scp->fid.unique;
798 cep->lock.waitStates = 0;
799 cep->lock.exclLocked = scp->rw.flags;
800 cep->lock.readersReading = 0;
801 cep->lock.numWaiting = scp->rw.waiters;
802 cep->lock.pid_last_reader = 0;
803 cep->lock.pid_writer = 0;
804 cep->lock.src_indicator = 0;
805 cep->Length = (afs_int64) scp->length.QuadPart;
806 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
807 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
808 if (scp->flags & CM_SCACHEFLAG_PURERO) {
809 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
811 cep->cbExpires = volp->cbExpiresRO;
815 /* TODO: handle time_t */
816 cep->cbExpires = (afs_int32) scp->cbExpires;
818 cep->refCount = scp->refCount;
819 cep->opens = scp->openReads;
820 cep->writers = scp->openWrites;
821 switch (scp->fileType) {
822 case CM_SCACHETYPE_FILE:
825 case CM_SCACHETYPE_MOUNTPOINT:
828 case CM_SCACHETYPE_DIRECTORY:
829 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
834 case CM_SCACHETYPE_SYMLINK:
837 case CM_SCACHETYPE_DFSLINK:
840 case CM_SCACHETYPE_INVALID:
845 if (scp->flags & CM_SCACHEFLAG_STATD)
847 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
849 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
850 scp->mountPointStringp[0])
852 if (scp->flags & CM_SCACHEFLAG_WAITING)
857 * Return our results.
860 lock_ReleaseRead(&cm_scacheLock);
865 /* debug interface: not implemented */
867 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
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_XStatsVersion from host 0x%x port %d - not implemented",
883 ntohl(host), ntohs(port));
889 /* debug interface: not implemented */
891 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
892 AFSCB_CollData *datap)
894 struct rx_connection *connp;
895 struct rx_peer *peerp;
896 unsigned long host = 0;
897 unsigned short port = 0;
902 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
903 host = rx_HostOf(peerp);
904 port = rx_PortOf(peerp);
907 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
908 ntohl(host), ntohs(port));
914 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
919 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
921 return SRXAFSCB_InitCallBackState3(callp, NULL);
924 /* debug interface */
926 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
930 struct rx_connection *connp;
931 struct rx_peer *peerp;
932 unsigned long host = 0;
933 unsigned short port = 0;
938 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
939 host = rx_HostOf(peerp);
940 port = rx_PortOf(peerp);
943 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
947 lock_ObtainRead(&cm_syscfgLock);
948 if (cm_LanAdapterChangeDetected) {
949 lock_ConvertRToW(&cm_syscfgLock);
950 if (cm_LanAdapterChangeDetected) {
951 /* get network related info */
952 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
953 code = syscfg_GetIFInfo(&cm_noIPAddr,
954 cm_IPAddr, cm_SubnetMask,
955 cm_NetMtu, cm_NetFlags);
956 cm_LanAdapterChangeDetected = 0;
958 lock_ConvertWToR(&cm_syscfgLock);
961 /* return all network interface addresses */
962 addr->numberOfInterfaces = cm_noIPAddr;
963 addr->uuid = cm_data.Uuid;
964 for ( i=0; i < cm_noIPAddr; i++ ) {
965 addr->addr_in[i] = cm_IPAddr[i];
966 addr->subnetmask[i] = cm_SubnetMask[i];
967 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
968 cm_NetMtu[i] : rx_mtu;
971 lock_ReleaseRead(&cm_syscfgLock);
977 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
981 cm_server_t *tsp = NULL;
982 cm_scache_t *scp = NULL;
983 cm_cell_t* cellp = NULL;
987 afs_uint32 discardType;
988 struct rx_connection *connp;
989 struct rx_peer *peerp;
990 unsigned long host = 0;
991 unsigned short port = 0;
996 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
997 host = rx_HostOf(peerp);
998 port = rx_PortOf(peerp);
1001 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
1002 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 Uuid%s ->",osi_LogSaveString(afsd_logp,p));
1006 tsp = cm_FindServerByUuid(serverUuid, CM_SERVER_FILE, FALSE);
1009 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
1016 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d",
1020 osi_Log3(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d for cell %s",
1023 cellp->name /* does not need to be saved, doesn't change */);
1025 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 from unknown host");
1028 if (connp && peerp) {
1029 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
1031 osi_Log1(afsd_logp, "InitCallbackState3 server %x", tsp);
1033 /* record the callback in the racing revokes structure. This
1034 * shouldn't be necessary, since we shouldn't be making callback
1035 * granting calls while we're going to get an initstate call,
1036 * but there probably are some obscure races, so better safe
1039 * We do this first since we don't hold the cm_scacheLock and vnode
1040 * locks over the entire callback scan operation below. The
1041 * big loop below is guaranteed to hit any callback already
1042 * processed. The call to RecordRacingRevoke is guaranteed
1043 * to kill any callback that is currently being returned.
1044 * Anything that sneaks past both must start
1045 * after the call to RecordRacingRevoke.
1050 fid.cell = cellp->cellID;
1051 fid.volume = fid.vnode = fid.unique = 0;
1053 cm_RecordRacingRevoke(&fid, CM_RACINGFLAG_CANCELALL);
1055 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
1058 /* now search all vnodes looking for guys with this callback, if we
1059 * found it, or guys with any callbacks, if we didn't find the server
1060 * (that's how multihomed machines will appear and how we'll handle
1061 * them, albeit a little inefficiently). That is, we're discarding all
1062 * callbacks from all hosts if we get an initstate call from an unknown
1063 * host. Since these calls are rare, and multihomed servers
1064 * are "rare," hopefully this won't be a problem.
1066 lock_ObtainWrite(&cm_scacheLock);
1067 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
1068 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
1069 cm_HoldSCacheNoLock(scp);
1070 lock_ReleaseWrite(&cm_scacheLock);
1071 lock_ObtainWrite(&scp->rw);
1073 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
1074 /* we have a callback, now decide if we should clear it */
1075 if (cm_ServerEqual(scp->cbServerp, tsp)) {
1076 osi_Log4(afsd_logp, "InitCallbackState3 Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1077 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1078 discardFid = scp->fid;
1079 discardType = scp->fileType;
1080 cm_DiscardSCache(scp);
1084 lock_ReleaseWrite(&scp->rw);
1086 cm_CallbackNotifyChange(scp);
1087 if (RDR_Initialized)
1088 RDR_InvalidateObject(discardFid.cell, discardFid.volume, discardFid.vnode, discardFid.unique,
1089 discardFid.hash, discardType, AFS_INVALIDATE_EXPIRED);
1091 lock_ObtainWrite(&cm_scacheLock);
1092 cm_ReleaseSCacheNoLock(scp);
1094 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO))
1095 cm_callbackDiscardROVolumeByFID(&scp->fid);
1097 } /* search one hash bucket */
1098 } /* search all hash buckets */
1100 lock_ReleaseWrite(&cm_scacheLock);
1103 /* reset the No flags on the server */
1104 cm_SetServerNo64Bit(tsp, 0);
1105 cm_SetServerNoInlineBulk(tsp, 0);
1107 /* we're done with the server structure */
1114 /* debug interface */
1116 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1118 struct rx_connection *connp;
1119 struct rx_peer *peerp;
1120 unsigned long host = 0;
1121 unsigned short port = 0;
1128 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1129 host = rx_HostOf(peerp);
1130 port = rx_PortOf(peerp);
1133 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1134 UuidToString((UUID *)&cm_data.Uuid, &p);
1135 UuidToString((UUID *)clientUuid, &q);
1136 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1137 osi_LogSaveString(afsd_logp,p),
1138 osi_LogSaveString(afsd_logp,q),
1144 code = 1; /* failure */
1146 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1153 /* debug interface */
1155 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1159 cm_serverRef_t * serverRefp;
1162 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1164 *a_name = (char *)xdr_alloc(sizeof(char));
1170 lock_ObtainRead(&cm_serverLock);
1171 len = strlen(cellp->name)+1;
1172 *a_name = (char *)xdr_alloc(len);
1174 memcpy(*a_name, cellp->name, len);
1176 for ( sn = 0, serverRefp = cellp->vlServersp;
1177 sn < AFSMAXCELLHOSTS && serverRefp;
1178 sn++, serverRefp = serverRefp->next);
1180 a_hosts->serverList_len = sn;
1181 a_hosts->serverList_val = (afs_int32 *)xdr_alloc(sn * sizeof(afs_int32));
1183 for ( sn = 0, serverRefp = cellp->vlServersp;
1184 sn < AFSMAXCELLHOSTS && serverRefp;
1185 sn++, serverRefp = serverRefp->next)
1187 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1190 lock_ReleaseRead(&cm_serverLock);
1194 /* debug interface */
1196 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1197 char **a_name, serverList *a_hosts)
1199 struct rx_connection *connp;
1200 struct rx_peer *peerp;
1201 unsigned long host = 0;
1202 unsigned short port = 0;
1208 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1209 host = rx_HostOf(peerp);
1210 port = rx_PortOf(peerp);
1213 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1214 a_cellnum, ntohl(host), ntohs(port));
1216 a_hosts->serverList_val = 0;
1217 a_hosts->serverList_len = 0;
1220 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1225 /* debug interface */
1227 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1228 struct interfaceAddr *addr,
1229 Capabilities * capabilities)
1232 afs_uint32 *dataBuffP;
1233 afs_int32 dataBytes;
1235 struct rx_connection *connp;
1236 struct rx_peer *peerp;
1237 unsigned long host = 0;
1238 unsigned short port = 0;
1243 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1244 host = rx_HostOf(peerp);
1245 port = rx_PortOf(peerp);
1248 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1252 lock_ObtainRead(&cm_syscfgLock);
1253 if (cm_LanAdapterChangeDetected) {
1254 lock_ConvertRToW(&cm_syscfgLock);
1255 if (cm_LanAdapterChangeDetected) {
1256 /* get network related info */
1257 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1258 code = syscfg_GetIFInfo(&cm_noIPAddr,
1259 cm_IPAddr, cm_SubnetMask,
1260 cm_NetMtu, cm_NetFlags);
1261 cm_LanAdapterChangeDetected = 0;
1263 lock_ConvertWToR(&cm_syscfgLock);
1266 /* return all network interface addresses */
1267 addr->numberOfInterfaces = cm_noIPAddr;
1268 addr->uuid = cm_data.Uuid;
1269 for ( i=0; i < cm_noIPAddr; i++ ) {
1270 addr->addr_in[i] = cm_IPAddr[i];
1271 addr->subnetmask[i] = cm_SubnetMask[i];
1272 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1273 cm_NetMtu[i] : rx_mtu;
1275 lock_ReleaseRead(&cm_syscfgLock);
1277 dataBytes = 1 * sizeof(afs_uint32);
1278 dataBuffP = (afs_uint32 *) xdr_alloc(dataBytes);
1279 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1280 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1281 capabilities->Capabilities_val = dataBuffP;
1286 /*------------------------------------------------------------------------
1287 * EXPORTED SRXAFSCB_GetServerPrefs
1290 * Routine to list server preferences used by this client.
1293 * a_call : Ptr to Rx call on which this request came in.
1294 * a_index : Input server index
1295 * a_srvr_addr : Output server address (0xffffffff on last server)
1296 * a_srvr_rank : Output server rank
1302 * Nothing interesting.
1306 *------------------------------------------------------------------------*/
1308 int SRXAFSCB_GetServerPrefs(
1309 struct rx_call *callp,
1311 afs_int32 *a_srvr_addr,
1312 afs_int32 *a_srvr_rank)
1314 struct rx_connection *connp;
1315 struct rx_peer *peerp;
1316 unsigned long host = 0;
1317 unsigned short port = 0;
1322 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1323 host = rx_HostOf(peerp);
1324 port = rx_PortOf(peerp);
1327 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1331 *a_srvr_addr = 0xffffffff;
1332 *a_srvr_rank = 0xffffffff;
1337 /*------------------------------------------------------------------------
1338 * EXPORTED SRXAFSCB_GetCellServDB
1341 * Routine to list cells configured for this client
1344 * a_call : Ptr to Rx call on which this request came in.
1345 * a_index : Input cell index
1346 * a_name : Output cell name ("" on last cell)
1347 * a_hosts : Output cell database servers
1353 * Nothing interesting.
1357 *------------------------------------------------------------------------*/
1359 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1360 serverList *a_hosts)
1362 struct rx_connection *connp;
1363 struct rx_peer *peerp;
1364 unsigned long host = 0;
1365 unsigned short port = 0;
1371 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1372 host = rx_HostOf(peerp);
1373 port = rx_PortOf(peerp);
1376 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1377 ntohl(host), ntohs(port));
1379 #ifdef AFS_FREELANCE_CLIENT
1380 if (cm_freelanceEnabled && index == 0) {
1381 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1385 rc = GetCellCommon(index+1, a_name, a_hosts);
1390 /*------------------------------------------------------------------------
1391 * EXPORTED SRXAFSCB_GetLocalCell
1394 * Routine to return name of client's local cell
1397 * a_call : Ptr to Rx call on which this request came in.
1398 * a_name : Output cell name
1404 * Nothing interesting.
1408 *------------------------------------------------------------------------*/
1410 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1413 struct rx_connection *connp;
1414 struct rx_peer *peerp;
1415 unsigned long host = 0;
1416 unsigned short port = 0;
1422 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1423 host = rx_HostOf(peerp);
1424 port = rx_PortOf(peerp);
1427 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1428 ntohl(host), ntohs(port));
1430 if (cm_data.rootCellp) {
1431 len = strlen(cm_data.rootCellp->name) + 1;
1432 t_name = (char *)xdr_alloc(len);
1434 memcpy(t_name, cm_data.rootCellp->name, len);
1436 t_name = (char *)xdr_alloc(1);
1446 * afs_MarshallCacheConfig - marshall client cache configuration
1450 * IN callerVersion - the rpc stat version of the caller.
1452 * IN config - client cache configuration.
1454 * OUT ptr - buffer where configuration is marshalled.
1460 static void afs_MarshallCacheConfig(
1461 afs_uint32 callerVersion,
1462 cm_initparams_v1 *config,
1466 * We currently only support version 1.
1468 *(ptr++) = config->nChunkFiles;
1469 *(ptr++) = config->nStatCaches;
1470 *(ptr++) = config->nDataCaches;
1471 *(ptr++) = config->nVolumeCaches;
1472 *(ptr++) = config->firstChunkSize;
1473 *(ptr++) = config->otherChunkSize;
1474 *(ptr++) = config->cacheSize;
1475 *(ptr++) = config->setTime;
1476 *(ptr++) = config->memCache;
1481 /*------------------------------------------------------------------------
1482 * EXPORTED SRXAFSCB_GetCacheConfig
1485 * Routine to return parameters used to initialize client cache.
1486 * Client may request any format version. Server may not return
1487 * format version greater than version requested by client.
1490 * a_call: Ptr to Rx call on which this request came in.
1491 * callerVersion: Data format version desired by the client.
1492 * serverVersion: Data format version of output data.
1493 * configCount: Number bytes allocated for output data.
1494 * config: Client cache configuration.
1500 * Nothing interesting.
1504 *------------------------------------------------------------------------*/
1506 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1507 afs_uint32 callerVersion,
1508 afs_uint32 *serverVersion,
1509 afs_uint32 *configCount,
1510 cacheConfig *config)
1512 afs_uint32 *t_config;
1514 extern cm_initparams_v1 cm_initParams;
1515 struct rx_connection *connp;
1516 struct rx_peer *peerp;
1517 unsigned long host = 0;
1518 unsigned short port = 0;
1523 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1524 host = rx_HostOf(peerp);
1525 port = rx_PortOf(peerp);
1528 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1529 ntohl(host), ntohs(port));
1532 * Currently only support version 1
1534 allocsize = sizeof(cm_initparams_v1);
1535 t_config = (afs_uint32 *)xdr_alloc(allocsize);
1537 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1539 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1542 #define SIZE_MAX UINT_MAX
1544 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1546 *configCount = (afs_uint32)allocsize;
1547 config->cacheConfig_val = t_config;
1548 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1553 /* called by afsd without any locks to initialize this module */
1554 void cm_InitCallback(void)
1556 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1557 cm_activeCallbackGrantingCalls = 0;
1560 /* called with locked scp; tells us whether we've got a callback.
1561 * Expirations are checked by a background daemon so as to make
1562 * this function as inexpensive as possible
1564 int cm_HaveCallback(cm_scache_t *scp)
1566 #ifdef AFS_FREELANCE_CLIENT
1567 if (cm_freelanceEnabled &&
1568 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1569 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1570 if (cm_getLocalMountPointChange()) {
1571 cm_clearLocalMountPointChange();
1572 lock_ReleaseWrite(&scp->rw);
1573 cm_reInitLocalMountPoints();
1574 lock_ObtainWrite(&scp->rw);
1576 return (cm_data.fakeDirVersion == scp->dataVersion);
1579 if (cm_readonlyVolumeVersioning &&
1580 (scp->flags & CM_SCACHEFLAG_PURERO)) {
1581 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1584 if (cm_OfflineROIsValid) {
1585 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1593 if (cm_readonlyVolumeVersioning &&
1595 volp->creationDateRO == scp->volumeCreationDate &&
1596 volp->cbServerpRO != NULL) {
1603 if (scp->cbServerp != NULL)
1609 /* need to detect a broken callback that races with our obtaining a callback.
1610 * Need to be able to do this even if we don't know the file ID of the file
1611 * we're breaking the callback on at the time we start the acquisition of the
1612 * callback (as in the case where we are creating a file).
1614 * So, we start by writing down the count of the # of callbacks we've received
1615 * so far, and bumping a global counter of the # of callback granting calls
1616 * outstanding (all done under cm_callbackLock).
1618 * When we're back from the call, we look at all of the callback revokes with
1619 * counter numbers greater than the one we recorded in our caller's structure,
1620 * and replay those that are higher than when we started the call.
1622 * We free all the structures in the queue when the count of the # of outstanding
1623 * callback-granting calls drops to zero.
1625 * We call this function with the scp locked, too, but in its current implementation,
1626 * this knowledge is not used.
1628 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1630 lock_ObtainWrite(&cm_callbackLock);
1631 cbrp->callbackCount = cm_callbackCount;
1632 cm_activeCallbackGrantingCalls++;
1633 cbrp->startTime = time(NULL);
1634 cbrp->serverp = NULL;
1635 lock_ReleaseWrite(&cm_callbackLock);
1638 /* Called at the end of a callback-granting call, to remove the callback
1639 * info from the scache entry, if necessary.
1641 * Called with scp write locked, so we can discard the callbacks easily with
1642 * this locking hierarchy.
1644 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1645 AFSCallBack *cbp, AFSVolSync *volSyncp, long flags)
1647 cm_racingRevokes_t *revp; /* where we are */
1648 cm_racingRevokes_t *nrevp; /* where we'll be next */
1650 cm_server_t * serverp = NULL;
1651 int discardScp = 0, discardVolCB = 0;
1653 lock_ObtainWrite(&cm_callbackLock);
1654 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1655 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1656 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1659 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1660 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1662 if (cm_activeCallbackGrantingCalls == 0)
1667 /* record the callback; we'll clear it below if we really lose it */
1670 if (!cm_ServerEqual(scp->cbServerp, cbrp->serverp)) {
1671 serverp = scp->cbServerp;
1673 cm_GetServer(cbrp->serverp);
1674 scp->cbServerp = cbrp->serverp;
1677 serverp = cbrp->serverp;
1679 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1682 serverp = cbrp->serverp;
1685 cbrp->serverp = NULL;
1688 /* a callback was actually revoked during our granting call, so
1689 * run down the list of revoked fids, looking for ours.
1690 * If activeCallbackGrantingCalls is zero, free the elements, too.
1692 * May need to go through entire list just to do the freeing.
1694 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1695 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1696 /* if this callback came in later than when we started the
1697 * callback-granting call, and if this fid is the right fid,
1698 * then clear the callback.
1700 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1701 && revp->callbackCount > cbrp->callbackCount
1702 && (( scp->fid.volume == revp->fid.volume &&
1703 scp->fid.vnode == revp->fid.vnode &&
1704 scp->fid.unique == revp->fid.unique)
1706 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1707 scp->fid.volume == revp->fid.volume)
1709 ((revp->flags & CM_RACINGFLAG_CANCELALL) &&
1710 (revp->fid.cell == 0 || scp->fid.cell == revp->fid.cell)))) {
1711 /* this one matches */
1713 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1715 cbrp->callbackCount, revp->callbackCount,
1718 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1719 (revp->flags & CM_RACINGFLAG_ALL))
1720 cm_callbackDiscardROVolumeByFID(&scp->fid);
1726 /* if we freed the list, zap the pointer to it */
1728 cm_racingRevokesp = NULL;
1730 lock_ReleaseWrite(&cm_callbackLock);
1733 cm_DiscardSCache(scp);
1734 lock_ReleaseWrite(&scp->rw);
1735 cm_CallbackNotifyChange(scp);
1736 if (RDR_Initialized)
1737 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
1738 scp->fid.hash, scp->fileType, AFS_INVALIDATE_CALLBACK);
1739 lock_ObtainWrite(&scp->rw);
1741 if (scp && scp->flags & CM_SCACHEFLAG_PURERO) {
1742 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1745 lock_ObtainWrite(&cm_scacheLock);
1746 volp->cbExpiresRO = scp->cbExpires;
1747 volp->creationDateRO = volSyncp->spare1;
1748 if (volp->cbServerpRO != scp->cbServerp) {
1749 if (volp->cbServerpRO)
1750 cm_PutServer(volp->cbServerpRO);
1751 cm_GetServer(scp->cbServerp);
1752 volp->cbServerpRO = scp->cbServerp;
1754 lock_ReleaseWrite(&cm_scacheLock);
1762 lock_ObtainWrite(&cm_serverLock);
1763 cm_FreeServer(serverp);
1764 lock_ReleaseWrite(&cm_serverLock);
1768 /* if flags is 1, we want to force the code to make one call, anyway.
1769 * called with locked scp; returns with same.
1771 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1772 struct cm_req *reqp, long flags)
1775 cm_conn_t *connp = NULL;
1776 AFSFetchStatus afsStatus;
1778 AFSCallBack callback;
1780 cm_callbackRequest_t cbr;
1783 struct rx_connection * rxconnp = NULL;
1784 int syncop_done = 0;
1786 memset(&volSync, 0, sizeof(volSync));
1788 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1789 scp, scp->fid.cell, scp->fid.volume, flags);
1791 #ifdef AFS_FREELANCE_CLIENT
1792 // The case where a callback is needed on /afs is handled
1793 // specially. We need to fetch the status by calling
1795 if (cm_freelanceEnabled &&
1796 (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1797 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)) {
1799 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1800 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1805 if (scp->dataVersion != cm_data.fakeDirVersion) {
1806 memset(&afsStatus, 0, sizeof(afsStatus));
1807 memset(&volSync, 0, sizeof(volSync));
1808 InterlockedIncrement(&scp->activeRPCs);
1810 // Fetch the status info
1811 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1815 #endif /* AFS_FREELANCE_CLIENT */
1817 mustCall = (flags & 1);
1818 cm_AFSFidFromFid(&tfid, &scp->fid);
1820 if (!mustCall && cm_HaveCallback(scp))
1823 /* turn off mustCall, since it has now forced us past the check above */
1826 /* otherwise, we have to make an RPC to get the status */
1828 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1829 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1834 cm_StartCallbackGrantingCall(scp, &cbr);
1836 lock_ReleaseWrite(&scp->rw);
1838 /* now make the RPC */
1839 InterlockedIncrement(&scp->activeRPCs);
1840 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1841 scp, sfid.volume, sfid.vnode, sfid.unique);
1843 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1847 rxconnp = cm_GetRxConn(connp);
1848 code = RXAFS_FetchStatus(rxconnp, &tfid,
1849 &afsStatus, &callback, &volSync);
1850 rx_PutConnection(rxconnp);
1852 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1854 code = cm_MapRPCError(code, reqp);
1856 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1857 code, scp, scp->fid.volume, scp->fid.vnode);
1859 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1860 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1862 lock_ObtainWrite(&scp->rw);
1864 cm_EndCallbackGrantingCall(scp, &cbr, &callback, &volSync, 0);
1865 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1867 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, NULL, 0);
1868 InterlockedDecrement(&scp->activeRPCs);
1871 /* if we got an error, return to caller */
1878 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1881 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1882 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1883 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1885 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1886 scp, scp->fid.cell, scp->fid.volume);
1894 * cm_CBServersDownTime() returns 1 if the downTime parameter is valid.
1896 * Servers with multiple interfaces have multiple cm_server_t objects
1897 * which share the same UUID. If one interface is down but others are up,
1898 * the server should not be considered down. The returned downTime should
1899 * be the largest non-zero value if down or zero if up. If the cbServerp
1900 * is down, it is updated to refer to an interface that is up (if one exists).
1902 * called with cm_scacheLock held
1905 cm_CBServersDownTime(cm_scache_t *scp, cm_volume_t *volp, time_t * pdownTime)
1907 cm_vol_state_t *statep;
1908 cm_serverRef_t *tsrp;
1910 time_t downTime = 0;
1911 cm_server_t * upserver = NULL;
1912 cm_server_t * downserver;
1916 if (scp->cbServerp == NULL)
1919 if (!(scp->cbServerp->flags & CM_SERVERFLAG_DOWN))
1922 statep = cm_VolumeStateByID(volp, scp->fid.volume);
1924 for (tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1925 if (tsrp->status == srv_deleted)
1928 if (!cm_ServerEqual(tsrp->server, scp->cbServerp))
1931 if (!(tsrp->server->flags & CM_SERVERFLAG_DOWN)) {
1934 upserver = tsrp->server;
1935 cm_GetServer(upserver);
1939 if (tsrp->server->downTime > downTime)
1940 downTime = tsrp->server->downTime;
1943 downTime = scp->cbServerp->downTime;
1946 /* if the cbServerp does not match the current volume server list
1947 * we report the callback server as up so the callback can be
1952 *pdownTime = downTime;
1954 lock_ObtainWrite(&scp->rw);
1955 downserver = scp->cbServerp;
1956 scp->cbServerp = upserver;
1957 lock_ReleaseWrite(&scp->rw);
1958 cm_PutServer(downserver);
1963 /* called periodically by cm_daemon to shut down use of expired callbacks */
1964 void cm_CheckCBExpiration(void)
1969 enum volstatus volstate;
1970 time_t now, downTime;
1972 osi_Log0(afsd_logp, "CheckCBExpiration");
1975 lock_ObtainWrite(&cm_scacheLock);
1976 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1977 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1979 cm_HoldSCacheNoLock(scp);
1980 lock_ReleaseWrite(&cm_scacheLock);
1983 * If this is not a PURERO object and there is no callback
1984 * or it hasn't expired, there is nothing to do
1986 if (!(scp->flags & CM_SCACHEFLAG_PURERO) &&
1987 (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires))
1991 * Determine the volume state and update the callback info
1992 * to the latest if it is a PURERO object.
1994 volp = cm_GetVolumeByFID(&scp->fid);
1995 volstate = vl_unknown;
1998 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1999 volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
2001 lock_ObtainWrite(&scp->rw);
2002 scp->cbExpires = volp->cbExpiresRO;
2003 if (volp->cbServerpRO != scp->cbServerp) {
2005 cm_PutServer(scp->cbServerp);
2006 cm_GetServer(volp->cbServerpRO);
2007 scp->cbServerp = volp->cbServerpRO;
2009 lock_ReleaseWrite(&scp->rw);
2011 volstate = cm_GetVolumeStatus(volp, scp->fid.volume);
2014 /* If there is no callback or it hasn't expired, there is nothing to do */
2015 if (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires)
2018 /* If the volume is known not to be online, do not expire the callback */
2019 if (volstate != vl_online)
2023 * If all the servers are down and the callback expired after the
2024 * issuing server went down, do not expire the callback
2026 if (cm_CBServersDownTime(scp, volp, &downTime) && downTime && downTime < scp->cbExpires)
2029 /* The callback has expired, discard the status info */
2030 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
2031 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
2032 lock_ObtainWrite(&scp->rw);
2033 cm_DiscardSCache(scp);
2034 lock_ReleaseWrite(&scp->rw);
2036 if (RDR_Initialized)
2037 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
2038 scp->fid.hash, scp->fileType, AFS_INVALIDATE_EXPIRED);
2040 cm_CallbackNotifyChange(scp);
2046 lock_ObtainWrite(&cm_scacheLock);
2047 cm_ReleaseSCacheNoLock(scp);
2050 lock_ReleaseWrite(&cm_scacheLock);
2052 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
2057 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
2061 struct rx_connection * rxconnp;
2063 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
2065 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
2067 rxconnp = cm_GetRxConn(connp);
2068 rx_SetConnDeadTime(rxconnp, 10);
2069 code = RXAFS_GiveUpAllCallBacks(rxconnp);
2070 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
2071 rx_PutConnection(rxconnp);
2075 cm_server_vols_t * tsrvp;
2079 cm_ForceNewConnections(tsp);
2081 lock_ObtainMutex(&tsp->mx);
2082 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
2083 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
2084 tsp->downTime = time(NULL);
2086 /* Now update the volume status */
2087 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2088 for (i=0; i<NUM_SERVER_VOLS; i++) {
2089 if (tsrvp->ids[i] != 0) {
2093 lock_ReleaseMutex(&tsp->mx);
2094 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2095 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2096 lock_ObtainMutex(&tsp->mx);
2098 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2104 lock_ReleaseMutex(&tsp->mx);
2110 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
2114 if (!cm_giveUpAllCBs)
2117 lock_ObtainRead(&cm_serverLock);
2118 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
2119 cm_GetServerNoLock(tsp);
2120 lock_ReleaseRead(&cm_serverLock);
2121 cm_GiveUpAllCallbacks(tsp, markDown);
2122 lock_ObtainRead(&cm_serverLock);
2123 cm_PutServerNoLock(tsp);
2125 lock_ReleaseRead(&cm_serverLock);
2129 cm_GiveUpAllCallbacksAllServersMulti(afs_int32 markDown)
2132 cm_conn_t **conns = NULL;
2133 struct rx_connection **rxconns = NULL;
2134 afs_int32 i, nconns = 0, maxconns;
2135 cm_server_t ** serversp, *tsp;
2137 time_t start, *deltas;
2139 maxconns = cm_numFileServers;
2143 conns = (cm_conn_t **)malloc(maxconns * sizeof(cm_conn_t *));
2144 rxconns = (struct rx_connection **)malloc(maxconns * sizeof(struct rx_connection *));
2145 deltas = (time_t *)malloc(maxconns * sizeof (time_t));
2146 results = (afs_int32 *)malloc(maxconns * sizeof (afs_int32));
2147 serversp = (cm_server_t **)malloc(maxconns * sizeof(cm_server_t *));
2149 lock_ObtainRead(&cm_serverLock);
2150 for (nconns=0, tsp = cm_allServersp; tsp && nconns < maxconns; tsp = tsp->allNextp) {
2151 if (tsp->type != CM_SERVER_FILE ||
2152 (tsp->flags & CM_SERVERFLAG_DOWN) ||
2153 tsp->cellp == NULL /* SetPrefs only */)
2156 cm_GetServerNoLock(tsp);
2157 lock_ReleaseRead(&cm_serverLock);
2159 serversp[nconns] = tsp;
2160 code = cm_ConnByServer(tsp, cm_rootUserp, &conns[nconns]);
2162 lock_ObtainRead(&cm_serverLock);
2163 cm_PutServerNoLock(tsp);
2166 lock_ObtainRead(&cm_serverLock);
2167 rxconns[nconns] = cm_GetRxConn(conns[nconns]);
2168 rx_SetConnDeadTime(rxconns[nconns], 10);
2172 lock_ReleaseRead(&cm_serverLock);
2175 /* Perform the multi call */
2177 multi_Rx(rxconns,nconns)
2179 multi_RXAFS_GiveUpAllCallBacks();
2180 results[multi_i]=multi_error;
2184 /* Process results of servers that support RXAFS_GetCapabilities */
2185 for (i=0; i<nconns; i++) {
2186 rx_SetConnDeadTime(rxconns[i], ConnDeadtimeout);
2187 rx_PutConnection(rxconns[i]);
2188 cm_PutConn(conns[i]);
2191 cm_GCConnections(tsp);
2194 cm_server_vols_t * tsrvp;
2198 cm_ForceNewConnections(tsp);
2200 lock_ObtainMutex(&tsp->mx);
2201 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
2202 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
2203 tsp->downTime = time(NULL);
2205 /* Now update the volume status */
2206 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2207 for (i=0; i<NUM_SERVER_VOLS; i++) {
2208 if (tsrvp->ids[i] != 0) {
2212 lock_ReleaseMutex(&tsp->mx);
2213 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2214 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2215 lock_ObtainMutex(&tsp->mx);
2217 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2223 lock_ReleaseMutex(&tsp->mx);