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"
44 #include "afs/sysincludes.h" /*Standard vendor system headers */
45 #include "afsincludes.h" /*AFS-based standard headers */
46 #include "afs/afs_stats.h"
47 #include "afs/afs_cbqueue.h"
48 #include "afs/afs_osidnlc.h"
50 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
51 afs_int32 afs_vcount = 0; /* number of vcache in use now */
59 #endif /* AFS_SGI64_ENV */
61 /* Exported variables */
63 afs_rwlock_t afs_xvcdirty; /*Lock: discon vcache dirty list mgmt */
65 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries */
66 afs_rwlock_t afs_xvreclaim; /*Lock: entries reclaimed, not on free list */
67 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks */
68 #if !defined(AFS_LINUX22_ENV)
69 static struct vcache *freeVCList; /*Free list for stat cache entries */
70 struct vcache *ReclaimedVCList; /*Reclaimed list for stat entries */
71 static struct vcache *Initial_freeVCList; /*Initial list for above */
73 struct afs_q VLRU; /*vcache LRU */
74 afs_int32 vcachegen = 0;
75 unsigned int afs_paniconwarn = 0;
76 struct vcache *afs_vhashT[VCSIZE];
77 struct afs_q afs_vhashTV[VCSIZE];
78 static struct afs_cbr *afs_cbrHashT[CBRSIZE];
79 afs_int32 afs_bulkStatsLost;
80 int afs_norefpanic = 0;
83 /* Disk backed vcache definitions
84 * Both protected by xvcache */
86 static int afs_nextVcacheSlot = 0;
87 static struct afs_slotlist *afs_freeSlotList = NULL;
90 /* Forward declarations */
91 static afs_int32 afs_QueueVCB(struct vcache *avc);
94 * Generate an index into the hash table for a given Fid.
96 * \return The hash value.
99 afs_HashCBRFid(struct AFSFid *fid)
101 return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE;
105 * Insert a CBR entry into the hash table.
106 * Must be called with afs_xvcb held.
111 afs_InsertHashCBR(struct afs_cbr *cbr)
113 int slot = afs_HashCBRFid(&cbr->fid);
115 cbr->hash_next = afs_cbrHashT[slot];
116 if (afs_cbrHashT[slot])
117 afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next;
119 cbr->hash_pprev = &afs_cbrHashT[slot];
120 afs_cbrHashT[slot] = cbr;
125 * Flush the given vcache entry.
128 * afs_xvcache lock must be held for writing upon entry to
129 * prevent people from changing the vrefCount field, and to
130 * protect the lruq and hnext fields.
131 * LOCK: afs_FlushVCache afs_xvcache W
132 * REFCNT: vcache ref count must be zero on entry except for osf1
133 * RACE: lock is dropped and reobtained, permitting race in caller
135 * \param avc Pointer to vcache entry to flush.
136 * \param slept Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
140 afs_FlushVCache(struct vcache *avc, int *slept)
141 { /*afs_FlushVCache */
144 struct vcache **uvc, *wvc;
147 AFS_STATCNT(afs_FlushVCache);
148 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
149 ICL_TYPE_INT32, avc->f.states);
151 code = osi_VM_FlushVCache(avc, slept);
155 if (avc->f.states & CVFlushed) {
159 #if !defined(AFS_LINUX22_ENV)
160 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
161 refpanic("LRU vs. Free inconsistency");
164 avc->f.states |= CVFlushed;
165 /* pull the entry out of the lruq and put it on the free list */
166 QRemove(&avc->vlruq);
168 /* keep track of # of files that we bulk stat'd, but never used
169 * before they got recycled.
171 if (avc->f.states & CBulkStat)
174 /* remove entry from the hash chain */
175 i = VCHash(&avc->f.fid);
176 uvc = &afs_vhashT[i];
177 for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
180 avc->hnext = (struct vcache *)NULL;
185 /* remove entry from the volume hash table */
186 QRemove(&avc->vhashq);
189 osi_FreeSmallSpace(avc->mvid);
190 avc->mvid = (struct VenusFid *)0;
192 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
193 avc->linkData = NULL;
195 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
196 /* OK, there are no internal vrefCounts, so there shouldn't
197 * be any more refs here. */
199 #ifdef AFS_DARWIN80_ENV
200 vnode_clearfsnode(AFSTOV(avc));
201 vnode_removefsref(AFSTOV(avc));
203 avc->v->v_data = NULL; /* remove from vnode */
205 AFSTOV(avc) = NULL; /* also drop the ptr to vnode */
208 #ifdef AFS_SUN510_ENV
209 /* As we use private vnodes, cleanup is up to us */
210 vn_reinit(AFSTOV(avc));
212 afs_FreeAllAxs(&(avc->Access));
214 ObtainWriteLock(&afs_xcbhash, 460);
215 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
216 avc->f.states &= ~(CStatd | CUnique);
217 ReleaseWriteLock(&afs_xcbhash);
218 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
219 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
221 osi_dnlc_purgevp(avc);
224 * Next, keep track of which vnodes we've deleted for create's
225 * optimistic synchronization algorithm
228 if (avc->f.fid.Fid.Vnode & 1)
233 #if !defined(AFS_LINUX22_ENV)
234 /* put the entry in the free list */
235 avc->nextfree = freeVCList;
237 if (avc->vlruq.prev || avc->vlruq.next) {
238 refpanic("LRU vs. Free inconsistency");
240 avc->f.states |= CVFlushed;
242 /* This should put it back on the vnode free list since usecount is 1 */
245 if (VREFCOUNT_GT(avc,0)) {
246 AFS_RELE(AFSTOV(avc));
247 afs_stats_cmperf.vcacheXAllocs--;
249 if (afs_norefpanic) {
250 afs_warn("flush vc refcnt < 1");
253 osi_Panic("flush vc refcnt < 1");
255 #endif /* AFS_LINUX22_ENV */
260 } /*afs_FlushVCache */
264 * The core of the inactive vnode op for all but IRIX.
270 afs_InactiveVCache(struct vcache *avc, afs_ucred_t *acred)
272 AFS_STATCNT(afs_inactive);
273 if (avc->f.states & CDirty) {
274 /* we can't keep trying to push back dirty data forever. Give up. */
275 afs_InvalidateAllSegments(avc); /* turns off dirty bit */
277 avc->f.states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
278 avc->f.states &= ~CDirty; /* Turn it off */
279 if (avc->f.states & CUnlinked) {
280 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
281 avc->f.states |= CUnlinkedDel;
284 afs_remunlink(avc, 1); /* ignore any return code */
291 * Allocate a callback return structure from the
292 * free list and return it.
294 * Environment: The alloc and free routines are both called with the afs_xvcb lock
295 * held, so we don't have to worry about blocking in osi_Alloc.
297 * \return The allocated afs_cbr.
299 static struct afs_cbr *afs_cbrSpace = 0;
300 /* if alloc limit below changes, fix me! */
301 static struct afs_cbr *afs_cbrHeads[2];
305 register struct afs_cbr *tsp;
308 while (!afs_cbrSpace) {
309 if (afs_stats_cmperf.CallBackAlloced >= 2) {
310 /* don't allocate more than 2 * AFS_NCBRS for now */
312 afs_stats_cmperf.CallBackFlushes++;
316 (struct afs_cbr *)afs_osi_Alloc(AFS_NCBRS *
317 sizeof(struct afs_cbr));
318 for (i = 0; i < AFS_NCBRS - 1; i++) {
319 tsp[i].next = &tsp[i + 1];
321 tsp[AFS_NCBRS - 1].next = 0;
323 afs_cbrHeads[afs_stats_cmperf.CallBackAlloced] = tsp;
324 afs_stats_cmperf.CallBackAlloced++;
328 afs_cbrSpace = tsp->next;
333 * Free a callback return structure, removing it from all lists.
335 * Environment: the xvcb lock is held over these calls.
337 * \param asp The address of the structure to free.
342 afs_FreeCBR(register struct afs_cbr *asp)
344 *(asp->pprev) = asp->next;
346 asp->next->pprev = asp->pprev;
348 *(asp->hash_pprev) = asp->hash_next;
350 asp->hash_next->hash_pprev = asp->hash_pprev;
352 asp->next = afs_cbrSpace;
358 * Flush all queued callbacks to all servers.
360 * Environment: holds xvcb lock over RPC to guard against race conditions
361 * when a new callback is granted for the same file later on.
363 * \return 0 for success.
366 afs_FlushVCBs(afs_int32 lockit)
368 struct AFSFid *tfids;
369 struct AFSCallBack callBacks[1];
370 struct AFSCBFids fidArray;
371 struct AFSCBs cbArray;
373 struct afs_cbr *tcbrp;
377 struct vrequest treq;
379 int safety1, safety2, safety3;
381 if ((code = afs_InitReq(&treq, afs_osi_credp)))
383 treq.flags |= O_NONBLOCK;
384 tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
387 ObtainWriteLock(&afs_xvcb, 273);
388 ObtainReadLock(&afs_xserver);
389 for (i = 0; i < NSERVERS; i++) {
390 for (safety1 = 0, tsp = afs_servers[i];
391 tsp && safety1 < afs_totalServers + 10;
392 tsp = tsp->next, safety1++) {
394 if (tsp->cbrs == (struct afs_cbr *)0)
397 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
398 * and make an RPC, over and over again.
400 tcount = 0; /* number found so far */
401 for (safety2 = 0; safety2 < afs_cacheStats; safety2++) {
402 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
403 /* if buffer is full, or we've queued all we're going
404 * to from this server, we should flush out the
407 fidArray.AFSCBFids_len = tcount;
408 fidArray.AFSCBFids_val = (struct AFSFid *)tfids;
409 cbArray.AFSCBs_len = 1;
410 cbArray.AFSCBs_val = callBacks;
411 memset(&callBacks[0], 0, sizeof(callBacks[0]));
412 callBacks[0].CallBackType = CB_EXCLUSIVE;
413 for (safety3 = 0; safety3 < AFS_MAXHOSTS * 2; safety3++) {
414 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
415 tsp->cell->cellNum, &treq, 0,
419 (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
422 RXAFS_GiveUpCallBacks(tc->id, &fidArray,
430 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK,
435 /* ignore return code, since callbacks may have
436 * been returned anyway, we shouldn't leave them
437 * around to be returned again.
439 * Next, see if we are done with this server, and if so,
440 * break to deal with the next one.
446 /* if to flush full buffer */
447 /* if we make it here, we have an entry at the head of cbrs,
448 * which we should copy to the file ID array and then free.
451 tfids[tcount++] = tcbrp->fid;
453 /* Freeing the CBR will unlink it from the server's CBR list */
455 } /* while loop for this one server */
456 if (safety2 > afs_cacheStats) {
457 afs_warn("possible internal error afs_flushVCBs (%d)\n",
460 } /* for loop for this hash chain */
461 } /* loop through all hash chains */
462 if (safety1 > afs_totalServers + 2) {
464 ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n",
465 safety1, afs_totalServers + 2);
467 osi_Panic("afs_flushVCBS safety1");
470 ReleaseReadLock(&afs_xserver);
472 ReleaseWriteLock(&afs_xvcb);
473 afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
478 * Queue a callback on the given fid.
481 * Locks the xvcb lock.
482 * Called when the xvcache lock is already held.
484 * \param avc vcache entry
485 * \return 1 if queued, 0 otherwise
489 afs_QueueVCB(struct vcache *avc)
493 struct afs_cbr *tcbp;
495 AFS_STATCNT(afs_QueueVCB);
497 ObtainWriteLock(&afs_xvcb, 274);
499 /* we can't really give back callbacks on RO files, since the
500 * server only tracks them on a per-volume basis, and we don't
501 * know whether we still have some other files from the same
503 if (!((avc->f.states & CRO) == 0 && avc->callback)) {
507 /* The callback is really just a struct server ptr. */
508 tsp = (struct server *)(avc->callback);
510 /* we now have a pointer to the server, so we just allocate
511 * a queue entry and queue it.
513 tcbp = afs_AllocCBR();
514 tcbp->fid = avc->f.fid.Fid;
516 tcbp->next = tsp->cbrs;
518 tsp->cbrs->pprev = &tcbp->next;
521 tcbp->pprev = &tsp->cbrs;
523 afs_InsertHashCBR(tcbp);
527 /* now release locks and return */
528 ReleaseWriteLock(&afs_xvcb);
534 * Remove a queued callback for a given Fid.
537 * Locks xvcb and xserver locks.
538 * Typically called with xdcache, xvcache and/or individual vcache
541 * \param afid The fid we want cleansed of queued callbacks.
546 afs_RemoveVCB(struct VenusFid *afid)
549 struct afs_cbr *cbr, *ncbr;
551 AFS_STATCNT(afs_RemoveVCB);
552 ObtainWriteLock(&afs_xvcb, 275);
554 slot = afs_HashCBRFid(&afid->Fid);
555 ncbr = afs_cbrHashT[slot];
559 ncbr = cbr->hash_next;
561 if (afid->Fid.Volume == cbr->fid.Volume &&
562 afid->Fid.Vnode == cbr->fid.Vnode &&
563 afid->Fid.Unique == cbr->fid.Unique) {
568 ReleaseWriteLock(&afs_xvcb);
572 afs_FlushReclaimedVcaches(void)
574 #if !defined(AFS_LINUX22_ENV)
577 struct vcache *tmpReclaimedVCList = NULL;
579 ObtainWriteLock(&afs_xvreclaim, 76);
580 while (ReclaimedVCList) {
581 tvc = ReclaimedVCList; /* take from free list */
582 ReclaimedVCList = tvc->nextfree;
583 tvc->nextfree = NULL;
584 code = afs_FlushVCache(tvc, &fv_slept);
586 /* Ok, so, if we got code != 0, uh, wtf do we do? */
587 /* Probably, build a temporary list and then put all back when we
588 get to the end of the list */
589 /* This is actually really crappy, but we need to not leak these.
590 We probably need a way to be smarter about this. */
591 tvc->nextfree = tmpReclaimedVCList;
592 tmpReclaimedVCList = tvc;
593 /* printf("Reclaim list flush %lx failed: %d\n", (unsigned long) tvc, code); */
595 if (tvc->f.states & (CVInit
596 #ifdef AFS_DARWIN80_ENV
600 tvc->f.states &= ~(CVInit
601 #ifdef AFS_DARWIN80_ENV
605 afs_osi_Wakeup(&tvc->f.states);
608 if (tmpReclaimedVCList)
609 ReclaimedVCList = tmpReclaimedVCList;
611 ReleaseWriteLock(&afs_xvreclaim);
616 afs_ShakeLooseVCaches(afs_int32 anumber)
618 #if defined(AFS_LINUX22_ENV)
621 struct afs_q *tq, *uq;
623 afs_int32 target = anumber;
625 if (afsd_dynamic_vcaches || afs_vcount >= afs_maxvcount) {
627 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
630 if (tvc->f.states & CVFlushed) {
631 refpanic("CVFlushed on VLRU");
632 } else if (!afsd_dynamic_vcaches && i++ > afs_maxvcount) {
633 refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)");
634 } else if (QNext(uq) != tq) {
635 refpanic("VLRU inconsistent");
636 } else if (!VREFCOUNT_GT(tvc,0)) {
637 refpanic("refcnt 0 on VLRU");
640 #if defined(AFS_LINUX22_ENV)
641 if (tvc != afs_globalVp && VREFCOUNT(tvc) > 1 && tvc->opens == 0) {
642 struct dentry *dentry;
643 struct list_head *cur, *head;
645 #if defined(AFS_LINUX24_ENV)
646 spin_lock(&dcache_lock);
647 #endif /* AFS_LINUX24_ENV */
648 head = &(AFSTOV(tvc))->i_dentry;
652 while ((cur = cur->next) != head) {
653 dentry = list_entry(cur, struct dentry, d_alias);
655 if (d_unhashed(dentry))
660 #if defined(AFS_LINUX24_ENV)
661 spin_unlock(&dcache_lock);
662 #endif /* AFS_LINUX24_ENV */
663 if (d_invalidate(dentry) == -EBUSY) {
665 /* perhaps lock and try to continue? (use cur as head?) */
669 #if defined(AFS_LINUX24_ENV)
670 spin_lock(&dcache_lock);
671 #endif /* AFS_LINUX24_ENV */
674 #if defined(AFS_LINUX24_ENV)
675 spin_unlock(&dcache_lock);
676 #endif /* AFS_LINUX24_ENV */
680 #endif /* AFS_LINUX22_ENV */
682 if (VREFCOUNT_GT(tvc,0) && !VREFCOUNT_GT(tvc,1) &&
684 && (tvc->f.states & CUnlinkedDel) == 0) {
685 code = afs_FlushVCache(tvc, &fv_slept);
692 continue; /* start over - may have raced. */
698 if (!afsd_dynamic_vcaches && anumber == target) {
699 afs_warn("afs_ShakeLooseVCaches: warning none freed, using %d of %d\n",
700 afs_vcount, afs_maxvcount);
702 } /* finished freeing up space */
704 printf("recycled %d entries\n", target-anumber);
710 /* Alloc new vnode. */
712 static struct vcache *
713 afs_AllocVCache(void)
716 #if defined(AFS_LINUX22_ENV)
720 ip = new_inode(afs_globalVFS);
722 osi_Panic("afs_AllocVCache: no more inodes");
724 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
727 tvc = afs_osi_Alloc(sizeof(struct vcache));
728 ip->u.generic_ip = tvc;
735 if (afsd_dynamic_vcaches && afs_maxvcount < afs_vcount) {
736 afs_maxvcount = afs_vcount;
737 /*printf("peak vnodes: %d\n", afs_maxvcount);*/
740 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
742 /* none free, making one is better than a panic */
743 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
744 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
745 #if (defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)) && !defined(UKERNEL)
746 tvc->v = NULL; /* important to clean this, or use memset 0 */
747 #endif /* DARWIN || XBSD && !UKERNEL */
748 #ifdef KERNEL_HAVE_PIN
749 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
751 #if defined(AFS_SGI_ENV)
753 char name[METER_NAMSZ];
754 memset(tvc, 0, sizeof(struct vcache));
755 tvc->v.v_number = ++afsvnumbers;
756 tvc->vc_rwlockid = OSI_NO_LOCKID;
757 initnsema(&tvc->vc_rwlock, 1,
758 makesname(name, "vrw", tvc->v.v_number));
759 #ifndef AFS_SGI53_ENV
760 initnsema(&tvc->v.v_sync, 0,
761 makesname(name, "vsy", tvc->v.v_number));
763 #ifndef AFS_SGI62_ENV
764 initnlock(&tvc->v.v_lock,
765 makesname(name, "vlk", tvc->v.v_number));
768 #endif /* AFS_SGI_ENV */
770 #ifdef AFS_DISCON_ENV
771 /* If we create a new inode, we either give it a new slot number,
772 * or if one's available, use a slot number from the slot free list
774 if (afs_freeSlotList != NULL) {
775 struct afs_slotlist *tmp;
777 tvc->diskSlot = afs_freeSlotList->slot;
778 tmp = afs_freeSlotList;
779 afs_freeSlotList = tmp->next;
780 afs_osi_Free(tmp, sizeof(struct afs_slotlist));
782 tvc->diskSlot = afs_nextVcacheSlot++;
790 * This routine is responsible for allocating a new cache entry
791 * from the free list. It formats the cache entry and inserts it
792 * into the appropriate hash tables. It must be called with
793 * afs_xvcache write-locked so as to prevent several processes from
794 * trying to create a new cache entry simultaneously.
796 * LOCK: afs_NewVCache afs_xvcache W
798 * \param afid The file id of the file whose cache entry is being created.
800 * \return The new vcache struct.
803 static_inline struct vcache *
804 afs_NewVCache_int(struct VenusFid *afid, struct server *serverp, int seq)
808 afs_int32 anumber = VCACHE_FREE;
810 struct gnode *gnodepnt;
812 #if !defined(AFS_LINUX22_ENV)
813 struct afs_q *tq, *uq;
817 AFS_STATCNT(afs_NewVCache);
819 afs_FlushReclaimedVcaches();
821 #if defined(AFS_LINUX22_ENV)
822 if(!afsd_dynamic_vcaches) {
823 afs_ShakeLooseVCaches(anumber);
824 if (afs_vcount >= afs_maxvcount) {
825 afs_warn("afs_NewVCache - none freed\n");
829 tvc = afs_AllocVCache();
830 #else /* AFS_LINUX22_ENV */
831 /* pull out a free cache entry */
835 for (tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
839 if (tvc->f.states & CVFlushed) {
840 refpanic("CVFlushed on VLRU");
841 } else if (i++ > 2 * afs_cacheStats) { /* even allowing for a few xallocs... */
842 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
843 } else if (QNext(uq) != tq) {
844 refpanic("VLRU inconsistent");
845 } else if (tvc->f.states & CVInit) {
849 if (!VREFCOUNT_GT(tvc,0)
850 #if defined(AFS_DARWIN_ENV) && !defined(UKERNEL) && !defined(AFS_DARWIN80_ENV)
851 || ((VREFCOUNT(tvc) == 1) &&
852 (UBCINFOEXISTS(AFSTOV(tvc))))
854 && tvc->opens == 0 && (tvc->f.states & CUnlinkedDel) == 0) {
855 #if defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
856 #ifdef AFS_DARWIN80_ENV
857 vnode_t tvp = AFSTOV(tvc);
858 /* VREFCOUNT_GT only sees usecounts, not iocounts */
859 /* so this may fail to actually recycle the vnode now */
860 /* must call vnode_get to avoid races. */
862 if (vnode_get(tvp) == 0) {
864 /* must release lock, since vnode_put will immediately
865 reclaim if there are no other users */
866 ReleaseWriteLock(&afs_xvcache);
871 ObtainWriteLock(&afs_xvcache, 336);
873 /* we can't use the vnode_recycle return value to figure
874 * this out, since the iocount we have to hold makes it
876 if (AFSTOV(tvc) == tvp) {
877 if (anumber > 0 && fv_slept) {
878 QRemove(&tvc->vlruq);
879 QAdd(&VLRU, &tvc->vlruq);
884 #else /* AFS_DARWIN80_ENV */
886 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
887 * then it puts the vnode on the free list.
888 * If we don't do this we end up with a cleaned vnode that's
889 * not on the free list.
890 * XXX assume FreeBSD is the same for now.
893 #if defined(AFS_FBSD80_ENV)
894 /* vgone() is correct, but v_usecount is assumed not
895 * to be 0, and I suspect that currently our usage ensures that
897 if (vrefcnt(AFSTOV(tvc)) < 1) {
900 vn_lock(AFSTOV(tvc), LK_EXCLUSIVE | LK_RETRY); /* !glocked */
903 #if defined(AFS_FBSD80_ENV)
904 VOP_UNLOCK(AFSTOV(tvc), 0);
910 #else /* AFS_DARWIN80_ENV || AFS_XBSD_ENV */
911 code = afs_FlushVCache(tvc, &fv_slept);
912 #endif /* AFS_DARWIN80_ENV || AFS_XBSD_ENV */
921 continue; /* start over - may have raced. */
927 } /* end of if (!freeVCList) */
930 tvc = afs_AllocVCache();
932 tvc = freeVCList; /* take from free list */
933 freeVCList = tvc->nextfree;
934 tvc->nextfree = NULL;
935 } /* end of if (!freeVCList) */
937 #endif /* AFS_LINUX22_ENV */
939 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
941 panic("afs_NewVCache(): free vcache with vnode attached");
944 #if !defined(AFS_SGI_ENV) && !defined(AFS_LINUX22_ENV)
946 #if defined(AFS_DISCON_ENV)
947 /* We need to preserve the slot that we're being stored into on
951 slot = tvc->diskSlot;
952 memset(tvc, 0, sizeof(struct vcache));
953 tvc->diskSlot = slot;
956 memset(tvc, 0, sizeof(struct vcache));
961 memset(&(tvc->f), 0, sizeof(struct fvcache));
964 AFS_RWLOCK_INIT(&tvc->lock, "vcache lock");
965 #if defined(AFS_SUN5_ENV)
966 AFS_RWLOCK_INIT(&tvc->vlock, "vcache vlock");
967 #endif /* defined(AFS_SUN5_ENV) */
970 tvc->linkData = NULL;
973 tvc->execsOrWriters = 0;
975 tvc->f.states = CVInit;
976 tvc->last_looker = 0;
978 tvc->asynchrony = -1;
980 #if defined(AFS_LINUX26_ENV)
984 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
987 tvc->f.truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
988 hzero(tvc->f.m.DataVersion); /* in case we copy it into flushDV */
990 tvc->callback = serverp; /* to minimize chance that clear
992 #if defined(AFS_DISCON_ENV)
993 QZero(&tvc->metadirty);
999 tvc->hnext = afs_vhashT[i];
1000 afs_vhashT[i] = tvc;
1001 QAdd(&afs_vhashTV[j], &tvc->vhashq);
1003 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1004 refpanic("NewVCache VLRU inconsistent");
1006 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
1007 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1008 refpanic("NewVCache VLRU inconsistent2");
1010 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1011 refpanic("NewVCache VLRU inconsistent3");
1013 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1014 refpanic("NewVCache VLRU inconsistent4");
1017 /* it should now be safe to drop the xvcache lock */
1019 ReleaseWriteLock(&afs_xvcache);
1021 afs_nbsd_getnewvnode(tvc); /* includes one refcount */
1023 ObtainWriteLock(&afs_xvcache,337);
1024 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
1026 #ifdef AFS_DARWIN_ENV
1027 ReleaseWriteLock(&afs_xvcache);
1029 afs_darwin_getnewvnode(tvc, seq ? 0 : 1); /* includes one refcount */
1031 ObtainWriteLock(&afs_xvcache,338);
1032 #ifdef AFS_DARWIN80_ENV
1033 LOCKINIT(tvc->rwlock);
1035 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
1042 ReleaseWriteLock(&afs_xvcache);
1044 #if defined(AFS_FBSD60_ENV)
1045 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
1046 #elif defined(AFS_FBSD50_ENV)
1047 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
1049 if (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
1051 panic("afs getnewvnode"); /* can't happen */
1052 #ifdef AFS_FBSD70_ENV
1053 /* XXX verified on 80--TODO check on 7x */
1055 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* !glocked */
1056 insmntque(vp, afs_globalVFS);
1061 ObtainWriteLock(&afs_xvcache,339);
1062 if (tvc->v != NULL) {
1063 /* I'd like to know if this ever happens...
1064 * We don't drop global for the rest of this function,
1065 * so if we do lose the race, the other thread should
1066 * have found the same vnode and finished initializing
1067 * the vcache entry. Is it conceivable that this vcache
1068 * entry could be recycled during this interval? If so,
1069 * then there probably needs to be some sort of additional
1070 * mutual exclusion (an Embryonic flag would suffice).
1072 afs_warn("afs_NewVCache: lost the race\n");
1076 tvc->v->v_data = tvc;
1077 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
1081 #if defined(AFS_LINUX22_ENV)
1082 /* Hold it for the LRU (should make count 2) */
1083 VN_HOLD(AFSTOV(tvc));
1084 #elif !(defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV))
1085 VREFCOUNT_SET(tvc, 1); /* us */
1088 #ifdef AFS_AIX32_ENV
1089 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
1090 tvc->vmh = tvc->segid = NULL;
1094 #if defined(AFS_CACHE_BYPASS)
1095 tvc->cachingStates = 0;
1096 tvc->cachingTransitions = 0;
1099 #ifdef AFS_BOZONLOCK_ENV
1100 #if defined(AFS_SUN5_ENV)
1101 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
1103 #if defined(AFS_SUN55_ENV)
1104 /* This is required if the kaio (kernel aynchronous io)
1105 ** module is installed. Inside the kernel, the function
1106 ** check_vp( common/os/aio.c) checks to see if the kernel has
1107 ** to provide asynchronous io for this vnode. This
1108 ** function extracts the device number by following the
1109 ** v_data field of the vnode. If we do not set this field
1110 ** then the system panics. The value of the v_data field
1111 ** is not really important for AFS vnodes because the kernel
1112 ** does not do asynchronous io for regular files. Hence,
1113 ** for the time being, we fill up the v_data field with the
1114 ** vnode pointer itself. */
1115 tvc->v.v_data = (char *)tvc;
1116 #endif /* AFS_SUN55_ENV */
1118 afs_BozonInit(&tvc->pvnLock, tvc);
1121 /* initialize vnode data, note vrefCount is v.v_count */
1123 /* Don't forget to free the gnode space */
1124 tvc->v.v_gnode = gnodepnt =
1125 (struct gnode *)osi_AllocSmallSpace(sizeof(struct gnode));
1126 memset(gnodepnt, 0, sizeof(struct gnode));
1128 #ifdef AFS_SGI64_ENV
1129 memset((void *)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc));
1130 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
1131 #ifdef AFS_SGI65_ENV
1132 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
1133 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1135 bhv_head_init(&(tvc->v.v_bh));
1136 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1138 #ifdef AFS_SGI65_ENV
1139 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion *)tvc;
1140 #ifdef VNODE_TRACING
1141 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
1143 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
1145 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
1146 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
1148 vnode_pcache_init(&tvc->v);
1149 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
1150 /* Above define is never true except in SGI test kernels. */
1151 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number));
1153 #ifdef INTR_KTHREADS
1154 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
1157 SetAfsVnode(AFSTOV(tvc));
1158 #endif /* AFS_SGI64_ENV */
1160 * The proper value for mvstat (for root fids) is setup by the caller.
1163 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
1165 if (afs_globalVFS == 0)
1166 osi_Panic("afs globalvfs");
1167 #if !defined(AFS_LINUX22_ENV)
1168 vSetVfsp(tvc, afs_globalVFS);
1170 vSetType(tvc, VREG);
1172 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
1173 tvc->v.v_vfsprev = NULL;
1174 afs_globalVFS->vfs_vnodes = &tvc->v;
1175 if (tvc->v.v_vfsnext != NULL)
1176 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
1177 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us! */
1178 gnodepnt->gn_vnode = &tvc->v;
1180 #if defined(AFS_SGI_ENV)
1181 VN_SET_DPAGES(&(tvc->v), (struct pfdat *)NULL);
1182 osi_Assert((tvc->v.v_flag & VINACT) == 0);
1184 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
1185 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
1186 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
1187 osi_Assert(tvc->v.v_filocks == NULL);
1188 #if !defined(AFS_SGI65_ENV)
1189 osi_Assert(tvc->v.v_filocksem == NULL);
1191 osi_Assert(tvc->cred == NULL);
1192 #ifdef AFS_SGI64_ENV
1193 vnode_pcache_reinit(&tvc->v);
1194 tvc->v.v_rdev = NODEV;
1196 vn_initlist((struct vnlist *)&tvc->v);
1198 #endif /* AFS_SGI_ENV */
1200 osi_dnlc_purgedp(tvc); /* this may be overkill */
1201 memset(&(tvc->callsort), 0, sizeof(struct afs_q));
1203 tvc->f.states &=~ CVInit;
1205 tvc->f.states |= CBulkFetching;
1206 tvc->f.m.Length = seq;
1208 afs_osi_Wakeup(&tvc->f.states);
1211 } /*afs_NewVCache */
1215 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
1217 return afs_NewVCache_int(afid, serverp, 0);
1221 afs_NewBulkVCache(struct VenusFid *afid, struct server *serverp, int seq)
1223 return afs_NewVCache_int(afid, serverp, seq);
1229 * LOCK: afs_FlushActiveVcaches afs_xvcache N
1231 * \param doflocks : Do we handle flocks?
1234 afs_FlushActiveVcaches(register afs_int32 doflocks)
1236 register struct vcache *tvc;
1238 register struct afs_conn *tc;
1239 register afs_int32 code;
1240 afs_ucred_t *cred = NULL;
1241 struct vrequest treq, ureq;
1242 struct AFSVolSync tsync;
1245 AFS_STATCNT(afs_FlushActiveVcaches);
1246 ObtainReadLock(&afs_xvcache);
1247 for (i = 0; i < VCSIZE; i++) {
1248 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1249 if (tvc->f.states & CVInit) continue;
1250 #ifdef AFS_DARWIN80_ENV
1251 if (tvc->f.states & CDeadVnode &&
1252 (tvc->f.states & (CCore|CUnlinkedDel) ||
1253 tvc->flockCount)) panic("Dead vnode has core/unlinkedel/flock");
1255 if (doflocks && tvc->flockCount != 0) {
1256 /* if this entry has an flock, send a keep-alive call out */
1258 ReleaseReadLock(&afs_xvcache);
1259 ObtainWriteLock(&tvc->lock, 51);
1261 afs_InitReq(&treq, afs_osi_credp);
1262 treq.flags |= O_NONBLOCK;
1264 tc = afs_Conn(&tvc->f.fid, &treq, SHARED_LOCK);
1266 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1269 RXAFS_ExtendLock(tc->id,
1270 (struct AFSFid *)&tvc->f.fid.Fid,
1276 } while (afs_Analyze
1277 (tc, code, &tvc->f.fid, &treq,
1278 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1280 ReleaseWriteLock(&tvc->lock);
1281 #ifdef AFS_DARWIN80_ENV
1283 ObtainReadLock(&afs_xvcache);
1285 ObtainReadLock(&afs_xvcache);
1290 if ((tvc->f.states & CCore) || (tvc->f.states & CUnlinkedDel)) {
1292 * Don't let it evaporate in case someone else is in
1293 * this code. Also, drop the afs_xvcache lock while
1294 * getting vcache locks.
1297 ReleaseReadLock(&afs_xvcache);
1298 #ifdef AFS_BOZONLOCK_ENV
1299 afs_BozonLock(&tvc->pvnLock, tvc);
1301 #if defined(AFS_SGI_ENV)
1303 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1305 osi_Assert(VREFCOUNT_GT(tvc,0));
1306 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1308 ObtainWriteLock(&tvc->lock, 52);
1309 if (tvc->f.states & CCore) {
1310 tvc->f.states &= ~CCore;
1311 /* XXXX Find better place-holder for cred XXXX */
1312 cred = (afs_ucred_t *)tvc->linkData;
1313 tvc->linkData = NULL; /* XXX */
1314 afs_InitReq(&ureq, cred);
1315 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1316 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1317 tvc->execsOrWriters);
1318 code = afs_StoreOnLastReference(tvc, &ureq);
1319 ReleaseWriteLock(&tvc->lock);
1320 #ifdef AFS_BOZONLOCK_ENV
1321 afs_BozonUnlock(&tvc->pvnLock, tvc);
1323 hzero(tvc->flushDV);
1326 if (code && code != VNOVNODE) {
1327 afs_StoreWarn(code, tvc->f.fid.Fid.Volume,
1328 /* /dev/console */ 1);
1330 } else if (tvc->f.states & CUnlinkedDel) {
1334 ReleaseWriteLock(&tvc->lock);
1335 #ifdef AFS_BOZONLOCK_ENV
1336 afs_BozonUnlock(&tvc->pvnLock, tvc);
1338 #if defined(AFS_SGI_ENV)
1339 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1341 afs_remunlink(tvc, 0);
1342 #if defined(AFS_SGI_ENV)
1343 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1346 /* lost (or won, perhaps) the race condition */
1347 ReleaseWriteLock(&tvc->lock);
1348 #ifdef AFS_BOZONLOCK_ENV
1349 afs_BozonUnlock(&tvc->pvnLock, tvc);
1352 #if defined(AFS_SGI_ENV)
1353 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1355 #ifdef AFS_DARWIN80_ENV
1358 AFS_RELE(AFSTOV(tvc));
1359 /* Matches write code setting CCore flag */
1362 ObtainReadLock(&afs_xvcache);
1364 ObtainReadLock(&afs_xvcache);
1367 AFS_RELE(AFSTOV(tvc));
1368 /* Matches write code setting CCore flag */
1375 ReleaseReadLock(&afs_xvcache);
1381 * Make sure a cache entry is up-to-date status-wise.
1383 * NOTE: everywhere that calls this can potentially be sped up
1384 * by checking CStatd first, and avoiding doing the InitReq
1385 * if this is up-to-date.
1387 * Anymore, the only places that call this KNOW already that the
1388 * vcache is not up-to-date, so we don't screw around.
1390 * \param avc : Ptr to vcache entry to verify.
1396 * Make sure a cache entry is up-to-date status-wise.
1398 * NOTE: everywhere that calls this can potentially be sped up
1399 * by checking CStatd first, and avoiding doing the InitReq
1400 * if this is up-to-date.
1402 * Anymore, the only places that call this KNOW already that the
1403 * vcache is not up-to-date, so we don't screw around.
1405 * \param avc Pointer to vcache entry to verify.
1408 * \return 0 for success or other error codes.
1411 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1413 register struct vcache *tvc;
1415 AFS_STATCNT(afs_VerifyVCache);
1417 /* otherwise we must fetch the status info */
1419 ObtainWriteLock(&avc->lock, 53);
1420 if (avc->f.states & CStatd) {
1421 ReleaseWriteLock(&avc->lock);
1424 ObtainWriteLock(&afs_xcbhash, 461);
1425 avc->f.states &= ~(CStatd | CUnique);
1426 avc->callback = NULL;
1427 afs_DequeueCallback(avc);
1428 ReleaseWriteLock(&afs_xcbhash);
1429 ReleaseWriteLock(&avc->lock);
1431 /* since we've been called back, or the callback has expired,
1432 * it's possible that the contents of this directory, or this
1433 * file's name have changed, thus invalidating the dnlc contents.
1435 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1436 osi_dnlc_purgedp(avc);
1438 osi_dnlc_purgevp(avc);
1440 /* fetch the status info */
1441 tvc = afs_GetVCache(&avc->f.fid, areq, NULL, avc);
1444 /* Put it back; caller has already incremented vrefCount */
1448 } /*afs_VerifyVCache */
1452 * Simple copy of stat info into cache.
1454 * Callers:as of 1992-04-29, only called by WriteVCache
1456 * \param avc Ptr to vcache entry involved.
1457 * \param astat Ptr to stat info to copy.
1461 afs_SimpleVStat(register struct vcache *avc,
1462 register struct AFSFetchStatus *astat, struct vrequest *areq)
1465 AFS_STATCNT(afs_SimpleVStat);
1468 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1469 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1471 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1473 #ifdef AFS_64BIT_CLIENT
1474 FillInt64(length, astat->Length_hi, astat->Length);
1475 #else /* AFS_64BIT_CLIENT */
1476 length = astat->Length;
1477 #endif /* AFS_64BIT_CLIENT */
1478 #if defined(AFS_SGI_ENV)
1479 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1480 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1481 if (length < avc->f.m.Length) {
1482 vnode_t *vp = (vnode_t *) avc;
1484 osi_Assert(WriteLocked(&avc->lock));
1485 ReleaseWriteLock(&avc->lock);
1487 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1489 ObtainWriteLock(&avc->lock, 67);
1492 /* if writing the file, don't fetch over this value */
1493 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1494 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1495 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1496 avc->f.m.Length = length;
1497 avc->f.m.Date = astat->ClientModTime;
1499 avc->f.m.Owner = astat->Owner;
1500 avc->f.m.Group = astat->Group;
1501 avc->f.m.Mode = astat->UnixModeBits;
1502 if (vType(avc) == VREG) {
1503 avc->f.m.Mode |= S_IFREG;
1504 } else if (vType(avc) == VDIR) {
1505 avc->f.m.Mode |= S_IFDIR;
1506 } else if (vType(avc) == VLNK) {
1507 avc->f.m.Mode |= S_IFLNK;
1508 if ((avc->f.m.Mode & 0111) == 0)
1511 if (avc->f.states & CForeign) {
1512 struct axscache *ac;
1513 avc->f.anyAccess = astat->AnonymousAccess;
1515 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1517 * Caller has at least one bit not covered by anonymous, and
1518 * thus may have interesting rights.
1520 * HOWEVER, this is a really bad idea, because any access query
1521 * for bits which aren't covered by anonymous, on behalf of a user
1522 * who doesn't have any special rights, will result in an answer of
1523 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1524 * It's an especially bad idea under Ultrix, since (due to the lack of
1525 * a proper access() call) it must perform several afs_access() calls
1526 * in order to create magic mode bits that vary according to who makes
1527 * the call. In other words, _every_ stat() generates a test for
1530 #endif /* badidea */
1531 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1532 ac->axess = astat->CallerAccess;
1533 else /* not found, add a new one if possible */
1534 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1537 } /*afs_SimpleVStat */
1541 * Store the status info *only* back to the server for a
1544 * Environment: Must be called with a shared lock held on the vnode.
1546 * \param avc Ptr to the vcache entry.
1547 * \param astatus Ptr to the status info to store.
1548 * \param areq Ptr to the associated vrequest.
1550 * \return Operation status.
1554 afs_WriteVCache(register struct vcache *avc,
1555 register struct AFSStoreStatus *astatus,
1556 struct vrequest *areq)
1559 struct afs_conn *tc;
1560 struct AFSFetchStatus OutStatus;
1561 struct AFSVolSync tsync;
1563 AFS_STATCNT(afs_WriteVCache);
1564 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1565 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length));
1567 tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
1569 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1572 RXAFS_StoreStatus(tc->id, (struct AFSFid *)&avc->f.fid.Fid,
1573 astatus, &OutStatus, &tsync);
1578 } while (afs_Analyze
1579 (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1580 SHARED_LOCK, NULL));
1582 UpgradeSToWLock(&avc->lock, 20);
1584 /* success, do the changes locally */
1585 afs_SimpleVStat(avc, &OutStatus, areq);
1587 * Update the date, too. SimpleVStat didn't do this, since
1588 * it thought we were doing this after fetching new status
1589 * over a file being written.
1591 avc->f.m.Date = OutStatus.ClientModTime;
1593 /* failure, set up to check with server next time */
1594 ObtainWriteLock(&afs_xcbhash, 462);
1595 afs_DequeueCallback(avc);
1596 avc->f.states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1597 ReleaseWriteLock(&afs_xcbhash);
1598 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
1599 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1601 ConvertWToSLock(&avc->lock);
1604 } /*afs_WriteVCache */
1605 #if defined(AFS_DISCON_ENV)
1608 * Store status info only locally, set the proper disconnection flags
1609 * and add to dirty list.
1611 * \param avc The vcache to be written locally.
1612 * \param astatus Get attr fields from local store.
1613 * \param attrs This one is only of the vs_size.
1615 * \note Must be called with a shared lock on the vnode
1617 int afs_WriteVCacheDiscon(register struct vcache *avc,
1618 register struct AFSStoreStatus *astatus,
1619 struct vattr *attrs)
1622 afs_int32 flags = 0;
1624 UpgradeSToWLock(&avc->lock, 700);
1626 if (!astatus->Mask) {
1632 /* Set attributes. */
1633 if (astatus->Mask & AFS_SETMODTIME) {
1634 avc->f.m.Date = astatus->ClientModTime;
1635 flags |= VDisconSetTime;
1638 if (astatus->Mask & AFS_SETOWNER) {
1639 /* printf("Not allowed yet. \n"); */
1640 /*avc->f.m.Owner = astatus->Owner;*/
1643 if (astatus->Mask & AFS_SETGROUP) {
1644 /* printf("Not allowed yet. \n"); */
1645 /*avc->f.m.Group = astatus->Group;*/
1648 if (astatus->Mask & AFS_SETMODE) {
1649 avc->f.m.Mode = astatus->UnixModeBits;
1651 #if 0 /* XXX: Leaving this out, so it doesn't mess up the file type flag.*/
1653 if (vType(avc) == VREG) {
1654 avc->f.m.Mode |= S_IFREG;
1655 } else if (vType(avc) == VDIR) {
1656 avc->f.m.Mode |= S_IFDIR;
1657 } else if (vType(avc) == VLNK) {
1658 avc->f.m.Mode |= S_IFLNK;
1659 if ((avc->f.m.Mode & 0111) == 0)
1663 flags |= VDisconSetMode;
1664 } /* if(astatus.Mask & AFS_SETMODE) */
1666 } /* if (!astatus->Mask) */
1668 if (attrs->va_size > 0) {
1669 /* XXX: Do I need more checks? */
1670 /* Truncation operation. */
1671 flags |= VDisconTrunc;
1675 afs_DisconAddDirty(avc, flags, 1);
1677 /* XXX: How about the rest of the fields? */
1679 ConvertWToSLock(&avc->lock);
1687 * Copy astat block into vcache info
1689 * \note This code may get dataversion and length out of sync if the file has
1690 * been modified. This is less than ideal. I haven't thought about it sufficiently
1691 * to be certain that it is adequate.
1693 * \note Environment: Must be called under a write lock
1695 * \param avc Ptr to vcache entry.
1696 * \param astat Ptr to stat block to copy in.
1697 * \param areq Ptr to associated request.
1700 afs_ProcessFS(register struct vcache *avc,
1701 register struct AFSFetchStatus *astat, struct vrequest *areq)
1704 AFS_STATCNT(afs_ProcessFS);
1706 #ifdef AFS_64BIT_CLIENT
1707 FillInt64(length, astat->Length_hi, astat->Length);
1708 #else /* AFS_64BIT_CLIENT */
1709 length = astat->Length;
1710 #endif /* AFS_64BIT_CLIENT */
1711 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1712 * number for each bulk status request. Under no circumstances
1713 * should afs_DoBulkStat store a sequence number if the new
1714 * length will be ignored when afs_ProcessFS is called with
1715 * new stats. If you change the following conditional then you
1716 * also need to change the conditional in afs_DoBulkStat. */
1718 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1719 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1721 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1723 /* if we're writing or mapping this file, don't fetch over these
1726 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1727 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->f.m.Length),
1728 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1729 avc->f.m.Length = length;
1730 avc->f.m.Date = astat->ClientModTime;
1732 hset64(avc->f.m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1733 avc->f.m.Owner = astat->Owner;
1734 avc->f.m.Mode = astat->UnixModeBits;
1735 avc->f.m.Group = astat->Group;
1736 avc->f.m.LinkCount = astat->LinkCount;
1737 if (astat->FileType == File) {
1738 vSetType(avc, VREG);
1739 avc->f.m.Mode |= S_IFREG;
1740 } else if (astat->FileType == Directory) {
1741 vSetType(avc, VDIR);
1742 avc->f.m.Mode |= S_IFDIR;
1743 } else if (astat->FileType == SymbolicLink) {
1744 if (afs_fakestat_enable && (avc->f.m.Mode & 0111) == 0) {
1745 vSetType(avc, VDIR);
1746 avc->f.m.Mode |= S_IFDIR;
1748 vSetType(avc, VLNK);
1749 avc->f.m.Mode |= S_IFLNK;
1751 if ((avc->f.m.Mode & 0111) == 0) {
1755 avc->f.anyAccess = astat->AnonymousAccess;
1757 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1759 * Caller has at least one bit not covered by anonymous, and
1760 * thus may have interesting rights.
1762 * HOWEVER, this is a really bad idea, because any access query
1763 * for bits which aren't covered by anonymous, on behalf of a user
1764 * who doesn't have any special rights, will result in an answer of
1765 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1766 * It's an especially bad idea under Ultrix, since (due to the lack of
1767 * a proper access() call) it must perform several afs_access() calls
1768 * in order to create magic mode bits that vary according to who makes
1769 * the call. In other words, _every_ stat() generates a test for
1772 #endif /* badidea */
1774 struct axscache *ac;
1775 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1776 ac->axess = astat->CallerAccess;
1777 else /* not found, add a new one if possible */
1778 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1780 } /*afs_ProcessFS */
1784 * Get fid from server.
1787 * \param areq Request to be passed on.
1788 * \param name Name of ?? to lookup.
1789 * \param OutStatus Fetch status.
1794 * \return Success status of operation.
1797 afs_RemoteLookup(register struct VenusFid *afid, struct vrequest *areq,
1798 char *name, struct VenusFid *nfid,
1799 struct AFSFetchStatus *OutStatusp,
1800 struct AFSCallBack *CallBackp, struct server **serverp,
1801 struct AFSVolSync *tsyncp)
1805 register struct afs_conn *tc;
1806 struct AFSFetchStatus OutDirStatus;
1809 name = ""; /* XXX */
1811 tc = afs_Conn(afid, areq, SHARED_LOCK);
1814 *serverp = tc->srvr->server;
1816 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1819 RXAFS_Lookup(tc->id, (struct AFSFid *)&afid->Fid, name,
1820 (struct AFSFid *)&nfid->Fid, OutStatusp,
1821 &OutDirStatus, CallBackp, tsyncp);
1826 } while (afs_Analyze
1827 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1837 * Given a file id and a vrequest structure, fetch the status
1838 * information associated with the file.
1840 * \param afid File ID.
1841 * \param areq Ptr to associated vrequest structure, specifying the
1842 * user whose authentication tokens will be used.
1843 * \param avc Caller may already have a vcache for this file, which is
1846 * \note Environment:
1847 * The cache entry is returned with an increased vrefCount field.
1848 * The entry must be discarded by calling afs_PutVCache when you
1849 * are through using the pointer to the cache entry.
1851 * You should not hold any locks when calling this function, except
1852 * locks on other vcache entries. If you lock more than one vcache
1853 * entry simultaneously, you should lock them in this order:
1855 * 1. Lock all files first, then directories.
1856 * 2. Within a particular type, lock entries in Fid.Vnode order.
1858 * This locking hierarchy is convenient because it allows locking
1859 * of a parent dir cache entry, given a file (to check its access
1860 * control list). It also allows renames to be handled easily by
1861 * locking directories in a constant order.
1863 * \note NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1865 * \note Might have a vcache structure already, which must
1866 * already be held by the caller
1869 afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq,
1870 afs_int32 * cached, struct vcache *avc)
1873 afs_int32 code, newvcache = 0;
1874 register struct vcache *tvc;
1878 AFS_STATCNT(afs_GetVCache);
1881 *cached = 0; /* Init just in case */
1883 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1887 ObtainSharedLock(&afs_xvcache, 5);
1889 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU | IS_SLOCK);
1891 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1892 ReleaseSharedLock(&afs_xvcache);
1893 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1901 osi_Assert((tvc->f.states & CVInit) == 0);
1902 /* If we are in readdir, return the vnode even if not statd */
1903 if ((tvc->f.states & CStatd) || afs_InReadDir(tvc)) {
1904 ReleaseSharedLock(&afs_xvcache);
1908 UpgradeSToWLock(&afs_xvcache, 21);
1910 /* no cache entry, better grab one */
1911 tvc = afs_NewVCache(afid, NULL);
1914 ConvertWToSLock(&afs_xvcache);
1917 ReleaseSharedLock(&afs_xvcache);
1921 afs_stats_cmperf.vcacheMisses++;
1924 ReleaseSharedLock(&afs_xvcache);
1926 ObtainWriteLock(&tvc->lock, 54);
1928 if (tvc->f.states & CStatd) {
1929 ReleaseWriteLock(&tvc->lock);
1932 #ifdef AFS_DARWIN80_ENV
1933 /* Darwin 8.0 only has bufs in nfs, so we shouldn't have to worry about them.
1936 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1938 * XXX - I really don't like this. Should try to understand better.
1939 * It seems that sometimes, when we get called, we already hold the
1940 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1941 * We can't drop the vnode lock, because that could result in a race.
1942 * Sometimes, though, we get here and don't hold the vnode lock.
1943 * I hate code paths that sometimes hold locks and sometimes don't.
1944 * In any event, the dodge we use here is to check whether the vnode
1945 * is locked, and if it isn't, then we gain and drop it around the call
1946 * to vinvalbuf; otherwise, we leave it alone.
1949 struct vnode *vp = AFSTOV(tvc);
1952 #if defined(AFS_DARWIN_ENV)
1953 iheldthelock = VOP_ISLOCKED(vp);
1955 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc());
1956 /* this is messy. we can call fsync which will try to reobtain this */
1957 if (VTOAFS(vp) == tvc)
1958 ReleaseWriteLock(&tvc->lock);
1959 if (UBCINFOEXISTS(vp)) {
1960 vinvalbuf(vp, V_SAVE, &afs_osi_cred, current_proc(), PINOD, 0);
1962 if (VTOAFS(vp) == tvc)
1963 ObtainWriteLock(&tvc->lock, 954);
1965 VOP_UNLOCK(vp, LK_EXCLUSIVE, current_proc());
1966 #elif defined(AFS_FBSD80_ENV)
1967 iheldthelock = VOP_ISLOCKED(vp);
1968 if (!iheldthelock) {
1969 /* nosleep/sleep lock order reversal */
1970 int glocked = ISAFS_GLOCK();
1973 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1977 vinvalbuf(vp, V_SAVE, PINOD, 0); /* changed late in 8.0-CURRENT */
1980 #elif defined(AFS_FBSD60_ENV)
1981 iheldthelock = VOP_ISLOCKED(vp, curthread);
1983 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1984 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1986 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1987 #elif defined(AFS_FBSD50_ENV)
1988 iheldthelock = VOP_ISLOCKED(vp, curthread);
1990 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1991 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1993 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1994 #elif defined(AFS_FBSD40_ENV)
1995 iheldthelock = VOP_ISLOCKED(vp, curproc);
1997 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1998 vinvalbuf(vp, V_SAVE, osi_curcred(), curproc, PINOD, 0);
2000 VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
2001 #elif defined(AFS_OBSD_ENV)
2002 iheldthelock = VOP_ISLOCKED(vp, curproc);
2004 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
2005 uvm_vnp_uncache(vp);
2007 VOP_UNLOCK(vp, 0, curproc);
2013 ObtainWriteLock(&afs_xcbhash, 464);
2014 tvc->f.states &= ~CUnique;
2016 afs_DequeueCallback(tvc);
2017 ReleaseWriteLock(&afs_xcbhash);
2019 /* It is always appropriate to throw away all the access rights? */
2020 afs_FreeAllAxs(&(tvc->Access));
2021 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
2023 if ((tvp->states & VForeign)) {
2025 tvc->f.states |= CForeign;
2026 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
2027 && (tvp->rootUnique == afid->Fid.Unique)) {
2031 if (tvp->states & VRO)
2032 tvc->f.states |= CRO;
2033 if (tvp->states & VBackup)
2034 tvc->f.states |= CBackup;
2035 /* now copy ".." entry back out of volume structure, if necessary */
2036 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2038 tvc->mvid = (struct VenusFid *)
2039 osi_AllocSmallSpace(sizeof(struct VenusFid));
2040 *tvc->mvid = tvp->dotdot;
2042 afs_PutVolume(tvp, READ_LOCK);
2046 afs_RemoveVCB(afid);
2048 struct AFSFetchStatus OutStatus;
2050 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
2051 afs_ProcessFS(tvc, &OutStatus, areq);
2052 tvc->f.states |= CStatd | CUnique;
2053 tvc->f.parent.vnode = OutStatus.ParentVnode;
2054 tvc->f.parent.unique = OutStatus.ParentUnique;
2058 if (AFS_IS_DISCONNECTED) {
2059 /* Nothing to do otherwise...*/
2061 /* printf("Network is down in afs_GetCache"); */
2063 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
2065 /* For the NFS translator's benefit, make sure
2066 * non-directory vnodes always have their parent FID set
2067 * correctly, even when created as a result of decoding an
2068 * NFS filehandle. It would be nice to also do this for
2069 * directories, but we can't because the fileserver fills
2070 * in the FID of the directory itself instead of that of
2073 if (!code && OutStatus.FileType != Directory &&
2074 !tvc->f.parent.vnode) {
2075 tvc->f.parent.vnode = OutStatus.ParentVnode;
2076 tvc->f.parent.unique = OutStatus.ParentUnique;
2077 /* XXX - SXW - It's conceivable we should mark ourselves
2078 * as dirty again here, incase we've been raced
2079 * out of the FetchStatus call.
2086 ReleaseWriteLock(&tvc->lock);
2092 ReleaseWriteLock(&tvc->lock);
2095 } /*afs_GetVCache */
2100 * Lookup a vcache by fid. Look inside the cache first, if not
2101 * there, lookup the file on the server, and then get it's fresh
2106 * \param cached Is element cached? If NULL, don't answer.
2110 * \return The found element or NULL.
2113 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
2114 afs_int32 * cached, struct vcache *adp, char *aname)
2116 afs_int32 code, now, newvcache = 0;
2117 struct VenusFid nfid;
2118 register struct vcache *tvc;
2120 struct AFSFetchStatus OutStatus;
2121 struct AFSCallBack CallBack;
2122 struct AFSVolSync tsync;
2123 struct server *serverp = 0;
2127 AFS_STATCNT(afs_GetVCache);
2129 *cached = 0; /* Init just in case */
2131 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2135 ObtainReadLock(&afs_xvcache);
2136 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
2139 ReleaseReadLock(&afs_xvcache);
2141 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2142 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2146 ObtainReadLock(&tvc->lock);
2148 if (tvc->f.states & CStatd) {
2152 ReleaseReadLock(&tvc->lock);
2155 tvc->f.states &= ~CUnique;
2157 ReleaseReadLock(&tvc->lock);
2159 ObtainReadLock(&afs_xvcache);
2162 ReleaseReadLock(&afs_xvcache);
2164 /* lookup the file */
2167 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
2169 if (AFS_IS_DISCONNECTED) {
2170 /* printf("Network is down in afs_LookupVcache\n"); */
2174 afs_RemoteLookup(&adp->f.fid, areq, aname, &nfid, &OutStatus,
2175 &CallBack, &serverp, &tsync);
2177 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2181 ObtainSharedLock(&afs_xvcache, 6);
2182 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU | IS_SLOCK/* no xstats now */ );
2184 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2185 ReleaseSharedLock(&afs_xvcache);
2186 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2192 /* no cache entry, better grab one */
2193 UpgradeSToWLock(&afs_xvcache, 22);
2194 tvc = afs_NewVCache(&nfid, serverp);
2196 ConvertWToSLock(&afs_xvcache);
2199 ReleaseSharedLock(&afs_xvcache);
2204 ReleaseSharedLock(&afs_xvcache);
2205 ObtainWriteLock(&tvc->lock, 55);
2207 /* It is always appropriate to throw away all the access rights? */
2208 afs_FreeAllAxs(&(tvc->Access));
2209 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
2211 if ((tvp->states & VForeign)) {
2213 tvc->f.states |= CForeign;
2214 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
2215 && (tvp->rootUnique == afid->Fid.Unique))
2218 if (tvp->states & VRO)
2219 tvc->f.states |= CRO;
2220 if (tvp->states & VBackup)
2221 tvc->f.states |= CBackup;
2222 /* now copy ".." entry back out of volume structure, if necessary */
2223 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2225 tvc->mvid = (struct VenusFid *)
2226 osi_AllocSmallSpace(sizeof(struct VenusFid));
2227 *tvc->mvid = tvp->dotdot;
2232 ObtainWriteLock(&afs_xcbhash, 465);
2233 afs_DequeueCallback(tvc);
2234 tvc->f.states &= ~(CStatd | CUnique);
2235 ReleaseWriteLock(&afs_xcbhash);
2236 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2237 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2239 afs_PutVolume(tvp, READ_LOCK);
2240 ReleaseWriteLock(&tvc->lock);
2245 ObtainWriteLock(&afs_xcbhash, 466);
2246 if (origCBs == afs_allCBs) {
2247 if (CallBack.ExpirationTime) {
2248 tvc->callback = serverp;
2249 tvc->cbExpires = CallBack.ExpirationTime + now;
2250 tvc->f.states |= CStatd | CUnique;
2251 tvc->f.states &= ~CBulkFetching;
2252 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
2253 } else if (tvc->f.states & CRO) {
2254 /* adapt gives us an hour. */
2255 tvc->cbExpires = 3600 + osi_Time();
2256 /*XXX*/ tvc->f.states |= CStatd | CUnique;
2257 tvc->f.states &= ~CBulkFetching;
2258 afs_QueueCallback(tvc, CBHash(3600), tvp);
2260 tvc->callback = NULL;
2261 afs_DequeueCallback(tvc);
2262 tvc->f.states &= ~(CStatd | CUnique);
2263 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2264 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2267 afs_DequeueCallback(tvc);
2268 tvc->f.states &= ~CStatd;
2269 tvc->f.states &= ~CUnique;
2270 tvc->callback = NULL;
2271 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2272 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2274 ReleaseWriteLock(&afs_xcbhash);
2276 afs_PutVolume(tvp, READ_LOCK);
2277 afs_ProcessFS(tvc, &OutStatus, areq);
2279 ReleaseWriteLock(&tvc->lock);
2285 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2286 afs_int32 * cached, struct volume *tvolp)
2288 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2289 afs_int32 getNewFid = 0;
2291 struct VenusFid nfid;
2292 register struct vcache *tvc;
2293 struct server *serverp = 0;
2294 struct AFSFetchStatus OutStatus;
2295 struct AFSCallBack CallBack;
2296 struct AFSVolSync tsync;
2298 #ifdef AFS_DARWIN80_ENV
2305 if (!tvolp->rootVnode || getNewFid) {
2306 struct VenusFid tfid;
2309 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2310 origCBs = afs_allCBs; /* ignore InitCallBackState */
2312 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2317 /* ReleaseReadLock(&tvolp->lock); */
2318 ObtainWriteLock(&tvolp->lock, 56);
2319 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2320 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2321 ReleaseWriteLock(&tvolp->lock);
2322 /* ObtainReadLock(&tvolp->lock);*/
2325 afid->Fid.Vnode = tvolp->rootVnode;
2326 afid->Fid.Unique = tvolp->rootUnique;
2330 ObtainSharedLock(&afs_xvcache, 7);
2332 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2333 if (!FidCmp(&(tvc->f.fid), afid)) {
2334 if (tvc->f.states & CVInit) {
2335 ReleaseSharedLock(&afs_xvcache);
2336 afs_osi_Sleep(&tvc->f.states);
2339 #ifdef AFS_DARWIN80_ENV
2340 if (tvc->f.states & CDeadVnode) {
2341 if (!(tvc->f.states & CBulkFetching)) {
2342 ReleaseSharedLock(&afs_xvcache);
2343 afs_osi_Sleep(&tvc->f.states);
2348 if (vnode_get(tvp)) /* this bumps ref count */
2350 if (vnode_ref(tvp)) {
2352 /* AFSTOV(tvc) may be NULL */
2357 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
2359 vnode_recycle(AFSTOV(tvc));
2367 if (!haveStatus && (!tvc || !(tvc->f.states & CStatd))) {
2368 /* Mount point no longer stat'd or unknown. FID may have changed. */
2370 ReleaseSharedLock(&afs_xvcache);
2371 #ifdef AFS_DARWIN80_ENV
2374 vnode_put(AFSTOV(tvc));
2375 vnode_rele(AFSTOV(tvc));
2384 UpgradeSToWLock(&afs_xvcache, 23);
2385 /* no cache entry, better grab one */
2386 tvc = afs_NewVCache(afid, NULL);
2389 ReleaseWriteLock(&afs_xvcache);
2393 afs_stats_cmperf.vcacheMisses++;
2397 afs_stats_cmperf.vcacheHits++;
2398 #if defined(AFS_DARWIN80_ENV)
2399 /* we already bumped the ref count in the for loop above */
2400 #else /* AFS_DARWIN80_ENV */
2403 UpgradeSToWLock(&afs_xvcache, 24);
2404 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2405 refpanic("GRVC VLRU inconsistent0");
2407 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2408 refpanic("GRVC VLRU inconsistent1");
2410 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2411 refpanic("GRVC VLRU inconsistent2");
2413 QRemove(&tvc->vlruq); /* move to lruq head */
2414 QAdd(&VLRU, &tvc->vlruq);
2415 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2416 refpanic("GRVC VLRU inconsistent3");
2418 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2419 refpanic("GRVC VLRU inconsistent4");
2421 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2422 refpanic("GRVC VLRU inconsistent5");
2427 ReleaseWriteLock(&afs_xvcache);
2429 if (tvc->f.states & CStatd) {
2433 ObtainReadLock(&tvc->lock);
2434 tvc->f.states &= ~CUnique;
2435 tvc->callback = NULL; /* redundant, perhaps */
2436 ReleaseReadLock(&tvc->lock);
2439 ObtainWriteLock(&tvc->lock, 57);
2441 /* It is always appropriate to throw away all the access rights? */
2442 afs_FreeAllAxs(&(tvc->Access));
2445 tvc->f.states |= CForeign;
2446 if (tvolp->states & VRO)
2447 tvc->f.states |= CRO;
2448 if (tvolp->states & VBackup)
2449 tvc->f.states |= CBackup;
2450 /* now copy ".." entry back out of volume structure, if necessary */
2451 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2452 && (tvolp->rootUnique == afid->Fid.Unique)) {
2455 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2457 tvc->mvid = (struct VenusFid *)
2458 osi_AllocSmallSpace(sizeof(struct VenusFid));
2459 *tvc->mvid = tvolp->dotdot;
2463 afs_RemoveVCB(afid);
2466 struct VenusFid tfid;
2469 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2470 origCBs = afs_allCBs; /* ignore InitCallBackState */
2472 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2477 ObtainWriteLock(&afs_xcbhash, 467);
2478 afs_DequeueCallback(tvc);
2479 tvc->callback = NULL;
2480 tvc->f.states &= ~(CStatd | CUnique);
2481 ReleaseWriteLock(&afs_xcbhash);
2482 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2483 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2484 ReleaseWriteLock(&tvc->lock);
2489 ObtainWriteLock(&afs_xcbhash, 468);
2490 if (origCBs == afs_allCBs) {
2491 tvc->f.states |= CTruth;
2492 tvc->callback = serverp;
2493 if (CallBack.ExpirationTime != 0) {
2494 tvc->cbExpires = CallBack.ExpirationTime + start;
2495 tvc->f.states |= CStatd;
2496 tvc->f.states &= ~CBulkFetching;
2497 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2498 } else if (tvc->f.states & CRO) {
2499 /* adapt gives us an hour. */
2500 tvc->cbExpires = 3600 + osi_Time();
2501 /*XXX*/ tvc->f.states |= CStatd;
2502 tvc->f.states &= ~CBulkFetching;
2503 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2506 afs_DequeueCallback(tvc);
2507 tvc->callback = NULL;
2508 tvc->f.states &= ~(CStatd | CUnique);
2509 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2510 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2512 ReleaseWriteLock(&afs_xcbhash);
2513 afs_ProcessFS(tvc, &OutStatus, areq);
2515 ReleaseWriteLock(&tvc->lock);
2521 * Update callback status and (sometimes) attributes of a vnode.
2522 * Called after doing a fetch status RPC. Whilst disconnected, attributes
2523 * shouldn't be written to the vcache here.
2528 * \param Outsp Server status after rpc call.
2529 * \param acb Callback for this vnode.
2531 * \note The vcache must be write locked.
2534 afs_UpdateStatus(struct vcache *avc,
2535 struct VenusFid *afid,
2536 struct vrequest *areq,
2537 struct AFSFetchStatus *Outsp,
2538 struct AFSCallBack *acb,
2541 struct volume *volp;
2544 /* Dont write status in vcache if resyncing after a disconnection. */
2545 afs_ProcessFS(avc, Outsp, areq);
2547 volp = afs_GetVolume(afid, areq, READ_LOCK);
2548 ObtainWriteLock(&afs_xcbhash, 469);
2549 avc->f.states |= CTruth;
2550 if (avc->callback /* check for race */ ) {
2551 if (acb->ExpirationTime != 0) {
2552 avc->cbExpires = acb->ExpirationTime + start;
2553 avc->f.states |= CStatd;
2554 avc->f.states &= ~CBulkFetching;
2555 afs_QueueCallback(avc, CBHash(acb->ExpirationTime), volp);
2556 } else if (avc->f.states & CRO) {
2557 /* ordinary callback on a read-only volume -- AFS 3.2 style */
2558 avc->cbExpires = 3600 + start;
2559 avc->f.states |= CStatd;
2560 avc->f.states &= ~CBulkFetching;
2561 afs_QueueCallback(avc, CBHash(3600), volp);
2563 afs_DequeueCallback(avc);
2564 avc->callback = NULL;
2565 avc->f.states &= ~(CStatd | CUnique);
2566 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2567 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2570 afs_DequeueCallback(avc);
2571 avc->callback = NULL;
2572 avc->f.states &= ~(CStatd | CUnique);
2573 if ((avc->f.states & CForeign) || (avc->f.fid.Fid.Vnode & 1))
2574 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2576 ReleaseWriteLock(&afs_xcbhash);
2578 afs_PutVolume(volp, READ_LOCK);
2582 * Must be called with avc write-locked
2583 * don't absolutely have to invalidate the hint unless the dv has
2584 * changed, but be sure to get it right else there will be consistency bugs.
2587 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2588 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2591 afs_uint32 start = 0;
2592 register struct afs_conn *tc;
2593 struct AFSCallBack CallBack;
2594 struct AFSVolSync tsync;
2597 tc = afs_Conn(afid, areq, SHARED_LOCK);
2598 avc->dchint = NULL; /* invalidate hints */
2600 avc->callback = tc->srvr->server;
2602 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2605 RXAFS_FetchStatus(tc->id, (struct AFSFid *)&afid->Fid, Outsp,
2613 } while (afs_Analyze
2614 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2615 SHARED_LOCK, NULL));
2618 afs_UpdateStatus(avc, afid, areq, Outsp, &CallBack, start);
2620 /* used to undo the local callback, but that's too extreme.
2621 * There are plenty of good reasons that fetchstatus might return
2622 * an error, such as EPERM. If we have the vnode cached, statd,
2623 * with callback, might as well keep track of the fact that we
2624 * don't have access...
2626 if (code == EPERM || code == EACCES) {
2627 struct axscache *ac;
2628 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2630 else /* not found, add a new one if possible */
2631 afs_AddAxs(avc->Access, areq->uid, 0);
2642 * Stuff some information into the vcache for the given file.
2645 * afid : File in question.
2646 * OutStatus : Fetch status on the file.
2647 * CallBack : Callback info.
2648 * tc : RPC connection involved.
2649 * areq : vrequest involved.
2652 * Nothing interesting.
2655 afs_StuffVcache(register struct VenusFid *afid,
2656 struct AFSFetchStatus *OutStatus,
2657 struct AFSCallBack *CallBack, register struct afs_conn *tc,
2658 struct vrequest *areq)
2660 register afs_int32 code, i, newvcache = 0;
2661 register struct vcache *tvc;
2662 struct AFSVolSync tsync;
2664 struct axscache *ac;
2667 AFS_STATCNT(afs_StuffVcache);
2668 #ifdef IFS_VCACHECOUNT
2673 ObtainSharedLock(&afs_xvcache, 8);
2675 tvc = afs_FindVCache(afid, &retry, DO_VLRU| IS_SLOCK /* no stats */ );
2677 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2678 ReleaseSharedLock(&afs_xvcache);
2679 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2685 /* no cache entry, better grab one */
2686 UpgradeSToWLock(&afs_xvcache, 25);
2687 tvc = afs_NewVCache(afid, NULL);
2689 ConvertWToSLock(&afs_xvcache);
2692 ReleaseSharedLock(&afs_xvcache);
2697 ReleaseSharedLock(&afs_xvcache);
2698 ObtainWriteLock(&tvc->lock, 58);
2700 tvc->f.states &= ~CStatd;
2701 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2702 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2704 /* Is it always appropriate to throw away all the access rights? */
2705 afs_FreeAllAxs(&(tvc->Access));
2707 /*Copy useful per-volume info */
2708 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2710 if (newvcache && (tvp->states & VForeign))
2711 tvc->f.states |= CForeign;
2712 if (tvp->states & VRO)
2713 tvc->f.states |= CRO;
2714 if (tvp->states & VBackup)
2715 tvc->f.states |= CBackup;
2717 * Now, copy ".." entry back out of volume structure, if
2720 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2722 tvc->mvid = (struct VenusFid *)
2723 osi_AllocSmallSpace(sizeof(struct VenusFid));
2724 *tvc->mvid = tvp->dotdot;
2727 /* store the stat on the file */
2728 afs_RemoveVCB(afid);
2729 afs_ProcessFS(tvc, OutStatus, areq);
2730 tvc->callback = tc->srvr->server;
2732 /* we use osi_Time twice below. Ideally, we would use the time at which
2733 * the FetchStatus call began, instead, but we don't have it here. So we
2734 * make do with "now". In the CRO case, it doesn't really matter. In
2735 * the other case, we hope that the difference between "now" and when the
2736 * call actually began execution on the server won't be larger than the
2737 * padding which the server keeps. Subtract 1 second anyway, to be on
2738 * the safe side. Can't subtract more because we don't know how big
2739 * ExpirationTime is. Possible consistency problems may arise if the call
2740 * timeout period becomes longer than the server's expiration padding. */
2741 ObtainWriteLock(&afs_xcbhash, 470);
2742 if (CallBack->ExpirationTime != 0) {
2743 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2744 tvc->f.states |= CStatd;
2745 tvc->f.states &= ~CBulkFetching;
2746 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2747 } else if (tvc->f.states & CRO) {
2748 /* old-fashioned AFS 3.2 style */
2749 tvc->cbExpires = 3600 + osi_Time();
2750 /*XXX*/ tvc->f.states |= CStatd;
2751 tvc->f.states &= ~CBulkFetching;
2752 afs_QueueCallback(tvc, CBHash(3600), tvp);
2754 afs_DequeueCallback(tvc);
2755 tvc->callback = NULL;
2756 tvc->f.states &= ~(CStatd | CUnique);
2757 if ((tvc->f.states & CForeign) || (tvc->f.fid.Fid.Vnode & 1))
2758 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2760 ReleaseWriteLock(&afs_xcbhash);
2762 afs_PutVolume(tvp, READ_LOCK);
2764 /* look in per-pag cache */
2765 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2766 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2767 else /* not found, add a new one if possible */
2768 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2770 ReleaseWriteLock(&tvc->lock);
2771 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2772 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2773 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2775 * Release ref count... hope this guy stays around...
2778 } /*afs_StuffVcache */
2782 * Decrements the reference count on a cache entry.
2784 * \param avc Pointer to the cache entry to decrement.
2786 * \note Environment: Nothing interesting.
2789 afs_PutVCache(register struct vcache *avc)
2791 AFS_STATCNT(afs_PutVCache);
2792 #ifdef AFS_DARWIN80_ENV
2793 vnode_put(AFSTOV(avc));
2797 * Can we use a read lock here?
2799 ObtainReadLock(&afs_xvcache);
2801 ReleaseReadLock(&afs_xvcache);
2803 } /*afs_PutVCache */
2807 * Reset a vcache entry, so local contents are ignored, and the
2808 * server will be reconsulted next time the vcache is used
2810 * \param avc Pointer to the cache entry to reset
2813 * \note avc must be write locked on entry
2816 afs_ResetVCache(struct vcache *avc, afs_ucred_t *acred) {
2817 ObtainWriteLock(&afs_xcbhash, 456);
2818 afs_DequeueCallback(avc);
2819 avc->f.states &= ~(CStatd | CDirty); /* next reference will re-stat */
2820 ReleaseWriteLock(&afs_xcbhash);
2821 /* now find the disk cache entries */
2822 afs_TryToSmush(avc, acred, 1);
2823 osi_dnlc_purgedp(avc);
2824 if (avc->linkData && !(avc->f.states & CCore)) {
2825 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
2826 avc->linkData = NULL;
2831 * Sleepa when searching for a vcache. Releases all the pending locks,
2832 * sleeps then obtains the previously released locks.
2834 * \param vcache Enter sleep state.
2835 * \param flag Determines what locks to use.
2839 static void findvc_sleep(struct vcache *avc, int flag) {
2840 if (flag & IS_SLOCK) {
2841 ReleaseSharedLock(&afs_xvcache);
2843 if (flag & IS_WLOCK) {
2844 ReleaseWriteLock(&afs_xvcache);
2846 ReleaseReadLock(&afs_xvcache);
2849 afs_osi_Sleep(&avc->f.states);
2850 if (flag & IS_SLOCK) {
2851 ObtainSharedLock(&afs_xvcache, 341);
2853 if (flag & IS_WLOCK) {
2854 ObtainWriteLock(&afs_xvcache, 343);
2856 ObtainReadLock(&afs_xvcache);
2861 * Find a vcache entry given a fid.
2863 * \param afid Pointer to the fid whose cache entry we desire.
2864 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2865 * unlock the vnode, and try again.
2866 * \param flag Bit 1 to specify whether to compute hit statistics. Not
2867 * set if FindVCache is called as part of internal bookkeeping.
2869 * \note Environment: Must be called with the afs_xvcache lock at least held at
2870 * the read level. In order to do the VLRU adjustment, the xvcache lock
2871 * must be shared-- we upgrade it here.
2875 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2878 register struct vcache *tvc;
2880 #ifdef AFS_DARWIN80_ENV
2884 AFS_STATCNT(afs_FindVCache);
2888 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2889 if (FidMatches(afid, tvc)) {
2890 if (tvc->f.states & CVInit) {
2891 findvc_sleep(tvc, flag);
2894 #ifdef AFS_DARWIN80_ENV
2895 if (tvc->f.states & CDeadVnode) {
2896 if (!(tvc->f.states & CBulkFetching)) {
2897 findvc_sleep(tvc, flag);
2904 if (vnode_ref(tvp)) {
2906 /* AFSTOV(tvc) may be NULL */
2911 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
2913 vnode_recycle(AFSTOV(tvc));
2921 /* should I have a read lock on the vnode here? */
2925 #if !defined(AFS_DARWIN80_ENV)
2926 osi_vnhold(tvc, retry); /* already held, above */
2927 if (retry && *retry)
2930 #if defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
2931 tvc->f.states |= CUBCinit;
2933 if (UBCINFOMISSING(AFSTOV(tvc)) ||
2934 UBCINFORECLAIMED(AFSTOV(tvc))) {
2935 ubc_info_init(AFSTOV(tvc));
2938 tvc->f.states &= ~CUBCinit;
2941 * only move to front of vlru if we have proper vcache locking)
2943 if (flag & DO_VLRU) {
2944 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2945 refpanic("FindVC VLRU inconsistent1");
2947 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2948 refpanic("FindVC VLRU inconsistent1");
2950 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2951 refpanic("FindVC VLRU inconsistent2");
2953 UpgradeSToWLock(&afs_xvcache, 26);
2954 QRemove(&tvc->vlruq);
2955 QAdd(&VLRU, &tvc->vlruq);
2956 ConvertWToSLock(&afs_xvcache);
2957 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2958 refpanic("FindVC VLRU inconsistent1");
2960 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2961 refpanic("FindVC VLRU inconsistent2");
2963 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2964 refpanic("FindVC VLRU inconsistent3");
2970 if (flag & DO_STATS) {
2972 afs_stats_cmperf.vcacheHits++;
2974 afs_stats_cmperf.vcacheMisses++;
2975 if (afs_IsPrimaryCellNum(afid->Cell))
2976 afs_stats_cmperf.vlocalAccesses++;
2978 afs_stats_cmperf.vremoteAccesses++;
2981 } /*afs_FindVCache */
2984 * Find a vcache entry given a fid. Does a wildcard match on what we
2985 * have for the fid. If more than one entry, don't return anything.
2987 * \param avcp Fill in pointer if we found one and only one.
2988 * \param afid Pointer to the fid whose cache entry we desire.
2989 * \param retry (SGI-specific) tell the caller to drop the lock on xvcache,
2990 * unlock the vnode, and try again.
2991 * \param flags bit 1 to specify whether to compute hit statistics. Not
2992 * set if FindVCache is called as part of internal bookkeeping.
2994 * \note Environment: Must be called with the afs_xvcache lock at least held at
2995 * the read level. In order to do the VLRU adjustment, the xvcache lock
2996 * must be shared-- we upgrade it here.
2998 * \return Number of matches found.
3001 int afs_duplicate_nfs_fids = 0;
3004 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
3006 register struct vcache *tvc;
3008 afs_int32 count = 0;
3009 struct vcache *found_tvc = NULL;
3010 #ifdef AFS_DARWIN80_ENV
3014 AFS_STATCNT(afs_FindVCache);
3018 ObtainSharedLock(&afs_xvcache, 331);
3021 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3022 /* Match only on what we have.... */
3023 if (((tvc->f.fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
3024 && (tvc->f.fid.Fid.Volume == afid->Fid.Volume)
3025 && ((tvc->f.fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
3026 && (tvc->f.fid.Cell == afid->Cell)) {
3027 if (tvc->f.states & CVInit) {
3028 ReleaseSharedLock(&afs_xvcache);
3029 afs_osi_Sleep(&tvc->f.states);
3032 #ifdef AFS_DARWIN80_ENV
3033 if (tvc->f.states & CDeadVnode) {
3034 if (!(tvc->f.states & CBulkFetching)) {
3035 ReleaseSharedLock(&afs_xvcache);
3036 afs_osi_Sleep(&tvc->f.states);
3041 if (vnode_get(tvp)) {
3042 /* This vnode no longer exists. */
3045 if (vnode_ref(tvp)) {
3046 /* This vnode no longer exists. */
3048 /* AFSTOV(tvc) may be NULL */
3053 if (tvc->f.states & (CBulkFetching|CDeadVnode)) {
3055 vnode_recycle(AFSTOV(tvc));
3058 #endif /* AFS_DARWIN80_ENV */
3062 afs_duplicate_nfs_fids++;
3063 ReleaseSharedLock(&afs_xvcache);
3064 #ifdef AFS_DARWIN80_ENV
3065 /* Drop our reference counts. */
3066 vnode_put(AFSTOV(tvc));
3067 vnode_put(AFSTOV(found_tvc));
3076 /* should I have a read lock on the vnode here? */
3078 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
3079 afs_int32 retry = 0;
3080 osi_vnhold(tvc, &retry);
3083 found_tvc = (struct vcache *)0;
3084 ReleaseSharedLock(&afs_xvcache);
3085 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
3089 osi_vnhold(tvc, (int *)0); /* already held, above */
3092 * We obtained the xvcache lock above.
3094 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
3095 refpanic("FindVC VLRU inconsistent1");
3097 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
3098 refpanic("FindVC VLRU inconsistent1");
3100 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
3101 refpanic("FindVC VLRU inconsistent2");
3103 UpgradeSToWLock(&afs_xvcache, 568);
3104 QRemove(&tvc->vlruq);
3105 QAdd(&VLRU, &tvc->vlruq);
3106 ConvertWToSLock(&afs_xvcache);
3107 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
3108 refpanic("FindVC VLRU inconsistent1");
3110 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
3111 refpanic("FindVC VLRU inconsistent2");
3113 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
3114 refpanic("FindVC VLRU inconsistent3");
3120 afs_stats_cmperf.vcacheHits++;
3122 afs_stats_cmperf.vcacheMisses++;
3123 if (afs_IsPrimaryCellNum(afid->Cell))
3124 afs_stats_cmperf.vlocalAccesses++;
3126 afs_stats_cmperf.vremoteAccesses++;
3128 *avcp = tvc; /* May be null */
3130 ReleaseSharedLock(&afs_xvcache);
3131 return (tvc ? 1 : 0);
3133 } /*afs_NFSFindVCache */
3139 * Initialize vcache related variables
3144 afs_vcacheInit(int astatSize)
3146 #if !defined(AFS_LINUX22_ENV)
3147 register struct vcache *tvp;
3150 #if defined(AFS_LINUX22_ENV)
3151 if (!afs_maxvcount) {
3152 afs_maxvcount = astatSize; /* no particular limit on linux? */
3153 if (astatSize < afs_maxvcount) {
3154 afs_maxvcount = astatSize;
3157 #else /* AFS_LINUX22_ENV */
3161 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3162 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3164 #if !defined(AFS_LINUX22_ENV)
3165 /* Allocate and thread the struct vcache entries */
3166 tvp = (struct vcache *)afs_osi_Alloc(astatSize * sizeof(struct vcache));
3167 memset(tvp, 0, sizeof(struct vcache) * astatSize);
3169 Initial_freeVCList = tvp;
3170 freeVCList = &(tvp[0]);
3171 for (i = 0; i < astatSize - 1; i++) {
3172 tvp[i].nextfree = &(tvp[i + 1]);
3174 tvp[astatSize - 1].nextfree = NULL;
3175 # ifdef KERNEL_HAVE_PIN
3176 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
3180 #if defined(AFS_SGI_ENV)
3181 for (i = 0; i < astatSize; i++) {
3182 char name[METER_NAMSZ];
3183 struct vcache *tvc = &tvp[i];
3185 tvc->v.v_number = ++afsvnumbers;
3186 tvc->vc_rwlockid = OSI_NO_LOCKID;
3187 initnsema(&tvc->vc_rwlock, 1,
3188 makesname(name, "vrw", tvc->v.v_number));
3189 #ifndef AFS_SGI53_ENV
3190 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
3192 #ifndef AFS_SGI62_ENV
3193 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
3194 #endif /* AFS_SGI62_ENV */
3198 for(i = 0; i < VCSIZE; ++i)
3199 QInit(&afs_vhashTV[i]);
3206 shutdown_vcache(void)
3209 struct afs_cbr *tsp;
3211 * XXX We may potentially miss some of the vcaches because if when
3212 * there are no free vcache entries and all the vcache entries are active
3213 * ones then we allocate an additional one - admittedly we almost never
3218 register struct afs_q *tq, *uq = NULL;
3219 register struct vcache *tvc;
3220 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
3224 osi_FreeSmallSpace(tvc->mvid);
3225 tvc->mvid = (struct VenusFid *)0;
3228 aix_gnode_rele(AFSTOV(tvc));
3230 if (tvc->linkData) {
3231 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3236 * Also free the remaining ones in the Cache
3238 for (i = 0; i < VCSIZE; i++) {
3239 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3241 osi_FreeSmallSpace(tvc->mvid);
3242 tvc->mvid = (struct VenusFid *)0;
3246 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
3247 #ifdef AFS_AIX32_ENV
3250 vms_delete(tvc->segid);
3252 tvc->segid = tvc->vmh = NULL;
3253 if (VREFCOUNT_GT(tvc,0))
3254 osi_Panic("flushVcache: vm race");
3262 #if defined(AFS_SUN5_ENV)
3268 if (tvc->linkData) {
3269 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3274 afs_FreeAllAxs(&(tvc->Access));
3280 * Free any leftover callback queue
3282 for (i = 0; i < afs_stats_cmperf.CallBackAlloced; i++) {
3283 tsp = afs_cbrHeads[i];
3284 afs_cbrHeads[i] = 0;
3285 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
3289 #if !defined(AFS_LINUX22_ENV)
3290 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3292 # ifdef KERNEL_HAVE_PIN
3293 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3296 freeVCList = Initial_freeVCList = 0;
3299 AFS_RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3300 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3302 for(i = 0; i < VCSIZE; ++i)
3303 QInit(&afs_vhashTV[i]);
3307 afs_DisconGiveUpCallbacks(void) {
3312 ObtainWriteLock(&afs_xvcache, 1002); /* XXX - should be a unique number */
3314 /* Somehow, walk the set of vcaches, with each one coming out as tvc */
3315 for (i = 0; i < VCSIZE; i++) {
3316 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3317 if (afs_QueueVCB(tvc)) {
3318 tvc->callback = NULL;
3324 ReleaseWriteLock(&afs_xvcache);
3331 * Clear the Statd flag from all vcaches
3333 * This function removes the Statd flag from all vcaches. It's used by
3334 * disconnected mode to tidy up during reconnection
3338 afs_ClearAllStatdFlag(void) {
3342 ObtainWriteLock(&afs_xvcache, 715);
3344 for (i = 0; i < VCSIZE; i++) {
3345 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3346 tvc->f.states &= ~(CStatd|CUnique);
3349 ReleaseWriteLock(&afs_xvcache);