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);
90 * The PFlush algorithm makes use of the fact that Fid.Unique is not used in
91 * below hash algorithms. Change it if need be so that flushing algorithm
92 * doesn't move things from one hash chain to another.
94 /* Don't hash on the cell; our callback-breaking code sometimes fails to compute
95 * the cell correctly, and only scans one hash bucket. */
96 int VCHash(struct VenusFid *fid)
98 return opr_jhash_int2(fid->Fid.Volume, fid->Fid.Vnode, 0) &
99 opr_jhash_mask(VCSIZEBITS);
101 /* Hash only on volume to speed up volume callbacks. */
102 int VCHashV(struct VenusFid *fid)
104 return opr_jhash_int(fid->Fid.Vnode, 0) & opr_jhash_mask(VCSIZEBITS);
108 * Generate an index into the hash table for a given Fid.
110 * \return The hash value.
113 afs_HashCBRFid(struct AFSFid *fid)
115 return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE;
119 * Insert a CBR entry into the hash table.
120 * Must be called with afs_xvcb held.
125 afs_InsertHashCBR(struct afs_cbr *cbr)
127 int slot = afs_HashCBRFid(&cbr->fid);
129 cbr->hash_next = afs_cbrHashT[slot];
130 if (afs_cbrHashT[slot])
131 afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next;
133 cbr->hash_pprev = &afs_cbrHashT[slot];
134 afs_cbrHashT[slot] = cbr;
139 * Flush the given vcache entry.
142 * afs_xvcache lock must be held for writing upon entry to
143 * prevent people from changing the vrefCount field, and to
144 * protect the lruq and hnext fields.
145 * LOCK: afs_FlushVCache afs_xvcache W
146 * REFCNT: vcache ref count must be zero on entry except for osf1
147 * RACE: lock is dropped and reobtained, permitting race in caller
149 * \param avc Pointer to vcache entry to flush.
150 * \param slept Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
154 afs_FlushVCache(struct vcache *avc, int *slept)
155 { /*afs_FlushVCache */
158 struct vcache **uvc, *wvc;
160 /* NOTE: We must have nothing drop afs_xvcache until we have removed all
161 * possible references to this vcache. This means all hash tables, queues,
165 AFS_STATCNT(afs_FlushVCache);
166 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
167 ICL_TYPE_INT32, avc->f.states);
169 code = osi_VM_FlushVCache(avc);
173 if (avc->f.states & CVFlushed) {
177 #if !defined(AFS_LINUX22_ENV)
178 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
179 refpanic("LRU vs. Free inconsistency");
182 avc->f.states |= CVFlushed;
183 /* pull the entry out of the lruq and put it on the free list */
184 QRemove(&avc->vlruq);
186 /* keep track of # of files that we bulk stat'd, but never used
187 * before they got recycled.
189 if (avc->f.states & CBulkStat)
192 /* remove entry from the hash chain */
193 i = VCHash(&avc->f.fid);
194 uvc = &afs_vhashT[i];
195 for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
203 /* remove entry from the volume hash table */
204 QRemove(&avc->vhashq);
206 #if defined(AFS_LINUX26_ENV)
208 struct pagewriter *pw, *store;
209 struct list_head tofree;
211 INIT_LIST_HEAD(&tofree);
212 spin_lock(&avc->pagewriter_lock);
213 list_for_each_entry_safe(pw, store, &avc->pagewriters, link) {
215 /* afs_osi_Free may sleep so we need to defer it */
216 list_add_tail(&pw->link, &tofree);
218 spin_unlock(&avc->pagewriter_lock);
219 list_for_each_entry_safe(pw, store, &tofree, link) {
221 afs_osi_Free(pw, sizeof(struct pagewriter));
226 if (avc->mvid.target_root)
227 osi_FreeSmallSpace(avc->mvid.target_root);
228 avc->mvid.target_root = NULL;
230 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
231 avc->linkData = NULL;
233 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
234 /* OK, there are no internal vrefCounts, so there shouldn't
235 * be any more refs here. */
237 #ifdef AFS_DARWIN80_ENV
238 vnode_clearfsnode(AFSTOV(avc));
239 vnode_removefsref(AFSTOV(avc));
241 avc->v->v_data = NULL; /* remove from vnode */
243 AFSTOV(avc) = NULL; /* also drop the ptr to vnode */
246 #ifdef AFS_SUN510_ENV
247 /* As we use private vnodes, cleanup is up to us */
248 vn_reinit(AFSTOV(avc));
250 afs_FreeAllAxs(&(avc->Access));
251 ObtainWriteLock(&afs_xcbhash, 460);
252 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
253 avc->f.states &= ~(CStatd | CUnique);
254 ReleaseWriteLock(&afs_xcbhash);
255 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
256 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
258 osi_dnlc_purgevp(avc);
260 /* By this point, the vcache has been removed from all global structures
261 * via which someone could try to use the vcache. It is okay to drop
262 * afs_xvcache at this point (if *slept is set). */
264 if (afs_shuttingdown == AFS_RUNNING)
265 afs_QueueVCB(avc, slept);
268 * Next, keep track of which vnodes we've deleted for create's
269 * optimistic synchronization algorithm
272 if (avc->f.fid.Fid.Vnode & 1)
278 #if !defined(AFS_LINUX22_ENV)
279 /* put the entry in the free list */
280 avc->nextfree = freeVCList;
282 if (avc->vlruq.prev || avc->vlruq.next) {
283 refpanic("LRU vs. Free inconsistency");
285 avc->f.states |= CVFlushed;
287 /* This should put it back on the vnode free list since usecount is 1 */
289 if (VREFCOUNT_GT(avc,0)) {
290 AFS_RELE(AFSTOV(avc));
291 afs_stats_cmperf.vcacheXAllocs--;
293 if (afs_norefpanic) {
294 afs_warn("flush vc refcnt < 1");
297 osi_Panic("flush vc refcnt < 1");
299 #endif /* AFS_LINUX22_ENV */
304 } /*afs_FlushVCache */
308 * The core of the inactive vnode op for all but IRIX.
314 afs_InactiveVCache(struct vcache *avc, afs_ucred_t *acred)
316 AFS_STATCNT(afs_inactive);
317 if (avc->f.states & CDirty) {
318 /* we can't keep trying to push back dirty data forever. Give up. */
319 afs_InvalidateAllSegments(avc); /* turns off dirty bit */
321 avc->f.states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
322 avc->f.states &= ~CDirty; /* Turn it off */
323 if (avc->f.states & CUnlinked) {
324 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
325 avc->f.states |= CUnlinkedDel;
328 afs_remunlink(avc, 1); /* ignore any return code */
335 * Allocate a callback return structure from the
336 * free list and return it.
338 * Environment: The alloc and free routines are both called with the afs_xvcb lock
339 * held, so we don't have to worry about blocking in osi_Alloc.
341 * \return The allocated afs_cbr.
343 static struct afs_cbr *afs_cbrSpace = 0;
344 /* if alloc limit below changes, fix me! */
345 static struct afs_cbr *afs_cbrHeads[16];
352 while (!afs_cbrSpace) {
353 if (afs_stats_cmperf.CallBackAlloced >= sizeof(afs_cbrHeads)/sizeof(afs_cbrHeads[0])) {
354 /* don't allocate more than 16 * AFS_NCBRS for now */
356 afs_stats_cmperf.CallBackFlushes++;
359 tsp = afs_osi_Alloc(AFS_NCBRS * sizeof(struct afs_cbr));
360 osi_Assert(tsp != NULL);
361 for (i = 0; i < AFS_NCBRS - 1; i++) {
362 tsp[i].next = &tsp[i + 1];
364 tsp[AFS_NCBRS - 1].next = 0;
366 afs_cbrHeads[afs_stats_cmperf.CallBackAlloced] = tsp;
367 afs_stats_cmperf.CallBackAlloced++;
371 afs_cbrSpace = tsp->next;
376 * Free a callback return structure, removing it from all lists.
378 * Environment: the xvcb lock is held over these calls.
380 * \param asp The address of the structure to free.
385 afs_FreeCBR(struct afs_cbr *asp)
387 *(asp->pprev) = asp->next;
389 asp->next->pprev = asp->pprev;
391 *(asp->hash_pprev) = asp->hash_next;
393 asp->hash_next->hash_pprev = asp->hash_pprev;
395 asp->next = afs_cbrSpace;
401 FlushAllVCBs(int nconns, struct rx_connection **rxconns,
402 struct afs_conn **conns)
407 results = afs_osi_Alloc(nconns * sizeof (afs_int32));
408 osi_Assert(results != NULL);
411 multi_Rx(rxconns,nconns)
413 multi_RXAFS_GiveUpAllCallBacks();
414 results[multi_i] = multi_error;
419 * Freeing the CBR will unlink it from the server's CBR list
420 * do it here, not in the loop, because a dynamic CBR will call
421 * into the memory management routines.
423 for ( i = 0 ; i < nconns ; i++ ) {
424 if (results[i] == 0) {
425 /* Unchain all of them */
426 while (conns[i]->parent->srvr->server->cbrs)
427 afs_FreeCBR(conns[i]->parent->srvr->server->cbrs);
430 afs_osi_Free(results, nconns * sizeof(afs_int32));
434 * Flush all queued callbacks to all servers.
436 * Environment: holds xvcb lock over RPC to guard against race conditions
437 * when a new callback is granted for the same file later on.
439 * \return 0 for success.
442 afs_FlushVCBs(afs_int32 lockit)
444 struct AFSFid *tfids;
445 struct AFSCallBack callBacks[1];
446 struct AFSCBFids fidArray;
447 struct AFSCBs cbArray;
449 struct afs_cbr *tcbrp;
453 struct vrequest *treq = NULL;
455 int safety1, safety2, safety3;
458 if (AFS_IS_DISCONNECTED)
461 if ((code = afs_CreateReq(&treq, afs_osi_credp)))
463 treq->flags |= O_NONBLOCK;
464 tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
465 osi_Assert(tfids != NULL);
468 ObtainWriteLock(&afs_xvcb, 273);
471 * First, attempt a multi across everything, all addresses
472 * for all servers we know of.
476 afs_LoopServers(AFS_LS_ALL, NULL, 0, FlushAllVCBs, NULL);
478 ObtainReadLock(&afs_xserver);
479 for (i = 0; i < NSERVERS; i++) {
480 for (safety1 = 0, tsp = afs_servers[i];
481 tsp && safety1 < afs_totalServers + 10;
482 tsp = tsp->next, safety1++) {
484 if (tsp->cbrs == (struct afs_cbr *)0)
487 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
488 * and make an RPC, over and over again.
490 tcount = 0; /* number found so far */
491 for (safety2 = 0; safety2 < afs_cacheStats; safety2++) {
492 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
493 struct rx_connection *rxconn;
494 /* if buffer is full, or we've queued all we're going
495 * to from this server, we should flush out the
498 fidArray.AFSCBFids_len = tcount;
499 fidArray.AFSCBFids_val = (struct AFSFid *)tfids;
500 cbArray.AFSCBs_len = 1;
501 cbArray.AFSCBs_val = callBacks;
502 memset(&callBacks[0], 0, sizeof(callBacks[0]));
503 callBacks[0].CallBackType = CB_EXCLUSIVE;
504 for (safety3 = 0; safety3 < AFS_MAXHOSTS * 2; safety3++) {
505 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
506 tsp->cell->cellNum, treq, 0,
507 SHARED_LOCK, 0, &rxconn);
510 (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
513 RXAFS_GiveUpCallBacks(rxconn, &fidArray,
520 (tc, rxconn, code, 0, treq,
521 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK,
526 /* ignore return code, since callbacks may have
527 * been returned anyway, we shouldn't leave them
528 * around to be returned again.
530 * Next, see if we are done with this server, and if so,
531 * break to deal with the next one.
537 /* if to flush full buffer */
538 /* if we make it here, we have an entry at the head of cbrs,
539 * which we should copy to the file ID array and then free.
542 tfids[tcount++] = tcbrp->fid;
544 /* Freeing the CBR will unlink it from the server's CBR list */
546 } /* while loop for this one server */
547 if (safety2 > afs_cacheStats) {
548 afs_warn("possible internal error afs_flushVCBs (%d)\n",
551 } /* for loop for this hash chain */
552 } /* loop through all hash chains */
553 if (safety1 > afs_totalServers + 2) {
555 ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n",
556 safety1, afs_totalServers + 2);
558 osi_Panic("afs_flushVCBS safety1");
561 ReleaseReadLock(&afs_xserver);
563 ReleaseWriteLock(&afs_xvcb);
564 afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
565 afs_DestroyReq(treq);
570 * Queue a callback on the given fid.
573 * Locks the xvcb lock.
574 * Called when the xvcache lock is already held.
575 * RACE: afs_xvcache may be dropped and reacquired
577 * \param avc vcache entry
578 * \param slep Set to 1 if we dropped afs_xvcache
579 * \return 1 if queued, 0 otherwise
583 afs_QueueVCB(struct vcache *avc, int *slept)
587 struct afs_cbr *tcbp;
590 AFS_STATCNT(afs_QueueVCB);
592 ObtainWriteLock(&afs_xvcb, 274);
594 /* we can't really give back callbacks on RO files, since the
595 * server only tracks them on a per-volume basis, and we don't
596 * know whether we still have some other files from the same
598 if (!((avc->f.states & CRO) == 0 && avc->callback)) {
602 /* The callback is really just a struct server ptr. */
603 tsp = (struct server *)(avc->callback);
606 /* If we don't have CBR space, AllocCBR may block or hit the net for
607 * clearing up CBRs. Hitting the net may involve a fileserver
608 * needing to contact us, so we must drop xvcache so we don't block
609 * those requests from going through. */
610 reacquire = *slept = 1;
611 ReleaseWriteLock(&afs_xvcache);
614 /* we now have a pointer to the server, so we just allocate
615 * a queue entry and queue it.
617 tcbp = afs_AllocCBR();
618 tcbp->fid = avc->f.fid.Fid;
620 tcbp->next = tsp->cbrs;
622 tsp->cbrs->pprev = &tcbp->next;
625 tcbp->pprev = &tsp->cbrs;
627 afs_InsertHashCBR(tcbp);
631 /* now release locks and return */
632 ReleaseWriteLock(&afs_xvcb);
635 /* make sure this is after dropping xvcb, for locking order */
636 ObtainWriteLock(&afs_xvcache, 279);
643 * Remove a queued callback for a given Fid.
646 * Locks xvcb and xserver locks.
647 * Typically called with xdcache, xvcache and/or individual vcache
650 * \param afid The fid we want cleansed of queued callbacks.
655 afs_RemoveVCB(struct VenusFid *afid)
658 struct afs_cbr *cbr, *ncbr;
660 AFS_STATCNT(afs_RemoveVCB);
661 ObtainWriteLock(&afs_xvcb, 275);
663 slot = afs_HashCBRFid(&afid->Fid);
664 ncbr = afs_cbrHashT[slot];
668 ncbr = cbr->hash_next;
670 if (afid->Fid.Volume == cbr->fid.Volume &&
671 afid->Fid.Vnode == cbr->fid.Vnode &&
672 afid->Fid.Unique == cbr->fid.Unique) {
677 ReleaseWriteLock(&afs_xvcb);
681 afs_FlushReclaimedVcaches(void)
683 #if !defined(AFS_LINUX22_ENV)
686 struct vcache *tmpReclaimedVCList = NULL;
688 ObtainWriteLock(&afs_xvreclaim, 76);
689 while (ReclaimedVCList) {
690 tvc = ReclaimedVCList; /* take from free list */
691 ReclaimedVCList = tvc->nextfree;
692 tvc->nextfree = NULL;
693 code = afs_FlushVCache(tvc, &fv_slept);
695 /* Ok, so, if we got code != 0, uh, wtf do we do? */
696 /* Probably, build a temporary list and then put all back when we
697 get to the end of the list */
698 /* This is actually really crappy, but we need to not leak these.
699 We probably need a way to be smarter about this. */
700 tvc->nextfree = tmpReclaimedVCList;
701 tmpReclaimedVCList = tvc;
702 /* printf("Reclaim list flush %lx failed: %d\n", (unsigned long) tvc, code); */
704 if (tvc->f.states & (CVInit
705 #ifdef AFS_DARWIN80_ENV
709 tvc->f.states &= ~(CVInit
710 #ifdef AFS_DARWIN80_ENV
714 afs_osi_Wakeup(&tvc->f.states);
717 if (tmpReclaimedVCList)
718 ReclaimedVCList = tmpReclaimedVCList;
720 ReleaseWriteLock(&afs_xvreclaim);
725 afs_PostPopulateVCache(struct vcache *avc, struct VenusFid *afid, int seq)
728 * The proper value for mvstat (for root fids) is setup by the caller.
730 avc->mvstat = AFS_MVSTAT_FILE;
731 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
732 avc->mvstat = AFS_MVSTAT_ROOT;
734 if (afs_globalVFS == 0)
735 osi_Panic("afs globalvfs");
737 osi_PostPopulateVCache(avc);
740 osi_dnlc_purgedp(avc); /* this may be overkill */
741 memset(&(avc->callsort), 0, sizeof(struct afs_q));
743 avc->f.states &=~ CVInit;
745 avc->f.states |= CBulkFetching;
746 avc->f.m.Length = seq;
748 afs_osi_Wakeup(&avc->f.states);
752 afs_ShakeLooseVCaches(afs_int32 anumber)
757 struct afs_q *tq, *uq;
758 int fv_slept, defersleep = 0;
760 afs_int32 target = anumber;
767 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
770 if (tvc->f.states & CVFlushed) {
771 refpanic("CVFlushed on VLRU");
772 } else if (i++ > limit) {
773 afs_warn("afs_ShakeLooseVCaches: i %d limit %d afs_vcount %d afs_maxvcount %d\n",
774 (int)i, limit, (int)afs_vcount, (int)afs_maxvcount);
775 refpanic("Found too many AFS vnodes on VLRU (VLRU cycle?)");
776 } else if (QNext(uq) != tq) {
777 refpanic("VLRU inconsistent");
778 } else if (tvc->f.states & CVInit) {
783 evicted = osi_TryEvictVCache(tvc, &fv_slept, defersleep);
793 * This vcache was busy and we slept while trying to evict it.
794 * Move this busy vcache to the head of the VLRU so vcaches
795 * following this busy vcache can be evicted during the retry.
797 QRemove(&tvc->vlruq);
798 QAdd(&VLRU, &tvc->vlruq);
800 goto retry; /* start over - may have raced. */
803 if (anumber && !defersleep) {
810 if (!afsd_dynamic_vcaches && anumber == target) {
811 afs_warn("afs_ShakeLooseVCaches: warning none freed, using %d of %d\n",
812 afs_vcount, afs_maxvcount);
818 /* Alloc new vnode. */
820 static struct vcache *
821 afs_AllocVCache(void)
825 tvc = osi_NewVnode();
830 if (afsd_dynamic_vcaches && afs_maxvcount < afs_vcount) {
831 afs_maxvcount = afs_vcount;
832 /*printf("peak vnodes: %d\n", afs_maxvcount);*/
835 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
837 /* If we create a new inode, we either give it a new slot number,
838 * or if one's available, use a slot number from the slot free list
840 if (afs_freeSlotList != NULL) {
841 struct afs_slotlist *tmp;
843 tvc->diskSlot = afs_freeSlotList->slot;
844 tmp = afs_freeSlotList;
845 afs_freeSlotList = tmp->next;
846 afs_osi_Free(tmp, sizeof(struct afs_slotlist));
848 tvc->diskSlot = afs_nextVcacheSlot++;
854 /* Pre populate a newly allocated vcache. On platforms where the actual
855 * vnode is attached to the vcache, this function is called before attachment,
856 * therefore it cannot perform any actions on the vnode itself */
859 afs_PrePopulateVCache(struct vcache *avc, struct VenusFid *afid,
860 struct server *serverp) {
863 slot = avc->diskSlot;
865 osi_PrePopulateVCache(avc);
867 avc->diskSlot = slot;
868 QZero(&avc->metadirty);
870 AFS_RWLOCK_INIT(&avc->lock, "vcache lock");
872 memset(&avc->mvid, 0, sizeof(avc->mvid));
873 avc->linkData = NULL;
876 avc->execsOrWriters = 0;
878 avc->f.states = CVInit;
879 avc->last_looker = 0;
881 avc->asynchrony = -1;
885 avc->f.truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
886 hzero(avc->f.m.DataVersion); /* in case we copy it into flushDV */
888 avc->callback = serverp; /* to minimize chance that clear
891 #if defined(AFS_CACHE_BYPASS)
892 avc->cachingStates = 0;
893 avc->cachingTransitions = 0;
898 afs_FlushAllVCaches(void)
901 struct vcache *tvc, *nvc;
903 ObtainWriteLock(&afs_xvcache, 867);
906 for (i = 0; i < VCSIZE; i++) {
907 for (tvc = afs_vhashT[i]; tvc; tvc = nvc) {
911 if (afs_FlushVCache(tvc, &slept)) {
912 afs_warn("Failed to flush vcache 0x%lx\n", (unsigned long)(uintptrsz)tvc);
920 ReleaseWriteLock(&afs_xvcache);
924 * This routine is responsible for allocating a new cache entry
925 * from the free list. It formats the cache entry and inserts it
926 * into the appropriate hash tables. It must be called with
927 * afs_xvcache write-locked so as to prevent several processes from
928 * trying to create a new cache entry simultaneously.
930 * LOCK: afs_NewVCache afs_xvcache W
932 * \param afid The file id of the file whose cache entry is being created.
934 * \return The new vcache struct.
937 static_inline struct vcache *
938 afs_NewVCache_int(struct VenusFid *afid, struct server *serverp, int seq)
942 afs_int32 anumber = VCACHE_FREE;
944 AFS_STATCNT(afs_NewVCache);
946 afs_FlushReclaimedVcaches();
948 #if defined(AFS_LINUX22_ENV)
949 if(!afsd_dynamic_vcaches && afs_vcount >= afs_maxvcount) {
950 afs_ShakeLooseVCaches(anumber);
951 if (afs_vcount >= afs_maxvcount) {
952 afs_warn("afs_NewVCache - none freed\n");
956 tvc = afs_AllocVCache();
957 #else /* AFS_LINUX22_ENV */
958 /* pull out a free cache entry */
960 afs_ShakeLooseVCaches(anumber);
964 tvc = afs_AllocVCache();
966 tvc = freeVCList; /* take from free list */
967 freeVCList = tvc->nextfree;
968 tvc->nextfree = NULL;
969 afs_vcount++; /* balanced by FlushVCache */
970 } /* end of if (!freeVCList) */
972 #endif /* AFS_LINUX22_ENV */
974 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
976 panic("afs_NewVCache(): free vcache with vnode attached");
979 /* Populate the vcache with as much as we can. */
980 afs_PrePopulateVCache(tvc, afid, serverp);
982 /* Thread the vcache onto the VLRU */
987 tvc->hnext = afs_vhashT[i];
989 QAdd(&afs_vhashTV[j], &tvc->vhashq);
991 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
992 refpanic("NewVCache VLRU inconsistent");
994 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
995 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
996 refpanic("NewVCache VLRU inconsistent2");
998 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
999 refpanic("NewVCache VLRU inconsistent3");
1001 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1002 refpanic("NewVCache VLRU inconsistent4");
1006 /* it should now be safe to drop the xvcache lock - so attach an inode
1007 * to this vcache, where necessary */
1008 osi_AttachVnode(tvc, seq);
1010 /* Get a reference count to hold this vcache for the VLRUQ. Note that
1011 * we have to do this after attaching the vnode, because the reference
1012 * count may be held in the vnode itself */
1014 #if defined(AFS_LINUX22_ENV)
1015 /* Hold it for the LRU (should make count 2) */
1017 #elif !(defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV))
1018 VREFCOUNT_SET(tvc, 1); /* us */
1021 #if defined (AFS_FBSD_ENV)
1022 if (tvc->f.states & CVInit)
1024 afs_PostPopulateVCache(tvc, afid, seq);
1027 } /*afs_NewVCache */
1031 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
1033 return afs_NewVCache_int(afid, serverp, 0);
1037 afs_NewBulkVCache(struct VenusFid *afid, struct server *serverp, int seq)
1039 return afs_NewVCache_int(afid, serverp, seq);
1045 * LOCK: afs_FlushActiveVcaches afs_xvcache N
1047 * \param doflocks : Do we handle flocks?
1050 afs_FlushActiveVcaches(afs_int32 doflocks)
1054 struct afs_conn *tc;
1056 afs_ucred_t *cred = NULL;
1057 struct vrequest *treq = NULL;
1058 struct AFSVolSync tsync;
1061 AFS_STATCNT(afs_FlushActiveVcaches);
1063 code = afs_CreateReq(&treq, afs_osi_credp);
1065 afs_warn("unable to alloc treq\n");
1069 ObtainReadLock(&afs_xvcache);
1070 for (i = 0; i < VCSIZE; i++) {
1071 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1072 if (tvc->f.states & CVInit) continue;
1073 #ifdef AFS_DARWIN80_ENV
1074 if (tvc->f.states & CDeadVnode &&
1075 (tvc->f.states & (CCore|CUnlinkedDel) ||
1076 tvc->flockCount)) panic("Dead vnode has core/unlinkedel/flock");
1078 if (doflocks && tvc->flockCount != 0) {
1079 struct rx_connection *rxconn;
1080 /* if this entry has an flock, send a keep-alive call out */
1082 ReleaseReadLock(&afs_xvcache);
1083 ObtainWriteLock(&tvc->lock, 51);
1085 code = afs_InitReq(treq, afs_osi_credp);
1088 break; /* shutting down: do not try to extend the lock */
1090 treq->flags |= O_NONBLOCK;
1092 tc = afs_Conn(&tvc->f.fid, treq, SHARED_LOCK, &rxconn);
1094 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1097 RXAFS_ExtendLock(rxconn,
1098 (struct AFSFid *)&tvc->f.fid.Fid,
1104 } while (afs_Analyze
1105 (tc, rxconn, code, &tvc->f.fid, treq,
1106 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1108 ReleaseWriteLock(&tvc->lock);
1109 #ifdef AFS_DARWIN80_ENV
1111 ObtainReadLock(&afs_xvcache);
1113 ObtainReadLock(&afs_xvcache);
1118 if ((tvc->f.states & CCore) || (tvc->f.states & CUnlinkedDel)) {
1120 * Don't let it evaporate in case someone else is in
1121 * this code. Also, drop the afs_xvcache lock while
1122 * getting vcache locks.
1125 ReleaseReadLock(&afs_xvcache);
1126 #if defined(AFS_SGI_ENV)
1128 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1130 osi_Assert(VREFCOUNT_GT(tvc,0));
1131 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1133 ObtainWriteLock(&tvc->lock, 52);
1134 if (tvc->f.states & CCore) {
1135 tvc->f.states &= ~CCore;
1136 /* XXXX Find better place-holder for cred XXXX */
1137 cred = (afs_ucred_t *)tvc->linkData;
1138 tvc->linkData = NULL; /* XXX */
1139 code = afs_InitReq(treq, cred);
1140 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1141 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1142 tvc->execsOrWriters);
1143 if (!code) { /* avoid store when shutting down */
1144 code = afs_StoreOnLastReference(tvc, treq);
1146 ReleaseWriteLock(&tvc->lock);
1147 hzero(tvc->flushDV);
1150 if (code && code != VNOVNODE) {
1151 afs_StoreWarn(code, tvc->f.fid.Fid.Volume,
1152 /* /dev/console */ 1);
1154 } else if (tvc->f.states & CUnlinkedDel) {
1158 ReleaseWriteLock(&tvc->lock);
1159 #if defined(AFS_SGI_ENV)
1160 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1162 afs_remunlink(tvc, 0);
1163 #if defined(AFS_SGI_ENV)
1164 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1167 /* lost (or won, perhaps) the race condition */
1168 ReleaseWriteLock(&tvc->lock);
1170 #if defined(AFS_SGI_ENV)
1171 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1173 #ifdef AFS_DARWIN80_ENV
1176 AFS_RELE(AFSTOV(tvc));
1177 /* Matches write code setting CCore flag */
1180 ObtainReadLock(&afs_xvcache);
1182 ObtainReadLock(&afs_xvcache);
1185 AFS_RELE(AFSTOV(tvc));
1186 /* Matches write code setting CCore flag */
1193 ReleaseReadLock(&afs_xvcache);
1194 afs_DestroyReq(treq);
1200 * Make sure a cache entry is up-to-date status-wise.
1202 * NOTE: everywhere that calls this can potentially be sped up
1203 * by checking CStatd first, and avoiding doing the InitReq
1204 * if this is up-to-date.
1206 * Anymore, the only places that call this KNOW already that the
1207 * vcache is not up-to-date, so we don't screw around.
1209 * \param avc : Ptr to vcache entry to verify.
1215 * Make sure a cache entry is up-to-date status-wise.
1217 * NOTE: everywhere that calls this can potentially be sped up
1218 * by checking CStatd first, and avoiding doing the InitReq
1219 * if this is up-to-date.
1221 * Anymore, the only places that call this KNOW already that the
1222 * vcache is not up-to-date, so we don't screw around.
1224 * \param avc Pointer to vcache entry to verify.
1227 * \return 0 for success or other error codes.
1230 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1234 AFS_STATCNT(afs_VerifyVCache);
1236 /* otherwise we must fetch the status info */
1238 ObtainWriteLock(&avc->lock, 53);
1239 if (avc->f.states & CStatd) {
1240 ReleaseWriteLock(&avc->lock);
1243 ObtainWriteLock(&afs_xcbhash, 461);
1244 avc->f.states &= ~(CStatd | CUnique);
1245 avc->callback = NULL;
1246 afs_DequeueCallback(avc);
1247 ReleaseWriteLock(&afs_xcbhash);
1248 ReleaseWriteLock(&avc->lock);
1250 /* since we've been called back, or the callback has expired,
1251 * it's possible that the contents of this directory, or this
1252 * file's name have changed, thus invalidating the dnlc contents.
1254 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1255 osi_dnlc_purgedp(avc);
1257 osi_dnlc_purgevp(avc);
1259 /* fetch the status info */
1260 tvc = afs_GetVCache(&avc->f.fid, areq, NULL, avc);
1263 /* Put it back; caller has already incremented vrefCount */
1267 } /*afs_VerifyVCache */
1271 * Simple copy of stat info into cache.
1273 * Callers:as of 1992-04-29, only called by WriteVCache
1275 * \param avc Ptr to vcache entry involved.
1276 * \param astat Ptr to stat info to copy.
1280 afs_SimpleVStat(struct vcache *avc,
1281 struct AFSFetchStatus *astat, struct vrequest *areq)
1284 AFS_STATCNT(afs_SimpleVStat);
1286 #ifdef AFS_64BIT_CLIENT
1287 FillInt64(length, astat->Length_hi, astat->Length);
1288 #else /* AFS_64BIT_CLIENT */
1289 length = astat->Length;
1290 #endif /* AFS_64BIT_CLIENT */
1292 #if defined(AFS_SGI_ENV)
1293 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1294 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1295 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1296 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1297 if (length < avc->f.m.Length) {
1298 vnode_t *vp = (vnode_t *) avc;
1300 osi_Assert(WriteLocked(&avc->lock));
1301 ReleaseWriteLock(&avc->lock);
1303 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1305 ObtainWriteLock(&avc->lock, 67);
1310 if (!afs_DirtyPages(avc)) {
1311 /* if actively writing the file, don't fetch over this value */
1312 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1313 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1314 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1315 avc->f.m.Length = length;
1316 avc->f.m.Date = astat->ClientModTime;
1318 avc->f.m.Owner = astat->Owner;
1319 avc->f.m.Group = astat->Group;
1320 avc->f.m.Mode = astat->UnixModeBits;
1321 if (vType(avc) == VREG) {
1322 avc->f.m.Mode |= S_IFREG;
1323 } else if (vType(avc) == VDIR) {
1324 avc->f.m.Mode |= S_IFDIR;
1325 } else if (vType(avc) == VLNK) {
1326 avc->f.m.Mode |= S_IFLNK;
1327 if ((avc->f.m.Mode & 0111) == 0)
1328 avc->mvstat = AFS_MVSTAT_MTPT;
1330 if (avc->f.states & CForeign) {
1331 struct axscache *ac;
1332 avc->f.anyAccess = astat->AnonymousAccess;
1334 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1336 * Caller has at least one bit not covered by anonymous, and
1337 * thus may have interesting rights.
1339 * HOWEVER, this is a really bad idea, because any access query
1340 * for bits which aren't covered by anonymous, on behalf of a user
1341 * who doesn't have any special rights, will result in an answer of
1342 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1343 * It's an especially bad idea under Ultrix, since (due to the lack of
1344 * a proper access() call) it must perform several afs_access() calls
1345 * in order to create magic mode bits that vary according to who makes
1346 * the call. In other words, _every_ stat() generates a test for
1349 #endif /* badidea */
1350 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1351 ac->axess = astat->CallerAccess;
1352 else /* not found, add a new one if possible */
1353 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1356 } /*afs_SimpleVStat */
1360 * Store the status info *only* back to the server for a
1363 * Environment: Must be called with a shared lock held on the vnode.
1365 * \param avc Ptr to the vcache entry.
1366 * \param astatus Ptr to the status info to store.
1367 * \param areq Ptr to the associated vrequest.
1369 * \return Operation status.
1373 afs_WriteVCache(struct vcache *avc,
1374 struct AFSStoreStatus *astatus,
1375 struct vrequest *areq)
1378 struct afs_conn *tc;
1379 struct AFSFetchStatus OutStatus;
1380 struct AFSVolSync tsync;
1381 struct rx_connection *rxconn;
1383 AFS_STATCNT(afs_WriteVCache);
1384 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1385 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length));
1387 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1389 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1392 RXAFS_StoreStatus(rxconn, (struct AFSFid *)&avc->f.fid.Fid,
1393 astatus, &OutStatus, &tsync);
1398 } while (afs_Analyze
1399 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1400 SHARED_LOCK, NULL));
1402 UpgradeSToWLock(&avc->lock, 20);
1404 /* success, do the changes locally */
1405 afs_SimpleVStat(avc, &OutStatus, areq);
1407 * Update the date, too. SimpleVStat didn't do this, since
1408 * it thought we were doing this after fetching new status
1409 * over a file being written.
1411 avc->f.m.Date = OutStatus.ClientModTime;
1413 /* failure, set up to check with server next time */
1414 ObtainWriteLock(&afs_xcbhash, 462);
1415 afs_DequeueCallback(avc);
1416 avc->f.states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1417 ReleaseWriteLock(&afs_xcbhash);
1418 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1419 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1421 ConvertWToSLock(&avc->lock);
1424 } /*afs_WriteVCache */
1427 * Store status info only locally, set the proper disconnection flags
1428 * and add to dirty list.
1430 * \param avc The vcache to be written locally.
1431 * \param astatus Get attr fields from local store.
1432 * \param attrs This one is only of the vs_size.
1434 * \note Must be called with a shared lock on the vnode
1437 afs_WriteVCacheDiscon(struct vcache *avc,
1438 struct AFSStoreStatus *astatus,
1439 struct vattr *attrs)
1442 afs_int32 flags = 0;
1444 UpgradeSToWLock(&avc->lock, 700);
1446 if (!astatus->Mask) {
1452 /* Set attributes. */
1453 if (astatus->Mask & AFS_SETMODTIME) {
1454 avc->f.m.Date = astatus->ClientModTime;
1455 flags |= VDisconSetTime;
1458 if (astatus->Mask & AFS_SETOWNER) {
1459 /* printf("Not allowed yet. \n"); */
1460 /*avc->f.m.Owner = astatus->Owner;*/
1463 if (astatus->Mask & AFS_SETGROUP) {
1464 /* printf("Not allowed yet. \n"); */
1465 /*avc->f.m.Group = astatus->Group;*/
1468 if (astatus->Mask & AFS_SETMODE) {
1469 avc->f.m.Mode = astatus->UnixModeBits;
1471 #if 0 /* XXX: Leaving this out, so it doesn't mess up the file type flag.*/
1473 if (vType(avc) == VREG) {
1474 avc->f.m.Mode |= S_IFREG;
1475 } else if (vType(avc) == VDIR) {
1476 avc->f.m.Mode |= S_IFDIR;
1477 } else if (vType(avc) == VLNK) {
1478 avc->f.m.Mode |= S_IFLNK;
1479 if ((avc->f.m.Mode & 0111) == 0)
1480 avc->mvstat = AFS_MVSTAT_MTPT;
1483 flags |= VDisconSetMode;
1484 } /* if(astatus.Mask & AFS_SETMODE) */
1486 } /* if (!astatus->Mask) */
1488 if (attrs->va_size > 0) {
1489 /* XXX: Do I need more checks? */
1490 /* Truncation operation. */
1491 flags |= VDisconTrunc;
1495 afs_DisconAddDirty(avc, flags, 1);
1497 /* XXX: How about the rest of the fields? */
1499 ConvertWToSLock(&avc->lock);
1505 * Copy astat block into vcache info
1507 * \note This code may get dataversion and length out of sync if the file has
1508 * been modified. This is less than ideal. I haven't thought about it sufficiently
1509 * to be certain that it is adequate.
1511 * \note Environment: Must be called under a write lock
1513 * \param avc Ptr to vcache entry.
1514 * \param astat Ptr to stat block to copy in.
1515 * \param areq Ptr to associated request.
1518 afs_ProcessFS(struct vcache *avc,
1519 struct AFSFetchStatus *astat, struct vrequest *areq)
1522 AFS_STATCNT(afs_ProcessFS);
1524 #ifdef AFS_64BIT_CLIENT
1525 FillInt64(length, astat->Length_hi, astat->Length);
1526 #else /* AFS_64BIT_CLIENT */
1527 length = astat->Length;
1528 #endif /* AFS_64BIT_CLIENT */
1529 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1530 * number for each bulk status request. Under no circumstances
1531 * should afs_DoBulkStat store a sequence number if the new
1532 * length will be ignored when afs_ProcessFS is called with
1533 * new stats. If you change the following conditional then you
1534 * also need to change the conditional in afs_DoBulkStat. */
1536 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1537 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1539 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1541 /* if we're writing or mapping this file, don't fetch over these
1544 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1545 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1546 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1547 avc->f.m.Length = length;
1548 avc->f.m.Date = astat->ClientModTime;
1550 hset64(avc->f.m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1551 avc->f.m.Owner = astat->Owner;
1552 avc->f.m.Mode = astat->UnixModeBits;
1553 avc->f.m.Group = astat->Group;
1554 avc->f.m.LinkCount = astat->LinkCount;
1555 if (astat->FileType == File) {
1556 vSetType(avc, VREG);
1557 avc->f.m.Mode |= S_IFREG;
1558 } else if (astat->FileType == Directory) {
1559 vSetType(avc, VDIR);
1560 avc->f.m.Mode |= S_IFDIR;
1561 } else if (astat->FileType == SymbolicLink) {
1562 if (afs_fakestat_enable && (avc->f.m.Mode & 0111) == 0) {
1563 vSetType(avc, VDIR);
1564 avc->f.m.Mode |= S_IFDIR;
1566 vSetType(avc, VLNK);
1567 avc->f.m.Mode |= S_IFLNK;
1569 if ((avc->f.m.Mode & 0111) == 0) {
1570 avc->mvstat = AFS_MVSTAT_MTPT;
1573 avc->f.anyAccess = astat->AnonymousAccess;
1575 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1577 * Caller has at least one bit not covered by anonymous, and
1578 * thus may have interesting rights.
1580 * HOWEVER, this is a really bad idea, because any access query
1581 * for bits which aren't covered by anonymous, on behalf of a user
1582 * who doesn't have any special rights, will result in an answer of
1583 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1584 * It's an especially bad idea under Ultrix, since (due to the lack of
1585 * a proper access() call) it must perform several afs_access() calls
1586 * in order to create magic mode bits that vary according to who makes
1587 * the call. In other words, _every_ stat() generates a test for
1590 #endif /* badidea */
1592 struct axscache *ac;
1593 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1594 ac->axess = astat->CallerAccess;
1595 else /* not found, add a new one if possible */
1596 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1598 } /*afs_ProcessFS */
1602 * Get fid from server.
1605 * \param areq Request to be passed on.
1606 * \param name Name of ?? to lookup.
1607 * \param OutStatus Fetch status.
1612 * \return Success status of operation.
1615 afs_RemoteLookup(struct VenusFid *afid, struct vrequest *areq,
1616 char *name, struct VenusFid *nfid,
1617 struct AFSFetchStatus *OutStatusp,
1618 struct AFSCallBack *CallBackp, struct server **serverp,
1619 struct AFSVolSync *tsyncp)
1622 struct afs_conn *tc;
1623 struct rx_connection *rxconn;
1624 struct AFSFetchStatus OutDirStatus;
1627 name = ""; /* XXX */
1629 tc = afs_Conn(afid, areq, SHARED_LOCK, &rxconn);
1632 *serverp = tc->parent->srvr->server;
1633 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1636 RXAFS_Lookup(rxconn, (struct AFSFid *)&afid->Fid, name,
1637 (struct AFSFid *)&nfid->Fid, OutStatusp,
1638 &OutDirStatus, CallBackp, tsyncp);
1643 } while (afs_Analyze
1644 (tc, rxconn, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1654 * Given a file id and a vrequest structure, fetch the status
1655 * information associated with the file.
1657 * \param afid File ID.
1658 * \param areq Ptr to associated vrequest structure, specifying the
1659 * user whose authentication tokens will be used.
1660 * \param avc Caller may already have a vcache for this file, which is
1663 * \note Environment:
1664 * The cache entry is returned with an increased vrefCount field.
1665 * The entry must be discarded by calling afs_PutVCache when you
1666 * are through using the pointer to the cache entry.
1668 * You should not hold any locks when calling this function, except
1669 * locks on other vcache entries. If you lock more than one vcache
1670 * entry simultaneously, you should lock them in this order:
1672 * 1. Lock all files first, then directories.
1673 * 2. Within a particular type, lock entries in Fid.Vnode order.
1675 * This locking hierarchy is convenient because it allows locking
1676 * of a parent dir cache entry, given a file (to check its access
1677 * control list). It also allows renames to be handled easily by
1678 * locking directories in a constant order.
1680 * \note NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1682 * \note Might have a vcache structure already, which must
1683 * already be held by the caller
1686 afs_GetVCache(struct VenusFid *afid, struct vrequest *areq,
1687 afs_int32 * cached, struct vcache *avc)
1690 afs_int32 code, newvcache = 0;
1695 AFS_STATCNT(afs_GetVCache);
1698 *cached = 0; /* Init just in case */
1700 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1704 ObtainSharedLock(&afs_xvcache, 5);
1706 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU | IS_SLOCK);
1708 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1709 ReleaseSharedLock(&afs_xvcache);
1710 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1717 osi_Assert((tvc->f.states & CVInit) == 0);
1718 /* If we are in readdir, return the vnode even if not statd */
1719 if ((tvc->f.states & CStatd) || afs_InReadDir(tvc)) {
1720 ReleaseSharedLock(&afs_xvcache);
1724 UpgradeSToWLock(&afs_xvcache, 21);
1726 /* no cache entry, better grab one */
1727 tvc = afs_NewVCache(afid, NULL);
1730 ConvertWToSLock(&afs_xvcache);
1733 ReleaseSharedLock(&afs_xvcache);
1737 afs_stats_cmperf.vcacheMisses++;
1740 ReleaseSharedLock(&afs_xvcache);
1742 ObtainWriteLock(&tvc->lock, 54);
1744 if (tvc->f.states & CStatd) {
1745 ReleaseWriteLock(&tvc->lock);
1748 #ifdef AFS_DARWIN80_ENV
1749 /* Darwin 8.0 only has bufs in nfs, so we shouldn't have to worry about them.
1752 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1754 * XXX - I really don't like this. Should try to understand better.
1755 * It seems that sometimes, when we get called, we already hold the
1756 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1757 * We can't drop the vnode lock, because that could result in a race.
1758 * Sometimes, though, we get here and don't hold the vnode lock.
1759 * I hate code paths that sometimes hold locks and sometimes don't.
1760 * In any event, the dodge we use here is to check whether the vnode
1761 * is locked, and if it isn't, then we gain and drop it around the call
1762 * to vinvalbuf; otherwise, we leave it alone.
1765 struct vnode *vp = AFSTOV(tvc);
1768 #if defined(AFS_DARWIN_ENV)
1769 iheldthelock = VOP_ISLOCKED(vp);
1771 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc());
1772 /* this is messy. we can call fsync which will try to reobtain this */
1773 if (VTOAFS(vp) == tvc)
1774 ReleaseWriteLock(&tvc->lock);
1775 if (UBCINFOEXISTS(vp)) {
1776 vinvalbuf(vp, V_SAVE, &afs_osi_cred, current_proc(), PINOD, 0);
1778 if (VTOAFS(vp) == tvc)
1779 ObtainWriteLock(&tvc->lock, 954);
1781 VOP_UNLOCK(vp, LK_EXCLUSIVE, current_proc());
1782 #elif defined(AFS_FBSD80_ENV)
1783 iheldthelock = VOP_ISLOCKED(vp);
1784 if (!iheldthelock) {
1785 /* nosleep/sleep lock order reversal */
1786 int glocked = ISAFS_GLOCK();
1789 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1793 vinvalbuf(vp, V_SAVE, PINOD, 0); /* changed late in 8.0-CURRENT */
1796 #elif defined(AFS_FBSD60_ENV)
1797 iheldthelock = VOP_ISLOCKED(vp, curthread);
1799 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1801 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1804 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1805 #elif defined(AFS_FBSD_ENV)
1806 iheldthelock = VOP_ISLOCKED(vp, curthread);
1808 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1809 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1811 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1812 #elif defined(AFS_OBSD_ENV)
1813 iheldthelock = VOP_ISLOCKED(vp, curproc);
1815 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1816 uvm_vnp_uncache(vp);
1818 VOP_UNLOCK(vp, 0, curproc);
1819 #elif defined(AFS_NBSD40_ENV)
1820 iheldthelock = VOP_ISLOCKED(vp);
1821 if (!iheldthelock) {
1822 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY);
1824 uvm_vnp_uncache(vp);
1832 ObtainWriteLock(&afs_xcbhash, 464);
1833 tvc->f.states &= ~CUnique;
1835 afs_DequeueCallback(tvc);
1836 ReleaseWriteLock(&afs_xcbhash);
1838 /* It is always appropriate to throw away all the access rights? */
1839 afs_FreeAllAxs(&(tvc->Access));
1840 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1842 if ((tvp->states & VForeign)) {
1844 tvc->f.states |= CForeign;
1845 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1846 && (tvp->rootUnique == afid->Fid.Unique)) {
1847 tvc->mvstat = AFS_MVSTAT_ROOT;
1850 if (tvp->states & VRO)
1851 tvc->f.states |= CRO;
1852 if (tvp->states & VBackup)
1853 tvc->f.states |= CBackup;
1854 /* now copy ".." entry back out of volume structure, if necessary */
1855 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvp->dotdot.Fid.Volume != 0) {
1856 if (!tvc->mvid.parent)
1857 tvc->mvid.parent = (struct VenusFid *)
1858 osi_AllocSmallSpace(sizeof(struct VenusFid));
1859 *tvc->mvid.parent = tvp->dotdot;
1861 afs_PutVolume(tvp, READ_LOCK);
1865 afs_RemoveVCB(afid);
1867 struct AFSFetchStatus OutStatus;
1869 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1870 afs_ProcessFS(tvc, &OutStatus, areq);
1871 tvc->f.states |= CStatd | CUnique;
1872 tvc->f.parent.vnode = OutStatus.ParentVnode;
1873 tvc->f.parent.unique = OutStatus.ParentUnique;
1877 if (AFS_IS_DISCONNECTED) {
1878 /* Nothing to do otherwise...*/
1880 /* printf("Network is down in afs_GetCache"); */
1882 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1884 /* For the NFS translator's benefit, make sure
1885 * non-directory vnodes always have their parent FID set
1886 * correctly, even when created as a result of decoding an
1887 * NFS filehandle. It would be nice to also do this for
1888 * directories, but we can't because the fileserver fills
1889 * in the FID of the directory itself instead of that of
1892 if (!code && OutStatus.FileType != Directory &&
1893 !tvc->f.parent.vnode) {
1894 tvc->f.parent.vnode = OutStatus.ParentVnode;
1895 tvc->f.parent.unique = OutStatus.ParentUnique;
1896 /* XXX - SXW - It's conceivable we should mark ourselves
1897 * as dirty again here, incase we've been raced
1898 * out of the FetchStatus call.
1905 ReleaseWriteLock(&tvc->lock);
1911 ReleaseWriteLock(&tvc->lock);
1914 } /*afs_GetVCache */
1919 * Lookup a vcache by fid. Look inside the cache first, if not
1920 * there, lookup the file on the server, and then get it's fresh
1925 * \param cached Is element cached? If NULL, don't answer.
1929 * \return The found element or NULL.
1932 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1933 afs_int32 * cached, struct vcache *adp, char *aname)
1935 afs_int32 code, now, newvcache = 0;
1936 struct VenusFid nfid;
1939 struct AFSFetchStatus OutStatus;
1940 struct AFSCallBack CallBack;
1941 struct AFSVolSync tsync;
1942 struct server *serverp = 0;
1946 AFS_STATCNT(afs_GetVCache);
1948 *cached = 0; /* Init just in case */
1950 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1954 ObtainReadLock(&afs_xvcache);
1955 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
1958 ReleaseReadLock(&afs_xvcache);
1960 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1961 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1965 ObtainReadLock(&tvc->lock);
1967 if (tvc->f.states & CStatd) {
1971 ReleaseReadLock(&tvc->lock);
1974 tvc->f.states &= ~CUnique;
1976 ReleaseReadLock(&tvc->lock);
1978 ObtainReadLock(&afs_xvcache);
1981 ReleaseReadLock(&afs_xvcache);
1983 /* lookup the file */
1986 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1988 if (AFS_IS_DISCONNECTED) {
1989 /* printf("Network is down in afs_LookupVcache\n"); */
1993 afs_RemoteLookup(&adp->f.fid, areq, aname, &nfid, &OutStatus,
1994 &CallBack, &serverp, &tsync);
1996 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2000 ObtainSharedLock(&afs_xvcache, 6);
2001 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU | IS_SLOCK/* no xstats now */ );
2003 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2004 ReleaseSharedLock(&afs_xvcache);
2005 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2011 /* no cache entry, better grab one */
2012 UpgradeSToWLock(&afs_xvcache, 22);
2013 tvc = afs_NewVCache(&nfid, serverp);
2015 ConvertWToSLock(&afs_xvcache);
2018 ReleaseSharedLock(&afs_xvcache);
2023 ReleaseSharedLock(&afs_xvcache);
2024 ObtainWriteLock(&tvc->lock, 55);
2026 /* It is always appropriate to throw away all the access rights? */
2027 afs_FreeAllAxs(&(tvc->Access));
2028 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
2030 if ((tvp->states & VForeign)) {
2032 tvc->f.states |= CForeign;
2033 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
2034 && (tvp->rootUnique == afid->Fid.Unique))
2035 tvc->mvstat = AFS_MVSTAT_ROOT;
2037 if (tvp->states & VRO)
2038 tvc->f.states |= CRO;
2039 if (tvp->states & VBackup)
2040 tvc->f.states |= CBackup;
2041 /* now copy ".." entry back out of volume structure, if necessary */
2042 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvp->dotdot.Fid.Volume != 0) {
2043 if (!tvc->mvid.parent)
2044 tvc->mvid.parent = (struct VenusFid *)
2045 osi_AllocSmallSpace(sizeof(struct VenusFid));
2046 *tvc->mvid.parent = tvp->dotdot;
2051 ObtainWriteLock(&afs_xcbhash, 465);
2052 afs_DequeueCallback(tvc);
2053 tvc->f.states &= ~(CStatd | CUnique);
2054 ReleaseWriteLock(&afs_xcbhash);
2055 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2056 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2058 afs_PutVolume(tvp, READ_LOCK);
2059 ReleaseWriteLock(&tvc->lock);
2064 ObtainWriteLock(&afs_xcbhash, 466);
2065 if (origCBs == afs_allCBs) {
2066 if (CallBack.ExpirationTime) {
2067 tvc->callback = serverp;
2068 tvc->cbExpires = CallBack.ExpirationTime + now;
2069 tvc->f.states |= CStatd | CUnique;
2070 tvc->f.states &= ~CBulkFetching;
2071 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
2072 } else if (tvc->f.states & CRO) {
2073 /* adapt gives us an hour. */
2074 tvc->cbExpires = 3600 + osi_Time();
2075 /*XXX*/ tvc->f.states |= CStatd | CUnique;
2076 tvc->f.states &= ~CBulkFetching;
2077 afs_QueueCallback(tvc, CBHash(3600), tvp);
2079 tvc->callback = NULL;
2080 afs_DequeueCallback(tvc);
2081 tvc->f.states &= ~(CStatd | CUnique);
2082 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2083 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2086 afs_DequeueCallback(tvc);
2087 tvc->f.states &= ~CStatd;
2088 tvc->f.states &= ~CUnique;
2089 tvc->callback = NULL;
2090 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2091 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2093 ReleaseWriteLock(&afs_xcbhash);
2095 afs_PutVolume(tvp, READ_LOCK);
2096 afs_ProcessFS(tvc, &OutStatus, areq);
2098 ReleaseWriteLock(&tvc->lock);
2104 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2105 afs_int32 * cached, struct volume *tvolp)
2107 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2108 afs_int32 getNewFid = 0;
2110 struct VenusFid nfid;
2112 struct server *serverp = 0;
2113 struct AFSFetchStatus OutStatus;
2114 struct AFSCallBack CallBack;
2115 struct AFSVolSync tsync;
2117 #ifdef AFS_DARWIN80_ENV
2124 if (!tvolp->rootVnode || getNewFid) {
2125 struct VenusFid tfid;
2128 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2129 origCBs = afs_allCBs; /* ignore InitCallBackState */
2131 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2136 /* ReleaseReadLock(&tvolp->lock); */
2137 ObtainWriteLock(&tvolp->lock, 56);
2138 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2139 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2140 ReleaseWriteLock(&tvolp->lock);
2141 /* ObtainReadLock(&tvolp->lock);*/
2144 afid->Fid.Vnode = tvolp->rootVnode;
2145 afid->Fid.Unique = tvolp->rootUnique;
2149 ObtainSharedLock(&afs_xvcache, 7);
2151 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2152 if (!FidCmp(&(tvc->f.fid), afid)) {
2153 if (tvc->f.states & CVInit) {
2154 ReleaseSharedLock(&afs_xvcache);
2155 afs_osi_Sleep(&tvc->f.states);
2158 #ifdef AFS_DARWIN80_ENV
2159 if (tvc->f.states & CDeadVnode) {
2160 ReleaseSharedLock(&afs_xvcache);
2161 afs_osi_Sleep(&tvc->f.states);
2165 if (vnode_get(tvp)) /* this bumps ref count */
2167 if (vnode_ref(tvp)) {
2169 /* AFSTOV(tvc) may be NULL */
2179 if (!haveStatus && (!tvc || !(tvc->f.states & CStatd))) {
2180 /* Mount point no longer stat'd or unknown. FID may have changed. */
2182 ReleaseSharedLock(&afs_xvcache);
2183 #ifdef AFS_DARWIN80_ENV
2186 vnode_put(AFSTOV(tvc));
2187 vnode_rele(AFSTOV(tvc));
2196 UpgradeSToWLock(&afs_xvcache, 23);
2197 /* no cache entry, better grab one */
2198 tvc = afs_NewVCache(afid, NULL);
2201 ReleaseWriteLock(&afs_xvcache);
2205 afs_stats_cmperf.vcacheMisses++;
2209 afs_stats_cmperf.vcacheHits++;
2210 #if defined(AFS_DARWIN80_ENV)
2211 /* we already bumped the ref count in the for loop above */
2212 #else /* AFS_DARWIN80_ENV */
2215 UpgradeSToWLock(&afs_xvcache, 24);
2216 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2217 refpanic("GRVC VLRU inconsistent0");
2219 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2220 refpanic("GRVC VLRU inconsistent1");
2222 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2223 refpanic("GRVC VLRU inconsistent2");
2225 QRemove(&tvc->vlruq); /* move to lruq head */
2226 QAdd(&VLRU, &tvc->vlruq);
2227 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2228 refpanic("GRVC VLRU inconsistent3");
2230 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2231 refpanic("GRVC VLRU inconsistent4");
2233 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2234 refpanic("GRVC VLRU inconsistent5");
2239 ReleaseWriteLock(&afs_xvcache);
2241 if (tvc->f.states & CStatd) {
2245 ObtainReadLock(&tvc->lock);
2246 tvc->f.states &= ~CUnique;
2247 tvc->callback = NULL; /* redundant, perhaps */
2248 ReleaseReadLock(&tvc->lock);
2251 ObtainWriteLock(&tvc->lock, 57);
2253 /* It is always appropriate to throw away all the access rights? */
2254 afs_FreeAllAxs(&(tvc->Access));
2257 tvc->f.states |= CForeign;
2258 if (tvolp->states & VRO)
2259 tvc->f.states |= CRO;
2260 if (tvolp->states & VBackup)
2261 tvc->f.states |= CBackup;
2262 /* now copy ".." entry back out of volume structure, if necessary */
2263 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2264 && (tvolp->rootUnique == afid->Fid.Unique)) {
2265 tvc->mvstat = AFS_MVSTAT_ROOT;
2267 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvolp->dotdot.Fid.Volume != 0) {
2268 if (!tvc->mvid.parent)
2269 tvc->mvid.parent = (struct VenusFid *)
2270 osi_AllocSmallSpace(sizeof(struct VenusFid));
2271 *tvc->mvid.parent = tvolp->dotdot;
2275 afs_RemoveVCB(afid);
2278 struct VenusFid tfid;
2281 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2282 origCBs = afs_allCBs; /* ignore InitCallBackState */
2284 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2289 ObtainWriteLock(&afs_xcbhash, 467);
2290 afs_DequeueCallback(tvc);
2291 tvc->callback = NULL;
2292 tvc->f.states &= ~(CStatd | CUnique);
2293 ReleaseWriteLock(&afs_xcbhash);
2294 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2295 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2296 ReleaseWriteLock(&tvc->lock);
2301 ObtainWriteLock(&afs_xcbhash, 468);
2302 if (origCBs == afs_allCBs) {
2303 tvc->f.states |= CTruth;
2304 tvc->callback = serverp;
2305 if (CallBack.ExpirationTime != 0) {
2306 tvc->cbExpires = CallBack.ExpirationTime + start;
2307 tvc->f.states |= CStatd;
2308 tvc->f.states &= ~CBulkFetching;
2309 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2310 } else if (tvc->f.states & CRO) {
2311 /* adapt gives us an hour. */
2312 tvc->cbExpires = 3600 + osi_Time();
2313 /*XXX*/ tvc->f.states |= CStatd;
2314 tvc->f.states &= ~CBulkFetching;
2315 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2318 afs_DequeueCallback(tvc);
2319 tvc->callback = NULL;
2320 tvc->f.states &= ~(CStatd | CUnique);
2321 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2322 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2324 ReleaseWriteLock(&afs_xcbhash);
2325 afs_ProcessFS(tvc, &OutStatus, areq);
2327 ReleaseWriteLock(&tvc->lock);
2333 * Update callback status and (sometimes) attributes of a vnode.
2334 * Called after doing a fetch status RPC. Whilst disconnected, attributes
2335 * shouldn't be written to the vcache here.
2340 * \param Outsp Server status after rpc call.
2341 * \param acb Callback for this vnode.
2343 * \note The vcache must be write locked.
2346 afs_UpdateStatus(struct vcache *avc, struct VenusFid *afid,
2347 struct vrequest *areq, struct AFSFetchStatus *Outsp,
2348 struct AFSCallBack *acb, afs_uint32 start)
2350 struct volume *volp;
2353 /* Dont write status in vcache if resyncing after a disconnection. */
2354 afs_ProcessFS(avc, Outsp, areq);
2356 volp = afs_GetVolume(afid, areq, READ_LOCK);
2357 ObtainWriteLock(&afs_xcbhash, 469);
2358 avc->f.states |= CTruth;
2359 if (avc->callback /* check for race */ ) {
2360 if (acb->ExpirationTime != 0) {
2361 avc->cbExpires = acb->ExpirationTime + start;
2362 avc->f.states |= CStatd;
2363 avc->f.states &= ~CBulkFetching;
2364 afs_QueueCallback(avc, CBHash(acb->ExpirationTime), volp);
2365 } else if (avc->f.states & CRO) {
2366 /* ordinary callback on a read-only volume -- AFS 3.2 style */
2367 avc->cbExpires = 3600 + start;
2368 avc->f.states |= CStatd;
2369 avc->f.states &= ~CBulkFetching;
2370 afs_QueueCallback(avc, CBHash(3600), volp);
2372 afs_DequeueCallback(avc);
2373 avc->callback = NULL;
2374 avc->f.states &= ~(CStatd | CUnique);
2375 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2376 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2379 afs_DequeueCallback(avc);
2380 avc->callback = NULL;
2381 avc->f.states &= ~(CStatd | CUnique);
2382 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2383 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2385 ReleaseWriteLock(&afs_xcbhash);
2387 afs_PutVolume(volp, READ_LOCK);
2391 afs_BadFetchStatus(struct afs_conn *tc)
2393 int addr = ntohl(tc->parent->srvr->sa_ip);
2394 afs_warn("afs: Invalid AFSFetchStatus from server %u.%u.%u.%u\n",
2395 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2397 afs_warn("afs: This suggests the server may be sending bad data that "
2398 "can lead to availability issues or data corruption. The "
2399 "issue has been avoided for now, but it may not always be "
2400 "detectable. Please upgrade the server if possible.\n");
2404 * Check if a given AFSFetchStatus structure is sane.
2406 * @param[in] tc The server from which we received the status
2407 * @param[in] status The status we received
2409 * @return whether the given structure is valid or not
2410 * @retval 0 the structure is fine
2411 * @retval nonzero the structure looks like garbage; act as if we received
2412 * the returned error code from the server
2415 afs_CheckFetchStatus(struct afs_conn *tc, struct AFSFetchStatus *status)
2417 if (status->errorCode ||
2418 status->InterfaceVersion != 1 ||
2419 !(status->FileType > Invalid && status->FileType <= SymbolicLink) ||
2420 status->ParentVnode == 0 || status->ParentUnique == 0) {
2422 afs_warn("afs: FetchStatus ec %u iv %u ft %u pv %u pu %u\n",
2423 (unsigned)status->errorCode, (unsigned)status->InterfaceVersion,
2424 (unsigned)status->FileType, (unsigned)status->ParentVnode,
2425 (unsigned)status->ParentUnique);
2426 afs_BadFetchStatus(tc);
2434 * Must be called with avc write-locked
2435 * don't absolutely have to invalidate the hint unless the dv has
2436 * changed, but be sure to get it right else there will be consistency bugs.
2439 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2440 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2443 afs_uint32 start = 0;
2444 struct afs_conn *tc;
2445 struct AFSCallBack CallBack;
2446 struct AFSVolSync tsync;
2447 struct rx_connection *rxconn;
2450 tc = afs_Conn(afid, areq, SHARED_LOCK, &rxconn);
2451 avc->dchint = NULL; /* invalidate hints */
2453 avc->callback = tc->parent->srvr->server;
2455 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2458 RXAFS_FetchStatus(rxconn, (struct AFSFid *)&afid->Fid, Outsp,
2465 code = afs_CheckFetchStatus(tc, Outsp);
2470 } while (afs_Analyze
2471 (tc, rxconn, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2472 SHARED_LOCK, NULL));
2475 afs_UpdateStatus(avc, afid, areq, Outsp, &CallBack, start);
2477 /* used to undo the local callback, but that's too extreme.
2478 * There are plenty of good reasons that fetchstatus might return
2479 * an error, such as EPERM. If we have the vnode cached, statd,
2480 * with callback, might as well keep track of the fact that we
2481 * don't have access...
2483 if (code == EPERM || code == EACCES) {
2484 struct axscache *ac;
2485 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2487 else /* not found, add a new one if possible */
2488 afs_AddAxs(avc->Access, areq->uid, 0);
2499 * Stuff some information into the vcache for the given file.
2502 * afid : File in question.
2503 * OutStatus : Fetch status on the file.
2504 * CallBack : Callback info.
2505 * tc : RPC connection involved.
2506 * areq : vrequest involved.
2509 * Nothing interesting.
2512 afs_StuffVcache(struct VenusFid *afid,
2513 struct AFSFetchStatus *OutStatus,
2514 struct AFSCallBack *CallBack, struct afs_conn *tc,
2515 struct vrequest *areq)
2517 afs_int32 code, i, newvcache = 0;
2519 struct AFSVolSync tsync;
2521 struct axscache *ac;
2524 AFS_STATCNT(afs_StuffVcache);
2525 #ifdef IFS_VCACHECOUNT
2530 ObtainSharedLock(&afs_xvcache, 8);
2532 tvc = afs_FindVCache(afid, &retry, DO_VLRU| IS_SLOCK /* no stats */ );
2534 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2535 ReleaseSharedLock(&afs_xvcache);
2536 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2542 /* no cache entry, better grab one */
2543 UpgradeSToWLock(&afs_xvcache, 25);
2544 tvc = afs_NewVCache(afid, NULL);
2546 ConvertWToSLock(&afs_xvcache);
2549 ReleaseSharedLock(&afs_xvcache);
2554 ReleaseSharedLock(&afs_xvcache);
2555 ObtainWriteLock(&tvc->lock, 58);
2557 tvc->f.states &= ~CStatd;
2558 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2559 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2561 /* Is it always appropriate to throw away all the access rights? */
2562 afs_FreeAllAxs(&(tvc->Access));
2564 /*Copy useful per-volume info */
2565 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2567 if (newvcache && (tvp->states & VForeign))
2568 tvc->f.states |= CForeign;
2569 if (tvp->states & VRO)
2570 tvc->f.states |= CRO;
2571 if (tvp->states & VBackup)
2572 tvc->f.states |= CBackup;
2574 * Now, copy ".." entry back out of volume structure, if
2577 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvp->dotdot.Fid.Volume != 0) {
2578 if (!tvc->mvid.parent)
2579 tvc->mvid.parent = (struct VenusFid *)
2580 osi_AllocSmallSpace(sizeof(struct VenusFid));
2581 *tvc->mvid.parent = tvp->dotdot;
2584 /* store the stat on the file */
2585 afs_RemoveVCB(afid);
2586 afs_ProcessFS(tvc, OutStatus, areq);
2587 tvc->callback = tc->srvr->server;
2589 /* we use osi_Time twice below. Ideally, we would use the time at which
2590 * the FetchStatus call began, instead, but we don't have it here. So we
2591 * make do with "now". In the CRO case, it doesn't really matter. In
2592 * the other case, we hope that the difference between "now" and when the
2593 * call actually began execution on the server won't be larger than the
2594 * padding which the server keeps. Subtract 1 second anyway, to be on
2595 * the safe side. Can't subtract more because we don't know how big
2596 * ExpirationTime is. Possible consistency problems may arise if the call
2597 * timeout period becomes longer than the server's expiration padding. */
2598 ObtainWriteLock(&afs_xcbhash, 470);
2599 if (CallBack->ExpirationTime != 0) {
2600 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2601 tvc->f.states |= CStatd;
2602 tvc->f.states &= ~CBulkFetching;
2603 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2604 } else if (tvc->f.states & CRO) {
2605 /* old-fashioned AFS 3.2 style */
2606 tvc->cbExpires = 3600 + osi_Time();
2607 /*XXX*/ tvc->f.states |= CStatd;
2608 tvc->f.states &= ~CBulkFetching;
2609 afs_QueueCallback(tvc, CBHash(3600), tvp);
2611 afs_DequeueCallback(tvc);
2612 tvc->callback = NULL;
2613 tvc->f.states &= ~(CStatd | CUnique);
2614 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2615 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2617 ReleaseWriteLock(&afs_xcbhash);
2619 afs_PutVolume(tvp, READ_LOCK);
2621 /* look in per-pag cache */
2622 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2623 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2624 else /* not found, add a new one if possible */
2625 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2627 ReleaseWriteLock(&tvc->lock);
2628 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2629 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2630 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2632 * Release ref count... hope this guy stays around...
2635 } /*afs_StuffVcache */
2639 * Decrements the reference count on a cache entry.
2641 * \param avc Pointer to the cache entry to decrement.
2643 * \note Environment: Nothing interesting.
2646 afs_PutVCache(struct vcache *avc)
2648 AFS_STATCNT(afs_PutVCache);
2649 #ifdef AFS_DARWIN80_ENV
2650 vnode_put(AFSTOV(avc));
2654 * Can we use a read lock here?
2656 ObtainReadLock(&afs_xvcache);
2658 ReleaseReadLock(&afs_xvcache);
2660 } /*afs_PutVCache */
2664 * Reset a vcache entry, so local contents are ignored, and the
2665 * server will be reconsulted next time the vcache is used
2667 * \param avc Pointer to the cache entry to reset
2669 * \param skipdnlc skip the dnlc purge for this vnode
2671 * \note avc must be write locked on entry
2673 * \note The caller should purge the dnlc when skipdnlc is set.
2676 afs_ResetVCache(struct vcache *avc, afs_ucred_t *acred, afs_int32 skipdnlc)
2678 ObtainWriteLock(&afs_xcbhash, 456);
2679 afs_DequeueCallback(avc);
2680 avc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat */
2681 ReleaseWriteLock(&afs_xcbhash);
2682 /* now find the disk cache entries */
2683 afs_TryToSmush(avc, acred, 1);
2685 osi_dnlc_purgedp(avc);
2687 if (avc->linkData && !(avc->f.states & CCore)) {
2688 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
2689 avc->linkData = NULL;
2694 * Sleepa when searching for a vcache. Releases all the pending locks,
2695 * sleeps then obtains the previously released locks.
2697 * \param vcache Enter sleep state.
2698 * \param flag Determines what locks to use.
2703 findvc_sleep(struct vcache *avc, int flag)
2705 if (flag & IS_SLOCK) {
2706 ReleaseSharedLock(&afs_xvcache);
2708 if (flag & IS_WLOCK) {
2709 ReleaseWriteLock(&afs_xvcache);
2711 ReleaseReadLock(&afs_xvcache);
2714 afs_osi_Sleep(&avc->f.states);
2715 if (flag & IS_SLOCK) {
2716 ObtainSharedLock(&afs_xvcache, 341);
2718 if (flag & IS_WLOCK) {
2719 ObtainWriteLock(&afs_xvcache, 343);
2721 ObtainReadLock(&afs_xvcache);
2727 * Add a reference on an existing vcache entry.
2729 * \param tvc Pointer to the vcache.
2731 * \note Environment: Must be called with at least one reference from
2732 * elsewhere on the vcache, even if that reference will be dropped.
2733 * The global lock is required.
2735 * \return 0 on success, -1 on failure.
2739 afs_RefVCache(struct vcache *tvc)
2741 #ifdef AFS_DARWIN80_ENV
2745 /* AFS_STATCNT(afs_RefVCache); */
2747 #ifdef AFS_DARWIN80_ENV
2751 if (vnode_ref(tvp)) {
2753 /* AFSTOV(tvc) may be NULL */
2762 } /*afs_RefVCache */
2765 * Find a vcache entry given a fid.
2767 * \param afid Pointer to the fid whose cache entry we desire.
2768 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2769 * unlock the vnode, and try again.
2770 * \param flag Bit 1 to specify whether to compute hit statistics. Not
2771 * set if FindVCache is called as part of internal bookkeeping.
2773 * \note Environment: Must be called with the afs_xvcache lock at least held at
2774 * the read level. In order to do the VLRU adjustment, the xvcache lock
2775 * must be shared-- we upgrade it here.
2779 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2784 #ifdef AFS_DARWIN80_ENV
2785 struct vcache *deadvc = NULL, *livevc = NULL;
2789 AFS_STATCNT(afs_FindVCache);
2793 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2794 if (FidMatches(afid, tvc)) {
2795 if (tvc->f.states & CVInit) {
2796 findvc_sleep(tvc, flag);
2799 #ifdef AFS_DARWIN80_ENV
2800 if (tvc->f.states & CDeadVnode) {
2801 findvc_sleep(tvc, flag);
2809 /* should I have a read lock on the vnode here? */
2813 #if defined(AFS_DARWIN80_ENV)
2817 if (tvp && vnode_ref(tvp)) {
2819 /* AFSTOV(tvc) may be NULL */
2828 #elif defined(AFS_DARWIN_ENV)
2829 tvc->f.states |= CUBCinit;
2831 if (UBCINFOMISSING(AFSTOV(tvc)) ||
2832 UBCINFORECLAIMED(AFSTOV(tvc))) {
2833 ubc_info_init(AFSTOV(tvc));
2836 tvc->f.states &= ~CUBCinit;
2838 osi_vnhold(tvc, retry); /* already held, above */
2839 if (retry && *retry)
2843 * only move to front of vlru if we have proper vcache locking)
2845 if (flag & DO_VLRU) {
2846 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2847 refpanic("FindVC VLRU inconsistent1");
2849 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2850 refpanic("FindVC VLRU inconsistent1");
2852 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2853 refpanic("FindVC VLRU inconsistent2");
2855 UpgradeSToWLock(&afs_xvcache, 26);
2856 QRemove(&tvc->vlruq);
2857 QAdd(&VLRU, &tvc->vlruq);
2858 ConvertWToSLock(&afs_xvcache);
2859 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2860 refpanic("FindVC VLRU inconsistent1");
2862 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2863 refpanic("FindVC VLRU inconsistent2");
2865 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2866 refpanic("FindVC VLRU inconsistent3");
2872 if (flag & DO_STATS) {
2874 afs_stats_cmperf.vcacheHits++;
2876 afs_stats_cmperf.vcacheMisses++;
2877 if (afs_IsPrimaryCellNum(afid->Cell))
2878 afs_stats_cmperf.vlocalAccesses++;
2880 afs_stats_cmperf.vremoteAccesses++;
2883 } /*afs_FindVCache */
2886 * Find a vcache entry given a fid. Does a wildcard match on what we
2887 * have for the fid. If more than one entry, don't return anything.
2889 * \param avcp Fill in pointer if we found one and only one.
2890 * \param afid Pointer to the fid whose cache entry we desire.
2891 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2892 * unlock the vnode, and try again.
2893 * \param flags bit 1 to specify whether to compute hit statistics. Not
2894 * set if FindVCache is called as part of internal bookkeeping.
2896 * \note Environment: Must be called with the afs_xvcache lock at least held at
2897 * the read level. In order to do the VLRU adjustment, the xvcache lock
2898 * must be shared-- we upgrade it here.
2900 * \return Number of matches found.
2903 int afs_duplicate_nfs_fids = 0;
2906 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2910 afs_int32 count = 0;
2911 struct vcache *found_tvc = NULL;
2912 #ifdef AFS_DARWIN80_ENV
2916 AFS_STATCNT(afs_FindVCache);
2920 ObtainSharedLock(&afs_xvcache, 331);
2923 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2924 /* Match only on what we have.... */
2925 if (((tvc->f.fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2926 && (tvc->f.fid.Fid.Volume == afid->Fid.Volume)
2927 && ((tvc->f.fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2928 && (tvc->f.fid.Cell == afid->Cell)) {
2929 if (tvc->f.states & CVInit) {
2930 ReleaseSharedLock(&afs_xvcache);
2931 afs_osi_Sleep(&tvc->f.states);
2934 #ifdef AFS_DARWIN80_ENV
2935 if (tvc->f.states & CDeadVnode) {
2936 ReleaseSharedLock(&afs_xvcache);
2937 afs_osi_Sleep(&tvc->f.states);
2941 if (vnode_get(tvp)) {
2942 /* This vnode no longer exists. */
2945 if (vnode_ref(tvp)) {
2946 /* This vnode no longer exists. */
2948 /* AFSTOV(tvc) may be NULL */
2953 #endif /* AFS_DARWIN80_ENV */
2957 afs_duplicate_nfs_fids++;
2958 ReleaseSharedLock(&afs_xvcache);
2959 #ifdef AFS_DARWIN80_ENV
2960 /* Drop our reference counts. */
2961 vnode_put(AFSTOV(tvc));
2962 vnode_put(AFSTOV(found_tvc));
2971 /* should I have a read lock on the vnode here? */
2973 #ifndef AFS_DARWIN80_ENV
2974 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2975 afs_int32 retry = 0;
2976 osi_vnhold(tvc, &retry);
2979 found_tvc = (struct vcache *)0;
2980 ReleaseSharedLock(&afs_xvcache);
2981 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2985 osi_vnhold(tvc, (int *)0); /* already held, above */
2989 * We obtained the xvcache lock above.
2991 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2992 refpanic("FindVC VLRU inconsistent1");
2994 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2995 refpanic("FindVC VLRU inconsistent1");
2997 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2998 refpanic("FindVC VLRU inconsistent2");
3000 UpgradeSToWLock(&afs_xvcache, 568);
3001 QRemove(&tvc->vlruq);
3002 QAdd(&VLRU, &tvc->vlruq);
3003 ConvertWToSLock(&afs_xvcache);
3004 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
3005 refpanic("FindVC VLRU inconsistent1");
3007 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
3008 refpanic("FindVC VLRU inconsistent2");
3010 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
3011 refpanic("FindVC VLRU inconsistent3");
3017 afs_stats_cmperf.vcacheHits++;
3019 afs_stats_cmperf.vcacheMisses++;
3020 if (afs_IsPrimaryCellNum(afid->Cell))
3021 afs_stats_cmperf.vlocalAccesses++;
3023 afs_stats_cmperf.vremoteAccesses++;
3025 *avcp = tvc; /* May be null */
3027 ReleaseSharedLock(&afs_xvcache);
3028 return (tvc ? 1 : 0);
3030 } /*afs_NFSFindVCache */
3036 * Initialize vcache related variables
3041 afs_vcacheInit(int astatSize)
3043 #if !defined(AFS_LINUX22_ENV)
3047 if (!afs_maxvcount) {
3048 afs_maxvcount = astatSize; /* no particular limit on linux? */
3050 #if !defined(AFS_LINUX22_ENV)
3054 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3055 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3057 #if !defined(AFS_LINUX22_ENV)
3058 /* Allocate and thread the struct vcache entries */
3059 tvp = afs_osi_Alloc(astatSize * sizeof(struct vcache));
3060 osi_Assert(tvp != NULL);
3061 memset(tvp, 0, sizeof(struct vcache) * astatSize);
3063 Initial_freeVCList = tvp;
3064 freeVCList = &(tvp[0]);
3065 for (i = 0; i < astatSize - 1; i++) {
3066 tvp[i].nextfree = &(tvp[i + 1]);
3068 tvp[astatSize - 1].nextfree = NULL;
3069 # ifdef KERNEL_HAVE_PIN
3070 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
3074 #if defined(AFS_SGI_ENV)
3075 for (i = 0; i < astatSize; i++) {
3076 char name[METER_NAMSZ];
3077 struct vcache *tvc = &tvp[i];
3079 tvc->v.v_number = ++afsvnumbers;
3080 tvc->vc_rwlockid = OSI_NO_LOCKID;
3081 initnsema(&tvc->vc_rwlock, 1,
3082 makesname(name, "vrw", tvc->v.v_number));
3083 #ifndef AFS_SGI53_ENV
3084 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
3086 #ifndef AFS_SGI62_ENV
3087 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
3088 #endif /* AFS_SGI62_ENV */
3092 for(i = 0; i < VCSIZE; ++i)
3093 QInit(&afs_vhashTV[i]);
3100 shutdown_vcache(void)
3103 struct afs_cbr *tsp;
3105 * XXX We may potentially miss some of the vcaches because if when
3106 * there are no free vcache entries and all the vcache entries are active
3107 * ones then we allocate an additional one - admittedly we almost never
3112 struct afs_q *tq, *uq = NULL;
3114 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
3117 if (tvc->mvid.target_root) {
3118 osi_FreeSmallSpace(tvc->mvid.target_root);
3119 tvc->mvid.target_root = NULL;
3122 aix_gnode_rele(AFSTOV(tvc));
3124 if (tvc->linkData) {
3125 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3130 * Also free the remaining ones in the Cache
3132 for (i = 0; i < VCSIZE; i++) {
3133 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3134 if (tvc->mvid.target_root) {
3135 osi_FreeSmallSpace(tvc->mvid.target_root);
3136 tvc->mvid.target_root = NULL;
3140 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
3141 #ifdef AFS_AIX32_ENV
3144 vms_delete(tvc->segid);
3146 tvc->segid = tvc->vmh = NULL;
3147 if (VREFCOUNT_GT(tvc,0))
3148 osi_Panic("flushVcache: vm race");
3156 #if defined(AFS_SUN5_ENV)
3162 if (tvc->linkData) {
3163 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3168 afs_FreeAllAxs(&(tvc->Access));
3174 * Free any leftover callback queue
3176 for (i = 0; i < afs_stats_cmperf.CallBackAlloced; i++) {
3177 tsp = afs_cbrHeads[i];
3178 afs_cbrHeads[i] = 0;
3179 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
3183 #if !defined(AFS_LINUX22_ENV)
3184 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3186 # ifdef KERNEL_HAVE_PIN
3187 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3190 freeVCList = Initial_freeVCList = 0;
3193 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3194 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3196 for(i = 0; i < VCSIZE; ++i)
3197 QInit(&afs_vhashTV[i]);
3201 afs_DisconGiveUpCallbacks(void)
3207 ObtainWriteLock(&afs_xvcache, 1002); /* XXX - should be a unique number */
3210 /* Somehow, walk the set of vcaches, with each one coming out as tvc */
3211 for (i = 0; i < VCSIZE; i++) {
3212 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3214 if (afs_QueueVCB(tvc, &slept)) {
3215 tvc->callback = NULL;
3224 ReleaseWriteLock(&afs_xvcache);
3231 * Clear the Statd flag from all vcaches
3233 * This function removes the Statd flag from all vcaches. It's used by
3234 * disconnected mode to tidy up during reconnection
3238 afs_ClearAllStatdFlag(void)
3243 ObtainWriteLock(&afs_xvcache, 715);
3245 for (i = 0; i < VCSIZE; i++) {
3246 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3247 tvc->f.states &= ~(CStatd|CUnique);
3250 ReleaseWriteLock(&afs_xvcache);