2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
11 #include <afs/afs_args.h>
22 #include <rx_pthread.h>
24 #include <WINNT/syscfg.h>
25 #include <WINNT/afsreg.h>
26 #include <../afsrdr/kif.h>
28 /*extern void afsi_log(char *pattern, ...);*/
30 /* read/write lock for all global storage in this module */
31 osi_rwlock_t cm_callbackLock;
33 afs_int32 cm_OfflineROIsValid = 0;
35 #ifdef AFS_FREELANCE_CLIENT
36 extern osi_mutex_t cm_Freelance_Lock;
39 /* count of # of callback breaking messages received by this CM so far. We use
40 * this count in determining whether there have been any callback breaks that
41 * apply to a call that returned a new callback. If the counter doesn't
42 * increase during a call, then we know that no callbacks were broken during
43 * that call, and thus that the callback that was just returned is still valid.
45 long cm_callbackCount;
47 /* count of number of RPCs potentially returning a callback executing now.
48 * When this counter hits zero, we can clear out the racing revokes list, since
49 * at that time, we know that none of the just-executed callback revokes will
50 * apply to any future call that returns a callback (since the latter hasn't
51 * even started execution yet).
53 long cm_activeCallbackGrantingCalls;
55 /* list of callbacks that have been broken recently. If a call returning a
56 * callback is executing and a callback revoke runs immediately after it at the
57 * server, the revoke may end up being processed before the response to the
58 * original callback granting call. We detect this by keeping a list of
59 * callback revokes that have been received since we *started* the callback
60 * granting call, and discarding any callbacks received for the same file ID,
61 * even if the callback revoke was received before the callback grant.
63 cm_racingRevokes_t *cm_racingRevokesp;
65 /* record a (potentially) racing revoke for this file ID; null means for all
66 * file IDs, and is used by InitCallBackState.
68 * The cancelFlags describe whether we're just discarding callbacks for the same
69 * file ID, the same volume, or all from the same server.
71 * Called with no locks held.
73 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
75 cm_racingRevokes_t *rp;
77 lock_ObtainWrite(&cm_callbackLock);
79 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
80 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
82 if (cm_activeCallbackGrantingCalls > 0) {
83 rp = malloc(sizeof(*rp));
84 memset(rp, 0, sizeof(*rp));
85 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
86 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
87 if (fidp) rp->fid = *fidp;
88 rp->callbackCount = ++cm_callbackCount;
90 lock_ReleaseWrite(&cm_callbackLock);
94 * When we lose a callback, may have to send change notification replies.
95 * Do not call with a lock on the scp.
97 void cm_CallbackNotifyChange(cm_scache_t *scp)
103 /* why does this have to query the registry each time? */
104 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
105 AFSREG_CLT_OPENAFS_SUBKEY,
107 KEY_READ|KEY_QUERY_VALUE,
108 &hKey) == ERROR_SUCCESS) {
110 dummyLen = sizeof(DWORD);
111 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
112 (BYTE *) &dwDelay, &dummyLen);
116 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
119 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
120 scp->fileType, scp->flags, dwDelay);
125 /* for directories, this sends a change notification on the dir itself */
126 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
128 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
130 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
131 scp, NULL, NULL, TRUE);
133 dc_break_callback(FID_HASH_FN(&scp->fid));
136 /* and for files, this sends a change notification on the file's parent dir */
140 tfid.cell = scp->fid.cell;
141 tfid.volume = scp->fid.volume;
142 tfid.vnode = scp->parentVnode;
143 tfid.unique = scp->parentUnique;
144 dscp = cm_FindSCache(&tfid);
147 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
149 FILE_NOTIFY_GENERIC_FILE_FILTER,
150 dscp, NULL, NULL, TRUE);
153 dc_break_callback(FID_HASH_FN(&dscp->fid));
156 cm_ReleaseSCache(dscp);
160 /* called with no locks held for every file ID that is revoked directly by
161 * a callback revoke call. Does not have to handle volume callback breaks,
162 * since those have already been split out.
164 * The callp parameter is currently unused.
166 void cm_RevokeCallback(struct rx_call *callp, cm_cell_t * cellp, AFSFid *fidp)
172 /* don't bother setting cell, since we won't be checking it (to aid
173 * in working with multi-homed servers: we don't know the cell if we
174 * don't recognize the IP address).
177 tfid.volume = fidp->Volume;
178 tfid.vnode = fidp->Vnode;
179 tfid.unique = fidp->Unique;
180 hash = CM_SCACHE_HASH(&tfid);
182 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
183 fidp->Volume, fidp->Vnode, fidp->Unique);
185 /* do this first, so that if we're executing a callback granting call
186 * at this moment, we kill it before it can be merged in. Otherwise,
187 * it could complete while we're doing the scan below, and get missed
188 * by both the scan and by this code.
190 cm_RecordRacingRevoke(&tfid, 0);
192 lock_ObtainWrite(&cm_scacheLock);
193 /* do all in the hash bucket, since we don't know how many we'll find with
196 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
197 if (scp->fid.volume == tfid.volume &&
198 scp->fid.vnode == tfid.vnode &&
199 scp->fid.unique == tfid.unique &&
200 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
201 scp->cbExpires > 0 &&
202 scp->cbServerp != NULL)
204 cm_HoldSCacheNoLock(scp);
205 lock_ReleaseWrite(&cm_scacheLock);
206 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
207 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
209 lock_ObtainMutex(&scp->mx);
210 cm_DiscardSCache(scp);
211 lock_ReleaseMutex(&scp->mx);
213 cm_CallbackNotifyChange(scp);
215 lock_ObtainWrite(&cm_scacheLock);
216 cm_ReleaseSCacheNoLock(scp);
219 lock_ReleaseWrite(&cm_scacheLock);
221 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
222 fidp->Volume, fidp->Vnode, fidp->Unique);
225 /* called to revoke a volume callback, which is typically issued when a volume
226 * is moved from one server to another.
228 * Called with no locks held.
230 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
236 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
238 /* do this first, so that if we're executing a callback granting call
239 * at this moment, we kill it before it can be merged in. Otherwise,
240 * it could complete while we're doing the scan below, and get missed
241 * by both the scan and by this code.
243 tfid.cell = tfid.vnode = tfid.unique = 0;
244 tfid.volume = fidp->Volume;
245 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
247 lock_ObtainWrite(&cm_scacheLock);
248 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
249 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
250 if (scp->fid.volume == fidp->Volume &&
251 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
252 scp->cbExpires > 0 &&
253 scp->cbServerp != NULL) {
254 cm_HoldSCacheNoLock(scp);
255 lock_ReleaseWrite(&cm_scacheLock);
257 lock_ObtainMutex(&scp->mx);
258 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
259 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
260 cm_DiscardSCache(scp);
261 lock_ReleaseMutex(&scp->mx);
263 cm_CallbackNotifyChange(scp);
264 lock_ObtainWrite(&cm_scacheLock);
265 cm_ReleaseSCacheNoLock(scp);
267 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp) {
268 scp->volp->cbExpiresRO = 0;
272 } /* search one hash bucket */
273 } /* search all hash buckets */
275 lock_ReleaseWrite(&cm_scacheLock);
277 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
281 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
282 * given data pointer, without triggering "cast truncates pointer"
283 * warnings. We use this where we explicitly don't care whether a
284 * pointer is truncated -- it loses information where a pointer is
285 * larger than an afs_int32.
289 afs_data_pointer_to_int32(const void *p)
292 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
296 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
301 /* used to determine the byte order of the system */
304 char c[sizeof(int) / sizeof(char)];
310 /* little-endian system */
313 /* big-endian system */
314 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
319 return ip.i32[i32_sub];
321 /*------------------------------------------------------------------------
322 * EXPORTED SRXAFSCB_CallBack
325 * Routine called by the server-side callback RPC interface to
326 * implement passing in callback information.
330 * rx_call : Ptr to Rx call on which this request came in.
331 * fidsArrayp : Ptr to array of fids involved.
332 * cbsArrayp : Ptr to matching callback info for the fids.
338 * Nothing interesting.
342 *------------------------------------------------------------------------*/
343 /* handle incoming RPC callback breaking message.
344 * Called with no locks held.
347 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
351 struct rx_connection *connp;
352 struct rx_peer *peerp;
353 unsigned long host = 0;
354 unsigned short port = 0;
355 cm_server_t *tsp = NULL;
356 cm_cell_t * cellp = NULL;
358 MUTEX_ENTER(&callp->lock);
360 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
361 host = rx_HostOf(peerp);
362 port = rx_PortOf(peerp);
364 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
369 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
373 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
374 tfidp = &fidsArrayp->AFSCBFids_val[i];
376 if (tfidp->Volume == 0)
377 continue; /* means don't do anything */
378 else if (tfidp->Vnode == 0)
379 cm_RevokeVolumeCallback(callp, cellp, tfidp);
381 cm_RevokeCallback(callp, cellp, tfidp);
384 MUTEX_EXIT(&callp->lock);
388 /*------------------------------------------------------------------------
389 * EXPORTED SRXAFSCB_InitCallBackState
392 * Routine called by the server-side callback RPC interface to
393 * implement clearing all callbacks from this host.
396 * rx_call : Ptr to Rx call on which this request came in.
402 * Nothing interesting.
406 *------------------------------------------------------------------------*/
407 /* called with no locks by RPC system when a server indicates that it has never
408 * heard from us, or for other reasons has had to discard callbacks from us
409 * without telling us, e.g. a network partition.
412 SRXAFSCB_InitCallBackState(struct rx_call *callp)
414 struct sockaddr_in taddr;
419 struct rx_connection *connp;
420 struct rx_peer *peerp;
421 unsigned long host = 0;
422 unsigned short port = 0;
424 MUTEX_ENTER(&callp->lock);
426 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
427 host = rx_HostOf(peerp);
428 port = rx_PortOf(peerp);
431 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
435 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
436 taddr.sin_family = AF_INET;
437 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
439 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
441 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
443 /* record the callback in the racing revokes structure. This
444 * shouldn't be necessary, since we shouldn't be making callback
445 * granting calls while we're going to get an initstate call,
446 * but there probably are some obscure races, so better safe
449 * We do this first since we don't hold the cm_scacheLock and vnode
450 * locks over the entire callback scan operation below. The
451 * big loop below is guaranteed to hit any callback already
452 * processed. The call to RecordRacingRevoke is guaranteed
453 * to kill any callback that is currently being returned.
454 * Anything that sneaks past both must start
455 * after the call to RecordRacingRevoke.
457 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
459 /* now search all vnodes looking for guys with this callback, if we
460 * found it, or guys with any callbacks, if we didn't find the server
461 * (that's how multihomed machines will appear and how we'll handle
462 * them, albeit a little inefficiently). That is, we're discarding all
463 * callbacks from all hosts if we get an initstate call from an unknown
464 * host. Since these calls are rare, and multihomed servers
465 * are "rare," hopefully this won't be a problem.
467 lock_ObtainWrite(&cm_scacheLock);
468 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
469 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
470 cm_HoldSCacheNoLock(scp);
471 lock_ReleaseWrite(&cm_scacheLock);
472 lock_ObtainMutex(&scp->mx);
474 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
475 /* we have a callback, now decide if we should clear it */
476 if (scp->cbServerp == tsp || tsp == NULL) {
477 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%p vol %u vn %u uniq %u",
478 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
479 cm_DiscardSCache(scp);
483 lock_ReleaseMutex(&scp->mx);
485 cm_CallbackNotifyChange(scp);
486 lock_ObtainWrite(&cm_scacheLock);
487 cm_ReleaseSCacheNoLock(scp);
489 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO) && scp->volp && scp->volp->cbExpiresRO != 0)
490 scp->volp->cbExpiresRO = 0;
492 } /* search one hash bucket */
493 } /* search all hash buckets */
495 lock_ReleaseWrite(&cm_scacheLock);
498 /* reset the No flags on the server */
499 cm_SetServerNo64Bit(tsp, 0);
500 cm_SetServerNoInlineBulk(tsp, 0);
502 /* we're done with the server structure */
506 MUTEX_EXIT(&callp->lock);
510 /*------------------------------------------------------------------------
511 * EXPORTED SRXAFSCB_Probe
514 * Routine called by the server-side callback RPC interface to
515 * implement ``probing'' the Cache Manager, just making sure it's
519 * rx_call : Ptr to Rx call on which this request came in.
525 * Nothing interesting.
529 *------------------------------------------------------------------------*/
531 SRXAFSCB_Probe(struct rx_call *callp)
533 struct rx_connection *connp;
534 struct rx_peer *peerp;
535 unsigned long host = 0;
536 unsigned short port = 0;
538 MUTEX_ENTER(&callp->lock);
540 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
541 host = rx_HostOf(peerp);
542 port = rx_PortOf(peerp);
545 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
549 MUTEX_EXIT(&callp->lock);
553 /*------------------------------------------------------------------------
554 * EXPORTED SRXAFSCB_GetLock
557 * Routine called by the server-side callback RPC interface to
558 * implement pulling out the contents of a lock in the lock
562 * a_call : Ptr to Rx call on which this request came in.
563 * a_index : Index of desired lock.
564 * a_result : Ptr to a buffer for the given lock.
567 * 0 if everything went fine,
568 * 1 if we were given a bad index.
571 * Nothing interesting.
575 *------------------------------------------------------------------------*/
576 /* debug interface */
578 extern osi_rwlock_t cm_aclLock;
579 extern osi_rwlock_t buf_globalLock;
580 extern osi_rwlock_t cm_callbackLock;
581 extern osi_rwlock_t cm_cellLock;
582 extern osi_rwlock_t cm_connLock;
583 extern osi_rwlock_t cm_daemonLock;
584 extern osi_rwlock_t cm_dnlcLock;
585 extern osi_rwlock_t cm_scacheLock;
586 extern osi_rwlock_t cm_serverLock;
587 extern osi_rwlock_t cm_userLock;
588 extern osi_rwlock_t cm_utilsLock;
589 extern osi_rwlock_t cm_volumeLock;
590 extern osi_rwlock_t smb_globalLock;
591 extern osi_rwlock_t smb_rctLock;
593 extern osi_mutex_t cm_Freelance_Lock;
594 extern osi_mutex_t cm_bufGetMutex;
595 extern osi_mutex_t cm_Afsdsbmt_Lock;
596 extern osi_mutex_t tokenEventLock;
597 extern osi_mutex_t smb_ListenerLock;
598 extern osi_mutex_t smb_RawBufLock;
599 extern osi_mutex_t smb_Dir_Watch_Lock;
601 #define LOCKTYPE_RW 1
602 #define LOCKTYPE_MUTEX 2
603 static struct _ltable {
608 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
609 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
610 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
611 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
612 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
613 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
614 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
615 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
616 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
617 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
618 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
619 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
620 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
621 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
622 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
623 {"cm_bufGetMutex", (char*)&cm_bufGetMutex, LOCKTYPE_MUTEX},
624 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
625 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
626 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
627 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
628 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
632 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
634 struct _ltable *tl; /*Ptr to lock table entry */
637 int nentries; /*Num entries in table */
638 int code; /*Return code */
639 struct rx_connection *connp;
640 struct rx_peer *peerp;
641 unsigned long host = 0;
642 unsigned short port = 0;
644 MUTEX_ENTER(&callp->lock);
646 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
647 host = rx_HostOf(peerp);
648 port = rx_PortOf(peerp);
651 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
652 index, ntohl(host), ntohs(port));
654 nentries = sizeof(ltable) / sizeof(struct _ltable);
655 if (index < 0 || index >= nentries) {
662 * Found it - copy out its contents.
665 strncpy(lockp->name, tl->name, sizeof(lockp->name));
666 lockp->name[sizeof(lockp->name)-1] = '\0';
667 lockp->lock.waitStates = 0;
668 switch ( tl->type ) {
670 rwp = (osi_rwlock_t *)tl->addr;
671 lockp->lock.exclLocked = rwp->flags;
672 lockp->lock.readersReading = rwp->readers;
673 lockp->lock.numWaiting = rwp->waiters;
676 mtxp = (osi_mutex_t *)tl->addr;
677 lockp->lock.exclLocked = mtxp->flags;
678 lockp->lock.readersReading = 0;
679 lockp->lock.numWaiting = mtxp->waiters;
682 lockp->lock.pid_last_reader = 0;
683 lockp->lock.pid_writer = 0;
684 lockp->lock.src_indicator = 0;
688 MUTEX_EXIT(&callp->lock);
692 /* debug interface */
694 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
699 struct rx_connection *connp;
700 struct rx_peer *peerp;
701 unsigned long host = 0;
702 unsigned short port = 0;
704 MUTEX_ENTER(&callp->lock);
706 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
707 host = rx_HostOf(peerp);
708 port = rx_PortOf(peerp);
711 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
712 ntohl(host), ntohs(port));
714 lock_ObtainRead(&cm_scacheLock);
715 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
716 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
720 } /*Zip through current hash chain */
721 } /*Zip through hash chains */
731 * Copy out the located entry.
733 memset(cep, 0, sizeof(AFSDBCacheEntry));
734 cep->addr = afs_data_pointer_to_int32(scp);
735 cep->cell = scp->fid.cell;
736 cep->netFid.Volume = scp->fid.volume;
737 cep->netFid.Vnode = scp->fid.vnode;
738 cep->netFid.Unique = scp->fid.unique;
739 cep->lock.waitStates = 0;
740 cep->lock.exclLocked = scp->mx.flags;
741 cep->lock.readersReading = 0;
742 cep->lock.numWaiting = scp->mx.waiters;
743 cep->lock.pid_last_reader = 0;
744 cep->lock.pid_writer = 0;
745 cep->lock.src_indicator = 0;
746 cep->Length = scp->length.LowPart;
747 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
748 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
749 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp)
750 cep->cbExpires = scp->volp->cbExpiresRO;
752 cep->cbExpires = scp->cbExpires;
753 cep->refCount = scp->refCount;
754 cep->opens = scp->openReads;
755 cep->writers = scp->openWrites;
756 switch (scp->fileType) {
757 case CM_SCACHETYPE_FILE:
760 case CM_SCACHETYPE_MOUNTPOINT:
763 case CM_SCACHETYPE_DIRECTORY:
764 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
769 case CM_SCACHETYPE_SYMLINK:
772 case CM_SCACHETYPE_DFSLINK:
775 case CM_SCACHETYPE_INVALID:
780 if (scp->flags & CM_SCACHEFLAG_STATD)
782 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
784 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
785 scp->mountPointStringp[0])
787 if (scp->flags & CM_SCACHEFLAG_WAITING)
792 * Return our results.
795 lock_ReleaseRead(&cm_scacheLock);
797 MUTEX_EXIT(&callp->lock);
801 /* debug interface */
803 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
808 struct rx_connection *connp;
809 struct rx_peer *peerp;
810 unsigned long host = 0;
811 unsigned short port = 0;
813 MUTEX_ENTER(&callp->lock);
815 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
816 host = rx_HostOf(peerp);
817 port = rx_PortOf(peerp);
820 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
821 ntohl(host), ntohs(port));
823 lock_ObtainRead(&cm_scacheLock);
824 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
825 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
829 } /*Zip through current hash chain */
830 } /*Zip through hash chains */
840 * Copy out the located entry.
842 memset(cep, 0, sizeof(AFSDBCacheEntry64));
843 cep->addr = afs_data_pointer_to_int32(scp);
844 cep->cell = scp->fid.cell;
845 cep->netFid.Volume = scp->fid.volume;
846 cep->netFid.Vnode = scp->fid.vnode;
847 cep->netFid.Unique = scp->fid.unique;
848 cep->lock.waitStates = 0;
849 cep->lock.exclLocked = scp->mx.flags;
850 cep->lock.readersReading = 0;
851 cep->lock.numWaiting = scp->mx.waiters;
852 cep->lock.pid_last_reader = 0;
853 cep->lock.pid_writer = 0;
854 cep->lock.src_indicator = 0;
855 #if !defined(AFS_64BIT_ENV)
856 cep->Length.high = scp->length.HighPart;
857 cep->Length.low = scp->length.LowPart;
859 cep->Length = (afs_int64) scp->length.QuadPart;
861 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
862 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
863 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp)
864 cep->cbExpires = scp->volp->cbExpiresRO;
866 cep->cbExpires = scp->cbExpires;
867 cep->refCount = scp->refCount;
868 cep->opens = scp->openReads;
869 cep->writers = scp->openWrites;
870 switch (scp->fileType) {
871 case CM_SCACHETYPE_FILE:
874 case CM_SCACHETYPE_MOUNTPOINT:
877 case CM_SCACHETYPE_DIRECTORY:
878 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
883 case CM_SCACHETYPE_SYMLINK:
886 case CM_SCACHETYPE_DFSLINK:
889 case CM_SCACHETYPE_INVALID:
894 if (scp->flags & CM_SCACHEFLAG_STATD)
896 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
898 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
899 scp->mountPointStringp[0])
901 if (scp->flags & CM_SCACHEFLAG_WAITING)
906 * Return our results.
909 lock_ReleaseRead(&cm_scacheLock);
911 MUTEX_EXIT(&callp->lock);
915 /* debug interface: not implemented */
917 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
919 struct rx_connection *connp;
920 struct rx_peer *peerp;
921 unsigned long host = 0;
922 unsigned short port = 0;
924 MUTEX_ENTER(&callp->lock);
926 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
927 host = rx_HostOf(peerp);
928 port = rx_PortOf(peerp);
931 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
932 ntohl(host), ntohs(port));
935 MUTEX_EXIT(&callp->lock);
939 /* debug interface: not implemented */
941 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
942 AFSCB_CollData *datap)
944 struct rx_connection *connp;
945 struct rx_peer *peerp;
946 unsigned long host = 0;
947 unsigned short port = 0;
949 MUTEX_ENTER(&callp->lock);
951 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
952 host = rx_HostOf(peerp);
953 port = rx_PortOf(peerp);
956 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
957 ntohl(host), ntohs(port));
959 MUTEX_EXIT(&callp->lock);
964 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
966 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
968 return SRXAFSCB_InitCallBackState(callp);
971 /* debug interface */
973 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
976 int cm_noIPAddr; /* number of client network interfaces */
977 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
978 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
979 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
980 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
982 struct rx_connection *connp;
983 struct rx_peer *peerp;
984 unsigned long host = 0;
985 unsigned short port = 0;
987 MUTEX_ENTER(&callp->lock);
989 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
990 host = rx_HostOf(peerp);
991 port = rx_PortOf(peerp);
994 /* get network related info */
995 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
996 code = syscfg_GetIFInfo(&cm_noIPAddr,
997 cm_IPAddr, cm_SubnetMask,
998 cm_NetMtu, cm_NetFlags);
1000 /* return all network interface addresses */
1001 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
1005 addr->numberOfInterfaces = cm_noIPAddr;
1006 addr->uuid = cm_data.Uuid;
1007 for ( i=0; i < cm_noIPAddr; i++ ) {
1008 addr->addr_in[i] = cm_IPAddr[i];
1009 addr->subnetmask[i] = cm_SubnetMask[i];
1010 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1011 cm_NetMtu[i] : rx_mtu;
1014 MUTEX_EXIT(&callp->lock);
1019 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
1023 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
1024 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",p);
1027 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1029 return SRXAFSCB_InitCallBackState(callp);
1032 /* debug interface */
1034 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1036 struct rx_connection *connp;
1037 struct rx_peer *peerp;
1038 unsigned long host = 0;
1039 unsigned short port = 0;
1043 MUTEX_ENTER(&callp->lock);
1045 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1046 host = rx_HostOf(peerp);
1047 port = rx_PortOf(peerp);
1050 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1051 UuidToString((UUID *)&cm_data.Uuid, &p);
1052 UuidToString((UUID *)clientUuid, &q);
1053 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1054 osi_LogSaveString(afsd_logp,p),
1055 osi_LogSaveString(afsd_logp,q),
1061 code = 1; /* failure */
1063 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1067 MUTEX_EXIT(&callp->lock);
1071 /* debug interface */
1073 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1074 char **a_name, serverList *a_hosts)
1078 cm_serverRef_t * serverRefp;
1079 struct rx_connection *connp;
1080 struct rx_peer *peerp;
1081 unsigned long host = 0;
1082 unsigned short port = 0;
1084 MUTEX_ENTER(&callp->lock);
1086 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1087 host = rx_HostOf(peerp);
1088 port = rx_PortOf(peerp);
1091 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1092 a_cellnum, ntohl(host), ntohs(port));
1094 a_hosts->serverList_val = 0;
1095 a_hosts->serverList_len = 0;
1097 cellp = cm_FindCellByID(a_cellnum);
1099 *a_name = strdup("");
1100 MUTEX_EXIT(&callp->lock);
1104 lock_ObtainRead(&cm_serverLock);
1105 *a_name = strdup(cellp->name);
1107 for ( sn = 0, serverRefp = cellp->vlServersp;
1108 sn < AFSMAXCELLHOSTS && serverRefp;
1109 sn++, serverRefp = serverRefp->next);
1111 a_hosts->serverList_len = sn;
1112 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1114 for ( sn = 0, serverRefp = cellp->vlServersp;
1115 sn < AFSMAXCELLHOSTS && serverRefp;
1116 sn++, serverRefp = serverRefp->next)
1118 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1121 lock_ReleaseRead(&cm_serverLock);
1122 MUTEX_EXIT(&callp->lock);
1126 /* debug interface */
1128 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1129 struct interfaceAddr *addr,
1130 Capabilities * capabilities)
1133 afs_int32 *dataBuffP;
1134 afs_int32 dataBytes;
1135 int cm_noIPAddr; /* number of client network interfaces */
1136 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
1137 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
1138 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
1139 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
1141 struct rx_connection *connp;
1142 struct rx_peer *peerp;
1143 unsigned long host = 0;
1144 unsigned short port = 0;
1146 MUTEX_ENTER(&callp->lock);
1148 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1149 host = rx_HostOf(peerp);
1150 port = rx_PortOf(peerp);
1153 /* get network related info */
1154 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1155 code = syscfg_GetIFInfo(&cm_noIPAddr,
1156 cm_IPAddr, cm_SubnetMask,
1157 cm_NetMtu, cm_NetFlags);
1159 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1163 /* return all network interface addresses */
1164 addr->numberOfInterfaces = cm_noIPAddr;
1165 addr->uuid = cm_data.Uuid;
1166 for ( i=0; i < cm_noIPAddr; i++ ) {
1167 addr->addr_in[i] = cm_IPAddr[i];
1168 addr->subnetmask[i] = cm_SubnetMask[i];
1169 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1170 cm_NetMtu[i] : rx_mtu;
1173 dataBytes = 1 * sizeof(afs_int32);
1174 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1175 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1176 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1177 capabilities->Capabilities_val = dataBuffP;
1179 MUTEX_EXIT(&callp->lock);
1183 /*------------------------------------------------------------------------
1184 * EXPORTED SRXAFSCB_GetServerPrefs
1187 * Routine to list server preferences used by this client.
1190 * a_call : Ptr to Rx call on which this request came in.
1191 * a_index : Input server index
1192 * a_srvr_addr : Output server address (0xffffffff on last server)
1193 * a_srvr_rank : Output server rank
1199 * Nothing interesting.
1203 *------------------------------------------------------------------------*/
1205 int SRXAFSCB_GetServerPrefs(
1206 struct rx_call *callp,
1208 afs_int32 *a_srvr_addr,
1209 afs_int32 *a_srvr_rank)
1211 struct rx_connection *connp;
1212 struct rx_peer *peerp;
1213 unsigned long host = 0;
1214 unsigned short port = 0;
1216 MUTEX_ENTER(&callp->lock);
1218 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1219 host = rx_HostOf(peerp);
1220 port = rx_PortOf(peerp);
1223 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1227 *a_srvr_addr = 0xffffffff;
1228 *a_srvr_rank = 0xffffffff;
1230 MUTEX_EXIT(&callp->lock);
1234 /*------------------------------------------------------------------------
1235 * EXPORTED SRXAFSCB_GetCellServDB
1238 * Routine to list cells configured for this client
1241 * a_call : Ptr to Rx call on which this request came in.
1242 * a_index : Input cell index
1243 * a_name : Output cell name ("" on last cell)
1244 * a_hosts : Output cell database servers
1250 * Nothing interesting.
1254 *------------------------------------------------------------------------*/
1256 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1257 serverList *a_hosts)
1260 struct rx_connection *connp;
1261 struct rx_peer *peerp;
1262 unsigned long host = 0;
1263 unsigned short port = 0;
1265 MUTEX_ENTER(&callp->lock);
1267 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1268 host = rx_HostOf(peerp);
1269 port = rx_PortOf(peerp);
1272 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1273 ntohl(host), ntohs(port));
1275 t_name = (char *)malloc(AFSNAMEMAX);
1278 a_hosts->serverList_len = 0;
1280 MUTEX_EXIT(&callp->lock);
1284 /*------------------------------------------------------------------------
1285 * EXPORTED SRXAFSCB_GetLocalCell
1288 * Routine to return name of client's local cell
1291 * a_call : Ptr to Rx call on which this request came in.
1292 * a_name : Output cell name
1298 * Nothing interesting.
1302 *------------------------------------------------------------------------*/
1304 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1307 struct rx_connection *connp;
1308 struct rx_peer *peerp;
1309 unsigned long host = 0;
1310 unsigned short port = 0;
1312 MUTEX_ENTER(&callp->lock);
1314 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1315 host = rx_HostOf(peerp);
1316 port = rx_PortOf(peerp);
1319 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1320 ntohl(host), ntohs(port));
1322 if (cm_data.rootCellp) {
1323 t_name = (char *)malloc(strlen(cm_data.rootCellp->name)+1);
1324 strcpy(t_name, cm_data.rootCellp->name);
1326 t_name = (char *)malloc(1);
1331 MUTEX_EXIT(&callp->lock);
1337 * afs_MarshallCacheConfig - marshall client cache configuration
1341 * IN callerVersion - the rpc stat version of the caller.
1343 * IN config - client cache configuration.
1345 * OUT ptr - buffer where configuration is marshalled.
1351 static void afs_MarshallCacheConfig(
1352 afs_uint32 callerVersion,
1353 cm_initparams_v1 *config,
1357 * We currently only support version 1.
1359 *(ptr++) = config->nChunkFiles;
1360 *(ptr++) = config->nStatCaches;
1361 *(ptr++) = config->nDataCaches;
1362 *(ptr++) = config->nVolumeCaches;
1363 *(ptr++) = config->firstChunkSize;
1364 *(ptr++) = config->otherChunkSize;
1365 *(ptr++) = config->cacheSize;
1366 *(ptr++) = config->setTime;
1367 *(ptr++) = config->memCache;
1372 /*------------------------------------------------------------------------
1373 * EXPORTED SRXAFSCB_GetCacheConfig
1376 * Routine to return parameters used to initialize client cache.
1377 * Client may request any format version. Server may not return
1378 * format version greater than version requested by client.
1381 * a_call: Ptr to Rx call on which this request came in.
1382 * callerVersion: Data format version desired by the client.
1383 * serverVersion: Data format version of output data.
1384 * configCount: Number bytes allocated for output data.
1385 * config: Client cache configuration.
1391 * Nothing interesting.
1395 *------------------------------------------------------------------------*/
1397 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1398 afs_uint32 callerVersion,
1399 afs_uint32 *serverVersion,
1400 afs_uint32 *configCount,
1401 cacheConfig *config)
1403 afs_uint32 *t_config;
1405 extern cm_initparams_v1 cm_initParams;
1406 struct rx_connection *connp;
1407 struct rx_peer *peerp;
1408 unsigned long host = 0;
1409 unsigned short port = 0;
1411 MUTEX_ENTER(&callp->lock);
1413 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1414 host = rx_HostOf(peerp);
1415 port = rx_PortOf(peerp);
1418 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1419 ntohl(host), ntohs(port));
1422 * Currently only support version 1
1424 allocsize = sizeof(cm_initparams_v1);
1425 t_config = (afs_uint32 *)malloc(allocsize);
1427 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1429 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1432 #define SIZE_MAX UINT_MAX
1434 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1436 *configCount = (afs_uint32)allocsize;
1437 config->cacheConfig_val = t_config;
1438 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1440 MUTEX_EXIT(&callp->lock);
1444 /* called by afsd without any locks to initialize this module */
1445 void cm_InitCallback(void)
1447 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
1448 cm_activeCallbackGrantingCalls = 0;
1451 /* called with locked scp; tells us whether we've got a callback.
1452 * Expirations are checked by a background daemon so as to make
1453 * this function as inexpensive as possible
1455 int cm_HaveCallback(cm_scache_t *scp)
1457 #ifdef AFS_FREELANCE_CLIENT
1458 // yj: we handle callbacks specially for callbacks on the root directory
1459 // Since it's local, we almost always say that we have callback on it
1460 // The only time we send back a 0 is if we're need to initialize or
1461 // reinitialize the fake directory
1463 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1464 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1465 // hence should return false. it's 0 otherwise
1466 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1467 // if the fake directory is loaded and this is the first time cm_HaveCallback
1468 // is called since then. We return false in this case to allow cm_GetCallback
1469 // to be called because cm_GetCallback has some initialization work to do.
1470 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1471 // good shape and we simply return true, provided no change is detected.
1474 if (cm_freelanceEnabled &&
1475 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1476 /* if it's something on /afs */
1477 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
1478 /* if it's not root.afs */
1482 lock_ObtainMutex(&cm_Freelance_Lock);
1483 fdc = cm_fakeDirCallback;
1484 fgc = cm_fakeGettingCallback;
1485 lock_ReleaseMutex(&cm_Freelance_Lock);
1487 if (fdc==1) { // first call since init
1489 } else if (fdc==2 && !fgc) { // we're in good shape
1490 if (cm_getLocalMountPointChange()) { // check for changes
1491 cm_clearLocalMountPointChange(); // clear the changefile
1492 lock_ReleaseMutex(&scp->mx); // this is re-locked in reInitLocalMountPoints
1493 cm_reInitLocalMountPoints(); // start reinit
1494 lock_ObtainMutex(&scp->mx); // now get the lock back
1497 return 1; // no change
1503 if (scp->cbServerp != NULL) {
1505 } else if (cm_OfflineROIsValid) {
1506 switch (cm_GetVolumeStatus(scp->volp, scp->fid.volume)) {
1519 /* need to detect a broken callback that races with our obtaining a callback.
1520 * Need to be able to do this even if we don't know the file ID of the file
1521 * we're breaking the callback on at the time we start the acquisition of the
1522 * callback (as in the case where we are creating a file).
1524 * So, we start by writing down the count of the # of callbacks we've received
1525 * so far, and bumping a global counter of the # of callback granting calls
1526 * outstanding (all done under cm_callbackLock).
1528 * When we're back from the call, we look at all of the callback revokes with
1529 * counter numbers greater than the one we recorded in our caller's structure,
1530 * and replay those that are higher than when we started the call.
1532 * We free all the structures in the queue when the count of the # of outstanding
1533 * callback-granting calls drops to zero.
1535 * We call this function with the scp locked, too, but in its current implementation,
1536 * this knowledge is not used.
1538 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1540 lock_ObtainWrite(&cm_callbackLock);
1541 cbrp->callbackCount = cm_callbackCount;
1542 cm_activeCallbackGrantingCalls++;
1543 cbrp->startTime = time(NULL);
1544 cbrp->serverp = NULL;
1545 lock_ReleaseWrite(&cm_callbackLock);
1548 /* Called at the end of a callback-granting call, to remove the callback
1549 * info from the scache entry, if necessary.
1551 * Called with scp locked, so we can discard the callbacks easily with
1552 * this locking hierarchy.
1554 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1555 AFSCallBack *cbp, long flags)
1557 cm_racingRevokes_t *revp; /* where we are */
1558 cm_racingRevokes_t *nrevp; /* where we'll be next */
1560 cm_server_t * serverp = NULL;
1561 int discardScp = 0, discardVolCB = 0;
1563 lock_ObtainWrite(&cm_callbackLock);
1564 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1565 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1566 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1569 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1570 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1572 if (cm_activeCallbackGrantingCalls == 0)
1577 /* record the callback; we'll clear it below if we really lose it */
1580 if (scp->cbServerp != cbrp->serverp) {
1581 serverp = scp->cbServerp;
1583 cm_GetServer(cbrp->serverp);
1584 scp->cbServerp = cbrp->serverp;
1587 serverp = cbrp->serverp;
1589 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1590 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp)
1591 scp->volp->cbExpiresRO = scp->cbExpires;
1594 serverp = cbrp->serverp;
1597 cbrp->serverp = NULL;
1600 /* a callback was actually revoked during our granting call, so
1601 * run down the list of revoked fids, looking for ours.
1602 * If activeCallbackGrantingCalls is zero, free the elements, too.
1604 * May need to go through entire list just to do the freeing.
1606 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1607 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1608 /* if this callback came in later than when we started the
1609 * callback-granting call, and if this fid is the right fid,
1610 * then clear the callback.
1612 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1613 && revp->callbackCount > cbrp->callbackCount
1614 && (( scp->fid.volume == revp->fid.volume &&
1615 scp->fid.vnode == revp->fid.vnode &&
1616 scp->fid.unique == revp->fid.unique)
1618 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1619 scp->fid.volume == revp->fid.volume)
1621 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1622 /* this one matches */
1624 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1626 cbrp->callbackCount, revp->callbackCount,
1630 if ((scp->flags & CM_SCACHEFLAG_PURERO) && scp->volp &&
1631 (revp->flags & (CM_RACINGFLAG_CANCELVOL | CM_RACINGFLAG_CANCELALL)))
1632 scp->volp->cbExpiresRO = 0;
1638 /* if we freed the list, zap the pointer to it */
1640 cm_racingRevokesp = NULL;
1642 lock_ReleaseWrite(&cm_callbackLock);
1645 cm_DiscardSCache(scp);
1646 lock_ReleaseMutex(&scp->mx);
1647 cm_CallbackNotifyChange(scp);
1648 lock_ObtainMutex(&scp->mx);
1652 lock_ObtainWrite(&cm_serverLock);
1653 cm_FreeServer(serverp);
1654 lock_ReleaseWrite(&cm_serverLock);
1658 /* if flags is 1, we want to force the code to make one call, anyway.
1659 * called with locked scp; returns with same.
1661 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1662 struct cm_req *reqp, long flags)
1665 cm_conn_t *connp = NULL;
1666 AFSFetchStatus afsStatus;
1668 AFSCallBack callback;
1670 cm_callbackRequest_t cbr;
1673 struct rx_connection * callp = NULL;
1674 int syncop_done = 0;
1676 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1677 scp, scp->fid.cell, scp->fid.volume, flags);
1679 #ifdef AFS_FREELANCE_CLIENT
1680 // The case where a callback is needed on /afs is handled
1681 // specially. We need to fetch the status by calling
1682 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1683 if (cm_freelanceEnabled) {
1684 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1685 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1686 scp->fid.unique==0x1 &&
1687 scp->fid.vnode==0x1) {
1689 // Start by indicating that we're in the process
1690 // of fetching the callback
1691 lock_ObtainMutex(&cm_Freelance_Lock);
1692 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1693 cm_fakeGettingCallback = 1;
1694 lock_ReleaseMutex(&cm_Freelance_Lock);
1696 // Fetch the status info
1697 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1699 // Indicate that the callback is not done
1700 lock_ObtainMutex(&cm_Freelance_Lock);
1701 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1702 cm_fakeDirCallback = 2;
1704 // Indicate that we're no longer fetching the callback
1705 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1706 cm_fakeGettingCallback = 0;
1707 lock_ReleaseMutex(&cm_Freelance_Lock);
1712 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1713 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1716 #endif /* AFS_FREELANCE_CLIENT */
1718 mustCall = (flags & 1);
1719 cm_AFSFidFromFid(&tfid, &scp->fid);
1721 if (!mustCall && cm_HaveCallback(scp))
1724 /* turn off mustCall, since it has now forced us past the check above */
1727 /* otherwise, we have to make an RPC to get the status */
1729 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1730 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1735 cm_StartCallbackGrantingCall(scp, &cbr);
1737 lock_ReleaseMutex(&scp->mx);
1739 /* now make the RPC */
1740 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1741 scp, sfid.volume, sfid.vnode, sfid.unique);
1743 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1747 callp = cm_GetRxConn(connp);
1748 code = RXAFS_FetchStatus(callp, &tfid,
1749 &afsStatus, &callback, &volSync);
1750 rx_PutConnection(callp);
1752 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1754 code = cm_MapRPCError(code, reqp);
1756 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1757 code, scp, scp->fid.volume, scp->fid.vnode);
1759 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1760 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1762 lock_ObtainMutex(&scp->mx);
1764 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1765 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1767 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1770 /* if we got an error, return to caller */
1776 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1779 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1780 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1781 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1783 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1784 scp, scp->fid.cell, scp->fid.volume);
1791 /* called with cm_scacheLock held */
1792 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1794 cm_vol_state_t *statep;
1795 cm_volume_t * volp = scp->volp;
1796 afs_uint32 volID = scp->fid.volume;
1797 cm_serverRef_t *tsrp;
1802 if (scp->cbServerp == NULL)
1805 if (volp->rw.ID == volID) {
1807 } else if (volp->ro.ID == volID) {
1809 } else if (volp->bk.ID == volID) {
1813 if (statep->state == vl_online)
1816 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1817 if (tsrp->server == scp->cbServerp)
1819 if (tsrp->server->downTime > *downTime)
1820 *downTime = tsrp->server->downTime;
1823 /* if the cbServerp does not match the current volume server list
1824 * we report the callback server as up so the callback can be
1827 return(found ? 0 : 1);
1830 /* called periodically by cm_daemon to shut down use of expired callbacks */
1831 void cm_CheckCBExpiration(void)
1835 time_t now, downTime;
1837 osi_Log0(afsd_logp, "CheckCBExpiration");
1840 lock_ObtainWrite(&cm_scacheLock);
1841 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1842 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1844 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp) {
1845 if (scp->volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1846 scp->cbExpires = scp->volp->cbExpiresRO;
1849 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1850 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1852 cm_HoldSCacheNoLock(scp);
1853 lock_ReleaseWrite(&cm_scacheLock);
1855 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1856 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1857 lock_ObtainMutex(&scp->mx);
1858 cm_DiscardSCache(scp);
1859 lock_ReleaseMutex(&scp->mx);
1860 cm_CallbackNotifyChange(scp);
1862 cm_ReleaseSCacheNoLock(scp);
1863 lock_ObtainWrite(&cm_scacheLock);
1867 lock_ReleaseWrite(&cm_scacheLock);
1869 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1874 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1878 struct rx_connection * rxconnp;
1880 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1882 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1884 rxconnp = cm_GetRxConn(connp);
1885 rx_SetConnDeadTime(rxconnp, 10);
1886 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1887 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1888 rx_PutConnection(rxconnp);
1892 cm_server_vols_t * tsrvp;
1896 lock_ObtainMutex(&tsp->mx);
1897 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1898 tsp->flags |= CM_SERVERFLAG_DOWN;
1899 tsp->downTime = osi_Time();
1901 cm_ForceNewConnections(tsp);
1902 lock_ReleaseMutex(&tsp->mx);
1904 /* Now update the volume status */
1905 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
1906 for (i=0; i<NUM_SERVER_VOLS; i++) {
1907 if (tsrvp->ids[i] != 0) {
1912 code = cm_GetVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
1913 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE, &volp);
1915 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
1926 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
1930 lock_ObtainWrite(&cm_serverLock);
1931 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
1932 cm_GetServerNoLock(tsp);
1933 lock_ReleaseWrite(&cm_serverLock);
1934 cm_GiveUpAllCallbacks(tsp, markDown);
1935 lock_ObtainWrite(&cm_serverLock);
1936 cm_PutServerNoLock(tsp);
1938 lock_ReleaseWrite(&cm_serverLock);