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;
585 struct vm_info *vm_info_ptr;
586 #endif /* AFS_MACH_ENV */
589 #endif /* AFS_OSF_ENV */
590 struct afs_q *tq, *uq;
593 AFS_STATCNT(afs_NewVCache);
596 if (afs_vcount >= afs_maxvcount) {
599 * If we are using > 33 % of the total system vnodes for AFS vcache
600 * entries or we are using the maximum number of vcache entries,
601 * then free some. (if our usage is > 33% we should free some, if
602 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
603 * we _must_ free some -- no choice).
605 if (((3 * afs_vcount) > nvnode) || (afs_vcount >= afs_maxvcount)) {
607 struct afs_q *tq, *uq;
612 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
615 if (tvc->states & CVFlushed)
616 refpanic("CVFlushed on VLRU");
617 else if (i++ > afs_maxvcount)
618 refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)");
619 else if (QNext(uq) != tq)
620 refpanic("VLRU inconsistent");
621 else if (VREFCOUNT(tvc) < 1)
622 refpanic("refcnt 0 on VLRU");
624 if (VREFCOUNT(tvc) == 1 && tvc->opens == 0
625 && (tvc->states & CUnlinkedDel) == 0) {
626 code = afs_FlushVCache(tvc, &fv_slept);
633 continue; /* start over - may have raced. */
639 if (anumber == VCACHE_FREE) {
640 printf("NewVCache: warning none freed, using %d of %d\n",
641 afs_vcount, afs_maxvcount);
642 if (afs_vcount >= afs_maxvcount) {
643 osi_Panic("NewVCache - none freed");
644 /* XXX instead of panicing, should do afs_maxvcount++
645 * and magic up another one */
651 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
652 /* What should we do ???? */
653 osi_Panic("afs_NewVCache: no more vnodes");
658 tvc->nextfree = NULL;
660 #else /* AFS_OSF_ENV */
661 /* pull out a free cache entry */
664 for (tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
668 if (tvc->states & CVFlushed) {
669 refpanic("CVFlushed on VLRU");
670 } else if (i++ > 2 * afs_cacheStats) { /* even allowing for a few xallocs... */
671 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
672 } else if (QNext(uq) != tq) {
673 refpanic("VLRU inconsistent");
675 #ifdef AFS_DARWIN_ENV
676 if ((VREFCOUNT(tvc) < DARWIN_REFBASE) ||
677 (VREFCOUNT(tvc) < 1 + DARWIN_REFBASE &&
678 UBCINFOEXISTS(&tvc->v))) {
681 (UBCINFOEXISTS(&tvc->v) ? 1 : 0));
683 if (tvc->opens == 0 && ((tvc->states & CUnlinkedDel) == 0)
684 && VREFCOUNT(tvc) == DARWIN_REFBASE + 1
685 && UBCINFOEXISTS(&tvc->v)) {
686 osi_VM_TryReclaim(tvc, &fv_slept);
690 continue; /* start over - may have raced. */
693 #elif defined(AFS_LINUX22_ENV)
694 if (tvc != afs_globalVp && VREFCOUNT(tvc) && tvc->opens == 0) {
695 struct dentry *dentry;
696 struct list_head *cur, *head = &(AFSTOI(tvc))->i_dentry;
701 #if defined(AFS_LINUX24_ENV)
702 spin_lock(&dcache_lock);
705 while ((cur = cur->next) != head) {
706 dentry = list_entry(cur, struct dentry, d_alias);
708 if (d_unhashed(dentry))
713 #if defined(AFS_LINUX24_ENV)
714 spin_unlock(&dcache_lock);
716 if (d_invalidate(dentry) == -EBUSY) {
718 /* perhaps lock and try to continue? (use cur as head?) */
724 #if defined(AFS_LINUX24_ENV)
725 spin_unlock(&dcache_lock);
733 if (VREFCOUNT(tvc) ==
734 #ifdef AFS_DARWIN_ENV
739 && tvc->opens == 0 && (tvc->states & CUnlinkedDel) == 0) {
740 #if defined(AFS_XBSD_ENV)
742 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
743 * then it puts the vnode on the free list.
744 * If we don't do this we end up with a cleaned vnode that's
745 * not on the free list.
746 * XXX assume FreeBSD is the same for now.
751 code = afs_FlushVCache(tvc, &fv_slept);
759 continue; /* start over - may have raced. */
767 /* none free, making one is better than a panic */
768 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
769 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
770 #ifdef KERNEL_HAVE_PIN
771 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
774 /* In case it still comes here we need to fill this */
775 tvc->v.v_vm_info = VM_INFO_NULL;
776 vm_info_init(tvc->v.v_vm_info);
777 /* perhaps we should also do close_flush on non-NeXT mach systems;
778 * who knows; we don't currently have the sources.
780 #endif /* AFS_MACH_ENV */
781 #if defined(AFS_SGI_ENV)
783 char name[METER_NAMSZ];
784 memset(tvc, 0, sizeof(struct vcache));
785 tvc->v.v_number = ++afsvnumbers;
786 tvc->vc_rwlockid = OSI_NO_LOCKID;
787 initnsema(&tvc->vc_rwlock, 1,
788 makesname(name, "vrw", tvc->v.v_number));
789 #ifndef AFS_SGI53_ENV
790 initnsema(&tvc->v.v_sync, 0,
791 makesname(name, "vsy", tvc->v.v_number));
793 #ifndef AFS_SGI62_ENV
794 initnlock(&tvc->v.v_lock,
795 makesname(name, "vlk", tvc->v.v_number));
798 #endif /* AFS_SGI_ENV */
800 tvc = freeVCList; /* take from free list */
801 freeVCList = tvc->nextfree;
802 tvc->nextfree = NULL;
804 #endif /* AFS_OSF_ENV */
807 vm_info_ptr = tvc->v.v_vm_info;
808 #endif /* AFS_MACH_ENV */
810 #if defined(AFS_XBSD_ENV)
812 panic("afs_NewVCache(): free vcache with vnode attached");
815 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
816 memset((char *)tvc, 0, sizeof(struct vcache));
821 RWLOCK_INIT(&tvc->lock, "vcache lock");
822 #if defined(AFS_SUN5_ENV)
823 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
824 #endif /* defined(AFS_SUN5_ENV) */
827 tvc->v.v_vm_info = vm_info_ptr;
828 tvc->v.v_vm_info->pager = MEMORY_OBJECT_NULL;
829 #endif /* AFS_MACH_ENV */
832 afs_nbsd_getnewvnode(tvc); /* includes one refcount */
834 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
841 #ifdef AFS_FBSD50_ENV
842 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
844 if (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
846 panic("afs getnewvnode"); /* can't happen */
848 if (tvc->v != NULL) {
849 /* I'd like to know if this ever happens...
850 * We don't drop global for the rest of this function,
851 * so if we do lose the race, the other thread should
852 * have found the same vnode and finished initializing
853 * the vcache entry. Is it conceivable that this vcache
854 * entry could be recycled during this interval? If so,
855 * then there probably needs to be some sort of additional
856 * mutual exclusion (an Embryonic flag would suffice).
858 printf("afs_NewVCache: lost the race\n");
862 tvc->v->v_data = tvc;
863 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
866 tvc->parentVnode = 0;
868 tvc->linkData = NULL;
871 tvc->execsOrWriters = 0;
875 tvc->last_looker = 0;
877 tvc->asynchrony = -1;
879 afs_symhint_inval(tvc);
881 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
884 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
885 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
886 #if defined(AFS_LINUX22_ENV)
888 struct inode *ip = AFSTOI(tvc);
889 struct address_space *mapping = &ip->i_data;
891 #if defined(AFS_LINUX26_ENV)
894 sema_init(&ip->i_sem, 1);
895 INIT_LIST_HEAD(&ip->i_hash);
896 INIT_LIST_HEAD(&ip->i_dentry);
897 #if defined(AFS_LINUX24_ENV)
898 sema_init(&ip->i_zombie, 1);
899 init_waitqueue_head(&ip->i_wait);
900 spin_lock_init(&ip->i_data.i_shared_lock);
901 #ifdef STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK
902 spin_lock_init(&ip->i_data.page_lock);
904 INIT_LIST_HEAD(&ip->i_data.clean_pages);
905 INIT_LIST_HEAD(&ip->i_data.dirty_pages);
906 INIT_LIST_HEAD(&ip->i_data.locked_pages);
907 INIT_LIST_HEAD(&ip->i_dirty_buffers);
908 #ifdef STRUCT_INODE_HAS_I_DIRTY_DATA_BUFFERS
909 INIT_LIST_HEAD(&ip->i_dirty_data_buffers);
911 #ifdef STRUCT_INODE_HAS_I_DEVICES
912 INIT_LIST_HEAD(&ip->i_devices);
914 #ifdef STRUCT_INODE_HAS_I_TRUNCATE_SEM
915 init_rwsem(&ip->i_truncate_sem);
917 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
918 init_rwsem(&ip->i_alloc_sem);
921 #else /* AFS_LINUX22_ENV */
922 sema_init(&ip->i_atomic_write, 1);
923 init_waitqueue(&ip->i_wait);
927 #if defined(AFS_LINUX24_ENV)
929 ip->i_mapping = mapping;
930 #ifdef STRUCT_ADDRESS_SPACE_HAS_GFP_MASK
931 ip->i_data.gfp_mask = GFP_HIGHUSER;
933 #if defined(AFS_LINUX26_ENV)
934 mapping_set_gfp_mask(mapping, GFP_HIGHUSER);
936 extern struct backing_dev_info afs_backing_dev_info;
938 mapping->backing_dev_info = &afs_backing_dev_info;
943 #if !defined(AFS_LINUX26_ENV)
945 ip->i_dev = afs_globalVFS->s_dev;
947 #ifdef STRUCT_INODE_HAS_I_SECURITY
948 ip->i_security = NULL;
949 if (security_inode_alloc(ip))
950 panic("Cannot allocate inode security");
953 ip->i_sb = afs_globalVFS;
954 put_inode_on_dummy_list(ip);
955 #ifdef STRUCT_INODE_HAS_I_SB_LIST
956 list_add(&ip->i_sb_list, &ip->i_sb->s_inodes);
962 /* Hold it for the LRU (should make count 2) */
963 VN_HOLD(AFSTOV(tvc));
964 #else /* AFS_OSF_ENV */
965 #if !defined(AFS_XBSD_ENV)
966 VREFCOUNT_SET(tvc, 1); /* us */
967 #endif /* AFS_XBSD_ENV */
968 #endif /* AFS_OSF_ENV */
970 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
971 tvc->vmh = tvc->segid = NULL;
974 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
975 #if defined(AFS_SUN5_ENV)
976 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
978 #if defined(AFS_SUN55_ENV)
979 /* This is required if the kaio (kernel aynchronous io)
980 ** module is installed. Inside the kernel, the function
981 ** check_vp( common/os/aio.c) checks to see if the kernel has
982 ** to provide asynchronous io for this vnode. This
983 ** function extracts the device number by following the
984 ** v_data field of the vnode. If we do not set this field
985 ** then the system panics. The value of the v_data field
986 ** is not really important for AFS vnodes because the kernel
987 ** does not do asynchronous io for regular files. Hence,
988 ** for the time being, we fill up the v_data field with the
989 ** vnode pointer itself. */
990 tvc->v.v_data = (char *)tvc;
991 #endif /* AFS_SUN55_ENV */
993 afs_BozonInit(&tvc->pvnLock, tvc);
997 tvc->callback = serverp; /* to minimize chance that clear
999 /* initialize vnode data, note vrefCount is v.v_count */
1001 /* Don't forget to free the gnode space */
1002 tvc->v.v_gnode = gnodepnt =
1003 (struct gnode *)osi_AllocSmallSpace(sizeof(struct gnode));
1004 memset((char *)gnodepnt, 0, sizeof(struct gnode));
1006 #ifdef AFS_SGI64_ENV
1007 memset((void *)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc));
1008 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
1009 #ifdef AFS_SGI65_ENV
1010 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
1011 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1013 bhv_head_init(&(tvc->v.v_bh));
1014 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1016 #ifdef AFS_SGI65_ENV
1017 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion *)tvc;
1018 #ifdef VNODE_TRACING
1019 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
1021 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
1023 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
1024 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
1026 vnode_pcache_init(&tvc->v);
1027 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
1028 /* Above define is never true execpt in SGI test kernels. */
1029 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
1031 #ifdef INTR_KTHREADS
1032 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
1035 SetAfsVnode(AFSTOV(tvc));
1036 #endif /* AFS_SGI64_ENV */
1037 #ifdef AFS_DARWIN_ENV
1038 tvc->v.v_ubcinfo = UBC_INFO_NULL;
1039 lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0);
1040 cache_purge(AFSTOV(tvc));
1041 tvc->v.v_data = tvc;
1042 tvc->v.v_tag = VT_AFS;
1043 /* VLISTNONE(&tvc->v); */
1044 tvc->v.v_freelist.tqe_next = 0;
1045 tvc->v.v_freelist.tqe_prev = (struct vnode **)0xdeadb;
1046 tvc->vrefCount += DARWIN_REFBASE;
1049 * The proper value for mvstat (for root fids) is setup by the caller.
1052 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
1054 if (afs_globalVFS == 0)
1055 osi_Panic("afs globalvfs");
1056 vSetVfsp(tvc, afs_globalVFS);
1057 vSetType(tvc, VREG);
1059 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
1060 tvc->v.v_vfsprev = NULL;
1061 afs_globalVFS->vfs_vnodes = &tvc->v;
1062 if (tvc->v.v_vfsnext != NULL)
1063 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
1064 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us! */
1065 gnodepnt->gn_vnode = &tvc->v;
1068 tvc->v.g_dev = ((struct mount *)afs_globalVFS->vfs_data)->m_dev;
1070 #if defined(AFS_DUX40_ENV)
1071 insmntque(tvc, afs_globalVFS, &afs_ubcops);
1074 /* Is this needed??? */
1075 insmntque(tvc, afs_globalVFS);
1076 #endif /* AFS_OSF_ENV */
1077 #endif /* AFS_DUX40_ENV */
1078 #if defined(AFS_SGI_ENV)
1079 VN_SET_DPAGES(&(tvc->v), (struct pfdat *)NULL);
1080 osi_Assert((tvc->v.v_flag & VINACT) == 0);
1082 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
1083 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
1084 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
1085 osi_Assert(tvc->v.v_filocks == NULL);
1086 #if !defined(AFS_SGI65_ENV)
1087 osi_Assert(tvc->v.v_filocksem == NULL);
1089 osi_Assert(tvc->cred == NULL);
1090 #ifdef AFS_SGI64_ENV
1091 vnode_pcache_reinit(&tvc->v);
1092 tvc->v.v_rdev = NODEV;
1094 vn_initlist((struct vnlist *)&tvc->v);
1096 #endif /* AFS_SGI_ENV */
1098 osi_dnlc_purgedp(tvc); /* this may be overkill */
1099 memset((char *)&(tvc->quick), 0, sizeof(struct vtodc));
1100 memset((char *)&(tvc->callsort), 0, sizeof(struct afs_q));
1104 tvc->hnext = afs_vhashT[i];
1105 afs_vhashT[i] = tvc;
1106 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1107 refpanic("NewVCache VLRU inconsistent");
1109 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
1110 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1111 refpanic("NewVCache VLRU inconsistent2");
1113 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1114 refpanic("NewVCache VLRU inconsistent3");
1116 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1117 refpanic("NewVCache VLRU inconsistent4");
1123 } /*afs_NewVCache */
1127 * afs_FlushActiveVcaches
1133 * doflocks : Do we handle flocks?
1135 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1137 afs_FlushActiveVcaches(register afs_int32 doflocks)
1139 register struct vcache *tvc;
1141 register struct conn *tc;
1142 register afs_int32 code;
1143 register struct AFS_UCRED *cred = NULL;
1144 struct vrequest treq, ureq;
1145 struct AFSVolSync tsync;
1148 AFS_STATCNT(afs_FlushActiveVcaches);
1149 ObtainReadLock(&afs_xvcache);
1150 for (i = 0; i < VCSIZE; i++) {
1151 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1152 if (doflocks && tvc->flockCount != 0) {
1153 /* if this entry has an flock, send a keep-alive call out */
1155 ReleaseReadLock(&afs_xvcache);
1156 ObtainWriteLock(&tvc->lock, 51);
1158 afs_InitReq(&treq, afs_osi_credp);
1159 treq.flags |= O_NONBLOCK;
1161 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1163 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1166 RXAFS_ExtendLock(tc->id,
1167 (struct AFSFid *)&tvc->fid.Fid,
1173 } while (afs_Analyze
1174 (tc, code, &tvc->fid, &treq,
1175 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1177 ReleaseWriteLock(&tvc->lock);
1178 ObtainReadLock(&afs_xvcache);
1182 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1184 * Don't let it evaporate in case someone else is in
1185 * this code. Also, drop the afs_xvcache lock while
1186 * getting vcache locks.
1189 ReleaseReadLock(&afs_xvcache);
1190 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1191 afs_BozonLock(&tvc->pvnLock, tvc);
1193 #if defined(AFS_SGI_ENV)
1195 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1197 osi_Assert(VREFCOUNT(tvc) > 0);
1198 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1200 ObtainWriteLock(&tvc->lock, 52);
1201 if (tvc->states & CCore) {
1202 tvc->states &= ~CCore;
1203 /* XXXX Find better place-holder for cred XXXX */
1204 cred = (struct AFS_UCRED *)tvc->linkData;
1205 tvc->linkData = NULL; /* XXX */
1206 afs_InitReq(&ureq, cred);
1207 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1208 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1209 tvc->execsOrWriters);
1210 code = afs_StoreOnLastReference(tvc, &ureq);
1211 ReleaseWriteLock(&tvc->lock);
1212 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1213 afs_BozonUnlock(&tvc->pvnLock, tvc);
1215 hzero(tvc->flushDV);
1218 if (code && code != VNOVNODE) {
1219 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1220 /* /dev/console */ 1);
1222 } else if (tvc->states & CUnlinkedDel) {
1226 ReleaseWriteLock(&tvc->lock);
1227 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1228 afs_BozonUnlock(&tvc->pvnLock, tvc);
1230 #if defined(AFS_SGI_ENV)
1231 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1233 afs_remunlink(tvc, 0);
1234 #if defined(AFS_SGI_ENV)
1235 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1238 /* lost (or won, perhaps) the race condition */
1239 ReleaseWriteLock(&tvc->lock);
1240 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1241 afs_BozonUnlock(&tvc->pvnLock, tvc);
1244 #if defined(AFS_SGI_ENV)
1245 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1247 ObtainReadLock(&afs_xvcache);
1253 AFS_RELE(AFSTOV(tvc));
1255 /* Matches write code setting CCore flag */
1259 #ifdef AFS_DARWIN_ENV
1260 if (VREFCOUNT(tvc) == 1 + DARWIN_REFBASE
1261 && UBCINFOEXISTS(&tvc->v)) {
1263 panic("flushactive open, hasubc, but refcnt 1");
1264 osi_VM_TryReclaim(tvc, 0);
1269 ReleaseReadLock(&afs_xvcache);
1277 * Make sure a cache entry is up-to-date status-wise.
1279 * NOTE: everywhere that calls this can potentially be sped up
1280 * by checking CStatd first, and avoiding doing the InitReq
1281 * if this is up-to-date.
1283 * Anymore, the only places that call this KNOW already that the
1284 * vcache is not up-to-date, so we don't screw around.
1287 * avc : Ptr to vcache entry to verify.
1292 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1294 register struct vcache *tvc;
1296 AFS_STATCNT(afs_VerifyVCache);
1298 #if defined(AFS_OSF_ENV)
1299 ObtainReadLock(&avc->lock);
1300 if (afs_IsWired(avc)) {
1301 ReleaseReadLock(&avc->lock);
1304 ReleaseReadLock(&avc->lock);
1305 #endif /* AFS_OSF_ENV */
1306 /* otherwise we must fetch the status info */
1308 ObtainWriteLock(&avc->lock, 53);
1309 if (avc->states & CStatd) {
1310 ReleaseWriteLock(&avc->lock);
1313 ObtainWriteLock(&afs_xcbhash, 461);
1314 avc->states &= ~(CStatd | CUnique);
1315 avc->callback = NULL;
1316 afs_DequeueCallback(avc);
1317 ReleaseWriteLock(&afs_xcbhash);
1318 ReleaseWriteLock(&avc->lock);
1320 /* since we've been called back, or the callback has expired,
1321 * it's possible that the contents of this directory, or this
1322 * file's name have changed, thus invalidating the dnlc contents.
1324 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1325 osi_dnlc_purgedp(avc);
1327 osi_dnlc_purgevp(avc);
1329 /* fetch the status info */
1330 tvc = afs_GetVCache(&avc->fid, areq, NULL, avc);
1333 /* Put it back; caller has already incremented vrefCount */
1337 } /*afs_VerifyVCache */
1344 * Simple copy of stat info into cache.
1347 * avc : Ptr to vcache entry involved.
1348 * astat : Ptr to stat info to copy.
1351 * Nothing interesting.
1353 * Callers: as of 1992-04-29, only called by WriteVCache
1356 afs_SimpleVStat(register struct vcache *avc,
1357 register struct AFSFetchStatus *astat, struct vrequest *areq)
1360 AFS_STATCNT(afs_SimpleVStat);
1363 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1364 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1366 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1368 #ifdef AFS_64BIT_CLIENT
1369 FillInt64(length, astat->Length_hi, astat->Length);
1370 #else /* AFS_64BIT_CLIENT */
1371 length = astat->Length;
1372 #endif /* AFS_64BIT_CLIENT */
1373 #if defined(AFS_SGI_ENV)
1374 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1375 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1376 if (length < avc->m.Length) {
1377 vnode_t *vp = (vnode_t *) avc;
1379 osi_Assert(WriteLocked(&avc->lock));
1380 ReleaseWriteLock(&avc->lock);
1382 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1384 ObtainWriteLock(&avc->lock, 67);
1387 /* if writing the file, don't fetch over this value */
1388 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1389 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1390 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1391 avc->m.Length = length;
1392 avc->m.Date = astat->ClientModTime;
1394 avc->m.Owner = astat->Owner;
1395 avc->m.Group = astat->Group;
1396 avc->m.Mode = astat->UnixModeBits;
1397 if (vType(avc) == VREG) {
1398 avc->m.Mode |= S_IFREG;
1399 } else if (vType(avc) == VDIR) {
1400 avc->m.Mode |= S_IFDIR;
1401 } else if (vType(avc) == VLNK) {
1402 avc->m.Mode |= S_IFLNK;
1403 if ((avc->m.Mode & 0111) == 0)
1406 if (avc->states & CForeign) {
1407 struct axscache *ac;
1408 avc->anyAccess = astat->AnonymousAccess;
1410 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1412 * Caller has at least one bit not covered by anonymous, and
1413 * thus may have interesting rights.
1415 * HOWEVER, this is a really bad idea, because any access query
1416 * for bits which aren't covered by anonymous, on behalf of a user
1417 * who doesn't have any special rights, will result in an answer of
1418 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1419 * It's an especially bad idea under Ultrix, since (due to the lack of
1420 * a proper access() call) it must perform several afs_access() calls
1421 * in order to create magic mode bits that vary according to who makes
1422 * the call. In other words, _every_ stat() generates a test for
1425 #endif /* badidea */
1426 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1427 ac->axess = astat->CallerAccess;
1428 else /* not found, add a new one if possible */
1429 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1433 } /*afs_SimpleVStat */
1440 * Store the status info *only* back to the server for a
1444 * avc : Ptr to the vcache entry.
1445 * astatus : Ptr to the status info to store.
1446 * areq : Ptr to the associated vrequest.
1449 * Must be called with a shared lock held on the vnode.
1453 afs_WriteVCache(register struct vcache *avc,
1454 register struct AFSStoreStatus *astatus,
1455 struct vrequest *areq)
1459 struct AFSFetchStatus OutStatus;
1460 struct AFSVolSync tsync;
1462 AFS_STATCNT(afs_WriteVCache);
1463 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1464 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length));
1467 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1469 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1472 RXAFS_StoreStatus(tc->id, (struct AFSFid *)&avc->fid.Fid,
1473 astatus, &OutStatus, &tsync);
1478 } while (afs_Analyze
1479 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1480 SHARED_LOCK, NULL));
1482 UpgradeSToWLock(&avc->lock, 20);
1484 /* success, do the changes locally */
1485 afs_SimpleVStat(avc, &OutStatus, areq);
1487 * Update the date, too. SimpleVStat didn't do this, since
1488 * it thought we were doing this after fetching new status
1489 * over a file being written.
1491 avc->m.Date = OutStatus.ClientModTime;
1493 /* failure, set up to check with server next time */
1494 ObtainWriteLock(&afs_xcbhash, 462);
1495 afs_DequeueCallback(avc);
1496 avc->states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1497 ReleaseWriteLock(&afs_xcbhash);
1498 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1499 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1501 ConvertWToSLock(&avc->lock);
1504 } /*afs_WriteVCache */
1510 * Copy astat block into vcache info
1513 * avc : Ptr to vcache entry.
1514 * astat : Ptr to stat block to copy in.
1515 * areq : Ptr to associated request.
1518 * Must be called under a write lock
1520 * Note: this code may get dataversion and length out of sync if the file has
1521 * been modified. This is less than ideal. I haven't thought about
1522 * it sufficiently to be certain that it is adequate.
1525 afs_ProcessFS(register struct vcache *avc,
1526 register struct AFSFetchStatus *astat, struct vrequest *areq)
1529 AFS_STATCNT(afs_ProcessFS);
1531 #ifdef AFS_64BIT_CLIENT
1532 FillInt64(length, astat->Length_hi, astat->Length);
1533 #else /* AFS_64BIT_CLIENT */
1534 length = astat->Length;
1535 #endif /* AFS_64BIT_CLIENT */
1536 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1537 * number for each bulk status request. Under no circumstances
1538 * should afs_DoBulkStat store a sequence number if the new
1539 * length will be ignored when afs_ProcessFS is called with
1540 * new stats. If you change the following conditional then you
1541 * also need to change the conditional in afs_DoBulkStat. */
1543 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1544 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1546 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1548 /* if we're writing or mapping this file, don't fetch over these
1551 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1552 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1553 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1554 avc->m.Length = length;
1555 avc->m.Date = astat->ClientModTime;
1557 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1558 avc->m.Owner = astat->Owner;
1559 avc->m.Mode = astat->UnixModeBits;
1560 avc->m.Group = astat->Group;
1561 avc->m.LinkCount = astat->LinkCount;
1562 if (astat->FileType == File) {
1563 vSetType(avc, VREG);
1564 avc->m.Mode |= S_IFREG;
1565 } else if (astat->FileType == Directory) {
1566 vSetType(avc, VDIR);
1567 avc->m.Mode |= S_IFDIR;
1568 } else if (astat->FileType == SymbolicLink) {
1569 if (afs_fakestat_enable && (avc->m.Mode & 0111) == 0) {
1570 vSetType(avc, VDIR);
1571 avc->m.Mode |= S_IFDIR;
1573 vSetType(avc, VLNK);
1574 avc->m.Mode |= S_IFLNK;
1576 if ((avc->m.Mode & 0111) == 0) {
1580 avc->anyAccess = astat->AnonymousAccess;
1582 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1584 * Caller has at least one bit not covered by anonymous, and
1585 * thus may have interesting rights.
1587 * HOWEVER, this is a really bad idea, because any access query
1588 * for bits which aren't covered by anonymous, on behalf of a user
1589 * who doesn't have any special rights, will result in an answer of
1590 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1591 * It's an especially bad idea under Ultrix, since (due to the lack of
1592 * a proper access() call) it must perform several afs_access() calls
1593 * in order to create magic mode bits that vary according to who makes
1594 * the call. In other words, _every_ stat() generates a test for
1597 #endif /* badidea */
1599 struct axscache *ac;
1600 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1601 ac->axess = astat->CallerAccess;
1602 else /* not found, add a new one if possible */
1603 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1605 #ifdef AFS_LINUX22_ENV
1606 vcache2inode(avc); /* Set the inode attr cache */
1608 #ifdef AFS_DARWIN_ENV
1609 osi_VM_Setup(avc, 1);
1612 } /*afs_ProcessFS */
1616 afs_RemoteLookup(register struct VenusFid *afid, struct vrequest *areq,
1617 char *name, struct VenusFid *nfid,
1618 struct AFSFetchStatus *OutStatusp,
1619 struct AFSCallBack *CallBackp, struct server **serverp,
1620 struct AFSVolSync *tsyncp)
1624 register struct conn *tc;
1625 struct AFSFetchStatus OutDirStatus;
1628 name = ""; /* XXX */
1630 tc = afs_Conn(afid, areq, SHARED_LOCK);
1633 *serverp = tc->srvr->server;
1635 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1638 RXAFS_Lookup(tc->id, (struct AFSFid *)&afid->Fid, name,
1639 (struct AFSFid *)&nfid->Fid, OutStatusp,
1640 &OutDirStatus, CallBackp, tsyncp);
1645 } while (afs_Analyze
1646 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1657 * Given a file id and a vrequest structure, fetch the status
1658 * information associated with the file.
1662 * areq : Ptr to associated vrequest structure, specifying the
1663 * user whose authentication tokens will be used.
1664 * avc : caller may already have a vcache for this file, which is
1668 * The cache entry is returned with an increased vrefCount field.
1669 * The entry must be discarded by calling afs_PutVCache when you
1670 * are through using the pointer to the cache entry.
1672 * You should not hold any locks when calling this function, except
1673 * locks on other vcache entries. If you lock more than one vcache
1674 * entry simultaneously, you should lock them in this order:
1676 * 1. Lock all files first, then directories.
1677 * 2. Within a particular type, lock entries in Fid.Vnode order.
1679 * This locking hierarchy is convenient because it allows locking
1680 * of a parent dir cache entry, given a file (to check its access
1681 * control list). It also allows renames to be handled easily by
1682 * locking directories in a constant order.
1683 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1685 /* might have a vcache structure already, which must
1686 * already be held by the caller */
1689 afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq,
1690 afs_int32 * cached, struct vcache *avc)
1693 afs_int32 code, newvcache = 0;
1694 register struct vcache *tvc;
1698 AFS_STATCNT(afs_GetVCache);
1701 *cached = 0; /* Init just in case */
1703 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1707 ObtainSharedLock(&afs_xvcache, 5);
1709 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU);
1711 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1712 ReleaseSharedLock(&afs_xvcache);
1713 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1721 if (tvc->states & CStatd) {
1722 ReleaseSharedLock(&afs_xvcache);
1726 UpgradeSToWLock(&afs_xvcache, 21);
1728 /* no cache entry, better grab one */
1729 tvc = afs_NewVCache(afid, NULL);
1732 ConvertWToSLock(&afs_xvcache);
1733 afs_stats_cmperf.vcacheMisses++;
1736 ReleaseSharedLock(&afs_xvcache);
1738 ObtainWriteLock(&tvc->lock, 54);
1740 if (tvc->states & CStatd) {
1741 #ifdef AFS_LINUX22_ENV
1744 ReleaseWriteLock(&tvc->lock);
1745 #ifdef AFS_DARWIN_ENV
1746 osi_VM_Setup(tvc, 0);
1750 #if defined(AFS_OSF_ENV)
1751 if (afs_IsWired(tvc)) {
1752 ReleaseWriteLock(&tvc->lock);
1755 #endif /* AFS_OSF_ENV */
1757 VOP_LOCK(AFSTOV(tvc), LK_EXCLUSIVE | LK_RETRY, curproc);
1758 uvm_vnp_uncache(AFSTOV(tvc));
1759 VOP_UNLOCK(AFSTOV(tvc), 0, curproc);
1763 * XXX - I really don't like this. Should try to understand better.
1764 * It seems that sometimes, when we get called, we already hold the
1765 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1766 * We can't drop the vnode lock, because that could result in a race.
1767 * Sometimes, though, we get here and don't hold the vnode lock.
1768 * I hate code paths that sometimes hold locks and sometimes don't.
1769 * In any event, the dodge we use here is to check whether the vnode
1770 * is locked, and if it isn't, then we gain and drop it around the call
1771 * to vinvalbuf; otherwise, we leave it alone.
1778 #ifdef AFS_FBSD50_ENV
1779 iheldthelock = VOP_ISLOCKED(vp, curthread);
1781 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1782 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1784 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1786 iheldthelock = VOP_ISLOCKED(vp, curproc);
1788 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1789 vinvalbuf(vp, V_SAVE, osi_curcred(), curproc, PINOD, 0);
1791 VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
1796 ObtainWriteLock(&afs_xcbhash, 464);
1797 tvc->states &= ~CUnique;
1799 afs_DequeueCallback(tvc);
1800 ReleaseWriteLock(&afs_xcbhash);
1802 /* It is always appropriate to throw away all the access rights? */
1803 afs_FreeAllAxs(&(tvc->Access));
1804 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1806 if ((tvp->states & VForeign)) {
1808 tvc->states |= CForeign;
1809 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1810 && (tvp->rootUnique == afid->Fid.Unique)) {
1814 if (tvp->states & VRO)
1816 if (tvp->states & VBackup)
1817 tvc->states |= CBackup;
1818 /* now copy ".." entry back out of volume structure, if necessary */
1819 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1821 tvc->mvid = (struct VenusFid *)
1822 osi_AllocSmallSpace(sizeof(struct VenusFid));
1823 *tvc->mvid = tvp->dotdot;
1825 afs_PutVolume(tvp, READ_LOCK);
1829 afs_RemoveVCB(afid);
1831 struct AFSFetchStatus OutStatus;
1833 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1834 afs_ProcessFS(tvc, &OutStatus, areq);
1835 tvc->states |= CStatd | CUnique;
1838 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1843 ReleaseWriteLock(&tvc->lock);
1845 ObtainReadLock(&afs_xvcache);
1847 ReleaseReadLock(&afs_xvcache);
1851 ReleaseWriteLock(&tvc->lock);
1854 } /*afs_GetVCache */
1859 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1860 afs_int32 * cached, struct vcache *adp, char *aname)
1862 afs_int32 code, now, newvcache = 0;
1863 struct VenusFid nfid;
1864 register struct vcache *tvc;
1866 struct AFSFetchStatus OutStatus;
1867 struct AFSCallBack CallBack;
1868 struct AFSVolSync tsync;
1869 struct server *serverp = 0;
1873 AFS_STATCNT(afs_GetVCache);
1875 *cached = 0; /* Init just in case */
1877 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1881 ObtainReadLock(&afs_xvcache);
1882 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
1885 ReleaseReadLock(&afs_xvcache);
1887 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1888 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1892 ObtainReadLock(&tvc->lock);
1894 if (tvc->states & CStatd) {
1898 ReleaseReadLock(&tvc->lock);
1901 tvc->states &= ~CUnique;
1903 ReleaseReadLock(&tvc->lock);
1904 ObtainReadLock(&afs_xvcache);
1908 ReleaseReadLock(&afs_xvcache);
1910 /* lookup the file */
1913 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1915 afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1918 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1922 ObtainSharedLock(&afs_xvcache, 6);
1923 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU /* no xstats now */ );
1925 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1926 ReleaseSharedLock(&afs_xvcache);
1927 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1933 /* no cache entry, better grab one */
1934 UpgradeSToWLock(&afs_xvcache, 22);
1935 tvc = afs_NewVCache(&nfid, serverp);
1937 ConvertWToSLock(&afs_xvcache);
1940 ReleaseSharedLock(&afs_xvcache);
1941 ObtainWriteLock(&tvc->lock, 55);
1943 /* It is always appropriate to throw away all the access rights? */
1944 afs_FreeAllAxs(&(tvc->Access));
1945 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1947 if ((tvp->states & VForeign)) {
1949 tvc->states |= CForeign;
1950 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1951 && (tvp->rootUnique == afid->Fid.Unique))
1954 if (tvp->states & VRO)
1956 if (tvp->states & VBackup)
1957 tvc->states |= CBackup;
1958 /* now copy ".." entry back out of volume structure, if necessary */
1959 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1961 tvc->mvid = (struct VenusFid *)
1962 osi_AllocSmallSpace(sizeof(struct VenusFid));
1963 *tvc->mvid = tvp->dotdot;
1968 ObtainWriteLock(&afs_xcbhash, 465);
1969 afs_DequeueCallback(tvc);
1970 tvc->states &= ~(CStatd | CUnique);
1971 ReleaseWriteLock(&afs_xcbhash);
1972 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1973 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1975 afs_PutVolume(tvp, READ_LOCK);
1976 ReleaseWriteLock(&tvc->lock);
1977 ObtainReadLock(&afs_xvcache);
1979 ReleaseReadLock(&afs_xvcache);
1983 ObtainWriteLock(&afs_xcbhash, 466);
1984 if (origCBs == afs_allCBs) {
1985 if (CallBack.ExpirationTime) {
1986 tvc->callback = serverp;
1987 tvc->cbExpires = CallBack.ExpirationTime + now;
1988 tvc->states |= CStatd | CUnique;
1989 tvc->states &= ~CBulkFetching;
1990 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1991 } else if (tvc->states & CRO) {
1992 /* adapt gives us an hour. */
1993 tvc->cbExpires = 3600 + osi_Time();
1994 /*XXX*/ tvc->states |= CStatd | CUnique;
1995 tvc->states &= ~CBulkFetching;
1996 afs_QueueCallback(tvc, CBHash(3600), tvp);
1998 tvc->callback = NULL;
1999 afs_DequeueCallback(tvc);
2000 tvc->states &= ~(CStatd | CUnique);
2001 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2002 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2005 afs_DequeueCallback(tvc);
2006 tvc->states &= ~CStatd;
2007 tvc->states &= ~CUnique;
2008 tvc->callback = NULL;
2009 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2010 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2012 ReleaseWriteLock(&afs_xcbhash);
2014 afs_PutVolume(tvp, READ_LOCK);
2015 afs_ProcessFS(tvc, &OutStatus, areq);
2017 ReleaseWriteLock(&tvc->lock);
2023 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2024 afs_int32 * cached, struct volume *tvolp)
2026 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2027 afs_int32 getNewFid = 0;
2029 struct VenusFid nfid;
2030 register struct vcache *tvc;
2031 struct server *serverp = 0;
2032 struct AFSFetchStatus OutStatus;
2033 struct AFSCallBack CallBack;
2034 struct AFSVolSync tsync;
2040 if (!tvolp->rootVnode || getNewFid) {
2041 struct VenusFid tfid;
2044 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2045 origCBs = afs_allCBs; /* ignore InitCallBackState */
2047 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2052 /* ReleaseReadLock(&tvolp->lock); */
2053 ObtainWriteLock(&tvolp->lock, 56);
2054 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2055 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2056 ReleaseWriteLock(&tvolp->lock);
2057 /* ObtainReadLock(&tvolp->lock);*/
2060 afid->Fid.Vnode = tvolp->rootVnode;
2061 afid->Fid.Unique = tvolp->rootUnique;
2064 ObtainSharedLock(&afs_xvcache, 7);
2066 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2067 if (!FidCmp(&(tvc->fid), afid)) {
2069 /* Grab this vnode, possibly reactivating from the free list */
2070 /* for the present (95.05.25) everything on the hash table is
2071 * definitively NOT in the free list -- at least until afs_reclaim
2072 * can be safely implemented */
2075 vg = vget(AFSTOV(tvc)); /* this bumps ref count */
2079 #endif /* AFS_OSF_ENV */
2080 #ifdef AFS_DARWIN14_ENV
2081 /* It'd really suck if we allowed duplicate vcaches for the
2082 * same fid to happen. Wonder if this will work? */
2083 struct vnode *vp = AFSTOV(tvc);
2084 if (vp->v_flag & (VXLOCK | VORECLAIM | VTERMINATE)) {
2085 printf("precluded FindVCache on %x (%d:%d:%d)\n",
2086 vp, tvc->fid.Fid.Volume, tvc->fid.Fid.Vnode,
2087 tvc->fid.Fid.Unique);
2088 simple_lock(&vp->v_interlock);
2089 SET(vp->v_flag, VTERMWANT);
2090 simple_unlock(&vp->v_interlock);
2091 (void)tsleep((caddr_t) & vp->v_ubcinfo, PINOD, "vget1", 0);
2092 printf("VTERMWANT ended on %x\n", vp);
2100 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
2101 /* Mount point no longer stat'd or unknown. FID may have changed. */
2104 AFS_RELE(AFSTOV(tvc));
2108 ReleaseSharedLock(&afs_xvcache);
2113 UpgradeSToWLock(&afs_xvcache, 23);
2114 /* no cache entry, better grab one */
2115 tvc = afs_NewVCache(afid, NULL);
2117 afs_stats_cmperf.vcacheMisses++;
2121 afs_stats_cmperf.vcacheHits++;
2123 /* we already bumped the ref count in the for loop above */
2124 #else /* AFS_OSF_ENV */
2127 UpgradeSToWLock(&afs_xvcache, 24);
2128 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2129 refpanic("GRVC VLRU inconsistent0");
2131 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2132 refpanic("GRVC VLRU inconsistent1");
2134 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2135 refpanic("GRVC VLRU inconsistent2");
2137 QRemove(&tvc->vlruq); /* move to lruq head */
2138 QAdd(&VLRU, &tvc->vlruq);
2139 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2140 refpanic("GRVC VLRU inconsistent3");
2142 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2143 refpanic("GRVC VLRU inconsistent4");
2145 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2146 refpanic("GRVC VLRU inconsistent5");
2151 ReleaseWriteLock(&afs_xvcache);
2153 if (tvc->states & CStatd) {
2157 ObtainReadLock(&tvc->lock);
2158 tvc->states &= ~CUnique;
2159 tvc->callback = NULL; /* redundant, perhaps */
2160 ReleaseReadLock(&tvc->lock);
2163 ObtainWriteLock(&tvc->lock, 57);
2165 /* It is always appropriate to throw away all the access rights? */
2166 afs_FreeAllAxs(&(tvc->Access));
2169 tvc->states |= CForeign;
2170 if (tvolp->states & VRO)
2172 if (tvolp->states & VBackup)
2173 tvc->states |= CBackup;
2174 /* now copy ".." entry back out of volume structure, if necessary */
2175 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2176 && (tvolp->rootUnique == afid->Fid.Unique)) {
2179 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2181 tvc->mvid = (struct VenusFid *)
2182 osi_AllocSmallSpace(sizeof(struct VenusFid));
2183 *tvc->mvid = tvolp->dotdot;
2187 afs_RemoveVCB(afid);
2190 struct VenusFid tfid;
2193 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2194 origCBs = afs_allCBs; /* ignore InitCallBackState */
2196 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2201 ObtainWriteLock(&afs_xcbhash, 467);
2202 afs_DequeueCallback(tvc);
2203 tvc->callback = NULL;
2204 tvc->states &= ~(CStatd | CUnique);
2205 ReleaseWriteLock(&afs_xcbhash);
2206 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2207 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2208 ReleaseWriteLock(&tvc->lock);
2209 ObtainReadLock(&afs_xvcache);
2211 ReleaseReadLock(&afs_xvcache);
2215 ObtainWriteLock(&afs_xcbhash, 468);
2216 if (origCBs == afs_allCBs) {
2217 tvc->states |= CTruth;
2218 tvc->callback = serverp;
2219 if (CallBack.ExpirationTime != 0) {
2220 tvc->cbExpires = CallBack.ExpirationTime + start;
2221 tvc->states |= CStatd;
2222 tvc->states &= ~CBulkFetching;
2223 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2224 } else if (tvc->states & CRO) {
2225 /* adapt gives us an hour. */
2226 tvc->cbExpires = 3600 + osi_Time();
2227 /*XXX*/ tvc->states |= CStatd;
2228 tvc->states &= ~CBulkFetching;
2229 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2232 afs_DequeueCallback(tvc);
2233 tvc->callback = NULL;
2234 tvc->states &= ~(CStatd | CUnique);
2235 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2236 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2238 ReleaseWriteLock(&afs_xcbhash);
2239 afs_ProcessFS(tvc, &OutStatus, areq);
2241 ReleaseWriteLock(&tvc->lock);
2248 * must be called with avc write-locked
2249 * don't absolutely have to invalidate the hint unless the dv has
2250 * changed, but be sure to get it right else there will be consistency bugs.
2253 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2254 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2257 afs_uint32 start = 0;
2258 register struct conn *tc;
2259 struct AFSCallBack CallBack;
2260 struct AFSVolSync tsync;
2261 struct volume *volp;
2264 tc = afs_Conn(afid, areq, SHARED_LOCK);
2265 avc->quick.stamp = 0;
2266 avc->h1.dchint = NULL; /* invalidate hints */
2268 avc->callback = tc->srvr->server;
2270 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2273 RXAFS_FetchStatus(tc->id, (struct AFSFid *)&afid->Fid, Outsp,
2281 } while (afs_Analyze
2282 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2283 SHARED_LOCK, NULL));
2286 afs_ProcessFS(avc, Outsp, areq);
2287 volp = afs_GetVolume(afid, areq, READ_LOCK);
2288 ObtainWriteLock(&afs_xcbhash, 469);
2289 avc->states |= CTruth;
2290 if (avc->callback /* check for race */ ) {
2291 if (CallBack.ExpirationTime != 0) {
2292 avc->cbExpires = CallBack.ExpirationTime + start;
2293 avc->states |= CStatd;
2294 avc->states &= ~CBulkFetching;
2295 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2296 } else if (avc->states & CRO) { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2297 avc->cbExpires = 3600 + start;
2298 avc->states |= CStatd;
2299 avc->states &= ~CBulkFetching;
2300 afs_QueueCallback(avc, CBHash(3600), volp);
2302 afs_DequeueCallback(avc);
2303 avc->callback = NULL;
2304 avc->states &= ~(CStatd | CUnique);
2305 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2306 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2309 afs_DequeueCallback(avc);
2310 avc->callback = NULL;
2311 avc->states &= ~(CStatd | CUnique);
2312 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2313 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2315 ReleaseWriteLock(&afs_xcbhash);
2317 afs_PutVolume(volp, READ_LOCK);
2319 /* used to undo the local callback, but that's too extreme.
2320 * There are plenty of good reasons that fetchstatus might return
2321 * an error, such as EPERM. If we have the vnode cached, statd,
2322 * with callback, might as well keep track of the fact that we
2323 * don't have access...
2325 if (code == EPERM || code == EACCES) {
2326 struct axscache *ac;
2327 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2329 else /* not found, add a new one if possible */
2330 afs_AddAxs(avc->Access, areq->uid, 0);
2341 * Stuff some information into the vcache for the given file.
2344 * afid : File in question.
2345 * OutStatus : Fetch status on the file.
2346 * CallBack : Callback info.
2347 * tc : RPC connection involved.
2348 * areq : vrequest involved.
2351 * Nothing interesting.
2354 afs_StuffVcache(register struct VenusFid *afid,
2355 struct AFSFetchStatus *OutStatus,
2356 struct AFSCallBack *CallBack, register struct conn *tc,
2357 struct vrequest *areq)
2359 register afs_int32 code, i, newvcache = 0;
2360 register struct vcache *tvc;
2361 struct AFSVolSync tsync;
2363 struct axscache *ac;
2366 AFS_STATCNT(afs_StuffVcache);
2367 #ifdef IFS_VCACHECOUNT
2372 ObtainSharedLock(&afs_xvcache, 8);
2374 tvc = afs_FindVCache(afid, &retry, DO_VLRU /* no stats */ );
2376 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2377 ReleaseSharedLock(&afs_xvcache);
2378 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2384 /* no cache entry, better grab one */
2385 UpgradeSToWLock(&afs_xvcache, 25);
2386 tvc = afs_NewVCache(afid, NULL);
2388 ConvertWToSLock(&afs_xvcache);
2391 ReleaseSharedLock(&afs_xvcache);
2392 ObtainWriteLock(&tvc->lock, 58);
2394 tvc->states &= ~CStatd;
2395 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2396 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2398 /* Is it always appropriate to throw away all the access rights? */
2399 afs_FreeAllAxs(&(tvc->Access));
2401 /*Copy useful per-volume info */
2402 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2404 if (newvcache && (tvp->states & VForeign))
2405 tvc->states |= CForeign;
2406 if (tvp->states & VRO)
2408 if (tvp->states & VBackup)
2409 tvc->states |= CBackup;
2411 * Now, copy ".." entry back out of volume structure, if
2414 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2416 tvc->mvid = (struct VenusFid *)
2417 osi_AllocSmallSpace(sizeof(struct VenusFid));
2418 *tvc->mvid = tvp->dotdot;
2421 /* store the stat on the file */
2422 afs_RemoveVCB(afid);
2423 afs_ProcessFS(tvc, OutStatus, areq);
2424 tvc->callback = tc->srvr->server;
2426 /* we use osi_Time twice below. Ideally, we would use the time at which
2427 * the FetchStatus call began, instead, but we don't have it here. So we
2428 * make do with "now". In the CRO case, it doesn't really matter. In
2429 * the other case, we hope that the difference between "now" and when the
2430 * call actually began execution on the server won't be larger than the
2431 * padding which the server keeps. Subtract 1 second anyway, to be on
2432 * the safe side. Can't subtract more because we don't know how big
2433 * ExpirationTime is. Possible consistency problems may arise if the call
2434 * timeout period becomes longer than the server's expiration padding. */
2435 ObtainWriteLock(&afs_xcbhash, 470);
2436 if (CallBack->ExpirationTime != 0) {
2437 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2438 tvc->states |= CStatd;
2439 tvc->states &= ~CBulkFetching;
2440 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2441 } else if (tvc->states & CRO) {
2442 /* old-fashioned AFS 3.2 style */
2443 tvc->cbExpires = 3600 + osi_Time();
2444 /*XXX*/ tvc->states |= CStatd;
2445 tvc->states &= ~CBulkFetching;
2446 afs_QueueCallback(tvc, CBHash(3600), tvp);
2448 afs_DequeueCallback(tvc);
2449 tvc->callback = NULL;
2450 tvc->states &= ~(CStatd | CUnique);
2451 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2452 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2454 ReleaseWriteLock(&afs_xcbhash);
2456 afs_PutVolume(tvp, READ_LOCK);
2458 /* look in per-pag cache */
2459 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2460 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2461 else /* not found, add a new one if possible */
2462 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2464 ReleaseWriteLock(&tvc->lock);
2465 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2466 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2467 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2469 * Release ref count... hope this guy stays around...
2472 } /*afs_StuffVcache */
2479 * Decrements the reference count on a cache entry.
2482 * avc : Pointer to the cache entry to decrement.
2485 * Nothing interesting.
2488 afs_PutVCache(register struct vcache *avc)
2490 AFS_STATCNT(afs_PutVCache);
2492 * Can we use a read lock here?
2494 ObtainReadLock(&afs_xvcache);
2496 ReleaseReadLock(&afs_xvcache);
2497 } /*afs_PutVCache */
2503 * Find a vcache entry given a fid.
2506 * afid : Pointer to the fid whose cache entry we desire.
2507 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2508 * unlock the vnode, and try again.
2509 * flags: bit 1 to specify whether to compute hit statistics. Not
2510 * set if FindVCache is called as part of internal bookkeeping.
2513 * Must be called with the afs_xvcache lock at least held at
2514 * the read level. In order to do the VLRU adjustment, the xvcache lock
2515 * must be shared-- we upgrade it here.
2519 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2522 register struct vcache *tvc;
2525 AFS_STATCNT(afs_FindVCache);
2528 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2529 if (FidMatches(afid, tvc)) {
2531 /* Grab this vnode, possibly reactivating from the free list */
2534 vg = vget(AFSTOV(tvc));
2538 #endif /* AFS_OSF_ENV */
2543 /* should I have a read lock on the vnode here? */
2547 #if !defined(AFS_OSF_ENV)
2548 osi_vnhold(tvc, retry); /* already held, above */
2549 if (retry && *retry)
2553 * only move to front of vlru if we have proper vcache locking)
2555 if (flag & DO_VLRU) {
2556 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2557 refpanic("FindVC VLRU inconsistent1");
2559 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2560 refpanic("FindVC VLRU inconsistent1");
2562 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2563 refpanic("FindVC VLRU inconsistent2");
2565 UpgradeSToWLock(&afs_xvcache, 26);
2566 QRemove(&tvc->vlruq);
2567 QAdd(&VLRU, &tvc->vlruq);
2568 ConvertWToSLock(&afs_xvcache);
2569 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2570 refpanic("FindVC VLRU inconsistent1");
2572 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2573 refpanic("FindVC VLRU inconsistent2");
2575 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2576 refpanic("FindVC VLRU inconsistent3");
2582 if (flag & DO_STATS) {
2584 afs_stats_cmperf.vcacheHits++;
2586 afs_stats_cmperf.vcacheMisses++;
2587 if (afs_IsPrimaryCellNum(afid->Cell))
2588 afs_stats_cmperf.vlocalAccesses++;
2590 afs_stats_cmperf.vremoteAccesses++;
2592 #ifdef AFS_LINUX22_ENV
2593 if (tvc && (tvc->states & CStatd))
2594 vcache2inode(tvc); /* mainly to reset i_nlink */
2596 #ifdef AFS_DARWIN_ENV
2598 osi_VM_Setup(tvc, 0);
2601 } /*afs_FindVCache */
2607 * Find a vcache entry given a fid. Does a wildcard match on what we
2608 * have for the fid. If more than one entry, don't return anything.
2611 * avcp : Fill in pointer if we found one and only one.
2612 * afid : Pointer to the fid whose cache entry we desire.
2613 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2614 * unlock the vnode, and try again.
2615 * flags: bit 1 to specify whether to compute hit statistics. Not
2616 * set if FindVCache is called as part of internal bookkeeping.
2619 * Must be called with the afs_xvcache lock at least held at
2620 * the read level. In order to do the VLRU adjustment, the xvcache lock
2621 * must be shared-- we upgrade it here.
2624 * number of matches found.
2627 int afs_duplicate_nfs_fids = 0;
2630 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2632 register struct vcache *tvc;
2634 afs_int32 count = 0;
2635 struct vcache *found_tvc = NULL;
2637 AFS_STATCNT(afs_FindVCache);
2639 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2643 ObtainSharedLock(&afs_xvcache, 331);
2646 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2647 /* Match only on what we have.... */
2648 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2649 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2650 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2651 && (tvc->fid.Cell == afid->Cell)) {
2653 /* Grab this vnode, possibly reactivating from the free list */
2656 vg = vget(AFSTOV(tvc));
2659 /* This vnode no longer exists. */
2662 #endif /* AFS_OSF_ENV */
2667 /* Drop our reference counts. */
2669 vrele(AFSTOV(found_tvc));
2671 afs_duplicate_nfs_fids++;
2672 ReleaseSharedLock(&afs_xvcache);
2680 /* should I have a read lock on the vnode here? */
2682 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2683 afs_int32 retry = 0;
2684 osi_vnhold(tvc, &retry);
2687 found_tvc = (struct vcache *)0;
2688 ReleaseSharedLock(&afs_xvcache);
2689 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2693 #if !defined(AFS_OSF_ENV)
2694 osi_vnhold(tvc, (int *)0); /* already held, above */
2698 * We obtained the xvcache lock above.
2700 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2701 refpanic("FindVC VLRU inconsistent1");
2703 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2704 refpanic("FindVC VLRU inconsistent1");
2706 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2707 refpanic("FindVC VLRU inconsistent2");
2709 UpgradeSToWLock(&afs_xvcache, 568);
2710 QRemove(&tvc->vlruq);
2711 QAdd(&VLRU, &tvc->vlruq);
2712 ConvertWToSLock(&afs_xvcache);
2713 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2714 refpanic("FindVC VLRU inconsistent1");
2716 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2717 refpanic("FindVC VLRU inconsistent2");
2719 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2720 refpanic("FindVC VLRU inconsistent3");
2726 afs_stats_cmperf.vcacheHits++;
2728 afs_stats_cmperf.vcacheMisses++;
2729 if (afs_IsPrimaryCellNum(afid->Cell))
2730 afs_stats_cmperf.vlocalAccesses++;
2732 afs_stats_cmperf.vremoteAccesses++;
2734 *avcp = tvc; /* May be null */
2736 ReleaseSharedLock(&afs_xvcache);
2737 return (tvc ? 1 : 0);
2739 } /*afs_NFSFindVCache */
2747 * Initialize vcache related variables
2750 afs_vcacheInit(int astatSize)
2752 register struct vcache *tvp;
2754 #if defined(AFS_OSF_ENV)
2755 if (!afs_maxvcount) {
2756 #if defined(AFS_OSF30_ENV)
2757 afs_maxvcount = max_vnodes / 2; /* limit ourselves to half the total */
2759 afs_maxvcount = nvnode / 2; /* limit ourselves to half the total */
2761 if (astatSize < afs_maxvcount) {
2762 afs_maxvcount = astatSize;
2765 #else /* AFS_OSF_ENV */
2769 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2770 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2772 #if !defined(AFS_OSF_ENV)
2773 #ifdef AFS_LINUX26_ENV
2774 printf("old style would have needed %d contiguous bytes\n", astatSize *
2775 sizeof(struct vcache));
2776 Initial_freeVCList = freeVCList = tvp = (struct vcache *)
2777 afs_osi_Alloc(sizeof(struct vcache));
2778 for (i = 0; i < astatSize; i++) {
2779 tvp->nextfree = (struct vcache *) afs_osi_Alloc(sizeof(struct vcache));
2780 tvp = tvp->nextfree;
2782 tvp->nextfree = NULL;
2784 /* Allocate and thread the struct vcache entries */
2785 tvp = (struct vcache *)afs_osi_Alloc(astatSize * sizeof(struct vcache));
2786 memset((char *)tvp, 0, sizeof(struct vcache) * astatSize);
2788 Initial_freeVCList = tvp;
2789 freeVCList = &(tvp[0]);
2790 for (i = 0; i < astatSize - 1; i++) {
2791 tvp[i].nextfree = &(tvp[i + 1]);
2793 tvp[astatSize - 1].nextfree = NULL;
2794 #ifdef KERNEL_HAVE_PIN
2795 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2800 #if defined(AFS_SGI_ENV)
2801 for (i = 0; i < astatSize; i++) {
2802 char name[METER_NAMSZ];
2803 struct vcache *tvc = &tvp[i];
2805 tvc->v.v_number = ++afsvnumbers;
2806 tvc->vc_rwlockid = OSI_NO_LOCKID;
2807 initnsema(&tvc->vc_rwlock, 1,
2808 makesname(name, "vrw", tvc->v.v_number));
2809 #ifndef AFS_SGI53_ENV
2810 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2812 #ifndef AFS_SGI62_ENV
2813 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2814 #endif /* AFS_SGI62_ENV */
2828 shutdown_vcache(void)
2831 struct afs_cbr *tsp, *nsp;
2833 * XXX We may potentially miss some of the vcaches because if when there're no
2834 * free vcache entries and all the vcache entries are active ones then we allocate
2835 * an additional one - admittedly we almost never had that occur.
2839 register struct afs_q *tq, *uq;
2840 register struct vcache *tvc;
2841 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2845 osi_FreeSmallSpace(tvc->mvid);
2846 tvc->mvid = (struct VenusFid *)0;
2849 aix_gnode_rele(AFSTOV(tvc));
2851 if (tvc->linkData) {
2852 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2857 * Also free the remaining ones in the Cache
2859 for (i = 0; i < VCSIZE; i++) {
2860 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2862 osi_FreeSmallSpace(tvc->mvid);
2863 tvc->mvid = (struct VenusFid *)0;
2867 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2868 #ifdef AFS_AIX32_ENV
2871 vms_delete(tvc->segid);
2873 tvc->segid = tvc->vmh = NULL;
2875 osi_Panic("flushVcache: vm race");
2883 #if defined(AFS_SUN5_ENV)
2889 if (tvc->linkData) {
2890 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2894 afs_FreeAllAxs(&(tvc->Access));
2900 * Free any leftover callback queue
2902 for (tsp = afs_cbrSpace; tsp; tsp = nsp) {
2904 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2908 #ifdef AFS_LINUX26_ENV
2910 struct vcache *tvp = Initial_freeVCList;
2912 struct vcache *next = tvp->nextfree;
2914 afs_osi_Free(tvp, sizeof(struct vcache));
2919 #ifdef KERNEL_HAVE_PIN
2920 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2922 #if !defined(AFS_OSF_ENV)
2923 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2927 #if !defined(AFS_OSF_ENV)
2928 freeVCList = Initial_freeVCList = 0;
2930 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2931 LOCK_INIT(&afs_xvcb, "afs_xvcb");