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>
18 #include <sys/socket.h>
26 #include <rx_pthread.h>
28 #include <WINNT/syscfg.h>
29 #include <WINNT/afsreg.h>
30 #include <../afsrdr/kif.h>
32 /*extern void afsi_log(char *pattern, ...);*/
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 = 0;
41 #ifdef AFS_FREELANCE_CLIENT
42 extern osi_mutex_t cm_Freelance_Lock;
45 /* count of # of callback breaking messages received by this CM so far. We use
46 * this count in determining whether there have been any callback breaks that
47 * apply to a call that returned a new callback. If the counter doesn't
48 * increase during a call, then we know that no callbacks were broken during
49 * that call, and thus that the callback that was just returned is still valid.
51 long cm_callbackCount;
53 /* count of number of RPCs potentially returning a callback executing now.
54 * When this counter hits zero, we can clear out the racing revokes list, since
55 * at that time, we know that none of the just-executed callback revokes will
56 * apply to any future call that returns a callback (since the latter hasn't
57 * even started execution yet).
59 long cm_activeCallbackGrantingCalls;
61 /* list of callbacks that have been broken recently. If a call returning a
62 * callback is executing and a callback revoke runs immediately after it at the
63 * server, the revoke may end up being processed before the response to the
64 * original callback granting call. We detect this by keeping a list of
65 * callback revokes that have been received since we *started* the callback
66 * granting call, and discarding any callbacks received for the same file ID,
67 * even if the callback revoke was received before the callback grant.
69 cm_racingRevokes_t *cm_racingRevokesp;
71 /* record a (potentially) racing revoke for this file ID; null means for all
72 * file IDs, and is used by InitCallBackState.
74 * The cancelFlags describe whether we're just discarding callbacks for the same
75 * file ID, the same volume, or all from the same server.
77 * Called with no locks held.
79 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
81 cm_racingRevokes_t *rp;
83 lock_ObtainWrite(&cm_callbackLock);
85 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
86 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
88 if (cm_activeCallbackGrantingCalls > 0) {
89 rp = malloc(sizeof(*rp));
90 memset(rp, 0, sizeof(*rp));
91 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
92 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
93 if (fidp) rp->fid = *fidp;
94 rp->callbackCount = ++cm_callbackCount;
96 lock_ReleaseWrite(&cm_callbackLock);
100 * When we lose a callback, may have to send change notification replies.
101 * Do not call with a lock on the scp.
103 void cm_CallbackNotifyChange(cm_scache_t *scp)
109 /* why does this have to query the registry each time? */
110 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
111 AFSREG_CLT_OPENAFS_SUBKEY,
113 KEY_READ|KEY_QUERY_VALUE,
114 &hKey) == ERROR_SUCCESS) {
116 dummyLen = sizeof(DWORD);
117 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
118 (BYTE *) &dwDelay, &dummyLen);
122 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
125 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
126 scp->fileType, scp->flags, dwDelay);
131 /* for directories, this sends a change notification on the dir itself */
132 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
134 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
136 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
137 scp, NULL, NULL, TRUE);
139 dc_break_callback(FID_HASH_FN(&scp->fid));
142 /* and for files, this sends a change notification on the file's parent dir */
146 tfid.cell = scp->fid.cell;
147 tfid.volume = scp->fid.volume;
148 tfid.vnode = scp->parentVnode;
149 tfid.unique = scp->parentUnique;
150 dscp = cm_FindSCache(&tfid);
153 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
155 FILE_NOTIFY_GENERIC_FILE_FILTER,
156 dscp, NULL, NULL, TRUE);
159 dc_break_callback(FID_HASH_FN(&dscp->fid));
162 cm_ReleaseSCache(dscp);
166 /* called with no locks held for every file ID that is revoked directly by
167 * a callback revoke call. Does not have to handle volume callback breaks,
168 * since those have already been split out.
170 * The callp parameter is currently unused.
172 void cm_RevokeCallback(struct rx_call *callp, cm_cell_t * cellp, AFSFid *fidp)
178 /* don't bother setting cell, since we won't be checking it (to aid
179 * in working with multi-homed servers: we don't know the cell if we
180 * don't recognize the IP address).
183 tfid.volume = fidp->Volume;
184 tfid.vnode = fidp->Vnode;
185 tfid.unique = fidp->Unique;
186 hash = CM_SCACHE_HASH(&tfid);
188 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
189 fidp->Volume, fidp->Vnode, fidp->Unique);
191 /* do this first, so that if we're executing a callback granting call
192 * at this moment, we kill it before it can be merged in. Otherwise,
193 * it could complete while we're doing the scan below, and get missed
194 * by both the scan and by this code.
196 cm_RecordRacingRevoke(&tfid, 0);
198 lock_ObtainWrite(&cm_scacheLock);
199 /* do all in the hash bucket, since we don't know how many we'll find with
202 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
203 if (scp->fid.volume == tfid.volume &&
204 scp->fid.vnode == tfid.vnode &&
205 scp->fid.unique == tfid.unique &&
206 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
207 scp->cbExpires > 0 &&
208 scp->cbServerp != NULL)
210 cm_HoldSCacheNoLock(scp);
211 lock_ReleaseWrite(&cm_scacheLock);
212 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
213 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
215 lock_ObtainMutex(&scp->mx);
216 cm_DiscardSCache(scp);
217 lock_ReleaseMutex(&scp->mx);
219 cm_CallbackNotifyChange(scp);
221 lock_ObtainWrite(&cm_scacheLock);
222 cm_ReleaseSCacheNoLock(scp);
225 lock_ReleaseWrite(&cm_scacheLock);
227 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
228 fidp->Volume, fidp->Vnode, fidp->Unique);
231 /* called to revoke a volume callback, which is typically issued when a volume
232 * is moved from one server to another.
234 * Called with no locks held.
236 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
242 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
244 /* do this first, so that if we're executing a callback granting call
245 * at this moment, we kill it before it can be merged in. Otherwise,
246 * it could complete while we're doing the scan below, and get missed
247 * by both the scan and by this code.
249 tfid.cell = tfid.vnode = tfid.unique = 0;
250 tfid.volume = fidp->Volume;
251 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
253 lock_ObtainWrite(&cm_scacheLock);
254 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
255 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
256 if (scp->fid.volume == fidp->Volume &&
257 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
258 scp->cbExpires > 0 &&
259 scp->cbServerp != NULL) {
260 cm_HoldSCacheNoLock(scp);
261 lock_ReleaseWrite(&cm_scacheLock);
263 lock_ObtainMutex(&scp->mx);
264 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
265 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
266 cm_DiscardSCache(scp);
267 lock_ReleaseMutex(&scp->mx);
269 cm_CallbackNotifyChange(scp);
270 lock_ObtainWrite(&cm_scacheLock);
271 cm_ReleaseSCacheNoLock(scp);
273 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp) {
274 scp->volp->cbExpiresRO = 0;
278 } /* search one hash bucket */
279 } /* search all hash buckets */
281 lock_ReleaseWrite(&cm_scacheLock);
283 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
287 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
288 * given data pointer, without triggering "cast truncates pointer"
289 * warnings. We use this where we explicitly don't care whether a
290 * pointer is truncated -- it loses information where a pointer is
291 * larger than an afs_int32.
295 afs_data_pointer_to_int32(const void *p)
298 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
302 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
307 /* used to determine the byte order of the system */
310 char c[sizeof(int) / sizeof(char)];
316 /* little-endian system */
319 /* big-endian system */
320 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
325 return ip.i32[i32_sub];
327 /*------------------------------------------------------------------------
328 * EXPORTED SRXAFSCB_CallBack
331 * Routine called by the server-side callback RPC interface to
332 * implement passing in callback information.
336 * rx_call : Ptr to Rx call on which this request came in.
337 * fidsArrayp : Ptr to array of fids involved.
338 * cbsArrayp : Ptr to matching callback info for the fids.
344 * Nothing interesting.
348 *------------------------------------------------------------------------*/
349 /* handle incoming RPC callback breaking message.
350 * Called with no locks held.
353 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
357 struct rx_connection *connp;
358 struct rx_peer *peerp;
359 unsigned long host = 0;
360 unsigned short port = 0;
361 cm_server_t *tsp = NULL;
362 cm_cell_t* cellp = NULL;
364 #ifdef HOLD_CALL_MUTEX
365 MUTEX_ENTER(&callp->lock);
367 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
368 host = rx_HostOf(peerp);
369 port = rx_PortOf(peerp);
371 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
376 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
380 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
383 cellp->name /* does not need to be saved, doesn't change */);
385 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
389 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
390 tfidp = &fidsArrayp->AFSCBFids_val[i];
392 if (tfidp->Volume == 0)
393 continue; /* means don't do anything */
394 else if (tfidp->Vnode == 0)
395 cm_RevokeVolumeCallback(callp, cellp, tfidp);
397 cm_RevokeCallback(callp, cellp, tfidp);
399 #ifdef HOLD_CALL_MUTEX
400 MUTEX_EXIT(&callp->lock);
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)
431 struct sockaddr_in taddr;
436 struct rx_connection *connp;
437 struct rx_peer *peerp;
438 unsigned long host = 0;
439 unsigned short port = 0;
441 #ifdef HOLD_CALL_MUTEX
442 MUTEX_ENTER(&callp->lock);
444 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
445 host = rx_HostOf(peerp);
446 port = rx_PortOf(peerp);
449 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState from host 0x%x port %d",
453 if ((rx_ConnectionOf(callp)) && (rx_PeerOf(rx_ConnectionOf(callp)))) {
454 taddr.sin_family = AF_INET;
455 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
457 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
459 osi_Log1(afsd_logp, "Init Callback State server %x", tsp);
461 /* record the callback in the racing revokes structure. This
462 * shouldn't be necessary, since we shouldn't be making callback
463 * granting calls while we're going to get an initstate call,
464 * but there probably are some obscure races, so better safe
467 * We do this first since we don't hold the cm_scacheLock and vnode
468 * locks over the entire callback scan operation below. The
469 * big loop below is guaranteed to hit any callback already
470 * processed. The call to RecordRacingRevoke is guaranteed
471 * to kill any callback that is currently being returned.
472 * Anything that sneaks past both must start
473 * after the call to RecordRacingRevoke.
475 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
477 /* now search all vnodes looking for guys with this callback, if we
478 * found it, or guys with any callbacks, if we didn't find the server
479 * (that's how multihomed machines will appear and how we'll handle
480 * them, albeit a little inefficiently). That is, we're discarding all
481 * callbacks from all hosts if we get an initstate call from an unknown
482 * host. Since these calls are rare, and multihomed servers
483 * are "rare," hopefully this won't be a problem.
485 lock_ObtainWrite(&cm_scacheLock);
486 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
487 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
488 cm_HoldSCacheNoLock(scp);
489 lock_ReleaseWrite(&cm_scacheLock);
490 lock_ObtainMutex(&scp->mx);
492 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
493 /* we have a callback, now decide if we should clear it */
494 if (scp->cbServerp == tsp || tsp == NULL) {
495 osi_Log4(afsd_logp, "InitCallbackState Discarding SCache scp 0x%p vol %u vn %u uniq %u",
496 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
497 cm_DiscardSCache(scp);
501 lock_ReleaseMutex(&scp->mx);
503 cm_CallbackNotifyChange(scp);
504 lock_ObtainWrite(&cm_scacheLock);
505 cm_ReleaseSCacheNoLock(scp);
507 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO) && scp->volp && scp->volp->cbExpiresRO != 0)
508 scp->volp->cbExpiresRO = 0;
510 } /* search one hash bucket */
511 } /* search all hash buckets */
513 lock_ReleaseWrite(&cm_scacheLock);
516 /* reset the No flags on the server */
517 cm_SetServerNo64Bit(tsp, 0);
518 cm_SetServerNoInlineBulk(tsp, 0);
520 /* we're done with the server structure */
524 #ifdef HOLD_CALL_MUTEX
525 MUTEX_EXIT(&callp->lock);
530 /*------------------------------------------------------------------------
531 * EXPORTED SRXAFSCB_Probe
534 * Routine called by the server-side callback RPC interface to
535 * implement ``probing'' the Cache Manager, just making sure it's
539 * rx_call : Ptr to Rx call on which this request came in.
545 * Nothing interesting.
549 *------------------------------------------------------------------------*/
551 SRXAFSCB_Probe(struct rx_call *callp)
553 struct rx_connection *connp;
554 struct rx_peer *peerp;
555 unsigned long host = 0;
556 unsigned short port = 0;
558 #ifdef HOLD_CALL_MUTEX
559 MUTEX_ENTER(&callp->lock);
561 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
562 host = rx_HostOf(peerp);
563 port = rx_PortOf(peerp);
566 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
570 #ifdef HOLD_CALL_MUTEX
571 MUTEX_EXIT(&callp->lock);
576 /*------------------------------------------------------------------------
577 * EXPORTED SRXAFSCB_GetLock
580 * Routine called by the server-side callback RPC interface to
581 * implement pulling out the contents of a lock in the lock
585 * a_call : Ptr to Rx call on which this request came in.
586 * a_index : Index of desired lock.
587 * a_result : Ptr to a buffer for the given lock.
590 * 0 if everything went fine,
591 * 1 if we were given a bad index.
594 * Nothing interesting.
598 *------------------------------------------------------------------------*/
599 /* debug interface */
601 extern osi_rwlock_t cm_aclLock;
602 extern osi_rwlock_t buf_globalLock;
603 extern osi_rwlock_t cm_callbackLock;
604 extern osi_rwlock_t cm_cellLock;
605 extern osi_rwlock_t cm_connLock;
606 extern osi_rwlock_t cm_daemonLock;
607 extern osi_rwlock_t cm_dnlcLock;
608 extern osi_rwlock_t cm_scacheLock;
609 extern osi_rwlock_t cm_serverLock;
610 extern osi_rwlock_t cm_userLock;
611 extern osi_rwlock_t cm_utilsLock;
612 extern osi_rwlock_t cm_volumeLock;
613 extern osi_rwlock_t smb_globalLock;
614 extern osi_rwlock_t smb_rctLock;
616 extern osi_mutex_t cm_Freelance_Lock;
617 extern osi_mutex_t cm_bufGetMutex;
618 extern osi_mutex_t cm_Afsdsbmt_Lock;
619 extern osi_mutex_t tokenEventLock;
620 extern osi_mutex_t smb_ListenerLock;
621 extern osi_mutex_t smb_RawBufLock;
622 extern osi_mutex_t smb_Dir_Watch_Lock;
624 #define LOCKTYPE_RW 1
625 #define LOCKTYPE_MUTEX 2
626 static struct _ltable {
631 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
632 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
633 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
634 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
635 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
636 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
637 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
638 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
639 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
640 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
641 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
642 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
643 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
644 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
645 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
646 {"cm_bufGetMutex", (char*)&cm_bufGetMutex, LOCKTYPE_MUTEX},
647 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
648 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
649 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
650 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
651 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
655 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
657 struct _ltable *tl; /*Ptr to lock table entry */
660 int nentries; /*Num entries in table */
661 int code; /*Return code */
662 struct rx_connection *connp;
663 struct rx_peer *peerp;
664 unsigned long host = 0;
665 unsigned short port = 0;
667 #ifdef HOLD_CALL_MUTEX
668 MUTEX_ENTER(&callp->lock);
670 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
671 host = rx_HostOf(peerp);
672 port = rx_PortOf(peerp);
675 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
676 index, ntohl(host), ntohs(port));
678 nentries = sizeof(ltable) / sizeof(struct _ltable);
679 if (index < 0 || index >= nentries) {
686 * Found it - copy out its contents.
689 strncpy(lockp->name, tl->name, sizeof(lockp->name));
690 lockp->name[sizeof(lockp->name)-1] = '\0';
691 lockp->lock.waitStates = 0;
692 switch ( tl->type ) {
694 rwp = (osi_rwlock_t *)tl->addr;
695 lockp->lock.exclLocked = rwp->flags;
696 lockp->lock.readersReading = rwp->readers;
697 lockp->lock.numWaiting = rwp->waiters;
700 mtxp = (osi_mutex_t *)tl->addr;
701 lockp->lock.exclLocked = mtxp->flags;
702 lockp->lock.readersReading = 0;
703 lockp->lock.numWaiting = mtxp->waiters;
706 lockp->lock.pid_last_reader = 0;
707 lockp->lock.pid_writer = 0;
708 lockp->lock.src_indicator = 0;
712 #ifdef HOLD_CALL_MUTEX
713 MUTEX_EXIT(&callp->lock);
718 /* debug interface */
720 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
725 struct rx_connection *connp;
726 struct rx_peer *peerp;
727 unsigned long host = 0;
728 unsigned short port = 0;
730 #ifdef HOLD_CALL_MUTEX
731 MUTEX_ENTER(&callp->lock);
733 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
734 host = rx_HostOf(peerp);
735 port = rx_PortOf(peerp);
738 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
739 ntohl(host), ntohs(port));
741 lock_ObtainRead(&cm_scacheLock);
742 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
743 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
747 } /*Zip through current hash chain */
748 } /*Zip through hash chains */
758 * Copy out the located entry.
760 memset(cep, 0, sizeof(AFSDBCacheEntry));
761 cep->addr = afs_data_pointer_to_int32(scp);
762 cep->cell = scp->fid.cell;
763 cep->netFid.Volume = scp->fid.volume;
764 cep->netFid.Vnode = scp->fid.vnode;
765 cep->netFid.Unique = scp->fid.unique;
766 cep->lock.waitStates = 0;
767 cep->lock.exclLocked = scp->mx.flags;
768 cep->lock.readersReading = 0;
769 cep->lock.numWaiting = scp->mx.waiters;
770 cep->lock.pid_last_reader = 0;
771 cep->lock.pid_writer = 0;
772 cep->lock.src_indicator = 0;
773 cep->Length = scp->length.LowPart;
774 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
775 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
776 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp)
777 cep->cbExpires = scp->volp->cbExpiresRO;
779 cep->cbExpires = scp->cbExpires;
780 cep->refCount = scp->refCount;
781 cep->opens = scp->openReads;
782 cep->writers = scp->openWrites;
783 switch (scp->fileType) {
784 case CM_SCACHETYPE_FILE:
787 case CM_SCACHETYPE_MOUNTPOINT:
790 case CM_SCACHETYPE_DIRECTORY:
791 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
796 case CM_SCACHETYPE_SYMLINK:
799 case CM_SCACHETYPE_DFSLINK:
802 case CM_SCACHETYPE_INVALID:
807 if (scp->flags & CM_SCACHEFLAG_STATD)
809 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
811 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
812 scp->mountPointStringp[0])
814 if (scp->flags & CM_SCACHEFLAG_WAITING)
819 * Return our results.
822 lock_ReleaseRead(&cm_scacheLock);
824 #ifdef HOLD_CALL_MUTEX
825 MUTEX_EXIT(&callp->lock);
830 /* debug interface */
832 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
837 struct rx_connection *connp;
838 struct rx_peer *peerp;
839 unsigned long host = 0;
840 unsigned short port = 0;
842 #ifdef HOLD_CALL_MUTEX
843 MUTEX_ENTER(&callp->lock);
845 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
846 host = rx_HostOf(peerp);
847 port = rx_PortOf(peerp);
850 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
851 ntohl(host), ntohs(port));
853 lock_ObtainRead(&cm_scacheLock);
854 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
855 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
859 } /*Zip through current hash chain */
860 } /*Zip through hash chains */
870 * Copy out the located entry.
872 memset(cep, 0, sizeof(AFSDBCacheEntry64));
873 cep->addr = afs_data_pointer_to_int32(scp);
874 cep->cell = scp->fid.cell;
875 cep->netFid.Volume = scp->fid.volume;
876 cep->netFid.Vnode = scp->fid.vnode;
877 cep->netFid.Unique = scp->fid.unique;
878 cep->lock.waitStates = 0;
879 cep->lock.exclLocked = scp->mx.flags;
880 cep->lock.readersReading = 0;
881 cep->lock.numWaiting = scp->mx.waiters;
882 cep->lock.pid_last_reader = 0;
883 cep->lock.pid_writer = 0;
884 cep->lock.src_indicator = 0;
885 #if !defined(AFS_64BIT_ENV)
886 cep->Length.high = scp->length.HighPart;
887 cep->Length.low = scp->length.LowPart;
889 cep->Length = (afs_int64) scp->length.QuadPart;
891 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
892 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
893 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp)
894 cep->cbExpires = scp->volp->cbExpiresRO;
896 cep->cbExpires = scp->cbExpires;
897 cep->refCount = scp->refCount;
898 cep->opens = scp->openReads;
899 cep->writers = scp->openWrites;
900 switch (scp->fileType) {
901 case CM_SCACHETYPE_FILE:
904 case CM_SCACHETYPE_MOUNTPOINT:
907 case CM_SCACHETYPE_DIRECTORY:
908 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
913 case CM_SCACHETYPE_SYMLINK:
916 case CM_SCACHETYPE_DFSLINK:
919 case CM_SCACHETYPE_INVALID:
924 if (scp->flags & CM_SCACHEFLAG_STATD)
926 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
928 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
929 scp->mountPointStringp[0])
931 if (scp->flags & CM_SCACHEFLAG_WAITING)
936 * Return our results.
939 lock_ReleaseRead(&cm_scacheLock);
941 #ifdef HOLD_CALL_MUTEX
942 MUTEX_EXIT(&callp->lock);
947 /* debug interface: not implemented */
949 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
951 struct rx_connection *connp;
952 struct rx_peer *peerp;
953 unsigned long host = 0;
954 unsigned short port = 0;
956 #ifdef HOLD_CALL_MUTEX
957 MUTEX_ENTER(&callp->lock);
959 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
960 host = rx_HostOf(peerp);
961 port = rx_PortOf(peerp);
964 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
965 ntohl(host), ntohs(port));
968 #ifdef HOLD_CALL_MUTEX
969 MUTEX_EXIT(&callp->lock);
974 /* debug interface: not implemented */
976 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
977 AFSCB_CollData *datap)
979 struct rx_connection *connp;
980 struct rx_peer *peerp;
981 unsigned long host = 0;
982 unsigned short port = 0;
984 #ifdef HOLD_CALL_MUTEX
985 MUTEX_ENTER(&callp->lock);
987 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
988 host = rx_HostOf(peerp);
989 port = rx_PortOf(peerp);
992 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
993 ntohl(host), ntohs(port));
995 #ifdef HOLD_CALL_MUTEX
996 MUTEX_EXIT(&callp->lock);
1002 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
1004 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
1006 return SRXAFSCB_InitCallBackState(callp);
1009 /* debug interface */
1011 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
1014 int cm_noIPAddr; /* number of client network interfaces */
1015 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
1016 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
1017 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
1018 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
1020 struct rx_connection *connp;
1021 struct rx_peer *peerp;
1022 unsigned long host = 0;
1023 unsigned short port = 0;
1025 #ifdef HOLD_CALL_MUTEX
1026 MUTEX_ENTER(&callp->lock);
1028 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1029 host = rx_HostOf(peerp);
1030 port = rx_PortOf(peerp);
1033 /* get network related info */
1034 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1035 code = syscfg_GetIFInfo(&cm_noIPAddr,
1036 cm_IPAddr, cm_SubnetMask,
1037 cm_NetMtu, cm_NetFlags);
1039 /* return all network interface addresses */
1040 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
1044 addr->numberOfInterfaces = cm_noIPAddr;
1045 addr->uuid = cm_data.Uuid;
1046 for ( i=0; i < cm_noIPAddr; i++ ) {
1047 addr->addr_in[i] = cm_IPAddr[i];
1048 addr->subnetmask[i] = cm_SubnetMask[i];
1049 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1050 cm_NetMtu[i] : rx_mtu;
1053 #ifdef HOLD_CALL_MUTEX
1054 MUTEX_EXIT(&callp->lock);
1060 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
1064 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
1065 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 %s ->",p);
1068 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 - no server Uuid ->");
1070 return SRXAFSCB_InitCallBackState(callp);
1073 /* debug interface */
1075 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1077 struct rx_connection *connp;
1078 struct rx_peer *peerp;
1079 unsigned long host = 0;
1080 unsigned short port = 0;
1084 #ifdef HOLD_CALL_MUTEX
1085 MUTEX_ENTER(&callp->lock);
1087 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1088 host = rx_HostOf(peerp);
1089 port = rx_PortOf(peerp);
1092 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1093 UuidToString((UUID *)&cm_data.Uuid, &p);
1094 UuidToString((UUID *)clientUuid, &q);
1095 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1096 osi_LogSaveString(afsd_logp,p),
1097 osi_LogSaveString(afsd_logp,q),
1103 code = 1; /* failure */
1105 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1109 #ifdef HOLD_CALL_MUTEX
1110 MUTEX_EXIT(&callp->lock);
1115 /* debug interface */
1117 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1121 cm_serverRef_t * serverRefp;
1123 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1125 *a_name = strdup("");
1129 lock_ObtainRead(&cm_serverLock);
1130 *a_name = strdup(cellp->name);
1132 for ( sn = 0, serverRefp = cellp->vlServersp;
1133 sn < AFSMAXCELLHOSTS && serverRefp;
1134 sn++, serverRefp = serverRefp->next);
1136 a_hosts->serverList_len = sn;
1137 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1139 for ( sn = 0, serverRefp = cellp->vlServersp;
1140 sn < AFSMAXCELLHOSTS && serverRefp;
1141 sn++, serverRefp = serverRefp->next)
1143 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1146 lock_ReleaseRead(&cm_serverLock);
1150 /* debug interface */
1152 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1153 char **a_name, serverList *a_hosts)
1155 struct rx_connection *connp;
1156 struct rx_peer *peerp;
1157 unsigned long host = 0;
1158 unsigned short port = 0;
1161 #ifdef HOLD_CALL_MUTEX
1162 MUTEX_ENTER(&callp->lock);
1164 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1165 host = rx_HostOf(peerp);
1166 port = rx_PortOf(peerp);
1169 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1170 a_cellnum, ntohl(host), ntohs(port));
1172 a_hosts->serverList_val = 0;
1173 a_hosts->serverList_len = 0;
1176 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1178 #ifdef HOLD_CALL_MUTEX
1179 MUTEX_EXIT(&callp->lock);
1184 /* debug interface */
1186 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1187 struct interfaceAddr *addr,
1188 Capabilities * capabilities)
1191 afs_int32 *dataBuffP;
1192 afs_int32 dataBytes;
1193 int cm_noIPAddr; /* number of client network interfaces */
1194 int cm_IPAddr[CM_MAXINTERFACE_ADDR]; /* client's IP address in host order */
1195 int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
1196 int cm_NetMtu[CM_MAXINTERFACE_ADDR]; /* client's MTU sizes */
1197 int cm_NetFlags[CM_MAXINTERFACE_ADDR]; /* network flags */
1199 struct rx_connection *connp;
1200 struct rx_peer *peerp;
1201 unsigned long host = 0;
1202 unsigned short port = 0;
1204 #ifdef HOLD_CALL_MUTEX
1205 MUTEX_ENTER(&callp->lock);
1207 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1208 host = rx_HostOf(peerp);
1209 port = rx_PortOf(peerp);
1212 /* get network related info */
1213 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1214 code = syscfg_GetIFInfo(&cm_noIPAddr,
1215 cm_IPAddr, cm_SubnetMask,
1216 cm_NetMtu, cm_NetFlags);
1218 osi_Log2(afsd_logp, "SRXAFSCB_TellMeAboutYourself from host 0x%x port %d",
1222 /* return all network interface addresses */
1223 addr->numberOfInterfaces = cm_noIPAddr;
1224 addr->uuid = cm_data.Uuid;
1225 for ( i=0; i < cm_noIPAddr; i++ ) {
1226 addr->addr_in[i] = cm_IPAddr[i];
1227 addr->subnetmask[i] = cm_SubnetMask[i];
1228 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1229 cm_NetMtu[i] : rx_mtu;
1232 dataBytes = 1 * sizeof(afs_int32);
1233 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1234 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1235 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1236 capabilities->Capabilities_val = dataBuffP;
1238 #ifdef HOLD_CALL_MUTEX
1239 MUTEX_EXIT(&callp->lock);
1244 /*------------------------------------------------------------------------
1245 * EXPORTED SRXAFSCB_GetServerPrefs
1248 * Routine to list server preferences used by this client.
1251 * a_call : Ptr to Rx call on which this request came in.
1252 * a_index : Input server index
1253 * a_srvr_addr : Output server address (0xffffffff on last server)
1254 * a_srvr_rank : Output server rank
1260 * Nothing interesting.
1264 *------------------------------------------------------------------------*/
1266 int SRXAFSCB_GetServerPrefs(
1267 struct rx_call *callp,
1269 afs_int32 *a_srvr_addr,
1270 afs_int32 *a_srvr_rank)
1272 struct rx_connection *connp;
1273 struct rx_peer *peerp;
1274 unsigned long host = 0;
1275 unsigned short port = 0;
1277 #ifdef HOLD_CALL_MUTEX
1278 MUTEX_ENTER(&callp->lock);
1280 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1281 host = rx_HostOf(peerp);
1282 port = rx_PortOf(peerp);
1285 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1289 *a_srvr_addr = 0xffffffff;
1290 *a_srvr_rank = 0xffffffff;
1292 #ifdef HOLD_CALL_MUTEX
1293 MUTEX_EXIT(&callp->lock);
1298 /*------------------------------------------------------------------------
1299 * EXPORTED SRXAFSCB_GetCellServDB
1302 * Routine to list cells configured for this client
1305 * a_call : Ptr to Rx call on which this request came in.
1306 * a_index : Input cell index
1307 * a_name : Output cell name ("" on last cell)
1308 * a_hosts : Output cell database servers
1314 * Nothing interesting.
1318 *------------------------------------------------------------------------*/
1320 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1321 serverList *a_hosts)
1323 struct rx_connection *connp;
1324 struct rx_peer *peerp;
1325 unsigned long host = 0;
1326 unsigned short port = 0;
1329 #ifdef HOLD_CALL_MUTEX
1330 MUTEX_ENTER(&callp->lock);
1332 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1333 host = rx_HostOf(peerp);
1334 port = rx_PortOf(peerp);
1337 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1338 ntohl(host), ntohs(port));
1340 #ifdef AFS_FREELANCE_CLIENT
1341 if (cm_freelanceEnabled && index == 0) {
1342 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1346 rc = GetCellCommon(index+1, a_name, a_hosts);
1351 /*------------------------------------------------------------------------
1352 * EXPORTED SRXAFSCB_GetLocalCell
1355 * Routine to return name of client's local cell
1358 * a_call : Ptr to Rx call on which this request came in.
1359 * a_name : Output cell name
1365 * Nothing interesting.
1369 *------------------------------------------------------------------------*/
1371 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1374 struct rx_connection *connp;
1375 struct rx_peer *peerp;
1376 unsigned long host = 0;
1377 unsigned short port = 0;
1379 #ifdef HOLD_CALL_MUTEX
1380 MUTEX_ENTER(&callp->lock);
1382 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1383 host = rx_HostOf(peerp);
1384 port = rx_PortOf(peerp);
1387 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1388 ntohl(host), ntohs(port));
1390 if (cm_data.rootCellp) {
1391 t_name = (char *)malloc(strlen(cm_data.rootCellp->name)+1);
1392 strcpy(t_name, cm_data.rootCellp->name);
1394 t_name = (char *)malloc(1);
1399 #ifdef HOLD_CALL_MUTEX
1400 MUTEX_EXIT(&callp->lock);
1407 * afs_MarshallCacheConfig - marshall client cache configuration
1411 * IN callerVersion - the rpc stat version of the caller.
1413 * IN config - client cache configuration.
1415 * OUT ptr - buffer where configuration is marshalled.
1421 static void afs_MarshallCacheConfig(
1422 afs_uint32 callerVersion,
1423 cm_initparams_v1 *config,
1427 * We currently only support version 1.
1429 *(ptr++) = config->nChunkFiles;
1430 *(ptr++) = config->nStatCaches;
1431 *(ptr++) = config->nDataCaches;
1432 *(ptr++) = config->nVolumeCaches;
1433 *(ptr++) = config->firstChunkSize;
1434 *(ptr++) = config->otherChunkSize;
1435 *(ptr++) = config->cacheSize;
1436 *(ptr++) = config->setTime;
1437 *(ptr++) = config->memCache;
1442 /*------------------------------------------------------------------------
1443 * EXPORTED SRXAFSCB_GetCacheConfig
1446 * Routine to return parameters used to initialize client cache.
1447 * Client may request any format version. Server may not return
1448 * format version greater than version requested by client.
1451 * a_call: Ptr to Rx call on which this request came in.
1452 * callerVersion: Data format version desired by the client.
1453 * serverVersion: Data format version of output data.
1454 * configCount: Number bytes allocated for output data.
1455 * config: Client cache configuration.
1461 * Nothing interesting.
1465 *------------------------------------------------------------------------*/
1467 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1468 afs_uint32 callerVersion,
1469 afs_uint32 *serverVersion,
1470 afs_uint32 *configCount,
1471 cacheConfig *config)
1473 afs_uint32 *t_config;
1475 extern cm_initparams_v1 cm_initParams;
1476 struct rx_connection *connp;
1477 struct rx_peer *peerp;
1478 unsigned long host = 0;
1479 unsigned short port = 0;
1481 #ifdef HOLD_CALL_MUTEX
1482 MUTEX_ENTER(&callp->lock);
1484 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1485 host = rx_HostOf(peerp);
1486 port = rx_PortOf(peerp);
1489 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1490 ntohl(host), ntohs(port));
1493 * Currently only support version 1
1495 allocsize = sizeof(cm_initparams_v1);
1496 t_config = (afs_uint32 *)malloc(allocsize);
1498 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1500 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1503 #define SIZE_MAX UINT_MAX
1505 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1507 *configCount = (afs_uint32)allocsize;
1508 config->cacheConfig_val = t_config;
1509 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1511 #ifdef HOLD_CALL_MUTEX
1512 MUTEX_EXIT(&callp->lock);
1517 /* called by afsd without any locks to initialize this module */
1518 void cm_InitCallback(void)
1520 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock");
1521 cm_activeCallbackGrantingCalls = 0;
1524 /* called with locked scp; tells us whether we've got a callback.
1525 * Expirations are checked by a background daemon so as to make
1526 * this function as inexpensive as possible
1528 int cm_HaveCallback(cm_scache_t *scp)
1530 #ifdef AFS_FREELANCE_CLIENT
1531 // yj: we handle callbacks specially for callbacks on the root directory
1532 // Since it's local, we almost always say that we have callback on it
1533 // The only time we send back a 0 is if we're need to initialize or
1534 // reinitialize the fake directory
1536 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1537 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1538 // hence should return false. it's 0 otherwise
1539 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1540 // if the fake directory is loaded and this is the first time cm_HaveCallback
1541 // is called since then. We return false in this case to allow cm_GetCallback
1542 // to be called because cm_GetCallback has some initialization work to do.
1543 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1544 // good shape and we simply return true, provided no change is detected.
1547 if (cm_freelanceEnabled &&
1548 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1549 /* if it's something on /afs */
1550 if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1)) {
1551 /* if it's not root.afs */
1555 lock_ObtainMutex(&cm_Freelance_Lock);
1556 fdc = cm_fakeDirCallback;
1557 fgc = cm_fakeGettingCallback;
1558 lock_ReleaseMutex(&cm_Freelance_Lock);
1560 if (fdc==1) { // first call since init
1562 } else if (fdc==2 && !fgc) { // we're in good shape
1563 if (cm_getLocalMountPointChange()) { // check for changes
1564 cm_clearLocalMountPointChange(); // clear the changefile
1565 lock_ReleaseMutex(&scp->mx); // this is re-locked in reInitLocalMountPoints
1566 cm_reInitLocalMountPoints(); // start reinit
1567 lock_ObtainMutex(&scp->mx); // now get the lock back
1570 return 1; // no change
1576 if (scp->cbServerp != NULL) {
1578 } else if (cm_OfflineROIsValid) {
1579 switch (cm_GetVolumeStatus(scp->volp, scp->fid.volume)) {
1592 /* need to detect a broken callback that races with our obtaining a callback.
1593 * Need to be able to do this even if we don't know the file ID of the file
1594 * we're breaking the callback on at the time we start the acquisition of the
1595 * callback (as in the case where we are creating a file).
1597 * So, we start by writing down the count of the # of callbacks we've received
1598 * so far, and bumping a global counter of the # of callback granting calls
1599 * outstanding (all done under cm_callbackLock).
1601 * When we're back from the call, we look at all of the callback revokes with
1602 * counter numbers greater than the one we recorded in our caller's structure,
1603 * and replay those that are higher than when we started the call.
1605 * We free all the structures in the queue when the count of the # of outstanding
1606 * callback-granting calls drops to zero.
1608 * We call this function with the scp locked, too, but in its current implementation,
1609 * this knowledge is not used.
1611 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1613 lock_ObtainWrite(&cm_callbackLock);
1614 cbrp->callbackCount = cm_callbackCount;
1615 cm_activeCallbackGrantingCalls++;
1616 cbrp->startTime = time(NULL);
1617 cbrp->serverp = NULL;
1618 lock_ReleaseWrite(&cm_callbackLock);
1621 /* Called at the end of a callback-granting call, to remove the callback
1622 * info from the scache entry, if necessary.
1624 * Called with scp locked, so we can discard the callbacks easily with
1625 * this locking hierarchy.
1627 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1628 AFSCallBack *cbp, long flags)
1630 cm_racingRevokes_t *revp; /* where we are */
1631 cm_racingRevokes_t *nrevp; /* where we'll be next */
1633 cm_server_t * serverp = NULL;
1634 int discardScp = 0, discardVolCB = 0;
1636 lock_ObtainWrite(&cm_callbackLock);
1637 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1638 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1639 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1642 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1643 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1645 if (cm_activeCallbackGrantingCalls == 0)
1650 /* record the callback; we'll clear it below if we really lose it */
1653 if (scp->cbServerp != cbrp->serverp) {
1654 serverp = scp->cbServerp;
1656 cm_GetServer(cbrp->serverp);
1657 scp->cbServerp = cbrp->serverp;
1660 serverp = cbrp->serverp;
1662 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1663 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp)
1664 scp->volp->cbExpiresRO = scp->cbExpires;
1667 serverp = cbrp->serverp;
1670 cbrp->serverp = NULL;
1673 /* a callback was actually revoked during our granting call, so
1674 * run down the list of revoked fids, looking for ours.
1675 * If activeCallbackGrantingCalls is zero, free the elements, too.
1677 * May need to go through entire list just to do the freeing.
1679 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1680 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1681 /* if this callback came in later than when we started the
1682 * callback-granting call, and if this fid is the right fid,
1683 * then clear the callback.
1685 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1686 && revp->callbackCount > cbrp->callbackCount
1687 && (( scp->fid.volume == revp->fid.volume &&
1688 scp->fid.vnode == revp->fid.vnode &&
1689 scp->fid.unique == revp->fid.unique)
1691 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1692 scp->fid.volume == revp->fid.volume)
1694 (revp->flags & CM_RACINGFLAG_CANCELALL))) {
1695 /* this one matches */
1697 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1699 cbrp->callbackCount, revp->callbackCount,
1703 if ((scp->flags & CM_SCACHEFLAG_PURERO) && scp->volp &&
1704 (revp->flags & (CM_RACINGFLAG_CANCELVOL | CM_RACINGFLAG_CANCELALL)))
1705 scp->volp->cbExpiresRO = 0;
1711 /* if we freed the list, zap the pointer to it */
1713 cm_racingRevokesp = NULL;
1715 lock_ReleaseWrite(&cm_callbackLock);
1718 cm_DiscardSCache(scp);
1719 lock_ReleaseMutex(&scp->mx);
1720 cm_CallbackNotifyChange(scp);
1721 lock_ObtainMutex(&scp->mx);
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 * callp = NULL;
1747 int syncop_done = 0;
1749 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1750 scp, scp->fid.cell, scp->fid.volume, flags);
1752 #ifdef AFS_FREELANCE_CLIENT
1753 // The case where a callback is needed on /afs is handled
1754 // specially. We need to fetch the status by calling
1755 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1756 if (cm_freelanceEnabled) {
1757 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1758 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
1759 scp->fid.unique==0x1 &&
1760 scp->fid.vnode==0x1) {
1762 // Start by indicating that we're in the process
1763 // of fetching the callback
1764 lock_ObtainMutex(&cm_Freelance_Lock);
1765 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1766 cm_fakeGettingCallback = 1;
1767 lock_ReleaseMutex(&cm_Freelance_Lock);
1769 // Fetch the status info
1770 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1772 // Indicate that the callback is not done
1773 lock_ObtainMutex(&cm_Freelance_Lock);
1774 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1775 cm_fakeDirCallback = 2;
1777 // Indicate that we're no longer fetching the callback
1778 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1779 cm_fakeGettingCallback = 0;
1780 lock_ReleaseMutex(&cm_Freelance_Lock);
1785 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1786 osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
1789 #endif /* AFS_FREELANCE_CLIENT */
1791 mustCall = (flags & 1);
1792 cm_AFSFidFromFid(&tfid, &scp->fid);
1794 if (!mustCall && cm_HaveCallback(scp))
1797 /* turn off mustCall, since it has now forced us past the check above */
1800 /* otherwise, we have to make an RPC to get the status */
1802 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1803 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1808 cm_StartCallbackGrantingCall(scp, &cbr);
1810 lock_ReleaseMutex(&scp->mx);
1812 /* now make the RPC */
1813 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1814 scp, sfid.volume, sfid.vnode, sfid.unique);
1816 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1820 callp = cm_GetRxConn(connp);
1821 code = RXAFS_FetchStatus(callp, &tfid,
1822 &afsStatus, &callback, &volSync);
1823 rx_PutConnection(callp);
1825 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1827 code = cm_MapRPCError(code, reqp);
1829 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1830 code, scp, scp->fid.volume, scp->fid.vnode);
1832 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1833 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1835 lock_ObtainMutex(&scp->mx);
1837 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1838 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1840 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1843 /* if we got an error, return to caller */
1849 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1852 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1853 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1854 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1856 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1857 scp, scp->fid.cell, scp->fid.volume);
1864 /* called with cm_scacheLock held */
1865 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1867 cm_vol_state_t *statep;
1868 cm_volume_t * volp = scp->volp;
1869 afs_uint32 volID = scp->fid.volume;
1870 cm_serverRef_t *tsrp;
1875 if (scp->cbServerp == NULL)
1878 if (volp->rw.ID == volID) {
1880 } else if (volp->ro.ID == volID) {
1882 } else if (volp->bk.ID == volID) {
1886 if (statep->state == vl_online)
1889 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1890 if (tsrp->server == scp->cbServerp)
1892 if (tsrp->server->downTime > *downTime)
1893 *downTime = tsrp->server->downTime;
1896 /* if the cbServerp does not match the current volume server list
1897 * we report the callback server as up so the callback can be
1900 return(found ? 0 : 1);
1903 /* called periodically by cm_daemon to shut down use of expired callbacks */
1904 void cm_CheckCBExpiration(void)
1908 time_t now, downTime;
1910 osi_Log0(afsd_logp, "CheckCBExpiration");
1913 lock_ObtainWrite(&cm_scacheLock);
1914 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1915 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1917 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp) {
1918 if (scp->volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
1919 scp->cbExpires = scp->volp->cbExpiresRO;
1922 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1923 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1925 cm_HoldSCacheNoLock(scp);
1926 lock_ReleaseWrite(&cm_scacheLock);
1928 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1929 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1930 lock_ObtainMutex(&scp->mx);
1931 cm_DiscardSCache(scp);
1932 lock_ReleaseMutex(&scp->mx);
1933 cm_CallbackNotifyChange(scp);
1935 cm_ReleaseSCacheNoLock(scp);
1936 lock_ObtainWrite(&cm_scacheLock);
1940 lock_ReleaseWrite(&cm_scacheLock);
1942 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1947 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1951 struct rx_connection * rxconnp;
1953 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1955 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1957 rxconnp = cm_GetRxConn(connp);
1958 rx_SetConnDeadTime(rxconnp, 10);
1959 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1960 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1961 rx_PutConnection(rxconnp);
1965 cm_server_vols_t * tsrvp;
1969 lock_ObtainMutex(&tsp->mx);
1970 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1971 tsp->flags |= CM_SERVERFLAG_DOWN;
1972 tsp->downTime = osi_Time();
1974 cm_ForceNewConnections(tsp);
1976 /* Now update the volume status */
1977 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
1978 for (i=0; i<NUM_SERVER_VOLS; i++) {
1979 if (tsrvp->ids[i] != 0) {
1984 code = cm_GetVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
1985 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
1987 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
1993 lock_ReleaseMutex(&tsp->mx);
1999 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
2003 if (!cm_giveUpAllCBs)
2006 lock_ObtainWrite(&cm_serverLock);
2007 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
2008 cm_GetServerNoLock(tsp);
2009 lock_ReleaseWrite(&cm_serverLock);
2010 cm_GiveUpAllCallbacks(tsp, markDown);
2011 lock_ObtainWrite(&cm_serverLock);
2012 cm_PutServerNoLock(tsp);
2014 lock_ReleaseWrite(&cm_serverLock);