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);
200 lock_ObtainWrite(&scp->rw);
201 cm_DiscardSCache(scp);
202 lock_ReleaseWrite(&scp->rw);
204 cm_CallbackNotifyChange(scp);
206 lock_ObtainWrite(&cm_scacheLock);
207 cm_ReleaseSCacheNoLock(scp);
210 lock_ReleaseWrite(&cm_scacheLock);
212 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
213 fidp->Volume, fidp->Vnode, fidp->Unique);
217 cm_callbackDiscardROVolumeByFID(cm_fid_t *fidp)
219 cm_volume_t *volp = cm_GetVolumeByFID(fidp);
222 if (volp->cbExpiresRO) {
223 volp->cbExpiresRO = 0;
224 if (volp->cbServerpRO) {
225 cm_PutServer(volp->cbServerpRO);
226 volp->cbServerpRO = NULL;
228 volp->creationDateRO = 0;
233 /* called to revoke a volume callback, which is typically issued when a volume
234 * is moved from one server to another.
236 * Called with no locks held.
238 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
244 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
246 /* do this first, so that if we're executing a callback granting call
247 * at this moment, we kill it before it can be merged in. Otherwise,
248 * it could complete while we're doing the scan below, and get missed
249 * by both the scan and by this code.
251 tfid.cell = cellp ? cellp->cellID : 0;
252 tfid.volume = fidp->Volume;
253 tfid.vnode = tfid.unique = 0;
255 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
257 lock_ObtainWrite(&cm_scacheLock);
258 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
259 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
260 if (scp->fid.volume == fidp->Volume &&
261 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
262 scp->cbExpires > 0 &&
263 scp->cbServerp != NULL) {
264 cm_HoldSCacheNoLock(scp);
265 lock_ReleaseWrite(&cm_scacheLock);
267 lock_ObtainWrite(&scp->rw);
268 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
269 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
270 cm_DiscardSCache(scp);
271 lock_ReleaseWrite(&scp->rw);
273 cm_CallbackNotifyChange(scp);
274 lock_ObtainWrite(&cm_scacheLock);
275 cm_ReleaseSCacheNoLock(scp);
276 if (scp->flags & CM_SCACHEFLAG_PURERO)
277 cm_callbackDiscardROVolumeByFID(&scp->fid);
279 } /* search one hash bucket */
280 } /* search all hash buckets */
282 lock_ReleaseWrite(&cm_scacheLock);
284 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
288 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
289 * given data pointer, without triggering "cast truncates pointer"
290 * warnings. We use this where we explicitly don't care whether a
291 * pointer is truncated -- it loses information where a pointer is
292 * larger than an afs_int32.
296 afs_data_pointer_to_int32(const void *p)
299 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
303 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
308 /* used to determine the byte order of the system */
311 char c[sizeof(int) / sizeof(char)];
317 /* little-endian system */
320 /* big-endian system */
321 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
326 return ip.i32[i32_sub];
328 /*------------------------------------------------------------------------
329 * EXPORTED SRXAFSCB_CallBack
332 * Routine called by the server-side callback RPC interface to
333 * implement passing in callback information.
337 * rx_call : Ptr to Rx call on which this request came in.
338 * fidsArrayp : Ptr to array of fids involved.
339 * cbsArrayp : Ptr to matching callback info for the fids.
345 * Nothing interesting.
349 *------------------------------------------------------------------------*/
350 /* handle incoming RPC callback breaking message.
351 * Called with no locks held.
354 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
358 struct rx_connection *connp;
359 struct rx_peer *peerp;
360 unsigned long host = 0;
361 unsigned short port = 0;
362 cm_server_t *tsp = NULL;
363 cm_cell_t* cellp = NULL;
368 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
369 host = rx_HostOf(peerp);
370 port = rx_PortOf(peerp);
372 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
379 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
383 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
386 cellp->name /* does not need to be saved, doesn't change */);
388 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
392 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
393 tfidp = &fidsArrayp->AFSCBFids_val[i];
395 if (tfidp->Volume == 0)
396 continue; /* means don't do anything */
397 else if (tfidp->Vnode == 0)
398 cm_RevokeVolumeCallback(callp, cellp, tfidp);
400 cm_RevokeCallback(callp, cellp, tfidp);
405 /*------------------------------------------------------------------------
406 * EXPORTED SRXAFSCB_InitCallBackState
409 * Routine called by the server-side callback RPC interface to
410 * implement clearing all callbacks from this host.
413 * rx_call : Ptr to Rx call on which this request came in.
419 * Nothing interesting.
423 *------------------------------------------------------------------------*/
424 /* called with no locks by RPC system when a server indicates that it has never
425 * heard from us, or for other reasons has had to discard callbacks from us
426 * without telling us, e.g. a network partition.
429 SRXAFSCB_InitCallBackState(struct rx_call *callp)
434 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState ->");
436 return SRXAFSCB_InitCallBackState3(callp, NULL);
439 /*------------------------------------------------------------------------
440 * EXPORTED SRXAFSCB_Probe
443 * Routine called by the server-side callback RPC interface to
444 * implement ``probing'' the Cache Manager, just making sure it's
448 * rx_call : Ptr to Rx call on which this request came in.
454 * Nothing interesting.
458 *------------------------------------------------------------------------*/
460 SRXAFSCB_Probe(struct rx_call *callp)
462 struct rx_connection *connp;
463 struct rx_peer *peerp;
464 unsigned long host = 0;
465 unsigned short port = 0;
470 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
471 host = rx_HostOf(peerp);
472 port = rx_PortOf(peerp);
475 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
482 /*------------------------------------------------------------------------
483 * EXPORTED SRXAFSCB_GetLock
486 * Routine called by the server-side callback RPC interface to
487 * implement pulling out the contents of a lock in the lock
491 * a_call : Ptr to Rx call on which this request came in.
492 * a_index : Index of desired lock.
493 * a_result : Ptr to a buffer for the given lock.
496 * 0 if everything went fine,
497 * 1 if we were given a bad index.
500 * Nothing interesting.
504 *------------------------------------------------------------------------*/
505 /* debug interface */
507 extern osi_rwlock_t cm_aclLock;
508 extern osi_rwlock_t buf_globalLock;
509 extern osi_rwlock_t cm_cellLock;
510 extern osi_rwlock_t cm_connLock;
511 extern osi_rwlock_t cm_daemonLock;
512 extern osi_rwlock_t cm_dnlcLock;
513 extern osi_rwlock_t cm_scacheLock;
514 extern osi_rwlock_t cm_serverLock;
515 extern osi_rwlock_t cm_syscfgLock;
516 extern osi_rwlock_t cm_userLock;
517 extern osi_rwlock_t cm_utilsLock;
518 extern osi_rwlock_t cm_volumeLock;
519 extern osi_rwlock_t smb_globalLock;
520 extern osi_rwlock_t smb_rctLock;
522 extern osi_mutex_t cm_Freelance_Lock;
523 extern osi_mutex_t cm_Afsdsbmt_Lock;
524 extern osi_mutex_t tokenEventLock;
525 extern osi_mutex_t smb_ListenerLock;
526 extern osi_mutex_t smb_RawBufLock;
527 extern osi_mutex_t smb_Dir_Watch_Lock;
529 #define LOCKTYPE_RW 1
530 #define LOCKTYPE_MUTEX 2
531 static struct _ltable {
536 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
537 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
538 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
539 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
540 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
541 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
542 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
543 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
544 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
545 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
546 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
547 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
548 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
549 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
550 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
551 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
552 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
553 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
554 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
555 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
556 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
560 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
562 struct _ltable *tl; /*Ptr to lock table entry */
565 int nentries; /*Num entries in table */
566 int code; /*Return code */
567 struct rx_connection *connp;
568 struct rx_peer *peerp;
569 unsigned long host = 0;
570 unsigned short port = 0;
575 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
576 host = rx_HostOf(peerp);
577 port = rx_PortOf(peerp);
580 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
581 index, ntohl(host), ntohs(port));
583 nentries = sizeof(ltable) / sizeof(struct _ltable);
584 if (index < 0 || index >= nentries) {
591 * Found it - copy out its contents.
594 strncpy(lockp->name, tl->name, sizeof(lockp->name));
595 lockp->name[sizeof(lockp->name)-1] = '\0';
596 lockp->lock.waitStates = 0;
597 switch ( tl->type ) {
599 rwp = (osi_rwlock_t *)tl->addr;
600 lockp->lock.exclLocked = rwp->flags;
601 lockp->lock.readersReading = rwp->readers;
602 lockp->lock.numWaiting = rwp->waiters;
605 mtxp = (osi_mutex_t *)tl->addr;
606 lockp->lock.exclLocked = mtxp->flags;
607 lockp->lock.readersReading = 0;
608 lockp->lock.numWaiting = mtxp->waiters;
611 lockp->lock.pid_last_reader = 0;
612 lockp->lock.pid_writer = 0;
613 lockp->lock.src_indicator = 0;
620 /* debug interface */
622 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
627 struct rx_connection *connp;
628 struct rx_peer *peerp;
629 unsigned long host = 0;
630 unsigned short port = 0;
635 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
636 host = rx_HostOf(peerp);
637 port = rx_PortOf(peerp);
640 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
641 ntohl(host), ntohs(port));
643 lock_ObtainRead(&cm_scacheLock);
644 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
645 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
649 } /*Zip through current hash chain */
650 } /*Zip through hash chains */
660 * Copy out the located entry.
662 memset(cep, 0, sizeof(AFSDBCacheEntry));
663 cep->addr = afs_data_pointer_to_int32(scp);
664 cep->cell = scp->fid.cell;
665 cep->netFid.Volume = scp->fid.volume;
666 cep->netFid.Vnode = scp->fid.vnode;
667 cep->netFid.Unique = scp->fid.unique;
668 cep->lock.waitStates = 0;
669 cep->lock.exclLocked = scp->rw.flags;
670 cep->lock.readersReading = 0;
671 cep->lock.numWaiting = scp->rw.waiters;
672 cep->lock.pid_last_reader = 0;
673 cep->lock.pid_writer = 0;
674 cep->lock.src_indicator = 0;
675 cep->Length = scp->length.LowPart;
676 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
677 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
678 if (scp->flags & CM_SCACHEFLAG_PURERO) {
679 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
681 cep->cbExpires = volp->cbExpiresRO;
685 /* TODO: deal with time_t below */
686 cep->cbExpires = (afs_int32) scp->cbExpires;
688 cep->refCount = scp->refCount;
689 cep->opens = scp->openReads;
690 cep->writers = scp->openWrites;
691 switch (scp->fileType) {
692 case CM_SCACHETYPE_FILE:
695 case CM_SCACHETYPE_MOUNTPOINT:
698 case CM_SCACHETYPE_DIRECTORY:
699 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
704 case CM_SCACHETYPE_SYMLINK:
707 case CM_SCACHETYPE_DFSLINK:
710 case CM_SCACHETYPE_INVALID:
715 if (scp->flags & CM_SCACHEFLAG_STATD)
717 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
719 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
720 scp->mountPointStringp[0])
722 if (scp->flags & CM_SCACHEFLAG_WAITING)
727 * Return our results.
730 lock_ReleaseRead(&cm_scacheLock);
735 /* debug interface */
737 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
742 struct rx_connection *connp;
743 struct rx_peer *peerp;
744 unsigned long host = 0;
745 unsigned short port = 0;
750 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
751 host = rx_HostOf(peerp);
752 port = rx_PortOf(peerp);
755 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
756 ntohl(host), ntohs(port));
758 lock_ObtainRead(&cm_scacheLock);
759 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
760 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
764 } /*Zip through current hash chain */
765 } /*Zip through hash chains */
775 * Copy out the located entry.
777 memset(cep, 0, sizeof(AFSDBCacheEntry64));
778 cep->addr = afs_data_pointer_to_int32(scp);
779 cep->cell = scp->fid.cell;
780 cep->netFid.Volume = scp->fid.volume;
781 cep->netFid.Vnode = scp->fid.vnode;
782 cep->netFid.Unique = scp->fid.unique;
783 cep->lock.waitStates = 0;
784 cep->lock.exclLocked = scp->rw.flags;
785 cep->lock.readersReading = 0;
786 cep->lock.numWaiting = scp->rw.waiters;
787 cep->lock.pid_last_reader = 0;
788 cep->lock.pid_writer = 0;
789 cep->lock.src_indicator = 0;
790 cep->Length = (afs_int64) scp->length.QuadPart;
791 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
792 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
793 if (scp->flags & CM_SCACHEFLAG_PURERO) {
794 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
796 cep->cbExpires = volp->cbExpiresRO;
800 /* TODO: handle time_t */
801 cep->cbExpires = (afs_int32) scp->cbExpires;
803 cep->refCount = scp->refCount;
804 cep->opens = scp->openReads;
805 cep->writers = scp->openWrites;
806 switch (scp->fileType) {
807 case CM_SCACHETYPE_FILE:
810 case CM_SCACHETYPE_MOUNTPOINT:
813 case CM_SCACHETYPE_DIRECTORY:
814 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
819 case CM_SCACHETYPE_SYMLINK:
822 case CM_SCACHETYPE_DFSLINK:
825 case CM_SCACHETYPE_INVALID:
830 if (scp->flags & CM_SCACHEFLAG_STATD)
832 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
834 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
835 scp->mountPointStringp[0])
837 if (scp->flags & CM_SCACHEFLAG_WAITING)
842 * Return our results.
845 lock_ReleaseRead(&cm_scacheLock);
850 /* debug interface: not implemented */
852 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
854 struct rx_connection *connp;
855 struct rx_peer *peerp;
856 unsigned long host = 0;
857 unsigned short port = 0;
862 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
863 host = rx_HostOf(peerp);
864 port = rx_PortOf(peerp);
867 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
868 ntohl(host), ntohs(port));
874 /* debug interface: not implemented */
876 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
877 AFSCB_CollData *datap)
879 struct rx_connection *connp;
880 struct rx_peer *peerp;
881 unsigned long host = 0;
882 unsigned short port = 0;
887 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
888 host = rx_HostOf(peerp);
889 port = rx_PortOf(peerp);
892 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
893 ntohl(host), ntohs(port));
899 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
904 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
906 return SRXAFSCB_InitCallBackState3(callp, NULL);
909 /* debug interface */
911 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
915 struct rx_connection *connp;
916 struct rx_peer *peerp;
917 unsigned long host = 0;
918 unsigned short port = 0;
923 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
924 host = rx_HostOf(peerp);
925 port = rx_PortOf(peerp);
928 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
932 lock_ObtainRead(&cm_syscfgLock);
933 if (cm_LanAdapterChangeDetected) {
934 lock_ConvertRToW(&cm_syscfgLock);
935 if (cm_LanAdapterChangeDetected) {
936 /* get network related info */
937 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
938 code = syscfg_GetIFInfo(&cm_noIPAddr,
939 cm_IPAddr, cm_SubnetMask,
940 cm_NetMtu, cm_NetFlags);
941 cm_LanAdapterChangeDetected = 0;
943 lock_ConvertWToR(&cm_syscfgLock);
946 /* return all network interface addresses */
947 addr->numberOfInterfaces = cm_noIPAddr;
948 addr->uuid = cm_data.Uuid;
949 for ( i=0; i < cm_noIPAddr; i++ ) {
950 addr->addr_in[i] = cm_IPAddr[i];
951 addr->subnetmask[i] = cm_SubnetMask[i];
952 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
953 cm_NetMtu[i] : rx_mtu;
956 lock_ReleaseRead(&cm_syscfgLock);
962 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
966 cm_server_t *tsp = NULL;
967 cm_scache_t *scp = NULL;
968 cm_cell_t* cellp = NULL;
971 struct rx_connection *connp;
972 struct rx_peer *peerp;
973 unsigned long host = 0;
974 unsigned short port = 0;
979 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
980 host = rx_HostOf(peerp);
981 port = rx_PortOf(peerp);
984 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
985 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 Uuid%s ->",osi_LogSaveString(afsd_logp,p));
989 tsp = cm_FindServerByUuid(serverUuid, CM_SERVER_FILE, FALSE);
992 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
999 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d",
1003 osi_Log3(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d for cell %s",
1006 cellp->name /* does not need to be saved, doesn't change */);
1008 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 from unknown host");
1011 if (connp && peerp) {
1012 tsp = cm_FindServerByIP(host, port, CM_SERVER_FILE, FALSE);
1014 osi_Log1(afsd_logp, "InitCallbackState3 server %x", tsp);
1016 /* record the callback in the racing revokes structure. This
1017 * shouldn't be necessary, since we shouldn't be making callback
1018 * granting calls while we're going to get an initstate call,
1019 * but there probably are some obscure races, so better safe
1022 * We do this first since we don't hold the cm_scacheLock and vnode
1023 * locks over the entire callback scan operation below. The
1024 * big loop below is guaranteed to hit any callback already
1025 * processed. The call to RecordRacingRevoke is guaranteed
1026 * to kill any callback that is currently being returned.
1027 * Anything that sneaks past both must start
1028 * after the call to RecordRacingRevoke.
1033 fid.cell = cellp->cellID;
1034 fid.volume = fid.vnode = fid.unique = 0;
1036 cm_RecordRacingRevoke(&fid, CM_RACINGFLAG_CANCELALL);
1038 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
1041 /* now search all vnodes looking for guys with this callback, if we
1042 * found it, or guys with any callbacks, if we didn't find the server
1043 * (that's how multihomed machines will appear and how we'll handle
1044 * them, albeit a little inefficiently). That is, we're discarding all
1045 * callbacks from all hosts if we get an initstate call from an unknown
1046 * host. Since these calls are rare, and multihomed servers
1047 * are "rare," hopefully this won't be a problem.
1049 lock_ObtainWrite(&cm_scacheLock);
1050 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
1051 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
1052 cm_HoldSCacheNoLock(scp);
1053 lock_ReleaseWrite(&cm_scacheLock);
1054 lock_ObtainWrite(&scp->rw);
1056 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
1057 /* we have a callback, now decide if we should clear it */
1058 if (cm_ServerEqual(scp->cbServerp, tsp)) {
1059 osi_Log4(afsd_logp, "InitCallbackState3 Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1060 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1061 cm_DiscardSCache(scp);
1065 lock_ReleaseWrite(&scp->rw);
1067 cm_CallbackNotifyChange(scp);
1068 lock_ObtainWrite(&cm_scacheLock);
1069 cm_ReleaseSCacheNoLock(scp);
1071 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO))
1072 cm_callbackDiscardROVolumeByFID(&scp->fid);
1074 } /* search one hash bucket */
1075 } /* search all hash buckets */
1077 lock_ReleaseWrite(&cm_scacheLock);
1080 /* reset the No flags on the server */
1081 cm_SetServerNo64Bit(tsp, 0);
1082 cm_SetServerNoInlineBulk(tsp, 0);
1084 /* we're done with the server structure */
1091 /* debug interface */
1093 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1095 struct rx_connection *connp;
1096 struct rx_peer *peerp;
1097 unsigned long host = 0;
1098 unsigned short port = 0;
1105 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1106 host = rx_HostOf(peerp);
1107 port = rx_PortOf(peerp);
1110 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1111 UuidToString((UUID *)&cm_data.Uuid, &p);
1112 UuidToString((UUID *)clientUuid, &q);
1113 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1114 osi_LogSaveString(afsd_logp,p),
1115 osi_LogSaveString(afsd_logp,q),
1121 code = 1; /* failure */
1123 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1130 /* debug interface */
1132 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1136 cm_serverRef_t * serverRefp;
1138 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1140 *a_name = strdup("");
1144 lock_ObtainRead(&cm_serverLock);
1145 *a_name = strdup(cellp->name);
1147 for ( sn = 0, serverRefp = cellp->vlServersp;
1148 sn < AFSMAXCELLHOSTS && serverRefp;
1149 sn++, serverRefp = serverRefp->next);
1151 a_hosts->serverList_len = sn;
1152 a_hosts->serverList_val = (afs_int32 *)xdr_alloc(sn * sizeof(afs_int32));
1154 for ( sn = 0, serverRefp = cellp->vlServersp;
1155 sn < AFSMAXCELLHOSTS && serverRefp;
1156 sn++, serverRefp = serverRefp->next)
1158 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1161 lock_ReleaseRead(&cm_serverLock);
1165 /* debug interface */
1167 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1168 char **a_name, serverList *a_hosts)
1170 struct rx_connection *connp;
1171 struct rx_peer *peerp;
1172 unsigned long host = 0;
1173 unsigned short port = 0;
1179 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1180 host = rx_HostOf(peerp);
1181 port = rx_PortOf(peerp);
1184 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1185 a_cellnum, ntohl(host), ntohs(port));
1187 a_hosts->serverList_val = 0;
1188 a_hosts->serverList_len = 0;
1191 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1196 /* debug interface */
1198 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1199 struct interfaceAddr *addr,
1200 Capabilities * capabilities)
1203 afs_uint32 *dataBuffP;
1204 afs_int32 dataBytes;
1206 struct rx_connection *connp;
1207 struct rx_peer *peerp;
1208 unsigned long host = 0;
1209 unsigned short port = 0;
1214 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1215 host = rx_HostOf(peerp);
1216 port = rx_PortOf(peerp);
1219 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1223 lock_ObtainRead(&cm_syscfgLock);
1224 if (cm_LanAdapterChangeDetected) {
1225 lock_ConvertRToW(&cm_syscfgLock);
1226 if (cm_LanAdapterChangeDetected) {
1227 /* get network related info */
1228 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1229 code = syscfg_GetIFInfo(&cm_noIPAddr,
1230 cm_IPAddr, cm_SubnetMask,
1231 cm_NetMtu, cm_NetFlags);
1232 cm_LanAdapterChangeDetected = 0;
1234 lock_ConvertWToR(&cm_syscfgLock);
1237 /* return all network interface addresses */
1238 addr->numberOfInterfaces = cm_noIPAddr;
1239 addr->uuid = cm_data.Uuid;
1240 for ( i=0; i < cm_noIPAddr; i++ ) {
1241 addr->addr_in[i] = cm_IPAddr[i];
1242 addr->subnetmask[i] = cm_SubnetMask[i];
1243 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1244 cm_NetMtu[i] : rx_mtu;
1246 lock_ReleaseRead(&cm_syscfgLock);
1248 dataBytes = 1 * sizeof(afs_uint32);
1249 dataBuffP = (afs_uint32 *) xdr_alloc(dataBytes);
1250 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1251 capabilities->Capabilities_len = dataBytes / sizeof(afs_uint32);
1252 capabilities->Capabilities_val = dataBuffP;
1257 /*------------------------------------------------------------------------
1258 * EXPORTED SRXAFSCB_GetServerPrefs
1261 * Routine to list server preferences used by this client.
1264 * a_call : Ptr to Rx call on which this request came in.
1265 * a_index : Input server index
1266 * a_srvr_addr : Output server address (0xffffffff on last server)
1267 * a_srvr_rank : Output server rank
1273 * Nothing interesting.
1277 *------------------------------------------------------------------------*/
1279 int SRXAFSCB_GetServerPrefs(
1280 struct rx_call *callp,
1282 afs_int32 *a_srvr_addr,
1283 afs_int32 *a_srvr_rank)
1285 struct rx_connection *connp;
1286 struct rx_peer *peerp;
1287 unsigned long host = 0;
1288 unsigned short port = 0;
1293 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1294 host = rx_HostOf(peerp);
1295 port = rx_PortOf(peerp);
1298 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1302 *a_srvr_addr = 0xffffffff;
1303 *a_srvr_rank = 0xffffffff;
1308 /*------------------------------------------------------------------------
1309 * EXPORTED SRXAFSCB_GetCellServDB
1312 * Routine to list cells configured for this client
1315 * a_call : Ptr to Rx call on which this request came in.
1316 * a_index : Input cell index
1317 * a_name : Output cell name ("" on last cell)
1318 * a_hosts : Output cell database servers
1324 * Nothing interesting.
1328 *------------------------------------------------------------------------*/
1330 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1331 serverList *a_hosts)
1333 struct rx_connection *connp;
1334 struct rx_peer *peerp;
1335 unsigned long host = 0;
1336 unsigned short port = 0;
1342 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1343 host = rx_HostOf(peerp);
1344 port = rx_PortOf(peerp);
1347 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1348 ntohl(host), ntohs(port));
1350 #ifdef AFS_FREELANCE_CLIENT
1351 if (cm_freelanceEnabled && index == 0) {
1352 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1356 rc = GetCellCommon(index+1, a_name, a_hosts);
1361 /*------------------------------------------------------------------------
1362 * EXPORTED SRXAFSCB_GetLocalCell
1365 * Routine to return name of client's local cell
1368 * a_call : Ptr to Rx call on which this request came in.
1369 * a_name : Output cell name
1375 * Nothing interesting.
1379 *------------------------------------------------------------------------*/
1381 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1384 struct rx_connection *connp;
1385 struct rx_peer *peerp;
1386 unsigned long host = 0;
1387 unsigned short port = 0;
1392 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1393 host = rx_HostOf(peerp);
1394 port = rx_PortOf(peerp);
1397 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1398 ntohl(host), ntohs(port));
1400 if (cm_data.rootCellp) {
1401 t_name = strdup(cm_data.rootCellp->name);
1403 t_name = (char *)xdr_alloc(1);
1413 * afs_MarshallCacheConfig - marshall client cache configuration
1417 * IN callerVersion - the rpc stat version of the caller.
1419 * IN config - client cache configuration.
1421 * OUT ptr - buffer where configuration is marshalled.
1427 static void afs_MarshallCacheConfig(
1428 afs_uint32 callerVersion,
1429 cm_initparams_v1 *config,
1433 * We currently only support version 1.
1435 *(ptr++) = config->nChunkFiles;
1436 *(ptr++) = config->nStatCaches;
1437 *(ptr++) = config->nDataCaches;
1438 *(ptr++) = config->nVolumeCaches;
1439 *(ptr++) = config->firstChunkSize;
1440 *(ptr++) = config->otherChunkSize;
1441 *(ptr++) = config->cacheSize;
1442 *(ptr++) = config->setTime;
1443 *(ptr++) = config->memCache;
1448 /*------------------------------------------------------------------------
1449 * EXPORTED SRXAFSCB_GetCacheConfig
1452 * Routine to return parameters used to initialize client cache.
1453 * Client may request any format version. Server may not return
1454 * format version greater than version requested by client.
1457 * a_call: Ptr to Rx call on which this request came in.
1458 * callerVersion: Data format version desired by the client.
1459 * serverVersion: Data format version of output data.
1460 * configCount: Number bytes allocated for output data.
1461 * config: Client cache configuration.
1467 * Nothing interesting.
1471 *------------------------------------------------------------------------*/
1473 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1474 afs_uint32 callerVersion,
1475 afs_uint32 *serverVersion,
1476 afs_uint32 *configCount,
1477 cacheConfig *config)
1479 afs_uint32 *t_config;
1481 extern cm_initparams_v1 cm_initParams;
1482 struct rx_connection *connp;
1483 struct rx_peer *peerp;
1484 unsigned long host = 0;
1485 unsigned short port = 0;
1490 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1491 host = rx_HostOf(peerp);
1492 port = rx_PortOf(peerp);
1495 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1496 ntohl(host), ntohs(port));
1499 * Currently only support version 1
1501 allocsize = sizeof(cm_initparams_v1);
1502 t_config = (afs_uint32 *)xdr_alloc(allocsize);
1504 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1506 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1509 #define SIZE_MAX UINT_MAX
1511 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1513 *configCount = (afs_uint32)allocsize;
1514 config->cacheConfig_val = t_config;
1515 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1520 /* called by afsd without any locks to initialize this module */
1521 void cm_InitCallback(void)
1523 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1524 cm_activeCallbackGrantingCalls = 0;
1527 /* called with locked scp; tells us whether we've got a callback.
1528 * Expirations are checked by a background daemon so as to make
1529 * this function as inexpensive as possible
1531 int cm_HaveCallback(cm_scache_t *scp)
1533 #ifdef AFS_FREELANCE_CLIENT
1534 if (cm_freelanceEnabled &&
1535 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1536 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1537 if (cm_getLocalMountPointChange()) {
1538 cm_clearLocalMountPointChange();
1539 lock_ReleaseWrite(&scp->rw);
1540 cm_reInitLocalMountPoints();
1541 lock_ObtainWrite(&scp->rw);
1543 return (cm_data.fakeDirVersion == scp->dataVersion);
1546 if (cm_readonlyVolumeVersioning &&
1547 (scp->flags & CM_SCACHEFLAG_PURERO)) {
1548 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1551 if (cm_OfflineROIsValid) {
1552 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1561 volp->creationDateRO == scp->volumeCreationDate &&
1562 volp->cbServerpRO != NULL) {
1569 if (scp->cbServerp != NULL)
1575 /* need to detect a broken callback that races with our obtaining a callback.
1576 * Need to be able to do this even if we don't know the file ID of the file
1577 * we're breaking the callback on at the time we start the acquisition of the
1578 * callback (as in the case where we are creating a file).
1580 * So, we start by writing down the count of the # of callbacks we've received
1581 * so far, and bumping a global counter of the # of callback granting calls
1582 * outstanding (all done under cm_callbackLock).
1584 * When we're back from the call, we look at all of the callback revokes with
1585 * counter numbers greater than the one we recorded in our caller's structure,
1586 * and replay those that are higher than when we started the call.
1588 * We free all the structures in the queue when the count of the # of outstanding
1589 * callback-granting calls drops to zero.
1591 * We call this function with the scp locked, too, but in its current implementation,
1592 * this knowledge is not used.
1594 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1596 lock_ObtainWrite(&cm_callbackLock);
1597 cbrp->callbackCount = cm_callbackCount;
1598 cm_activeCallbackGrantingCalls++;
1599 cbrp->startTime = time(NULL);
1600 cbrp->serverp = NULL;
1601 lock_ReleaseWrite(&cm_callbackLock);
1604 /* Called at the end of a callback-granting call, to remove the callback
1605 * info from the scache entry, if necessary.
1607 * Called with scp write locked, so we can discard the callbacks easily with
1608 * this locking hierarchy.
1610 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1611 AFSCallBack *cbp, AFSVolSync *volSyncp, long flags)
1613 cm_racingRevokes_t *revp; /* where we are */
1614 cm_racingRevokes_t *nrevp; /* where we'll be next */
1616 cm_server_t * serverp = NULL;
1617 int discardScp = 0, discardVolCB = 0;
1619 lock_ObtainWrite(&cm_callbackLock);
1620 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1621 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1622 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1625 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1626 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1628 if (cm_activeCallbackGrantingCalls == 0)
1633 /* record the callback; we'll clear it below if we really lose it */
1636 if (!cm_ServerEqual(scp->cbServerp, cbrp->serverp)) {
1637 serverp = scp->cbServerp;
1639 cm_GetServer(cbrp->serverp);
1640 scp->cbServerp = cbrp->serverp;
1643 serverp = cbrp->serverp;
1645 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1648 serverp = cbrp->serverp;
1651 cbrp->serverp = NULL;
1654 /* a callback was actually revoked during our granting call, so
1655 * run down the list of revoked fids, looking for ours.
1656 * If activeCallbackGrantingCalls is zero, free the elements, too.
1658 * May need to go through entire list just to do the freeing.
1660 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1661 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1662 /* if this callback came in later than when we started the
1663 * callback-granting call, and if this fid is the right fid,
1664 * then clear the callback.
1666 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1667 && revp->callbackCount > cbrp->callbackCount
1668 && (( scp->fid.volume == revp->fid.volume &&
1669 scp->fid.vnode == revp->fid.vnode &&
1670 scp->fid.unique == revp->fid.unique)
1672 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1673 scp->fid.volume == revp->fid.volume)
1675 ((revp->flags & CM_RACINGFLAG_CANCELALL) &&
1676 (revp->fid.cell == 0 || scp->fid.cell == revp->fid.cell)))) {
1677 /* this one matches */
1679 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1681 cbrp->callbackCount, revp->callbackCount,
1684 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1685 (revp->flags & CM_RACINGFLAG_ALL))
1686 cm_callbackDiscardROVolumeByFID(&scp->fid);
1692 /* if we freed the list, zap the pointer to it */
1694 cm_racingRevokesp = NULL;
1696 lock_ReleaseWrite(&cm_callbackLock);
1699 cm_DiscardSCache(scp);
1700 lock_ReleaseWrite(&scp->rw);
1701 cm_CallbackNotifyChange(scp);
1702 lock_ObtainWrite(&scp->rw);
1704 if (scp && scp->flags & CM_SCACHEFLAG_PURERO) {
1705 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1708 lock_ObtainWrite(&cm_scacheLock);
1709 volp->cbExpiresRO = scp->cbExpires;
1710 volp->creationDateRO = volSyncp->spare1;
1711 if (volp->cbServerpRO != scp->cbServerp) {
1712 if (volp->cbServerpRO)
1713 cm_PutServer(volp->cbServerpRO);
1714 cm_GetServer(scp->cbServerp);
1715 volp->cbServerpRO = scp->cbServerp;
1717 lock_ReleaseWrite(&cm_scacheLock);
1725 lock_ObtainWrite(&cm_serverLock);
1726 cm_FreeServer(serverp);
1727 lock_ReleaseWrite(&cm_serverLock);
1731 /* if flags is 1, we want to force the code to make one call, anyway.
1732 * called with locked scp; returns with same.
1734 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1735 struct cm_req *reqp, long flags)
1738 cm_conn_t *connp = NULL;
1739 AFSFetchStatus afsStatus;
1741 AFSCallBack callback;
1743 cm_callbackRequest_t cbr;
1746 struct rx_connection * rxconnp = NULL;
1747 int syncop_done = 0;
1749 memset(&volSync, 0, sizeof(volSync));
1751 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1752 scp, scp->fid.cell, scp->fid.volume, flags);
1754 #ifdef AFS_FREELANCE_CLIENT
1755 // The case where a callback is needed on /afs is handled
1756 // specially. We need to fetch the status by calling
1758 if (cm_freelanceEnabled &&
1759 (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1760 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)) {
1762 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1763 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1768 if (scp->dataVersion != cm_data.fakeDirVersion) {
1769 memset(&afsStatus, 0, sizeof(afsStatus));
1770 memset(&volSync, 0, sizeof(volSync));
1772 // Fetch the status info
1773 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1777 #endif /* AFS_FREELANCE_CLIENT */
1779 mustCall = (flags & 1);
1780 cm_AFSFidFromFid(&tfid, &scp->fid);
1782 if (!mustCall && cm_HaveCallback(scp))
1785 /* turn off mustCall, since it has now forced us past the check above */
1788 /* otherwise, we have to make an RPC to get the status */
1790 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1791 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1796 cm_StartCallbackGrantingCall(scp, &cbr);
1798 lock_ReleaseWrite(&scp->rw);
1800 /* now make the RPC */
1801 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1802 scp, sfid.volume, sfid.vnode, sfid.unique);
1804 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1808 rxconnp = cm_GetRxConn(connp);
1809 code = RXAFS_FetchStatus(rxconnp, &tfid,
1810 &afsStatus, &callback, &volSync);
1811 rx_PutConnection(rxconnp);
1813 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1815 code = cm_MapRPCError(code, reqp);
1817 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1818 code, scp, scp->fid.volume, scp->fid.vnode);
1820 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1821 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1823 lock_ObtainWrite(&scp->rw);
1825 cm_EndCallbackGrantingCall(scp, &cbr, &callback, &volSync, 0);
1826 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
1828 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, NULL, 0);
1831 /* if we got an error, return to caller */
1838 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1841 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1842 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1843 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1845 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1846 scp, scp->fid.cell, scp->fid.volume);
1854 * cm_CBServersDownTime() returns 1 if the downTime parameter is valid.
1856 * Servers with multiple interfaces have multiple cm_server_t objects
1857 * which share the same UUID. If one interface is down but others are up,
1858 * the server should not be considered down. The returned downTime should
1859 * be the largest non-zero value if down or zero if up. If the cbServerp
1860 * is down, it is updated to refer to an interface that is up (if one exists).
1862 * called with cm_scacheLock held
1865 cm_CBServersDownTime(cm_scache_t *scp, cm_volume_t *volp, time_t * pdownTime)
1867 cm_vol_state_t *statep;
1868 cm_serverRef_t *tsrp;
1870 time_t downTime = 0;
1871 cm_server_t * upserver = NULL;
1872 cm_server_t * downserver;
1876 if (scp->cbServerp == NULL)
1879 if (!(scp->cbServerp->flags & CM_SERVERFLAG_DOWN))
1882 statep = cm_VolumeStateByID(volp, scp->fid.volume);
1884 for (tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1885 if (tsrp->status == srv_deleted)
1888 if (!cm_ServerEqual(tsrp->server, scp->cbServerp))
1891 if (!(tsrp->server->flags & CM_SERVERFLAG_DOWN)) {
1894 upserver = tsrp->server;
1895 cm_GetServer(upserver);
1899 if (tsrp->server->downTime > downTime)
1900 downTime = tsrp->server->downTime;
1903 downTime = scp->cbServerp->downTime;
1906 /* if the cbServerp does not match the current volume server list
1907 * we report the callback server as up so the callback can be
1912 *pdownTime = downTime;
1914 lock_ObtainWrite(&scp->rw);
1915 downserver = scp->cbServerp;
1916 scp->cbServerp = upserver;
1917 lock_ReleaseWrite(&scp->rw);
1918 cm_PutServer(downserver);
1923 /* called periodically by cm_daemon to shut down use of expired callbacks */
1924 void cm_CheckCBExpiration(void)
1929 enum volstatus volstate;
1930 time_t now, downTime;
1932 osi_Log0(afsd_logp, "CheckCBExpiration");
1935 lock_ObtainWrite(&cm_scacheLock);
1936 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1937 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1939 cm_HoldSCacheNoLock(scp);
1940 lock_ReleaseWrite(&cm_scacheLock);
1943 * If this is not a PURERO object and there is no callback
1944 * or it hasn't expired, there is nothing to do
1946 if (!(scp->flags & CM_SCACHEFLAG_PURERO) &&
1947 (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires))
1951 * Determine the volume state and update the callback info
1952 * to the latest if it is a PURERO object.
1954 volp = cm_GetVolumeByFID(&scp->fid);
1955 volstate = vl_unknown;
1958 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1959 volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1961 lock_ObtainWrite(&scp->rw);
1962 scp->cbExpires = volp->cbExpiresRO;
1963 if (volp->cbServerpRO != scp->cbServerp) {
1965 cm_PutServer(scp->cbServerp);
1966 cm_GetServer(volp->cbServerpRO);
1967 scp->cbServerp = volp->cbServerpRO;
1969 lock_ReleaseWrite(&scp->rw);
1971 volstate = cm_GetVolumeStatus(volp, scp->fid.volume);
1974 /* If there is no callback or it hasn't expired, there is nothing to do */
1975 if (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires)
1978 /* If the volume is known not to be online, do not expire the callback */
1979 if (volstate != vl_online)
1983 * If all the servers are down and the callback expired after the
1984 * issuing server went down, do not expire the callback
1986 if (cm_CBServersDownTime(scp, volp, &downTime) && downTime && downTime < scp->cbExpires)
1989 /* The callback has expired, discard the status info */
1990 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1991 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1992 lock_ObtainWrite(&scp->rw);
1993 cm_DiscardSCache(scp);
1994 lock_ReleaseWrite(&scp->rw);
1996 cm_CallbackNotifyChange(scp);
2002 lock_ObtainWrite(&cm_scacheLock);
2003 cm_ReleaseSCacheNoLock(scp);
2006 lock_ReleaseWrite(&cm_scacheLock);
2008 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
2013 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
2017 struct rx_connection * rxconnp;
2019 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
2021 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
2023 rxconnp = cm_GetRxConn(connp);
2024 rx_SetConnDeadTime(rxconnp, 10);
2025 code = RXAFS_GiveUpAllCallBacks(rxconnp);
2026 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
2027 rx_PutConnection(rxconnp);
2031 cm_server_vols_t * tsrvp;
2035 cm_ForceNewConnections(tsp);
2037 lock_ObtainMutex(&tsp->mx);
2038 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
2039 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
2040 tsp->downTime = time(NULL);
2042 /* Now update the volume status */
2043 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2044 for (i=0; i<NUM_SERVER_VOLS; i++) {
2045 if (tsrvp->ids[i] != 0) {
2049 lock_ReleaseMutex(&tsp->mx);
2050 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2051 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2052 lock_ObtainMutex(&tsp->mx);
2054 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2060 lock_ReleaseMutex(&tsp->mx);
2066 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
2070 if (!cm_giveUpAllCBs)
2073 lock_ObtainWrite(&cm_serverLock);
2074 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
2075 cm_GetServerNoLock(tsp);
2076 lock_ReleaseWrite(&cm_serverLock);
2077 cm_GiveUpAllCallbacks(tsp, markDown);
2078 lock_ObtainWrite(&cm_serverLock);
2079 cm_PutServerNoLock(tsp);
2081 lock_ReleaseWrite(&cm_serverLock);
2085 cm_GiveUpAllCallbacksAllServersMulti(afs_int32 markDown)
2088 cm_conn_t **conns = NULL;
2089 struct rx_connection **rxconns = NULL;
2090 afs_int32 i, nconns = 0, maxconns;
2091 cm_server_t ** serversp, *tsp;
2093 time_t start, *deltas;
2095 maxconns = cm_numFileServers;
2099 conns = (cm_conn_t **)malloc(maxconns * sizeof(cm_conn_t *));
2100 rxconns = (struct rx_connection **)malloc(maxconns * sizeof(struct rx_connection *));
2101 deltas = (time_t *)malloc(maxconns * sizeof (time_t));
2102 results = (afs_int32 *)malloc(maxconns * sizeof (afs_int32));
2103 serversp = (cm_server_t **)malloc(maxconns * sizeof(cm_server_t *));
2105 lock_ObtainRead(&cm_serverLock);
2106 for (nconns=0, tsp = cm_allServersp; tsp && nconns < maxconns; tsp = tsp->allNextp) {
2107 if (tsp->type != CM_SERVER_FILE ||
2108 (tsp->flags & CM_SERVERFLAG_DOWN) ||
2109 tsp->cellp == NULL /* SetPrefs only */)
2112 cm_GetServerNoLock(tsp);
2113 lock_ReleaseRead(&cm_serverLock);
2115 serversp[nconns] = tsp;
2116 code = cm_ConnByServer(tsp, cm_rootUserp, &conns[nconns]);
2118 lock_ObtainRead(&cm_serverLock);
2119 cm_PutServerNoLock(tsp);
2122 lock_ObtainRead(&cm_serverLock);
2123 rxconns[nconns] = cm_GetRxConn(conns[nconns]);
2124 rx_SetConnDeadTime(rxconns[nconns], 10);
2128 lock_ReleaseRead(&cm_serverLock);
2131 /* Perform the multi call */
2133 multi_Rx(rxconns,nconns)
2135 multi_RXAFS_GiveUpAllCallBacks();
2136 results[multi_i]=multi_error;
2140 /* Process results of servers that support RXAFS_GetCapabilities */
2141 for (i=0; i<nconns; i++) {
2142 rx_SetConnDeadTime(rxconns[i], ConnDeadtimeout);
2143 rx_PutConnection(rxconns[i]);
2144 cm_PutConn(conns[i]);
2147 cm_GCConnections(tsp);
2150 cm_server_vols_t * tsrvp;
2154 cm_ForceNewConnections(tsp);
2156 lock_ObtainMutex(&tsp->mx);
2157 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
2158 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
2159 tsp->downTime = time(NULL);
2161 /* Now update the volume status */
2162 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
2163 for (i=0; i<NUM_SERVER_VOLS; i++) {
2164 if (tsrvp->ids[i] != 0) {
2168 lock_ReleaseMutex(&tsp->mx);
2169 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2170 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2171 lock_ObtainMutex(&tsp->mx);
2173 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2179 lock_ReleaseMutex(&tsp->mx);