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
38 #include <afsconfig.h>
39 #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 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
51 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
52 afs_int32 afs_vcount = 0; /* number of vcache in use now */
53 #endif /* AFS_OSF_ENV */
61 #endif /* AFS_SGI64_ENV */
63 /* Exported variables */
64 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries */
65 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks */
66 #if !defined(AFS_LINUX22_ENV)
67 static struct vcache *freeVCList; /*Free list for stat cache entries */
68 static struct vcache *Initial_freeVCList; /*Initial list for above */
70 struct afs_q VLRU; /*vcache LRU */
71 afs_int32 vcachegen = 0;
72 unsigned int afs_paniconwarn = 0;
73 struct vcache *afs_vhashT[VCSIZE];
74 struct afs_q afs_vhashTV[VCSIZE];
75 static struct afs_cbr *afs_cbrHashT[CBRSIZE];
76 afs_int32 afs_bulkStatsLost;
77 int afs_norefpanic = 0;
79 /* Forward declarations */
80 static afs_int32 afs_QueueVCB(struct vcache *avc);
85 * Generate an index into the hash table for a given Fid.
88 afs_HashCBRFid(struct AFSFid *fid)
90 return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE;
96 * Insert a CBR entry into the hash table.
97 * Must be called with afs_xvcb held.
100 afs_InsertHashCBR(struct afs_cbr *cbr)
102 int slot = afs_HashCBRFid(&cbr->fid);
104 cbr->hash_next = afs_cbrHashT[slot];
105 if (afs_cbrHashT[slot])
106 afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next;
108 cbr->hash_pprev = &afs_cbrHashT[slot];
109 afs_cbrHashT[slot] = cbr;
116 * Flush the given vcache entry.
119 * avc : Pointer to vcache entry to flush.
120 * slept : Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
123 * afs_xvcache lock must be held for writing upon entry to
124 * prevent people from changing the vrefCount field, and to
125 * protect the lruq and hnext fields.
126 * LOCK: afs_FlushVCache afs_xvcache W
127 * REFCNT: vcache ref count must be zero on entry except for osf1
128 * RACE: lock is dropped and reobtained, permitting race in caller
132 afs_FlushVCache(struct vcache *avc, int *slept)
133 { /*afs_FlushVCache */
136 struct vcache **uvc, *wvc;
139 AFS_STATCNT(afs_FlushVCache);
140 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
141 ICL_TYPE_INT32, avc->states);
144 VN_LOCK(AFSTOV(avc));
148 code = osi_VM_FlushVCache(avc, slept);
152 if (avc->states & CVFlushed) {
156 #if !defined(AFS_LINUX22_ENV)
157 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
158 refpanic("LRU vs. Free inconsistency");
161 avc->states |= CVFlushed;
162 /* pull the entry out of the lruq and put it on the free list */
163 QRemove(&avc->vlruq);
164 avc->vlruq.prev = avc->vlruq.next = (struct afs_q *)0;
166 /* keep track of # of files that we bulk stat'd, but never used
167 * before they got recycled.
169 if (avc->states & CBulkStat)
172 /* remove entry from the hash chain */
173 i = VCHash(&avc->fid);
174 uvc = &afs_vhashT[i];
175 for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
178 avc->hnext = (struct vcache *)NULL;
183 /* remove entry from the volume hash table */
184 QRemove(&avc->vhashq);
187 osi_FreeSmallSpace(avc->mvid);
188 avc->mvid = (struct VenusFid *)0;
190 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
191 avc->linkData = NULL;
193 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
194 /* OK, there are no internal vrefCounts, so there shouldn't
195 * be any more refs here. */
197 avc->v->v_data = NULL; /* remove from vnode */
198 avc->v = NULL; /* also drop the ptr to vnode */
201 afs_FreeAllAxs(&(avc->Access));
203 /* we can't really give back callbacks on RO files, since the
204 * server only tracks them on a per-volume basis, and we don't
205 * know whether we still have some other files from the same
207 if ((avc->states & CRO) == 0 && avc->callback) {
210 ObtainWriteLock(&afs_xcbhash, 460);
211 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
212 avc->states &= ~(CStatd | CUnique);
213 ReleaseWriteLock(&afs_xcbhash);
214 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
215 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
217 osi_dnlc_purgevp(avc);
220 * Next, keep track of which vnodes we've deleted for create's
221 * optimistic synchronization algorithm
224 if (avc->fid.Fid.Vnode & 1)
229 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
230 /* put the entry in the free list */
231 avc->nextfree = freeVCList;
233 if (avc->vlruq.prev || avc->vlruq.next) {
234 refpanic("LRU vs. Free inconsistency");
236 avc->states |= CVFlushed;
238 /* This should put it back on the vnode free list since usecount is 1 */
241 if (VREFCOUNT(avc) > 0) {
242 #if defined(AFS_OSF_ENV)
243 VN_UNLOCK(AFSTOV(avc));
245 AFS_RELE(AFSTOV(avc));
247 if (afs_norefpanic) {
248 printf("flush vc refcnt < 1");
250 #if defined(AFS_OSF_ENV)
251 (void)vgone(avc, VX_NOSLEEP, NULL);
253 VN_UNLOCK(AFSTOV(avc));
256 osi_Panic("flush vc refcnt < 1");
258 #endif /* AFS_OSF_ENV */
263 VN_UNLOCK(AFSTOV(avc));
267 } /*afs_FlushVCache */
273 * The core of the inactive vnode op for all but IRIX.
276 afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred)
278 AFS_STATCNT(afs_inactive);
279 if (avc->states & CDirty) {
280 /* we can't keep trying to push back dirty data forever. Give up. */
281 afs_InvalidateAllSegments(avc); /* turns off dirty bit */
283 avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
284 avc->states &= ~CDirty; /* Turn it off */
285 if (avc->states & CUnlinked) {
286 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
287 avc->states |= CUnlinkedDel;
290 afs_remunlink(avc, 1); /* ignore any return code */
299 * Description: allocate a callback return structure from the
300 * free list and return it.
302 * Env: The alloc and free routines are both called with the afs_xvcb lock
303 * held, so we don't have to worry about blocking in osi_Alloc.
305 static struct afs_cbr *afs_cbrSpace = 0;
309 register struct afs_cbr *tsp;
312 while (!afs_cbrSpace) {
313 if (afs_stats_cmperf.CallBackAlloced >= 2) {
314 /* don't allocate more than 2 * AFS_NCBRS for now */
316 afs_stats_cmperf.CallBackFlushes++;
320 (struct afs_cbr *)afs_osi_Alloc(AFS_NCBRS *
321 sizeof(struct afs_cbr));
322 for (i = 0; i < AFS_NCBRS - 1; i++) {
323 tsp[i].next = &tsp[i + 1];
325 tsp[AFS_NCBRS - 1].next = 0;
327 afs_stats_cmperf.CallBackAlloced++;
331 afs_cbrSpace = tsp->next;
338 * Description: free a callback return structure, removing it from all lists.
341 * asp -- the address of the structure to free.
343 * Environment: the xvcb lock is held over these calls.
346 afs_FreeCBR(register struct afs_cbr *asp)
348 *(asp->pprev) = asp->next;
350 asp->next->pprev = asp->pprev;
352 *(asp->hash_pprev) = asp->hash_next;
354 asp->hash_next->hash_pprev = asp->hash_pprev;
356 asp->next = afs_cbrSpace;
364 * Description: flush all queued callbacks to all servers.
368 * Environment: holds xvcb lock over RPC to guard against race conditions
369 * when a new callback is granted for the same file later on.
372 afs_FlushVCBs(afs_int32 lockit)
374 struct AFSFid *tfids;
375 struct AFSCallBack callBacks[1];
376 struct AFSCBFids fidArray;
377 struct AFSCBs cbArray;
379 struct afs_cbr *tcbrp;
383 struct vrequest treq;
385 int safety1, safety2, safety3;
387 if ((code = afs_InitReq(&treq, afs_osi_credp)))
389 treq.flags |= O_NONBLOCK;
390 tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
393 MObtainWriteLock(&afs_xvcb, 273);
394 ObtainReadLock(&afs_xserver);
395 for (i = 0; i < NSERVERS; i++) {
396 for (safety1 = 0, tsp = afs_servers[i];
397 tsp && safety1 < afs_totalServers + 10;
398 tsp = tsp->next, safety1++) {
400 if (tsp->cbrs == (struct afs_cbr *)0)
403 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
404 * and make an RPC, over and over again.
406 tcount = 0; /* number found so far */
407 for (safety2 = 0; safety2 < afs_cacheStats; safety2++) {
408 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
409 /* if buffer is full, or we've queued all we're going
410 * to from this server, we should flush out the
413 fidArray.AFSCBFids_len = tcount;
414 fidArray.AFSCBFids_val = (struct AFSFid *)tfids;
415 cbArray.AFSCBs_len = 1;
416 cbArray.AFSCBs_val = callBacks;
417 memset(&callBacks[0], 0, sizeof(callBacks[0]));
418 callBacks[0].CallBackType = CB_EXCLUSIVE;
419 for (safety3 = 0; safety3 < MAXHOSTS * 2; safety3++) {
420 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
421 tsp->cell->cellNum, &treq, 0,
425 (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
428 RXAFS_GiveUpCallBacks(tc->id, &fidArray,
436 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK,
441 /* ignore return code, since callbacks may have
442 * been returned anyway, we shouldn't leave them
443 * around to be returned again.
445 * Next, see if we are done with this server, and if so,
446 * break to deal with the next one.
452 /* if to flush full buffer */
453 /* if we make it here, we have an entry at the head of cbrs,
454 * which we should copy to the file ID array and then free.
457 tfids[tcount++] = tcbrp->fid;
459 /* Freeing the CBR will unlink it from the server's CBR list */
461 } /* while loop for this one server */
462 if (safety2 > afs_cacheStats) {
463 afs_warn("possible internal error afs_flushVCBs (%d)\n",
466 } /* for loop for this hash chain */
467 } /* loop through all hash chains */
468 if (safety1 > afs_totalServers + 2) {
470 ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n",
471 safety1, afs_totalServers + 2);
473 osi_Panic("afs_flushVCBS safety1");
476 ReleaseReadLock(&afs_xserver);
478 MReleaseWriteLock(&afs_xvcb);
479 afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
487 * Queue a callback on the given fid.
493 * Locks the xvcb lock.
494 * Called when the xvcache lock is already held.
498 afs_QueueVCB(struct vcache *avc)
501 struct afs_cbr *tcbp;
503 AFS_STATCNT(afs_QueueVCB);
504 /* The callback is really just a struct server ptr. */
505 tsp = (struct server *)(avc->callback);
507 /* we now have a pointer to the server, so we just allocate
508 * a queue entry and queue it.
510 MObtainWriteLock(&afs_xvcb, 274);
511 tcbp = afs_AllocCBR();
512 tcbp->fid = avc->fid.Fid;
514 tcbp->next = tsp->cbrs;
516 tsp->cbrs->pprev = &tcbp->next;
519 tcbp->pprev = &tsp->cbrs;
521 afs_InsertHashCBR(tcbp);
523 /* now release locks and return */
524 MReleaseWriteLock(&afs_xvcb);
533 * Remove a queued callback for a given Fid.
536 * afid: The fid we want cleansed of queued callbacks.
539 * Locks xvcb and xserver locks.
540 * Typically called with xdcache, xvcache and/or individual vcache
545 afs_RemoveVCB(struct VenusFid *afid)
548 struct afs_cbr *cbr, *ncbr;
550 AFS_STATCNT(afs_RemoveVCB);
551 MObtainWriteLock(&afs_xvcb, 275);
553 slot = afs_HashCBRFid(&afid->Fid);
554 ncbr = afs_cbrHashT[slot];
558 ncbr = cbr->hash_next;
560 if (afid->Fid.Volume == cbr->fid.Volume &&
561 afid->Fid.Vnode == cbr->fid.Vnode &&
562 afid->Fid.Unique == cbr->fid.Unique) {
567 MReleaseWriteLock(&afs_xvcb);
574 * This routine is responsible for allocating a new cache entry
575 * from the free list. It formats the cache entry and inserts it
576 * into the appropriate hash tables. It must be called with
577 * afs_xvcache write-locked so as to prevent several processes from
578 * trying to create a new cache entry simultaneously.
581 * afid : The file id of the file whose cache entry is being
584 /* LOCK: afs_NewVCache afs_xvcache W */
586 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
590 afs_int32 anumber = VCACHE_FREE;
592 struct gnode *gnodepnt;
596 #endif /* AFS_OSF_ENV */
597 struct afs_q *tq, *uq;
600 AFS_STATCNT(afs_NewVCache);
601 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
602 #if defined(AFS_OSF30_ENV) || defined(AFS_LINUX22_ENV)
603 if (afs_vcount >= afs_maxvcount)
606 * If we are using > 33 % of the total system vnodes for AFS vcache
607 * entries or we are using the maximum number of vcache entries,
608 * then free some. (if our usage is > 33% we should free some, if
609 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
610 * we _must_ free some -- no choice).
612 if (((3 * afs_vcount) > nvnode) || (afs_vcount >= afs_maxvcount))
619 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
622 if (tvc->states & CVFlushed) {
623 refpanic("CVFlushed on VLRU");
624 } else if (i++ > afs_maxvcount) {
625 refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)");
626 } else if (QNext(uq) != tq) {
627 refpanic("VLRU inconsistent");
628 } else if (VREFCOUNT(tvc) < 1) {
629 refpanic("refcnt 0 on VLRU");
632 #if defined(AFS_LINUX22_ENV)
633 if (tvc != afs_globalVp && VREFCOUNT(tvc) > 1 && tvc->opens == 0) {
634 struct dentry *dentry;
635 struct list_head *cur, *head;
638 #if defined(AFS_LINUX24_ENV)
639 spin_lock(&dcache_lock);
641 head = &(AFSTOV(tvc))->i_dentry;
645 while ((cur = cur->next) != head) {
646 dentry = list_entry(cur, struct dentry, d_alias);
648 if (d_unhashed(dentry))
653 #if defined(AFS_LINUX24_ENV)
654 spin_unlock(&dcache_lock);
656 if (d_invalidate(dentry) == -EBUSY) {
658 /* perhaps lock and try to continue? (use cur as head?) */
662 #if defined(AFS_LINUX24_ENV)
663 spin_lock(&dcache_lock);
667 #if defined(AFS_LINUX24_ENV)
668 spin_unlock(&dcache_lock);
676 if (VREFCOUNT(tvc) == 1 && tvc->opens == 0
677 && (tvc->states & CUnlinkedDel) == 0) {
678 code = afs_FlushVCache(tvc, &fv_slept);
685 continue; /* start over - may have raced. */
691 if (anumber == VCACHE_FREE) {
692 printf("NewVCache: warning none freed, using %d of %d\n",
693 afs_vcount, afs_maxvcount);
694 if (afs_vcount >= afs_maxvcount) {
695 osi_Panic("NewVCache - none freed");
696 /* XXX instead of panicing, should do afs_maxvcount++
697 * and magic up another one */
702 #if defined(AFS_LINUX22_ENV)
707 ip = new_inode(afs_globalVFS);
709 osi_Panic("afs_NewVCache: no more inodes");
711 #if defined(STRUCT_SUPER_HAS_ALLOC_INODE)
714 tvc = afs_osi_Alloc(sizeof(struct vcache));
715 ip->u.generic_ip = tvc;
721 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
722 /* What should we do ???? */
723 osi_Panic("afs_NewVCache: no more vnodes");
728 tvc->nextfree = NULL;
731 #else /* AFS_OSF_ENV */
732 /* pull out a free cache entry */
735 for (tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
739 if (tvc->states & CVFlushed) {
740 refpanic("CVFlushed on VLRU");
742 } else if (i++ > 2 * afs_cacheStats) { /* even allowing for a few xallocs... */
743 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
745 } else if (QNext(uq) != tq) {
746 refpanic("VLRU inconsistent");
749 if (((VREFCOUNT(tvc) == 0)
750 #if defined(AFS_DARWIN_ENV) && !defined(UKERNEL)
751 || ((VREFCOUNT(tvc) == 1) &&
752 (UBCINFOEXISTS(AFSTOV(tvc))))
754 ) && tvc->opens == 0 && (tvc->states & CUnlinkedDel) == 0) {
755 #if defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
757 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
758 * then it puts the vnode on the free list.
759 * If we don't do this we end up with a cleaned vnode that's
760 * not on the free list.
761 * XXX assume FreeBSD is the same for now.
768 code = afs_FlushVCache(tvc, &fv_slept);
776 continue; /* start over - may have raced. */
784 /* none free, making one is better than a panic */
785 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
786 if (afs_cacheStats == afs_stats_cmperf.vcacheXAllocs) printf("would vlru cycle panic\n");
787 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
788 #if defined(AFS_DARWIN_ENV) && !defined(UKERNEL)
789 tvc->v = NULL; /* important to clean this, or use memset 0 */
791 #ifdef KERNEL_HAVE_PIN
792 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
794 #if defined(AFS_SGI_ENV)
796 char name[METER_NAMSZ];
797 memset(tvc, 0, sizeof(struct vcache));
798 tvc->v.v_number = ++afsvnumbers;
799 tvc->vc_rwlockid = OSI_NO_LOCKID;
800 initnsema(&tvc->vc_rwlock, 1,
801 makesname(name, "vrw", tvc->v.v_number));
802 #ifndef AFS_SGI53_ENV
803 initnsema(&tvc->v.v_sync, 0,
804 makesname(name, "vsy", tvc->v.v_number));
806 #ifndef AFS_SGI62_ENV
807 initnlock(&tvc->v.v_lock,
808 makesname(name, "vlk", tvc->v.v_number));
811 #endif /* AFS_SGI_ENV */
813 tvc = freeVCList; /* take from free list */
814 freeVCList = tvc->nextfree;
815 tvc->nextfree = NULL;
817 #endif /* AFS_OSF_ENV */
819 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
821 panic("afs_NewVCache(): free vcache with vnode attached");
824 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
825 memset((char *)tvc, 0, sizeof(struct vcache));
830 RWLOCK_INIT(&tvc->lock, "vcache lock");
831 #if defined(AFS_SUN5_ENV)
832 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
833 #endif /* defined(AFS_SUN5_ENV) */
837 afs_nbsd_getnewvnode(tvc); /* includes one refcount */
839 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
841 #ifdef AFS_DARWIN_ENV
843 afs_darwin_getnewvnode(tvc); /* includes one refcount */
845 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
852 #if defined(AFS_FBSD60_ENV)
853 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
854 #elif defined(AFS_FBSD50_ENV)
855 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
857 if (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
859 panic("afs getnewvnode"); /* can't happen */
861 if (tvc->v != NULL) {
862 /* I'd like to know if this ever happens...
863 * We don't drop global for the rest of this function,
864 * so if we do lose the race, the other thread should
865 * have found the same vnode and finished initializing
866 * the vcache entry. Is it conceivable that this vcache
867 * entry could be recycled during this interval? If so,
868 * then there probably needs to be some sort of additional
869 * mutual exclusion (an Embryonic flag would suffice).
871 printf("afs_NewVCache: lost the race\n");
875 tvc->v->v_data = tvc;
876 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
879 tvc->parentVnode = 0;
881 tvc->linkData = NULL;
884 tvc->execsOrWriters = 0;
888 tvc->last_looker = 0;
890 tvc->asynchrony = -1;
893 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
896 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
897 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
899 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
900 /* Hold it for the LRU (should make count 2) */
901 VN_HOLD(AFSTOV(tvc));
902 #else /* AFS_OSF_ENV */
903 #if !(defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV))
904 VREFCOUNT_SET(tvc, 1); /* us */
905 #endif /* AFS_XBSD_ENV */
906 #endif /* AFS_OSF_ENV */
908 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
909 tvc->vmh = tvc->segid = NULL;
912 #ifdef AFS_BOZONLOCK_ENV
913 #if defined(AFS_SUN5_ENV)
914 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
916 #if defined(AFS_SUN55_ENV)
917 /* This is required if the kaio (kernel aynchronous io)
918 ** module is installed. Inside the kernel, the function
919 ** check_vp( common/os/aio.c) checks to see if the kernel has
920 ** to provide asynchronous io for this vnode. This
921 ** function extracts the device number by following the
922 ** v_data field of the vnode. If we do not set this field
923 ** then the system panics. The value of the v_data field
924 ** is not really important for AFS vnodes because the kernel
925 ** does not do asynchronous io for regular files. Hence,
926 ** for the time being, we fill up the v_data field with the
927 ** vnode pointer itself. */
928 tvc->v.v_data = (char *)tvc;
929 #endif /* AFS_SUN55_ENV */
931 afs_BozonInit(&tvc->pvnLock, tvc);
935 tvc->callback = serverp; /* to minimize chance that clear
937 /* initialize vnode data, note vrefCount is v.v_count */
939 /* Don't forget to free the gnode space */
940 tvc->v.v_gnode = gnodepnt =
941 (struct gnode *)osi_AllocSmallSpace(sizeof(struct gnode));
942 memset((char *)gnodepnt, 0, sizeof(struct gnode));
945 memset((void *)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc));
946 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
948 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
949 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
951 bhv_head_init(&(tvc->v.v_bh));
952 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
955 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion *)tvc;
957 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
959 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
961 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
962 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
964 vnode_pcache_init(&tvc->v);
965 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
966 /* Above define is never true execpt in SGI test kernels. */
967 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
970 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
973 SetAfsVnode(AFSTOV(tvc));
974 #endif /* AFS_SGI64_ENV */
976 * The proper value for mvstat (for root fids) is setup by the caller.
979 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
981 if (afs_globalVFS == 0)
982 osi_Panic("afs globalvfs");
983 #if !defined(AFS_LINUX22_ENV)
984 vSetVfsp(tvc, afs_globalVFS);
988 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
989 tvc->v.v_vfsprev = NULL;
990 afs_globalVFS->vfs_vnodes = &tvc->v;
991 if (tvc->v.v_vfsnext != NULL)
992 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
993 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us! */
994 gnodepnt->gn_vnode = &tvc->v;
996 #if defined(AFS_DUX40_ENV)
997 insmntque(tvc, afs_globalVFS, &afs_ubcops);
1000 /* Is this needed??? */
1001 insmntque(tvc, afs_globalVFS);
1002 #endif /* AFS_OSF_ENV */
1003 #endif /* AFS_DUX40_ENV */
1004 #if defined(AFS_SGI_ENV)
1005 VN_SET_DPAGES(&(tvc->v), (struct pfdat *)NULL);
1006 osi_Assert((tvc->v.v_flag & VINACT) == 0);
1008 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
1009 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
1010 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
1011 osi_Assert(tvc->v.v_filocks == NULL);
1012 #if !defined(AFS_SGI65_ENV)
1013 osi_Assert(tvc->v.v_filocksem == NULL);
1015 osi_Assert(tvc->cred == NULL);
1016 #ifdef AFS_SGI64_ENV
1017 vnode_pcache_reinit(&tvc->v);
1018 tvc->v.v_rdev = NODEV;
1020 vn_initlist((struct vnlist *)&tvc->v);
1022 #endif /* AFS_SGI_ENV */
1024 osi_dnlc_purgedp(tvc); /* this may be overkill */
1025 memset((char *)&(tvc->callsort), 0, sizeof(struct afs_q));
1030 tvc->hnext = afs_vhashT[i];
1031 afs_vhashT[i] = tvc;
1032 QAdd(&afs_vhashTV[i], &tvc->vhashq);
1034 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1035 refpanic("NewVCache VLRU inconsistent");
1037 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
1038 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1039 refpanic("NewVCache VLRU inconsistent2");
1041 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1042 refpanic("NewVCache VLRU inconsistent3");
1044 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1045 refpanic("NewVCache VLRU inconsistent4");
1051 } /*afs_NewVCache */
1055 * afs_FlushActiveVcaches
1061 * doflocks : Do we handle flocks?
1063 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1065 afs_FlushActiveVcaches(register afs_int32 doflocks)
1067 register struct vcache *tvc;
1069 register struct conn *tc;
1070 register afs_int32 code;
1071 register struct AFS_UCRED *cred = NULL;
1072 struct vrequest treq, ureq;
1073 struct AFSVolSync tsync;
1076 AFS_STATCNT(afs_FlushActiveVcaches);
1077 ObtainReadLock(&afs_xvcache);
1078 for (i = 0; i < VCSIZE; i++) {
1079 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1080 if (doflocks && tvc->flockCount != 0) {
1081 /* if this entry has an flock, send a keep-alive call out */
1083 ReleaseReadLock(&afs_xvcache);
1084 ObtainWriteLock(&tvc->lock, 51);
1086 afs_InitReq(&treq, afs_osi_credp);
1087 treq.flags |= O_NONBLOCK;
1089 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1091 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1094 RXAFS_ExtendLock(tc->id,
1095 (struct AFSFid *)&tvc->fid.Fid,
1101 } while (afs_Analyze
1102 (tc, code, &tvc->fid, &treq,
1103 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1105 ReleaseWriteLock(&tvc->lock);
1106 ObtainReadLock(&afs_xvcache);
1110 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1112 * Don't let it evaporate in case someone else is in
1113 * this code. Also, drop the afs_xvcache lock while
1114 * getting vcache locks.
1117 ReleaseReadLock(&afs_xvcache);
1118 #ifdef AFS_BOZONLOCK_ENV
1119 afs_BozonLock(&tvc->pvnLock, tvc);
1121 #if defined(AFS_SGI_ENV)
1123 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1125 osi_Assert(VREFCOUNT(tvc) > 0);
1126 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1128 ObtainWriteLock(&tvc->lock, 52);
1129 if (tvc->states & CCore) {
1130 tvc->states &= ~CCore;
1131 /* XXXX Find better place-holder for cred XXXX */
1132 cred = (struct AFS_UCRED *)tvc->linkData;
1133 tvc->linkData = NULL; /* XXX */
1134 afs_InitReq(&ureq, cred);
1135 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1136 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1137 tvc->execsOrWriters);
1138 code = afs_StoreOnLastReference(tvc, &ureq);
1139 ReleaseWriteLock(&tvc->lock);
1140 #ifdef AFS_BOZONLOCK_ENV
1141 afs_BozonUnlock(&tvc->pvnLock, tvc);
1143 hzero(tvc->flushDV);
1146 if (code && code != VNOVNODE) {
1147 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1148 /* /dev/console */ 1);
1150 } else if (tvc->states & CUnlinkedDel) {
1154 ReleaseWriteLock(&tvc->lock);
1155 #ifdef AFS_BOZONLOCK_ENV
1156 afs_BozonUnlock(&tvc->pvnLock, tvc);
1158 #if defined(AFS_SGI_ENV)
1159 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1161 afs_remunlink(tvc, 0);
1162 #if defined(AFS_SGI_ENV)
1163 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1166 /* lost (or won, perhaps) the race condition */
1167 ReleaseWriteLock(&tvc->lock);
1168 #ifdef AFS_BOZONLOCK_ENV
1169 afs_BozonUnlock(&tvc->pvnLock, tvc);
1172 #if defined(AFS_SGI_ENV)
1173 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1175 ObtainReadLock(&afs_xvcache);
1178 AFS_RELE(AFSTOV(tvc));
1179 /* Matches write code setting CCore flag */
1185 ReleaseReadLock(&afs_xvcache);
1193 * Make sure a cache entry is up-to-date status-wise.
1195 * NOTE: everywhere that calls this can potentially be sped up
1196 * by checking CStatd first, and avoiding doing the InitReq
1197 * if this is up-to-date.
1199 * Anymore, the only places that call this KNOW already that the
1200 * vcache is not up-to-date, so we don't screw around.
1203 * avc : Ptr to vcache entry to verify.
1208 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1210 register struct vcache *tvc;
1212 AFS_STATCNT(afs_VerifyVCache);
1214 #if defined(AFS_OSF_ENV)
1215 ObtainReadLock(&avc->lock);
1216 if (afs_IsWired(avc)) {
1217 ReleaseReadLock(&avc->lock);
1220 ReleaseReadLock(&avc->lock);
1221 #endif /* AFS_OSF_ENV */
1222 /* otherwise we must fetch the status info */
1224 ObtainWriteLock(&avc->lock, 53);
1225 if (avc->states & CStatd) {
1226 ReleaseWriteLock(&avc->lock);
1229 ObtainWriteLock(&afs_xcbhash, 461);
1230 avc->states &= ~(CStatd | CUnique);
1231 avc->callback = NULL;
1232 afs_DequeueCallback(avc);
1233 ReleaseWriteLock(&afs_xcbhash);
1234 ReleaseWriteLock(&avc->lock);
1236 /* since we've been called back, or the callback has expired,
1237 * it's possible that the contents of this directory, or this
1238 * file's name have changed, thus invalidating the dnlc contents.
1240 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1241 osi_dnlc_purgedp(avc);
1243 osi_dnlc_purgevp(avc);
1245 /* fetch the status info */
1246 tvc = afs_GetVCache(&avc->fid, areq, NULL, avc);
1249 /* Put it back; caller has already incremented vrefCount */
1253 } /*afs_VerifyVCache */
1260 * Simple copy of stat info into cache.
1263 * avc : Ptr to vcache entry involved.
1264 * astat : Ptr to stat info to copy.
1267 * Nothing interesting.
1269 * Callers: as of 1992-04-29, only called by WriteVCache
1272 afs_SimpleVStat(register struct vcache *avc,
1273 register struct AFSFetchStatus *astat, struct vrequest *areq)
1276 AFS_STATCNT(afs_SimpleVStat);
1279 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1280 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1282 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1284 #ifdef AFS_64BIT_CLIENT
1285 FillInt64(length, astat->Length_hi, astat->Length);
1286 #else /* AFS_64BIT_CLIENT */
1287 length = astat->Length;
1288 #endif /* AFS_64BIT_CLIENT */
1289 #if defined(AFS_SGI_ENV)
1290 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1291 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1292 if (length < avc->m.Length) {
1293 vnode_t *vp = (vnode_t *) avc;
1295 osi_Assert(WriteLocked(&avc->lock));
1296 ReleaseWriteLock(&avc->lock);
1298 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1300 ObtainWriteLock(&avc->lock, 67);
1303 /* if writing the file, don't fetch over this value */
1304 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1305 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1306 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1307 avc->m.Length = length;
1308 avc->m.Date = astat->ClientModTime;
1310 avc->m.Owner = astat->Owner;
1311 avc->m.Group = astat->Group;
1312 avc->m.Mode = astat->UnixModeBits;
1313 if (vType(avc) == VREG) {
1314 avc->m.Mode |= S_IFREG;
1315 } else if (vType(avc) == VDIR) {
1316 avc->m.Mode |= S_IFDIR;
1317 } else if (vType(avc) == VLNK) {
1318 avc->m.Mode |= S_IFLNK;
1319 if ((avc->m.Mode & 0111) == 0)
1322 if (avc->states & CForeign) {
1323 struct axscache *ac;
1324 avc->anyAccess = astat->AnonymousAccess;
1326 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1328 * Caller has at least one bit not covered by anonymous, and
1329 * thus may have interesting rights.
1331 * HOWEVER, this is a really bad idea, because any access query
1332 * for bits which aren't covered by anonymous, on behalf of a user
1333 * who doesn't have any special rights, will result in an answer of
1334 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1335 * It's an especially bad idea under Ultrix, since (due to the lack of
1336 * a proper access() call) it must perform several afs_access() calls
1337 * in order to create magic mode bits that vary according to who makes
1338 * the call. In other words, _every_ stat() generates a test for
1341 #endif /* badidea */
1342 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1343 ac->axess = astat->CallerAccess;
1344 else /* not found, add a new one if possible */
1345 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1349 } /*afs_SimpleVStat */
1356 * Store the status info *only* back to the server for a
1360 * avc : Ptr to the vcache entry.
1361 * astatus : Ptr to the status info to store.
1362 * areq : Ptr to the associated vrequest.
1365 * Must be called with a shared lock held on the vnode.
1369 afs_WriteVCache(register struct vcache *avc,
1370 register struct AFSStoreStatus *astatus,
1371 struct vrequest *areq)
1375 struct AFSFetchStatus OutStatus;
1376 struct AFSVolSync tsync;
1378 AFS_STATCNT(afs_WriteVCache);
1379 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1380 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length));
1383 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1385 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1388 RXAFS_StoreStatus(tc->id, (struct AFSFid *)&avc->fid.Fid,
1389 astatus, &OutStatus, &tsync);
1394 } while (afs_Analyze
1395 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1396 SHARED_LOCK, NULL));
1398 UpgradeSToWLock(&avc->lock, 20);
1400 /* success, do the changes locally */
1401 afs_SimpleVStat(avc, &OutStatus, areq);
1403 * Update the date, too. SimpleVStat didn't do this, since
1404 * it thought we were doing this after fetching new status
1405 * over a file being written.
1407 avc->m.Date = OutStatus.ClientModTime;
1409 /* failure, set up to check with server next time */
1410 ObtainWriteLock(&afs_xcbhash, 462);
1411 afs_DequeueCallback(avc);
1412 avc->states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1413 ReleaseWriteLock(&afs_xcbhash);
1414 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1415 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1417 ConvertWToSLock(&avc->lock);
1420 } /*afs_WriteVCache */
1426 * Copy astat block into vcache info
1429 * avc : Ptr to vcache entry.
1430 * astat : Ptr to stat block to copy in.
1431 * areq : Ptr to associated request.
1434 * Must be called under a write lock
1436 * Note: this code may get dataversion and length out of sync if the file has
1437 * been modified. This is less than ideal. I haven't thought about
1438 * it sufficiently to be certain that it is adequate.
1441 afs_ProcessFS(register struct vcache *avc,
1442 register struct AFSFetchStatus *astat, struct vrequest *areq)
1445 AFS_STATCNT(afs_ProcessFS);
1447 #ifdef AFS_64BIT_CLIENT
1448 FillInt64(length, astat->Length_hi, astat->Length);
1449 #else /* AFS_64BIT_CLIENT */
1450 length = astat->Length;
1451 #endif /* AFS_64BIT_CLIENT */
1452 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1453 * number for each bulk status request. Under no circumstances
1454 * should afs_DoBulkStat store a sequence number if the new
1455 * length will be ignored when afs_ProcessFS is called with
1456 * new stats. If you change the following conditional then you
1457 * also need to change the conditional in afs_DoBulkStat. */
1459 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1460 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1462 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1464 /* if we're writing or mapping this file, don't fetch over these
1467 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1468 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1469 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1470 avc->m.Length = length;
1471 avc->m.Date = astat->ClientModTime;
1473 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1474 avc->m.Owner = astat->Owner;
1475 avc->m.Mode = astat->UnixModeBits;
1476 avc->m.Group = astat->Group;
1477 avc->m.LinkCount = astat->LinkCount;
1478 if (astat->FileType == File) {
1479 vSetType(avc, VREG);
1480 avc->m.Mode |= S_IFREG;
1481 } else if (astat->FileType == Directory) {
1482 vSetType(avc, VDIR);
1483 avc->m.Mode |= S_IFDIR;
1484 } else if (astat->FileType == SymbolicLink) {
1485 if (afs_fakestat_enable && (avc->m.Mode & 0111) == 0) {
1486 vSetType(avc, VDIR);
1487 avc->m.Mode |= S_IFDIR;
1489 vSetType(avc, VLNK);
1490 avc->m.Mode |= S_IFLNK;
1492 if ((avc->m.Mode & 0111) == 0) {
1496 avc->anyAccess = astat->AnonymousAccess;
1498 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1500 * Caller has at least one bit not covered by anonymous, and
1501 * thus may have interesting rights.
1503 * HOWEVER, this is a really bad idea, because any access query
1504 * for bits which aren't covered by anonymous, on behalf of a user
1505 * who doesn't have any special rights, will result in an answer of
1506 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1507 * It's an especially bad idea under Ultrix, since (due to the lack of
1508 * a proper access() call) it must perform several afs_access() calls
1509 * in order to create magic mode bits that vary according to who makes
1510 * the call. In other words, _every_ stat() generates a test for
1513 #endif /* badidea */
1515 struct axscache *ac;
1516 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1517 ac->axess = astat->CallerAccess;
1518 else /* not found, add a new one if possible */
1519 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1521 } /*afs_ProcessFS */
1525 afs_RemoteLookup(register struct VenusFid *afid, struct vrequest *areq,
1526 char *name, struct VenusFid *nfid,
1527 struct AFSFetchStatus *OutStatusp,
1528 struct AFSCallBack *CallBackp, struct server **serverp,
1529 struct AFSVolSync *tsyncp)
1533 register struct conn *tc;
1534 struct AFSFetchStatus OutDirStatus;
1537 name = ""; /* XXX */
1539 tc = afs_Conn(afid, areq, SHARED_LOCK);
1542 *serverp = tc->srvr->server;
1544 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1547 RXAFS_Lookup(tc->id, (struct AFSFid *)&afid->Fid, name,
1548 (struct AFSFid *)&nfid->Fid, OutStatusp,
1549 &OutDirStatus, CallBackp, tsyncp);
1554 } while (afs_Analyze
1555 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1566 * Given a file id and a vrequest structure, fetch the status
1567 * information associated with the file.
1571 * areq : Ptr to associated vrequest structure, specifying the
1572 * user whose authentication tokens will be used.
1573 * avc : caller may already have a vcache for this file, which is
1577 * The cache entry is returned with an increased vrefCount field.
1578 * The entry must be discarded by calling afs_PutVCache when you
1579 * are through using the pointer to the cache entry.
1581 * You should not hold any locks when calling this function, except
1582 * locks on other vcache entries. If you lock more than one vcache
1583 * entry simultaneously, you should lock them in this order:
1585 * 1. Lock all files first, then directories.
1586 * 2. Within a particular type, lock entries in Fid.Vnode order.
1588 * This locking hierarchy is convenient because it allows locking
1589 * of a parent dir cache entry, given a file (to check its access
1590 * control list). It also allows renames to be handled easily by
1591 * locking directories in a constant order.
1592 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1594 /* might have a vcache structure already, which must
1595 * already be held by the caller */
1598 afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq,
1599 afs_int32 * cached, struct vcache *avc)
1602 afs_int32 code, newvcache = 0;
1603 register struct vcache *tvc;
1607 AFS_STATCNT(afs_GetVCache);
1610 *cached = 0; /* Init just in case */
1612 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1616 ObtainSharedLock(&afs_xvcache, 5);
1618 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU);
1620 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1621 ReleaseSharedLock(&afs_xvcache);
1622 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1630 if (tvc->states & CStatd) {
1631 ReleaseSharedLock(&afs_xvcache);
1635 UpgradeSToWLock(&afs_xvcache, 21);
1637 /* no cache entry, better grab one */
1638 tvc = afs_NewVCache(afid, NULL);
1641 ConvertWToSLock(&afs_xvcache);
1642 afs_stats_cmperf.vcacheMisses++;
1645 ReleaseSharedLock(&afs_xvcache);
1647 ObtainWriteLock(&tvc->lock, 54);
1649 if (tvc->states & CStatd) {
1650 ReleaseWriteLock(&tvc->lock);
1653 #if defined(AFS_OSF_ENV)
1654 if (afs_IsWired(tvc)) {
1655 ReleaseWriteLock(&tvc->lock);
1658 #endif /* AFS_OSF_ENV */
1659 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1661 * XXX - I really don't like this. Should try to understand better.
1662 * It seems that sometimes, when we get called, we already hold the
1663 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1664 * We can't drop the vnode lock, because that could result in a race.
1665 * Sometimes, though, we get here and don't hold the vnode lock.
1666 * I hate code paths that sometimes hold locks and sometimes don't.
1667 * In any event, the dodge we use here is to check whether the vnode
1668 * is locked, and if it isn't, then we gain and drop it around the call
1669 * to vinvalbuf; otherwise, we leave it alone.
1672 struct vnode *vp = AFSTOV(tvc);
1675 #if defined(AFS_DARWIN_ENV)
1676 iheldthelock = VOP_ISLOCKED(vp);
1678 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc());
1679 /* this is messy. we can call fsync which will try to reobtain this */
1680 if (VTOAFS(vp) == tvc)
1681 ReleaseWriteLock(&tvc->lock);
1682 if (UBCINFOEXISTS(vp)) {
1683 vinvalbuf(vp, V_SAVE, &afs_osi_cred, current_proc(), PINOD, 0);
1685 if (VTOAFS(vp) == tvc)
1686 ObtainWriteLock(&tvc->lock, 954);
1688 VOP_UNLOCK(vp, LK_EXCLUSIVE, current_proc());
1689 #elif defined(AFS_FBSD60_ENV)
1690 iheldthelock = VOP_ISLOCKED(vp, curthread);
1692 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1693 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1695 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1696 #elif defined(AFS_FBSD50_ENV)
1697 iheldthelock = VOP_ISLOCKED(vp, curthread);
1699 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1700 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1702 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1703 #elif defined(AFS_FBSD40_ENV)
1704 iheldthelock = VOP_ISLOCKED(vp, curproc);
1706 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1707 vinvalbuf(vp, V_SAVE, osi_curcred(), curproc, PINOD, 0);
1709 VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
1710 #elif defined(AFS_OBSD_ENV)
1711 iheldthelock = VOP_ISLOCKED(vp, curproc);
1713 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1714 uvm_vnp_uncache(vp);
1716 VOP_UNLOCK(vp, 0, curproc);
1721 ObtainWriteLock(&afs_xcbhash, 464);
1722 tvc->states &= ~CUnique;
1724 afs_DequeueCallback(tvc);
1725 ReleaseWriteLock(&afs_xcbhash);
1727 /* It is always appropriate to throw away all the access rights? */
1728 afs_FreeAllAxs(&(tvc->Access));
1729 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1731 if ((tvp->states & VForeign)) {
1733 tvc->states |= CForeign;
1734 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1735 && (tvp->rootUnique == afid->Fid.Unique)) {
1739 if (tvp->states & VRO)
1741 if (tvp->states & VBackup)
1742 tvc->states |= CBackup;
1743 /* now copy ".." entry back out of volume structure, if necessary */
1744 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1746 tvc->mvid = (struct VenusFid *)
1747 osi_AllocSmallSpace(sizeof(struct VenusFid));
1748 *tvc->mvid = tvp->dotdot;
1750 afs_PutVolume(tvp, READ_LOCK);
1754 afs_RemoveVCB(afid);
1756 struct AFSFetchStatus OutStatus;
1758 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1759 afs_ProcessFS(tvc, &OutStatus, areq);
1760 tvc->states |= CStatd | CUnique;
1763 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1768 ReleaseWriteLock(&tvc->lock);
1770 ObtainReadLock(&afs_xvcache);
1772 ReleaseReadLock(&afs_xvcache);
1776 ReleaseWriteLock(&tvc->lock);
1779 } /*afs_GetVCache */
1784 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1785 afs_int32 * cached, struct vcache *adp, char *aname)
1787 afs_int32 code, now, newvcache = 0;
1788 struct VenusFid nfid;
1789 register struct vcache *tvc;
1791 struct AFSFetchStatus OutStatus;
1792 struct AFSCallBack CallBack;
1793 struct AFSVolSync tsync;
1794 struct server *serverp = 0;
1798 AFS_STATCNT(afs_GetVCache);
1800 *cached = 0; /* Init just in case */
1802 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1806 ObtainReadLock(&afs_xvcache);
1807 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
1810 ReleaseReadLock(&afs_xvcache);
1812 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1813 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1817 ObtainReadLock(&tvc->lock);
1819 if (tvc->states & CStatd) {
1823 ReleaseReadLock(&tvc->lock);
1826 tvc->states &= ~CUnique;
1828 ReleaseReadLock(&tvc->lock);
1829 ObtainReadLock(&afs_xvcache);
1833 ReleaseReadLock(&afs_xvcache);
1835 /* lookup the file */
1838 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1840 afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1843 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1847 ObtainSharedLock(&afs_xvcache, 6);
1848 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU /* no xstats now */ );
1850 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1851 ReleaseSharedLock(&afs_xvcache);
1852 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1858 /* no cache entry, better grab one */
1859 UpgradeSToWLock(&afs_xvcache, 22);
1860 tvc = afs_NewVCache(&nfid, serverp);
1862 ConvertWToSLock(&afs_xvcache);
1865 ReleaseSharedLock(&afs_xvcache);
1866 ObtainWriteLock(&tvc->lock, 55);
1868 /* It is always appropriate to throw away all the access rights? */
1869 afs_FreeAllAxs(&(tvc->Access));
1870 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1872 if ((tvp->states & VForeign)) {
1874 tvc->states |= CForeign;
1875 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1876 && (tvp->rootUnique == afid->Fid.Unique))
1879 if (tvp->states & VRO)
1881 if (tvp->states & VBackup)
1882 tvc->states |= CBackup;
1883 /* now copy ".." entry back out of volume structure, if necessary */
1884 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1886 tvc->mvid = (struct VenusFid *)
1887 osi_AllocSmallSpace(sizeof(struct VenusFid));
1888 *tvc->mvid = tvp->dotdot;
1893 ObtainWriteLock(&afs_xcbhash, 465);
1894 afs_DequeueCallback(tvc);
1895 tvc->states &= ~(CStatd | CUnique);
1896 ReleaseWriteLock(&afs_xcbhash);
1897 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1898 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1900 afs_PutVolume(tvp, READ_LOCK);
1901 ReleaseWriteLock(&tvc->lock);
1902 ObtainReadLock(&afs_xvcache);
1904 ReleaseReadLock(&afs_xvcache);
1908 ObtainWriteLock(&afs_xcbhash, 466);
1909 if (origCBs == afs_allCBs) {
1910 if (CallBack.ExpirationTime) {
1911 tvc->callback = serverp;
1912 tvc->cbExpires = CallBack.ExpirationTime + now;
1913 tvc->states |= CStatd | CUnique;
1914 tvc->states &= ~CBulkFetching;
1915 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1916 } else if (tvc->states & CRO) {
1917 /* adapt gives us an hour. */
1918 tvc->cbExpires = 3600 + osi_Time();
1919 /*XXX*/ tvc->states |= CStatd | CUnique;
1920 tvc->states &= ~CBulkFetching;
1921 afs_QueueCallback(tvc, CBHash(3600), tvp);
1923 tvc->callback = NULL;
1924 afs_DequeueCallback(tvc);
1925 tvc->states &= ~(CStatd | CUnique);
1926 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1927 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1930 afs_DequeueCallback(tvc);
1931 tvc->states &= ~CStatd;
1932 tvc->states &= ~CUnique;
1933 tvc->callback = NULL;
1934 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1935 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1937 ReleaseWriteLock(&afs_xcbhash);
1939 afs_PutVolume(tvp, READ_LOCK);
1940 afs_ProcessFS(tvc, &OutStatus, areq);
1942 ReleaseWriteLock(&tvc->lock);
1948 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
1949 afs_int32 * cached, struct volume *tvolp)
1951 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
1952 afs_int32 getNewFid = 0;
1954 struct VenusFid nfid;
1955 register struct vcache *tvc;
1956 struct server *serverp = 0;
1957 struct AFSFetchStatus OutStatus;
1958 struct AFSCallBack CallBack;
1959 struct AFSVolSync tsync;
1965 if (!tvolp->rootVnode || getNewFid) {
1966 struct VenusFid tfid;
1969 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1970 origCBs = afs_allCBs; /* ignore InitCallBackState */
1972 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
1977 /* ReleaseReadLock(&tvolp->lock); */
1978 ObtainWriteLock(&tvolp->lock, 56);
1979 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
1980 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
1981 ReleaseWriteLock(&tvolp->lock);
1982 /* ObtainReadLock(&tvolp->lock);*/
1985 afid->Fid.Vnode = tvolp->rootVnode;
1986 afid->Fid.Unique = tvolp->rootUnique;
1989 ObtainSharedLock(&afs_xvcache, 7);
1991 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1992 if (!FidCmp(&(tvc->fid), afid)) {
1994 /* Grab this vnode, possibly reactivating from the free list */
1995 /* for the present (95.05.25) everything on the hash table is
1996 * definitively NOT in the free list -- at least until afs_reclaim
1997 * can be safely implemented */
2000 vg = vget(AFSTOV(tvc)); /* this bumps ref count */
2004 #endif /* AFS_OSF_ENV */
2009 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
2010 /* Mount point no longer stat'd or unknown. FID may have changed. */
2013 AFS_RELE(AFSTOV(tvc));
2017 ReleaseSharedLock(&afs_xvcache);
2022 UpgradeSToWLock(&afs_xvcache, 23);
2023 /* no cache entry, better grab one */
2024 tvc = afs_NewVCache(afid, NULL);
2026 afs_stats_cmperf.vcacheMisses++;
2030 afs_stats_cmperf.vcacheHits++;
2032 /* we already bumped the ref count in the for loop above */
2033 #else /* AFS_OSF_ENV */
2036 UpgradeSToWLock(&afs_xvcache, 24);
2037 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2038 refpanic("GRVC VLRU inconsistent0");
2040 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2041 refpanic("GRVC VLRU inconsistent1");
2043 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2044 refpanic("GRVC VLRU inconsistent2");
2046 QRemove(&tvc->vlruq); /* move to lruq head */
2047 QAdd(&VLRU, &tvc->vlruq);
2048 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2049 refpanic("GRVC VLRU inconsistent3");
2051 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2052 refpanic("GRVC VLRU inconsistent4");
2054 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2055 refpanic("GRVC VLRU inconsistent5");
2060 ReleaseWriteLock(&afs_xvcache);
2062 if (tvc->states & CStatd) {
2066 ObtainReadLock(&tvc->lock);
2067 tvc->states &= ~CUnique;
2068 tvc->callback = NULL; /* redundant, perhaps */
2069 ReleaseReadLock(&tvc->lock);
2072 ObtainWriteLock(&tvc->lock, 57);
2074 /* It is always appropriate to throw away all the access rights? */
2075 afs_FreeAllAxs(&(tvc->Access));
2078 tvc->states |= CForeign;
2079 if (tvolp->states & VRO)
2081 if (tvolp->states & VBackup)
2082 tvc->states |= CBackup;
2083 /* now copy ".." entry back out of volume structure, if necessary */
2084 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2085 && (tvolp->rootUnique == afid->Fid.Unique)) {
2088 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2090 tvc->mvid = (struct VenusFid *)
2091 osi_AllocSmallSpace(sizeof(struct VenusFid));
2092 *tvc->mvid = tvolp->dotdot;
2096 afs_RemoveVCB(afid);
2099 struct VenusFid tfid;
2102 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2103 origCBs = afs_allCBs; /* ignore InitCallBackState */
2105 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2110 ObtainWriteLock(&afs_xcbhash, 467);
2111 afs_DequeueCallback(tvc);
2112 tvc->callback = NULL;
2113 tvc->states &= ~(CStatd | CUnique);
2114 ReleaseWriteLock(&afs_xcbhash);
2115 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2116 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2117 ReleaseWriteLock(&tvc->lock);
2118 ObtainReadLock(&afs_xvcache);
2120 ReleaseReadLock(&afs_xvcache);
2124 ObtainWriteLock(&afs_xcbhash, 468);
2125 if (origCBs == afs_allCBs) {
2126 tvc->states |= CTruth;
2127 tvc->callback = serverp;
2128 if (CallBack.ExpirationTime != 0) {
2129 tvc->cbExpires = CallBack.ExpirationTime + start;
2130 tvc->states |= CStatd;
2131 tvc->states &= ~CBulkFetching;
2132 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2133 } else if (tvc->states & CRO) {
2134 /* adapt gives us an hour. */
2135 tvc->cbExpires = 3600 + osi_Time();
2136 /*XXX*/ tvc->states |= CStatd;
2137 tvc->states &= ~CBulkFetching;
2138 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2141 afs_DequeueCallback(tvc);
2142 tvc->callback = NULL;
2143 tvc->states &= ~(CStatd | CUnique);
2144 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2145 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2147 ReleaseWriteLock(&afs_xcbhash);
2148 afs_ProcessFS(tvc, &OutStatus, areq);
2150 ReleaseWriteLock(&tvc->lock);
2157 * must be called with avc write-locked
2158 * don't absolutely have to invalidate the hint unless the dv has
2159 * changed, but be sure to get it right else there will be consistency bugs.
2162 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2163 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2166 afs_uint32 start = 0;
2167 register struct conn *tc;
2168 struct AFSCallBack CallBack;
2169 struct AFSVolSync tsync;
2170 struct volume *volp;
2173 tc = afs_Conn(afid, areq, SHARED_LOCK);
2174 avc->dchint = NULL; /* invalidate hints */
2176 avc->callback = tc->srvr->server;
2178 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2181 RXAFS_FetchStatus(tc->id, (struct AFSFid *)&afid->Fid, Outsp,
2189 } while (afs_Analyze
2190 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2191 SHARED_LOCK, NULL));
2194 afs_ProcessFS(avc, Outsp, areq);
2195 volp = afs_GetVolume(afid, areq, READ_LOCK);
2196 ObtainWriteLock(&afs_xcbhash, 469);
2197 avc->states |= CTruth;
2198 if (avc->callback /* check for race */ ) {
2199 if (CallBack.ExpirationTime != 0) {
2200 avc->cbExpires = CallBack.ExpirationTime + start;
2201 avc->states |= CStatd;
2202 avc->states &= ~CBulkFetching;
2203 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2204 } else if (avc->states & CRO) { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2205 avc->cbExpires = 3600 + start;
2206 avc->states |= CStatd;
2207 avc->states &= ~CBulkFetching;
2208 afs_QueueCallback(avc, CBHash(3600), volp);
2210 afs_DequeueCallback(avc);
2211 avc->callback = NULL;
2212 avc->states &= ~(CStatd | CUnique);
2213 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2214 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2217 afs_DequeueCallback(avc);
2218 avc->callback = NULL;
2219 avc->states &= ~(CStatd | CUnique);
2220 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2221 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2223 ReleaseWriteLock(&afs_xcbhash);
2225 afs_PutVolume(volp, READ_LOCK);
2227 /* used to undo the local callback, but that's too extreme.
2228 * There are plenty of good reasons that fetchstatus might return
2229 * an error, such as EPERM. If we have the vnode cached, statd,
2230 * with callback, might as well keep track of the fact that we
2231 * don't have access...
2233 if (code == EPERM || code == EACCES) {
2234 struct axscache *ac;
2235 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2237 else /* not found, add a new one if possible */
2238 afs_AddAxs(avc->Access, areq->uid, 0);
2249 * Stuff some information into the vcache for the given file.
2252 * afid : File in question.
2253 * OutStatus : Fetch status on the file.
2254 * CallBack : Callback info.
2255 * tc : RPC connection involved.
2256 * areq : vrequest involved.
2259 * Nothing interesting.
2262 afs_StuffVcache(register struct VenusFid *afid,
2263 struct AFSFetchStatus *OutStatus,
2264 struct AFSCallBack *CallBack, register struct conn *tc,
2265 struct vrequest *areq)
2267 register afs_int32 code, i, newvcache = 0;
2268 register struct vcache *tvc;
2269 struct AFSVolSync tsync;
2271 struct axscache *ac;
2274 AFS_STATCNT(afs_StuffVcache);
2275 #ifdef IFS_VCACHECOUNT
2280 ObtainSharedLock(&afs_xvcache, 8);
2282 tvc = afs_FindVCache(afid, &retry, DO_VLRU /* no stats */ );
2284 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2285 ReleaseSharedLock(&afs_xvcache);
2286 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2292 /* no cache entry, better grab one */
2293 UpgradeSToWLock(&afs_xvcache, 25);
2294 tvc = afs_NewVCache(afid, NULL);
2296 ConvertWToSLock(&afs_xvcache);
2299 ReleaseSharedLock(&afs_xvcache);
2300 ObtainWriteLock(&tvc->lock, 58);
2302 tvc->states &= ~CStatd;
2303 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2304 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2306 /* Is it always appropriate to throw away all the access rights? */
2307 afs_FreeAllAxs(&(tvc->Access));
2309 /*Copy useful per-volume info */
2310 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2312 if (newvcache && (tvp->states & VForeign))
2313 tvc->states |= CForeign;
2314 if (tvp->states & VRO)
2316 if (tvp->states & VBackup)
2317 tvc->states |= CBackup;
2319 * Now, copy ".." entry back out of volume structure, if
2322 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2324 tvc->mvid = (struct VenusFid *)
2325 osi_AllocSmallSpace(sizeof(struct VenusFid));
2326 *tvc->mvid = tvp->dotdot;
2329 /* store the stat on the file */
2330 afs_RemoveVCB(afid);
2331 afs_ProcessFS(tvc, OutStatus, areq);
2332 tvc->callback = tc->srvr->server;
2334 /* we use osi_Time twice below. Ideally, we would use the time at which
2335 * the FetchStatus call began, instead, but we don't have it here. So we
2336 * make do with "now". In the CRO case, it doesn't really matter. In
2337 * the other case, we hope that the difference between "now" and when the
2338 * call actually began execution on the server won't be larger than the
2339 * padding which the server keeps. Subtract 1 second anyway, to be on
2340 * the safe side. Can't subtract more because we don't know how big
2341 * ExpirationTime is. Possible consistency problems may arise if the call
2342 * timeout period becomes longer than the server's expiration padding. */
2343 ObtainWriteLock(&afs_xcbhash, 470);
2344 if (CallBack->ExpirationTime != 0) {
2345 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2346 tvc->states |= CStatd;
2347 tvc->states &= ~CBulkFetching;
2348 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2349 } else if (tvc->states & CRO) {
2350 /* old-fashioned AFS 3.2 style */
2351 tvc->cbExpires = 3600 + osi_Time();
2352 /*XXX*/ tvc->states |= CStatd;
2353 tvc->states &= ~CBulkFetching;
2354 afs_QueueCallback(tvc, CBHash(3600), tvp);
2356 afs_DequeueCallback(tvc);
2357 tvc->callback = NULL;
2358 tvc->states &= ~(CStatd | CUnique);
2359 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2360 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2362 ReleaseWriteLock(&afs_xcbhash);
2364 afs_PutVolume(tvp, READ_LOCK);
2366 /* look in per-pag cache */
2367 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2368 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2369 else /* not found, add a new one if possible */
2370 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2372 ReleaseWriteLock(&tvc->lock);
2373 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2374 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2375 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2377 * Release ref count... hope this guy stays around...
2380 } /*afs_StuffVcache */
2387 * Decrements the reference count on a cache entry.
2390 * avc : Pointer to the cache entry to decrement.
2393 * Nothing interesting.
2396 afs_PutVCache(register struct vcache *avc)
2398 AFS_STATCNT(afs_PutVCache);
2400 * Can we use a read lock here?
2402 ObtainReadLock(&afs_xvcache);
2404 ReleaseReadLock(&afs_xvcache);
2405 } /*afs_PutVCache */
2411 * Find a vcache entry given a fid.
2414 * afid : Pointer to the fid whose cache entry we desire.
2415 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2416 * unlock the vnode, and try again.
2417 * flags: bit 1 to specify whether to compute hit statistics. Not
2418 * set if FindVCache is called as part of internal bookkeeping.
2421 * Must be called with the afs_xvcache lock at least held at
2422 * the read level. In order to do the VLRU adjustment, the xvcache lock
2423 * must be shared-- we upgrade it here.
2427 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2430 register struct vcache *tvc;
2433 AFS_STATCNT(afs_FindVCache);
2436 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2437 if (FidMatches(afid, tvc)) {
2439 /* Grab this vnode, possibly reactivating from the free list */
2442 vg = vget(AFSTOV(tvc));
2446 #endif /* AFS_OSF_ENV */
2451 /* should I have a read lock on the vnode here? */
2455 #if !defined(AFS_OSF_ENV)
2456 osi_vnhold(tvc, retry); /* already held, above */
2457 if (retry && *retry)
2460 #ifdef AFS_DARWIN_ENV
2461 tvc->states |= CUBCinit;
2463 if (UBCINFOMISSING(AFSTOV(tvc)) ||
2464 UBCINFORECLAIMED(AFSTOV(tvc))) {
2465 ubc_info_init(AFSTOV(tvc));
2468 tvc->states &= ~CUBCinit;
2471 * only move to front of vlru if we have proper vcache locking)
2473 if (flag & DO_VLRU) {
2474 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2475 refpanic("FindVC VLRU inconsistent1");
2477 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2478 refpanic("FindVC VLRU inconsistent1");
2480 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2481 refpanic("FindVC VLRU inconsistent2");
2483 UpgradeSToWLock(&afs_xvcache, 26);
2484 QRemove(&tvc->vlruq);
2485 QAdd(&VLRU, &tvc->vlruq);
2486 ConvertWToSLock(&afs_xvcache);
2487 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2488 refpanic("FindVC VLRU inconsistent1");
2490 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2491 refpanic("FindVC VLRU inconsistent2");
2493 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2494 refpanic("FindVC VLRU inconsistent3");
2500 if (flag & DO_STATS) {
2502 afs_stats_cmperf.vcacheHits++;
2504 afs_stats_cmperf.vcacheMisses++;
2505 if (afs_IsPrimaryCellNum(afid->Cell))
2506 afs_stats_cmperf.vlocalAccesses++;
2508 afs_stats_cmperf.vremoteAccesses++;
2511 } /*afs_FindVCache */
2517 * Find a vcache entry given a fid. Does a wildcard match on what we
2518 * have for the fid. If more than one entry, don't return anything.
2521 * avcp : Fill in pointer if we found one and only one.
2522 * afid : Pointer to the fid whose cache entry we desire.
2523 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2524 * unlock the vnode, and try again.
2525 * flags: bit 1 to specify whether to compute hit statistics. Not
2526 * set if FindVCache is called as part of internal bookkeeping.
2529 * Must be called with the afs_xvcache lock at least held at
2530 * the read level. In order to do the VLRU adjustment, the xvcache lock
2531 * must be shared-- we upgrade it here.
2534 * number of matches found.
2537 int afs_duplicate_nfs_fids = 0;
2540 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2542 register struct vcache *tvc;
2544 afs_int32 count = 0;
2545 struct vcache *found_tvc = NULL;
2547 AFS_STATCNT(afs_FindVCache);
2549 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2553 ObtainSharedLock(&afs_xvcache, 331);
2556 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2557 /* Match only on what we have.... */
2558 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2559 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2560 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2561 && (tvc->fid.Cell == afid->Cell)) {
2563 /* Grab this vnode, possibly reactivating from the free list */
2566 vg = vget(AFSTOV(tvc));
2569 /* This vnode no longer exists. */
2572 #endif /* AFS_OSF_ENV */
2577 /* Drop our reference counts. */
2579 vrele(AFSTOV(found_tvc));
2581 afs_duplicate_nfs_fids++;
2582 ReleaseSharedLock(&afs_xvcache);
2590 /* should I have a read lock on the vnode here? */
2592 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2593 afs_int32 retry = 0;
2594 osi_vnhold(tvc, &retry);
2597 found_tvc = (struct vcache *)0;
2598 ReleaseSharedLock(&afs_xvcache);
2599 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2603 #if !defined(AFS_OSF_ENV)
2604 osi_vnhold(tvc, (int *)0); /* already held, above */
2608 * We obtained the xvcache lock above.
2610 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2611 refpanic("FindVC VLRU inconsistent1");
2613 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2614 refpanic("FindVC VLRU inconsistent1");
2616 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2617 refpanic("FindVC VLRU inconsistent2");
2619 UpgradeSToWLock(&afs_xvcache, 568);
2620 QRemove(&tvc->vlruq);
2621 QAdd(&VLRU, &tvc->vlruq);
2622 ConvertWToSLock(&afs_xvcache);
2623 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2624 refpanic("FindVC VLRU inconsistent1");
2626 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2627 refpanic("FindVC VLRU inconsistent2");
2629 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2630 refpanic("FindVC VLRU inconsistent3");
2636 afs_stats_cmperf.vcacheHits++;
2638 afs_stats_cmperf.vcacheMisses++;
2639 if (afs_IsPrimaryCellNum(afid->Cell))
2640 afs_stats_cmperf.vlocalAccesses++;
2642 afs_stats_cmperf.vremoteAccesses++;
2644 *avcp = tvc; /* May be null */
2646 ReleaseSharedLock(&afs_xvcache);
2647 return (tvc ? 1 : 0);
2649 } /*afs_NFSFindVCache */
2657 * Initialize vcache related variables
2660 afs_vcacheInit(int astatSize)
2662 register struct vcache *tvp;
2664 #if defined(AFS_OSF_ENV) || defined(AFS_LINUX22_ENV)
2665 if (!afs_maxvcount) {
2666 #if defined(AFS_LINUX22_ENV)
2667 afs_maxvcount = astatSize; /* no particular limit on linux? */
2668 #elif defined(AFS_OSF30_ENV)
2669 afs_maxvcount = max_vnodes / 2; /* limit ourselves to half the total */
2671 afs_maxvcount = nvnode / 2; /* limit ourselves to half the total */
2673 if (astatSize < afs_maxvcount) {
2674 afs_maxvcount = astatSize;
2677 #else /* AFS_OSF_ENV */
2681 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2682 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2684 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
2685 /* Allocate and thread the struct vcache entries */
2686 tvp = (struct vcache *)afs_osi_Alloc(astatSize * sizeof(struct vcache));
2687 memset((char *)tvp, 0, sizeof(struct vcache) * astatSize);
2689 Initial_freeVCList = tvp;
2690 freeVCList = &(tvp[0]);
2691 for (i = 0; i < astatSize - 1; i++) {
2692 tvp[i].nextfree = &(tvp[i + 1]);
2694 tvp[astatSize - 1].nextfree = NULL;
2695 #ifdef KERNEL_HAVE_PIN
2696 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2700 #if defined(AFS_SGI_ENV)
2701 for (i = 0; i < astatSize; i++) {
2702 char name[METER_NAMSZ];
2703 struct vcache *tvc = &tvp[i];
2705 tvc->v.v_number = ++afsvnumbers;
2706 tvc->vc_rwlockid = OSI_NO_LOCKID;
2707 initnsema(&tvc->vc_rwlock, 1,
2708 makesname(name, "vrw", tvc->v.v_number));
2709 #ifndef AFS_SGI53_ENV
2710 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2712 #ifndef AFS_SGI62_ENV
2713 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2714 #endif /* AFS_SGI62_ENV */
2718 for(i = 0; i < VCSIZE; ++i)
2719 QInit(&afs_vhashTV[i]);
2727 shutdown_vcache(void)
2730 struct afs_cbr *tsp, *nsp;
2732 * XXX We may potentially miss some of the vcaches because if when there're no
2733 * free vcache entries and all the vcache entries are active ones then we allocate
2734 * an additional one - admittedly we almost never had that occur.
2738 register struct afs_q *tq, *uq;
2739 register struct vcache *tvc;
2740 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2744 osi_FreeSmallSpace(tvc->mvid);
2745 tvc->mvid = (struct VenusFid *)0;
2748 aix_gnode_rele(AFSTOV(tvc));
2750 if (tvc->linkData) {
2751 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2756 * Also free the remaining ones in the Cache
2758 for (i = 0; i < VCSIZE; i++) {
2759 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2761 osi_FreeSmallSpace(tvc->mvid);
2762 tvc->mvid = (struct VenusFid *)0;
2766 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2767 #ifdef AFS_AIX32_ENV
2770 vms_delete(tvc->segid);
2772 tvc->segid = tvc->vmh = NULL;
2774 osi_Panic("flushVcache: vm race");
2782 #if defined(AFS_SUN5_ENV)
2788 if (tvc->linkData) {
2789 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2793 afs_FreeAllAxs(&(tvc->Access));
2799 * Free any leftover callback queue
2801 for (tsp = afs_cbrSpace; tsp; tsp = nsp) {
2803 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2807 #ifdef KERNEL_HAVE_PIN
2808 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2810 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
2811 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2814 #if !defined(AFS_OSF_ENV) && !defined(AFS_LINUX22_ENV)
2815 freeVCList = Initial_freeVCList = 0;
2817 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2818 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2820 for(i = 0; i < VCSIZE; ++i)
2821 QInit(&afs_vhashTV[i]);