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)
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)
756 struct afs_q *tq, *uq;
757 int fv_slept, defersleep = 0;
759 afs_int32 target = anumber;
766 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
769 if (tvc->f.states & CVFlushed) {
770 refpanic("CVFlushed on VLRU");
771 } else if (i++ > limit) {
772 afs_warn("afs_ShakeLooseVCaches: i %d limit %d afs_vcount %d afs_maxvcount %d\n",
773 (int)i, limit, (int)afs_vcount, (int)afs_maxvcount);
774 refpanic("Found too many AFS vnodes on VLRU (VLRU cycle?)");
775 } else if (QNext(uq) != tq) {
776 refpanic("VLRU inconsistent");
777 } else if (tvc->f.states & CVInit) {
782 if (osi_TryEvictVCache(tvc, &fv_slept, defersleep))
788 goto retry; /* start over - may have raced. */
791 if (anumber && !defersleep) {
798 if (!afsd_dynamic_vcaches && anumber == target) {
799 afs_warn("afs_ShakeLooseVCaches: warning none freed, using %d of %d\n",
800 afs_vcount, afs_maxvcount);
806 /* Alloc new vnode. */
808 static struct vcache *
809 afs_AllocVCache(void)
813 tvc = osi_NewVnode();
818 if (afsd_dynamic_vcaches && afs_maxvcount < afs_vcount) {
819 afs_maxvcount = afs_vcount;
820 /*printf("peak vnodes: %d\n", afs_maxvcount);*/
823 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
825 /* If we create a new inode, we either give it a new slot number,
826 * or if one's available, use a slot number from the slot free list
828 if (afs_freeSlotList != NULL) {
829 struct afs_slotlist *tmp;
831 tvc->diskSlot = afs_freeSlotList->slot;
832 tmp = afs_freeSlotList;
833 afs_freeSlotList = tmp->next;
834 afs_osi_Free(tmp, sizeof(struct afs_slotlist));
836 tvc->diskSlot = afs_nextVcacheSlot++;
842 /* Pre populate a newly allocated vcache. On platforms where the actual
843 * vnode is attached to the vcache, this function is called before attachment,
844 * therefore it cannot perform any actions on the vnode itself */
847 afs_PrePopulateVCache(struct vcache *avc, struct VenusFid *afid,
848 struct server *serverp) {
851 slot = avc->diskSlot;
853 osi_PrePopulateVCache(avc);
855 avc->diskSlot = slot;
856 QZero(&avc->metadirty);
858 AFS_RWLOCK_INIT(&avc->lock, "vcache lock");
860 memset(&avc->mvid, 0, sizeof(avc->mvid));
861 avc->linkData = NULL;
864 avc->execsOrWriters = 0;
866 avc->f.states = CVInit;
867 avc->last_looker = 0;
869 avc->asynchrony = -1;
873 avc->f.truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
874 hzero(avc->f.m.DataVersion); /* in case we copy it into flushDV */
876 avc->callback = serverp; /* to minimize chance that clear
879 #if defined(AFS_CACHE_BYPASS)
880 avc->cachingStates = 0;
881 avc->cachingTransitions = 0;
886 afs_FlushAllVCaches(void)
889 struct vcache *tvc, *nvc;
891 ObtainWriteLock(&afs_xvcache, 867);
894 for (i = 0; i < VCSIZE; i++) {
895 for (tvc = afs_vhashT[i]; tvc; tvc = nvc) {
899 if (afs_FlushVCache(tvc, &slept)) {
900 afs_warn("Failed to flush vcache 0x%lx\n", (unsigned long)(uintptrsz)tvc);
908 ReleaseWriteLock(&afs_xvcache);
912 * This routine is responsible for allocating a new cache entry
913 * from the free list. It formats the cache entry and inserts it
914 * into the appropriate hash tables. It must be called with
915 * afs_xvcache write-locked so as to prevent several processes from
916 * trying to create a new cache entry simultaneously.
918 * LOCK: afs_NewVCache afs_xvcache W
920 * \param afid The file id of the file whose cache entry is being created.
922 * \return The new vcache struct.
925 static_inline struct vcache *
926 afs_NewVCache_int(struct VenusFid *afid, struct server *serverp, int seq)
930 afs_int32 anumber = VCACHE_FREE;
932 AFS_STATCNT(afs_NewVCache);
934 afs_FlushReclaimedVcaches();
936 #if defined(AFS_LINUX22_ENV)
937 if(!afsd_dynamic_vcaches && afs_vcount >= afs_maxvcount) {
938 afs_ShakeLooseVCaches(anumber);
939 if (afs_vcount >= afs_maxvcount) {
940 afs_warn("afs_NewVCache - none freed\n");
944 tvc = afs_AllocVCache();
945 #else /* AFS_LINUX22_ENV */
946 /* pull out a free cache entry */
948 afs_ShakeLooseVCaches(anumber);
952 tvc = afs_AllocVCache();
954 tvc = freeVCList; /* take from free list */
955 freeVCList = tvc->nextfree;
956 tvc->nextfree = NULL;
957 afs_vcount++; /* balanced by FlushVCache */
958 } /* end of if (!freeVCList) */
960 #endif /* AFS_LINUX22_ENV */
962 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
964 panic("afs_NewVCache(): free vcache with vnode attached");
967 /* Populate the vcache with as much as we can. */
968 afs_PrePopulateVCache(tvc, afid, serverp);
970 /* Thread the vcache onto the VLRU */
975 tvc->hnext = afs_vhashT[i];
977 QAdd(&afs_vhashTV[j], &tvc->vhashq);
979 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
980 refpanic("NewVCache VLRU inconsistent");
982 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
983 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
984 refpanic("NewVCache VLRU inconsistent2");
986 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
987 refpanic("NewVCache VLRU inconsistent3");
989 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
990 refpanic("NewVCache VLRU inconsistent4");
994 /* it should now be safe to drop the xvcache lock - so attach an inode
995 * to this vcache, where necessary */
996 osi_AttachVnode(tvc, seq);
998 /* Get a reference count to hold this vcache for the VLRUQ. Note that
999 * we have to do this after attaching the vnode, because the reference
1000 * count may be held in the vnode itself */
1002 #if defined(AFS_LINUX22_ENV)
1003 /* Hold it for the LRU (should make count 2) */
1005 #elif !(defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV))
1006 VREFCOUNT_SET(tvc, 1); /* us */
1009 #if defined (AFS_FBSD_ENV)
1010 if (tvc->f.states & CVInit)
1012 afs_PostPopulateVCache(tvc, afid, seq);
1015 } /*afs_NewVCache */
1019 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
1021 return afs_NewVCache_int(afid, serverp, 0);
1025 afs_NewBulkVCache(struct VenusFid *afid, struct server *serverp, int seq)
1027 return afs_NewVCache_int(afid, serverp, seq);
1033 * LOCK: afs_FlushActiveVcaches afs_xvcache N
1035 * \param doflocks : Do we handle flocks?
1038 afs_FlushActiveVcaches(afs_int32 doflocks)
1042 struct afs_conn *tc;
1044 afs_ucred_t *cred = NULL;
1045 struct vrequest *treq = NULL;
1046 struct AFSVolSync tsync;
1049 AFS_STATCNT(afs_FlushActiveVcaches);
1051 code = afs_CreateReq(&treq, afs_osi_credp);
1053 afs_warn("unable to alloc treq\n");
1057 ObtainReadLock(&afs_xvcache);
1058 for (i = 0; i < VCSIZE; i++) {
1059 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1060 if (tvc->f.states & CVInit) continue;
1061 #ifdef AFS_DARWIN80_ENV
1062 if (tvc->f.states & CDeadVnode &&
1063 (tvc->f.states & (CCore|CUnlinkedDel) ||
1064 tvc->flockCount)) panic("Dead vnode has core/unlinkedel/flock");
1066 if (doflocks && tvc->flockCount != 0) {
1067 struct rx_connection *rxconn;
1068 /* if this entry has an flock, send a keep-alive call out */
1070 ReleaseReadLock(&afs_xvcache);
1071 ObtainWriteLock(&tvc->lock, 51);
1073 code = afs_InitReq(treq, afs_osi_credp);
1076 break; /* shutting down: do not try to extend the lock */
1078 treq->flags |= O_NONBLOCK;
1080 tc = afs_Conn(&tvc->f.fid, treq, SHARED_LOCK, &rxconn);
1082 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1085 RXAFS_ExtendLock(rxconn,
1086 (struct AFSFid *)&tvc->f.fid.Fid,
1092 } while (afs_Analyze
1093 (tc, rxconn, code, &tvc->f.fid, treq,
1094 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1096 ReleaseWriteLock(&tvc->lock);
1097 #ifdef AFS_DARWIN80_ENV
1099 ObtainReadLock(&afs_xvcache);
1101 ObtainReadLock(&afs_xvcache);
1106 if ((tvc->f.states & CCore) || (tvc->f.states & CUnlinkedDel)) {
1108 * Don't let it evaporate in case someone else is in
1109 * this code. Also, drop the afs_xvcache lock while
1110 * getting vcache locks.
1113 ReleaseReadLock(&afs_xvcache);
1114 #if defined(AFS_SGI_ENV)
1116 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1118 osi_Assert(VREFCOUNT_GT(tvc,0));
1119 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1121 ObtainWriteLock(&tvc->lock, 52);
1122 if (tvc->f.states & CCore) {
1123 tvc->f.states &= ~CCore;
1124 /* XXXX Find better place-holder for cred XXXX */
1125 cred = (afs_ucred_t *)tvc->linkData;
1126 tvc->linkData = NULL; /* XXX */
1127 code = afs_InitReq(treq, cred);
1128 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1129 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1130 tvc->execsOrWriters);
1131 if (!code) { /* avoid store when shutting down */
1132 code = afs_StoreOnLastReference(tvc, treq);
1134 ReleaseWriteLock(&tvc->lock);
1135 hzero(tvc->flushDV);
1138 if (code && code != VNOVNODE) {
1139 afs_StoreWarn(code, tvc->f.fid.Fid.Volume,
1140 /* /dev/console */ 1);
1142 } else if (tvc->f.states & CUnlinkedDel) {
1146 ReleaseWriteLock(&tvc->lock);
1147 #if defined(AFS_SGI_ENV)
1148 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1150 afs_remunlink(tvc, 0);
1151 #if defined(AFS_SGI_ENV)
1152 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1155 /* lost (or won, perhaps) the race condition */
1156 ReleaseWriteLock(&tvc->lock);
1158 #if defined(AFS_SGI_ENV)
1159 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1161 #ifdef AFS_DARWIN80_ENV
1164 AFS_RELE(AFSTOV(tvc));
1165 /* Matches write code setting CCore flag */
1168 ObtainReadLock(&afs_xvcache);
1170 ObtainReadLock(&afs_xvcache);
1173 AFS_RELE(AFSTOV(tvc));
1174 /* Matches write code setting CCore flag */
1181 ReleaseReadLock(&afs_xvcache);
1182 afs_DestroyReq(treq);
1188 * Make sure a cache entry is up-to-date status-wise.
1190 * NOTE: everywhere that calls this can potentially be sped up
1191 * by checking CStatd first, and avoiding doing the InitReq
1192 * if this is up-to-date.
1194 * Anymore, the only places that call this KNOW already that the
1195 * vcache is not up-to-date, so we don't screw around.
1197 * \param avc : Ptr to vcache entry to verify.
1203 * Make sure a cache entry is up-to-date status-wise.
1205 * NOTE: everywhere that calls this can potentially be sped up
1206 * by checking CStatd first, and avoiding doing the InitReq
1207 * if this is up-to-date.
1209 * Anymore, the only places that call this KNOW already that the
1210 * vcache is not up-to-date, so we don't screw around.
1212 * \param avc Pointer to vcache entry to verify.
1215 * \return 0 for success or other error codes.
1218 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1222 AFS_STATCNT(afs_VerifyVCache);
1224 /* otherwise we must fetch the status info */
1226 ObtainWriteLock(&avc->lock, 53);
1227 if (avc->f.states & CStatd) {
1228 ReleaseWriteLock(&avc->lock);
1231 ObtainWriteLock(&afs_xcbhash, 461);
1232 avc->f.states &= ~(CStatd | CUnique);
1233 avc->callback = NULL;
1234 afs_DequeueCallback(avc);
1235 ReleaseWriteLock(&afs_xcbhash);
1236 ReleaseWriteLock(&avc->lock);
1238 /* since we've been called back, or the callback has expired,
1239 * it's possible that the contents of this directory, or this
1240 * file's name have changed, thus invalidating the dnlc contents.
1242 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1243 osi_dnlc_purgedp(avc);
1245 osi_dnlc_purgevp(avc);
1247 /* fetch the status info */
1248 tvc = afs_GetVCache(&avc->f.fid, areq, NULL, avc);
1251 /* Put it back; caller has already incremented vrefCount */
1255 } /*afs_VerifyVCache */
1259 * Simple copy of stat info into cache.
1261 * Callers:as of 1992-04-29, only called by WriteVCache
1263 * \param avc Ptr to vcache entry involved.
1264 * \param astat Ptr to stat info to copy.
1268 afs_SimpleVStat(struct vcache *avc,
1269 struct AFSFetchStatus *astat, struct vrequest *areq)
1272 AFS_STATCNT(afs_SimpleVStat);
1274 #ifdef AFS_64BIT_CLIENT
1275 FillInt64(length, astat->Length_hi, astat->Length);
1276 #else /* AFS_64BIT_CLIENT */
1277 length = astat->Length;
1278 #endif /* AFS_64BIT_CLIENT */
1280 #if defined(AFS_SGI_ENV)
1281 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1282 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1283 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1284 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1285 if (length < avc->f.m.Length) {
1286 vnode_t *vp = (vnode_t *) avc;
1288 osi_Assert(WriteLocked(&avc->lock));
1289 ReleaseWriteLock(&avc->lock);
1291 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1293 ObtainWriteLock(&avc->lock, 67);
1298 if (!afs_DirtyPages(avc)) {
1299 /* if actively writing the file, don't fetch over this value */
1300 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1301 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1302 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1303 avc->f.m.Length = length;
1304 avc->f.m.Date = astat->ClientModTime;
1306 avc->f.m.Owner = astat->Owner;
1307 avc->f.m.Group = astat->Group;
1308 avc->f.m.Mode = astat->UnixModeBits;
1309 if (vType(avc) == VREG) {
1310 avc->f.m.Mode |= S_IFREG;
1311 } else if (vType(avc) == VDIR) {
1312 avc->f.m.Mode |= S_IFDIR;
1313 } else if (vType(avc) == VLNK) {
1314 avc->f.m.Mode |= S_IFLNK;
1315 if ((avc->f.m.Mode & 0111) == 0)
1316 avc->mvstat = AFS_MVSTAT_MTPT;
1318 if (avc->f.states & CForeign) {
1319 struct axscache *ac;
1320 avc->f.anyAccess = astat->AnonymousAccess;
1322 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1324 * Caller has at least one bit not covered by anonymous, and
1325 * thus may have interesting rights.
1327 * HOWEVER, this is a really bad idea, because any access query
1328 * for bits which aren't covered by anonymous, on behalf of a user
1329 * who doesn't have any special rights, will result in an answer of
1330 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1331 * It's an especially bad idea under Ultrix, since (due to the lack of
1332 * a proper access() call) it must perform several afs_access() calls
1333 * in order to create magic mode bits that vary according to who makes
1334 * the call. In other words, _every_ stat() generates a test for
1337 #endif /* badidea */
1338 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1339 ac->axess = astat->CallerAccess;
1340 else /* not found, add a new one if possible */
1341 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1344 } /*afs_SimpleVStat */
1348 * Store the status info *only* back to the server for a
1351 * Environment: Must be called with a shared lock held on the vnode.
1353 * \param avc Ptr to the vcache entry.
1354 * \param astatus Ptr to the status info to store.
1355 * \param areq Ptr to the associated vrequest.
1357 * \return Operation status.
1361 afs_WriteVCache(struct vcache *avc,
1362 struct AFSStoreStatus *astatus,
1363 struct vrequest *areq)
1366 struct afs_conn *tc;
1367 struct AFSFetchStatus OutStatus;
1368 struct AFSVolSync tsync;
1369 struct rx_connection *rxconn;
1371 AFS_STATCNT(afs_WriteVCache);
1372 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1373 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length));
1375 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
1377 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1380 RXAFS_StoreStatus(rxconn, (struct AFSFid *)&avc->f.fid.Fid,
1381 astatus, &OutStatus, &tsync);
1386 } while (afs_Analyze
1387 (tc, rxconn, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1388 SHARED_LOCK, NULL));
1390 UpgradeSToWLock(&avc->lock, 20);
1392 /* success, do the changes locally */
1393 afs_SimpleVStat(avc, &OutStatus, areq);
1395 * Update the date, too. SimpleVStat didn't do this, since
1396 * it thought we were doing this after fetching new status
1397 * over a file being written.
1399 avc->f.m.Date = OutStatus.ClientModTime;
1401 /* failure, set up to check with server next time */
1402 ObtainWriteLock(&afs_xcbhash, 462);
1403 afs_DequeueCallback(avc);
1404 avc->f.states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1405 ReleaseWriteLock(&afs_xcbhash);
1406 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1407 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1409 ConvertWToSLock(&avc->lock);
1412 } /*afs_WriteVCache */
1415 * Store status info only locally, set the proper disconnection flags
1416 * and add to dirty list.
1418 * \param avc The vcache to be written locally.
1419 * \param astatus Get attr fields from local store.
1420 * \param attrs This one is only of the vs_size.
1422 * \note Must be called with a shared lock on the vnode
1425 afs_WriteVCacheDiscon(struct vcache *avc,
1426 struct AFSStoreStatus *astatus,
1427 struct vattr *attrs)
1430 afs_int32 flags = 0;
1432 UpgradeSToWLock(&avc->lock, 700);
1434 if (!astatus->Mask) {
1440 /* Set attributes. */
1441 if (astatus->Mask & AFS_SETMODTIME) {
1442 avc->f.m.Date = astatus->ClientModTime;
1443 flags |= VDisconSetTime;
1446 if (astatus->Mask & AFS_SETOWNER) {
1447 /* printf("Not allowed yet. \n"); */
1448 /*avc->f.m.Owner = astatus->Owner;*/
1451 if (astatus->Mask & AFS_SETGROUP) {
1452 /* printf("Not allowed yet. \n"); */
1453 /*avc->f.m.Group = astatus->Group;*/
1456 if (astatus->Mask & AFS_SETMODE) {
1457 avc->f.m.Mode = astatus->UnixModeBits;
1459 #if 0 /* XXX: Leaving this out, so it doesn't mess up the file type flag.*/
1461 if (vType(avc) == VREG) {
1462 avc->f.m.Mode |= S_IFREG;
1463 } else if (vType(avc) == VDIR) {
1464 avc->f.m.Mode |= S_IFDIR;
1465 } else if (vType(avc) == VLNK) {
1466 avc->f.m.Mode |= S_IFLNK;
1467 if ((avc->f.m.Mode & 0111) == 0)
1468 avc->mvstat = AFS_MVSTAT_MTPT;
1471 flags |= VDisconSetMode;
1472 } /* if(astatus.Mask & AFS_SETMODE) */
1474 } /* if (!astatus->Mask) */
1476 if (attrs->va_size > 0) {
1477 /* XXX: Do I need more checks? */
1478 /* Truncation operation. */
1479 flags |= VDisconTrunc;
1483 afs_DisconAddDirty(avc, flags, 1);
1485 /* XXX: How about the rest of the fields? */
1487 ConvertWToSLock(&avc->lock);
1493 * Copy astat block into vcache info
1495 * \note This code may get dataversion and length out of sync if the file has
1496 * been modified. This is less than ideal. I haven't thought about it sufficiently
1497 * to be certain that it is adequate.
1499 * \note Environment: Must be called under a write lock
1501 * \param avc Ptr to vcache entry.
1502 * \param astat Ptr to stat block to copy in.
1503 * \param areq Ptr to associated request.
1506 afs_ProcessFS(struct vcache *avc,
1507 struct AFSFetchStatus *astat, struct vrequest *areq)
1510 AFS_STATCNT(afs_ProcessFS);
1512 #ifdef AFS_64BIT_CLIENT
1513 FillInt64(length, astat->Length_hi, astat->Length);
1514 #else /* AFS_64BIT_CLIENT */
1515 length = astat->Length;
1516 #endif /* AFS_64BIT_CLIENT */
1517 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1518 * number for each bulk status request. Under no circumstances
1519 * should afs_DoBulkStat store a sequence number if the new
1520 * length will be ignored when afs_ProcessFS is called with
1521 * new stats. If you change the following conditional then you
1522 * also need to change the conditional in afs_DoBulkStat. */
1524 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1525 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1527 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1529 /* if we're writing or mapping this file, don't fetch over these
1532 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1533 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1534 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1535 avc->f.m.Length = length;
1536 avc->f.m.Date = astat->ClientModTime;
1538 hset64(avc->f.m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1539 avc->f.m.Owner = astat->Owner;
1540 avc->f.m.Mode = astat->UnixModeBits;
1541 avc->f.m.Group = astat->Group;
1542 avc->f.m.LinkCount = astat->LinkCount;
1543 if (astat->FileType == File) {
1544 vSetType(avc, VREG);
1545 avc->f.m.Mode |= S_IFREG;
1546 } else if (astat->FileType == Directory) {
1547 vSetType(avc, VDIR);
1548 avc->f.m.Mode |= S_IFDIR;
1549 } else if (astat->FileType == SymbolicLink) {
1550 if (afs_fakestat_enable && (avc->f.m.Mode & 0111) == 0) {
1551 vSetType(avc, VDIR);
1552 avc->f.m.Mode |= S_IFDIR;
1554 vSetType(avc, VLNK);
1555 avc->f.m.Mode |= S_IFLNK;
1557 if ((avc->f.m.Mode & 0111) == 0) {
1558 avc->mvstat = AFS_MVSTAT_MTPT;
1561 avc->f.anyAccess = astat->AnonymousAccess;
1563 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1565 * Caller has at least one bit not covered by anonymous, and
1566 * thus may have interesting rights.
1568 * HOWEVER, this is a really bad idea, because any access query
1569 * for bits which aren't covered by anonymous, on behalf of a user
1570 * who doesn't have any special rights, will result in an answer of
1571 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1572 * It's an especially bad idea under Ultrix, since (due to the lack of
1573 * a proper access() call) it must perform several afs_access() calls
1574 * in order to create magic mode bits that vary according to who makes
1575 * the call. In other words, _every_ stat() generates a test for
1578 #endif /* badidea */
1580 struct axscache *ac;
1581 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1582 ac->axess = astat->CallerAccess;
1583 else /* not found, add a new one if possible */
1584 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1586 } /*afs_ProcessFS */
1590 * Get fid from server.
1593 * \param areq Request to be passed on.
1594 * \param name Name of ?? to lookup.
1595 * \param OutStatus Fetch status.
1600 * \return Success status of operation.
1603 afs_RemoteLookup(struct VenusFid *afid, struct vrequest *areq,
1604 char *name, struct VenusFid *nfid,
1605 struct AFSFetchStatus *OutStatusp,
1606 struct AFSCallBack *CallBackp, struct server **serverp,
1607 struct AFSVolSync *tsyncp)
1610 struct afs_conn *tc;
1611 struct rx_connection *rxconn;
1612 struct AFSFetchStatus OutDirStatus;
1615 name = ""; /* XXX */
1617 tc = afs_Conn(afid, areq, SHARED_LOCK, &rxconn);
1620 *serverp = tc->parent->srvr->server;
1621 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1624 RXAFS_Lookup(rxconn, (struct AFSFid *)&afid->Fid, name,
1625 (struct AFSFid *)&nfid->Fid, OutStatusp,
1626 &OutDirStatus, CallBackp, tsyncp);
1631 } while (afs_Analyze
1632 (tc, rxconn, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1642 * Given a file id and a vrequest structure, fetch the status
1643 * information associated with the file.
1645 * \param afid File ID.
1646 * \param areq Ptr to associated vrequest structure, specifying the
1647 * user whose authentication tokens will be used.
1648 * \param avc Caller may already have a vcache for this file, which is
1651 * \note Environment:
1652 * The cache entry is returned with an increased vrefCount field.
1653 * The entry must be discarded by calling afs_PutVCache when you
1654 * are through using the pointer to the cache entry.
1656 * You should not hold any locks when calling this function, except
1657 * locks on other vcache entries. If you lock more than one vcache
1658 * entry simultaneously, you should lock them in this order:
1660 * 1. Lock all files first, then directories.
1661 * 2. Within a particular type, lock entries in Fid.Vnode order.
1663 * This locking hierarchy is convenient because it allows locking
1664 * of a parent dir cache entry, given a file (to check its access
1665 * control list). It also allows renames to be handled easily by
1666 * locking directories in a constant order.
1668 * \note NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1670 * \note Might have a vcache structure already, which must
1671 * already be held by the caller
1674 afs_GetVCache(struct VenusFid *afid, struct vrequest *areq,
1675 afs_int32 * cached, struct vcache *avc)
1678 afs_int32 code, newvcache = 0;
1683 AFS_STATCNT(afs_GetVCache);
1686 *cached = 0; /* Init just in case */
1688 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1692 ObtainSharedLock(&afs_xvcache, 5);
1694 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU | IS_SLOCK);
1696 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1697 ReleaseSharedLock(&afs_xvcache);
1698 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1705 osi_Assert((tvc->f.states & CVInit) == 0);
1706 /* If we are in readdir, return the vnode even if not statd */
1707 if ((tvc->f.states & CStatd) || afs_InReadDir(tvc)) {
1708 ReleaseSharedLock(&afs_xvcache);
1712 UpgradeSToWLock(&afs_xvcache, 21);
1714 /* no cache entry, better grab one */
1715 tvc = afs_NewVCache(afid, NULL);
1718 ConvertWToSLock(&afs_xvcache);
1721 ReleaseSharedLock(&afs_xvcache);
1725 afs_stats_cmperf.vcacheMisses++;
1728 ReleaseSharedLock(&afs_xvcache);
1730 ObtainWriteLock(&tvc->lock, 54);
1732 if (tvc->f.states & CStatd) {
1733 ReleaseWriteLock(&tvc->lock);
1736 #ifdef AFS_DARWIN80_ENV
1737 /* Darwin 8.0 only has bufs in nfs, so we shouldn't have to worry about them.
1740 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1742 * XXX - I really don't like this. Should try to understand better.
1743 * It seems that sometimes, when we get called, we already hold the
1744 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1745 * We can't drop the vnode lock, because that could result in a race.
1746 * Sometimes, though, we get here and don't hold the vnode lock.
1747 * I hate code paths that sometimes hold locks and sometimes don't.
1748 * In any event, the dodge we use here is to check whether the vnode
1749 * is locked, and if it isn't, then we gain and drop it around the call
1750 * to vinvalbuf; otherwise, we leave it alone.
1753 struct vnode *vp = AFSTOV(tvc);
1756 #if defined(AFS_DARWIN_ENV)
1757 iheldthelock = VOP_ISLOCKED(vp);
1759 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc());
1760 /* this is messy. we can call fsync which will try to reobtain this */
1761 if (VTOAFS(vp) == tvc)
1762 ReleaseWriteLock(&tvc->lock);
1763 if (UBCINFOEXISTS(vp)) {
1764 vinvalbuf(vp, V_SAVE, &afs_osi_cred, current_proc(), PINOD, 0);
1766 if (VTOAFS(vp) == tvc)
1767 ObtainWriteLock(&tvc->lock, 954);
1769 VOP_UNLOCK(vp, LK_EXCLUSIVE, current_proc());
1770 #elif defined(AFS_FBSD80_ENV)
1771 iheldthelock = VOP_ISLOCKED(vp);
1772 if (!iheldthelock) {
1773 /* nosleep/sleep lock order reversal */
1774 int glocked = ISAFS_GLOCK();
1777 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1781 vinvalbuf(vp, V_SAVE, PINOD, 0); /* changed late in 8.0-CURRENT */
1784 #elif defined(AFS_FBSD60_ENV)
1785 iheldthelock = VOP_ISLOCKED(vp, curthread);
1787 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1789 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1792 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1793 #elif defined(AFS_FBSD_ENV)
1794 iheldthelock = VOP_ISLOCKED(vp, curthread);
1796 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1797 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1799 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1800 #elif defined(AFS_OBSD_ENV)
1801 iheldthelock = VOP_ISLOCKED(vp, curproc);
1803 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1804 uvm_vnp_uncache(vp);
1806 VOP_UNLOCK(vp, 0, curproc);
1807 #elif defined(AFS_NBSD40_ENV)
1808 iheldthelock = VOP_ISLOCKED(vp);
1809 if (!iheldthelock) {
1810 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY);
1812 uvm_vnp_uncache(vp);
1820 ObtainWriteLock(&afs_xcbhash, 464);
1821 tvc->f.states &= ~CUnique;
1823 afs_DequeueCallback(tvc);
1824 ReleaseWriteLock(&afs_xcbhash);
1826 /* It is always appropriate to throw away all the access rights? */
1827 afs_FreeAllAxs(&(tvc->Access));
1828 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1830 if ((tvp->states & VForeign)) {
1832 tvc->f.states |= CForeign;
1833 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1834 && (tvp->rootUnique == afid->Fid.Unique)) {
1835 tvc->mvstat = AFS_MVSTAT_ROOT;
1838 if (tvp->states & VRO)
1839 tvc->f.states |= CRO;
1840 if (tvp->states & VBackup)
1841 tvc->f.states |= CBackup;
1842 /* now copy ".." entry back out of volume structure, if necessary */
1843 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvp->dotdot.Fid.Volume != 0) {
1844 if (!tvc->mvid.parent)
1845 tvc->mvid.parent = (struct VenusFid *)
1846 osi_AllocSmallSpace(sizeof(struct VenusFid));
1847 *tvc->mvid.parent = tvp->dotdot;
1849 afs_PutVolume(tvp, READ_LOCK);
1853 afs_RemoveVCB(afid);
1855 struct AFSFetchStatus OutStatus;
1857 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1858 afs_ProcessFS(tvc, &OutStatus, areq);
1859 tvc->f.states |= CStatd | CUnique;
1860 tvc->f.parent.vnode = OutStatus.ParentVnode;
1861 tvc->f.parent.unique = OutStatus.ParentUnique;
1865 if (AFS_IS_DISCONNECTED) {
1866 /* Nothing to do otherwise...*/
1868 /* printf("Network is down in afs_GetCache"); */
1870 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1872 /* For the NFS translator's benefit, make sure
1873 * non-directory vnodes always have their parent FID set
1874 * correctly, even when created as a result of decoding an
1875 * NFS filehandle. It would be nice to also do this for
1876 * directories, but we can't because the fileserver fills
1877 * in the FID of the directory itself instead of that of
1880 if (!code && OutStatus.FileType != Directory &&
1881 !tvc->f.parent.vnode) {
1882 tvc->f.parent.vnode = OutStatus.ParentVnode;
1883 tvc->f.parent.unique = OutStatus.ParentUnique;
1884 /* XXX - SXW - It's conceivable we should mark ourselves
1885 * as dirty again here, incase we've been raced
1886 * out of the FetchStatus call.
1893 ReleaseWriteLock(&tvc->lock);
1899 ReleaseWriteLock(&tvc->lock);
1902 } /*afs_GetVCache */
1907 * Lookup a vcache by fid. Look inside the cache first, if not
1908 * there, lookup the file on the server, and then get it's fresh
1913 * \param cached Is element cached? If NULL, don't answer.
1917 * \return The found element or NULL.
1920 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1921 afs_int32 * cached, struct vcache *adp, char *aname)
1923 afs_int32 code, now, newvcache = 0;
1924 struct VenusFid nfid;
1927 struct AFSFetchStatus OutStatus;
1928 struct AFSCallBack CallBack;
1929 struct AFSVolSync tsync;
1930 struct server *serverp = 0;
1934 AFS_STATCNT(afs_GetVCache);
1936 *cached = 0; /* Init just in case */
1938 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1942 ObtainReadLock(&afs_xvcache);
1943 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
1946 ReleaseReadLock(&afs_xvcache);
1948 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1949 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1953 ObtainReadLock(&tvc->lock);
1955 if (tvc->f.states & CStatd) {
1959 ReleaseReadLock(&tvc->lock);
1962 tvc->f.states &= ~CUnique;
1964 ReleaseReadLock(&tvc->lock);
1966 ObtainReadLock(&afs_xvcache);
1969 ReleaseReadLock(&afs_xvcache);
1971 /* lookup the file */
1974 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1976 if (AFS_IS_DISCONNECTED) {
1977 /* printf("Network is down in afs_LookupVcache\n"); */
1981 afs_RemoteLookup(&adp->f.fid, areq, aname, &nfid, &OutStatus,
1982 &CallBack, &serverp, &tsync);
1984 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1988 ObtainSharedLock(&afs_xvcache, 6);
1989 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU | IS_SLOCK/* no xstats now */ );
1991 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1992 ReleaseSharedLock(&afs_xvcache);
1993 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1999 /* no cache entry, better grab one */
2000 UpgradeSToWLock(&afs_xvcache, 22);
2001 tvc = afs_NewVCache(&nfid, serverp);
2003 ConvertWToSLock(&afs_xvcache);
2006 ReleaseSharedLock(&afs_xvcache);
2011 ReleaseSharedLock(&afs_xvcache);
2012 ObtainWriteLock(&tvc->lock, 55);
2014 /* It is always appropriate to throw away all the access rights? */
2015 afs_FreeAllAxs(&(tvc->Access));
2016 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
2018 if ((tvp->states & VForeign)) {
2020 tvc->f.states |= CForeign;
2021 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
2022 && (tvp->rootUnique == afid->Fid.Unique))
2023 tvc->mvstat = AFS_MVSTAT_ROOT;
2025 if (tvp->states & VRO)
2026 tvc->f.states |= CRO;
2027 if (tvp->states & VBackup)
2028 tvc->f.states |= CBackup;
2029 /* now copy ".." entry back out of volume structure, if necessary */
2030 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvp->dotdot.Fid.Volume != 0) {
2031 if (!tvc->mvid.parent)
2032 tvc->mvid.parent = (struct VenusFid *)
2033 osi_AllocSmallSpace(sizeof(struct VenusFid));
2034 *tvc->mvid.parent = tvp->dotdot;
2039 ObtainWriteLock(&afs_xcbhash, 465);
2040 afs_DequeueCallback(tvc);
2041 tvc->f.states &= ~(CStatd | CUnique);
2042 ReleaseWriteLock(&afs_xcbhash);
2043 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2044 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2046 afs_PutVolume(tvp, READ_LOCK);
2047 ReleaseWriteLock(&tvc->lock);
2052 ObtainWriteLock(&afs_xcbhash, 466);
2053 if (origCBs == afs_allCBs) {
2054 if (CallBack.ExpirationTime) {
2055 tvc->callback = serverp;
2056 tvc->cbExpires = CallBack.ExpirationTime + now;
2057 tvc->f.states |= CStatd | CUnique;
2058 tvc->f.states &= ~CBulkFetching;
2059 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
2060 } else if (tvc->f.states & CRO) {
2061 /* adapt gives us an hour. */
2062 tvc->cbExpires = 3600 + osi_Time();
2063 /*XXX*/ tvc->f.states |= CStatd | CUnique;
2064 tvc->f.states &= ~CBulkFetching;
2065 afs_QueueCallback(tvc, CBHash(3600), tvp);
2067 tvc->callback = NULL;
2068 afs_DequeueCallback(tvc);
2069 tvc->f.states &= ~(CStatd | CUnique);
2070 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2071 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2074 afs_DequeueCallback(tvc);
2075 tvc->f.states &= ~CStatd;
2076 tvc->f.states &= ~CUnique;
2077 tvc->callback = NULL;
2078 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2079 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2081 ReleaseWriteLock(&afs_xcbhash);
2083 afs_PutVolume(tvp, READ_LOCK);
2084 afs_ProcessFS(tvc, &OutStatus, areq);
2086 ReleaseWriteLock(&tvc->lock);
2092 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2093 afs_int32 * cached, struct volume *tvolp)
2095 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2096 afs_int32 getNewFid = 0;
2098 struct VenusFid nfid;
2100 struct server *serverp = 0;
2101 struct AFSFetchStatus OutStatus;
2102 struct AFSCallBack CallBack;
2103 struct AFSVolSync tsync;
2105 #ifdef AFS_DARWIN80_ENV
2112 if (!tvolp->rootVnode || getNewFid) {
2113 struct VenusFid tfid;
2116 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2117 origCBs = afs_allCBs; /* ignore InitCallBackState */
2119 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2124 /* ReleaseReadLock(&tvolp->lock); */
2125 ObtainWriteLock(&tvolp->lock, 56);
2126 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2127 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2128 ReleaseWriteLock(&tvolp->lock);
2129 /* ObtainReadLock(&tvolp->lock);*/
2132 afid->Fid.Vnode = tvolp->rootVnode;
2133 afid->Fid.Unique = tvolp->rootUnique;
2137 ObtainSharedLock(&afs_xvcache, 7);
2139 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2140 if (!FidCmp(&(tvc->f.fid), afid)) {
2141 if (tvc->f.states & CVInit) {
2142 ReleaseSharedLock(&afs_xvcache);
2143 afs_osi_Sleep(&tvc->f.states);
2146 #ifdef AFS_DARWIN80_ENV
2147 if (tvc->f.states & CDeadVnode) {
2148 ReleaseSharedLock(&afs_xvcache);
2149 afs_osi_Sleep(&tvc->f.states);
2153 if (vnode_get(tvp)) /* this bumps ref count */
2155 if (vnode_ref(tvp)) {
2157 /* AFSTOV(tvc) may be NULL */
2167 if (!haveStatus && (!tvc || !(tvc->f.states & CStatd))) {
2168 /* Mount point no longer stat'd or unknown. FID may have changed. */
2170 ReleaseSharedLock(&afs_xvcache);
2171 #ifdef AFS_DARWIN80_ENV
2174 vnode_put(AFSTOV(tvc));
2175 vnode_rele(AFSTOV(tvc));
2184 UpgradeSToWLock(&afs_xvcache, 23);
2185 /* no cache entry, better grab one */
2186 tvc = afs_NewVCache(afid, NULL);
2189 ReleaseWriteLock(&afs_xvcache);
2193 afs_stats_cmperf.vcacheMisses++;
2197 afs_stats_cmperf.vcacheHits++;
2198 #if defined(AFS_DARWIN80_ENV)
2199 /* we already bumped the ref count in the for loop above */
2200 #else /* AFS_DARWIN80_ENV */
2203 UpgradeSToWLock(&afs_xvcache, 24);
2204 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2205 refpanic("GRVC VLRU inconsistent0");
2207 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2208 refpanic("GRVC VLRU inconsistent1");
2210 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2211 refpanic("GRVC VLRU inconsistent2");
2213 QRemove(&tvc->vlruq); /* move to lruq head */
2214 QAdd(&VLRU, &tvc->vlruq);
2215 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2216 refpanic("GRVC VLRU inconsistent3");
2218 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2219 refpanic("GRVC VLRU inconsistent4");
2221 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2222 refpanic("GRVC VLRU inconsistent5");
2227 ReleaseWriteLock(&afs_xvcache);
2229 if (tvc->f.states & CStatd) {
2233 ObtainReadLock(&tvc->lock);
2234 tvc->f.states &= ~CUnique;
2235 tvc->callback = NULL; /* redundant, perhaps */
2236 ReleaseReadLock(&tvc->lock);
2239 ObtainWriteLock(&tvc->lock, 57);
2241 /* It is always appropriate to throw away all the access rights? */
2242 afs_FreeAllAxs(&(tvc->Access));
2245 tvc->f.states |= CForeign;
2246 if (tvolp->states & VRO)
2247 tvc->f.states |= CRO;
2248 if (tvolp->states & VBackup)
2249 tvc->f.states |= CBackup;
2250 /* now copy ".." entry back out of volume structure, if necessary */
2251 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2252 && (tvolp->rootUnique == afid->Fid.Unique)) {
2253 tvc->mvstat = AFS_MVSTAT_ROOT;
2255 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvolp->dotdot.Fid.Volume != 0) {
2256 if (!tvc->mvid.parent)
2257 tvc->mvid.parent = (struct VenusFid *)
2258 osi_AllocSmallSpace(sizeof(struct VenusFid));
2259 *tvc->mvid.parent = tvolp->dotdot;
2263 afs_RemoveVCB(afid);
2266 struct VenusFid tfid;
2269 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2270 origCBs = afs_allCBs; /* ignore InitCallBackState */
2272 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2277 ObtainWriteLock(&afs_xcbhash, 467);
2278 afs_DequeueCallback(tvc);
2279 tvc->callback = NULL;
2280 tvc->f.states &= ~(CStatd | CUnique);
2281 ReleaseWriteLock(&afs_xcbhash);
2282 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2283 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2284 ReleaseWriteLock(&tvc->lock);
2289 ObtainWriteLock(&afs_xcbhash, 468);
2290 if (origCBs == afs_allCBs) {
2291 tvc->f.states |= CTruth;
2292 tvc->callback = serverp;
2293 if (CallBack.ExpirationTime != 0) {
2294 tvc->cbExpires = CallBack.ExpirationTime + start;
2295 tvc->f.states |= CStatd;
2296 tvc->f.states &= ~CBulkFetching;
2297 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2298 } else if (tvc->f.states & CRO) {
2299 /* adapt gives us an hour. */
2300 tvc->cbExpires = 3600 + osi_Time();
2301 /*XXX*/ tvc->f.states |= CStatd;
2302 tvc->f.states &= ~CBulkFetching;
2303 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2306 afs_DequeueCallback(tvc);
2307 tvc->callback = NULL;
2308 tvc->f.states &= ~(CStatd | CUnique);
2309 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2310 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2312 ReleaseWriteLock(&afs_xcbhash);
2313 afs_ProcessFS(tvc, &OutStatus, areq);
2315 ReleaseWriteLock(&tvc->lock);
2321 * Update callback status and (sometimes) attributes of a vnode.
2322 * Called after doing a fetch status RPC. Whilst disconnected, attributes
2323 * shouldn't be written to the vcache here.
2328 * \param Outsp Server status after rpc call.
2329 * \param acb Callback for this vnode.
2331 * \note The vcache must be write locked.
2334 afs_UpdateStatus(struct vcache *avc, struct VenusFid *afid,
2335 struct vrequest *areq, struct AFSFetchStatus *Outsp,
2336 struct AFSCallBack *acb, afs_uint32 start)
2338 struct volume *volp;
2341 /* Dont write status in vcache if resyncing after a disconnection. */
2342 afs_ProcessFS(avc, Outsp, areq);
2344 volp = afs_GetVolume(afid, areq, READ_LOCK);
2345 ObtainWriteLock(&afs_xcbhash, 469);
2346 avc->f.states |= CTruth;
2347 if (avc->callback /* check for race */ ) {
2348 if (acb->ExpirationTime != 0) {
2349 avc->cbExpires = acb->ExpirationTime + start;
2350 avc->f.states |= CStatd;
2351 avc->f.states &= ~CBulkFetching;
2352 afs_QueueCallback(avc, CBHash(acb->ExpirationTime), volp);
2353 } else if (avc->f.states & CRO) {
2354 /* ordinary callback on a read-only volume -- AFS 3.2 style */
2355 avc->cbExpires = 3600 + start;
2356 avc->f.states |= CStatd;
2357 avc->f.states &= ~CBulkFetching;
2358 afs_QueueCallback(avc, CBHash(3600), volp);
2360 afs_DequeueCallback(avc);
2361 avc->callback = NULL;
2362 avc->f.states &= ~(CStatd | CUnique);
2363 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2364 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2367 afs_DequeueCallback(avc);
2368 avc->callback = NULL;
2369 avc->f.states &= ~(CStatd | CUnique);
2370 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2371 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2373 ReleaseWriteLock(&afs_xcbhash);
2375 afs_PutVolume(volp, READ_LOCK);
2379 afs_BadFetchStatus(struct afs_conn *tc)
2381 int addr = ntohl(tc->parent->srvr->sa_ip);
2382 afs_warn("afs: Invalid AFSFetchStatus from server %u.%u.%u.%u\n",
2383 (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
2385 afs_warn("afs: This suggests the server may be sending bad data that "
2386 "can lead to availability issues or data corruption. The "
2387 "issue has been avoided for now, but it may not always be "
2388 "detectable. Please upgrade the server if possible.\n");
2392 * Check if a given AFSFetchStatus structure is sane.
2394 * @param[in] tc The server from which we received the status
2395 * @param[in] status The status we received
2397 * @return whether the given structure is valid or not
2398 * @retval 0 the structure is fine
2399 * @retval nonzero the structure looks like garbage; act as if we received
2400 * the returned error code from the server
2403 afs_CheckFetchStatus(struct afs_conn *tc, struct AFSFetchStatus *status)
2405 if (status->errorCode ||
2406 status->InterfaceVersion != 1 ||
2407 !(status->FileType > Invalid && status->FileType <= SymbolicLink) ||
2408 status->ParentVnode == 0 || status->ParentUnique == 0) {
2410 afs_warn("afs: FetchStatus ec %u iv %u ft %u pv %u pu %u\n",
2411 (unsigned)status->errorCode, (unsigned)status->InterfaceVersion,
2412 (unsigned)status->FileType, (unsigned)status->ParentVnode,
2413 (unsigned)status->ParentUnique);
2414 afs_BadFetchStatus(tc);
2422 * Must be called with avc write-locked
2423 * don't absolutely have to invalidate the hint unless the dv has
2424 * changed, but be sure to get it right else there will be consistency bugs.
2427 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2428 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2431 afs_uint32 start = 0;
2432 struct afs_conn *tc;
2433 struct AFSCallBack CallBack;
2434 struct AFSVolSync tsync;
2435 struct rx_connection *rxconn;
2438 tc = afs_Conn(afid, areq, SHARED_LOCK, &rxconn);
2439 avc->dchint = NULL; /* invalidate hints */
2441 avc->callback = tc->parent->srvr->server;
2443 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2446 RXAFS_FetchStatus(rxconn, (struct AFSFid *)&afid->Fid, Outsp,
2453 code = afs_CheckFetchStatus(tc, Outsp);
2458 } while (afs_Analyze
2459 (tc, rxconn, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2460 SHARED_LOCK, NULL));
2463 afs_UpdateStatus(avc, afid, areq, Outsp, &CallBack, start);
2465 /* used to undo the local callback, but that's too extreme.
2466 * There are plenty of good reasons that fetchstatus might return
2467 * an error, such as EPERM. If we have the vnode cached, statd,
2468 * with callback, might as well keep track of the fact that we
2469 * don't have access...
2471 if (code == EPERM || code == EACCES) {
2472 struct axscache *ac;
2473 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2475 else /* not found, add a new one if possible */
2476 afs_AddAxs(avc->Access, areq->uid, 0);
2487 * Stuff some information into the vcache for the given file.
2490 * afid : File in question.
2491 * OutStatus : Fetch status on the file.
2492 * CallBack : Callback info.
2493 * tc : RPC connection involved.
2494 * areq : vrequest involved.
2497 * Nothing interesting.
2500 afs_StuffVcache(struct VenusFid *afid,
2501 struct AFSFetchStatus *OutStatus,
2502 struct AFSCallBack *CallBack, struct afs_conn *tc,
2503 struct vrequest *areq)
2505 afs_int32 code, i, newvcache = 0;
2507 struct AFSVolSync tsync;
2509 struct axscache *ac;
2512 AFS_STATCNT(afs_StuffVcache);
2513 #ifdef IFS_VCACHECOUNT
2518 ObtainSharedLock(&afs_xvcache, 8);
2520 tvc = afs_FindVCache(afid, &retry, DO_VLRU| IS_SLOCK /* no stats */ );
2522 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2523 ReleaseSharedLock(&afs_xvcache);
2524 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2530 /* no cache entry, better grab one */
2531 UpgradeSToWLock(&afs_xvcache, 25);
2532 tvc = afs_NewVCache(afid, NULL);
2534 ConvertWToSLock(&afs_xvcache);
2537 ReleaseSharedLock(&afs_xvcache);
2542 ReleaseSharedLock(&afs_xvcache);
2543 ObtainWriteLock(&tvc->lock, 58);
2545 tvc->f.states &= ~CStatd;
2546 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2547 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2549 /* Is it always appropriate to throw away all the access rights? */
2550 afs_FreeAllAxs(&(tvc->Access));
2552 /*Copy useful per-volume info */
2553 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2555 if (newvcache && (tvp->states & VForeign))
2556 tvc->f.states |= CForeign;
2557 if (tvp->states & VRO)
2558 tvc->f.states |= CRO;
2559 if (tvp->states & VBackup)
2560 tvc->f.states |= CBackup;
2562 * Now, copy ".." entry back out of volume structure, if
2565 if (tvc->mvstat == AFS_MVSTAT_ROOT && tvp->dotdot.Fid.Volume != 0) {
2566 if (!tvc->mvid.parent)
2567 tvc->mvid.parent = (struct VenusFid *)
2568 osi_AllocSmallSpace(sizeof(struct VenusFid));
2569 *tvc->mvid.parent = tvp->dotdot;
2572 /* store the stat on the file */
2573 afs_RemoveVCB(afid);
2574 afs_ProcessFS(tvc, OutStatus, areq);
2575 tvc->callback = tc->srvr->server;
2577 /* we use osi_Time twice below. Ideally, we would use the time at which
2578 * the FetchStatus call began, instead, but we don't have it here. So we
2579 * make do with "now". In the CRO case, it doesn't really matter. In
2580 * the other case, we hope that the difference between "now" and when the
2581 * call actually began execution on the server won't be larger than the
2582 * padding which the server keeps. Subtract 1 second anyway, to be on
2583 * the safe side. Can't subtract more because we don't know how big
2584 * ExpirationTime is. Possible consistency problems may arise if the call
2585 * timeout period becomes longer than the server's expiration padding. */
2586 ObtainWriteLock(&afs_xcbhash, 470);
2587 if (CallBack->ExpirationTime != 0) {
2588 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2589 tvc->f.states |= CStatd;
2590 tvc->f.states &= ~CBulkFetching;
2591 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2592 } else if (tvc->f.states & CRO) {
2593 /* old-fashioned AFS 3.2 style */
2594 tvc->cbExpires = 3600 + osi_Time();
2595 /*XXX*/ tvc->f.states |= CStatd;
2596 tvc->f.states &= ~CBulkFetching;
2597 afs_QueueCallback(tvc, CBHash(3600), tvp);
2599 afs_DequeueCallback(tvc);
2600 tvc->callback = NULL;
2601 tvc->f.states &= ~(CStatd | CUnique);
2602 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2603 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2605 ReleaseWriteLock(&afs_xcbhash);
2607 afs_PutVolume(tvp, READ_LOCK);
2609 /* look in per-pag cache */
2610 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2611 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2612 else /* not found, add a new one if possible */
2613 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2615 ReleaseWriteLock(&tvc->lock);
2616 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2617 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2618 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2620 * Release ref count... hope this guy stays around...
2623 } /*afs_StuffVcache */
2627 * Decrements the reference count on a cache entry.
2629 * \param avc Pointer to the cache entry to decrement.
2631 * \note Environment: Nothing interesting.
2634 afs_PutVCache(struct vcache *avc)
2636 AFS_STATCNT(afs_PutVCache);
2637 #ifdef AFS_DARWIN80_ENV
2638 vnode_put(AFSTOV(avc));
2642 * Can we use a read lock here?
2644 ObtainReadLock(&afs_xvcache);
2646 ReleaseReadLock(&afs_xvcache);
2648 } /*afs_PutVCache */
2652 * Reset a vcache entry, so local contents are ignored, and the
2653 * server will be reconsulted next time the vcache is used
2655 * \param avc Pointer to the cache entry to reset
2657 * \param skipdnlc skip the dnlc purge for this vnode
2659 * \note avc must be write locked on entry
2661 * \note The caller should purge the dnlc when skipdnlc is set.
2664 afs_ResetVCache(struct vcache *avc, afs_ucred_t *acred, afs_int32 skipdnlc)
2666 ObtainWriteLock(&afs_xcbhash, 456);
2667 afs_DequeueCallback(avc);
2668 avc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat */
2669 ReleaseWriteLock(&afs_xcbhash);
2670 /* now find the disk cache entries */
2671 afs_TryToSmush(avc, acred, 1);
2673 osi_dnlc_purgedp(avc);
2675 if (avc->linkData && !(avc->f.states & CCore)) {
2676 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
2677 avc->linkData = NULL;
2682 * Sleepa when searching for a vcache. Releases all the pending locks,
2683 * sleeps then obtains the previously released locks.
2685 * \param vcache Enter sleep state.
2686 * \param flag Determines what locks to use.
2691 findvc_sleep(struct vcache *avc, int flag)
2693 if (flag & IS_SLOCK) {
2694 ReleaseSharedLock(&afs_xvcache);
2696 if (flag & IS_WLOCK) {
2697 ReleaseWriteLock(&afs_xvcache);
2699 ReleaseReadLock(&afs_xvcache);
2702 afs_osi_Sleep(&avc->f.states);
2703 if (flag & IS_SLOCK) {
2704 ObtainSharedLock(&afs_xvcache, 341);
2706 if (flag & IS_WLOCK) {
2707 ObtainWriteLock(&afs_xvcache, 343);
2709 ObtainReadLock(&afs_xvcache);
2715 * Add a reference on an existing vcache entry.
2717 * \param tvc Pointer to the vcache.
2719 * \note Environment: Must be called with at least one reference from
2720 * elsewhere on the vcache, even if that reference will be dropped.
2721 * The global lock is required.
2723 * \return 0 on success, -1 on failure.
2727 afs_RefVCache(struct vcache *tvc)
2729 #ifdef AFS_DARWIN80_ENV
2733 /* AFS_STATCNT(afs_RefVCache); */
2735 #ifdef AFS_DARWIN80_ENV
2739 if (vnode_ref(tvp)) {
2741 /* AFSTOV(tvc) may be NULL */
2750 } /*afs_RefVCache */
2753 * Find a vcache entry given a fid.
2755 * \param afid Pointer to the fid whose cache entry we desire.
2756 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2757 * unlock the vnode, and try again.
2758 * \param flag Bit 1 to specify whether to compute hit statistics. Not
2759 * set if FindVCache is called as part of internal bookkeeping.
2761 * \note Environment: Must be called with the afs_xvcache lock at least held at
2762 * the read level. In order to do the VLRU adjustment, the xvcache lock
2763 * must be shared-- we upgrade it here.
2767 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2772 #ifdef AFS_DARWIN80_ENV
2773 struct vcache *deadvc = NULL, *livevc = NULL;
2777 AFS_STATCNT(afs_FindVCache);
2781 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2782 if (FidMatches(afid, tvc)) {
2783 if (tvc->f.states & CVInit) {
2784 findvc_sleep(tvc, flag);
2787 #ifdef AFS_DARWIN80_ENV
2788 if (tvc->f.states & CDeadVnode) {
2789 findvc_sleep(tvc, flag);
2797 /* should I have a read lock on the vnode here? */
2801 #if defined(AFS_DARWIN80_ENV)
2805 if (tvp && vnode_ref(tvp)) {
2807 /* AFSTOV(tvc) may be NULL */
2816 #elif defined(AFS_DARWIN_ENV)
2817 tvc->f.states |= CUBCinit;
2819 if (UBCINFOMISSING(AFSTOV(tvc)) ||
2820 UBCINFORECLAIMED(AFSTOV(tvc))) {
2821 ubc_info_init(AFSTOV(tvc));
2824 tvc->f.states &= ~CUBCinit;
2826 osi_vnhold(tvc, retry); /* already held, above */
2827 if (retry && *retry)
2831 * only move to front of vlru if we have proper vcache locking)
2833 if (flag & DO_VLRU) {
2834 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2835 refpanic("FindVC VLRU inconsistent1");
2837 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2838 refpanic("FindVC VLRU inconsistent1");
2840 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2841 refpanic("FindVC VLRU inconsistent2");
2843 UpgradeSToWLock(&afs_xvcache, 26);
2844 QRemove(&tvc->vlruq);
2845 QAdd(&VLRU, &tvc->vlruq);
2846 ConvertWToSLock(&afs_xvcache);
2847 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2848 refpanic("FindVC VLRU inconsistent1");
2850 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2851 refpanic("FindVC VLRU inconsistent2");
2853 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2854 refpanic("FindVC VLRU inconsistent3");
2860 if (flag & DO_STATS) {
2862 afs_stats_cmperf.vcacheHits++;
2864 afs_stats_cmperf.vcacheMisses++;
2865 if (afs_IsPrimaryCellNum(afid->Cell))
2866 afs_stats_cmperf.vlocalAccesses++;
2868 afs_stats_cmperf.vremoteAccesses++;
2871 } /*afs_FindVCache */
2874 * Find a vcache entry given a fid. Does a wildcard match on what we
2875 * have for the fid. If more than one entry, don't return anything.
2877 * \param avcp Fill in pointer if we found one and only one.
2878 * \param afid Pointer to the fid whose cache entry we desire.
2879 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2880 * unlock the vnode, and try again.
2881 * \param flags bit 1 to specify whether to compute hit statistics. Not
2882 * set if FindVCache is called as part of internal bookkeeping.
2884 * \note Environment: Must be called with the afs_xvcache lock at least held at
2885 * the read level. In order to do the VLRU adjustment, the xvcache lock
2886 * must be shared-- we upgrade it here.
2888 * \return Number of matches found.
2891 int afs_duplicate_nfs_fids = 0;
2894 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2898 afs_int32 count = 0;
2899 struct vcache *found_tvc = NULL;
2900 #ifdef AFS_DARWIN80_ENV
2904 AFS_STATCNT(afs_FindVCache);
2908 ObtainSharedLock(&afs_xvcache, 331);
2911 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2912 /* Match only on what we have.... */
2913 if (((tvc->f.fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2914 && (tvc->f.fid.Fid.Volume == afid->Fid.Volume)
2915 && ((tvc->f.fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2916 && (tvc->f.fid.Cell == afid->Cell)) {
2917 if (tvc->f.states & CVInit) {
2918 ReleaseSharedLock(&afs_xvcache);
2919 afs_osi_Sleep(&tvc->f.states);
2922 #ifdef AFS_DARWIN80_ENV
2923 if (tvc->f.states & CDeadVnode) {
2924 ReleaseSharedLock(&afs_xvcache);
2925 afs_osi_Sleep(&tvc->f.states);
2929 if (vnode_get(tvp)) {
2930 /* This vnode no longer exists. */
2933 if (vnode_ref(tvp)) {
2934 /* This vnode no longer exists. */
2936 /* AFSTOV(tvc) may be NULL */
2941 #endif /* AFS_DARWIN80_ENV */
2945 afs_duplicate_nfs_fids++;
2946 ReleaseSharedLock(&afs_xvcache);
2947 #ifdef AFS_DARWIN80_ENV
2948 /* Drop our reference counts. */
2949 vnode_put(AFSTOV(tvc));
2950 vnode_put(AFSTOV(found_tvc));
2959 /* should I have a read lock on the vnode here? */
2961 #ifndef AFS_DARWIN80_ENV
2962 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2963 afs_int32 retry = 0;
2964 osi_vnhold(tvc, &retry);
2967 found_tvc = (struct vcache *)0;
2968 ReleaseSharedLock(&afs_xvcache);
2969 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2973 osi_vnhold(tvc, (int *)0); /* already held, above */
2977 * We obtained the xvcache lock above.
2979 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2980 refpanic("FindVC VLRU inconsistent1");
2982 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2983 refpanic("FindVC VLRU inconsistent1");
2985 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2986 refpanic("FindVC VLRU inconsistent2");
2988 UpgradeSToWLock(&afs_xvcache, 568);
2989 QRemove(&tvc->vlruq);
2990 QAdd(&VLRU, &tvc->vlruq);
2991 ConvertWToSLock(&afs_xvcache);
2992 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2993 refpanic("FindVC VLRU inconsistent1");
2995 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2996 refpanic("FindVC VLRU inconsistent2");
2998 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2999 refpanic("FindVC VLRU inconsistent3");
3005 afs_stats_cmperf.vcacheHits++;
3007 afs_stats_cmperf.vcacheMisses++;
3008 if (afs_IsPrimaryCellNum(afid->Cell))
3009 afs_stats_cmperf.vlocalAccesses++;
3011 afs_stats_cmperf.vremoteAccesses++;
3013 *avcp = tvc; /* May be null */
3015 ReleaseSharedLock(&afs_xvcache);
3016 return (tvc ? 1 : 0);
3018 } /*afs_NFSFindVCache */
3024 * Initialize vcache related variables
3029 afs_vcacheInit(int astatSize)
3031 #if !defined(AFS_LINUX22_ENV)
3035 if (!afs_maxvcount) {
3036 afs_maxvcount = astatSize; /* no particular limit on linux? */
3038 #if !defined(AFS_LINUX22_ENV)
3042 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3043 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3045 #if !defined(AFS_LINUX22_ENV)
3046 /* Allocate and thread the struct vcache entries */
3047 tvp = afs_osi_Alloc(astatSize * sizeof(struct vcache));
3048 osi_Assert(tvp != NULL);
3049 memset(tvp, 0, sizeof(struct vcache) * astatSize);
3051 Initial_freeVCList = tvp;
3052 freeVCList = &(tvp[0]);
3053 for (i = 0; i < astatSize - 1; i++) {
3054 tvp[i].nextfree = &(tvp[i + 1]);
3056 tvp[astatSize - 1].nextfree = NULL;
3057 # ifdef KERNEL_HAVE_PIN
3058 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
3062 #if defined(AFS_SGI_ENV)
3063 for (i = 0; i < astatSize; i++) {
3064 char name[METER_NAMSZ];
3065 struct vcache *tvc = &tvp[i];
3067 tvc->v.v_number = ++afsvnumbers;
3068 tvc->vc_rwlockid = OSI_NO_LOCKID;
3069 initnsema(&tvc->vc_rwlock, 1,
3070 makesname(name, "vrw", tvc->v.v_number));
3071 #ifndef AFS_SGI53_ENV
3072 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
3074 #ifndef AFS_SGI62_ENV
3075 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
3076 #endif /* AFS_SGI62_ENV */
3080 for(i = 0; i < VCSIZE; ++i)
3081 QInit(&afs_vhashTV[i]);
3088 shutdown_vcache(void)
3091 struct afs_cbr *tsp;
3093 * XXX We may potentially miss some of the vcaches because if when
3094 * there are no free vcache entries and all the vcache entries are active
3095 * ones then we allocate an additional one - admittedly we almost never
3100 struct afs_q *tq, *uq = NULL;
3102 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
3105 if (tvc->mvid.target_root) {
3106 osi_FreeSmallSpace(tvc->mvid.target_root);
3107 tvc->mvid.target_root = NULL;
3110 aix_gnode_rele(AFSTOV(tvc));
3112 if (tvc->linkData) {
3113 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3118 * Also free the remaining ones in the Cache
3120 for (i = 0; i < VCSIZE; i++) {
3121 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3122 if (tvc->mvid.target_root) {
3123 osi_FreeSmallSpace(tvc->mvid.target_root);
3124 tvc->mvid.target_root = NULL;
3128 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
3129 #ifdef AFS_AIX32_ENV
3132 vms_delete(tvc->segid);
3134 tvc->segid = tvc->vmh = NULL;
3135 if (VREFCOUNT_GT(tvc,0))
3136 osi_Panic("flushVcache: vm race");
3144 #if defined(AFS_SUN5_ENV)
3150 if (tvc->linkData) {
3151 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3156 afs_FreeAllAxs(&(tvc->Access));
3162 * Free any leftover callback queue
3164 for (i = 0; i < afs_stats_cmperf.CallBackAlloced; i++) {
3165 tsp = afs_cbrHeads[i];
3166 afs_cbrHeads[i] = 0;
3167 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
3171 #if !defined(AFS_LINUX22_ENV)
3172 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3174 # ifdef KERNEL_HAVE_PIN
3175 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3178 freeVCList = Initial_freeVCList = 0;
3181 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3182 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3184 for(i = 0; i < VCSIZE; ++i)
3185 QInit(&afs_vhashTV[i]);
3189 afs_DisconGiveUpCallbacks(void)
3195 ObtainWriteLock(&afs_xvcache, 1002); /* XXX - should be a unique number */
3198 /* Somehow, walk the set of vcaches, with each one coming out as tvc */
3199 for (i = 0; i < VCSIZE; i++) {
3200 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3202 if (afs_QueueVCB(tvc, &slept)) {
3203 tvc->callback = NULL;
3212 ReleaseWriteLock(&afs_xvcache);
3219 * Clear the Statd flag from all vcaches
3221 * This function removes the Statd flag from all vcaches. It's used by
3222 * disconnected mode to tidy up during reconnection
3226 afs_ClearAllStatdFlag(void)
3231 ObtainWriteLock(&afs_xvcache, 715);
3233 for (i = 0; i < VCSIZE; i++) {
3234 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3235 tvc->f.states &= ~(CStatd|CUnique);
3238 ReleaseWriteLock(&afs_xvcache);