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"
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 struct vcache *freeVCList; /*Free list for stat cache entries */
67 struct vcache *Initial_freeVCList; /*Initial list for above */
68 struct afs_q VLRU; /*vcache LRU */
69 afs_int32 vcachegen = 0;
70 unsigned int afs_paniconwarn = 0;
71 struct vcache *afs_vhashT[VCSIZE];
72 static struct afs_cbr *afs_cbrHashT[CBRSIZE];
73 afs_int32 afs_bulkStatsLost;
74 int afs_norefpanic = 0;
76 /* Forward declarations */
77 static afs_int32 afs_QueueVCB(struct vcache *avc);
82 * Generate an index into the hash table for a given Fid.
85 afs_HashCBRFid(struct AFSFid *fid)
87 return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE;
93 * Insert a CBR entry into the hash table.
94 * Must be called with afs_xvcb held.
97 afs_InsertHashCBR(struct afs_cbr *cbr)
99 int slot = afs_HashCBRFid(&cbr->fid);
101 cbr->hash_next = afs_cbrHashT[slot];
102 if (afs_cbrHashT[slot])
103 afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next;
105 cbr->hash_pprev = &afs_cbrHashT[slot];
106 afs_cbrHashT[slot] = cbr;
113 * Flush the given vcache entry.
116 * avc : Pointer to vcache entry to flush.
117 * slept : Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
120 * afs_xvcache lock must be held for writing upon entry to
121 * prevent people from changing the vrefCount field, and to
122 * protect the lruq and hnext fields.
123 * LOCK: afs_FlushVCache afs_xvcache W
124 * REFCNT: vcache ref count must be zero on entry except for osf1
125 * RACE: lock is dropped and reobtained, permitting race in caller
129 afs_FlushVCache(struct vcache *avc, int *slept)
130 { /*afs_FlushVCache */
132 register afs_int32 i, code;
133 register struct vcache **uvc, *wvc;
136 AFS_STATCNT(afs_FlushVCache);
137 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
138 ICL_TYPE_INT32, avc->states);
141 VN_LOCK(AFSTOV(avc));
145 code = osi_VM_FlushVCache(avc, slept);
149 if (avc->states & CVFlushed) {
153 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
154 refpanic("LRU vs. Free inconsistency");
156 avc->states |= CVFlushed;
157 /* pull the entry out of the lruq and put it on the free list */
158 QRemove(&avc->vlruq);
159 avc->vlruq.prev = avc->vlruq.next = (struct afs_q *)0;
161 /* keep track of # of files that we bulk stat'd, but never used
162 * before they got recycled.
164 if (avc->states & CBulkStat)
167 /* remove entry from the hash chain */
168 i = VCHash(&avc->fid);
169 uvc = &afs_vhashT[i];
170 for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
173 avc->hnext = (struct vcache *)NULL;
178 osi_Panic("flushvcache"); /* not in correct hash bucket */
180 osi_FreeSmallSpace(avc->mvid);
181 avc->mvid = (struct VenusFid *)0;
183 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
184 avc->linkData = NULL;
186 #if defined(AFS_XBSD_ENV)
187 /* OK, there are no internal vrefCounts, so there shouldn't
188 * be any more refs here. */
190 avc->v->v_data = NULL; /* remove from vnode */
191 avc->v = NULL; /* also drop the ptr to vnode */
194 afs_FreeAllAxs(&(avc->Access));
196 /* we can't really give back callbacks on RO files, since the
197 * server only tracks them on a per-volume basis, and we don't
198 * know whether we still have some other files from the same
200 if ((avc->states & CRO) == 0 && avc->callback) {
203 ObtainWriteLock(&afs_xcbhash, 460);
204 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
205 avc->states &= ~(CStatd | CUnique);
206 ReleaseWriteLock(&afs_xcbhash);
207 afs_symhint_inval(avc);
208 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
209 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
211 osi_dnlc_purgevp(avc);
214 * Next, keep track of which vnodes we've deleted for create's
215 * optimistic synchronization algorithm
218 if (avc->fid.Fid.Vnode & 1)
223 #if !defined(AFS_OSF_ENV)
224 /* put the entry in the free list */
225 avc->nextfree = freeVCList;
227 if (avc->vlruq.prev || avc->vlruq.next) {
228 refpanic("LRU vs. Free inconsistency");
231 /* This should put it back on the vnode free list since usecount is 1 */
234 if (VREFCOUNT(avc) > 0) {
235 VN_UNLOCK(AFSTOV(avc));
236 AFS_RELE(AFSTOV(avc));
238 if (afs_norefpanic) {
239 printf("flush vc refcnt < 1");
241 (void)vgone(avc, VX_NOSLEEP, NULL);
243 VN_UNLOCK(AFSTOV(avc));
245 osi_Panic("flush vc refcnt < 1");
247 #endif /* AFS_OSF_ENV */
248 avc->states |= CVFlushed;
253 VN_UNLOCK(AFSTOV(avc));
257 } /*afs_FlushVCache */
263 * The core of the inactive vnode op for all but IRIX.
266 afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred)
268 AFS_STATCNT(afs_inactive);
269 if (avc->states & CDirty) {
270 /* we can't keep trying to push back dirty data forever. Give up. */
271 afs_InvalidateAllSegments(avc); /* turns off dirty bit */
273 avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
274 avc->states &= ~CDirty; /* Turn it off */
275 if (avc->states & CUnlinked) {
276 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
277 avc->states |= CUnlinkedDel;
280 afs_remunlink(avc, 1); /* ignore any return code */
289 * Description: allocate a callback return structure from the
290 * free list and return it.
292 * Env: The alloc and free routines are both called with the afs_xvcb lock
293 * held, so we don't have to worry about blocking in osi_Alloc.
295 static struct afs_cbr *afs_cbrSpace = 0;
299 register struct afs_cbr *tsp;
302 while (!afs_cbrSpace) {
303 if (afs_stats_cmperf.CallBackAlloced >= 2) {
304 /* don't allocate more than 2 * AFS_NCBRS for now */
306 afs_stats_cmperf.CallBackFlushes++;
310 (struct afs_cbr *)afs_osi_Alloc(AFS_NCBRS *
311 sizeof(struct afs_cbr));
312 for (i = 0; i < AFS_NCBRS - 1; i++) {
313 tsp[i].next = &tsp[i + 1];
315 tsp[AFS_NCBRS - 1].next = 0;
317 afs_stats_cmperf.CallBackAlloced++;
321 afs_cbrSpace = tsp->next;
328 * Description: free a callback return structure, removing it from all lists.
331 * asp -- the address of the structure to free.
333 * Environment: the xvcb lock is held over these calls.
336 afs_FreeCBR(register struct afs_cbr *asp)
338 *(asp->pprev) = asp->next;
340 asp->next->pprev = asp->pprev;
342 *(asp->hash_pprev) = asp->hash_next;
344 asp->hash_next->hash_pprev = asp->hash_pprev;
346 asp->next = afs_cbrSpace;
354 * Description: flush all queued callbacks to all servers.
358 * Environment: holds xvcb lock over RPC to guard against race conditions
359 * when a new callback is granted for the same file later on.
362 afs_FlushVCBs(afs_int32 lockit)
364 struct AFSFid *tfids;
365 struct AFSCallBack callBacks[1];
366 struct AFSCBFids fidArray;
367 struct AFSCBs cbArray;
369 struct afs_cbr *tcbrp;
373 struct vrequest treq;
375 int safety1, safety2, safety3;
377 if ((code = afs_InitReq(&treq, afs_osi_credp)))
379 treq.flags |= O_NONBLOCK;
380 tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
383 MObtainWriteLock(&afs_xvcb, 273);
384 ObtainReadLock(&afs_xserver);
385 for (i = 0; i < NSERVERS; i++) {
386 for (safety1 = 0, tsp = afs_servers[i];
387 tsp && safety1 < afs_totalServers + 10;
388 tsp = tsp->next, safety1++) {
390 if (tsp->cbrs == (struct afs_cbr *)0)
393 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
394 * and make an RPC, over and over again.
396 tcount = 0; /* number found so far */
397 for (safety2 = 0; safety2 < afs_cacheStats; safety2++) {
398 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
399 /* if buffer is full, or we've queued all we're going
400 * to from this server, we should flush out the
403 fidArray.AFSCBFids_len = tcount;
404 fidArray.AFSCBFids_val = (struct AFSFid *)tfids;
405 cbArray.AFSCBs_len = 1;
406 cbArray.AFSCBs_val = callBacks;
407 memset(&callBacks[0], 0, sizeof(callBacks[0]));
408 callBacks[0].CallBackType = CB_EXCLUSIVE;
409 for (safety3 = 0; safety3 < MAXHOSTS * 2; safety3++) {
410 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
411 tsp->cell->cellNum, &treq, 0,
415 (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
418 RXAFS_GiveUpCallBacks(tc->id, &fidArray,
426 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK,
431 /* ignore return code, since callbacks may have
432 * been returned anyway, we shouldn't leave them
433 * around to be returned again.
435 * Next, see if we are done with this server, and if so,
436 * break to deal with the next one.
442 /* if to flush full buffer */
443 /* if we make it here, we have an entry at the head of cbrs,
444 * which we should copy to the file ID array and then free.
447 tfids[tcount++] = tcbrp->fid;
449 /* Freeing the CBR will unlink it from the server's CBR list */
451 } /* while loop for this one server */
452 if (safety2 > afs_cacheStats) {
453 afs_warn("possible internal error afs_flushVCBs (%d)\n",
456 } /* for loop for this hash chain */
457 } /* loop through all hash chains */
458 if (safety1 > afs_totalServers + 2) {
460 ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n",
461 safety1, afs_totalServers + 2);
463 osi_Panic("afs_flushVCBS safety1");
466 ReleaseReadLock(&afs_xserver);
468 MReleaseWriteLock(&afs_xvcb);
469 afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
477 * Queue a callback on the given fid.
483 * Locks the xvcb lock.
484 * Called when the xvcache lock is already held.
488 afs_QueueVCB(struct vcache *avc)
491 struct afs_cbr *tcbp;
493 AFS_STATCNT(afs_QueueVCB);
494 /* The callback is really just a struct server ptr. */
495 tsp = (struct server *)(avc->callback);
497 /* we now have a pointer to the server, so we just allocate
498 * a queue entry and queue it.
500 MObtainWriteLock(&afs_xvcb, 274);
501 tcbp = afs_AllocCBR();
502 tcbp->fid = avc->fid.Fid;
504 tcbp->next = tsp->cbrs;
506 tsp->cbrs->pprev = &tcbp->next;
509 tcbp->pprev = &tsp->cbrs;
511 afs_InsertHashCBR(tcbp);
513 /* now release locks and return */
514 MReleaseWriteLock(&afs_xvcb);
523 * Remove a queued callback for a given Fid.
526 * afid: The fid we want cleansed of queued callbacks.
529 * Locks xvcb and xserver locks.
530 * Typically called with xdcache, xvcache and/or individual vcache
535 afs_RemoveVCB(struct VenusFid *afid)
538 struct afs_cbr *cbr, *ncbr;
540 AFS_STATCNT(afs_RemoveVCB);
541 MObtainWriteLock(&afs_xvcb, 275);
543 slot = afs_HashCBRFid(&afid->Fid);
544 ncbr = afs_cbrHashT[slot];
548 ncbr = cbr->hash_next;
550 if (afid->Fid.Volume == cbr->fid.Volume &&
551 afid->Fid.Vnode == cbr->fid.Vnode &&
552 afid->Fid.Unique == cbr->fid.Unique) {
557 MReleaseWriteLock(&afs_xvcb);
564 * This routine is responsible for allocating a new cache entry
565 * from the free list. It formats the cache entry and inserts it
566 * into the appropriate hash tables. It must be called with
567 * afs_xvcache write-locked so as to prevent several processes from
568 * trying to create a new cache entry simultaneously.
571 * afid : The file id of the file whose cache entry is being
574 /* LOCK: afs_NewVCache afs_xvcache W */
576 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
580 afs_int32 anumber = VCACHE_FREE;
582 struct gnode *gnodepnt;
586 #endif /* AFS_OSF_ENV */
587 struct afs_q *tq, *uq;
590 AFS_STATCNT(afs_NewVCache);
593 if (afs_vcount >= afs_maxvcount) {
596 * If we are using > 33 % of the total system vnodes for AFS vcache
597 * entries or we are using the maximum number of vcache entries,
598 * then free some. (if our usage is > 33% we should free some, if
599 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
600 * we _must_ free some -- no choice).
602 if (((3 * afs_vcount) > nvnode) || (afs_vcount >= afs_maxvcount)) {
604 struct afs_q *tq, *uq;
609 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
612 if (tvc->states & CVFlushed)
613 refpanic("CVFlushed on VLRU");
614 else if (i++ > afs_maxvcount)
615 refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)");
616 else if (QNext(uq) != tq)
617 refpanic("VLRU inconsistent");
618 else if (VREFCOUNT(tvc) < 1)
619 refpanic("refcnt 0 on VLRU");
621 if (VREFCOUNT(tvc) == 1 && tvc->opens == 0
622 && (tvc->states & CUnlinkedDel) == 0) {
623 code = afs_FlushVCache(tvc, &fv_slept);
630 continue; /* start over - may have raced. */
636 if (anumber == VCACHE_FREE) {
637 printf("NewVCache: warning none freed, using %d of %d\n",
638 afs_vcount, afs_maxvcount);
639 if (afs_vcount >= afs_maxvcount) {
640 osi_Panic("NewVCache - none freed");
641 /* XXX instead of panicing, should do afs_maxvcount++
642 * and magic up another one */
648 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
649 /* What should we do ???? */
650 osi_Panic("afs_NewVCache: no more vnodes");
655 tvc->nextfree = NULL;
657 #else /* AFS_OSF_ENV */
658 /* pull out a free cache entry */
661 for (tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
665 if (tvc->states & CVFlushed) {
666 refpanic("CVFlushed on VLRU");
667 } else if (i++ > 2 * afs_cacheStats) { /* even allowing for a few xallocs... */
668 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
669 } else if (QNext(uq) != tq) {
670 refpanic("VLRU inconsistent");
672 #ifdef AFS_DARWIN_ENV
673 if ((VREFCOUNT(tvc) < DARWIN_REFBASE) ||
674 (VREFCOUNT(tvc) < 1 + DARWIN_REFBASE &&
675 UBCINFOEXISTS(&tvc->v))) {
678 (UBCINFOEXISTS(&tvc->v) ? 1 : 0));
680 if (tvc->opens == 0 && ((tvc->states & CUnlinkedDel) == 0)
681 && VREFCOUNT(tvc) == DARWIN_REFBASE + 1
682 && UBCINFOEXISTS(&tvc->v)) {
683 osi_VM_TryReclaim(tvc, &fv_slept);
687 continue; /* start over - may have raced. */
690 #elif defined(AFS_LINUX22_ENV)
691 if (tvc != afs_globalVp && VREFCOUNT(tvc) && tvc->opens == 0) {
692 struct dentry *dentry;
693 struct list_head *cur, *head = &(AFSTOI(tvc))->i_dentry;
698 #if defined(AFS_LINUX24_ENV)
699 spin_lock(&dcache_lock);
702 while ((cur = cur->next) != head) {
703 dentry = list_entry(cur, struct dentry, d_alias);
705 if (d_unhashed(dentry))
710 #if defined(AFS_LINUX24_ENV)
711 spin_unlock(&dcache_lock);
713 if (d_invalidate(dentry) == -EBUSY) {
715 /* perhaps lock and try to continue? (use cur as head?) */
721 #if defined(AFS_LINUX24_ENV)
722 spin_unlock(&dcache_lock);
730 if (VREFCOUNT(tvc) ==
731 #ifdef AFS_DARWIN_ENV
736 && tvc->opens == 0 && (tvc->states & CUnlinkedDel) == 0) {
737 #if defined(AFS_XBSD_ENV)
739 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
740 * then it puts the vnode on the free list.
741 * If we don't do this we end up with a cleaned vnode that's
742 * not on the free list.
743 * XXX assume FreeBSD is the same for now.
748 code = afs_FlushVCache(tvc, &fv_slept);
756 continue; /* start over - may have raced. */
764 /* none free, making one is better than a panic */
765 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
766 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
767 #ifdef KERNEL_HAVE_PIN
768 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
770 #if defined(AFS_SGI_ENV)
772 char name[METER_NAMSZ];
773 memset(tvc, 0, sizeof(struct vcache));
774 tvc->v.v_number = ++afsvnumbers;
775 tvc->vc_rwlockid = OSI_NO_LOCKID;
776 initnsema(&tvc->vc_rwlock, 1,
777 makesname(name, "vrw", tvc->v.v_number));
778 #ifndef AFS_SGI53_ENV
779 initnsema(&tvc->v.v_sync, 0,
780 makesname(name, "vsy", tvc->v.v_number));
782 #ifndef AFS_SGI62_ENV
783 initnlock(&tvc->v.v_lock,
784 makesname(name, "vlk", tvc->v.v_number));
787 #endif /* AFS_SGI_ENV */
789 tvc = freeVCList; /* take from free list */
790 freeVCList = tvc->nextfree;
791 tvc->nextfree = NULL;
793 #endif /* AFS_OSF_ENV */
795 #if defined(AFS_XBSD_ENV)
797 panic("afs_NewVCache(): free vcache with vnode attached");
800 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
801 memset((char *)tvc, 0, sizeof(struct vcache));
806 RWLOCK_INIT(&tvc->lock, "vcache lock");
807 #if defined(AFS_SUN5_ENV)
808 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
809 #endif /* defined(AFS_SUN5_ENV) */
813 afs_nbsd_getnewvnode(tvc); /* includes one refcount */
815 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
822 #ifdef AFS_FBSD50_ENV
823 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
825 if (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
827 panic("afs getnewvnode"); /* can't happen */
829 if (tvc->v != NULL) {
830 /* I'd like to know if this ever happens...
831 * We don't drop global for the rest of this function,
832 * so if we do lose the race, the other thread should
833 * have found the same vnode and finished initializing
834 * the vcache entry. Is it conceivable that this vcache
835 * entry could be recycled during this interval? If so,
836 * then there probably needs to be some sort of additional
837 * mutual exclusion (an Embryonic flag would suffice).
839 printf("afs_NewVCache: lost the race\n");
843 tvc->v->v_data = tvc;
844 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
847 tvc->parentVnode = 0;
849 tvc->linkData = NULL;
852 tvc->execsOrWriters = 0;
856 tvc->last_looker = 0;
858 tvc->asynchrony = -1;
860 afs_symhint_inval(tvc);
862 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
865 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
866 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
867 #if defined(AFS_LINUX22_ENV)
869 struct inode *ip = AFSTOI(tvc);
870 #if defined(AFS_LINUX24_ENV)
871 struct address_space *mapping = &ip->i_data;
874 #if defined(AFS_LINUX26_ENV)
877 sema_init(&ip->i_sem, 1);
878 INIT_LIST_HEAD(&ip->i_hash);
879 INIT_LIST_HEAD(&ip->i_dentry);
880 #if defined(AFS_LINUX24_ENV)
881 sema_init(&ip->i_zombie, 1);
882 init_waitqueue_head(&ip->i_wait);
883 spin_lock_init(&ip->i_data.i_shared_lock);
884 #ifdef STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK
885 spin_lock_init(&ip->i_data.page_lock);
887 INIT_LIST_HEAD(&ip->i_data.clean_pages);
888 INIT_LIST_HEAD(&ip->i_data.dirty_pages);
889 INIT_LIST_HEAD(&ip->i_data.locked_pages);
890 INIT_LIST_HEAD(&ip->i_dirty_buffers);
891 #ifdef STRUCT_INODE_HAS_I_DIRTY_DATA_BUFFERS
892 INIT_LIST_HEAD(&ip->i_dirty_data_buffers);
894 #ifdef STRUCT_INODE_HAS_I_DEVICES
895 INIT_LIST_HEAD(&ip->i_devices);
897 #ifdef STRUCT_INODE_HAS_I_TRUNCATE_SEM
898 init_rwsem(&ip->i_truncate_sem);
900 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
901 init_rwsem(&ip->i_alloc_sem);
904 #else /* AFS_LINUX22_ENV */
905 sema_init(&ip->i_atomic_write, 1);
906 init_waitqueue(&ip->i_wait);
910 #if defined(AFS_LINUX24_ENV)
912 ip->i_mapping = mapping;
913 #ifdef STRUCT_ADDRESS_SPACE_HAS_GFP_MASK
914 ip->i_data.gfp_mask = GFP_HIGHUSER;
916 #if defined(AFS_LINUX26_ENV)
917 mapping_set_gfp_mask(mapping, GFP_HIGHUSER);
919 extern struct backing_dev_info afs_backing_dev_info;
921 mapping->backing_dev_info = &afs_backing_dev_info;
926 #if !defined(AFS_LINUX26_ENV)
928 ip->i_dev = afs_globalVFS->s_dev;
930 #ifdef STRUCT_INODE_HAS_I_SECURITY
931 ip->i_security = NULL;
932 if (security_inode_alloc(ip))
933 panic("Cannot allocate inode security");
936 ip->i_sb = afs_globalVFS;
937 put_inode_on_dummy_list(ip);
938 #ifdef STRUCT_INODE_HAS_I_SB_LIST
939 list_add(&ip->i_sb_list, &ip->i_sb->s_inodes);
941 #ifdef STRUCT_INODE_HAS_INOTIFY_LOCK
942 INIT_LIST_HEAD(&ip->inotify_watches);
943 spin_lock_init(&ip->inotify_lock);
949 /* Hold it for the LRU (should make count 2) */
950 VN_HOLD(AFSTOV(tvc));
951 #else /* AFS_OSF_ENV */
952 #if !defined(AFS_XBSD_ENV)
953 VREFCOUNT_SET(tvc, 1); /* us */
954 #endif /* AFS_XBSD_ENV */
955 #endif /* AFS_OSF_ENV */
957 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
958 tvc->vmh = tvc->segid = NULL;
961 #ifdef AFS_BOZONLOCK_ENV
962 #if defined(AFS_SUN5_ENV)
963 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
965 #if defined(AFS_SUN55_ENV)
966 /* This is required if the kaio (kernel aynchronous io)
967 ** module is installed. Inside the kernel, the function
968 ** check_vp( common/os/aio.c) checks to see if the kernel has
969 ** to provide asynchronous io for this vnode. This
970 ** function extracts the device number by following the
971 ** v_data field of the vnode. If we do not set this field
972 ** then the system panics. The value of the v_data field
973 ** is not really important for AFS vnodes because the kernel
974 ** does not do asynchronous io for regular files. Hence,
975 ** for the time being, we fill up the v_data field with the
976 ** vnode pointer itself. */
977 tvc->v.v_data = (char *)tvc;
978 #endif /* AFS_SUN55_ENV */
980 afs_BozonInit(&tvc->pvnLock, tvc);
984 tvc->callback = serverp; /* to minimize chance that clear
986 /* initialize vnode data, note vrefCount is v.v_count */
988 /* Don't forget to free the gnode space */
989 tvc->v.v_gnode = gnodepnt =
990 (struct gnode *)osi_AllocSmallSpace(sizeof(struct gnode));
991 memset((char *)gnodepnt, 0, sizeof(struct gnode));
994 memset((void *)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc));
995 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
997 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
998 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1000 bhv_head_init(&(tvc->v.v_bh));
1001 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1003 #ifdef AFS_SGI65_ENV
1004 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion *)tvc;
1005 #ifdef VNODE_TRACING
1006 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
1008 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
1010 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
1011 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
1013 vnode_pcache_init(&tvc->v);
1014 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
1015 /* Above define is never true execpt in SGI test kernels. */
1016 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
1018 #ifdef INTR_KTHREADS
1019 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
1022 SetAfsVnode(AFSTOV(tvc));
1023 #endif /* AFS_SGI64_ENV */
1024 #ifdef AFS_DARWIN_ENV
1025 tvc->v.v_ubcinfo = UBC_INFO_NULL;
1026 lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0);
1027 cache_purge(AFSTOV(tvc));
1028 tvc->v.v_data = tvc;
1029 tvc->v.v_tag = VT_AFS;
1030 /* VLISTNONE(&tvc->v); */
1031 tvc->v.v_freelist.tqe_next = 0;
1032 tvc->v.v_freelist.tqe_prev = (struct vnode **)0xdeadb;
1033 tvc->vrefCount += DARWIN_REFBASE;
1036 * The proper value for mvstat (for root fids) is setup by the caller.
1039 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
1041 if (afs_globalVFS == 0)
1042 osi_Panic("afs globalvfs");
1043 vSetVfsp(tvc, afs_globalVFS);
1044 vSetType(tvc, VREG);
1046 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
1047 tvc->v.v_vfsprev = NULL;
1048 afs_globalVFS->vfs_vnodes = &tvc->v;
1049 if (tvc->v.v_vfsnext != NULL)
1050 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
1051 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us! */
1052 gnodepnt->gn_vnode = &tvc->v;
1054 #if defined(AFS_DUX40_ENV)
1055 insmntque(tvc, afs_globalVFS, &afs_ubcops);
1058 /* Is this needed??? */
1059 insmntque(tvc, afs_globalVFS);
1060 #endif /* AFS_OSF_ENV */
1061 #endif /* AFS_DUX40_ENV */
1062 #if defined(AFS_SGI_ENV)
1063 VN_SET_DPAGES(&(tvc->v), (struct pfdat *)NULL);
1064 osi_Assert((tvc->v.v_flag & VINACT) == 0);
1066 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
1067 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
1068 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
1069 osi_Assert(tvc->v.v_filocks == NULL);
1070 #if !defined(AFS_SGI65_ENV)
1071 osi_Assert(tvc->v.v_filocksem == NULL);
1073 osi_Assert(tvc->cred == NULL);
1074 #ifdef AFS_SGI64_ENV
1075 vnode_pcache_reinit(&tvc->v);
1076 tvc->v.v_rdev = NODEV;
1078 vn_initlist((struct vnlist *)&tvc->v);
1080 #endif /* AFS_SGI_ENV */
1082 osi_dnlc_purgedp(tvc); /* this may be overkill */
1083 memset((char *)&(tvc->quick), 0, sizeof(struct vtodc));
1084 memset((char *)&(tvc->callsort), 0, sizeof(struct afs_q));
1088 tvc->hnext = afs_vhashT[i];
1089 afs_vhashT[i] = tvc;
1090 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1091 refpanic("NewVCache VLRU inconsistent");
1093 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
1094 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1095 refpanic("NewVCache VLRU inconsistent2");
1097 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1098 refpanic("NewVCache VLRU inconsistent3");
1100 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1101 refpanic("NewVCache VLRU inconsistent4");
1107 } /*afs_NewVCache */
1111 * afs_FlushActiveVcaches
1117 * doflocks : Do we handle flocks?
1119 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1121 afs_FlushActiveVcaches(register afs_int32 doflocks)
1123 register struct vcache *tvc;
1125 register struct conn *tc;
1126 register afs_int32 code;
1127 register struct AFS_UCRED *cred = NULL;
1128 struct vrequest treq, ureq;
1129 struct AFSVolSync tsync;
1132 AFS_STATCNT(afs_FlushActiveVcaches);
1133 ObtainReadLock(&afs_xvcache);
1134 for (i = 0; i < VCSIZE; i++) {
1135 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1136 if (doflocks && tvc->flockCount != 0) {
1137 /* if this entry has an flock, send a keep-alive call out */
1139 ReleaseReadLock(&afs_xvcache);
1140 ObtainWriteLock(&tvc->lock, 51);
1142 afs_InitReq(&treq, afs_osi_credp);
1143 treq.flags |= O_NONBLOCK;
1145 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1147 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1150 RXAFS_ExtendLock(tc->id,
1151 (struct AFSFid *)&tvc->fid.Fid,
1157 } while (afs_Analyze
1158 (tc, code, &tvc->fid, &treq,
1159 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1161 ReleaseWriteLock(&tvc->lock);
1162 ObtainReadLock(&afs_xvcache);
1166 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1168 * Don't let it evaporate in case someone else is in
1169 * this code. Also, drop the afs_xvcache lock while
1170 * getting vcache locks.
1173 ReleaseReadLock(&afs_xvcache);
1174 #ifdef AFS_BOZONLOCK_ENV
1175 afs_BozonLock(&tvc->pvnLock, tvc);
1177 #if defined(AFS_SGI_ENV)
1179 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1181 osi_Assert(VREFCOUNT(tvc) > 0);
1182 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1184 ObtainWriteLock(&tvc->lock, 52);
1185 if (tvc->states & CCore) {
1186 tvc->states &= ~CCore;
1187 /* XXXX Find better place-holder for cred XXXX */
1188 cred = (struct AFS_UCRED *)tvc->linkData;
1189 tvc->linkData = NULL; /* XXX */
1190 afs_InitReq(&ureq, cred);
1191 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1192 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1193 tvc->execsOrWriters);
1194 code = afs_StoreOnLastReference(tvc, &ureq);
1195 ReleaseWriteLock(&tvc->lock);
1196 #ifdef AFS_BOZONLOCK_ENV
1197 afs_BozonUnlock(&tvc->pvnLock, tvc);
1199 hzero(tvc->flushDV);
1202 if (code && code != VNOVNODE) {
1203 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1204 /* /dev/console */ 1);
1206 } else if (tvc->states & CUnlinkedDel) {
1210 ReleaseWriteLock(&tvc->lock);
1211 #ifdef AFS_BOZONLOCK_ENV
1212 afs_BozonUnlock(&tvc->pvnLock, tvc);
1214 #if defined(AFS_SGI_ENV)
1215 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1217 afs_remunlink(tvc, 0);
1218 #if defined(AFS_SGI_ENV)
1219 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1222 /* lost (or won, perhaps) the race condition */
1223 ReleaseWriteLock(&tvc->lock);
1224 #ifdef AFS_BOZONLOCK_ENV
1225 afs_BozonUnlock(&tvc->pvnLock, tvc);
1228 #if defined(AFS_SGI_ENV)
1229 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1231 ObtainReadLock(&afs_xvcache);
1234 AFS_RELE(AFSTOV(tvc));
1235 /* Matches write code setting CCore flag */
1239 #ifdef AFS_DARWIN_ENV
1240 if (VREFCOUNT(tvc) == 1 + DARWIN_REFBASE
1241 && UBCINFOEXISTS(&tvc->v)) {
1243 panic("flushactive open, hasubc, but refcnt 1");
1244 osi_VM_TryReclaim(tvc, 0);
1249 ReleaseReadLock(&afs_xvcache);
1257 * Make sure a cache entry is up-to-date status-wise.
1259 * NOTE: everywhere that calls this can potentially be sped up
1260 * by checking CStatd first, and avoiding doing the InitReq
1261 * if this is up-to-date.
1263 * Anymore, the only places that call this KNOW already that the
1264 * vcache is not up-to-date, so we don't screw around.
1267 * avc : Ptr to vcache entry to verify.
1272 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1274 register struct vcache *tvc;
1276 AFS_STATCNT(afs_VerifyVCache);
1278 #if defined(AFS_OSF_ENV)
1279 ObtainReadLock(&avc->lock);
1280 if (afs_IsWired(avc)) {
1281 ReleaseReadLock(&avc->lock);
1284 ReleaseReadLock(&avc->lock);
1285 #endif /* AFS_OSF_ENV */
1286 /* otherwise we must fetch the status info */
1288 ObtainWriteLock(&avc->lock, 53);
1289 if (avc->states & CStatd) {
1290 ReleaseWriteLock(&avc->lock);
1293 ObtainWriteLock(&afs_xcbhash, 461);
1294 avc->states &= ~(CStatd | CUnique);
1295 avc->callback = NULL;
1296 afs_DequeueCallback(avc);
1297 ReleaseWriteLock(&afs_xcbhash);
1298 ReleaseWriteLock(&avc->lock);
1300 /* since we've been called back, or the callback has expired,
1301 * it's possible that the contents of this directory, or this
1302 * file's name have changed, thus invalidating the dnlc contents.
1304 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1305 osi_dnlc_purgedp(avc);
1307 osi_dnlc_purgevp(avc);
1309 /* fetch the status info */
1310 tvc = afs_GetVCache(&avc->fid, areq, NULL, avc);
1313 /* Put it back; caller has already incremented vrefCount */
1317 } /*afs_VerifyVCache */
1324 * Simple copy of stat info into cache.
1327 * avc : Ptr to vcache entry involved.
1328 * astat : Ptr to stat info to copy.
1331 * Nothing interesting.
1333 * Callers: as of 1992-04-29, only called by WriteVCache
1336 afs_SimpleVStat(register struct vcache *avc,
1337 register struct AFSFetchStatus *astat, struct vrequest *areq)
1340 AFS_STATCNT(afs_SimpleVStat);
1343 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1344 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1346 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1348 #ifdef AFS_64BIT_CLIENT
1349 FillInt64(length, astat->Length_hi, astat->Length);
1350 #else /* AFS_64BIT_CLIENT */
1351 length = astat->Length;
1352 #endif /* AFS_64BIT_CLIENT */
1353 #if defined(AFS_SGI_ENV)
1354 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1355 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1356 if (length < avc->m.Length) {
1357 vnode_t *vp = (vnode_t *) avc;
1359 osi_Assert(WriteLocked(&avc->lock));
1360 ReleaseWriteLock(&avc->lock);
1362 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1364 ObtainWriteLock(&avc->lock, 67);
1367 /* if writing the file, don't fetch over this value */
1368 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1369 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1370 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1371 avc->m.Length = length;
1372 avc->m.Date = astat->ClientModTime;
1374 avc->m.Owner = astat->Owner;
1375 avc->m.Group = astat->Group;
1376 avc->m.Mode = astat->UnixModeBits;
1377 if (vType(avc) == VREG) {
1378 avc->m.Mode |= S_IFREG;
1379 } else if (vType(avc) == VDIR) {
1380 avc->m.Mode |= S_IFDIR;
1381 } else if (vType(avc) == VLNK) {
1382 avc->m.Mode |= S_IFLNK;
1383 if ((avc->m.Mode & 0111) == 0)
1386 if (avc->states & CForeign) {
1387 struct axscache *ac;
1388 avc->anyAccess = astat->AnonymousAccess;
1390 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1392 * Caller has at least one bit not covered by anonymous, and
1393 * thus may have interesting rights.
1395 * HOWEVER, this is a really bad idea, because any access query
1396 * for bits which aren't covered by anonymous, on behalf of a user
1397 * who doesn't have any special rights, will result in an answer of
1398 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1399 * It's an especially bad idea under Ultrix, since (due to the lack of
1400 * a proper access() call) it must perform several afs_access() calls
1401 * in order to create magic mode bits that vary according to who makes
1402 * the call. In other words, _every_ stat() generates a test for
1405 #endif /* badidea */
1406 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1407 ac->axess = astat->CallerAccess;
1408 else /* not found, add a new one if possible */
1409 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1413 } /*afs_SimpleVStat */
1420 * Store the status info *only* back to the server for a
1424 * avc : Ptr to the vcache entry.
1425 * astatus : Ptr to the status info to store.
1426 * areq : Ptr to the associated vrequest.
1429 * Must be called with a shared lock held on the vnode.
1433 afs_WriteVCache(register struct vcache *avc,
1434 register struct AFSStoreStatus *astatus,
1435 struct vrequest *areq)
1439 struct AFSFetchStatus OutStatus;
1440 struct AFSVolSync tsync;
1442 AFS_STATCNT(afs_WriteVCache);
1443 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1444 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length));
1447 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1449 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1452 RXAFS_StoreStatus(tc->id, (struct AFSFid *)&avc->fid.Fid,
1453 astatus, &OutStatus, &tsync);
1458 } while (afs_Analyze
1459 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1460 SHARED_LOCK, NULL));
1462 UpgradeSToWLock(&avc->lock, 20);
1464 /* success, do the changes locally */
1465 afs_SimpleVStat(avc, &OutStatus, areq);
1467 * Update the date, too. SimpleVStat didn't do this, since
1468 * it thought we were doing this after fetching new status
1469 * over a file being written.
1471 avc->m.Date = OutStatus.ClientModTime;
1473 /* failure, set up to check with server next time */
1474 ObtainWriteLock(&afs_xcbhash, 462);
1475 afs_DequeueCallback(avc);
1476 avc->states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1477 ReleaseWriteLock(&afs_xcbhash);
1478 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1479 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1481 ConvertWToSLock(&avc->lock);
1484 } /*afs_WriteVCache */
1490 * Copy astat block into vcache info
1493 * avc : Ptr to vcache entry.
1494 * astat : Ptr to stat block to copy in.
1495 * areq : Ptr to associated request.
1498 * Must be called under a write lock
1500 * Note: this code may get dataversion and length out of sync if the file has
1501 * been modified. This is less than ideal. I haven't thought about
1502 * it sufficiently to be certain that it is adequate.
1505 afs_ProcessFS(register struct vcache *avc,
1506 register struct AFSFetchStatus *astat, struct vrequest *areq)
1509 AFS_STATCNT(afs_ProcessFS);
1511 #ifdef AFS_64BIT_CLIENT
1512 FillInt64(length, astat->Length_hi, astat->Length);
1513 #else /* AFS_64BIT_CLIENT */
1514 length = astat->Length;
1515 #endif /* AFS_64BIT_CLIENT */
1516 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1517 * number for each bulk status request. Under no circumstances
1518 * should afs_DoBulkStat store a sequence number if the new
1519 * length will be ignored when afs_ProcessFS is called with
1520 * new stats. If you change the following conditional then you
1521 * also need to change the conditional in afs_DoBulkStat. */
1523 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1524 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1526 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1528 /* if we're writing or mapping this file, don't fetch over these
1531 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1532 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1533 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1534 avc->m.Length = length;
1535 avc->m.Date = astat->ClientModTime;
1537 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1538 avc->m.Owner = astat->Owner;
1539 avc->m.Mode = astat->UnixModeBits;
1540 avc->m.Group = astat->Group;
1541 avc->m.LinkCount = astat->LinkCount;
1542 if (astat->FileType == File) {
1543 vSetType(avc, VREG);
1544 avc->m.Mode |= S_IFREG;
1545 } else if (astat->FileType == Directory) {
1546 vSetType(avc, VDIR);
1547 avc->m.Mode |= S_IFDIR;
1548 } else if (astat->FileType == SymbolicLink) {
1549 if (afs_fakestat_enable && (avc->m.Mode & 0111) == 0) {
1550 vSetType(avc, VDIR);
1551 avc->m.Mode |= S_IFDIR;
1553 vSetType(avc, VLNK);
1554 avc->m.Mode |= S_IFLNK;
1556 if ((avc->m.Mode & 0111) == 0) {
1560 avc->anyAccess = astat->AnonymousAccess;
1562 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1564 * Caller has at least one bit not covered by anonymous, and
1565 * thus may have interesting rights.
1567 * HOWEVER, this is a really bad idea, because any access query
1568 * for bits which aren't covered by anonymous, on behalf of a user
1569 * who doesn't have any special rights, will result in an answer of
1570 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1571 * It's an especially bad idea under Ultrix, since (due to the lack of
1572 * a proper access() call) it must perform several afs_access() calls
1573 * in order to create magic mode bits that vary according to who makes
1574 * the call. In other words, _every_ stat() generates a test for
1577 #endif /* badidea */
1579 struct axscache *ac;
1580 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1581 ac->axess = astat->CallerAccess;
1582 else /* not found, add a new one if possible */
1583 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1585 #ifdef AFS_LINUX22_ENV
1586 vcache2inode(avc); /* Set the inode attr cache */
1588 #ifdef AFS_DARWIN_ENV
1589 osi_VM_Setup(avc, 1);
1592 } /*afs_ProcessFS */
1596 afs_RemoteLookup(register struct VenusFid *afid, struct vrequest *areq,
1597 char *name, struct VenusFid *nfid,
1598 struct AFSFetchStatus *OutStatusp,
1599 struct AFSCallBack *CallBackp, struct server **serverp,
1600 struct AFSVolSync *tsyncp)
1604 register struct conn *tc;
1605 struct AFSFetchStatus OutDirStatus;
1608 name = ""; /* XXX */
1610 tc = afs_Conn(afid, areq, SHARED_LOCK);
1613 *serverp = tc->srvr->server;
1615 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1618 RXAFS_Lookup(tc->id, (struct AFSFid *)&afid->Fid, name,
1619 (struct AFSFid *)&nfid->Fid, OutStatusp,
1620 &OutDirStatus, CallBackp, tsyncp);
1625 } while (afs_Analyze
1626 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1637 * Given a file id and a vrequest structure, fetch the status
1638 * information associated with the file.
1642 * areq : Ptr to associated vrequest structure, specifying the
1643 * user whose authentication tokens will be used.
1644 * avc : caller may already have a vcache for this file, which is
1648 * The cache entry is returned with an increased vrefCount field.
1649 * The entry must be discarded by calling afs_PutVCache when you
1650 * are through using the pointer to the cache entry.
1652 * You should not hold any locks when calling this function, except
1653 * locks on other vcache entries. If you lock more than one vcache
1654 * entry simultaneously, you should lock them in this order:
1656 * 1. Lock all files first, then directories.
1657 * 2. Within a particular type, lock entries in Fid.Vnode order.
1659 * This locking hierarchy is convenient because it allows locking
1660 * of a parent dir cache entry, given a file (to check its access
1661 * control list). It also allows renames to be handled easily by
1662 * locking directories in a constant order.
1663 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1665 /* might have a vcache structure already, which must
1666 * already be held by the caller */
1669 afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq,
1670 afs_int32 * cached, struct vcache *avc)
1673 afs_int32 code, newvcache = 0;
1674 register struct vcache *tvc;
1678 AFS_STATCNT(afs_GetVCache);
1681 *cached = 0; /* Init just in case */
1683 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1687 ObtainSharedLock(&afs_xvcache, 5);
1689 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU);
1691 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1692 ReleaseSharedLock(&afs_xvcache);
1693 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1701 if (tvc->states & CStatd) {
1702 ReleaseSharedLock(&afs_xvcache);
1706 UpgradeSToWLock(&afs_xvcache, 21);
1708 /* no cache entry, better grab one */
1709 tvc = afs_NewVCache(afid, NULL);
1712 ConvertWToSLock(&afs_xvcache);
1713 afs_stats_cmperf.vcacheMisses++;
1716 ReleaseSharedLock(&afs_xvcache);
1718 ObtainWriteLock(&tvc->lock, 54);
1720 if (tvc->states & CStatd) {
1721 #ifdef AFS_LINUX22_ENV
1724 ReleaseWriteLock(&tvc->lock);
1725 #ifdef AFS_DARWIN_ENV
1726 osi_VM_Setup(tvc, 0);
1730 #if defined(AFS_OSF_ENV)
1731 if (afs_IsWired(tvc)) {
1732 ReleaseWriteLock(&tvc->lock);
1735 #endif /* AFS_OSF_ENV */
1737 VOP_LOCK(AFSTOV(tvc), LK_EXCLUSIVE | LK_RETRY, curproc);
1738 uvm_vnp_uncache(AFSTOV(tvc));
1739 VOP_UNLOCK(AFSTOV(tvc), 0, curproc);
1743 * XXX - I really don't like this. Should try to understand better.
1744 * It seems that sometimes, when we get called, we already hold the
1745 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1746 * We can't drop the vnode lock, because that could result in a race.
1747 * Sometimes, though, we get here and don't hold the vnode lock.
1748 * I hate code paths that sometimes hold locks and sometimes don't.
1749 * In any event, the dodge we use here is to check whether the vnode
1750 * is locked, and if it isn't, then we gain and drop it around the call
1751 * to vinvalbuf; otherwise, we leave it alone.
1758 #ifdef AFS_FBSD50_ENV
1759 iheldthelock = VOP_ISLOCKED(vp, curthread);
1761 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1762 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1764 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1766 iheldthelock = VOP_ISLOCKED(vp, curproc);
1768 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1769 vinvalbuf(vp, V_SAVE, osi_curcred(), curproc, PINOD, 0);
1771 VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
1776 ObtainWriteLock(&afs_xcbhash, 464);
1777 tvc->states &= ~CUnique;
1779 afs_DequeueCallback(tvc);
1780 ReleaseWriteLock(&afs_xcbhash);
1782 /* It is always appropriate to throw away all the access rights? */
1783 afs_FreeAllAxs(&(tvc->Access));
1784 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1786 if ((tvp->states & VForeign)) {
1788 tvc->states |= CForeign;
1789 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1790 && (tvp->rootUnique == afid->Fid.Unique)) {
1794 if (tvp->states & VRO)
1796 if (tvp->states & VBackup)
1797 tvc->states |= CBackup;
1798 /* now copy ".." entry back out of volume structure, if necessary */
1799 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1801 tvc->mvid = (struct VenusFid *)
1802 osi_AllocSmallSpace(sizeof(struct VenusFid));
1803 *tvc->mvid = tvp->dotdot;
1805 afs_PutVolume(tvp, READ_LOCK);
1809 afs_RemoveVCB(afid);
1811 struct AFSFetchStatus OutStatus;
1813 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1814 afs_ProcessFS(tvc, &OutStatus, areq);
1815 tvc->states |= CStatd | CUnique;
1818 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1823 ReleaseWriteLock(&tvc->lock);
1825 ObtainReadLock(&afs_xvcache);
1827 ReleaseReadLock(&afs_xvcache);
1831 ReleaseWriteLock(&tvc->lock);
1834 } /*afs_GetVCache */
1839 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1840 afs_int32 * cached, struct vcache *adp, char *aname)
1842 afs_int32 code, now, newvcache = 0;
1843 struct VenusFid nfid;
1844 register struct vcache *tvc;
1846 struct AFSFetchStatus OutStatus;
1847 struct AFSCallBack CallBack;
1848 struct AFSVolSync tsync;
1849 struct server *serverp = 0;
1853 AFS_STATCNT(afs_GetVCache);
1855 *cached = 0; /* Init just in case */
1857 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1861 ObtainReadLock(&afs_xvcache);
1862 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
1865 ReleaseReadLock(&afs_xvcache);
1867 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1868 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1872 ObtainReadLock(&tvc->lock);
1874 if (tvc->states & CStatd) {
1878 ReleaseReadLock(&tvc->lock);
1881 tvc->states &= ~CUnique;
1883 ReleaseReadLock(&tvc->lock);
1884 ObtainReadLock(&afs_xvcache);
1888 ReleaseReadLock(&afs_xvcache);
1890 /* lookup the file */
1893 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1895 afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1898 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1902 ObtainSharedLock(&afs_xvcache, 6);
1903 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU /* no xstats now */ );
1905 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1906 ReleaseSharedLock(&afs_xvcache);
1907 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1913 /* no cache entry, better grab one */
1914 UpgradeSToWLock(&afs_xvcache, 22);
1915 tvc = afs_NewVCache(&nfid, serverp);
1917 ConvertWToSLock(&afs_xvcache);
1920 ReleaseSharedLock(&afs_xvcache);
1921 ObtainWriteLock(&tvc->lock, 55);
1923 /* It is always appropriate to throw away all the access rights? */
1924 afs_FreeAllAxs(&(tvc->Access));
1925 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1927 if ((tvp->states & VForeign)) {
1929 tvc->states |= CForeign;
1930 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1931 && (tvp->rootUnique == afid->Fid.Unique))
1934 if (tvp->states & VRO)
1936 if (tvp->states & VBackup)
1937 tvc->states |= CBackup;
1938 /* now copy ".." entry back out of volume structure, if necessary */
1939 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1941 tvc->mvid = (struct VenusFid *)
1942 osi_AllocSmallSpace(sizeof(struct VenusFid));
1943 *tvc->mvid = tvp->dotdot;
1948 ObtainWriteLock(&afs_xcbhash, 465);
1949 afs_DequeueCallback(tvc);
1950 tvc->states &= ~(CStatd | CUnique);
1951 ReleaseWriteLock(&afs_xcbhash);
1952 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1953 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1955 afs_PutVolume(tvp, READ_LOCK);
1956 ReleaseWriteLock(&tvc->lock);
1957 ObtainReadLock(&afs_xvcache);
1959 ReleaseReadLock(&afs_xvcache);
1963 ObtainWriteLock(&afs_xcbhash, 466);
1964 if (origCBs == afs_allCBs) {
1965 if (CallBack.ExpirationTime) {
1966 tvc->callback = serverp;
1967 tvc->cbExpires = CallBack.ExpirationTime + now;
1968 tvc->states |= CStatd | CUnique;
1969 tvc->states &= ~CBulkFetching;
1970 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1971 } else if (tvc->states & CRO) {
1972 /* adapt gives us an hour. */
1973 tvc->cbExpires = 3600 + osi_Time();
1974 /*XXX*/ tvc->states |= CStatd | CUnique;
1975 tvc->states &= ~CBulkFetching;
1976 afs_QueueCallback(tvc, CBHash(3600), tvp);
1978 tvc->callback = NULL;
1979 afs_DequeueCallback(tvc);
1980 tvc->states &= ~(CStatd | CUnique);
1981 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1982 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1985 afs_DequeueCallback(tvc);
1986 tvc->states &= ~CStatd;
1987 tvc->states &= ~CUnique;
1988 tvc->callback = NULL;
1989 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1990 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1992 ReleaseWriteLock(&afs_xcbhash);
1994 afs_PutVolume(tvp, READ_LOCK);
1995 afs_ProcessFS(tvc, &OutStatus, areq);
1997 ReleaseWriteLock(&tvc->lock);
2003 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2004 afs_int32 * cached, struct volume *tvolp)
2006 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2007 afs_int32 getNewFid = 0;
2009 struct VenusFid nfid;
2010 register struct vcache *tvc;
2011 struct server *serverp = 0;
2012 struct AFSFetchStatus OutStatus;
2013 struct AFSCallBack CallBack;
2014 struct AFSVolSync tsync;
2020 if (!tvolp->rootVnode || getNewFid) {
2021 struct VenusFid tfid;
2024 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2025 origCBs = afs_allCBs; /* ignore InitCallBackState */
2027 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2032 /* ReleaseReadLock(&tvolp->lock); */
2033 ObtainWriteLock(&tvolp->lock, 56);
2034 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2035 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2036 ReleaseWriteLock(&tvolp->lock);
2037 /* ObtainReadLock(&tvolp->lock);*/
2040 afid->Fid.Vnode = tvolp->rootVnode;
2041 afid->Fid.Unique = tvolp->rootUnique;
2044 ObtainSharedLock(&afs_xvcache, 7);
2046 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2047 if (!FidCmp(&(tvc->fid), afid)) {
2049 /* Grab this vnode, possibly reactivating from the free list */
2050 /* for the present (95.05.25) everything on the hash table is
2051 * definitively NOT in the free list -- at least until afs_reclaim
2052 * can be safely implemented */
2055 vg = vget(AFSTOV(tvc)); /* this bumps ref count */
2059 #endif /* AFS_OSF_ENV */
2060 #ifdef AFS_DARWIN14_ENV
2061 /* It'd really suck if we allowed duplicate vcaches for the
2062 * same fid to happen. Wonder if this will work? */
2063 struct vnode *vp = AFSTOV(tvc);
2064 if (vp->v_flag & (VXLOCK | VORECLAIM | VTERMINATE)) {
2065 printf("precluded FindVCache on %x (%d:%d:%d)\n",
2066 vp, tvc->fid.Fid.Volume, tvc->fid.Fid.Vnode,
2067 tvc->fid.Fid.Unique);
2068 simple_lock(&vp->v_interlock);
2069 SET(vp->v_flag, VTERMWANT);
2070 simple_unlock(&vp->v_interlock);
2071 (void)tsleep((caddr_t) & vp->v_ubcinfo, PINOD, "vget1", 0);
2072 printf("VTERMWANT ended on %x\n", vp);
2080 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
2081 /* Mount point no longer stat'd or unknown. FID may have changed. */
2084 AFS_RELE(AFSTOV(tvc));
2088 ReleaseSharedLock(&afs_xvcache);
2093 UpgradeSToWLock(&afs_xvcache, 23);
2094 /* no cache entry, better grab one */
2095 tvc = afs_NewVCache(afid, NULL);
2097 afs_stats_cmperf.vcacheMisses++;
2101 afs_stats_cmperf.vcacheHits++;
2103 /* we already bumped the ref count in the for loop above */
2104 #else /* AFS_OSF_ENV */
2107 UpgradeSToWLock(&afs_xvcache, 24);
2108 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2109 refpanic("GRVC VLRU inconsistent0");
2111 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2112 refpanic("GRVC VLRU inconsistent1");
2114 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2115 refpanic("GRVC VLRU inconsistent2");
2117 QRemove(&tvc->vlruq); /* move to lruq head */
2118 QAdd(&VLRU, &tvc->vlruq);
2119 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2120 refpanic("GRVC VLRU inconsistent3");
2122 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2123 refpanic("GRVC VLRU inconsistent4");
2125 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2126 refpanic("GRVC VLRU inconsistent5");
2131 ReleaseWriteLock(&afs_xvcache);
2133 if (tvc->states & CStatd) {
2137 ObtainReadLock(&tvc->lock);
2138 tvc->states &= ~CUnique;
2139 tvc->callback = NULL; /* redundant, perhaps */
2140 ReleaseReadLock(&tvc->lock);
2143 ObtainWriteLock(&tvc->lock, 57);
2145 /* It is always appropriate to throw away all the access rights? */
2146 afs_FreeAllAxs(&(tvc->Access));
2149 tvc->states |= CForeign;
2150 if (tvolp->states & VRO)
2152 if (tvolp->states & VBackup)
2153 tvc->states |= CBackup;
2154 /* now copy ".." entry back out of volume structure, if necessary */
2155 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2156 && (tvolp->rootUnique == afid->Fid.Unique)) {
2159 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2161 tvc->mvid = (struct VenusFid *)
2162 osi_AllocSmallSpace(sizeof(struct VenusFid));
2163 *tvc->mvid = tvolp->dotdot;
2167 afs_RemoveVCB(afid);
2170 struct VenusFid tfid;
2173 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2174 origCBs = afs_allCBs; /* ignore InitCallBackState */
2176 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2181 ObtainWriteLock(&afs_xcbhash, 467);
2182 afs_DequeueCallback(tvc);
2183 tvc->callback = NULL;
2184 tvc->states &= ~(CStatd | CUnique);
2185 ReleaseWriteLock(&afs_xcbhash);
2186 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2187 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2188 ReleaseWriteLock(&tvc->lock);
2189 ObtainReadLock(&afs_xvcache);
2191 ReleaseReadLock(&afs_xvcache);
2195 ObtainWriteLock(&afs_xcbhash, 468);
2196 if (origCBs == afs_allCBs) {
2197 tvc->states |= CTruth;
2198 tvc->callback = serverp;
2199 if (CallBack.ExpirationTime != 0) {
2200 tvc->cbExpires = CallBack.ExpirationTime + start;
2201 tvc->states |= CStatd;
2202 tvc->states &= ~CBulkFetching;
2203 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2204 } else if (tvc->states & CRO) {
2205 /* adapt gives us an hour. */
2206 tvc->cbExpires = 3600 + osi_Time();
2207 /*XXX*/ tvc->states |= CStatd;
2208 tvc->states &= ~CBulkFetching;
2209 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2212 afs_DequeueCallback(tvc);
2213 tvc->callback = NULL;
2214 tvc->states &= ~(CStatd | CUnique);
2215 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2216 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2218 ReleaseWriteLock(&afs_xcbhash);
2219 afs_ProcessFS(tvc, &OutStatus, areq);
2221 ReleaseWriteLock(&tvc->lock);
2228 * must be called with avc write-locked
2229 * don't absolutely have to invalidate the hint unless the dv has
2230 * changed, but be sure to get it right else there will be consistency bugs.
2233 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2234 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2237 afs_uint32 start = 0;
2238 register struct conn *tc;
2239 struct AFSCallBack CallBack;
2240 struct AFSVolSync tsync;
2241 struct volume *volp;
2244 tc = afs_Conn(afid, areq, SHARED_LOCK);
2245 avc->quick.stamp = 0;
2246 avc->h1.dchint = NULL; /* invalidate hints */
2248 avc->callback = tc->srvr->server;
2250 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2253 RXAFS_FetchStatus(tc->id, (struct AFSFid *)&afid->Fid, Outsp,
2261 } while (afs_Analyze
2262 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2263 SHARED_LOCK, NULL));
2266 afs_ProcessFS(avc, Outsp, areq);
2267 volp = afs_GetVolume(afid, areq, READ_LOCK);
2268 ObtainWriteLock(&afs_xcbhash, 469);
2269 avc->states |= CTruth;
2270 if (avc->callback /* check for race */ ) {
2271 if (CallBack.ExpirationTime != 0) {
2272 avc->cbExpires = CallBack.ExpirationTime + start;
2273 avc->states |= CStatd;
2274 avc->states &= ~CBulkFetching;
2275 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2276 } else if (avc->states & CRO) { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2277 avc->cbExpires = 3600 + start;
2278 avc->states |= CStatd;
2279 avc->states &= ~CBulkFetching;
2280 afs_QueueCallback(avc, CBHash(3600), volp);
2282 afs_DequeueCallback(avc);
2283 avc->callback = NULL;
2284 avc->states &= ~(CStatd | CUnique);
2285 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2286 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2289 afs_DequeueCallback(avc);
2290 avc->callback = NULL;
2291 avc->states &= ~(CStatd | CUnique);
2292 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2293 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2295 ReleaseWriteLock(&afs_xcbhash);
2297 afs_PutVolume(volp, READ_LOCK);
2299 /* used to undo the local callback, but that's too extreme.
2300 * There are plenty of good reasons that fetchstatus might return
2301 * an error, such as EPERM. If we have the vnode cached, statd,
2302 * with callback, might as well keep track of the fact that we
2303 * don't have access...
2305 if (code == EPERM || code == EACCES) {
2306 struct axscache *ac;
2307 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2309 else /* not found, add a new one if possible */
2310 afs_AddAxs(avc->Access, areq->uid, 0);
2321 * Stuff some information into the vcache for the given file.
2324 * afid : File in question.
2325 * OutStatus : Fetch status on the file.
2326 * CallBack : Callback info.
2327 * tc : RPC connection involved.
2328 * areq : vrequest involved.
2331 * Nothing interesting.
2334 afs_StuffVcache(register struct VenusFid *afid,
2335 struct AFSFetchStatus *OutStatus,
2336 struct AFSCallBack *CallBack, register struct conn *tc,
2337 struct vrequest *areq)
2339 register afs_int32 code, i, newvcache = 0;
2340 register struct vcache *tvc;
2341 struct AFSVolSync tsync;
2343 struct axscache *ac;
2346 AFS_STATCNT(afs_StuffVcache);
2347 #ifdef IFS_VCACHECOUNT
2352 ObtainSharedLock(&afs_xvcache, 8);
2354 tvc = afs_FindVCache(afid, &retry, DO_VLRU /* no stats */ );
2356 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2357 ReleaseSharedLock(&afs_xvcache);
2358 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2364 /* no cache entry, better grab one */
2365 UpgradeSToWLock(&afs_xvcache, 25);
2366 tvc = afs_NewVCache(afid, NULL);
2368 ConvertWToSLock(&afs_xvcache);
2371 ReleaseSharedLock(&afs_xvcache);
2372 ObtainWriteLock(&tvc->lock, 58);
2374 tvc->states &= ~CStatd;
2375 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2376 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2378 /* Is it always appropriate to throw away all the access rights? */
2379 afs_FreeAllAxs(&(tvc->Access));
2381 /*Copy useful per-volume info */
2382 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2384 if (newvcache && (tvp->states & VForeign))
2385 tvc->states |= CForeign;
2386 if (tvp->states & VRO)
2388 if (tvp->states & VBackup)
2389 tvc->states |= CBackup;
2391 * Now, copy ".." entry back out of volume structure, if
2394 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2396 tvc->mvid = (struct VenusFid *)
2397 osi_AllocSmallSpace(sizeof(struct VenusFid));
2398 *tvc->mvid = tvp->dotdot;
2401 /* store the stat on the file */
2402 afs_RemoveVCB(afid);
2403 afs_ProcessFS(tvc, OutStatus, areq);
2404 tvc->callback = tc->srvr->server;
2406 /* we use osi_Time twice below. Ideally, we would use the time at which
2407 * the FetchStatus call began, instead, but we don't have it here. So we
2408 * make do with "now". In the CRO case, it doesn't really matter. In
2409 * the other case, we hope that the difference between "now" and when the
2410 * call actually began execution on the server won't be larger than the
2411 * padding which the server keeps. Subtract 1 second anyway, to be on
2412 * the safe side. Can't subtract more because we don't know how big
2413 * ExpirationTime is. Possible consistency problems may arise if the call
2414 * timeout period becomes longer than the server's expiration padding. */
2415 ObtainWriteLock(&afs_xcbhash, 470);
2416 if (CallBack->ExpirationTime != 0) {
2417 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2418 tvc->states |= CStatd;
2419 tvc->states &= ~CBulkFetching;
2420 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2421 } else if (tvc->states & CRO) {
2422 /* old-fashioned AFS 3.2 style */
2423 tvc->cbExpires = 3600 + osi_Time();
2424 /*XXX*/ tvc->states |= CStatd;
2425 tvc->states &= ~CBulkFetching;
2426 afs_QueueCallback(tvc, CBHash(3600), tvp);
2428 afs_DequeueCallback(tvc);
2429 tvc->callback = NULL;
2430 tvc->states &= ~(CStatd | CUnique);
2431 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2432 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2434 ReleaseWriteLock(&afs_xcbhash);
2436 afs_PutVolume(tvp, READ_LOCK);
2438 /* look in per-pag cache */
2439 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2440 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2441 else /* not found, add a new one if possible */
2442 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2444 ReleaseWriteLock(&tvc->lock);
2445 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2446 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2447 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2449 * Release ref count... hope this guy stays around...
2452 } /*afs_StuffVcache */
2459 * Decrements the reference count on a cache entry.
2462 * avc : Pointer to the cache entry to decrement.
2465 * Nothing interesting.
2468 afs_PutVCache(register struct vcache *avc)
2470 AFS_STATCNT(afs_PutVCache);
2472 * Can we use a read lock here?
2474 ObtainReadLock(&afs_xvcache);
2476 ReleaseReadLock(&afs_xvcache);
2477 } /*afs_PutVCache */
2483 * Find a vcache entry given a fid.
2486 * afid : Pointer to the fid whose cache entry we desire.
2487 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2488 * unlock the vnode, and try again.
2489 * flags: bit 1 to specify whether to compute hit statistics. Not
2490 * set if FindVCache is called as part of internal bookkeeping.
2493 * Must be called with the afs_xvcache lock at least held at
2494 * the read level. In order to do the VLRU adjustment, the xvcache lock
2495 * must be shared-- we upgrade it here.
2499 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2502 register struct vcache *tvc;
2505 AFS_STATCNT(afs_FindVCache);
2508 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2509 if (FidMatches(afid, tvc)) {
2511 /* Grab this vnode, possibly reactivating from the free list */
2514 vg = vget(AFSTOV(tvc));
2518 #endif /* AFS_OSF_ENV */
2523 /* should I have a read lock on the vnode here? */
2527 #if !defined(AFS_OSF_ENV)
2528 osi_vnhold(tvc, retry); /* already held, above */
2529 if (retry && *retry)
2533 * only move to front of vlru if we have proper vcache locking)
2535 if (flag & DO_VLRU) {
2536 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2537 refpanic("FindVC VLRU inconsistent1");
2539 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2540 refpanic("FindVC VLRU inconsistent1");
2542 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2543 refpanic("FindVC VLRU inconsistent2");
2545 UpgradeSToWLock(&afs_xvcache, 26);
2546 QRemove(&tvc->vlruq);
2547 QAdd(&VLRU, &tvc->vlruq);
2548 ConvertWToSLock(&afs_xvcache);
2549 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2550 refpanic("FindVC VLRU inconsistent1");
2552 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2553 refpanic("FindVC VLRU inconsistent2");
2555 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2556 refpanic("FindVC VLRU inconsistent3");
2562 if (flag & DO_STATS) {
2564 afs_stats_cmperf.vcacheHits++;
2566 afs_stats_cmperf.vcacheMisses++;
2567 if (afs_IsPrimaryCellNum(afid->Cell))
2568 afs_stats_cmperf.vlocalAccesses++;
2570 afs_stats_cmperf.vremoteAccesses++;
2572 #ifdef AFS_LINUX22_ENV
2573 if (tvc && (tvc->states & CStatd))
2574 vcache2inode(tvc); /* mainly to reset i_nlink */
2576 #ifdef AFS_DARWIN_ENV
2578 osi_VM_Setup(tvc, 0);
2581 } /*afs_FindVCache */
2587 * Find a vcache entry given a fid. Does a wildcard match on what we
2588 * have for the fid. If more than one entry, don't return anything.
2591 * avcp : Fill in pointer if we found one and only one.
2592 * afid : Pointer to the fid whose cache entry we desire.
2593 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2594 * unlock the vnode, and try again.
2595 * flags: bit 1 to specify whether to compute hit statistics. Not
2596 * set if FindVCache is called as part of internal bookkeeping.
2599 * Must be called with the afs_xvcache lock at least held at
2600 * the read level. In order to do the VLRU adjustment, the xvcache lock
2601 * must be shared-- we upgrade it here.
2604 * number of matches found.
2607 int afs_duplicate_nfs_fids = 0;
2610 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2612 register struct vcache *tvc;
2614 afs_int32 count = 0;
2615 struct vcache *found_tvc = NULL;
2617 AFS_STATCNT(afs_FindVCache);
2619 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2623 ObtainSharedLock(&afs_xvcache, 331);
2626 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2627 /* Match only on what we have.... */
2628 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2629 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2630 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2631 && (tvc->fid.Cell == afid->Cell)) {
2633 /* Grab this vnode, possibly reactivating from the free list */
2636 vg = vget(AFSTOV(tvc));
2639 /* This vnode no longer exists. */
2642 #endif /* AFS_OSF_ENV */
2647 /* Drop our reference counts. */
2649 vrele(AFSTOV(found_tvc));
2651 afs_duplicate_nfs_fids++;
2652 ReleaseSharedLock(&afs_xvcache);
2660 /* should I have a read lock on the vnode here? */
2662 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2663 afs_int32 retry = 0;
2664 osi_vnhold(tvc, &retry);
2667 found_tvc = (struct vcache *)0;
2668 ReleaseSharedLock(&afs_xvcache);
2669 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2673 #if !defined(AFS_OSF_ENV)
2674 osi_vnhold(tvc, (int *)0); /* already held, above */
2678 * We obtained the xvcache lock above.
2680 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2681 refpanic("FindVC VLRU inconsistent1");
2683 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2684 refpanic("FindVC VLRU inconsistent1");
2686 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2687 refpanic("FindVC VLRU inconsistent2");
2689 UpgradeSToWLock(&afs_xvcache, 568);
2690 QRemove(&tvc->vlruq);
2691 QAdd(&VLRU, &tvc->vlruq);
2692 ConvertWToSLock(&afs_xvcache);
2693 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2694 refpanic("FindVC VLRU inconsistent1");
2696 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2697 refpanic("FindVC VLRU inconsistent2");
2699 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2700 refpanic("FindVC VLRU inconsistent3");
2706 afs_stats_cmperf.vcacheHits++;
2708 afs_stats_cmperf.vcacheMisses++;
2709 if (afs_IsPrimaryCellNum(afid->Cell))
2710 afs_stats_cmperf.vlocalAccesses++;
2712 afs_stats_cmperf.vremoteAccesses++;
2714 *avcp = tvc; /* May be null */
2716 ReleaseSharedLock(&afs_xvcache);
2717 return (tvc ? 1 : 0);
2719 } /*afs_NFSFindVCache */
2727 * Initialize vcache related variables
2730 afs_vcacheInit(int astatSize)
2732 register struct vcache *tvp;
2734 #if defined(AFS_OSF_ENV)
2735 if (!afs_maxvcount) {
2736 #if defined(AFS_OSF30_ENV)
2737 afs_maxvcount = max_vnodes / 2; /* limit ourselves to half the total */
2739 afs_maxvcount = nvnode / 2; /* limit ourselves to half the total */
2741 if (astatSize < afs_maxvcount) {
2742 afs_maxvcount = astatSize;
2745 #else /* AFS_OSF_ENV */
2749 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2750 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2752 #if !defined(AFS_OSF_ENV)
2753 #ifdef AFS_LINUX26_ENV
2754 printf("old style would have needed %d contiguous bytes\n", astatSize *
2755 sizeof(struct vcache));
2756 Initial_freeVCList = freeVCList = tvp = (struct vcache *)
2757 afs_osi_Alloc(sizeof(struct vcache));
2758 for (i = 0; i < astatSize; i++) {
2759 tvp->nextfree = (struct vcache *) afs_osi_Alloc(sizeof(struct vcache));
2760 tvp = tvp->nextfree;
2762 tvp->nextfree = NULL;
2764 /* Allocate and thread the struct vcache entries */
2765 tvp = (struct vcache *)afs_osi_Alloc(astatSize * sizeof(struct vcache));
2766 memset((char *)tvp, 0, sizeof(struct vcache) * astatSize);
2768 Initial_freeVCList = tvp;
2769 freeVCList = &(tvp[0]);
2770 for (i = 0; i < astatSize - 1; i++) {
2771 tvp[i].nextfree = &(tvp[i + 1]);
2773 tvp[astatSize - 1].nextfree = NULL;
2774 #ifdef KERNEL_HAVE_PIN
2775 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2780 #if defined(AFS_SGI_ENV)
2781 for (i = 0; i < astatSize; i++) {
2782 char name[METER_NAMSZ];
2783 struct vcache *tvc = &tvp[i];
2785 tvc->v.v_number = ++afsvnumbers;
2786 tvc->vc_rwlockid = OSI_NO_LOCKID;
2787 initnsema(&tvc->vc_rwlock, 1,
2788 makesname(name, "vrw", tvc->v.v_number));
2789 #ifndef AFS_SGI53_ENV
2790 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2792 #ifndef AFS_SGI62_ENV
2793 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2794 #endif /* AFS_SGI62_ENV */
2808 shutdown_vcache(void)
2811 struct afs_cbr *tsp, *nsp;
2813 * XXX We may potentially miss some of the vcaches because if when there're no
2814 * free vcache entries and all the vcache entries are active ones then we allocate
2815 * an additional one - admittedly we almost never had that occur.
2819 register struct afs_q *tq, *uq;
2820 register struct vcache *tvc;
2821 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2825 osi_FreeSmallSpace(tvc->mvid);
2826 tvc->mvid = (struct VenusFid *)0;
2829 aix_gnode_rele(AFSTOV(tvc));
2831 if (tvc->linkData) {
2832 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2837 * Also free the remaining ones in the Cache
2839 for (i = 0; i < VCSIZE; i++) {
2840 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2842 osi_FreeSmallSpace(tvc->mvid);
2843 tvc->mvid = (struct VenusFid *)0;
2847 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2848 #ifdef AFS_AIX32_ENV
2851 vms_delete(tvc->segid);
2853 tvc->segid = tvc->vmh = NULL;
2855 osi_Panic("flushVcache: vm race");
2863 #if defined(AFS_SUN5_ENV)
2869 if (tvc->linkData) {
2870 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2874 afs_FreeAllAxs(&(tvc->Access));
2880 * Free any leftover callback queue
2882 for (tsp = afs_cbrSpace; tsp; tsp = nsp) {
2884 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2888 #ifdef AFS_LINUX26_ENV
2890 struct vcache *tvp = Initial_freeVCList;
2892 struct vcache *next = tvp->nextfree;
2894 afs_osi_Free(tvp, sizeof(struct vcache));
2899 #ifdef KERNEL_HAVE_PIN
2900 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2902 #if !defined(AFS_OSF_ENV)
2903 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2907 #if !defined(AFS_OSF_ENV)
2908 freeVCList = Initial_freeVCList = 0;
2910 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2911 LOCK_INIT(&afs_xvcb, "afs_xvcb");