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"
46 #include "afs/sysincludes.h" /*Standard vendor system headers */
47 #include "afsincludes.h" /*AFS-based standard headers */
48 #include "afs/afs_stats.h"
49 #include "afs/afs_cbqueue.h"
50 #include "afs/afs_osidnlc.h"
52 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
53 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
54 afs_int32 afs_vcount = 0; /* number of vcache in use now */
55 #endif /* AFS_OSF_ENV */
63 #endif /* AFS_SGI64_ENV */
65 /* Exported variables */
66 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries */
67 afs_rwlock_t afs_xvreclaim; /*Lock: entries reclaimed, not on free list */
68 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks */
69 #if !defined(AFS_LINUX22_ENV)
70 static struct vcache *freeVCList; /*Free list for stat cache entries */
71 struct vcache *ReclaimedVCList; /*Reclaimed list for stat entries */
72 static struct vcache *Initial_freeVCList; /*Initial list for above */
74 struct afs_q VLRU; /*vcache LRU */
75 afs_int32 vcachegen = 0;
76 unsigned int afs_paniconwarn = 0;
77 struct vcache *afs_vhashT[VCSIZE];
78 struct afs_q afs_vhashTV[VCSIZE];
79 static struct afs_cbr *afs_cbrHashT[CBRSIZE];
80 afs_int32 afs_bulkStatsLost;
81 int afs_norefpanic = 0;
83 /* Forward declarations */
84 static afs_int32 afs_QueueVCB(struct vcache *avc);
89 * Generate an index into the hash table for a given Fid.
92 afs_HashCBRFid(struct AFSFid *fid)
94 return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE;
100 * Insert a CBR entry into the hash table.
101 * Must be called with afs_xvcb held.
104 afs_InsertHashCBR(struct afs_cbr *cbr)
106 int slot = afs_HashCBRFid(&cbr->fid);
108 cbr->hash_next = afs_cbrHashT[slot];
109 if (afs_cbrHashT[slot])
110 afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next;
112 cbr->hash_pprev = &afs_cbrHashT[slot];
113 afs_cbrHashT[slot] = cbr;
120 * Flush the given vcache entry.
123 * avc : Pointer to vcache entry to flush.
124 * slept : Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
127 * afs_xvcache lock must be held for writing upon entry to
128 * prevent people from changing the vrefCount field, and to
129 * protect the lruq and hnext fields.
130 * LOCK: afs_FlushVCache afs_xvcache W
131 * REFCNT: vcache ref count must be zero on entry except for osf1
132 * RACE: lock is dropped and reobtained, permitting race in caller
136 afs_FlushVCache(struct vcache *avc, int *slept)
137 { /*afs_FlushVCache */
140 struct vcache **uvc, *wvc;
143 AFS_STATCNT(afs_FlushVCache);
144 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
145 ICL_TYPE_INT32, avc->states);
148 VN_LOCK(AFSTOV(avc));
152 code = osi_VM_FlushVCache(avc, slept);
156 if (avc->states & CVFlushed) {
160 #if !defined(AFS_LINUX22_ENV)
161 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
162 refpanic("LRU vs. Free inconsistency");
165 avc->states |= CVFlushed;
166 /* pull the entry out of the lruq and put it on the free list */
167 QRemove(&avc->vlruq);
169 /* keep track of # of files that we bulk stat'd, but never used
170 * before they got recycled.
172 if (avc->states & CBulkStat)
175 /* remove entry from the hash chain */
176 i = VCHash(&avc->fid);
177 uvc = &afs_vhashT[i];
178 for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
181 avc->hnext = (struct vcache *)NULL;
186 /* remove entry from the volume hash table */
187 QRemove(&avc->vhashq);
190 osi_FreeSmallSpace(avc->mvid);
191 avc->mvid = (struct VenusFid *)0;
193 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
194 avc->linkData = NULL;
196 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
197 /* OK, there are no internal vrefCounts, so there shouldn't
198 * be any more refs here. */
200 #ifdef AFS_DARWIN80_ENV
201 vnode_clearfsnode(AFSTOV(avc));
202 vnode_removefsref(AFSTOV(avc));
204 avc->v->v_data = NULL; /* remove from vnode */
206 AFSTOV(avc) = NULL; /* also drop the ptr to vnode */
209 #ifdef AFS_SUN510_ENV
210 /* As we use private vnodes, cleanup is up to us */
211 vn_reinit(AFSTOV(avc));
213 afs_FreeAllAxs(&(avc->Access));
215 /* we can't really give back callbacks on RO files, since the
216 * server only tracks them on a per-volume basis, and we don't
217 * know whether we still have some other files from the same
219 if ((avc->states & CRO) == 0 && avc->callback) {
222 ObtainWriteLock(&afs_xcbhash, 460);
223 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
224 avc->states &= ~(CStatd | CUnique);
225 ReleaseWriteLock(&afs_xcbhash);
226 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
227 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
229 osi_dnlc_purgevp(avc);
232 * Next, keep track of which vnodes we've deleted for create's
233 * optimistic synchronization algorithm
236 if (avc->fid.Fid.Vnode & 1)
241 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
242 /* put the entry in the free list */
243 avc->nextfree = freeVCList;
245 if (avc->vlruq.prev || avc->vlruq.next) {
246 refpanic("LRU vs. Free inconsistency");
248 avc->states |= CVFlushed;
250 /* This should put it back on the vnode free list since usecount is 1 */
253 if (VREFCOUNT_GT(avc,0)) {
254 #if defined(AFS_OSF_ENV)
255 VN_UNLOCK(AFSTOV(avc));
257 AFS_RELE(AFSTOV(avc));
259 if (afs_norefpanic) {
260 printf("flush vc refcnt < 1");
262 #if defined(AFS_OSF_ENV)
263 (void)vgone(avc, VX_NOSLEEP, NULL);
265 VN_UNLOCK(AFSTOV(avc));
268 osi_Panic("flush vc refcnt < 1");
270 #endif /* AFS_OSF_ENV */
275 VN_UNLOCK(AFSTOV(avc));
279 } /*afs_FlushVCache */
285 * The core of the inactive vnode op for all but IRIX.
288 afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred)
290 AFS_STATCNT(afs_inactive);
291 if (avc->states & CDirty) {
292 /* we can't keep trying to push back dirty data forever. Give up. */
293 afs_InvalidateAllSegments(avc); /* turns off dirty bit */
295 avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
296 avc->states &= ~CDirty; /* Turn it off */
297 if (avc->states & CUnlinked) {
298 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
299 avc->states |= CUnlinkedDel;
302 afs_remunlink(avc, 1); /* ignore any return code */
311 * Description: allocate a callback return structure from the
312 * free list and return it.
314 * Env: The alloc and free routines are both called with the afs_xvcb lock
315 * held, so we don't have to worry about blocking in osi_Alloc.
317 static struct afs_cbr *afs_cbrSpace = 0;
321 register struct afs_cbr *tsp;
324 while (!afs_cbrSpace) {
325 if (afs_stats_cmperf.CallBackAlloced >= 2) {
326 /* don't allocate more than 2 * AFS_NCBRS for now */
328 afs_stats_cmperf.CallBackFlushes++;
332 (struct afs_cbr *)afs_osi_Alloc(AFS_NCBRS *
333 sizeof(struct afs_cbr));
334 for (i = 0; i < AFS_NCBRS - 1; i++) {
335 tsp[i].next = &tsp[i + 1];
337 tsp[AFS_NCBRS - 1].next = 0;
339 afs_stats_cmperf.CallBackAlloced++;
343 afs_cbrSpace = tsp->next;
350 * Description: free a callback return structure, removing it from all lists.
353 * asp -- the address of the structure to free.
355 * Environment: the xvcb lock is held over these calls.
358 afs_FreeCBR(register struct afs_cbr *asp)
360 *(asp->pprev) = asp->next;
362 asp->next->pprev = asp->pprev;
364 *(asp->hash_pprev) = asp->hash_next;
366 asp->hash_next->hash_pprev = asp->hash_pprev;
368 asp->next = afs_cbrSpace;
376 * Description: flush all queued callbacks to all servers.
380 * Environment: holds xvcb lock over RPC to guard against race conditions
381 * when a new callback is granted for the same file later on.
384 afs_FlushVCBs(afs_int32 lockit)
386 struct AFSFid *tfids;
387 struct AFSCallBack callBacks[1];
388 struct AFSCBFids fidArray;
389 struct AFSCBs cbArray;
391 struct afs_cbr *tcbrp;
395 struct vrequest treq;
397 int safety1, safety2, safety3;
399 if ((code = afs_InitReq(&treq, afs_osi_credp)))
401 treq.flags |= O_NONBLOCK;
402 tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
405 MObtainWriteLock(&afs_xvcb, 273);
406 ObtainReadLock(&afs_xserver);
407 for (i = 0; i < NSERVERS; i++) {
408 for (safety1 = 0, tsp = afs_servers[i];
409 tsp && safety1 < afs_totalServers + 10;
410 tsp = tsp->next, safety1++) {
412 if (tsp->cbrs == (struct afs_cbr *)0)
415 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
416 * and make an RPC, over and over again.
418 tcount = 0; /* number found so far */
419 for (safety2 = 0; safety2 < afs_cacheStats; safety2++) {
420 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
421 /* if buffer is full, or we've queued all we're going
422 * to from this server, we should flush out the
425 fidArray.AFSCBFids_len = tcount;
426 fidArray.AFSCBFids_val = (struct AFSFid *)tfids;
427 cbArray.AFSCBs_len = 1;
428 cbArray.AFSCBs_val = callBacks;
429 memset(&callBacks[0], 0, sizeof(callBacks[0]));
430 callBacks[0].CallBackType = CB_EXCLUSIVE;
431 for (safety3 = 0; safety3 < MAXHOSTS * 2; safety3++) {
432 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
433 tsp->cell->cellNum, &treq, 0,
437 (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
440 RXAFS_GiveUpCallBacks(tc->id, &fidArray,
448 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK,
453 /* ignore return code, since callbacks may have
454 * been returned anyway, we shouldn't leave them
455 * around to be returned again.
457 * Next, see if we are done with this server, and if so,
458 * break to deal with the next one.
464 /* if to flush full buffer */
465 /* if we make it here, we have an entry at the head of cbrs,
466 * which we should copy to the file ID array and then free.
469 tfids[tcount++] = tcbrp->fid;
471 /* Freeing the CBR will unlink it from the server's CBR list */
473 } /* while loop for this one server */
474 if (safety2 > afs_cacheStats) {
475 afs_warn("possible internal error afs_flushVCBs (%d)\n",
478 } /* for loop for this hash chain */
479 } /* loop through all hash chains */
480 if (safety1 > afs_totalServers + 2) {
482 ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n",
483 safety1, afs_totalServers + 2);
485 osi_Panic("afs_flushVCBS safety1");
488 ReleaseReadLock(&afs_xserver);
490 MReleaseWriteLock(&afs_xvcb);
491 afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
499 * Queue a callback on the given fid.
505 * Locks the xvcb lock.
506 * Called when the xvcache lock is already held.
510 afs_QueueVCB(struct vcache *avc)
513 struct afs_cbr *tcbp;
515 AFS_STATCNT(afs_QueueVCB);
516 /* The callback is really just a struct server ptr. */
517 tsp = (struct server *)(avc->callback);
519 /* we now have a pointer to the server, so we just allocate
520 * a queue entry and queue it.
522 MObtainWriteLock(&afs_xvcb, 274);
523 tcbp = afs_AllocCBR();
524 tcbp->fid = avc->fid.Fid;
526 tcbp->next = tsp->cbrs;
528 tsp->cbrs->pprev = &tcbp->next;
531 tcbp->pprev = &tsp->cbrs;
533 afs_InsertHashCBR(tcbp);
535 /* now release locks and return */
536 MReleaseWriteLock(&afs_xvcb);
545 * Remove a queued callback for a given Fid.
548 * afid: The fid we want cleansed of queued callbacks.
551 * Locks xvcb and xserver locks.
552 * Typically called with xdcache, xvcache and/or individual vcache
557 afs_RemoveVCB(struct VenusFid *afid)
560 struct afs_cbr *cbr, *ncbr;
562 AFS_STATCNT(afs_RemoveVCB);
563 MObtainWriteLock(&afs_xvcb, 275);
565 slot = afs_HashCBRFid(&afid->Fid);
566 ncbr = afs_cbrHashT[slot];
570 ncbr = cbr->hash_next;
572 if (afid->Fid.Volume == cbr->fid.Volume &&
573 afid->Fid.Vnode == cbr->fid.Vnode &&
574 afid->Fid.Unique == cbr->fid.Unique) {
579 MReleaseWriteLock(&afs_xvcb);
583 afs_FlushReclaimedVcaches(void)
585 #if !defined(AFS_LINUX22_ENV)
588 struct vcache *tmpReclaimedVCList = NULL;
590 ObtainWriteLock(&afs_xvreclaim, 76);
591 while (ReclaimedVCList) {
592 tvc = ReclaimedVCList; /* take from free list */
593 ReclaimedVCList = tvc->nextfree;
594 tvc->nextfree = NULL;
595 code = afs_FlushVCache(tvc, &fv_slept);
597 /* Ok, so, if we got code != 0, uh, wtf do we do? */
598 /* Probably, build a temporary list and then put all back when we
599 get to the end of the list */
600 /* This is actually really crappy, but we need to not leak these.
601 We probably need a way to be smarter about this. */
602 tvc->nextfree = tmpReclaimedVCList;
603 tmpReclaimedVCList = tvc;
604 printf("Reclaim list flush %lx failed: %d\n", (unsigned long) tvc, code);
606 if (tvc->states & (CVInit
607 #ifdef AFS_DARWIN80_ENV
611 tvc->states &= ~(CVInit
612 #ifdef AFS_DARWIN80_ENV
616 afs_osi_Wakeup(&tvc->states);
619 if (tmpReclaimedVCList)
620 ReclaimedVCList = tmpReclaimedVCList;
622 ReleaseWriteLock(&afs_xvreclaim);
630 * This routine is responsible for allocating a new cache entry
631 * from the free list. It formats the cache entry and inserts it
632 * into the appropriate hash tables. It must be called with
633 * afs_xvcache write-locked so as to prevent several processes from
634 * trying to create a new cache entry simultaneously.
637 * afid : The file id of the file whose cache entry is being
640 /* LOCK: afs_NewVCache afs_xvcache W */
642 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
646 afs_int32 anumber = VCACHE_FREE;
648 struct gnode *gnodepnt;
652 #endif /* AFS_OSF_ENV */
653 struct afs_q *tq, *uq;
656 AFS_STATCNT(afs_NewVCache);
658 afs_FlushReclaimedVcaches();
660 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
661 #if defined(AFS_OSF30_ENV) || defined(AFS_LINUX22_ENV)
662 if (afs_vcount >= afs_maxvcount)
665 * If we are using > 33 % of the total system vnodes for AFS vcache
666 * entries or we are using the maximum number of vcache entries,
667 * then free some. (if our usage is > 33% we should free some, if
668 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
669 * we _must_ free some -- no choice).
671 if (((3 * afs_vcount) > nvnode) || (afs_vcount >= afs_maxvcount))
678 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
681 if (tvc->states & CVFlushed) {
682 refpanic("CVFlushed on VLRU");
683 } else if (i++ > afs_maxvcount) {
684 refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)");
685 } else if (QNext(uq) != tq) {
686 refpanic("VLRU inconsistent");
687 } else if (!VREFCOUNT_GT(tvc,0)) {
688 refpanic("refcnt 0 on VLRU");
691 #if defined(AFS_LINUX22_ENV)
692 if (tvc != afs_globalVp && VREFCOUNT(tvc) > 1 && tvc->opens == 0) {
693 struct dentry *dentry;
694 struct list_head *cur, *head;
696 #if defined(AFS_LINUX24_ENV)
697 spin_lock(&dcache_lock);
699 head = &(AFSTOV(tvc))->i_dentry;
703 while ((cur = cur->next) != head) {
704 dentry = list_entry(cur, struct dentry, d_alias);
706 if (d_unhashed(dentry))
711 #if defined(AFS_LINUX24_ENV)
712 spin_unlock(&dcache_lock);
714 if (d_invalidate(dentry) == -EBUSY) {
716 /* perhaps lock and try to continue? (use cur as head?) */
720 #if defined(AFS_LINUX24_ENV)
721 spin_lock(&dcache_lock);
725 #if defined(AFS_LINUX24_ENV)
726 spin_unlock(&dcache_lock);
733 if (VREFCOUNT_GT(tvc,0) && !VREFCOUNT_GT(tvc,1) &&
735 && (tvc->states & CUnlinkedDel) == 0) {
736 code = afs_FlushVCache(tvc, &fv_slept);
743 continue; /* start over - may have raced. */
749 if (anumber == VCACHE_FREE) {
750 printf("afs_NewVCache: warning none freed, using %d of %d\n",
751 afs_vcount, afs_maxvcount);
752 if (afs_vcount >= afs_maxvcount) {
753 printf("afs_NewVCache - none freed\n");
759 #if defined(AFS_LINUX22_ENV)
764 ip = new_inode(afs_globalVFS);
766 osi_Panic("afs_NewVCache: no more inodes");
768 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
771 tvc = afs_osi_Alloc(sizeof(struct vcache));
772 ip->u.generic_ip = tvc;
778 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
779 /* What should we do ???? */
780 osi_Panic("afs_NewVCache: no more vnodes");
785 tvc->nextfree = NULL;
788 #else /* AFS_OSF_ENV */
789 /* pull out a free cache entry */
793 for (tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
797 if (tvc->states & CVFlushed) {
798 refpanic("CVFlushed on VLRU");
799 } else if (i++ > 2 * afs_cacheStats) { /* even allowing for a few xallocs... */
800 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
801 } else if (QNext(uq) != tq) {
802 refpanic("VLRU inconsistent");
803 } else if (tvc->states & CVInit) {
807 if (!VREFCOUNT_GT(tvc,0)
808 #if defined(AFS_DARWIN_ENV) && !defined(UKERNEL) && !defined(AFS_DARWIN80_ENV)
809 || ((VREFCOUNT(tvc) == 1) &&
810 (UBCINFOEXISTS(AFSTOV(tvc))))
812 && tvc->opens == 0 && (tvc->states & CUnlinkedDel) == 0) {
813 #if defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
814 #ifdef AFS_DARWIN80_ENV
815 vnode_t tvp = AFSTOV(tvc);
816 /* VREFCOUNT_GT only sees usecounts, not iocounts */
817 /* so this may fail to actually recycle the vnode now */
818 /* must call vnode_get to avoid races. */
820 if (vnode_get(tvp) == 0) {
822 /* must release lock, since vnode_put will immediately
823 reclaim if there are no other users */
824 ReleaseWriteLock(&afs_xvcache);
829 ObtainWriteLock(&afs_xvcache, 336);
831 /* we can't use the vnode_recycle return value to figure
832 * this out, since the iocount we have to hold makes it
834 if (AFSTOV(tvc) == tvp) {
835 if (anumber > 0 && fv_slept) {
836 QRemove(&tvc->vlruq);
837 QAdd(&VLRU, &tvc->vlruq);
844 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
845 * then it puts the vnode on the free list.
846 * If we don't do this we end up with a cleaned vnode that's
847 * not on the free list.
848 * XXX assume FreeBSD is the same for now.
857 code = afs_FlushVCache(tvc, &fv_slept);
867 continue; /* start over - may have raced. */
875 /* none free, making one is better than a panic */
876 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
877 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
878 #if defined(AFS_DARWIN_ENV) && !defined(UKERNEL)
879 tvc->v = NULL; /* important to clean this, or use memset 0 */
881 #ifdef KERNEL_HAVE_PIN
882 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
884 #if defined(AFS_SGI_ENV)
886 char name[METER_NAMSZ];
887 memset(tvc, 0, sizeof(struct vcache));
888 tvc->v.v_number = ++afsvnumbers;
889 tvc->vc_rwlockid = OSI_NO_LOCKID;
890 initnsema(&tvc->vc_rwlock, 1,
891 makesname(name, "vrw", tvc->v.v_number));
892 #ifndef AFS_SGI53_ENV
893 initnsema(&tvc->v.v_sync, 0,
894 makesname(name, "vsy", tvc->v.v_number));
896 #ifndef AFS_SGI62_ENV
897 initnlock(&tvc->v.v_lock,
898 makesname(name, "vlk", tvc->v.v_number));
901 #endif /* AFS_SGI_ENV */
903 tvc = freeVCList; /* take from free list */
904 freeVCList = tvc->nextfree;
905 tvc->nextfree = NULL;
907 #endif /* AFS_OSF_ENV */
909 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
911 panic("afs_NewVCache(): free vcache with vnode attached");
914 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
915 memset((char *)tvc, 0, sizeof(struct vcache));
920 RWLOCK_INIT(&tvc->lock, "vcache lock");
921 #if defined(AFS_SUN5_ENV)
922 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
923 #endif /* defined(AFS_SUN5_ENV) */
925 tvc->parentVnode = 0;
927 tvc->linkData = NULL;
930 tvc->execsOrWriters = 0;
933 tvc->states = CVInit;
934 tvc->last_looker = 0;
936 tvc->asynchrony = -1;
939 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
942 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
943 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
945 tvc->callback = serverp; /* to minimize chance that clear
947 #if defined(AFS_DISCON_ENV)
948 tvc->ddirty_next = NULL;
949 tvc->ddirty_flags = 0;
955 tvc->hnext = afs_vhashT[i];
957 QAdd(&afs_vhashTV[j], &tvc->vhashq);
959 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
960 refpanic("NewVCache VLRU inconsistent");
962 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
963 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
964 refpanic("NewVCache VLRU inconsistent2");
966 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
967 refpanic("NewVCache VLRU inconsistent3");
969 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
970 refpanic("NewVCache VLRU inconsistent4");
973 /* it should now be safe to drop the xvcache lock */
975 ReleaseWriteLock(&afs_xvcache);
977 afs_nbsd_getnewvnode(tvc); /* includes one refcount */
979 ObtainWriteLock(&afs_xvcache,337);
980 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
982 #ifdef AFS_DARWIN_ENV
983 ReleaseWriteLock(&afs_xvcache);
985 afs_darwin_getnewvnode(tvc); /* includes one refcount */
987 ObtainWriteLock(&afs_xvcache,338);
988 #ifdef AFS_DARWIN80_ENV
989 LOCKINIT(tvc->rwlock);
991 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
998 ReleaseWriteLock(&afs_xvcache);
1000 #if defined(AFS_FBSD60_ENV)
1001 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
1002 #elif defined(AFS_FBSD50_ENV)
1003 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
1005 if (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
1007 panic("afs getnewvnode"); /* can't happen */
1009 ObtainWriteLock(&afs_xvcache,339);
1010 if (tvc->v != NULL) {
1011 /* I'd like to know if this ever happens...
1012 * We don't drop global for the rest of this function,
1013 * so if we do lose the race, the other thread should
1014 * have found the same vnode and finished initializing
1015 * the vcache entry. Is it conceivable that this vcache
1016 * entry could be recycled during this interval? If so,
1017 * then there probably needs to be some sort of additional
1018 * mutual exclusion (an Embryonic flag would suffice).
1020 printf("afs_NewVCache: lost the race\n");
1024 tvc->v->v_data = tvc;
1025 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
1029 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
1030 /* Hold it for the LRU (should make count 2) */
1031 VN_HOLD(AFSTOV(tvc));
1032 #else /* AFS_OSF_ENV */
1033 #if !(defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV))
1034 VREFCOUNT_SET(tvc, 1); /* us */
1035 #endif /* AFS_XBSD_ENV */
1036 #endif /* AFS_OSF_ENV */
1037 #ifdef AFS_AIX32_ENV
1038 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
1039 tvc->vmh = tvc->segid = NULL;
1043 #if defined(AFS_CACHE_BYPASS)
1044 tvc->cachingStates = 0;
1045 tvc->cachingTransitions = 0;
1048 #ifdef AFS_BOZONLOCK_ENV
1049 #if defined(AFS_SUN5_ENV)
1050 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
1052 #if defined(AFS_SUN55_ENV)
1053 /* This is required if the kaio (kernel aynchronous io)
1054 ** module is installed. Inside the kernel, the function
1055 ** check_vp( common/os/aio.c) checks to see if the kernel has
1056 ** to provide asynchronous io for this vnode. This
1057 ** function extracts the device number by following the
1058 ** v_data field of the vnode. If we do not set this field
1059 ** then the system panics. The value of the v_data field
1060 ** is not really important for AFS vnodes because the kernel
1061 ** does not do asynchronous io for regular files. Hence,
1062 ** for the time being, we fill up the v_data field with the
1063 ** vnode pointer itself. */
1064 tvc->v.v_data = (char *)tvc;
1065 #endif /* AFS_SUN55_ENV */
1067 afs_BozonInit(&tvc->pvnLock, tvc);
1070 /* initialize vnode data, note vrefCount is v.v_count */
1072 /* Don't forget to free the gnode space */
1073 tvc->v.v_gnode = gnodepnt =
1074 (struct gnode *)osi_AllocSmallSpace(sizeof(struct gnode));
1075 memset((char *)gnodepnt, 0, sizeof(struct gnode));
1077 #ifdef AFS_SGI64_ENV
1078 memset((void *)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc));
1079 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
1080 #ifdef AFS_SGI65_ENV
1081 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
1082 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1084 bhv_head_init(&(tvc->v.v_bh));
1085 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1087 #ifdef AFS_SGI65_ENV
1088 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion *)tvc;
1089 #ifdef VNODE_TRACING
1090 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
1092 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
1094 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
1095 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
1097 vnode_pcache_init(&tvc->v);
1098 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
1099 /* Above define is never true execpt in SGI test kernels. */
1100 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
1102 #ifdef INTR_KTHREADS
1103 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
1106 SetAfsVnode(AFSTOV(tvc));
1107 #endif /* AFS_SGI64_ENV */
1109 * The proper value for mvstat (for root fids) is setup by the caller.
1112 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
1114 if (afs_globalVFS == 0)
1115 osi_Panic("afs globalvfs");
1116 #if !defined(AFS_LINUX22_ENV)
1117 vSetVfsp(tvc, afs_globalVFS);
1119 vSetType(tvc, VREG);
1121 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
1122 tvc->v.v_vfsprev = NULL;
1123 afs_globalVFS->vfs_vnodes = &tvc->v;
1124 if (tvc->v.v_vfsnext != NULL)
1125 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
1126 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us! */
1127 gnodepnt->gn_vnode = &tvc->v;
1129 #if defined(AFS_DUX40_ENV)
1130 insmntque(tvc, afs_globalVFS, &afs_ubcops);
1133 /* Is this needed??? */
1134 insmntque(tvc, afs_globalVFS);
1135 #endif /* AFS_OSF_ENV */
1136 #endif /* AFS_DUX40_ENV */
1137 #ifdef AFS_FBSD70_ENV
1138 #ifndef AFS_FBSD80_ENV /* yup. they put it back. */
1139 insmntque(AFSTOV(tvc), afs_globalVFS);
1142 #if defined(AFS_SGI_ENV)
1143 VN_SET_DPAGES(&(tvc->v), (struct pfdat *)NULL);
1144 osi_Assert((tvc->v.v_flag & VINACT) == 0);
1146 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
1147 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
1148 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
1149 osi_Assert(tvc->v.v_filocks == NULL);
1150 #if !defined(AFS_SGI65_ENV)
1151 osi_Assert(tvc->v.v_filocksem == NULL);
1153 osi_Assert(tvc->cred == NULL);
1154 #ifdef AFS_SGI64_ENV
1155 vnode_pcache_reinit(&tvc->v);
1156 tvc->v.v_rdev = NODEV;
1158 vn_initlist((struct vnlist *)&tvc->v);
1160 #endif /* AFS_SGI_ENV */
1162 osi_dnlc_purgedp(tvc); /* this may be overkill */
1163 memset((char *)&(tvc->callsort), 0, sizeof(struct afs_q));
1165 tvc->states &=~ CVInit;
1166 afs_osi_Wakeup(&tvc->states);
1170 } /*afs_NewVCache */
1174 * afs_FlushActiveVcaches
1180 * doflocks : Do we handle flocks?
1182 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1184 afs_FlushActiveVcaches(register afs_int32 doflocks)
1186 register struct vcache *tvc;
1188 register struct conn *tc;
1189 register afs_int32 code;
1190 register struct AFS_UCRED *cred = NULL;
1191 struct vrequest treq, ureq;
1192 struct AFSVolSync tsync;
1195 AFS_STATCNT(afs_FlushActiveVcaches);
1196 ObtainReadLock(&afs_xvcache);
1197 for (i = 0; i < VCSIZE; i++) {
1198 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1199 if (tvc->states & CVInit) continue;
1200 #ifdef AFS_DARWIN80_ENV
1201 if (tvc->states & CDeadVnode &&
1202 (tvc->states & (CCore|CUnlinkedDel) ||
1203 tvc->flockCount)) panic("Dead vnode has core/unlinkedel/flock");
1205 if (doflocks && tvc->flockCount != 0) {
1206 /* if this entry has an flock, send a keep-alive call out */
1208 ReleaseReadLock(&afs_xvcache);
1209 ObtainWriteLock(&tvc->lock, 51);
1211 afs_InitReq(&treq, afs_osi_credp);
1212 treq.flags |= O_NONBLOCK;
1214 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1216 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1219 RXAFS_ExtendLock(tc->id,
1220 (struct AFSFid *)&tvc->fid.Fid,
1226 } while (afs_Analyze
1227 (tc, code, &tvc->fid, &treq,
1228 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1230 ReleaseWriteLock(&tvc->lock);
1231 #ifdef AFS_DARWIN80_ENV
1233 ObtainReadLock(&afs_xvcache);
1235 ObtainReadLock(&afs_xvcache);
1240 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1242 * Don't let it evaporate in case someone else is in
1243 * this code. Also, drop the afs_xvcache lock while
1244 * getting vcache locks.
1247 ReleaseReadLock(&afs_xvcache);
1248 #ifdef AFS_BOZONLOCK_ENV
1249 afs_BozonLock(&tvc->pvnLock, tvc);
1251 #if defined(AFS_SGI_ENV)
1253 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1255 osi_Assert(VREFCOUNT_GT(tvc,0));
1256 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1258 ObtainWriteLock(&tvc->lock, 52);
1259 if (tvc->states & CCore) {
1260 tvc->states &= ~CCore;
1261 /* XXXX Find better place-holder for cred XXXX */
1262 cred = (struct AFS_UCRED *)tvc->linkData;
1263 tvc->linkData = NULL; /* XXX */
1264 afs_InitReq(&ureq, cred);
1265 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1266 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1267 tvc->execsOrWriters);
1268 code = afs_StoreOnLastReference(tvc, &ureq);
1269 ReleaseWriteLock(&tvc->lock);
1270 #ifdef AFS_BOZONLOCK_ENV
1271 afs_BozonUnlock(&tvc->pvnLock, tvc);
1273 hzero(tvc->flushDV);
1276 if (code && code != VNOVNODE) {
1277 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1278 /* /dev/console */ 1);
1280 } else if (tvc->states & CUnlinkedDel) {
1284 ReleaseWriteLock(&tvc->lock);
1285 #ifdef AFS_BOZONLOCK_ENV
1286 afs_BozonUnlock(&tvc->pvnLock, tvc);
1288 #if defined(AFS_SGI_ENV)
1289 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1291 afs_remunlink(tvc, 0);
1292 #if defined(AFS_SGI_ENV)
1293 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1296 /* lost (or won, perhaps) the race condition */
1297 ReleaseWriteLock(&tvc->lock);
1298 #ifdef AFS_BOZONLOCK_ENV
1299 afs_BozonUnlock(&tvc->pvnLock, tvc);
1302 #if defined(AFS_SGI_ENV)
1303 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1305 #ifdef AFS_DARWIN80_ENV
1308 AFS_RELE(AFSTOV(tvc));
1309 /* Matches write code setting CCore flag */
1312 ObtainReadLock(&afs_xvcache);
1314 ObtainReadLock(&afs_xvcache);
1317 AFS_RELE(AFSTOV(tvc));
1318 /* Matches write code setting CCore flag */
1325 ReleaseReadLock(&afs_xvcache);
1334 * Make sure a cache entry is up-to-date status-wise.
1336 * NOTE: everywhere that calls this can potentially be sped up
1337 * by checking CStatd first, and avoiding doing the InitReq
1338 * if this is up-to-date.
1340 * Anymore, the only places that call this KNOW already that the
1341 * vcache is not up-to-date, so we don't screw around.
1344 * avc : Ptr to vcache entry to verify.
1349 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1351 register struct vcache *tvc;
1353 AFS_STATCNT(afs_VerifyVCache);
1355 #if defined(AFS_OSF_ENV)
1356 ObtainReadLock(&avc->lock);
1357 if (afs_IsWired(avc)) {
1358 ReleaseReadLock(&avc->lock);
1361 ReleaseReadLock(&avc->lock);
1362 #endif /* AFS_OSF_ENV */
1363 /* otherwise we must fetch the status info */
1365 ObtainWriteLock(&avc->lock, 53);
1366 if (avc->states & CStatd) {
1367 ReleaseWriteLock(&avc->lock);
1370 ObtainWriteLock(&afs_xcbhash, 461);
1371 avc->states &= ~(CStatd | CUnique);
1372 avc->callback = NULL;
1373 afs_DequeueCallback(avc);
1374 ReleaseWriteLock(&afs_xcbhash);
1375 ReleaseWriteLock(&avc->lock);
1377 /* since we've been called back, or the callback has expired,
1378 * it's possible that the contents of this directory, or this
1379 * file's name have changed, thus invalidating the dnlc contents.
1381 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1382 osi_dnlc_purgedp(avc);
1384 osi_dnlc_purgevp(avc);
1386 /* fetch the status info */
1387 tvc = afs_GetVCache(&avc->fid, areq, NULL, avc);
1390 /* Put it back; caller has already incremented vrefCount */
1394 } /*afs_VerifyVCache */
1401 * Simple copy of stat info into cache.
1404 * avc : Ptr to vcache entry involved.
1405 * astat : Ptr to stat info to copy.
1408 * Nothing interesting.
1410 * Callers: as of 1992-04-29, only called by WriteVCache
1413 afs_SimpleVStat(register struct vcache *avc,
1414 register struct AFSFetchStatus *astat, struct vrequest *areq)
1417 AFS_STATCNT(afs_SimpleVStat);
1420 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1421 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1423 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1425 #ifdef AFS_64BIT_CLIENT
1426 FillInt64(length, astat->Length_hi, astat->Length);
1427 #else /* AFS_64BIT_CLIENT */
1428 length = astat->Length;
1429 #endif /* AFS_64BIT_CLIENT */
1430 #if defined(AFS_SGI_ENV)
1431 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1432 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1433 if (length < avc->m.Length) {
1434 vnode_t *vp = (vnode_t *) avc;
1436 osi_Assert(WriteLocked(&avc->lock));
1437 ReleaseWriteLock(&avc->lock);
1439 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1441 ObtainWriteLock(&avc->lock, 67);
1444 /* if writing the file, don't fetch over this value */
1445 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1446 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1447 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1448 avc->m.Length = length;
1449 avc->m.Date = astat->ClientModTime;
1451 avc->m.Owner = astat->Owner;
1452 avc->m.Group = astat->Group;
1453 avc->m.Mode = astat->UnixModeBits;
1454 if (vType(avc) == VREG) {
1455 avc->m.Mode |= S_IFREG;
1456 } else if (vType(avc) == VDIR) {
1457 avc->m.Mode |= S_IFDIR;
1458 } else if (vType(avc) == VLNK) {
1459 avc->m.Mode |= S_IFLNK;
1460 if ((avc->m.Mode & 0111) == 0)
1463 if (avc->states & CForeign) {
1464 struct axscache *ac;
1465 avc->anyAccess = astat->AnonymousAccess;
1467 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1469 * Caller has at least one bit not covered by anonymous, and
1470 * thus may have interesting rights.
1472 * HOWEVER, this is a really bad idea, because any access query
1473 * for bits which aren't covered by anonymous, on behalf of a user
1474 * who doesn't have any special rights, will result in an answer of
1475 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1476 * It's an especially bad idea under Ultrix, since (due to the lack of
1477 * a proper access() call) it must perform several afs_access() calls
1478 * in order to create magic mode bits that vary according to who makes
1479 * the call. In other words, _every_ stat() generates a test for
1482 #endif /* badidea */
1483 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1484 ac->axess = astat->CallerAccess;
1485 else /* not found, add a new one if possible */
1486 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1490 } /*afs_SimpleVStat */
1497 * Store the status info *only* back to the server for a
1501 * avc : Ptr to the vcache entry.
1502 * astatus : Ptr to the status info to store.
1503 * areq : Ptr to the associated vrequest.
1506 * Must be called with a shared lock held on the vnode.
1510 afs_WriteVCache(register struct vcache *avc,
1511 register struct AFSStoreStatus *astatus,
1512 struct vrequest *areq)
1516 struct AFSFetchStatus OutStatus;
1517 struct AFSVolSync tsync;
1519 AFS_STATCNT(afs_WriteVCache);
1520 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1521 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length));
1523 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1525 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1528 RXAFS_StoreStatus(tc->id, (struct AFSFid *)&avc->fid.Fid,
1529 astatus, &OutStatus, &tsync);
1534 } while (afs_Analyze
1535 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1536 SHARED_LOCK, NULL));
1538 UpgradeSToWLock(&avc->lock, 20);
1540 /* success, do the changes locally */
1541 afs_SimpleVStat(avc, &OutStatus, areq);
1543 * Update the date, too. SimpleVStat didn't do this, since
1544 * it thought we were doing this after fetching new status
1545 * over a file being written.
1547 avc->m.Date = OutStatus.ClientModTime;
1549 /* failure, set up to check with server next time */
1550 ObtainWriteLock(&afs_xcbhash, 462);
1551 afs_DequeueCallback(avc);
1552 avc->states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1553 ReleaseWriteLock(&afs_xcbhash);
1554 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1555 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1557 ConvertWToSLock(&avc->lock);
1560 } /*afs_WriteVCache */
1561 #if defined(AFS_DISCON_ENV)
1564 * Store status info only locally, set the proper disconnection flags
1565 * and add to dirty list.
1567 * \param avc The vcache to be written locally.
1568 * \param astatus Get attr fields from local store.
1569 * \param attrs This one is only of the vs_size.
1571 * \note Must be called with a shared lock on the vnode
1573 int afs_WriteVCacheDiscon(register struct vcache *avc,
1574 register struct AFSStoreStatus *astatus,
1575 struct vattr *attrs)
1578 afs_int32 flags = 0;
1580 UpgradeSToWLock(&avc->lock, 700);
1582 if (!astatus->Mask) {
1588 /* Set attributes. */
1589 if (astatus->Mask & AFS_SETMODTIME) {
1590 avc->m.Date = astatus->ClientModTime;
1591 flags |= VDisconSetTime;
1594 if (astatus->Mask & AFS_SETOWNER) {
1595 printf("Not allowed yet. \n");
1596 //avc->m.Owner = astatus->Owner;
1599 if (astatus->Mask & AFS_SETGROUP) {
1600 printf("Not allowed yet. \n");
1601 //avc->m.Group = astatus->Group;
1604 if (astatus->Mask & AFS_SETMODE) {
1605 avc->m.Mode = astatus->UnixModeBits;
1607 #if 0 /* XXX: Leaving this out, so it doesn't mess up the file type flag.*/
1609 if (vType(avc) == VREG) {
1610 avc->m.Mode |= S_IFREG;
1611 } else if (vType(avc) == VDIR) {
1612 avc->m.Mode |= S_IFDIR;
1613 } else if (vType(avc) == VLNK) {
1614 avc->m.Mode |= S_IFLNK;
1615 if ((avc->m.Mode & 0111) == 0)
1619 flags |= VDisconSetMode;
1620 } /* if(astatus.Mask & AFS_SETMODE) */
1622 } /* if (!astatus->Mask) */
1624 if (attrs->va_size > 0) {
1625 /* XXX: Do I need more checks? */
1626 /* Truncation operation. */
1627 flags |= VDisconTrunc;
1630 ObtainWriteLock(&afs_DDirtyVCListLock, 701);
1633 /* Add to disconnected dirty list and set dirty flag.*/
1634 if (!avc->ddirty_flags ||
1635 (avc->ddirty_flags == VDisconShadowed)) {
1636 /* Not in dirty list. */
1637 AFS_DISCON_ADD_DIRTY(avc);
1640 avc->ddirty_flags |= flags;
1643 ReleaseWriteLock(&afs_DDirtyVCListLock);
1645 /* XXX: How about the rest of the fields? */
1647 ConvertWToSLock(&avc->lock);
1658 * Copy astat block into vcache info
1661 * avc : Ptr to vcache entry.
1662 * astat : Ptr to stat block to copy in.
1663 * areq : Ptr to associated request.
1666 * Must be called under a write lock
1668 * Note: this code may get dataversion and length out of sync if the file has
1669 * been modified. This is less than ideal. I haven't thought about
1670 * it sufficiently to be certain that it is adequate.
1673 afs_ProcessFS(register struct vcache *avc,
1674 register struct AFSFetchStatus *astat, struct vrequest *areq)
1677 AFS_STATCNT(afs_ProcessFS);
1679 #ifdef AFS_64BIT_CLIENT
1680 FillInt64(length, astat->Length_hi, astat->Length);
1681 #else /* AFS_64BIT_CLIENT */
1682 length = astat->Length;
1683 #endif /* AFS_64BIT_CLIENT */
1684 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1685 * number for each bulk status request. Under no circumstances
1686 * should afs_DoBulkStat store a sequence number if the new
1687 * length will be ignored when afs_ProcessFS is called with
1688 * new stats. If you change the following conditional then you
1689 * also need to change the conditional in afs_DoBulkStat. */
1691 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1692 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1694 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1696 /* if we're writing or mapping this file, don't fetch over these
1699 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1700 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1701 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1702 avc->m.Length = length;
1703 avc->m.Date = astat->ClientModTime;
1705 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1706 avc->m.Owner = astat->Owner;
1707 avc->m.Mode = astat->UnixModeBits;
1708 avc->m.Group = astat->Group;
1709 avc->m.LinkCount = astat->LinkCount;
1710 if (astat->FileType == File) {
1711 vSetType(avc, VREG);
1712 avc->m.Mode |= S_IFREG;
1713 } else if (astat->FileType == Directory) {
1714 vSetType(avc, VDIR);
1715 avc->m.Mode |= S_IFDIR;
1716 } else if (astat->FileType == SymbolicLink) {
1717 if (afs_fakestat_enable && (avc->m.Mode & 0111) == 0) {
1718 vSetType(avc, VDIR);
1719 avc->m.Mode |= S_IFDIR;
1721 vSetType(avc, VLNK);
1722 avc->m.Mode |= S_IFLNK;
1724 if ((avc->m.Mode & 0111) == 0) {
1728 avc->anyAccess = astat->AnonymousAccess;
1730 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1732 * Caller has at least one bit not covered by anonymous, and
1733 * thus may have interesting rights.
1735 * HOWEVER, this is a really bad idea, because any access query
1736 * for bits which aren't covered by anonymous, on behalf of a user
1737 * who doesn't have any special rights, will result in an answer of
1738 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1739 * It's an especially bad idea under Ultrix, since (due to the lack of
1740 * a proper access() call) it must perform several afs_access() calls
1741 * in order to create magic mode bits that vary according to who makes
1742 * the call. In other words, _every_ stat() generates a test for
1745 #endif /* badidea */
1747 struct axscache *ac;
1748 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1749 ac->axess = astat->CallerAccess;
1750 else /* not found, add a new one if possible */
1751 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1753 } /*afs_ProcessFS */
1757 afs_RemoteLookup(register struct VenusFid *afid, struct vrequest *areq,
1758 char *name, struct VenusFid *nfid,
1759 struct AFSFetchStatus *OutStatusp,
1760 struct AFSCallBack *CallBackp, struct server **serverp,
1761 struct AFSVolSync *tsyncp)
1765 register struct conn *tc;
1766 struct AFSFetchStatus OutDirStatus;
1769 name = ""; /* XXX */
1771 tc = afs_Conn(afid, areq, SHARED_LOCK);
1774 *serverp = tc->srvr->server;
1776 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1779 RXAFS_Lookup(tc->id, (struct AFSFid *)&afid->Fid, name,
1780 (struct AFSFid *)&nfid->Fid, OutStatusp,
1781 &OutDirStatus, CallBackp, tsyncp);
1786 } while (afs_Analyze
1787 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1798 * Given a file id and a vrequest structure, fetch the status
1799 * information associated with the file.
1803 * areq : Ptr to associated vrequest structure, specifying the
1804 * user whose authentication tokens will be used.
1805 * avc : caller may already have a vcache for this file, which is
1809 * The cache entry is returned with an increased vrefCount field.
1810 * The entry must be discarded by calling afs_PutVCache when you
1811 * are through using the pointer to the cache entry.
1813 * You should not hold any locks when calling this function, except
1814 * locks on other vcache entries. If you lock more than one vcache
1815 * entry simultaneously, you should lock them in this order:
1817 * 1. Lock all files first, then directories.
1818 * 2. Within a particular type, lock entries in Fid.Vnode order.
1820 * This locking hierarchy is convenient because it allows locking
1821 * of a parent dir cache entry, given a file (to check its access
1822 * control list). It also allows renames to be handled easily by
1823 * locking directories in a constant order.
1824 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1826 /* might have a vcache structure already, which must
1827 * already be held by the caller */
1830 afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq,
1831 afs_int32 * cached, struct vcache *avc)
1834 afs_int32 code, newvcache = 0;
1835 register struct vcache *tvc;
1839 AFS_STATCNT(afs_GetVCache);
1842 *cached = 0; /* Init just in case */
1844 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1848 ObtainSharedLock(&afs_xvcache, 5);
1850 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU | IS_SLOCK);
1852 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1853 ReleaseSharedLock(&afs_xvcache);
1854 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1862 osi_Assert((tvc->states & CVInit) == 0);
1863 /* If we are in readdir, return the vnode even if not statd */
1864 if ((tvc->states & CStatd) || afs_InReadDir(tvc)) {
1865 ReleaseSharedLock(&afs_xvcache);
1869 UpgradeSToWLock(&afs_xvcache, 21);
1871 /* no cache entry, better grab one */
1872 tvc = afs_NewVCache(afid, NULL);
1875 ConvertWToSLock(&afs_xvcache);
1878 ReleaseSharedLock(&afs_xvcache);
1882 afs_stats_cmperf.vcacheMisses++;
1885 ReleaseSharedLock(&afs_xvcache);
1887 ObtainWriteLock(&tvc->lock, 54);
1889 if (tvc->states & CStatd) {
1890 ReleaseWriteLock(&tvc->lock);
1893 #if defined(AFS_OSF_ENV)
1894 if (afs_IsWired(tvc)) {
1895 ReleaseWriteLock(&tvc->lock);
1898 #endif /* AFS_OSF_ENV */
1899 #ifdef AFS_DARWIN80_ENV
1900 /* Darwin 8.0 only has bufs in nfs, so we shouldn't have to worry about them.
1903 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1905 * XXX - I really don't like this. Should try to understand better.
1906 * It seems that sometimes, when we get called, we already hold the
1907 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1908 * We can't drop the vnode lock, because that could result in a race.
1909 * Sometimes, though, we get here and don't hold the vnode lock.
1910 * I hate code paths that sometimes hold locks and sometimes don't.
1911 * In any event, the dodge we use here is to check whether the vnode
1912 * is locked, and if it isn't, then we gain and drop it around the call
1913 * to vinvalbuf; otherwise, we leave it alone.
1916 struct vnode *vp = AFSTOV(tvc);
1919 #if defined(AFS_DARWIN_ENV)
1920 iheldthelock = VOP_ISLOCKED(vp);
1922 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc());
1923 /* this is messy. we can call fsync which will try to reobtain this */
1924 if (VTOAFS(vp) == tvc)
1925 ReleaseWriteLock(&tvc->lock);
1926 if (UBCINFOEXISTS(vp)) {
1927 vinvalbuf(vp, V_SAVE, &afs_osi_cred, current_proc(), PINOD, 0);
1929 if (VTOAFS(vp) == tvc)
1930 ObtainWriteLock(&tvc->lock, 954);
1932 VOP_UNLOCK(vp, LK_EXCLUSIVE, current_proc());
1933 #elif defined(AFS_FBSD80_ENV)
1934 iheldthelock = VOP_ISLOCKED(vp);
1935 if (!iheldthelock) {
1936 /* nosleep/sleep lock order reversal */
1937 int glocked = ISAFS_GLOCK();
1940 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1944 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1947 #elif defined(AFS_FBSD60_ENV)
1948 iheldthelock = VOP_ISLOCKED(vp, curthread);
1950 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1951 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1953 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1954 #elif defined(AFS_FBSD50_ENV)
1955 iheldthelock = VOP_ISLOCKED(vp, curthread);
1957 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1958 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1960 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1961 #elif defined(AFS_FBSD40_ENV)
1962 iheldthelock = VOP_ISLOCKED(vp, curproc);
1964 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1965 vinvalbuf(vp, V_SAVE, osi_curcred(), curproc, PINOD, 0);
1967 VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
1968 #elif defined(AFS_OBSD_ENV)
1969 iheldthelock = VOP_ISLOCKED(vp, curproc);
1971 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1972 uvm_vnp_uncache(vp);
1974 VOP_UNLOCK(vp, 0, curproc);
1980 ObtainWriteLock(&afs_xcbhash, 464);
1981 tvc->states &= ~CUnique;
1983 afs_DequeueCallback(tvc);
1984 ReleaseWriteLock(&afs_xcbhash);
1986 /* It is always appropriate to throw away all the access rights? */
1987 afs_FreeAllAxs(&(tvc->Access));
1988 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1990 if ((tvp->states & VForeign)) {
1992 tvc->states |= CForeign;
1993 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1994 && (tvp->rootUnique == afid->Fid.Unique)) {
1998 if (tvp->states & VRO)
2000 if (tvp->states & VBackup)
2001 tvc->states |= CBackup;
2002 /* now copy ".." entry back out of volume structure, if necessary */
2003 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2005 tvc->mvid = (struct VenusFid *)
2006 osi_AllocSmallSpace(sizeof(struct VenusFid));
2007 *tvc->mvid = tvp->dotdot;
2009 afs_PutVolume(tvp, READ_LOCK);
2013 afs_RemoveVCB(afid);
2015 struct AFSFetchStatus OutStatus;
2017 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
2018 afs_ProcessFS(tvc, &OutStatus, areq);
2019 tvc->states |= CStatd | CUnique;
2020 tvc->parentVnode = OutStatus.ParentVnode;
2021 tvc->parentUnique = OutStatus.ParentUnique;
2025 if (AFS_IS_DISCONNECTED) {
2026 if (AFS_IS_DISCON_RW) {
2027 /* Seek the vnode manually. */
2028 ObtainSharedLock(&afs_xvcache, 738);
2029 avc = afs_FindVCache(afid, NULL, 1);
2030 ReleaseSharedLock(&afs_xvcache);
2032 if (vType(avc) == VDIR)
2033 OutStatus.FileType = Directory;
2035 code = tvc?0:ENOENT;
2037 /* Nothing to do otherwise...*/
2039 printf("Network is down in afs_GetCache");
2042 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
2044 /* For the NFS translator's benefit, make sure
2045 * non-directory vnodes always have their parent FID set
2046 * correctly, even when created as a result of decoding an
2047 * NFS filehandle. It would be nice to also do this for
2048 * directories, but we can't because the fileserver fills
2049 * in the FID of the directory itself instead of that of
2052 if (!code && OutStatus.FileType != Directory &&
2053 !tvc->parentVnode) {
2054 tvc->parentVnode = OutStatus.ParentVnode;
2055 tvc->parentUnique = OutStatus.ParentUnique;
2061 ReleaseWriteLock(&tvc->lock);
2067 ReleaseWriteLock(&tvc->lock);
2070 } /*afs_GetVCache */
2075 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
2076 afs_int32 * cached, struct vcache *adp, char *aname)
2078 afs_int32 code, now, newvcache = 0;
2079 struct VenusFid nfid;
2080 register struct vcache *tvc;
2082 struct AFSFetchStatus OutStatus;
2083 struct AFSCallBack CallBack;
2084 struct AFSVolSync tsync;
2085 struct server *serverp = 0;
2089 AFS_STATCNT(afs_GetVCache);
2091 *cached = 0; /* Init just in case */
2093 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2097 ObtainReadLock(&afs_xvcache);
2098 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
2101 ReleaseReadLock(&afs_xvcache);
2103 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2104 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2108 ObtainReadLock(&tvc->lock);
2110 if (tvc->states & CStatd) {
2114 ReleaseReadLock(&tvc->lock);
2117 tvc->states &= ~CUnique;
2119 ReleaseReadLock(&tvc->lock);
2121 ObtainReadLock(&afs_xvcache);
2124 ReleaseReadLock(&afs_xvcache);
2126 /* lookup the file */
2129 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
2131 if (AFS_IS_DISCONNECTED) {
2132 printf("Network is down in afs_LookupVcache\n");
2136 afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus,
2137 &CallBack, &serverp, &tsync);
2139 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2143 ObtainSharedLock(&afs_xvcache, 6);
2144 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU | IS_SLOCK/* no xstats now */ );
2146 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2147 ReleaseSharedLock(&afs_xvcache);
2148 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2154 /* no cache entry, better grab one */
2155 UpgradeSToWLock(&afs_xvcache, 22);
2156 tvc = afs_NewVCache(&nfid, serverp);
2158 ConvertWToSLock(&afs_xvcache);
2161 ReleaseSharedLock(&afs_xvcache);
2166 ReleaseSharedLock(&afs_xvcache);
2167 ObtainWriteLock(&tvc->lock, 55);
2169 /* It is always appropriate to throw away all the access rights? */
2170 afs_FreeAllAxs(&(tvc->Access));
2171 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
2173 if ((tvp->states & VForeign)) {
2175 tvc->states |= CForeign;
2176 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
2177 && (tvp->rootUnique == afid->Fid.Unique))
2180 if (tvp->states & VRO)
2182 if (tvp->states & VBackup)
2183 tvc->states |= CBackup;
2184 /* now copy ".." entry back out of volume structure, if necessary */
2185 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2187 tvc->mvid = (struct VenusFid *)
2188 osi_AllocSmallSpace(sizeof(struct VenusFid));
2189 *tvc->mvid = tvp->dotdot;
2194 ObtainWriteLock(&afs_xcbhash, 465);
2195 afs_DequeueCallback(tvc);
2196 tvc->states &= ~(CStatd | CUnique);
2197 ReleaseWriteLock(&afs_xcbhash);
2198 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2199 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2201 afs_PutVolume(tvp, READ_LOCK);
2202 ReleaseWriteLock(&tvc->lock);
2207 ObtainWriteLock(&afs_xcbhash, 466);
2208 if (origCBs == afs_allCBs) {
2209 if (CallBack.ExpirationTime) {
2210 tvc->callback = serverp;
2211 tvc->cbExpires = CallBack.ExpirationTime + now;
2212 tvc->states |= CStatd | CUnique;
2213 tvc->states &= ~CBulkFetching;
2214 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
2215 } else if (tvc->states & CRO) {
2216 /* adapt gives us an hour. */
2217 tvc->cbExpires = 3600 + osi_Time();
2218 /*XXX*/ tvc->states |= CStatd | CUnique;
2219 tvc->states &= ~CBulkFetching;
2220 afs_QueueCallback(tvc, CBHash(3600), tvp);
2222 tvc->callback = NULL;
2223 afs_DequeueCallback(tvc);
2224 tvc->states &= ~(CStatd | CUnique);
2225 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2226 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2229 afs_DequeueCallback(tvc);
2230 tvc->states &= ~CStatd;
2231 tvc->states &= ~CUnique;
2232 tvc->callback = NULL;
2233 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2234 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2236 ReleaseWriteLock(&afs_xcbhash);
2238 afs_PutVolume(tvp, READ_LOCK);
2239 afs_ProcessFS(tvc, &OutStatus, areq);
2241 ReleaseWriteLock(&tvc->lock);
2247 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2248 afs_int32 * cached, struct volume *tvolp)
2250 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2251 afs_int32 getNewFid = 0;
2253 struct VenusFid nfid;
2254 register struct vcache *tvc;
2255 struct server *serverp = 0;
2256 struct AFSFetchStatus OutStatus;
2257 struct AFSCallBack CallBack;
2258 struct AFSVolSync tsync;
2263 #ifdef AFS_DARWIN80_ENV
2270 if (!tvolp->rootVnode || getNewFid) {
2271 struct VenusFid tfid;
2274 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2275 origCBs = afs_allCBs; /* ignore InitCallBackState */
2277 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2282 /* ReleaseReadLock(&tvolp->lock); */
2283 ObtainWriteLock(&tvolp->lock, 56);
2284 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2285 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2286 ReleaseWriteLock(&tvolp->lock);
2287 /* ObtainReadLock(&tvolp->lock);*/
2290 afid->Fid.Vnode = tvolp->rootVnode;
2291 afid->Fid.Unique = tvolp->rootUnique;
2295 ObtainSharedLock(&afs_xvcache, 7);
2297 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2298 if (!FidCmp(&(tvc->fid), afid)) {
2299 if (tvc->states & CVInit) {
2300 ReleaseSharedLock(&afs_xvcache);
2301 afs_osi_Sleep(&tvc->states);
2305 /* Grab this vnode, possibly reactivating from the free list */
2306 /* for the present (95.05.25) everything on the hash table is
2307 * definitively NOT in the free list -- at least until afs_reclaim
2308 * can be safely implemented */
2310 vg = vget(AFSTOV(tvc)); /* this bumps ref count */
2314 #endif /* AFS_OSF_ENV */
2315 #ifdef AFS_DARWIN80_ENV
2316 if (tvc->states & CDeadVnode) {
2317 ReleaseSharedLock(&afs_xvcache);
2318 afs_osi_Sleep(&tvc->states);
2322 if (vnode_get(tvp)) /* this bumps ref count */
2324 if (vnode_ref(tvp)) {
2326 /* AFSTOV(tvc) may be NULL */
2336 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
2337 /* Mount point no longer stat'd or unknown. FID may have changed. */
2340 AFS_RELE(AFSTOV(tvc));
2343 ReleaseSharedLock(&afs_xvcache);
2344 #ifdef AFS_DARWIN80_ENV
2347 vnode_put(AFSTOV(tvc));
2348 vnode_rele(AFSTOV(tvc));
2357 UpgradeSToWLock(&afs_xvcache, 23);
2358 /* no cache entry, better grab one */
2359 tvc = afs_NewVCache(afid, NULL);
2362 ReleaseWriteLock(&afs_xvcache);
2366 afs_stats_cmperf.vcacheMisses++;
2370 afs_stats_cmperf.vcacheHits++;
2371 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN80_ENV)
2372 /* we already bumped the ref count in the for loop above */
2373 #else /* AFS_OSF_ENV */
2376 UpgradeSToWLock(&afs_xvcache, 24);
2377 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2378 refpanic("GRVC VLRU inconsistent0");
2380 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2381 refpanic("GRVC VLRU inconsistent1");
2383 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2384 refpanic("GRVC VLRU inconsistent2");
2386 QRemove(&tvc->vlruq); /* move to lruq head */
2387 QAdd(&VLRU, &tvc->vlruq);
2388 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2389 refpanic("GRVC VLRU inconsistent3");
2391 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2392 refpanic("GRVC VLRU inconsistent4");
2394 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2395 refpanic("GRVC VLRU inconsistent5");
2400 ReleaseWriteLock(&afs_xvcache);
2402 if (tvc->states & CStatd) {
2406 ObtainReadLock(&tvc->lock);
2407 tvc->states &= ~CUnique;
2408 tvc->callback = NULL; /* redundant, perhaps */
2409 ReleaseReadLock(&tvc->lock);
2412 ObtainWriteLock(&tvc->lock, 57);
2414 /* It is always appropriate to throw away all the access rights? */
2415 afs_FreeAllAxs(&(tvc->Access));
2418 tvc->states |= CForeign;
2419 if (tvolp->states & VRO)
2421 if (tvolp->states & VBackup)
2422 tvc->states |= CBackup;
2423 /* now copy ".." entry back out of volume structure, if necessary */
2424 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2425 && (tvolp->rootUnique == afid->Fid.Unique)) {
2428 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2430 tvc->mvid = (struct VenusFid *)
2431 osi_AllocSmallSpace(sizeof(struct VenusFid));
2432 *tvc->mvid = tvolp->dotdot;
2436 afs_RemoveVCB(afid);
2439 struct VenusFid tfid;
2442 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2443 origCBs = afs_allCBs; /* ignore InitCallBackState */
2445 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2450 ObtainWriteLock(&afs_xcbhash, 467);
2451 afs_DequeueCallback(tvc);
2452 tvc->callback = NULL;
2453 tvc->states &= ~(CStatd | CUnique);
2454 ReleaseWriteLock(&afs_xcbhash);
2455 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2456 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2457 ReleaseWriteLock(&tvc->lock);
2462 ObtainWriteLock(&afs_xcbhash, 468);
2463 if (origCBs == afs_allCBs) {
2464 tvc->states |= CTruth;
2465 tvc->callback = serverp;
2466 if (CallBack.ExpirationTime != 0) {
2467 tvc->cbExpires = CallBack.ExpirationTime + start;
2468 tvc->states |= CStatd;
2469 tvc->states &= ~CBulkFetching;
2470 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2471 } else if (tvc->states & CRO) {
2472 /* adapt gives us an hour. */
2473 tvc->cbExpires = 3600 + osi_Time();
2474 /*XXX*/ tvc->states |= CStatd;
2475 tvc->states &= ~CBulkFetching;
2476 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2479 afs_DequeueCallback(tvc);
2480 tvc->callback = NULL;
2481 tvc->states &= ~(CStatd | CUnique);
2482 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2483 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2485 ReleaseWriteLock(&afs_xcbhash);
2486 afs_ProcessFS(tvc, &OutStatus, areq);
2488 ReleaseWriteLock(&tvc->lock);
2494 * Update callback status and (sometimes) attributes of a vnode.
2495 * Called after doing a fetch status RPC. Whilst disconnected, attributes
2496 * shouldn't be written to the vcache here.
2501 * \param Outsp Server status after rpc call.
2502 * \param acb Callback for this vnode.
2504 * \note The vcache must be write locked.
2507 afs_UpdateStatus(struct vcache *avc,
2508 struct VenusFid *afid,
2509 struct vrequest *areq,
2510 struct AFSFetchStatus *Outsp,
2511 struct AFSCallBack *acb,
2514 struct volume *volp;
2517 /* Dont write status in vcache if resyncing after a disconnection. */
2518 afs_ProcessFS(avc, Outsp, areq);
2520 volp = afs_GetVolume(afid, areq, READ_LOCK);
2521 ObtainWriteLock(&afs_xcbhash, 469);
2522 avc->states |= CTruth;
2523 if (avc->callback /* check for race */ ) {
2524 if (acb->ExpirationTime != 0) {
2525 avc->cbExpires = acb->ExpirationTime + start;
2526 avc->states |= CStatd;
2527 avc->states &= ~CBulkFetching;
2528 afs_QueueCallback(avc, CBHash(acb->ExpirationTime), volp);
2529 } else if (avc->states & CRO) {
2530 /* ordinary callback on a read-only volume -- AFS 3.2 style */
2531 avc->cbExpires = 3600 + start;
2532 avc->states |= CStatd;
2533 avc->states &= ~CBulkFetching;
2534 afs_QueueCallback(avc, CBHash(3600), volp);
2536 afs_DequeueCallback(avc);
2537 avc->callback = NULL;
2538 avc->states &= ~(CStatd | CUnique);
2539 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2540 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2543 afs_DequeueCallback(avc);
2544 avc->callback = NULL;
2545 avc->states &= ~(CStatd | CUnique);
2546 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2547 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2549 ReleaseWriteLock(&afs_xcbhash);
2551 afs_PutVolume(volp, READ_LOCK);
2556 * must be called with avc write-locked
2557 * don't absolutely have to invalidate the hint unless the dv has
2558 * changed, but be sure to get it right else there will be consistency bugs.
2561 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2562 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2565 afs_uint32 start = 0;
2566 register struct conn *tc;
2567 struct AFSCallBack CallBack;
2568 struct AFSVolSync tsync;
2571 tc = afs_Conn(afid, areq, SHARED_LOCK);
2572 avc->dchint = NULL; /* invalidate hints */
2574 avc->callback = tc->srvr->server;
2576 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2579 RXAFS_FetchStatus(tc->id, (struct AFSFid *)&afid->Fid, Outsp,
2587 } while (afs_Analyze
2588 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2589 SHARED_LOCK, NULL));
2592 afs_UpdateStatus(avc, afid, areq, Outsp, &CallBack, start);
2594 /* used to undo the local callback, but that's too extreme.
2595 * There are plenty of good reasons that fetchstatus might return
2596 * an error, such as EPERM. If we have the vnode cached, statd,
2597 * with callback, might as well keep track of the fact that we
2598 * don't have access...
2600 if (code == EPERM || code == EACCES) {
2601 struct axscache *ac;
2602 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2604 else /* not found, add a new one if possible */
2605 afs_AddAxs(avc->Access, areq->uid, 0);
2616 * Stuff some information into the vcache for the given file.
2619 * afid : File in question.
2620 * OutStatus : Fetch status on the file.
2621 * CallBack : Callback info.
2622 * tc : RPC connection involved.
2623 * areq : vrequest involved.
2626 * Nothing interesting.
2629 afs_StuffVcache(register struct VenusFid *afid,
2630 struct AFSFetchStatus *OutStatus,
2631 struct AFSCallBack *CallBack, register struct conn *tc,
2632 struct vrequest *areq)
2634 register afs_int32 code, i, newvcache = 0;
2635 register struct vcache *tvc;
2636 struct AFSVolSync tsync;
2638 struct axscache *ac;
2641 AFS_STATCNT(afs_StuffVcache);
2642 #ifdef IFS_VCACHECOUNT
2647 ObtainSharedLock(&afs_xvcache, 8);
2649 tvc = afs_FindVCache(afid, &retry, DO_VLRU| IS_SLOCK /* no stats */ );
2651 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2652 ReleaseSharedLock(&afs_xvcache);
2653 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2659 /* no cache entry, better grab one */
2660 UpgradeSToWLock(&afs_xvcache, 25);
2661 tvc = afs_NewVCache(afid, NULL);
2663 ConvertWToSLock(&afs_xvcache);
2666 ReleaseSharedLock(&afs_xvcache);
2671 ReleaseSharedLock(&afs_xvcache);
2672 ObtainWriteLock(&tvc->lock, 58);
2674 tvc->states &= ~CStatd;
2675 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2676 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2678 /* Is it always appropriate to throw away all the access rights? */
2679 afs_FreeAllAxs(&(tvc->Access));
2681 /*Copy useful per-volume info */
2682 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2684 if (newvcache && (tvp->states & VForeign))
2685 tvc->states |= CForeign;
2686 if (tvp->states & VRO)
2688 if (tvp->states & VBackup)
2689 tvc->states |= CBackup;
2691 * Now, copy ".." entry back out of volume structure, if
2694 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2696 tvc->mvid = (struct VenusFid *)
2697 osi_AllocSmallSpace(sizeof(struct VenusFid));
2698 *tvc->mvid = tvp->dotdot;
2701 /* store the stat on the file */
2702 afs_RemoveVCB(afid);
2703 afs_ProcessFS(tvc, OutStatus, areq);
2704 tvc->callback = tc->srvr->server;
2706 /* we use osi_Time twice below. Ideally, we would use the time at which
2707 * the FetchStatus call began, instead, but we don't have it here. So we
2708 * make do with "now". In the CRO case, it doesn't really matter. In
2709 * the other case, we hope that the difference between "now" and when the
2710 * call actually began execution on the server won't be larger than the
2711 * padding which the server keeps. Subtract 1 second anyway, to be on
2712 * the safe side. Can't subtract more because we don't know how big
2713 * ExpirationTime is. Possible consistency problems may arise if the call
2714 * timeout period becomes longer than the server's expiration padding. */
2715 ObtainWriteLock(&afs_xcbhash, 470);
2716 if (CallBack->ExpirationTime != 0) {
2717 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2718 tvc->states |= CStatd;
2719 tvc->states &= ~CBulkFetching;
2720 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2721 } else if (tvc->states & CRO) {
2722 /* old-fashioned AFS 3.2 style */
2723 tvc->cbExpires = 3600 + osi_Time();
2724 /*XXX*/ tvc->states |= CStatd;
2725 tvc->states &= ~CBulkFetching;
2726 afs_QueueCallback(tvc, CBHash(3600), tvp);
2728 afs_DequeueCallback(tvc);
2729 tvc->callback = NULL;
2730 tvc->states &= ~(CStatd | CUnique);
2731 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2732 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2734 ReleaseWriteLock(&afs_xcbhash);
2736 afs_PutVolume(tvp, READ_LOCK);
2738 /* look in per-pag cache */
2739 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2740 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2741 else /* not found, add a new one if possible */
2742 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2744 ReleaseWriteLock(&tvc->lock);
2745 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2746 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2747 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2749 * Release ref count... hope this guy stays around...
2752 } /*afs_StuffVcache */
2759 * Decrements the reference count on a cache entry.
2762 * avc : Pointer to the cache entry to decrement.
2765 * Nothing interesting.
2768 afs_PutVCache(register struct vcache *avc)
2770 AFS_STATCNT(afs_PutVCache);
2771 #ifdef AFS_DARWIN80_ENV
2772 vnode_put(AFSTOV(avc));
2776 * Can we use a read lock here?
2778 ObtainReadLock(&afs_xvcache);
2780 ReleaseReadLock(&afs_xvcache);
2782 } /*afs_PutVCache */
2785 static void findvc_sleep(struct vcache *avc, int flag) {
2786 if (flag & IS_SLOCK) {
2787 ReleaseSharedLock(&afs_xvcache);
2789 if (flag & IS_WLOCK) {
2790 ReleaseWriteLock(&afs_xvcache);
2792 ReleaseReadLock(&afs_xvcache);
2795 afs_osi_Sleep(&avc->states);
2796 if (flag & IS_SLOCK) {
2797 ObtainSharedLock(&afs_xvcache, 341);
2799 if (flag & IS_WLOCK) {
2800 ObtainWriteLock(&afs_xvcache, 343);
2802 ObtainReadLock(&afs_xvcache);
2810 * Find a vcache entry given a fid.
2813 * afid : Pointer to the fid whose cache entry we desire.
2814 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2815 * unlock the vnode, and try again.
2816 * flags: bit 1 to specify whether to compute hit statistics. Not
2817 * set if FindVCache is called as part of internal bookkeeping.
2820 * Must be called with the afs_xvcache lock at least held at
2821 * the read level. In order to do the VLRU adjustment, the xvcache lock
2822 * must be shared-- we upgrade it here.
2826 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2829 register struct vcache *tvc;
2831 #if defined( AFS_OSF_ENV)
2834 #ifdef AFS_DARWIN80_ENV
2838 AFS_STATCNT(afs_FindVCache);
2842 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2843 if (FidMatches(afid, tvc)) {
2844 if (tvc->states & CVInit) {
2845 findvc_sleep(tvc, flag);
2849 /* Grab this vnode, possibly reactivating from the free list */
2851 vg = vget(AFSTOV(tvc));
2855 #endif /* AFS_OSF_ENV */
2856 #ifdef AFS_DARWIN80_ENV
2857 if (tvc->states & CDeadVnode) {
2858 findvc_sleep(tvc, flag);
2864 if (vnode_ref(tvp)) {
2866 /* AFSTOV(tvc) may be NULL */
2876 /* should I have a read lock on the vnode here? */
2880 #if !defined(AFS_OSF_ENV) && !defined(AFS_DARWIN80_ENV)
2881 osi_vnhold(tvc, retry); /* already held, above */
2882 if (retry && *retry)
2885 #if defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)
2886 tvc->states |= CUBCinit;
2888 if (UBCINFOMISSING(AFSTOV(tvc)) ||
2889 UBCINFORECLAIMED(AFSTOV(tvc))) {
2890 ubc_info_init(AFSTOV(tvc));
2893 tvc->states &= ~CUBCinit;
2896 * only move to front of vlru if we have proper vcache locking)
2898 if (flag & DO_VLRU) {
2899 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2900 refpanic("FindVC VLRU inconsistent1");
2902 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2903 refpanic("FindVC VLRU inconsistent1");
2905 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2906 refpanic("FindVC VLRU inconsistent2");
2908 UpgradeSToWLock(&afs_xvcache, 26);
2909 QRemove(&tvc->vlruq);
2910 QAdd(&VLRU, &tvc->vlruq);
2911 ConvertWToSLock(&afs_xvcache);
2912 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2913 refpanic("FindVC VLRU inconsistent1");
2915 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2916 refpanic("FindVC VLRU inconsistent2");
2918 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2919 refpanic("FindVC VLRU inconsistent3");
2925 if (flag & DO_STATS) {
2927 afs_stats_cmperf.vcacheHits++;
2929 afs_stats_cmperf.vcacheMisses++;
2930 if (afs_IsPrimaryCellNum(afid->Cell))
2931 afs_stats_cmperf.vlocalAccesses++;
2933 afs_stats_cmperf.vremoteAccesses++;
2936 } /*afs_FindVCache */
2942 * Find a vcache entry given a fid. Does a wildcard match on what we
2943 * have for the fid. If more than one entry, don't return anything.
2946 * avcp : Fill in pointer if we found one and only one.
2947 * afid : Pointer to the fid whose cache entry we desire.
2948 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2949 * unlock the vnode, and try again.
2950 * flags: bit 1 to specify whether to compute hit statistics. Not
2951 * set if FindVCache is called as part of internal bookkeeping.
2954 * Must be called with the afs_xvcache lock at least held at
2955 * the read level. In order to do the VLRU adjustment, the xvcache lock
2956 * must be shared-- we upgrade it here.
2959 * number of matches found.
2962 int afs_duplicate_nfs_fids = 0;
2965 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2967 register struct vcache *tvc;
2969 afs_int32 count = 0;
2970 struct vcache *found_tvc = NULL;
2974 #ifdef AFS_DARWIN80_ENV
2978 AFS_STATCNT(afs_FindVCache);
2982 ObtainSharedLock(&afs_xvcache, 331);
2985 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2986 /* Match only on what we have.... */
2987 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2988 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2989 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2990 && (tvc->fid.Cell == afid->Cell)) {
2991 if (tvc->states & CVInit) {
2992 ReleaseSharedLock(&afs_xvcache);
2993 afs_osi_Sleep(&tvc->states);
2997 /* Grab this vnode, possibly reactivating from the free list */
2999 vg = vget(AFSTOV(tvc));
3002 /* This vnode no longer exists. */
3005 #endif /* AFS_OSF_ENV */
3006 #ifdef AFS_DARWIN80_ENV
3007 if (tvc->states & CDeadVnode) {
3008 ReleaseSharedLock(&afs_xvcache);
3009 afs_osi_Sleep(&tvc->states);
3013 if (vnode_get(tvp)) {
3014 /* This vnode no longer exists. */
3017 if (vnode_ref(tvp)) {
3018 /* This vnode no longer exists. */
3020 /* AFSTOV(tvc) may be NULL */
3025 #endif /* AFS_DARWIN80_ENV */
3030 /* Drop our reference counts. */
3032 vrele(AFSTOV(found_tvc));
3034 afs_duplicate_nfs_fids++;
3035 ReleaseSharedLock(&afs_xvcache);
3036 #ifdef AFS_DARWIN80_ENV
3037 /* Drop our reference counts. */
3038 vnode_put(AFSTOV(tvc));
3039 vnode_put(AFSTOV(found_tvc));
3048 /* should I have a read lock on the vnode here? */
3050 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
3051 afs_int32 retry = 0;
3052 osi_vnhold(tvc, &retry);
3055 found_tvc = (struct vcache *)0;
3056 ReleaseSharedLock(&afs_xvcache);
3057 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
3061 #if !defined(AFS_OSF_ENV)
3062 osi_vnhold(tvc, (int *)0); /* already held, above */
3066 * We obtained the xvcache lock above.
3068 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
3069 refpanic("FindVC VLRU inconsistent1");
3071 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
3072 refpanic("FindVC VLRU inconsistent1");
3074 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
3075 refpanic("FindVC VLRU inconsistent2");
3077 UpgradeSToWLock(&afs_xvcache, 568);
3078 QRemove(&tvc->vlruq);
3079 QAdd(&VLRU, &tvc->vlruq);
3080 ConvertWToSLock(&afs_xvcache);
3081 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
3082 refpanic("FindVC VLRU inconsistent1");
3084 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
3085 refpanic("FindVC VLRU inconsistent2");
3087 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
3088 refpanic("FindVC VLRU inconsistent3");
3094 afs_stats_cmperf.vcacheHits++;
3096 afs_stats_cmperf.vcacheMisses++;
3097 if (afs_IsPrimaryCellNum(afid->Cell))
3098 afs_stats_cmperf.vlocalAccesses++;
3100 afs_stats_cmperf.vremoteAccesses++;
3102 *avcp = tvc; /* May be null */
3104 ReleaseSharedLock(&afs_xvcache);
3105 return (tvc ? 1 : 0);
3107 } /*afs_NFSFindVCache */
3115 * Initialize vcache related variables
3118 afs_vcacheInit(int astatSize)
3120 register struct vcache *tvp;
3122 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
3123 if (!afs_maxvcount) {
3124 #if defined(AFS_LINUX22_ENV)
3125 afs_maxvcount = astatSize; /* no particular limit on linux? */
3126 #elif defined(AFS_OSF30_ENV)
3127 afs_maxvcount = max_vnodes / 2; /* limit ourselves to half the total */
3129 afs_maxvcount = nvnode / 2; /* limit ourselves to half the total */
3131 if (astatSize < afs_maxvcount) {
3132 afs_maxvcount = astatSize;
3135 #else /* AFS_OSF_ENV */
3139 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3140 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3142 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
3143 /* Allocate and thread the struct vcache entries */
3144 tvp = (struct vcache *)afs_osi_Alloc(astatSize * sizeof(struct vcache));
3145 memset((char *)tvp, 0, sizeof(struct vcache) * astatSize);
3147 Initial_freeVCList = tvp;
3148 freeVCList = &(tvp[0]);
3149 for (i = 0; i < astatSize - 1; i++) {
3150 tvp[i].nextfree = &(tvp[i + 1]);
3152 tvp[astatSize - 1].nextfree = NULL;
3153 #ifdef KERNEL_HAVE_PIN
3154 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
3158 #if defined(AFS_SGI_ENV)
3159 for (i = 0; i < astatSize; i++) {
3160 char name[METER_NAMSZ];
3161 struct vcache *tvc = &tvp[i];
3163 tvc->v.v_number = ++afsvnumbers;
3164 tvc->vc_rwlockid = OSI_NO_LOCKID;
3165 initnsema(&tvc->vc_rwlock, 1,
3166 makesname(name, "vrw", tvc->v.v_number));
3167 #ifndef AFS_SGI53_ENV
3168 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
3170 #ifndef AFS_SGI62_ENV
3171 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
3172 #endif /* AFS_SGI62_ENV */
3176 for(i = 0; i < VCSIZE; ++i)
3177 QInit(&afs_vhashTV[i]);
3185 shutdown_vcache(void)
3188 struct afs_cbr *tsp, *nsp;
3190 * XXX We may potentially miss some of the vcaches because if when there're no
3191 * free vcache entries and all the vcache entries are active ones then we allocate
3192 * an additional one - admittedly we almost never had that occur.
3196 register struct afs_q *tq, *uq;
3197 register struct vcache *tvc;
3198 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
3202 osi_FreeSmallSpace(tvc->mvid);
3203 tvc->mvid = (struct VenusFid *)0;
3206 aix_gnode_rele(AFSTOV(tvc));
3208 if (tvc->linkData) {
3209 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3214 * Also free the remaining ones in the Cache
3216 for (i = 0; i < VCSIZE; i++) {
3217 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3219 osi_FreeSmallSpace(tvc->mvid);
3220 tvc->mvid = (struct VenusFid *)0;
3224 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
3225 #ifdef AFS_AIX32_ENV
3228 vms_delete(tvc->segid);
3230 tvc->segid = tvc->vmh = NULL;
3231 if (VREFCOUNT_GT(tvc,0))
3232 osi_Panic("flushVcache: vm race");
3240 #if defined(AFS_SUN5_ENV)
3246 if (tvc->linkData) {
3247 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
3251 afs_FreeAllAxs(&(tvc->Access));
3257 * Free any leftover callback queue
3259 for (tsp = afs_cbrSpace; tsp; tsp = nsp) {
3261 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
3265 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
3266 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3268 #ifdef KERNEL_HAVE_PIN
3269 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
3272 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
3273 freeVCList = Initial_freeVCList = 0;
3275 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
3276 LOCK_INIT(&afs_xvcb, "afs_xvcb");
3278 for(i = 0; i < VCSIZE; ++i)
3279 QInit(&afs_vhashTV[i]);
3282 #ifdef AFS_DISCON_ENV
3283 void afs_DisconGiveUpCallbacks() {
3288 ObtainWriteLock(&afs_xvcache, 1002); /* XXX - should be a unique number */
3290 /* Somehow, walk the set of vcaches, with each one coming out as tvc */
3291 for (i = 0; i < VCSIZE; i++) {
3292 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
3293 if ((tvc->states & CRO) == 0 && tvc->callback) {
3294 /* XXX - should we check if the callback has expired here? */
3296 tvc->callback = NULL;
3297 tvc->states &- ~(CStatd | CUnique);
3302 /*printf("%d callbacks to be discarded. queued ... ", nq);*/
3305 ReleaseWriteLock(&afs_xvcache);
3306 /*printf("gone\n");*/