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>
23 #include <rx_pthread.h>
25 #include <WINNT/syscfg.h>
26 #include <WINNT/afsreg.h>
29 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid);
31 /* read/write lock for all global storage in this module */
32 osi_rwlock_t cm_callbackLock;
34 afs_int32 cm_OfflineROIsValid = 0;
36 afs_int32 cm_giveUpAllCBs = 0;
38 afs_int32 cm_shutdown = 0;
40 #ifdef AFS_FREELANCE_CLIENT
41 extern osi_mutex_t cm_Freelance_Lock;
44 /* count of # of callback breaking messages received by this CM so far. We use
45 * this count in determining whether there have been any callback breaks that
46 * apply to a call that returned a new callback. If the counter doesn't
47 * increase during a call, then we know that no callbacks were broken during
48 * that call, and thus that the callback that was just returned is still valid.
50 long cm_callbackCount;
52 /* count of number of RPCs potentially returning a callback executing now.
53 * When this counter hits zero, we can clear out the racing revokes list, since
54 * at that time, we know that none of the just-executed callback revokes will
55 * apply to any future call that returns a callback (since the latter hasn't
56 * even started execution yet).
58 long cm_activeCallbackGrantingCalls;
60 /* list of callbacks that have been broken recently. If a call returning a
61 * callback is executing and a callback revoke runs immediately after it at the
62 * server, the revoke may end up being processed before the response to the
63 * original callback granting call. We detect this by keeping a list of
64 * callback revokes that have been received since we *started* the callback
65 * granting call, and discarding any callbacks received for the same file ID,
66 * even if the callback revoke was received before the callback grant.
68 cm_racingRevokes_t *cm_racingRevokesp;
70 /* record a (potentially) racing revoke for this file ID; null means for all
71 * file IDs, and is used by InitCallBackState.
73 * The cancelFlags describe whether we're just discarding callbacks for the same
74 * file ID, the same volume, or all from the same server.
76 * Called with no locks held.
78 void cm_RecordRacingRevoke(cm_fid_t *fidp, long cancelFlags)
80 cm_racingRevokes_t *rp;
82 lock_ObtainWrite(&cm_callbackLock);
84 osi_Log3(afsd_logp, "RecordRacingRevoke Volume %d Flags %lX activeCalls %d",
85 fidp ? fidp->volume : 0, cancelFlags, cm_activeCallbackGrantingCalls);
87 if (cm_activeCallbackGrantingCalls > 0) {
88 rp = malloc(sizeof(*rp));
89 memset(rp, 0, sizeof(*rp));
90 osi_QAdd((osi_queue_t **) &cm_racingRevokesp, &rp->q);
91 rp->flags |= (cancelFlags & CM_RACINGFLAG_ALL);
92 if (fidp) rp->fid = *fidp;
93 rp->callbackCount = ++cm_callbackCount;
95 lock_ReleaseWrite(&cm_callbackLock);
99 * When we lose a callback, may have to send change notification replies.
100 * Do not call with a lock on the scp.
102 void cm_CallbackNotifyChange(cm_scache_t *scp)
108 /* why does this have to query the registry each time? */
109 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE,
110 AFSREG_CLT_OPENAFS_SUBKEY,
112 KEY_READ|KEY_QUERY_VALUE,
113 &hKey) == ERROR_SUCCESS) {
115 dummyLen = sizeof(DWORD);
116 RegQueryValueEx(hKey, "CallBack Notify Change Delay", NULL, NULL,
117 (BYTE *) &dwDelay, &dummyLen);
121 if (dwDelay > 5000) /* do not allow a delay of more then 5 seconds */
124 osi_Log3(afsd_logp, "CallbackNotifyChange FileType %d Flags %lX Delay %dms",
125 scp->fileType, scp->flags, dwDelay);
130 /* for directories, this sends a change notification on the dir itself */
131 if (scp->fileType == CM_SCACHETYPE_DIRECTORY) {
132 if (scp->flags & CM_SCACHEFLAG_ANYWATCH)
134 FILE_NOTIFY_GENERIC_DIRECTORY_FILTER,
135 scp, NULL, NULL, TRUE);
137 /* and for files, this sends a change notification on the file's parent dir */
141 cm_SetFid(&tfid, scp->fid.cell, scp->fid.volume, scp->parentVnode, scp->parentUnique);
142 dscp = cm_FindSCache(&tfid);
144 dscp->flags & CM_SCACHEFLAG_ANYWATCH )
146 FILE_NOTIFY_GENERIC_FILE_FILTER,
147 dscp, NULL, NULL, TRUE);
149 cm_ReleaseSCache(dscp);
153 /* called with no locks held for every file ID that is revoked directly by
154 * a callback revoke call. Does not have to handle volume callback breaks,
155 * since those have already been split out.
157 * The callp parameter is currently unused.
159 void cm_RevokeCallback(struct rx_call *callp, cm_cell_t * cellp, AFSFid *fidp)
165 /* don't bother setting cell, since we won't be checking it (to aid
166 * in working with multi-homed servers: we don't know the cell if we
167 * don't recognize the IP address).
169 tfid.cell = cellp ? cellp->cellID : 0;
170 tfid.volume = fidp->Volume;
171 tfid.vnode = fidp->Vnode;
172 tfid.unique = fidp->Unique;
173 hash = CM_SCACHE_HASH(&tfid);
175 osi_Log3(afsd_logp, "RevokeCallback vol %u vn %u uniq %u",
176 fidp->Volume, fidp->Vnode, fidp->Unique);
178 /* do this first, so that if we're executing a callback granting call
179 * at this moment, we kill it before it can be merged in. Otherwise,
180 * it could complete while we're doing the scan below, and get missed
181 * by both the scan and by this code.
183 cm_RecordRacingRevoke(&tfid, 0);
185 lock_ObtainWrite(&cm_scacheLock);
186 /* do all in the hash bucket, since we don't know how many we'll find with
189 for (scp = cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
190 if (scp->fid.volume == tfid.volume &&
191 scp->fid.vnode == tfid.vnode &&
192 scp->fid.unique == tfid.unique &&
193 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
194 cm_HaveCallback(scp))
196 cm_HoldSCacheNoLock(scp);
197 lock_ReleaseWrite(&cm_scacheLock);
198 osi_Log4(afsd_logp, "RevokeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
199 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
201 lock_ObtainWrite(&scp->rw);
202 cm_DiscardSCache(scp);
203 lock_ReleaseWrite(&scp->rw);
205 cm_CallbackNotifyChange(scp);
207 lock_ObtainWrite(&cm_scacheLock);
208 cm_ReleaseSCacheNoLock(scp);
211 lock_ReleaseWrite(&cm_scacheLock);
213 osi_Log3(afsd_logp, "RevokeCallback Complete vol %u vn %u uniq %u",
214 fidp->Volume, fidp->Vnode, fidp->Unique);
217 /* called to revoke a volume callback, which is typically issued when a volume
218 * is moved from one server to another.
220 * Called with no locks held.
222 void cm_RevokeVolumeCallback(struct rx_call *callp, cm_cell_t *cellp, AFSFid *fidp)
228 osi_Log1(afsd_logp, "RevokeVolumeCallback vol %d", fidp->Volume);
230 /* do this first, so that if we're executing a callback granting call
231 * at this moment, we kill it before it can be merged in. Otherwise,
232 * it could complete while we're doing the scan below, and get missed
233 * by both the scan and by this code.
235 tfid.cell = cellp ? cellp->cellID : 0;
236 tfid.volume = fidp->Volume;
237 tfid.vnode = tfid.unique = 0;
239 cm_RecordRacingRevoke(&tfid, CM_RACINGFLAG_CANCELVOL);
241 lock_ObtainWrite(&cm_scacheLock);
242 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
243 for(scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
244 if (scp->fid.volume == fidp->Volume &&
245 (cellp == NULL || scp->fid.cell == cellp->cellID) &&
246 scp->cbExpires > 0 &&
247 scp->cbServerp != NULL) {
248 cm_HoldSCacheNoLock(scp);
249 lock_ReleaseWrite(&cm_scacheLock);
251 lock_ObtainWrite(&scp->rw);
252 osi_Log4(afsd_logp, "RevokeVolumeCallback Discarding SCache scp 0x%p vol %u vn %u uniq %u",
253 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
254 cm_DiscardSCache(scp);
255 lock_ReleaseWrite(&scp->rw);
257 cm_CallbackNotifyChange(scp);
258 lock_ObtainWrite(&cm_scacheLock);
259 cm_ReleaseSCacheNoLock(scp);
260 if (scp->flags & CM_SCACHEFLAG_PURERO) {
261 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
263 volp->cbExpiresRO = 0;
268 } /* search one hash bucket */
269 } /* search all hash buckets */
271 lock_ReleaseWrite(&cm_scacheLock);
273 osi_Log1(afsd_logp, "RevokeVolumeCallback Complete vol %d", fidp->Volume);
277 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
278 * given data pointer, without triggering "cast truncates pointer"
279 * warnings. We use this where we explicitly don't care whether a
280 * pointer is truncated -- it loses information where a pointer is
281 * larger than an afs_int32.
285 afs_data_pointer_to_int32(const void *p)
288 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
292 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
297 /* used to determine the byte order of the system */
300 char c[sizeof(int) / sizeof(char)];
306 /* little-endian system */
309 /* big-endian system */
310 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
315 return ip.i32[i32_sub];
317 /*------------------------------------------------------------------------
318 * EXPORTED SRXAFSCB_CallBack
321 * Routine called by the server-side callback RPC interface to
322 * implement passing in callback information.
326 * rx_call : Ptr to Rx call on which this request came in.
327 * fidsArrayp : Ptr to array of fids involved.
328 * cbsArrayp : Ptr to matching callback info for the fids.
334 * Nothing interesting.
338 *------------------------------------------------------------------------*/
339 /* handle incoming RPC callback breaking message.
340 * Called with no locks held.
343 SRXAFSCB_CallBack(struct rx_call *callp, AFSCBFids *fidsArrayp, AFSCBs *cbsArrayp)
347 struct rx_connection *connp;
348 struct rx_peer *peerp;
349 unsigned long host = 0;
350 unsigned short port = 0;
351 cm_server_t *tsp = NULL;
352 cm_cell_t* cellp = NULL;
357 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
358 host = rx_HostOf(peerp);
359 port = rx_PortOf(peerp);
361 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
368 osi_Log2(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d",
372 osi_Log3(afsd_logp, "SRXAFSCB_CallBack from host 0x%x port %d for cell %s",
375 cellp->name /* does not need to be saved, doesn't change */);
377 osi_Log0(afsd_logp, "SRXAFSCB_CallBack from unknown host");
381 for (i=0; i < (long) fidsArrayp->AFSCBFids_len; i++) {
382 tfidp = &fidsArrayp->AFSCBFids_val[i];
384 if (tfidp->Volume == 0)
385 continue; /* means don't do anything */
386 else if (tfidp->Vnode == 0)
387 cm_RevokeVolumeCallback(callp, cellp, tfidp);
389 cm_RevokeCallback(callp, cellp, tfidp);
394 /*------------------------------------------------------------------------
395 * EXPORTED SRXAFSCB_InitCallBackState
398 * Routine called by the server-side callback RPC interface to
399 * implement clearing all callbacks from this host.
402 * rx_call : Ptr to Rx call on which this request came in.
408 * Nothing interesting.
412 *------------------------------------------------------------------------*/
413 /* called with no locks by RPC system when a server indicates that it has never
414 * heard from us, or for other reasons has had to discard callbacks from us
415 * without telling us, e.g. a network partition.
418 SRXAFSCB_InitCallBackState(struct rx_call *callp)
423 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState ->");
425 return SRXAFSCB_InitCallBackState3(callp, NULL);
428 /*------------------------------------------------------------------------
429 * EXPORTED SRXAFSCB_Probe
432 * Routine called by the server-side callback RPC interface to
433 * implement ``probing'' the Cache Manager, just making sure it's
437 * rx_call : Ptr to Rx call on which this request came in.
443 * Nothing interesting.
447 *------------------------------------------------------------------------*/
449 SRXAFSCB_Probe(struct rx_call *callp)
451 struct rx_connection *connp;
452 struct rx_peer *peerp;
453 unsigned long host = 0;
454 unsigned short port = 0;
459 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
460 host = rx_HostOf(peerp);
461 port = rx_PortOf(peerp);
464 osi_Log2(afsd_logp, "SRXAFSCB_Probe from host 0x%x port %d",
471 /*------------------------------------------------------------------------
472 * EXPORTED SRXAFSCB_GetLock
475 * Routine called by the server-side callback RPC interface to
476 * implement pulling out the contents of a lock in the lock
480 * a_call : Ptr to Rx call on which this request came in.
481 * a_index : Index of desired lock.
482 * a_result : Ptr to a buffer for the given lock.
485 * 0 if everything went fine,
486 * 1 if we were given a bad index.
489 * Nothing interesting.
493 *------------------------------------------------------------------------*/
494 /* debug interface */
496 extern osi_rwlock_t cm_aclLock;
497 extern osi_rwlock_t buf_globalLock;
498 extern osi_rwlock_t cm_cellLock;
499 extern osi_rwlock_t cm_connLock;
500 extern osi_rwlock_t cm_daemonLock;
501 extern osi_rwlock_t cm_dnlcLock;
502 extern osi_rwlock_t cm_scacheLock;
503 extern osi_rwlock_t cm_serverLock;
504 extern osi_rwlock_t cm_syscfgLock;
505 extern osi_rwlock_t cm_userLock;
506 extern osi_rwlock_t cm_utilsLock;
507 extern osi_rwlock_t cm_volumeLock;
508 extern osi_rwlock_t smb_globalLock;
509 extern osi_rwlock_t smb_rctLock;
511 extern osi_mutex_t cm_Freelance_Lock;
512 extern osi_mutex_t cm_Afsdsbmt_Lock;
513 extern osi_mutex_t tokenEventLock;
514 extern osi_mutex_t smb_ListenerLock;
515 extern osi_mutex_t smb_RawBufLock;
516 extern osi_mutex_t smb_Dir_Watch_Lock;
518 #define LOCKTYPE_RW 1
519 #define LOCKTYPE_MUTEX 2
520 static struct _ltable {
525 {"cm_scacheLock", (char*)&cm_scacheLock, LOCKTYPE_RW},
526 {"buf_globalLock", (char*)&buf_globalLock, LOCKTYPE_RW},
527 {"cm_serverLock", (char*)&cm_serverLock, LOCKTYPE_RW},
528 {"cm_callbackLock", (char*)&cm_callbackLock, LOCKTYPE_RW},
529 {"cm_syscfgLock", (char*)&cm_syscfgLock, LOCKTYPE_RW},
530 {"cm_aclLock", (char*)&cm_aclLock, LOCKTYPE_RW},
531 {"cm_cellLock", (char*)&cm_cellLock, LOCKTYPE_RW},
532 {"cm_connLock", (char*)&cm_connLock, LOCKTYPE_RW},
533 {"cm_userLock", (char*)&cm_userLock, LOCKTYPE_RW},
534 {"cm_volumeLock", (char*)&cm_volumeLock, LOCKTYPE_RW},
535 {"cm_daemonLock", (char*)&cm_daemonLock, LOCKTYPE_RW},
536 {"cm_dnlcLock", (char*)&cm_dnlcLock, LOCKTYPE_RW},
537 {"cm_utilsLock", (char*)&cm_utilsLock, LOCKTYPE_RW},
538 {"smb_globalLock", (char*)&smb_globalLock, LOCKTYPE_RW},
539 {"smb_rctLock", (char*)&smb_rctLock, LOCKTYPE_RW},
540 {"cm_Freelance_Lock",(char*)&cm_Freelance_Lock, LOCKTYPE_MUTEX},
541 {"cm_Afsdsbmt_Lock", (char*)&cm_Afsdsbmt_Lock, LOCKTYPE_MUTEX},
542 {"tokenEventLock", (char*)&tokenEventLock, LOCKTYPE_MUTEX},
543 {"smb_ListenerLock", (char*)&smb_ListenerLock, LOCKTYPE_MUTEX},
544 {"smb_RawBufLock", (char*)&smb_RawBufLock, LOCKTYPE_MUTEX},
545 {"smb_Dir_Watch_Lock",(char*)&smb_Dir_Watch_Lock, LOCKTYPE_MUTEX}
549 SRXAFSCB_GetLock(struct rx_call *callp, long index, AFSDBLock *lockp)
551 struct _ltable *tl; /*Ptr to lock table entry */
554 int nentries; /*Num entries in table */
555 int code; /*Return code */
556 struct rx_connection *connp;
557 struct rx_peer *peerp;
558 unsigned long host = 0;
559 unsigned short port = 0;
564 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
565 host = rx_HostOf(peerp);
566 port = rx_PortOf(peerp);
569 osi_Log3(afsd_logp, "SRXAFSCB_GetLock(%d) from host 0x%x port %d",
570 index, ntohl(host), ntohs(port));
572 nentries = sizeof(ltable) / sizeof(struct _ltable);
573 if (index < 0 || index >= nentries) {
580 * Found it - copy out its contents.
583 strncpy(lockp->name, tl->name, sizeof(lockp->name));
584 lockp->name[sizeof(lockp->name)-1] = '\0';
585 lockp->lock.waitStates = 0;
586 switch ( tl->type ) {
588 rwp = (osi_rwlock_t *)tl->addr;
589 lockp->lock.exclLocked = rwp->flags;
590 lockp->lock.readersReading = rwp->readers;
591 lockp->lock.numWaiting = rwp->waiters;
594 mtxp = (osi_mutex_t *)tl->addr;
595 lockp->lock.exclLocked = mtxp->flags;
596 lockp->lock.readersReading = 0;
597 lockp->lock.numWaiting = mtxp->waiters;
600 lockp->lock.pid_last_reader = 0;
601 lockp->lock.pid_writer = 0;
602 lockp->lock.src_indicator = 0;
609 /* debug interface */
611 SRXAFSCB_GetCE(struct rx_call *callp, long index, AFSDBCacheEntry *cep)
616 struct rx_connection *connp;
617 struct rx_peer *peerp;
618 unsigned long host = 0;
619 unsigned short port = 0;
624 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
625 host = rx_HostOf(peerp);
626 port = rx_PortOf(peerp);
629 osi_Log2(afsd_logp, "SRXAFSCB_GetCE from host 0x%x port %d",
630 ntohl(host), ntohs(port));
632 lock_ObtainRead(&cm_scacheLock);
633 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
634 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
638 } /*Zip through current hash chain */
639 } /*Zip through hash chains */
649 * Copy out the located entry.
651 memset(cep, 0, sizeof(AFSDBCacheEntry));
652 cep->addr = afs_data_pointer_to_int32(scp);
653 cep->cell = scp->fid.cell;
654 cep->netFid.Volume = scp->fid.volume;
655 cep->netFid.Vnode = scp->fid.vnode;
656 cep->netFid.Unique = scp->fid.unique;
657 cep->lock.waitStates = 0;
658 cep->lock.exclLocked = scp->rw.flags;
659 cep->lock.readersReading = 0;
660 cep->lock.numWaiting = scp->rw.waiters;
661 cep->lock.pid_last_reader = 0;
662 cep->lock.pid_writer = 0;
663 cep->lock.src_indicator = 0;
664 cep->Length = scp->length.LowPart;
665 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
666 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
667 if (scp->flags & CM_SCACHEFLAG_PURERO) {
668 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
670 cep->cbExpires = volp->cbExpiresRO;
674 /* TODO: deal with time_t below */
675 cep->cbExpires = (afs_int32) scp->cbExpires;
677 cep->refCount = scp->refCount;
678 cep->opens = scp->openReads;
679 cep->writers = scp->openWrites;
680 switch (scp->fileType) {
681 case CM_SCACHETYPE_FILE:
684 case CM_SCACHETYPE_MOUNTPOINT:
687 case CM_SCACHETYPE_DIRECTORY:
688 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
693 case CM_SCACHETYPE_SYMLINK:
696 case CM_SCACHETYPE_DFSLINK:
699 case CM_SCACHETYPE_INVALID:
704 if (scp->flags & CM_SCACHEFLAG_STATD)
706 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
708 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
709 scp->mountPointStringp[0])
711 if (scp->flags & CM_SCACHEFLAG_WAITING)
716 * Return our results.
719 lock_ReleaseRead(&cm_scacheLock);
724 /* debug interface */
726 SRXAFSCB_GetCE64(struct rx_call *callp, long index, AFSDBCacheEntry64 *cep)
731 struct rx_connection *connp;
732 struct rx_peer *peerp;
733 unsigned long host = 0;
734 unsigned short port = 0;
739 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
740 host = rx_HostOf(peerp);
741 port = rx_PortOf(peerp);
744 osi_Log2(afsd_logp, "SRXAFSCB_GetCE64 from host 0x%x port %d",
745 ntohl(host), ntohs(port));
747 lock_ObtainRead(&cm_scacheLock);
748 for (i = 0; i < cm_data.scacheHashTableSize; i++) {
749 for (scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp) {
753 } /*Zip through current hash chain */
754 } /*Zip through hash chains */
764 * Copy out the located entry.
766 memset(cep, 0, sizeof(AFSDBCacheEntry64));
767 cep->addr = afs_data_pointer_to_int32(scp);
768 cep->cell = scp->fid.cell;
769 cep->netFid.Volume = scp->fid.volume;
770 cep->netFid.Vnode = scp->fid.vnode;
771 cep->netFid.Unique = scp->fid.unique;
772 cep->lock.waitStates = 0;
773 cep->lock.exclLocked = scp->rw.flags;
774 cep->lock.readersReading = 0;
775 cep->lock.numWaiting = scp->rw.waiters;
776 cep->lock.pid_last_reader = 0;
777 cep->lock.pid_writer = 0;
778 cep->lock.src_indicator = 0;
779 #if !defined(AFS_64BIT_ENV)
780 cep->Length.high = scp->length.HighPart;
781 cep->Length.low = scp->length.LowPart;
783 cep->Length = (afs_int64) scp->length.QuadPart;
785 cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
786 cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
787 if (scp->flags & CM_SCACHEFLAG_PURERO) {
788 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
790 cep->cbExpires = volp->cbExpiresRO;
794 /* TODO: handle time_t */
795 cep->cbExpires = (afs_int32) scp->cbExpires;
797 cep->refCount = scp->refCount;
798 cep->opens = scp->openReads;
799 cep->writers = scp->openWrites;
800 switch (scp->fileType) {
801 case CM_SCACHETYPE_FILE:
804 case CM_SCACHETYPE_MOUNTPOINT:
807 case CM_SCACHETYPE_DIRECTORY:
808 if (scp->fid.vnode == 1 && scp->fid.unique == 1)
813 case CM_SCACHETYPE_SYMLINK:
816 case CM_SCACHETYPE_DFSLINK:
819 case CM_SCACHETYPE_INVALID:
824 if (scp->flags & CM_SCACHEFLAG_STATD)
826 if (scp->flags & CM_SCACHEFLAG_RO || scp->flags & CM_SCACHEFLAG_PURERO)
828 if (scp->fileType == CM_SCACHETYPE_MOUNTPOINT &&
829 scp->mountPointStringp[0])
831 if (scp->flags & CM_SCACHEFLAG_WAITING)
836 * Return our results.
839 lock_ReleaseRead(&cm_scacheLock);
844 /* debug interface: not implemented */
846 SRXAFSCB_XStatsVersion(struct rx_call *callp, long *vp)
848 struct rx_connection *connp;
849 struct rx_peer *peerp;
850 unsigned long host = 0;
851 unsigned short port = 0;
856 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
857 host = rx_HostOf(peerp);
858 port = rx_PortOf(peerp);
861 osi_Log2(afsd_logp, "SRXAFSCB_XStatsVersion from host 0x%x port %d - not implemented",
862 ntohl(host), ntohs(port));
868 /* debug interface: not implemented */
870 SRXAFSCB_GetXStats(struct rx_call *callp, long cvn, long coln, long *srvp, long *timep,
871 AFSCB_CollData *datap)
873 struct rx_connection *connp;
874 struct rx_peer *peerp;
875 unsigned long host = 0;
876 unsigned short port = 0;
881 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
882 host = rx_HostOf(peerp);
883 port = rx_PortOf(peerp);
886 osi_Log2(afsd_logp, "SRXAFSCB_GetXStats from host 0x%x port %d - not implemented",
887 ntohl(host), ntohs(port));
893 SRXAFSCB_InitCallBackState2(struct rx_call *callp, struct interfaceAddr* addr)
898 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState2 ->");
900 return SRXAFSCB_InitCallBackState3(callp, NULL);
903 /* debug interface */
905 SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
909 struct rx_connection *connp;
910 struct rx_peer *peerp;
911 unsigned long host = 0;
912 unsigned short port = 0;
917 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
918 host = rx_HostOf(peerp);
919 port = rx_PortOf(peerp);
922 osi_Log2(afsd_logp, "SRXAFSCB_WhoAreYou from host 0x%x port %d",
926 lock_ObtainRead(&cm_syscfgLock);
927 if (cm_LanAdapterChangeDetected) {
928 lock_ConvertRToW(&cm_syscfgLock);
929 if (cm_LanAdapterChangeDetected) {
930 /* get network related info */
931 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
932 code = syscfg_GetIFInfo(&cm_noIPAddr,
933 cm_IPAddr, cm_SubnetMask,
934 cm_NetMtu, cm_NetFlags);
935 cm_LanAdapterChangeDetected = 0;
937 lock_ConvertWToR(&cm_syscfgLock);
940 /* return all network interface addresses */
941 addr->numberOfInterfaces = cm_noIPAddr;
942 addr->uuid = cm_data.Uuid;
943 for ( i=0; i < cm_noIPAddr; i++ ) {
944 addr->addr_in[i] = cm_IPAddr[i];
945 addr->subnetmask[i] = cm_SubnetMask[i];
946 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
947 cm_NetMtu[i] : rx_mtu;
950 lock_ReleaseRead(&cm_syscfgLock);
956 SRXAFSCB_InitCallBackState3(struct rx_call *callp, afsUUID* serverUuid)
960 struct sockaddr_in taddr;
961 cm_server_t *tsp = NULL;
962 cm_scache_t *scp = NULL;
963 cm_cell_t* cellp = NULL;
966 struct rx_connection *connp;
967 struct rx_peer *peerp;
968 unsigned long host = 0;
969 unsigned short port = 0;
974 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
975 host = rx_HostOf(peerp);
976 port = rx_PortOf(peerp);
979 if (UuidToString((UUID *)serverUuid, &p) == RPC_S_OK) {
980 osi_Log1(afsd_logp, "SRXAFSCB_InitCallBackState3 Uuid%s ->",osi_LogSaveString(afsd_logp,p));
984 tsp = cm_FindServerByUuid(serverUuid, CM_SERVER_FILE);
987 tsp = cm_FindServerByIP(host, CM_SERVER_FILE);
994 osi_Log2(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d",
998 osi_Log3(afsd_logp, "SRXAFSCB_InitCallBackState3 from host 0x%x port %d for cell %s",
1001 cellp->name /* does not need to be saved, doesn't change */);
1003 osi_Log0(afsd_logp, "SRXAFSCB_InitCallBackState3 from unknown host");
1006 if (connp && peerp) {
1007 taddr.sin_family = AF_INET;
1008 taddr.sin_addr.s_addr = rx_HostOf(rx_PeerOf(rx_ConnectionOf(callp)));
1010 tsp = cm_FindServer(&taddr, CM_SERVER_FILE);
1012 osi_Log1(afsd_logp, "InitCallbackState3 server %x", tsp);
1014 /* record the callback in the racing revokes structure. This
1015 * shouldn't be necessary, since we shouldn't be making callback
1016 * granting calls while we're going to get an initstate call,
1017 * but there probably are some obscure races, so better safe
1020 * We do this first since we don't hold the cm_scacheLock and vnode
1021 * locks over the entire callback scan operation below. The
1022 * big loop below is guaranteed to hit any callback already
1023 * processed. The call to RecordRacingRevoke is guaranteed
1024 * to kill any callback that is currently being returned.
1025 * Anything that sneaks past both must start
1026 * after the call to RecordRacingRevoke.
1031 fid.cell = cellp->cellID;
1032 fid.volume = fid.vnode = fid.unique = 0;
1034 cm_RecordRacingRevoke(&fid, CM_RACINGFLAG_CANCELALL);
1036 cm_RecordRacingRevoke(NULL, CM_RACINGFLAG_CANCELALL);
1039 /* now search all vnodes looking for guys with this callback, if we
1040 * found it, or guys with any callbacks, if we didn't find the server
1041 * (that's how multihomed machines will appear and how we'll handle
1042 * them, albeit a little inefficiently). That is, we're discarding all
1043 * callbacks from all hosts if we get an initstate call from an unknown
1044 * host. Since these calls are rare, and multihomed servers
1045 * are "rare," hopefully this won't be a problem.
1047 lock_ObtainWrite(&cm_scacheLock);
1048 for (hash = 0; hash < cm_data.scacheHashTableSize; hash++) {
1049 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
1050 cm_HoldSCacheNoLock(scp);
1051 lock_ReleaseWrite(&cm_scacheLock);
1052 lock_ObtainWrite(&scp->rw);
1054 if (scp->cbExpires > 0 && scp->cbServerp != NULL) {
1055 /* we have a callback, now decide if we should clear it */
1056 if (scp->cbServerp == tsp) {
1057 osi_Log4(afsd_logp, "InitCallbackState3 Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1058 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1059 cm_DiscardSCache(scp);
1063 lock_ReleaseWrite(&scp->rw);
1065 cm_CallbackNotifyChange(scp);
1066 lock_ObtainWrite(&cm_scacheLock);
1067 cm_ReleaseSCacheNoLock(scp);
1069 if (discarded && (scp->flags & CM_SCACHEFLAG_PURERO)) {
1070 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1072 if (volp->cbExpiresRO != 0)
1073 volp->cbExpiresRO = 0;
1078 } /* search one hash bucket */
1079 } /* search all hash buckets */
1081 lock_ReleaseWrite(&cm_scacheLock);
1084 /* reset the No flags on the server */
1085 cm_SetServerNo64Bit(tsp, 0);
1086 cm_SetServerNoInlineBulk(tsp, 0);
1088 /* we're done with the server structure */
1095 /* debug interface */
1097 SRXAFSCB_ProbeUuid(struct rx_call *callp, afsUUID* clientUuid)
1099 struct rx_connection *connp;
1100 struct rx_peer *peerp;
1101 unsigned long host = 0;
1102 unsigned short port = 0;
1109 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1110 host = rx_HostOf(peerp);
1111 port = rx_PortOf(peerp);
1114 if ( !afs_uuid_equal(&cm_data.Uuid, clientUuid) ) {
1115 UuidToString((UUID *)&cm_data.Uuid, &p);
1116 UuidToString((UUID *)clientUuid, &q);
1117 osi_Log4(afsd_logp, "SRXAFSCB_ProbeUuid %s != %s from host 0x%x port %d",
1118 osi_LogSaveString(afsd_logp,p),
1119 osi_LogSaveString(afsd_logp,q),
1125 code = 1; /* failure */
1127 osi_Log2(afsd_logp, "SRXAFSCB_ProbeUuid (success) from host 0x%x port %d",
1134 /* debug interface */
1136 GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
1140 cm_serverRef_t * serverRefp;
1142 cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
1144 *a_name = strdup("");
1148 lock_ObtainRead(&cm_serverLock);
1149 *a_name = strdup(cellp->name);
1151 for ( sn = 0, serverRefp = cellp->vlServersp;
1152 sn < AFSMAXCELLHOSTS && serverRefp;
1153 sn++, serverRefp = serverRefp->next);
1155 a_hosts->serverList_len = sn;
1156 a_hosts->serverList_val = (afs_int32 *)osi_Alloc(sn * sizeof(afs_int32));
1158 for ( sn = 0, serverRefp = cellp->vlServersp;
1159 sn < AFSMAXCELLHOSTS && serverRefp;
1160 sn++, serverRefp = serverRefp->next)
1162 a_hosts->serverList_val[sn] = ntohl(serverRefp->server->addr.sin_addr.s_addr);
1165 lock_ReleaseRead(&cm_serverLock);
1169 /* debug interface */
1171 SRXAFSCB_GetCellByNum(struct rx_call *callp, afs_int32 a_cellnum,
1172 char **a_name, serverList *a_hosts)
1174 struct rx_connection *connp;
1175 struct rx_peer *peerp;
1176 unsigned long host = 0;
1177 unsigned short port = 0;
1183 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1184 host = rx_HostOf(peerp);
1185 port = rx_PortOf(peerp);
1188 osi_Log3(afsd_logp, "SRXAFSCB_GetCellByNum(%d) from host 0x%x port %d",
1189 a_cellnum, ntohl(host), ntohs(port));
1191 a_hosts->serverList_val = 0;
1192 a_hosts->serverList_len = 0;
1195 rc = GetCellCommon(a_cellnum, a_name, a_hosts);
1200 /* debug interface */
1202 SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
1203 struct interfaceAddr *addr,
1204 Capabilities * capabilities)
1207 afs_int32 *dataBuffP;
1208 afs_int32 dataBytes;
1210 struct rx_connection *connp;
1211 struct rx_peer *peerp;
1212 unsigned long host = 0;
1213 unsigned short port = 0;
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_TellMeAboutYourself from host 0x%x port %d",
1227 lock_ObtainRead(&cm_syscfgLock);
1228 if (cm_LanAdapterChangeDetected) {
1229 lock_ConvertRToW(&cm_syscfgLock);
1230 if (cm_LanAdapterChangeDetected) {
1231 /* get network related info */
1232 cm_noIPAddr = CM_MAXINTERFACE_ADDR;
1233 code = syscfg_GetIFInfo(&cm_noIPAddr,
1234 cm_IPAddr, cm_SubnetMask,
1235 cm_NetMtu, cm_NetFlags);
1236 cm_LanAdapterChangeDetected = 0;
1238 lock_ConvertWToR(&cm_syscfgLock);
1241 /* return all network interface addresses */
1242 addr->numberOfInterfaces = cm_noIPAddr;
1243 addr->uuid = cm_data.Uuid;
1244 for ( i=0; i < cm_noIPAddr; i++ ) {
1245 addr->addr_in[i] = cm_IPAddr[i];
1246 addr->subnetmask[i] = cm_SubnetMask[i];
1247 addr->mtu[i] = (rx_mtu == -1 || (rx_mtu != -1 && cm_NetMtu[i] < rx_mtu)) ?
1248 cm_NetMtu[i] : rx_mtu;
1250 lock_ReleaseRead(&cm_syscfgLock);
1252 dataBytes = 1 * sizeof(afs_int32);
1253 dataBuffP = (afs_int32 *) osi_Alloc(dataBytes);
1254 dataBuffP[0] = CLIENT_CAPABILITY_ERRORTRANS;
1255 capabilities->Capabilities_len = dataBytes / sizeof(afs_int32);
1256 capabilities->Capabilities_val = dataBuffP;
1261 /*------------------------------------------------------------------------
1262 * EXPORTED SRXAFSCB_GetServerPrefs
1265 * Routine to list server preferences used by this client.
1268 * a_call : Ptr to Rx call on which this request came in.
1269 * a_index : Input server index
1270 * a_srvr_addr : Output server address (0xffffffff on last server)
1271 * a_srvr_rank : Output server rank
1277 * Nothing interesting.
1281 *------------------------------------------------------------------------*/
1283 int SRXAFSCB_GetServerPrefs(
1284 struct rx_call *callp,
1286 afs_int32 *a_srvr_addr,
1287 afs_int32 *a_srvr_rank)
1289 struct rx_connection *connp;
1290 struct rx_peer *peerp;
1291 unsigned long host = 0;
1292 unsigned short port = 0;
1297 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1298 host = rx_HostOf(peerp);
1299 port = rx_PortOf(peerp);
1302 osi_Log2(afsd_logp, "SRXAFSCB_GetServerPrefs from host 0x%x port %d - not implemented",
1306 *a_srvr_addr = 0xffffffff;
1307 *a_srvr_rank = 0xffffffff;
1312 /*------------------------------------------------------------------------
1313 * EXPORTED SRXAFSCB_GetCellServDB
1316 * Routine to list cells configured for this client
1319 * a_call : Ptr to Rx call on which this request came in.
1320 * a_index : Input cell index
1321 * a_name : Output cell name ("" on last cell)
1322 * a_hosts : Output cell database servers
1328 * Nothing interesting.
1332 *------------------------------------------------------------------------*/
1334 int SRXAFSCB_GetCellServDB(struct rx_call *callp, afs_int32 index, char **a_name,
1335 serverList *a_hosts)
1337 struct rx_connection *connp;
1338 struct rx_peer *peerp;
1339 unsigned long host = 0;
1340 unsigned short port = 0;
1346 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1347 host = rx_HostOf(peerp);
1348 port = rx_PortOf(peerp);
1351 osi_Log2(afsd_logp, "SRXAFSCB_GetCellServDB from host 0x%x port %d - not implemented",
1352 ntohl(host), ntohs(port));
1354 #ifdef AFS_FREELANCE_CLIENT
1355 if (cm_freelanceEnabled && index == 0) {
1356 rc = GetCellCommon(AFS_FAKE_ROOT_CELL_ID, a_name, a_hosts);
1360 rc = GetCellCommon(index+1, a_name, a_hosts);
1365 /*------------------------------------------------------------------------
1366 * EXPORTED SRXAFSCB_GetLocalCell
1369 * Routine to return name of client's local cell
1372 * a_call : Ptr to Rx call on which this request came in.
1373 * a_name : Output cell name
1379 * Nothing interesting.
1383 *------------------------------------------------------------------------*/
1385 int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
1388 struct rx_connection *connp;
1389 struct rx_peer *peerp;
1390 unsigned long host = 0;
1391 unsigned short port = 0;
1396 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1397 host = rx_HostOf(peerp);
1398 port = rx_PortOf(peerp);
1401 osi_Log2(afsd_logp, "SRXAFSCB_GetLocalCell from host 0x%x port %d",
1402 ntohl(host), ntohs(port));
1404 if (cm_data.rootCellp) {
1405 t_name = strdup(cm_data.rootCellp->name);
1407 t_name = (char *)malloc(1);
1417 * afs_MarshallCacheConfig - marshall client cache configuration
1421 * IN callerVersion - the rpc stat version of the caller.
1423 * IN config - client cache configuration.
1425 * OUT ptr - buffer where configuration is marshalled.
1431 static void afs_MarshallCacheConfig(
1432 afs_uint32 callerVersion,
1433 cm_initparams_v1 *config,
1437 * We currently only support version 1.
1439 *(ptr++) = config->nChunkFiles;
1440 *(ptr++) = config->nStatCaches;
1441 *(ptr++) = config->nDataCaches;
1442 *(ptr++) = config->nVolumeCaches;
1443 *(ptr++) = config->firstChunkSize;
1444 *(ptr++) = config->otherChunkSize;
1445 *(ptr++) = config->cacheSize;
1446 *(ptr++) = config->setTime;
1447 *(ptr++) = config->memCache;
1452 /*------------------------------------------------------------------------
1453 * EXPORTED SRXAFSCB_GetCacheConfig
1456 * Routine to return parameters used to initialize client cache.
1457 * Client may request any format version. Server may not return
1458 * format version greater than version requested by client.
1461 * a_call: Ptr to Rx call on which this request came in.
1462 * callerVersion: Data format version desired by the client.
1463 * serverVersion: Data format version of output data.
1464 * configCount: Number bytes allocated for output data.
1465 * config: Client cache configuration.
1471 * Nothing interesting.
1475 *------------------------------------------------------------------------*/
1477 int SRXAFSCB_GetCacheConfig(struct rx_call *callp,
1478 afs_uint32 callerVersion,
1479 afs_uint32 *serverVersion,
1480 afs_uint32 *configCount,
1481 cacheConfig *config)
1483 afs_uint32 *t_config;
1485 extern cm_initparams_v1 cm_initParams;
1486 struct rx_connection *connp;
1487 struct rx_peer *peerp;
1488 unsigned long host = 0;
1489 unsigned short port = 0;
1494 if ((connp = rx_ConnectionOf(callp)) && (peerp = rx_PeerOf(connp))) {
1495 host = rx_HostOf(peerp);
1496 port = rx_PortOf(peerp);
1499 osi_Log2(afsd_logp, "SRXAFSCB_GetCacheConfig from host 0x%x port %d - version 1 only",
1500 ntohl(host), ntohs(port));
1503 * Currently only support version 1
1505 allocsize = sizeof(cm_initparams_v1);
1506 t_config = (afs_uint32 *)malloc(allocsize);
1508 afs_MarshallCacheConfig(callerVersion, &cm_initParams, t_config);
1510 *serverVersion = AFS_CLIENT_RETRIEVAL_FIRST_EDITION;
1513 #define SIZE_MAX UINT_MAX
1515 osi_assertx(allocsize < SIZE_MAX, "allocsize >= SIZE_MAX");
1517 *configCount = (afs_uint32)allocsize;
1518 config->cacheConfig_val = t_config;
1519 config->cacheConfig_len = (*configCount)/sizeof(afs_uint32);
1524 /* called by afsd without any locks to initialize this module */
1525 void cm_InitCallback(void)
1527 lock_InitializeRWLock(&cm_callbackLock, "cm_callbackLock", LOCK_HIERARCHY_CALLBACK_GLOBAL);
1528 cm_activeCallbackGrantingCalls = 0;
1531 /* called with locked scp; tells us whether we've got a callback.
1532 * Expirations are checked by a background daemon so as to make
1533 * this function as inexpensive as possible
1535 int cm_HaveCallback(cm_scache_t *scp)
1537 #ifdef AFS_FREELANCE_CLIENT
1538 // yj: we handle callbacks specially for callbacks on the root directory
1539 // Since it's local, we almost always say that we have callback on it
1540 // The only time we send back a 0 is if we're need to initialize or
1541 // reinitialize the fake directory
1543 // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
1544 // cm_fakeGettingCallback is 1 if we're in the process of initialization and
1545 // hence should return false. it's 0 otherwise
1546 // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
1547 // if the fake directory is loaded and this is the first time cm_HaveCallback
1548 // is called since then. We return false in this case to allow cm_GetCallback
1549 // to be called because cm_GetCallback has some initialization work to do.
1550 // If cm_fakeDirCallback is 2, then it means that the fake directory is in
1551 // good shape and we simply return true, provided no change is detected.
1554 if (cm_freelanceEnabled &&
1555 scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1556 lock_ObtainMutex(&cm_Freelance_Lock);
1557 fdc = cm_fakeDirCallback;
1558 fgc = cm_fakeGettingCallback;
1559 lock_ReleaseMutex(&cm_Freelance_Lock);
1561 if (fdc==1) { // first call since init
1563 } else if (fdc==2 && !fgc) { // we're in good shape
1564 if (cm_getLocalMountPointChange()) { // check for changes
1565 cm_clearLocalMountPointChange(); // clear the changefile
1566 lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
1567 cm_reInitLocalMountPoints(); // start reinit
1568 lock_ObtainWrite(&scp->rw); // now get the lock back
1571 return (cm_data.fakeDirVersion == scp->dataVersion);
1577 if (scp->cbServerp != NULL) {
1579 } else if (cm_OfflineROIsValid) {
1580 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1582 switch (cm_GetVolumeStatus(volp, scp->fid.volume)) {
1598 /* need to detect a broken callback that races with our obtaining a callback.
1599 * Need to be able to do this even if we don't know the file ID of the file
1600 * we're breaking the callback on at the time we start the acquisition of the
1601 * callback (as in the case where we are creating a file).
1603 * So, we start by writing down the count of the # of callbacks we've received
1604 * so far, and bumping a global counter of the # of callback granting calls
1605 * outstanding (all done under cm_callbackLock).
1607 * When we're back from the call, we look at all of the callback revokes with
1608 * counter numbers greater than the one we recorded in our caller's structure,
1609 * and replay those that are higher than when we started the call.
1611 * We free all the structures in the queue when the count of the # of outstanding
1612 * callback-granting calls drops to zero.
1614 * We call this function with the scp locked, too, but in its current implementation,
1615 * this knowledge is not used.
1617 void cm_StartCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp)
1619 lock_ObtainWrite(&cm_callbackLock);
1620 cbrp->callbackCount = cm_callbackCount;
1621 cm_activeCallbackGrantingCalls++;
1622 cbrp->startTime = time(NULL);
1623 cbrp->serverp = NULL;
1624 lock_ReleaseWrite(&cm_callbackLock);
1627 /* Called at the end of a callback-granting call, to remove the callback
1628 * info from the scache entry, if necessary.
1630 * Called with scp write locked, so we can discard the callbacks easily with
1631 * this locking hierarchy.
1633 void cm_EndCallbackGrantingCall(cm_scache_t *scp, cm_callbackRequest_t *cbrp,
1634 AFSCallBack *cbp, long flags)
1636 cm_racingRevokes_t *revp; /* where we are */
1637 cm_racingRevokes_t *nrevp; /* where we'll be next */
1639 cm_server_t * serverp = NULL;
1640 int discardScp = 0, discardVolCB = 0;
1642 lock_ObtainWrite(&cm_callbackLock);
1643 if (flags & CM_CALLBACK_MAINTAINCOUNT) {
1644 osi_assertx(cm_activeCallbackGrantingCalls > 0,
1645 "CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1648 osi_assertx(cm_activeCallbackGrantingCalls-- > 0,
1649 "!CM_CALLBACK_MAINTAINCOUNT && cm_activeCallbackGrantingCalls == 0");
1651 if (cm_activeCallbackGrantingCalls == 0)
1656 /* record the callback; we'll clear it below if we really lose it */
1659 if (scp->cbServerp != cbrp->serverp) {
1660 serverp = scp->cbServerp;
1662 cm_GetServer(cbrp->serverp);
1663 scp->cbServerp = cbrp->serverp;
1666 serverp = cbrp->serverp;
1668 scp->cbExpires = cbrp->startTime + cbp->ExpirationTime;
1671 serverp = cbrp->serverp;
1674 cbrp->serverp = NULL;
1677 /* a callback was actually revoked during our granting call, so
1678 * run down the list of revoked fids, looking for ours.
1679 * If activeCallbackGrantingCalls is zero, free the elements, too.
1681 * May need to go through entire list just to do the freeing.
1683 for (revp = cm_racingRevokesp; revp; revp = nrevp) {
1684 nrevp = (cm_racingRevokes_t *) osi_QNext(&revp->q);
1685 /* if this callback came in later than when we started the
1686 * callback-granting call, and if this fid is the right fid,
1687 * then clear the callback.
1689 if (scp && cbrp && cbrp->callbackCount != cm_callbackCount
1690 && revp->callbackCount > cbrp->callbackCount
1691 && (( scp->fid.volume == revp->fid.volume &&
1692 scp->fid.vnode == revp->fid.vnode &&
1693 scp->fid.unique == revp->fid.unique)
1695 ((revp->flags & CM_RACINGFLAG_CANCELVOL) &&
1696 scp->fid.volume == revp->fid.volume)
1698 ((revp->flags & CM_RACINGFLAG_CANCELALL) &&
1699 (revp->fid.cell == 0 || scp->fid.cell == revp->fid.cell)))) {
1700 /* this one matches */
1702 "Racing revoke scp 0x%p old cbc %d rev cbc %d cur cbc %d",
1704 cbrp->callbackCount, revp->callbackCount,
1707 if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
1708 (revp->flags & CM_RACINGFLAG_ALL)) {
1709 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1711 volp->cbExpiresRO = 0;
1720 /* if we freed the list, zap the pointer to it */
1722 cm_racingRevokesp = NULL;
1724 lock_ReleaseWrite(&cm_callbackLock);
1727 cm_DiscardSCache(scp);
1728 lock_ReleaseWrite(&scp->rw);
1729 cm_CallbackNotifyChange(scp);
1730 lock_ObtainWrite(&scp->rw);
1732 if (scp && scp->flags & CM_SCACHEFLAG_PURERO) {
1733 cm_volume_t * volp = cm_GetVolumeByFID(&scp->fid);
1735 volp->cbExpiresRO = scp->cbExpires;
1742 lock_ObtainWrite(&cm_serverLock);
1743 cm_FreeServer(serverp);
1744 lock_ReleaseWrite(&cm_serverLock);
1748 /* if flags is 1, we want to force the code to make one call, anyway.
1749 * called with locked scp; returns with same.
1751 long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
1752 struct cm_req *reqp, long flags)
1755 cm_conn_t *connp = NULL;
1756 AFSFetchStatus afsStatus;
1758 AFSCallBack callback;
1760 cm_callbackRequest_t cbr;
1763 struct rx_connection * rxconnp = NULL;
1764 int syncop_done = 0;
1766 osi_Log4(afsd_logp, "GetCallback scp 0x%p cell %d vol %d flags %lX",
1767 scp, scp->fid.cell, scp->fid.volume, flags);
1769 #ifdef AFS_FREELANCE_CLIENT
1770 // The case where a callback is needed on /afs is handled
1771 // specially. We need to fetch the status by calling
1772 // cm_MergeStatus and mark that cm_fakeDirCallback is 2
1773 if (cm_freelanceEnabled) {
1774 if (scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
1775 scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
1776 // Start by indicating that we're in the process
1777 // of fetching the callback
1778 lock_ObtainMutex(&cm_Freelance_Lock);
1779 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=1");
1780 cm_fakeGettingCallback = 1;
1781 lock_ReleaseMutex(&cm_Freelance_Lock);
1783 // Fetch the status info
1784 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1786 // Indicate that the callback is not done
1787 lock_ObtainMutex(&cm_Freelance_Lock);
1788 osi_Log0(afsd_logp,"cm_getGetCallback fakeDirCallback=2");
1789 cm_fakeDirCallback = 2;
1791 // Indicate that we're no longer fetching the callback
1792 osi_Log0(afsd_logp,"cm_getGetCallback fakeGettingCallback=0");
1793 cm_fakeGettingCallback = 0;
1794 lock_ReleaseMutex(&cm_Freelance_Lock);
1799 #endif /* AFS_FREELANCE_CLIENT */
1801 mustCall = (flags & 1);
1802 cm_AFSFidFromFid(&tfid, &scp->fid);
1804 if (!mustCall && cm_HaveCallback(scp))
1807 /* turn off mustCall, since it has now forced us past the check above */
1810 /* otherwise, we have to make an RPC to get the status */
1812 code = cm_SyncOp(scp, NULL, userp, reqp, 0,
1813 CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1818 cm_StartCallbackGrantingCall(scp, &cbr);
1820 lock_ReleaseWrite(&scp->rw);
1822 /* now make the RPC */
1823 osi_Log4(afsd_logp, "CALL FetchStatus scp 0x%p vol %u vn %u uniq %u",
1824 scp, sfid.volume, sfid.vnode, sfid.unique);
1826 code = cm_ConnFromFID(&sfid, userp, reqp, &connp);
1830 rxconnp = cm_GetRxConn(connp);
1831 code = RXAFS_FetchStatus(rxconnp, &tfid,
1832 &afsStatus, &callback, &volSync);
1833 rx_PutConnection(rxconnp);
1835 } while (cm_Analyze(connp, userp, reqp, &sfid, &volSync, NULL,
1837 code = cm_MapRPCError(code, reqp);
1839 osi_Log4(afsd_logp, "CALL FetchStatus FAILURE code 0x%x scp 0x%p vol %u vn %u",
1840 code, scp, scp->fid.volume, scp->fid.vnode);
1842 osi_Log4(afsd_logp, "CALL FetchStatus SUCCESS scp 0x%p vol %u vn %u uniq %u",
1843 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1845 lock_ObtainWrite(&scp->rw);
1847 cm_EndCallbackGrantingCall(scp, &cbr, &callback, 0);
1848 cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, 0);
1850 cm_EndCallbackGrantingCall(NULL, &cbr, NULL, 0);
1853 /* if we got an error, return to caller */
1859 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS | CM_SCACHESYNC_GETCALLBACK);
1862 osi_Log2(afsd_logp, "GetCallback Failed code 0x%x scp 0x%p -->",code, scp);
1863 osi_Log4(afsd_logp, " cell %u vol %u vn %u uniq %u",
1864 scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1866 osi_Log3(afsd_logp, "GetCallback Complete scp 0x%p cell %d vol %d",
1867 scp, scp->fid.cell, scp->fid.volume);
1874 /* called with cm_scacheLock held */
1875 long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
1877 cm_vol_state_t *statep;
1879 afs_uint32 volID = scp->fid.volume;
1880 cm_serverRef_t *tsrp;
1885 if (scp->cbServerp == NULL)
1888 volp = cm_GetVolumeByFID(&scp->fid);
1892 statep = cm_VolumeStateByID(volp, volID);
1894 if (statep->state == vl_online)
1897 for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
1898 if (tsrp->status == srv_deleted)
1900 if (tsrp->server == scp->cbServerp)
1902 if (tsrp->server->downTime > *downTime)
1903 *downTime = tsrp->server->downTime;
1906 /* if the cbServerp does not match the current volume server list
1907 * we report the callback server as up so the callback can be
1910 return(found ? 0 : 1);
1913 /* called periodically by cm_daemon to shut down use of expired callbacks */
1914 void cm_CheckCBExpiration(void)
1918 time_t now, downTime;
1920 osi_Log0(afsd_logp, "CheckCBExpiration");
1923 lock_ObtainWrite(&cm_scacheLock);
1924 for (i=0; i<cm_data.scacheHashTableSize; i++) {
1925 for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
1927 if (scp->flags & CM_SCACHEFLAG_PURERO) {
1928 cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
1930 if (volp->cbExpiresRO > scp->cbExpires &&
1933 scp->cbExpires = volp->cbExpiresRO;
1938 if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
1939 (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
1941 cm_HoldSCacheNoLock(scp);
1942 lock_ReleaseWrite(&cm_scacheLock);
1944 osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
1945 scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1946 lock_ObtainWrite(&scp->rw);
1947 cm_DiscardSCache(scp);
1948 lock_ReleaseWrite(&scp->rw);
1949 cm_CallbackNotifyChange(scp);
1951 lock_ObtainWrite(&cm_scacheLock);
1952 cm_ReleaseSCacheNoLock(scp);
1956 lock_ReleaseWrite(&cm_scacheLock);
1958 osi_Log0(afsd_logp, "CheckCBExpiration Complete");
1963 cm_GiveUpAllCallbacks(cm_server_t *tsp, afs_int32 markDown)
1967 struct rx_connection * rxconnp;
1969 if ((tsp->type == CM_SERVER_FILE) && !(tsp->flags & CM_SERVERFLAG_DOWN))
1971 code = cm_ConnByServer(tsp, cm_rootUserp, &connp);
1973 rxconnp = cm_GetRxConn(connp);
1974 rx_SetConnDeadTime(rxconnp, 10);
1975 code = RXAFS_GiveUpAllCallBacks(rxconnp);
1976 rx_SetConnDeadTime(rxconnp, ConnDeadtimeout);
1977 rx_PutConnection(rxconnp);
1981 cm_server_vols_t * tsrvp;
1985 cm_ForceNewConnections(tsp);
1987 lock_ObtainMutex(&tsp->mx);
1988 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1989 tsp->flags |= CM_SERVERFLAG_DOWN;
1990 tsp->downTime = time(NULL);
1992 /* Now update the volume status */
1993 for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
1994 for (i=0; i<NUM_SERVER_VOLS; i++) {
1995 if (tsrvp->ids[i] != 0) {
1999 lock_ReleaseMutex(&tsp->mx);
2000 code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
2001 &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
2002 lock_ObtainMutex(&tsp->mx);
2004 cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
2010 lock_ReleaseMutex(&tsp->mx);
2016 cm_GiveUpAllCallbacksAllServers(afs_int32 markDown)
2020 if (!cm_giveUpAllCBs)
2023 lock_ObtainWrite(&cm_serverLock);
2024 for (tsp = cm_allServersp; tsp; tsp = tsp->allNextp) {
2025 cm_GetServerNoLock(tsp);
2026 lock_ReleaseWrite(&cm_serverLock);
2027 cm_GiveUpAllCallbacks(tsp, markDown);
2028 lock_ObtainWrite(&cm_serverLock);
2029 cm_PutServerNoLock(tsp);
2031 lock_ReleaseWrite(&cm_serverLock);