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
19 * afs_FlushActiveVcaches
22 * afs_WriteVCacheDiscon
40 #include <afsconfig.h>
41 #include "afs/param.h"
43 #include "afs/sysincludes.h" /*Standard vendor system headers */
44 #include "afsincludes.h" /*AFS-based standard headers */
45 #include "afs/afs_stats.h"
46 #include "afs/afs_cbqueue.h"
47 #include "afs/afs_osidnlc.h"
49 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
50 afs_int32 afs_vcount = 0; /* number of vcache in use now */
58 #endif /* AFS_SGI64_ENV */
60 /* Exported variables */
61 afs_rwlock_t afs_xvcdirty; /*Lock: discon vcache dirty list mgmt */
62 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries */
63 afs_rwlock_t afs_xvreclaim; /*Lock: entries reclaimed, not on free list */
64 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks */
65 #if !defined(AFS_LINUX22_ENV)
66 static struct vcache *freeVCList; /*Free list for stat cache entries */
67 struct vcache *ReclaimedVCList; /*Reclaimed list for stat entries */
68 static struct vcache *Initial_freeVCList; /*Initial list for above */
70 struct afs_q VLRU; /*vcache LRU */
71 afs_int32 vcachegen = 0;
72 unsigned int afs_paniconwarn = 0;
73 struct vcache *afs_vhashT[VCSIZE];
74 struct afs_q afs_vhashTV[VCSIZE];
75 static struct afs_cbr *afs_cbrHashT[CBRSIZE];
76 afs_int32 afs_bulkStatsLost;
77 int afs_norefpanic = 0;
80 /* Disk backed vcache definitions
81 * Both protected by xvcache */
82 static int afs_nextVcacheSlot = 0;
83 static struct afs_slotlist *afs_freeSlotList = NULL;
85 /* Forward declarations */
86 static afs_int32 afs_QueueVCB(struct vcache *avc, int *slept);
89 * Generate an index into the hash table for a given Fid.
91 * \return The hash value.
94 afs_HashCBRFid(struct AFSFid *fid)
96 return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE;
100 * Insert a CBR entry into the hash table.
101 * Must be called with afs_xvcb held.
106 afs_InsertHashCBR(struct afs_cbr *cbr)
108 int slot = afs_HashCBRFid(&cbr->fid);
110 cbr->hash_next = afs_cbrHashT[slot];
111 if (afs_cbrHashT[slot])
112 afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next;
114 cbr->hash_pprev = &afs_cbrHashT[slot];
115 afs_cbrHashT[slot] = cbr;
120 * Flush the given vcache entry.
123 * afs_xvcache lock must be held for writing upon entry to
124 * prevent people from changing the vrefCount field, and to
125 * protect the lruq and hnext fields.
126 * LOCK: afs_FlushVCache afs_xvcache W
127 * REFCNT: vcache ref count must be zero on entry except for osf1
128 * RACE: lock is dropped and reobtained, permitting race in caller
130 * \param avc Pointer to vcache entry to flush.
131 * \param slept Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
135 afs_FlushVCache(struct vcache *avc, int *slept)
136 { /*afs_FlushVCache */
139 struct vcache **uvc, *wvc;
141 /* NOTE: We must have nothing drop afs_xvcache until we have removed all
142 * possible references to this vcache. This means all hash tables, queues,
146 AFS_STATCNT(afs_FlushVCache);
147 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
148 ICL_TYPE_INT32, avc->f.states);
150 code = osi_VM_FlushVCache(avc);
154 if (avc->f.states & CVFlushed) {
158 #if !defined(AFS_LINUX22_ENV)
159 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
160 refpanic("LRU vs. Free inconsistency");
163 avc->f.states |= CVFlushed;
164 /* pull the entry out of the lruq and put it on the free list */
165 QRemove(&avc->vlruq);
167 /* keep track of # of files that we bulk stat'd, but never used
168 * before they got recycled.
170 if (avc->f.states & CBulkStat)
173 /* remove entry from the hash chain */
174 i = VCHash(&avc->f.fid);
175 uvc = &afs_vhashT[i];
176 for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
184 /* remove entry from the volume hash table */
185 QRemove(&avc->vhashq);
187 #if defined(AFS_LINUX26_ENV)
189 struct pagewriter *pw, *store;
190 struct list_head tofree;
192 INIT_LIST_HEAD(&tofree);
193 spin_lock(&avc->pagewriter_lock);
194 list_for_each_entry_safe(pw, store, &avc->pagewriters, link) {
196 /* afs_osi_Free may sleep so we need to defer it */
197 list_add_tail(&pw->link, &tofree);
199 spin_unlock(&avc->pagewriter_lock);
200 list_for_each_entry_safe(pw, store, &tofree, link) {
202 afs_osi_Free(pw, sizeof(struct pagewriter));
208 osi_FreeSmallSpace(avc->mvid);
209 avc->mvid = (struct VenusFid *)0;
211 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
212 avc->linkData = NULL;
214 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
215 /* OK, there are no internal vrefCounts, so there shouldn't
216 * be any more refs here. */
218 #ifdef AFS_DARWIN80_ENV
219 vnode_clearfsnode(AFSTOV(avc));
220 vnode_removefsref(AFSTOV(avc));
222 avc->v->v_data = NULL; /* remove from vnode */
224 AFSTOV(avc) = NULL; /* also drop the ptr to vnode */
227 #ifdef AFS_SUN510_ENV
228 /* As we use private vnodes, cleanup is up to us */
229 vn_reinit(AFSTOV(avc));
231 afs_FreeAllAxs(&(avc->Access));
232 ObtainWriteLock(&afs_xcbhash, 460);
233 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
234 avc->f.states &= ~(CStatd | CUnique);
235 ReleaseWriteLock(&afs_xcbhash);
236 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
237 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
239 osi_dnlc_purgevp(avc);
241 /* By this point, the vcache has been removed from all global structures
242 * via which someone could try to use the vcache. It is okay to drop
243 * afs_xvcache at this point (if *slept is set). */
245 if (!afs_shuttingdown)
246 afs_QueueVCB(avc, slept);
249 * Next, keep track of which vnodes we've deleted for create's
250 * optimistic synchronization algorithm
253 if (avc->f.fid.Fid.Vnode & 1)
259 #if !defined(AFS_LINUX22_ENV)
260 /* put the entry in the free list */
261 avc->nextfree = freeVCList;
263 if (avc->vlruq.prev || avc->vlruq.next) {
264 refpanic("LRU vs. Free inconsistency");
266 avc->f.states |= CVFlushed;
268 /* This should put it back on the vnode free list since usecount is 1 */
270 if (VREFCOUNT_GT(avc,0)) {
271 AFS_RELE(AFSTOV(avc));
272 afs_stats_cmperf.vcacheXAllocs--;
274 if (afs_norefpanic) {
275 afs_warn("flush vc refcnt < 1");
278 osi_Panic("flush vc refcnt < 1");
280 #endif /* AFS_LINUX22_ENV */
285 } /*afs_FlushVCache */
289 * The core of the inactive vnode op for all but IRIX.
295 afs_InactiveVCache(struct vcache *avc, afs_ucred_t *acred)
297 AFS_STATCNT(afs_inactive);
298 if (avc->f.states & CDirty) {
299 /* we can't keep trying to push back dirty data forever. Give up. */
300 afs_InvalidateAllSegments(avc); /* turns off dirty bit */
302 avc->f.states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
303 avc->f.states &= ~CDirty; /* Turn it off */
304 if (avc->f.states & CUnlinked) {
305 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
306 avc->f.states |= CUnlinkedDel;
309 afs_remunlink(avc, 1); /* ignore any return code */
316 * Allocate a callback return structure from the
317 * free list and return it.
319 * Environment: The alloc and free routines are both called with the afs_xvcb lock
320 * held, so we don't have to worry about blocking in osi_Alloc.
322 * \return The allocated afs_cbr.
324 static struct afs_cbr *afs_cbrSpace = 0;
325 /* if alloc limit below changes, fix me! */
326 static struct afs_cbr *afs_cbrHeads[16];
333 while (!afs_cbrSpace) {
334 if (afs_stats_cmperf.CallBackAlloced >= sizeof(afs_cbrHeads)/sizeof(afs_cbrHeads[0])) {
335 /* don't allocate more than 16 * AFS_NCBRS for now */
337 afs_stats_cmperf.CallBackFlushes++;
340 tsp = afs_osi_Alloc(AFS_NCBRS * sizeof(struct afs_cbr));
341 osi_Assert(tsp != NULL);
342 for (i = 0; i < AFS_NCBRS - 1; i++) {
343 tsp[i].next = &tsp[i + 1];
345 tsp[AFS_NCBRS - 1].next = 0;
347 afs_cbrHeads[afs_stats_cmperf.CallBackAlloced] = tsp;
348 afs_stats_cmperf.CallBackAlloced++;
352 afs_cbrSpace = tsp->next;
357 * Free a callback return structure, removing it from all lists.
359 * Environment: the xvcb lock is held over these calls.
361 * \param asp The address of the structure to free.
366 afs_FreeCBR(struct afs_cbr *asp)
368 *(asp->pprev) = asp->next;
370 asp->next->pprev = asp->pprev;
372 *(asp->hash_pprev) = asp->hash_next;
374 asp->hash_next->hash_pprev = asp->hash_pprev;
376 asp->next = afs_cbrSpace;
382 FlushAllVCBs(int nconns, struct rx_connection **rxconns,
383 struct afs_conn **conns)
388 results = afs_osi_Alloc(nconns * sizeof (afs_int32));
389 osi_Assert(results != NULL);
392 multi_Rx(rxconns,nconns)
394 multi_RXAFS_GiveUpAllCallBacks();
395 results[multi_i] = multi_error;
400 * Freeing the CBR will unlink it from the server's CBR list
401 * do it here, not in the loop, because a dynamic CBR will call
402 * into the memory management routines.
404 for ( i = 0 ; i < nconns ; i++ ) {
405 if (results[i] == 0) {
406 /* Unchain all of them */
407 while (conns[i]->parent->srvr->server->cbrs)
408 afs_FreeCBR(conns[i]->parent->srvr->server->cbrs);
411 afs_osi_Free(results, nconns * sizeof(afs_int32));
415 * Flush all queued callbacks to all servers.
417 * Environment: holds xvcb lock over RPC to guard against race conditions
418 * when a new callback is granted for the same file later on.
420 * \return 0 for success.
423 afs_FlushVCBs(afs_int32 lockit)
425 struct AFSFid *tfids;
426 struct AFSCallBack callBacks[1];
427 struct AFSCBFids fidArray;
428 struct AFSCBs cbArray;
430 struct afs_cbr *tcbrp;
434 struct vrequest *treq = NULL;
436 int safety1, safety2, safety3;
439 if (AFS_IS_DISCONNECTED)
442 if ((code = afs_CreateReq(&treq, afs_osi_credp)))
444 treq->flags |= O_NONBLOCK;
445 tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
446 osi_Assert(tfids != NULL);
449 ObtainWriteLock(&afs_xvcb, 273);
452 * First, attempt a multi across everything, all addresses
453 * for all servers we know of.
457 afs_LoopServers(AFS_LS_ALL, NULL, 0, FlushAllVCBs, NULL);
459 ObtainReadLock(&afs_xserver);
460 for (i = 0; i < NSERVERS; i++) {
461 for (safety1 = 0, tsp = afs_servers[i];
462 tsp && safety1 < afs_totalServers + 10;
463 tsp = tsp->next, safety1++) {
465 if (tsp->cbrs == (struct afs_cbr *)0)
468 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
469 * and make an RPC, over and over again.
471 tcount = 0; /* number found so far */
472 for (safety2 = 0; safety2 < afs_cacheStats; safety2++) {
473 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
474 struct rx_connection *rxconn;
475 /* if buffer is full, or we've queued all we're going
476 * to from this server, we should flush out the
479 fidArray.AFSCBFids_len = tcount;
480 fidArray.AFSCBFids_val = (struct AFSFid *)tfids;
481 cbArray.AFSCBs_len = 1;
482 cbArray.AFSCBs_val = callBacks;
483 memset(&callBacks[0], 0, sizeof(callBacks[0]));
484 callBacks[0].CallBackType = CB_EXCLUSIVE;
485 for (safety3 = 0; safety3 < AFS_MAXHOSTS * 2; safety3++) {
486 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
487 tsp->cell->cellNum, treq, 0,
488 SHARED_LOCK, 0, &rxconn);
491 (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
494 RXAFS_GiveUpCallBacks(rxconn, &fidArray,
501 (tc, rxconn, code, 0, treq,
502 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK,
507 /* ignore return code, since callbacks may have
508 * been returned anyway, we shouldn't leave them
509 * around to be returned again.
511 * Next, see if we are done with this server, and if so,
512 * break to deal with the next one.
518 /* if to flush full buffer */
519 /* if we make it here, we have an entry at the head of cbrs,
520 * which we should copy to the file ID array and then free.
523 tfids[tcount++] = tcbrp->fid;
525 /* Freeing the CBR will unlink it from the server's CBR list */
527 } /* while loop for this one server */
528 if (safety2 > afs_cacheStats) {
529 afs_warn("possible internal error afs_flushVCBs (%d)\n",
532 } /* for loop for this hash chain */
533 } /* loop through all hash chains */
534 if (safety1 > afs_totalServers + 2) {
536 ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n",
537 safety1, afs_totalServers + 2);
539 osi_Panic("afs_flushVCBS safety1");
542 ReleaseReadLock(&afs_xserver);
544 ReleaseWriteLock(&afs_xvcb);
545 afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
546 afs_DestroyReq(treq);
551 * Queue a callback on the given fid.
554 * Locks the xvcb lock.
555 * Called when the xvcache lock is already held.
556 * RACE: afs_xvcache may be dropped and reacquired
558 * \param avc vcache entry
559 * \param slep Set to 1 if we dropped afs_xvcache
560 * \return 1 if queued, 0 otherwise
564 afs_QueueVCB(struct vcache *avc, int *slept)
568 struct afs_cbr *tcbp;
571 AFS_STATCNT(afs_QueueVCB);
573 ObtainWriteLock(&afs_xvcb, 274);
575 /* we can't really give back callbacks on RO files, since the
576 * server only tracks them on a per-volume basis, and we don't
577 * know whether we still have some other files from the same
579 if (!((avc->f.states & CRO) == 0 && avc->callback)) {
583 /* The callback is really just a struct server ptr. */
584 tsp = (struct server *)(avc->callback);
587 /* If we don't have CBR space, AllocCBR may block or hit the net for
588 * clearing up CBRs. Hitting the net may involve a fileserver
589 * needing to contact us, so we must drop xvcache so we don't block
590 * those requests from going through. */
591 reacquire = *slept = 1;
592 ReleaseWriteLock(&afs_xvcache);
595 /* we now have a pointer to the server, so we just allocate
596 * a queue entry and queue it.
598 tcbp = afs_AllocCBR();
599 tcbp->fid = avc->f.fid.Fid;
601 tcbp->next = tsp->cbrs;
603 tsp->cbrs->pprev = &tcbp->next;
606 tcbp->pprev = &tsp->cbrs;
608 afs_InsertHashCBR(tcbp);
612 /* now release locks and return */
613 ReleaseWriteLock(&afs_xvcb);
616 /* make sure this is after dropping xvcb, for locking order */
617 ObtainWriteLock(&afs_xvcache, 279);
624 * Remove a queued callback for a given Fid.
627 * Locks xvcb and xserver locks.
628 * Typically called with xdcache, xvcache and/or individual vcache
631 * \param afid The fid we want cleansed of queued callbacks.
636 afs_RemoveVCB(struct VenusFid *afid)
639 struct afs_cbr *cbr, *ncbr;
641 AFS_STATCNT(afs_RemoveVCB);
642 ObtainWriteLock(&afs_xvcb, 275);
644 slot = afs_HashCBRFid(&afid->Fid);
645 ncbr = afs_cbrHashT[slot];
649 ncbr = cbr->hash_next;
651 if (afid->Fid.Volume == cbr->fid.Volume &&
652 afid->Fid.Vnode == cbr->fid.Vnode &&
653 afid->Fid.Unique == cbr->fid.Unique) {
658 ReleaseWriteLock(&afs_xvcb);
662 afs_FlushReclaimedVcaches(void)
664 #if !defined(AFS_LINUX22_ENV)
667 struct vcache *tmpReclaimedVCList = NULL;
669 ObtainWriteLock(&afs_xvreclaim, 76);
670 while (ReclaimedVCList) {
671 tvc = ReclaimedVCList; /* take from free list */
672 ReclaimedVCList = tvc->nextfree;
673 tvc->nextfree = NULL;
674 code = afs_FlushVCache(tvc, &fv_slept);
676 /* Ok, so, if we got code != 0, uh, wtf do we do? */
677 /* Probably, build a temporary list and then put all back when we
678 get to the end of the list */
679 /* This is actually really crappy, but we need to not leak these.
680 We probably need a way to be smarter about this. */
681 tvc->nextfree = tmpReclaimedVCList;
682 tmpReclaimedVCList = tvc;
683 /* printf("Reclaim list flush %lx failed: %d\n", (unsigned long) tvc, code); */
685 if (tvc->f.states & (CVInit
686 #ifdef AFS_DARWIN80_ENV
690 tvc->f.states &= ~(CVInit
691 #ifdef AFS_DARWIN80_ENV
695 afs_osi_Wakeup(&tvc->f.states);
698 if (tmpReclaimedVCList)
699 ReclaimedVCList = tmpReclaimedVCList;
701 ReleaseWriteLock(&afs_xvreclaim);
706 afs_PostPopulateVCache(struct vcache *avc, struct VenusFid *afid, int seq)
709 * The proper value for mvstat (for root fids) is setup by the caller.
712 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
715 if (afs_globalVFS == 0)
716 osi_Panic("afs globalvfs");
718 osi_PostPopulateVCache(avc);
721 osi_dnlc_purgedp(avc); /* this may be overkill */
722 memset(&(avc->callsort), 0, sizeof(struct afs_q));
724 avc->f.states &=~ CVInit;
726 avc->f.states |= CBulkFetching;
727 avc->f.m.Length = seq;
729 afs_osi_Wakeup(&avc->f.states);
733 afs_ShakeLooseVCaches(afs_int32 anumber)
737 struct afs_q *tq, *uq;
738 int fv_slept, defersleep = 0;
740 afs_int32 target = anumber;
747 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
750 if (tvc->f.states & CVFlushed) {
751 refpanic("CVFlushed on VLRU");
752 } else if (i++ > limit) {
753 afs_warn("afs_ShakeLooseVCaches: i %d limit %d afs_vcount %d afs_maxvcount %d\n",
754 (int)i, limit, (int)afs_vcount, (int)afs_maxvcount);
755 refpanic("Found too many AFS vnodes on VLRU (VLRU cycle?)");
756 } else if (QNext(uq) != tq) {
757 refpanic("VLRU inconsistent");
758 } else if (tvc->f.states & CVInit) {
763 if (osi_TryEvictVCache(tvc, &fv_slept, defersleep))
769 goto retry; /* start over - may have raced. */
772 if (anumber && !defersleep) {
779 if (!afsd_dynamic_vcaches && anumber == target) {
780 afs_warn("afs_ShakeLooseVCaches: warning none freed, using %d of %d\n",
781 afs_vcount, afs_maxvcount);
787 /* Alloc new vnode. */
789 static struct vcache *
790 afs_AllocVCache(void)
794 tvc = osi_NewVnode();
799 if (afsd_dynamic_vcaches && afs_maxvcount < afs_vcount) {
800 afs_maxvcount = afs_vcount;
801 /*printf("peak vnodes: %d\n", afs_maxvcount);*/
804 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
806 /* If we create a new inode, we either give it a new slot number,
807 * or if one's available, use a slot number from the slot free list
809 if (afs_freeSlotList != NULL) {
810 struct afs_slotlist *tmp;
812 tvc->diskSlot = afs_freeSlotList->slot;
813 tmp = afs_freeSlotList;
814 afs_freeSlotList = tmp->next;
815 afs_osi_Free(tmp, sizeof(struct afs_slotlist));
817 tvc->diskSlot = afs_nextVcacheSlot++;
823 /* Pre populate a newly allocated vcache. On platforms where the actual
824 * vnode is attached to the vcache, this function is called before attachment,
825 * therefore it cannot perform any actions on the vnode itself */
828 afs_PrePopulateVCache(struct vcache *avc, struct VenusFid *afid,
829 struct server *serverp) {
832 slot = avc->diskSlot;
834 osi_PrePopulateVCache(avc);
836 avc->diskSlot = slot;
837 QZero(&avc->metadirty);
839 AFS_RWLOCK_INIT(&avc->lock, "vcache lock");
842 avc->linkData = NULL;
845 avc->execsOrWriters = 0;
847 avc->f.states = CVInit;
848 avc->last_looker = 0;
850 avc->asynchrony = -1;
854 avc->f.truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
855 hzero(avc->f.m.DataVersion); /* in case we copy it into flushDV */
857 avc->callback = serverp; /* to minimize chance that clear
860 #if defined(AFS_CACHE_BYPASS)
861 avc->cachingStates = 0;
862 avc->cachingTransitions = 0;
867 afs_FlushAllVCaches(void)
870 struct vcache *tvc, *nvc;
872 ObtainWriteLock(&afs_xvcache, 867);
875 for (i = 0; i < VCSIZE; i++) {
876 for (tvc = afs_vhashT[i]; tvc; tvc = nvc) {
880 if (afs_FlushVCache(tvc, &slept)) {
881 afs_warn("Failed to flush vcache 0x%lx\n", (unsigned long)(uintptrsz)tvc);
889 ReleaseWriteLock(&afs_xvcache);
893 * This routine is responsible for allocating a new cache entry
894 * from the free list. It formats the cache entry and inserts it
895 * into the appropriate hash tables. It must be called with
896 * afs_xvcache write-locked so as to prevent several processes from
897 * trying to create a new cache entry simultaneously.
899 * LOCK: afs_NewVCache afs_xvcache W
901 * \param afid The file id of the file whose cache entry is being created.
903 * \return The new vcache struct.
906 static_inline struct vcache *
907 afs_NewVCache_int(struct VenusFid *afid, struct server *serverp, int seq)
911 afs_int32 anumber = VCACHE_FREE;
913 AFS_STATCNT(afs_NewVCache);
915 afs_FlushReclaimedVcaches();
917 #if defined(AFS_LINUX22_ENV)
918 if(!afsd_dynamic_vcaches && afs_vcount >= afs_maxvcount) {
919 afs_ShakeLooseVCaches(anumber);
920 if (afs_vcount >= afs_maxvcount) {
921 afs_warn("afs_NewVCache - none freed\n");
925 tvc = afs_AllocVCache();
926 #else /* AFS_LINUX22_ENV */
927 /* pull out a free cache entry */
929 afs_ShakeLooseVCaches(anumber);
933 tvc = afs_AllocVCache();
935 tvc = freeVCList; /* take from free list */
936 freeVCList = tvc->nextfree;
937 tvc->nextfree = NULL;
938 afs_vcount++; /* balanced by FlushVCache */
939 } /* end of if (!freeVCList) */
941 #endif /* AFS_LINUX22_ENV */
943 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
945 panic("afs_NewVCache(): free vcache with vnode attached");
948 /* Populate the vcache with as much as we can. */
949 afs_PrePopulateVCache(tvc, afid, serverp);
951 /* Thread the vcache onto the VLRU */
956 tvc->hnext = afs_vhashT[i];
958 QAdd(&afs_vhashTV[j], &tvc->vhashq);
960 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
961 refpanic("NewVCache VLRU inconsistent");
963 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
964 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
965 refpanic("NewVCache VLRU inconsistent2");
967 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
968 refpanic("NewVCache VLRU inconsistent3");
970 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
971 refpanic("NewVCache VLRU inconsistent4");
975 /* it should now be safe to drop the xvcache lock - so attach an inode
976 * to this vcache, where necessary */
977 osi_AttachVnode(tvc, seq);
979 /* Get a reference count to hold this vcache for the VLRUQ. Note that
980 * we have to do this after attaching the vnode, because the reference
981 * count may be held in the vnode itself */
983 #if defined(AFS_LINUX22_ENV)
984 /* Hold it for the LRU (should make count 2) */
986 #elif !(defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV))
987 VREFCOUNT_SET(tvc, 1); /* us */
990 #if defined (AFS_FBSD_ENV)
991 if (tvc->f.states & CVInit)
993 afs_PostPopulateVCache(tvc, afid, seq);
1000 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
1002 return afs_NewVCache_int(afid, serverp, 0);
1006 afs_NewBulkVCache(struct VenusFid *afid, struct server *serverp, int seq)
1008 return afs_NewVCache_int(afid, serverp, seq);
1014 * LOCK: afs_FlushActiveVcaches afs_xvcache N
1016 * \param doflocks : Do we handle flocks?
1019 afs_FlushActiveVcaches(afs_int32 doflocks)
1023 struct afs_conn *tc;
1025 afs_ucred_t *cred = NULL;
1026 struct vrequest *treq = NULL;
1027 struct AFSVolSync tsync;
1030 AFS_STATCNT(afs_FlushActiveVcaches);
1032 code = afs_CreateReq(&treq, afs_osi_credp);
1034 afs_warn("unable to alloc treq\n");
1038 ObtainReadLock(&afs_xvcache);
1039 for (i = 0; i < VCSIZE; i++) {
1040 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1041 if (tvc->f.states & CVInit) continue;
1042 #ifdef AFS_DARWIN80_ENV
1043 if (tvc->f.states & CDeadVnode &&
1044 (tvc->f.states & (CCore|CUnlinkedDel) ||
1045 tvc->flockCount)) panic("Dead vnode has core/unlinkedel/flock");
1047 if (doflocks && tvc->flockCount != 0) {
1048 struct rx_connection *rxconn;
1049 /* if this entry has an flock, send a keep-alive call out */
1051 ReleaseReadLock(&afs_xvcache);
1052 ObtainWriteLock(&tvc->lock, 51);
1054 code = afs_InitReq(treq, afs_osi_credp);
1057 break; /* shutting down: do not try to extend the lock */
1059 treq->flags |= O_NONBLOCK;
1061 tc = afs_Conn(&tvc->f.fid, treq, SHARED_LOCK, &rxconn);
1063 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1066 RXAFS_ExtendLock(rxconn,
1067 (struct AFSFid *)&tvc->f.fid.Fid,
1073 } while (afs_Analyze
1074 (tc, rxconn, code, &tvc->f.fid, treq,
1075 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1077 ReleaseWriteLock(&tvc->lock);
1078 #ifdef AFS_DARWIN80_ENV
1080 ObtainReadLock(&afs_xvcache);
1082 ObtainReadLock(&afs_xvcache);
1087 if ((tvc->f.states & CCore) || (tvc->f.states & CUnlinkedDel)) {
1089 * Don't let it evaporate in case someone else is in
1090 * this code. Also, drop the afs_xvcache lock while
1091 * getting vcache locks.
1094 ReleaseReadLock(&afs_xvcache);
1095 #if defined(AFS_SGI_ENV)
1097 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1099 osi_Assert(VREFCOUNT_GT(tvc,0));
1100 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1102 ObtainWriteLock(&tvc->lock, 52);
1103 if (tvc->f.states & CCore) {
1104 tvc->f.states &= ~CCore;
1105 /* XXXX Find better place-holder for cred XXXX */
1106 cred = (afs_ucred_t *)tvc->linkData;
1107 tvc->linkData = NULL; /* XXX */
1108 code = afs_InitReq(treq, cred);
1109 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1110 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1111 tvc->execsOrWriters);
1112 if (!code) { /* avoid store when shutting down */
1113 code = afs_StoreOnLastReference(tvc, treq);
1115 ReleaseWriteLock(&tvc->lock);
1116 hzero(tvc->flushDV);
1119 if (code && code != VNOVNODE) {
1120 afs_StoreWarn(code, tvc->f.fid.Fid.Volume,
1121 /* /dev/console */ 1);
1123 } else if (tvc->f.states & CUnlinkedDel) {
1127 ReleaseWriteLock(&tvc->lock);
1128 #if defined(AFS_SGI_ENV)
1129 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1131 afs_remunlink(tvc, 0);
1132 #if defined(AFS_SGI_ENV)
1133 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1136 /* lost (or won, perhaps) the race condition */
1137 ReleaseWriteLock(&tvc->lock);
1139 #if defined(AFS_SGI_ENV)
1140 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1142 #ifdef AFS_DARWIN80_ENV
1145 AFS_RELE(AFSTOV(tvc));
1146 /* Matches write code setting CCore flag */
1149 ObtainReadLock(&afs_xvcache);
1151 ObtainReadLock(&afs_xvcache);
1154 AFS_RELE(AFSTOV(tvc));
1155 /* Matches write code setting CCore flag */
1162 ReleaseReadLock(&afs_xvcache);
1163 afs_DestroyReq(treq);
1169 * Make sure a cache entry is up-to-date status-wise.
1171 * NOTE: everywhere that calls this can potentially be sped up
1172 * by checking CStatd first, and avoiding doing the InitReq
1173 * if this is up-to-date.
1175 * Anymore, the only places that call this KNOW already that the
1176 * vcache is not up-to-date, so we don't screw around.
1178 * \param avc : Ptr to vcache entry to verify.
1184 * Make sure a cache entry is up-to-date status-wise.
1186 * NOTE: everywhere that calls this can potentially be sped up
1187 * by checking CStatd first, and avoiding doing the InitReq
1188 * if this is up-to-date.
1190 * Anymore, the only places that call this KNOW already that the
1191 * vcache is not up-to-date, so we don't screw around.
1193 * \param avc Pointer to vcache entry to verify.
1196 * \return 0 for success or other error codes.
1199 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1203 AFS_STATCNT(afs_VerifyVCache);
1205 /* otherwise we must fetch the status info */
1207 ObtainWriteLock(&avc->lock, 53);
1208 if (avc->f.states & CStatd) {
1209 ReleaseWriteLock(&avc->lock);
1212 ObtainWriteLock(&afs_xcbhash, 461);
1213 avc->f.states &= ~(CStatd | CUnique);
1214 avc->callback = NULL;
1215 afs_DequeueCallback(avc);
1216 ReleaseWriteLock(&afs_xcbhash);
1217 ReleaseWriteLock(&avc->lock);
1219 /* since we've been called back, or the callback has expired,
1220 * it's possible that the contents of this directory, or this
1221 * file's name have changed, thus invalidating the dnlc contents.
1223 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1224 osi_dnlc_purgedp(avc);
1226 osi_dnlc_purgevp(avc);
1228 /* fetch the status info */
1229 tvc = afs_GetVCache(&avc->f.fid, areq, NULL, avc);
1232 /* Put it back; caller has already incremented vrefCount */
1236 } /*afs_VerifyVCache */
1240 * Simple copy of stat info into cache.
1242 * Callers:as of 1992-04-29, only called by WriteVCache
1244 * \param avc Ptr to vcache entry involved.
1245 * \param astat Ptr to stat info to copy.
1249 afs_SimpleVStat(struct vcache *avc,
1250 struct AFSFetchStatus *astat, struct vrequest *areq)
1253 AFS_STATCNT(afs_SimpleVStat);
1255 #ifdef AFS_64BIT_CLIENT
1256 FillInt64(length, astat->Length_hi, astat->Length);
1257 #else /* AFS_64BIT_CLIENT */
1258 length = astat->Length;
1259 #endif /* AFS_64BIT_CLIENT */
1261 #if defined(AFS_SGI_ENV)
1262 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1263 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1264 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1265 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1266 if (length < avc->f.m.Length) {
1267 vnode_t *vp = (vnode_t *) avc;
1269 osi_Assert(WriteLocked(&avc->lock));
1270 ReleaseWriteLock(&avc->lock);
1272 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1274 ObtainWriteLock(&avc->lock, 67);
1279 if (!afs_DirtyPages(avc)) {
1280 /* if actively writing the file, don't fetch over this value */
1281 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1282 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1283 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1284 avc->f.m.Length = length;
1285 avc->f.m.Date = astat->ClientModTime;
1287 avc->f.m.Owner = astat->Owner;
1288 avc->f.m.Group = astat->Group;
1289 avc->f.m.Mode = astat->UnixModeBits;
1290 if (vType(avc) == VREG) {
1291 avc->f.m.Mode |= S_IFREG;
1292 } else if (vType(avc) == VDIR) {
1293 avc->f.m.Mode |= S_IFDIR;
1294 } else if (vType(avc) == VLNK) {
1295 avc->f.m.Mode |= S_IFLNK;
1296 if ((avc->f.m.Mode & 0111) == 0)
1299 if (avc->f.states & CForeign) {
1300 struct axscache *ac;
1301 avc->f.anyAccess = astat->AnonymousAccess;
1303 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1305 * Caller has at least one bit not covered by anonymous, and
1306 * thus may have interesting rights.
1308 * HOWEVER, this is a really bad idea, because any access query
1309 * for bits which aren't covered by anonymous, on behalf of a user
1310 * who doesn't have any special rights, will result in an answer of
1311 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1312 * It's an especially bad idea under Ultrix, since (due to the lack of
1313 * a proper access() call) it must perform several afs_access() calls
1314 * in order to create magic mode bits that vary according to who makes
1315 * the call. In other words, _every_ stat() generates a test for
1318 #endif /* badidea */
1319 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1320 ac->axess = astat->CallerAccess;
1321 else /* not found, add a new one if possible */
1322 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1325 } /*afs_SimpleVStat */
1329 * Store the status info *only* back to the server for a
1332 * Environment: Must be called with a shared lock held on the vnode.
1334 * \param avc Ptr to the vcache entry.
1335 * \param astatus Ptr to the status info to store.
1336 * \param areq Ptr to the associated vrequest.
1338 * \return Operation status.
1342 afs_WriteVCache(struct vcache *avc,
1343 struct AFSStoreStatus *astatus,
1344 struct vrequest *areq)
1347 struct afs_conn *tc;
1348 struct AFSFetchStatus OutStatus;
1349 struct AFSVolSync tsync;
1350 struct rx_connection *rxconn;
1352 AFS_STATCNT(afs_WriteVCache);
1353 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1354 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length));
1356 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1358 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1361 RXAFS_StoreStatus(rxconn, (struct AFSFid *)&avc->f.fid.Fid,
1362 astatus, &OutStatus, &tsync);
1367 } while (afs_Analyze
1368 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1369 SHARED_LOCK, NULL));
1371 UpgradeSToWLock(&avc->lock, 20);
1373 /* success, do the changes locally */
1374 afs_SimpleVStat(avc, &OutStatus, areq);
1376 * Update the date, too. SimpleVStat didn't do this, since
1377 * it thought we were doing this after fetching new status
1378 * over a file being written.
1380 avc->f.m.Date = OutStatus.ClientModTime;
1382 /* failure, set up to check with server next time */
1383 ObtainWriteLock(&afs_xcbhash, 462);
1384 afs_DequeueCallback(avc);
1385 avc->f.states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1386 ReleaseWriteLock(&afs_xcbhash);
1387 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1388 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1390 ConvertWToSLock(&avc->lock);
1393 } /*afs_WriteVCache */
1396 * Store status info only locally, set the proper disconnection flags
1397 * and add to dirty list.
1399 * \param avc The vcache to be written locally.
1400 * \param astatus Get attr fields from local store.
1401 * \param attrs This one is only of the vs_size.
1403 * \note Must be called with a shared lock on the vnode
1406 afs_WriteVCacheDiscon(struct vcache *avc,
1407 struct AFSStoreStatus *astatus,
1408 struct vattr *attrs)
1411 afs_int32 flags = 0;
1413 UpgradeSToWLock(&avc->lock, 700);
1415 if (!astatus->Mask) {
1421 /* Set attributes. */
1422 if (astatus->Mask & AFS_SETMODTIME) {
1423 avc->f.m.Date = astatus->ClientModTime;
1424 flags |= VDisconSetTime;
1427 if (astatus->Mask & AFS_SETOWNER) {
1428 /* printf("Not allowed yet. \n"); */
1429 /*avc->f.m.Owner = astatus->Owner;*/
1432 if (astatus->Mask & AFS_SETGROUP) {
1433 /* printf("Not allowed yet. \n"); */
1434 /*avc->f.m.Group = astatus->Group;*/
1437 if (astatus->Mask & AFS_SETMODE) {
1438 avc->f.m.Mode = astatus->UnixModeBits;
1440 #if 0 /* XXX: Leaving this out, so it doesn't mess up the file type flag.*/
1442 if (vType(avc) == VREG) {
1443 avc->f.m.Mode |= S_IFREG;
1444 } else if (vType(avc) == VDIR) {
1445 avc->f.m.Mode |= S_IFDIR;
1446 } else if (vType(avc) == VLNK) {
1447 avc->f.m.Mode |= S_IFLNK;
1448 if ((avc->f.m.Mode & 0111) == 0)
1452 flags |= VDisconSetMode;
1453 } /* if(astatus.Mask & AFS_SETMODE) */
1455 } /* if (!astatus->Mask) */
1457 if (attrs->va_size > 0) {
1458 /* XXX: Do I need more checks? */
1459 /* Truncation operation. */
1460 flags |= VDisconTrunc;
1464 afs_DisconAddDirty(avc, flags, 1);
1466 /* XXX: How about the rest of the fields? */
1468 ConvertWToSLock(&avc->lock);
1474 * Copy astat block into vcache info
1476 * \note This code may get dataversion and length out of sync if the file has
1477 * been modified. This is less than ideal. I haven't thought about it sufficiently
1478 * to be certain that it is adequate.
1480 * \note Environment: Must be called under a write lock
1482 * \param avc Ptr to vcache entry.
1483 * \param astat Ptr to stat block to copy in.
1484 * \param areq Ptr to associated request.
1487 afs_ProcessFS(struct vcache *avc,
1488 struct AFSFetchStatus *astat, struct vrequest *areq)
1491 AFS_STATCNT(afs_ProcessFS);
1493 #ifdef AFS_64BIT_CLIENT
1494 FillInt64(length, astat->Length_hi, astat->Length);
1495 #else /* AFS_64BIT_CLIENT */
1496 length = astat->Length;
1497 #endif /* AFS_64BIT_CLIENT */
1498 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1499 * number for each bulk status request. Under no circumstances
1500 * should afs_DoBulkStat store a sequence number if the new
1501 * length will be ignored when afs_ProcessFS is called with
1502 * new stats. If you change the following conditional then you
1503 * also need to change the conditional in afs_DoBulkStat. */
1505 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1506 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1508 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1510 /* if we're writing or mapping this file, don't fetch over these
1513 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1514 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1515 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1516 avc->f.m.Length = length;
1517 avc->f.m.Date = astat->ClientModTime;
1519 hset64(avc->f.m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1520 avc->f.m.Owner = astat->Owner;
1521 avc->f.m.Mode = astat->UnixModeBits;
1522 avc->f.m.Group = astat->Group;
1523 avc->f.m.LinkCount = astat->LinkCount;
1524 if (astat->FileType == File) {
1525 vSetType(avc, VREG);
1526 avc->f.m.Mode |= S_IFREG;
1527 } else if (astat->FileType == Directory) {
1528 vSetType(avc, VDIR);
1529 avc->f.m.Mode |= S_IFDIR;
1530 } else if (astat->FileType == SymbolicLink) {
1531 if (afs_fakestat_enable && (avc->f.m.Mode & 0111) == 0) {
1532 vSetType(avc, VDIR);
1533 avc->f.m.Mode |= S_IFDIR;
1535 vSetType(avc, VLNK);
1536 avc->f.m.Mode |= S_IFLNK;
1538 if ((avc->f.m.Mode & 0111) == 0) {
1542 avc->f.anyAccess = astat->AnonymousAccess;
1544 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1546 * Caller has at least one bit not covered by anonymous, and
1547 * thus may have interesting rights.
1549 * HOWEVER, this is a really bad idea, because any access query
1550 * for bits which aren't covered by anonymous, on behalf of a user
1551 * who doesn't have any special rights, will result in an answer of
1552 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1553 * It's an especially bad idea under Ultrix, since (due to the lack of
1554 * a proper access() call) it must perform several afs_access() calls
1555 * in order to create magic mode bits that vary according to who makes
1556 * the call. In other words, _every_ stat() generates a test for
1559 #endif /* badidea */
1561 struct axscache *ac;
1562 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1563 ac->axess = astat->CallerAccess;
1564 else /* not found, add a new one if possible */
1565 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1567 } /*afs_ProcessFS */
1571 * Get fid from server.
1574 * \param areq Request to be passed on.
1575 * \param name Name of ?? to lookup.
1576 * \param OutStatus Fetch status.
1581 * \return Success status of operation.
1584 afs_RemoteLookup(struct VenusFid *afid, struct vrequest *areq,
1585 char *name, struct VenusFid *nfid,
1586 struct AFSFetchStatus *OutStatusp,
1587 struct AFSCallBack *CallBackp, struct server **serverp,
1588 struct AFSVolSync *tsyncp)
1591 struct afs_conn *tc;
1592 struct rx_connection *rxconn;
1593 struct AFSFetchStatus OutDirStatus;
1596 name = ""; /* XXX */
1598 tc = afs_Conn(afid, areq, SHARED_LOCK, &rxconn);
1601 *serverp = tc->parent->srvr->server;
1602 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1605 RXAFS_Lookup(rxconn, (struct AFSFid *)&afid->Fid, name,
1606 (struct AFSFid *)&nfid->Fid, OutStatusp,
1607 &OutDirStatus, CallBackp, tsyncp);
1612 } while (afs_Analyze
1613 (tc, rxconn, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1623 * Given a file id and a vrequest structure, fetch the status
1624 * information associated with the file.
1626 * \param afid File ID.
1627 * \param areq Ptr to associated vrequest structure, specifying the
1628 * user whose authentication tokens will be used.
1629 * \param avc Caller may already have a vcache for this file, which is
1632 * \note Environment:
1633 * The cache entry is returned with an increased vrefCount field.
1634 * The entry must be discarded by calling afs_PutVCache when you
1635 * are through using the pointer to the cache entry.
1637 * You should not hold any locks when calling this function, except
1638 * locks on other vcache entries. If you lock more than one vcache
1639 * entry simultaneously, you should lock them in this order:
1641 * 1. Lock all files first, then directories.
1642 * 2. Within a particular type, lock entries in Fid.Vnode order.
1644 * This locking hierarchy is convenient because it allows locking
1645 * of a parent dir cache entry, given a file (to check its access
1646 * control list). It also allows renames to be handled easily by
1647 * locking directories in a constant order.
1649 * \note NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1651 * \note Might have a vcache structure already, which must
1652 * already be held by the caller
1655 afs_GetVCache(struct VenusFid *afid, struct vrequest *areq,
1656 afs_int32 * cached, struct vcache *avc)
1659 afs_int32 code, newvcache = 0;
1664 AFS_STATCNT(afs_GetVCache);
1667 *cached = 0; /* Init just in case */
1669 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1673 ObtainSharedLock(&afs_xvcache, 5);
1675 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU | IS_SLOCK);
1677 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1678 ReleaseSharedLock(&afs_xvcache);
1679 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1686 osi_Assert((tvc->f.states & CVInit) == 0);
1687 /* If we are in readdir, return the vnode even if not statd */
1688 if ((tvc->f.states & CStatd) || afs_InReadDir(tvc)) {
1689 ReleaseSharedLock(&afs_xvcache);
1693 UpgradeSToWLock(&afs_xvcache, 21);
1695 /* no cache entry, better grab one */
1696 tvc = afs_NewVCache(afid, NULL);
1699 ConvertWToSLock(&afs_xvcache);
1702 ReleaseSharedLock(&afs_xvcache);
1706 afs_stats_cmperf.vcacheMisses++;
1709 ReleaseSharedLock(&afs_xvcache);
1711 ObtainWriteLock(&tvc->lock, 54);
1713 if (tvc->f.states & CStatd) {
1714 ReleaseWriteLock(&tvc->lock);
1717 #ifdef AFS_DARWIN80_ENV
1718 /* Darwin 8.0 only has bufs in nfs, so we shouldn't have to worry about them.
1721 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1723 * XXX - I really don't like this. Should try to understand better.
1724 * It seems that sometimes, when we get called, we already hold the
1725 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1726 * We can't drop the vnode lock, because that could result in a race.
1727 * Sometimes, though, we get here and don't hold the vnode lock.
1728 * I hate code paths that sometimes hold locks and sometimes don't.
1729 * In any event, the dodge we use here is to check whether the vnode
1730 * is locked, and if it isn't, then we gain and drop it around the call
1731 * to vinvalbuf; otherwise, we leave it alone.
1734 struct vnode *vp = AFSTOV(tvc);
1737 #if defined(AFS_DARWIN_ENV)
1738 iheldthelock = VOP_ISLOCKED(vp);
1740 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc());
1741 /* this is messy. we can call fsync which will try to reobtain this */
1742 if (VTOAFS(vp) == tvc)
1743 ReleaseWriteLock(&tvc->lock);
1744 if (UBCINFOEXISTS(vp)) {
1745 vinvalbuf(vp, V_SAVE, &afs_osi_cred, current_proc(), PINOD, 0);
1747 if (VTOAFS(vp) == tvc)
1748 ObtainWriteLock(&tvc->lock, 954);
1750 VOP_UNLOCK(vp, LK_EXCLUSIVE, current_proc());
1751 #elif defined(AFS_FBSD80_ENV)
1752 iheldthelock = VOP_ISLOCKED(vp);
1753 if (!iheldthelock) {
1754 /* nosleep/sleep lock order reversal */
1755 int glocked = ISAFS_GLOCK();
1758 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1762 vinvalbuf(vp, V_SAVE, PINOD, 0); /* changed late in 8.0-CURRENT */
1765 #elif defined(AFS_FBSD60_ENV)
1766 iheldthelock = VOP_ISLOCKED(vp, curthread);
1768 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1770 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1773 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1774 #elif defined(AFS_FBSD_ENV)
1775 iheldthelock = VOP_ISLOCKED(vp, curthread);
1777 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1778 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1780 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1781 #elif defined(AFS_OBSD_ENV)
1782 iheldthelock = VOP_ISLOCKED(vp, curproc);
1784 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1785 uvm_vnp_uncache(vp);
1787 VOP_UNLOCK(vp, 0, curproc);
1788 #elif defined(AFS_NBSD40_ENV)
1789 iheldthelock = VOP_ISLOCKED(vp);
1790 if (!iheldthelock) {
1791 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY);
1793 uvm_vnp_uncache(vp);
1801 ObtainWriteLock(&afs_xcbhash, 464);
1802 tvc->f.states &= ~CUnique;
1804 afs_DequeueCallback(tvc);
1805 ReleaseWriteLock(&afs_xcbhash);
1807 /* It is always appropriate to throw away all the access rights? */
1808 afs_FreeAllAxs(&(tvc->Access));
1809 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1811 if ((tvp->states & VForeign)) {
1813 tvc->f.states |= CForeign;
1814 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1815 && (tvp->rootUnique == afid->Fid.Unique)) {
1819 if (tvp->states & VRO)
1820 tvc->f.states |= CRO;
1821 if (tvp->states & VBackup)
1822 tvc->f.states |= CBackup;
1823 /* now copy ".." entry back out of volume structure, if necessary */
1824 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1826 tvc->mvid = (struct VenusFid *)
1827 osi_AllocSmallSpace(sizeof(struct VenusFid));
1828 *tvc->mvid = tvp->dotdot;
1830 afs_PutVolume(tvp, READ_LOCK);
1834 afs_RemoveVCB(afid);
1836 struct AFSFetchStatus OutStatus;
1838 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1839 afs_ProcessFS(tvc, &OutStatus, areq);
1840 tvc->f.states |= CStatd | CUnique;
1841 tvc->f.parent.vnode = OutStatus.ParentVnode;
1842 tvc->f.parent.unique = OutStatus.ParentUnique;
1846 if (AFS_IS_DISCONNECTED) {
1847 /* Nothing to do otherwise...*/
1849 /* printf("Network is down in afs_GetCache"); */
1851 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1853 /* For the NFS translator's benefit, make sure
1854 * non-directory vnodes always have their parent FID set
1855 * correctly, even when created as a result of decoding an
1856 * NFS filehandle. It would be nice to also do this for
1857 * directories, but we can't because the fileserver fills
1858 * in the FID of the directory itself instead of that of
1861 if (!code && OutStatus.FileType != Directory &&
1862 !tvc->f.parent.vnode) {
1863 tvc->f.parent.vnode = OutStatus.ParentVnode;
1864 tvc->f.parent.unique = OutStatus.ParentUnique;
1865 /* XXX - SXW - It's conceivable we should mark ourselves
1866 * as dirty again here, incase we've been raced
1867 * out of the FetchStatus call.
1874 ReleaseWriteLock(&tvc->lock);
1880 ReleaseWriteLock(&tvc->lock);
1883 } /*afs_GetVCache */
1888 * Lookup a vcache by fid. Look inside the cache first, if not
1889 * there, lookup the file on the server, and then get it's fresh
1894 * \param cached Is element cached? If NULL, don't answer.
1898 * \return The found element or NULL.
1901 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1902 afs_int32 * cached, struct vcache *adp, char *aname)
1904 afs_int32 code, now, newvcache = 0;
1905 struct VenusFid nfid;
1908 struct AFSFetchStatus OutStatus;
1909 struct AFSCallBack CallBack;
1910 struct AFSVolSync tsync;
1911 struct server *serverp = 0;
1915 AFS_STATCNT(afs_GetVCache);
1917 *cached = 0; /* Init just in case */
1919 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1923 ObtainReadLock(&afs_xvcache);
1924 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
1927 ReleaseReadLock(&afs_xvcache);
1929 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1930 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1934 ObtainReadLock(&tvc->lock);
1936 if (tvc->f.states & CStatd) {
1940 ReleaseReadLock(&tvc->lock);
1943 tvc->f.states &= ~CUnique;
1945 ReleaseReadLock(&tvc->lock);
1947 ObtainReadLock(&afs_xvcache);
1950 ReleaseReadLock(&afs_xvcache);
1952 /* lookup the file */
1955 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1957 if (AFS_IS_DISCONNECTED) {
1958 /* printf("Network is down in afs_LookupVcache\n"); */
1962 afs_RemoteLookup(&adp->f.fid, areq, aname, &nfid, &OutStatus,
1963 &CallBack, &serverp, &tsync);
1965 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1969 ObtainSharedLock(&afs_xvcache, 6);
1970 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU | IS_SLOCK/* no xstats now */ );
1972 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1973 ReleaseSharedLock(&afs_xvcache);
1974 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1980 /* no cache entry, better grab one */
1981 UpgradeSToWLock(&afs_xvcache, 22);
1982 tvc = afs_NewVCache(&nfid, serverp);
1984 ConvertWToSLock(&afs_xvcache);
1987 ReleaseSharedLock(&afs_xvcache);
1992 ReleaseSharedLock(&afs_xvcache);
1993 ObtainWriteLock(&tvc->lock, 55);
1995 /* It is always appropriate to throw away all the access rights? */
1996 afs_FreeAllAxs(&(tvc->Access));
1997 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1999 if ((tvp->states & VForeign)) {
2001 tvc->f.states |= CForeign;
2002 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
2003 && (tvp->rootUnique == afid->Fid.Unique))
2006 if (tvp->states & VRO)
2007 tvc->f.states |= CRO;
2008 if (tvp->states & VBackup)
2009 tvc->f.states |= CBackup;
2010 /* now copy ".." entry back out of volume structure, if necessary */
2011 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2013 tvc->mvid = (struct VenusFid *)
2014 osi_AllocSmallSpace(sizeof(struct VenusFid));
2015 *tvc->mvid = tvp->dotdot;
2020 ObtainWriteLock(&afs_xcbhash, 465);
2021 afs_DequeueCallback(tvc);
2022 tvc->f.states &= ~(CStatd | CUnique);
2023 ReleaseWriteLock(&afs_xcbhash);
2024 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2025 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2027 afs_PutVolume(tvp, READ_LOCK);
2028 ReleaseWriteLock(&tvc->lock);
2033 ObtainWriteLock(&afs_xcbhash, 466);
2034 if (origCBs == afs_allCBs) {
2035 if (CallBack.ExpirationTime) {
2036 tvc->callback = serverp;
2037 tvc->cbExpires = CallBack.ExpirationTime + now;
2038 tvc->f.states |= CStatd | CUnique;
2039 tvc->f.states &= ~CBulkFetching;
2040 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
2041 } else if (tvc->f.states & CRO) {
2042 /* adapt gives us an hour. */
2043 tvc->cbExpires = 3600 + osi_Time();
2044 /*XXX*/ tvc->f.states |= CStatd | CUnique;
2045 tvc->f.states &= ~CBulkFetching;
2046 afs_QueueCallback(tvc, CBHash(3600), tvp);
2048 tvc->callback = NULL;
2049 afs_DequeueCallback(tvc);
2050 tvc->f.states &= ~(CStatd | CUnique);
2051 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2052 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2055 afs_DequeueCallback(tvc);
2056 tvc->f.states &= ~CStatd;
2057 tvc->f.states &= ~CUnique;
2058 tvc->callback = NULL;
2059 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2060 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2062 ReleaseWriteLock(&afs_xcbhash);
2064 afs_PutVolume(tvp, READ_LOCK);
2065 afs_ProcessFS(tvc, &OutStatus, areq);
2067 ReleaseWriteLock(&tvc->lock);
2073 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2074 afs_int32 * cached, struct volume *tvolp)
2076 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2077 afs_int32 getNewFid = 0;
2079 struct VenusFid nfid;
2081 struct server *serverp = 0;
2082 struct AFSFetchStatus OutStatus;
2083 struct AFSCallBack CallBack;
2084 struct AFSVolSync tsync;
2086 #ifdef AFS_DARWIN80_ENV
2093 if (!tvolp->rootVnode || getNewFid) {
2094 struct VenusFid tfid;
2097 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2098 origCBs = afs_allCBs; /* ignore InitCallBackState */
2100 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2105 /* ReleaseReadLock(&tvolp->lock); */
2106 ObtainWriteLock(&tvolp->lock, 56);
2107 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2108 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2109 ReleaseWriteLock(&tvolp->lock);
2110 /* ObtainReadLock(&tvolp->lock);*/
2113 afid->Fid.Vnode = tvolp->rootVnode;
2114 afid->Fid.Unique = tvolp->rootUnique;
2118 ObtainSharedLock(&afs_xvcache, 7);
2120 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2121 if (!FidCmp(&(tvc->f.fid), afid)) {
2122 if (tvc->f.states & CVInit) {
2123 ReleaseSharedLock(&afs_xvcache);
2124 afs_osi_Sleep(&tvc->f.states);
2127 #ifdef AFS_DARWIN80_ENV
2128 if (tvc->f.states & CDeadVnode) {
2129 ReleaseSharedLock(&afs_xvcache);
2130 afs_osi_Sleep(&tvc->f.states);
2134 if (vnode_get(tvp)) /* this bumps ref count */
2136 if (vnode_ref(tvp)) {
2138 /* AFSTOV(tvc) may be NULL */
2148 if (!haveStatus && (!tvc || !(tvc->f.states & CStatd))) {
2149 /* Mount point no longer stat'd or unknown. FID may have changed. */
2151 ReleaseSharedLock(&afs_xvcache);
2152 #ifdef AFS_DARWIN80_ENV
2155 vnode_put(AFSTOV(tvc));
2156 vnode_rele(AFSTOV(tvc));
2165 UpgradeSToWLock(&afs_xvcache, 23);
2166 /* no cache entry, better grab one */
2167 tvc = afs_NewVCache(afid, NULL);
2170 ReleaseWriteLock(&afs_xvcache);
2174 afs_stats_cmperf.vcacheMisses++;
2178 afs_stats_cmperf.vcacheHits++;
2179 #if defined(AFS_DARWIN80_ENV)
2180 /* we already bumped the ref count in the for loop above */
2181 #else /* AFS_DARWIN80_ENV */
2184 UpgradeSToWLock(&afs_xvcache, 24);
2185 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2186 refpanic("GRVC VLRU inconsistent0");
2188 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2189 refpanic("GRVC VLRU inconsistent1");
2191 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2192 refpanic("GRVC VLRU inconsistent2");
2194 QRemove(&tvc->vlruq); /* move to lruq head */
2195 QAdd(&VLRU, &tvc->vlruq);
2196 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2197 refpanic("GRVC VLRU inconsistent3");
2199 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2200 refpanic("GRVC VLRU inconsistent4");
2202 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2203 refpanic("GRVC VLRU inconsistent5");
2208 ReleaseWriteLock(&afs_xvcache);
2210 if (tvc->f.states & CStatd) {
2214 ObtainReadLock(&tvc->lock);
2215 tvc->f.states &= ~CUnique;
2216 tvc->callback = NULL; /* redundant, perhaps */
2217 ReleaseReadLock(&tvc->lock);
2220 ObtainWriteLock(&tvc->lock, 57);
2222 /* It is always appropriate to throw away all the access rights? */
2223 afs_FreeAllAxs(&(tvc->Access));
2226 tvc->f.states |= CForeign;
2227 if (tvolp->states & VRO)
2228 tvc->f.states |= CRO;
2229 if (tvolp->states & VBackup)
2230 tvc->f.states |= CBackup;
2231 /* now copy ".." entry back out of volume structure, if necessary */
2232 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2233 && (tvolp->rootUnique == afid->Fid.Unique)) {
2236 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2238 tvc->mvid = (struct VenusFid *)
2239 osi_AllocSmallSpace(sizeof(struct VenusFid));
2240 *tvc->mvid = tvolp->dotdot;
2244 afs_RemoveVCB(afid);
2247 struct VenusFid tfid;
2250 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2251 origCBs = afs_allCBs; /* ignore InitCallBackState */
2253 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2258 ObtainWriteLock(&afs_xcbhash, 467);
2259 afs_DequeueCallback(tvc);
2260 tvc->callback = NULL;
2261 tvc->f.states &= ~(CStatd | CUnique);
2262 ReleaseWriteLock(&afs_xcbhash);
2263 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2264 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2265 ReleaseWriteLock(&tvc->lock);
2270 ObtainWriteLock(&afs_xcbhash, 468);
2271 if (origCBs == afs_allCBs) {
2272 tvc->f.states |= CTruth;
2273 tvc->callback = serverp;
2274 if (CallBack.ExpirationTime != 0) {
2275 tvc->cbExpires = CallBack.ExpirationTime + start;
2276 tvc->f.states |= CStatd;
2277 tvc->f.states &= ~CBulkFetching;
2278 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2279 } else if (tvc->f.states & CRO) {
2280 /* adapt gives us an hour. */
2281 tvc->cbExpires = 3600 + osi_Time();
2282 /*XXX*/ tvc->f.states |= CStatd;
2283 tvc->f.states &= ~CBulkFetching;
2284 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2287 afs_DequeueCallback(tvc);
2288 tvc->callback = NULL;
2289 tvc->f.states &= ~(CStatd | CUnique);
2290 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2291 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2293 ReleaseWriteLock(&afs_xcbhash);
2294 afs_ProcessFS(tvc, &OutStatus, areq);
2296 ReleaseWriteLock(&tvc->lock);
2302 * Update callback status and (sometimes) attributes of a vnode.
2303 * Called after doing a fetch status RPC. Whilst disconnected, attributes
2304 * shouldn't be written to the vcache here.
2309 * \param Outsp Server status after rpc call.
2310 * \param acb Callback for this vnode.
2312 * \note The vcache must be write locked.
2315 afs_UpdateStatus(struct vcache *avc, struct VenusFid *afid,
2316 struct vrequest *areq, struct AFSFetchStatus *Outsp,
2317 struct AFSCallBack *acb, afs_uint32 start)
2319 struct volume *volp;
2322 /* Dont write status in vcache if resyncing after a disconnection. */
2323 afs_ProcessFS(avc, Outsp, areq);
2325 volp = afs_GetVolume(afid, areq, READ_LOCK);
2326 ObtainWriteLock(&afs_xcbhash, 469);
2327 avc->f.states |= CTruth;
2328 if (avc->callback /* check for race */ ) {
2329 if (acb->ExpirationTime != 0) {
2330 avc->cbExpires = acb->ExpirationTime + start;
2331 avc->f.states |= CStatd;
2332 avc->f.states &= ~CBulkFetching;
2333 afs_QueueCallback(avc, CBHash(acb->ExpirationTime), volp);
2334 } else if (avc->f.states & CRO) {
2335 /* ordinary callback on a read-only volume -- AFS 3.2 style */
2336 avc->cbExpires = 3600 + start;
2337 avc->f.states |= CStatd;
2338 avc->f.states &= ~CBulkFetching;
2339 afs_QueueCallback(avc, CBHash(3600), volp);
2341 afs_DequeueCallback(avc);
2342 avc->callback = NULL;
2343 avc->f.states &= ~(CStatd | CUnique);
2344 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2345 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2348 afs_DequeueCallback(avc);
2349 avc->callback = NULL;
2350 avc->f.states &= ~(CStatd | CUnique);
2351 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2352 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2354 ReleaseWriteLock(&afs_xcbhash);
2356 afs_PutVolume(volp, READ_LOCK);
2360 afs_BadFetchStatus(struct afs_conn *tc)
2362 int addr = ntohl(tc->parent->srvr->sa_ip);
2363 afs_warn("afs: Invalid AFSFetchStatus from server %u.%u.%u.%u\n",
2364 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2366 afs_warn("afs: This suggests the server may be sending bad data that "
2367 "can lead to availability issues or data corruption. The "
2368 "issue has been avoided for now, but it may not always be "
2369 "detectable. Please upgrade the server if possible.\n");
2373 * Check if a given AFSFetchStatus structure is sane.
2375 * @param[in] tc The server from which we received the status
2376 * @param[in] status The status we received
2378 * @return whether the given structure is valid or not
2379 * @retval 0 the structure is fine
2380 * @retval nonzero the structure looks like garbage; act as if we received
2381 * the returned error code from the server
2384 afs_CheckFetchStatus(struct afs_conn *tc, struct AFSFetchStatus *status)
2386 if (status->errorCode ||
2387 status->InterfaceVersion != 1 ||
2388 !(status->FileType > Invalid && status->FileType <= SymbolicLink) ||
2389 status->ParentVnode == 0 || status->ParentUnique == 0) {
2391 afs_warn("afs: FetchStatus ec %u iv %u ft %u pv %u pu %u\n",
2392 (unsigned)status->errorCode, (unsigned)status->InterfaceVersion,
2393 (unsigned)status->FileType, (unsigned)status->ParentVnode,
2394 (unsigned)status->ParentUnique);
2395 afs_BadFetchStatus(tc);
2403 * Must be called with avc write-locked
2404 * don't absolutely have to invalidate the hint unless the dv has
2405 * changed, but be sure to get it right else there will be consistency bugs.
2408 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2409 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2412 afs_uint32 start = 0;
2413 struct afs_conn *tc;
2414 struct AFSCallBack CallBack;
2415 struct AFSVolSync tsync;
2416 struct rx_connection *rxconn;
2419 tc = afs_Conn(afid, areq, SHARED_LOCK, &rxconn);
2420 avc->dchint = NULL; /* invalidate hints */
2422 avc->callback = tc->parent->srvr->server;
2424 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2427 RXAFS_FetchStatus(rxconn, (struct AFSFid *)&afid->Fid, Outsp,
2434 code = afs_CheckFetchStatus(tc, Outsp);
2439 } while (afs_Analyze
2440 (tc, rxconn, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2441 SHARED_LOCK, NULL));
2444 afs_UpdateStatus(avc, afid, areq, Outsp, &CallBack, start);
2446 /* used to undo the local callback, but that's too extreme.
2447 * There are plenty of good reasons that fetchstatus might return
2448 * an error, such as EPERM. If we have the vnode cached, statd,
2449 * with callback, might as well keep track of the fact that we
2450 * don't have access...
2452 if (code == EPERM || code == EACCES) {
2453 struct axscache *ac;
2454 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2456 else /* not found, add a new one if possible */
2457 afs_AddAxs(avc->Access, areq->uid, 0);
2468 * Stuff some information into the vcache for the given file.
2471 * afid : File in question.
2472 * OutStatus : Fetch status on the file.
2473 * CallBack : Callback info.
2474 * tc : RPC connection involved.
2475 * areq : vrequest involved.
2478 * Nothing interesting.
2481 afs_StuffVcache(struct VenusFid *afid,
2482 struct AFSFetchStatus *OutStatus,
2483 struct AFSCallBack *CallBack, struct afs_conn *tc,
2484 struct vrequest *areq)
2486 afs_int32 code, i, newvcache = 0;
2488 struct AFSVolSync tsync;
2490 struct axscache *ac;
2493 AFS_STATCNT(afs_StuffVcache);
2494 #ifdef IFS_VCACHECOUNT
2499 ObtainSharedLock(&afs_xvcache, 8);
2501 tvc = afs_FindVCache(afid, &retry, DO_VLRU| IS_SLOCK /* no stats */ );
2503 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2504 ReleaseSharedLock(&afs_xvcache);
2505 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2511 /* no cache entry, better grab one */
2512 UpgradeSToWLock(&afs_xvcache, 25);
2513 tvc = afs_NewVCache(afid, NULL);
2515 ConvertWToSLock(&afs_xvcache);
2518 ReleaseSharedLock(&afs_xvcache);
2523 ReleaseSharedLock(&afs_xvcache);
2524 ObtainWriteLock(&tvc->lock, 58);
2526 tvc->f.states &= ~CStatd;
2527 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2528 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2530 /* Is it always appropriate to throw away all the access rights? */
2531 afs_FreeAllAxs(&(tvc->Access));
2533 /*Copy useful per-volume info */
2534 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2536 if (newvcache && (tvp->states & VForeign))
2537 tvc->f.states |= CForeign;
2538 if (tvp->states & VRO)
2539 tvc->f.states |= CRO;
2540 if (tvp->states & VBackup)
2541 tvc->f.states |= CBackup;
2543 * Now, copy ".." entry back out of volume structure, if
2546 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2548 tvc->mvid = (struct VenusFid *)
2549 osi_AllocSmallSpace(sizeof(struct VenusFid));
2550 *tvc->mvid = tvp->dotdot;
2553 /* store the stat on the file */
2554 afs_RemoveVCB(afid);
2555 afs_ProcessFS(tvc, OutStatus, areq);
2556 tvc->callback = tc->srvr->server;
2558 /* we use osi_Time twice below. Ideally, we would use the time at which
2559 * the FetchStatus call began, instead, but we don't have it here. So we
2560 * make do with "now". In the CRO case, it doesn't really matter. In
2561 * the other case, we hope that the difference between "now" and when the
2562 * call actually began execution on the server won't be larger than the
2563 * padding which the server keeps. Subtract 1 second anyway, to be on
2564 * the safe side. Can't subtract more because we don't know how big
2565 * ExpirationTime is. Possible consistency problems may arise if the call
2566 * timeout period becomes longer than the server's expiration padding. */
2567 ObtainWriteLock(&afs_xcbhash, 470);
2568 if (CallBack->ExpirationTime != 0) {
2569 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2570 tvc->f.states |= CStatd;
2571 tvc->f.states &= ~CBulkFetching;
2572 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2573 } else if (tvc->f.states & CRO) {
2574 /* old-fashioned AFS 3.2 style */
2575 tvc->cbExpires = 3600 + osi_Time();
2576 /*XXX*/ tvc->f.states |= CStatd;
2577 tvc->f.states &= ~CBulkFetching;
2578 afs_QueueCallback(tvc, CBHash(3600), tvp);
2580 afs_DequeueCallback(tvc);
2581 tvc->callback = NULL;
2582 tvc->f.states &= ~(CStatd | CUnique);
2583 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2584 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2586 ReleaseWriteLock(&afs_xcbhash);
2588 afs_PutVolume(tvp, READ_LOCK);
2590 /* look in per-pag cache */
2591 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2592 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2593 else /* not found, add a new one if possible */
2594 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2596 ReleaseWriteLock(&tvc->lock);
2597 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2598 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2599 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2601 * Release ref count... hope this guy stays around...
2604 } /*afs_StuffVcache */
2608 * Decrements the reference count on a cache entry.
2610 * \param avc Pointer to the cache entry to decrement.
2612 * \note Environment: Nothing interesting.
2615 afs_PutVCache(struct vcache *avc)
2617 AFS_STATCNT(afs_PutVCache);
2618 #ifdef AFS_DARWIN80_ENV
2619 vnode_put(AFSTOV(avc));
2623 * Can we use a read lock here?
2625 ObtainReadLock(&afs_xvcache);
2627 ReleaseReadLock(&afs_xvcache);
2629 } /*afs_PutVCache */
2633 * Reset a vcache entry, so local contents are ignored, and the
2634 * server will be reconsulted next time the vcache is used
2636 * \param avc Pointer to the cache entry to reset
2638 * \param skipdnlc skip the dnlc purge for this vnode
2640 * \note avc must be write locked on entry
2642 * \note The caller should purge the dnlc when skipdnlc is set.
2645 afs_ResetVCache(struct vcache *avc, afs_ucred_t *acred, afs_int32 skipdnlc)
2647 ObtainWriteLock(&afs_xcbhash, 456);
2648 afs_DequeueCallback(avc);
2649 avc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat */
2650 ReleaseWriteLock(&afs_xcbhash);
2651 /* now find the disk cache entries */
2652 afs_TryToSmush(avc, acred, 1);
2654 osi_dnlc_purgedp(avc);
2656 if (avc->linkData && !(avc->f.states & CCore)) {
2657 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
2658 avc->linkData = NULL;
2663 * Sleepa when searching for a vcache. Releases all the pending locks,
2664 * sleeps then obtains the previously released locks.
2666 * \param vcache Enter sleep state.
2667 * \param flag Determines what locks to use.
2672 findvc_sleep(struct vcache *avc, int flag)
2674 if (flag & IS_SLOCK) {
2675 ReleaseSharedLock(&afs_xvcache);
2677 if (flag & IS_WLOCK) {
2678 ReleaseWriteLock(&afs_xvcache);
2680 ReleaseReadLock(&afs_xvcache);
2683 afs_osi_Sleep(&avc->f.states);
2684 if (flag & IS_SLOCK) {
2685 ObtainSharedLock(&afs_xvcache, 341);
2687 if (flag & IS_WLOCK) {
2688 ObtainWriteLock(&afs_xvcache, 343);
2690 ObtainReadLock(&afs_xvcache);
2696 * Add a reference on an existing vcache entry.
2698 * \param tvc Pointer to the vcache.
2700 * \note Environment: Must be called with at least one reference from
2701 * elsewhere on the vcache, even if that reference will be dropped.
2702 * The global lock is required.
2704 * \return 0 on success, -1 on failure.
2708 afs_RefVCache(struct vcache *tvc)
2710 #ifdef AFS_DARWIN80_ENV
2714 /* AFS_STATCNT(afs_RefVCache); */
2716 #ifdef AFS_DARWIN80_ENV
2720 if (vnode_ref(tvp)) {
2722 /* AFSTOV(tvc) may be NULL */
2731 } /*afs_RefVCache */
2734 * Find a vcache entry given a fid.
2736 * \param afid Pointer to the fid whose cache entry we desire.
2737 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2738 * unlock the vnode, and try again.
2739 * \param flag Bit 1 to specify whether to compute hit statistics. Not
2740 * set if FindVCache is called as part of internal bookkeeping.
2742 * \note Environment: Must be called with the afs_xvcache lock at least held at
2743 * the read level. In order to do the VLRU adjustment, the xvcache lock
2744 * must be shared-- we upgrade it here.
2748 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2753 #ifdef AFS_DARWIN80_ENV
2754 struct vcache *deadvc = NULL, *livevc = NULL;
2758 AFS_STATCNT(afs_FindVCache);
2762 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2763 if (FidMatches(afid, tvc)) {
2764 if (tvc->f.states & CVInit) {
2765 findvc_sleep(tvc, flag);
2768 #ifdef AFS_DARWIN80_ENV
2769 if (tvc->f.states & CDeadVnode) {
2770 findvc_sleep(tvc, flag);
2778 /* should I have a read lock on the vnode here? */
2782 #if defined(AFS_DARWIN80_ENV)
2786 if (tvp && vnode_ref(tvp)) {
2788 /* AFSTOV(tvc) may be NULL */
2797 #elif defined(AFS_DARWIN_ENV)
2798 tvc->f.states |= CUBCinit;
2800 if (UBCINFOMISSING(AFSTOV(tvc)) ||
2801 UBCINFORECLAIMED(AFSTOV(tvc))) {
2802 ubc_info_init(AFSTOV(tvc));
2805 tvc->f.states &= ~CUBCinit;
2807 osi_vnhold(tvc, retry); /* already held, above */
2808 if (retry && *retry)
2812 * only move to front of vlru if we have proper vcache locking)
2814 if (flag & DO_VLRU) {
2815 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2816 refpanic("FindVC VLRU inconsistent1");
2818 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2819 refpanic("FindVC VLRU inconsistent1");
2821 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2822 refpanic("FindVC VLRU inconsistent2");
2824 UpgradeSToWLock(&afs_xvcache, 26);
2825 QRemove(&tvc->vlruq);
2826 QAdd(&VLRU, &tvc->vlruq);
2827 ConvertWToSLock(&afs_xvcache);
2828 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2829 refpanic("FindVC VLRU inconsistent1");
2831 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2832 refpanic("FindVC VLRU inconsistent2");
2834 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2835 refpanic("FindVC VLRU inconsistent3");
2841 if (flag & DO_STATS) {
2843 afs_stats_cmperf.vcacheHits++;
2845 afs_stats_cmperf.vcacheMisses++;
2846 if (afs_IsPrimaryCellNum(afid->Cell))
2847 afs_stats_cmperf.vlocalAccesses++;
2849 afs_stats_cmperf.vremoteAccesses++;
2852 } /*afs_FindVCache */
2855 * Find a vcache entry given a fid. Does a wildcard match on what we
2856 * have for the fid. If more than one entry, don't return anything.
2858 * \param avcp Fill in pointer if we found one and only one.
2859 * \param afid Pointer to the fid whose cache entry we desire.
2860 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2861 * unlock the vnode, and try again.
2862 * \param flags bit 1 to specify whether to compute hit statistics. Not
2863 * set if FindVCache is called as part of internal bookkeeping.
2865 * \note Environment: Must be called with the afs_xvcache lock at least held at
2866 * the read level. In order to do the VLRU adjustment, the xvcache lock
2867 * must be shared-- we upgrade it here.
2869 * \return Number of matches found.
2872 int afs_duplicate_nfs_fids = 0;
2875 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2879 afs_int32 count = 0;
2880 struct vcache *found_tvc = NULL;
2881 #ifdef AFS_DARWIN80_ENV
2885 AFS_STATCNT(afs_FindVCache);
2889 ObtainSharedLock(&afs_xvcache, 331);
2892 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2893 /* Match only on what we have.... */
2894 if (((tvc->f.fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2895 && (tvc->f.fid.Fid.Volume == afid->Fid.Volume)
2896 && ((tvc->f.fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2897 && (tvc->f.fid.Cell == afid->Cell)) {
2898 if (tvc->f.states & CVInit) {
2899 ReleaseSharedLock(&afs_xvcache);
2900 afs_osi_Sleep(&tvc->f.states);
2903 #ifdef AFS_DARWIN80_ENV
2904 if (tvc->f.states & CDeadVnode) {
2905 ReleaseSharedLock(&afs_xvcache);
2906 afs_osi_Sleep(&tvc->f.states);
2910 if (vnode_get(tvp)) {
2911 /* This vnode no longer exists. */
2914 if (vnode_ref(tvp)) {
2915 /* This vnode no longer exists. */
2917 /* AFSTOV(tvc) may be NULL */
2922 #endif /* AFS_DARWIN80_ENV */
2926 afs_duplicate_nfs_fids++;
2927 ReleaseSharedLock(&afs_xvcache);
2928 #ifdef AFS_DARWIN80_ENV
2929 /* Drop our reference counts. */
2930 vnode_put(AFSTOV(tvc));
2931 vnode_put(AFSTOV(found_tvc));
2940 /* should I have a read lock on the vnode here? */
2942 #ifndef AFS_DARWIN80_ENV
2943 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2944 afs_int32 retry = 0;
2945 osi_vnhold(tvc, &retry);
2948 found_tvc = (struct vcache *)0;
2949 ReleaseSharedLock(&afs_xvcache);
2950 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2954 osi_vnhold(tvc, (int *)0); /* already held, above */
2958 * We obtained the xvcache lock above.
2960 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2961 refpanic("FindVC VLRU inconsistent1");
2963 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2964 refpanic("FindVC VLRU inconsistent1");
2966 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2967 refpanic("FindVC VLRU inconsistent2");
2969 UpgradeSToWLock(&afs_xvcache, 568);
2970 QRemove(&tvc->vlruq);
2971 QAdd(&VLRU, &tvc->vlruq);
2972 ConvertWToSLock(&afs_xvcache);
2973 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2974 refpanic("FindVC VLRU inconsistent1");
2976 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2977 refpanic("FindVC VLRU inconsistent2");
2979 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2980 refpanic("FindVC VLRU inconsistent3");
2986 afs_stats_cmperf.vcacheHits++;
2988 afs_stats_cmperf.vcacheMisses++;
2989 if (afs_IsPrimaryCellNum(afid->Cell))
2990 afs_stats_cmperf.vlocalAccesses++;
2992 afs_stats_cmperf.vremoteAccesses++;
2994 *avcp = tvc; /* May be null */
2996 ReleaseSharedLock(&afs_xvcache);
2997 return (tvc ? 1 : 0);
2999 } /*afs_NFSFindVCache */
3005 * Initialize vcache related variables
3010 afs_vcacheInit(int astatSize)
3012 #if !defined(AFS_LINUX22_ENV)
3016 if (!afs_maxvcount) {
3017 afs_maxvcount = astatSize; /* no particular limit on linux? */
3019 #if !defined(AFS_LINUX22_ENV)
3023 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3024 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3026 #if !defined(AFS_LINUX22_ENV)
3027 /* Allocate and thread the struct vcache entries */
3028 tvp = afs_osi_Alloc(astatSize * sizeof(struct vcache));
3029 osi_Assert(tvp != NULL);
3030 memset(tvp, 0, sizeof(struct vcache) * astatSize);
3032 Initial_freeVCList = tvp;
3033 freeVCList = &(tvp[0]);
3034 for (i = 0; i < astatSize - 1; i++) {
3035 tvp[i].nextfree = &(tvp[i + 1]);
3037 tvp[astatSize - 1].nextfree = NULL;
3038 # ifdef KERNEL_HAVE_PIN
3039 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
3043 #if defined(AFS_SGI_ENV)
3044 for (i = 0; i < astatSize; i++) {
3045 char name[METER_NAMSZ];
3046 struct vcache *tvc = &tvp[i];
3048 tvc->v.v_number = ++afsvnumbers;
3049 tvc->vc_rwlockid = OSI_NO_LOCKID;
3050 initnsema(&tvc->vc_rwlock, 1,
3051 makesname(name, "vrw", tvc->v.v_number));
3052 #ifndef AFS_SGI53_ENV
3053 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
3055 #ifndef AFS_SGI62_ENV
3056 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
3057 #endif /* AFS_SGI62_ENV */
3061 for(i = 0; i < VCSIZE; ++i)
3062 QInit(&afs_vhashTV[i]);
3069 shutdown_vcache(void)
3072 struct afs_cbr *tsp;
3074 * XXX We may potentially miss some of the vcaches because if when
3075 * there are no free vcache entries and all the vcache entries are active
3076 * ones then we allocate an additional one - admittedly we almost never
3081 struct afs_q *tq, *uq = NULL;
3083 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
3087 osi_FreeSmallSpace(tvc->mvid);
3088 tvc->mvid = (struct VenusFid *)0;
3091 aix_gnode_rele(AFSTOV(tvc));
3093 if (tvc->linkData) {
3094 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3099 * Also free the remaining ones in the Cache
3101 for (i = 0; i < VCSIZE; i++) {
3102 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3104 osi_FreeSmallSpace(tvc->mvid);
3105 tvc->mvid = (struct VenusFid *)0;
3109 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
3110 #ifdef AFS_AIX32_ENV
3113 vms_delete(tvc->segid);
3115 tvc->segid = tvc->vmh = NULL;
3116 if (VREFCOUNT_GT(tvc,0))
3117 osi_Panic("flushVcache: vm race");
3125 #if defined(AFS_SUN5_ENV)
3131 if (tvc->linkData) {
3132 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3137 afs_FreeAllAxs(&(tvc->Access));
3143 * Free any leftover callback queue
3145 for (i = 0; i < afs_stats_cmperf.CallBackAlloced; i++) {
3146 tsp = afs_cbrHeads[i];
3147 afs_cbrHeads[i] = 0;
3148 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
3152 #if !defined(AFS_LINUX22_ENV)
3153 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3155 # ifdef KERNEL_HAVE_PIN
3156 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3159 freeVCList = Initial_freeVCList = 0;
3162 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3163 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3165 for(i = 0; i < VCSIZE; ++i)
3166 QInit(&afs_vhashTV[i]);
3170 afs_DisconGiveUpCallbacks(void)
3176 ObtainWriteLock(&afs_xvcache, 1002); /* XXX - should be a unique number */
3179 /* Somehow, walk the set of vcaches, with each one coming out as tvc */
3180 for (i = 0; i < VCSIZE; i++) {
3181 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3183 if (afs_QueueVCB(tvc, &slept)) {
3184 tvc->callback = NULL;
3193 ReleaseWriteLock(&afs_xvcache);
3200 * Clear the Statd flag from all vcaches
3202 * This function removes the Statd flag from all vcaches. It's used by
3203 * disconnected mode to tidy up during reconnection
3207 afs_ClearAllStatdFlag(void)
3212 ObtainWriteLock(&afs_xvcache, 715);
3214 for (i = 0; i < VCSIZE; i++) {
3215 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3216 tvc->f.states &= ~(CStatd|CUnique);
3219 ReleaseWriteLock(&afs_xvcache);