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 "../afs/param.h" /*Should be always first*/
39 #include "../afs/sysincludes.h" /*Standard vendor system headers*/
40 #include "../afs/afsincludes.h" /*AFS-based standard headers*/
41 #include "../afs/afs_stats.h"
42 #include "../afs/afs_cbqueue.h"
43 #include "../afs/afs_osidnlc.h"
46 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
47 afs_int32 afs_vcount = 0; /* number of vcache in use now */
48 #if defined(AFS_OSF30_ENV)
49 extern int max_vnodes; /* number of total system vnodes */
51 extern int nvnode; /* number of total system vnodes */
54 extern int numvnodes; /* number vnodes in use now */
56 #endif /* AFS_OSF_ENV */
61 /* Imported variables */
62 extern struct server *afs_servers[NSERVERS];
63 extern afs_rwlock_t afs_xserver;
64 extern afs_rwlock_t afs_xcbhash;
65 extern struct vcache *afs_globalVp;
67 extern struct mount *afs_globalVFS;
68 extern struct vnodeops Afs_vnodeops;
70 extern struct vfs *afs_globalVFS;
71 #endif /* AFS_OSF_ENV */
72 #if defined(AFS_DUX40_ENV)
73 extern struct vfs_ubcops afs_ubcops;
76 extern struct vnodeops Afs_vnodeops;
80 #endif /* AFS_SGI64_ENV */
82 /* Exported variables */
83 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries*/
84 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks*/
85 struct vcache *freeVCList; /*Free list for stat cache entries*/
86 struct vcache *Initial_freeVCList; /*Initial list for above*/
87 struct afs_q VLRU; /*vcache LRU*/
88 afs_int32 vcachegen = 0;
89 unsigned int afs_paniconwarn = 0;
90 struct vcache *afs_vhashT[VCSIZE];
91 afs_int32 afs_bulkStatsLost;
92 int afs_norefpanic = 0;
94 /* Forward declarations */
95 static afs_int32 afs_QueueVCB(struct vcache *avc);
102 * Flush the given vcache entry.
105 * avc : Pointer to vcache entry to flush.
106 * slept : Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
109 * afs_xvcache lock must be held for writing upon entry to
110 * prevent people from changing the vrefCount field, and to
111 * protect the lruq and hnext fields.
112 * LOCK: afs_FlushVCache afs_xvcache W
113 * REFCNT: vcache ref count must be zero on entry except for osf1
114 * RACE: lock is dropped and reobtained, permitting race in caller
117 int afs_FlushVCache(struct vcache *avc, int *slept)
118 { /*afs_FlushVCache*/
120 register afs_int32 i, code;
121 register struct vcache **uvc, *wvc, *tvc;
124 AFS_STATCNT(afs_FlushVCache);
125 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
126 ICL_TYPE_INT32, avc->states);
129 VN_LOCK((struct vnode *)avc);
133 code = osi_VM_FlushVCache(avc, slept);
137 if (avc->states & CVFlushed) {
141 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
142 refpanic ("LRU vs. Free inconsistency");
144 avc->states |= CVFlushed;
145 /* pull the entry out of the lruq and put it on the free list */
146 QRemove(&avc->vlruq);
147 avc->vlruq.prev = avc->vlruq.next = (struct afs_q *) 0;
149 /* keep track of # of files that we bulk stat'd, but never used
150 * before they got recycled.
152 if (avc->states & CBulkStat)
155 /* remove entry from the hash chain */
156 i = VCHash(&avc->fid);
157 uvc = &afs_vhashT[i];
158 for(wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
161 avc->hnext = (struct vcache *) NULL;
165 if (!wvc) osi_Panic("flushvcache"); /* not in correct hash bucket */
166 if (avc->mvid) osi_FreeSmallSpace(avc->mvid);
167 avc->mvid = (struct VenusFid*)0;
169 afs_osi_Free(avc->linkData, strlen(avc->linkData)+1);
170 avc->linkData = NULL;
172 afs_FreeAllAxs(&(avc->Access));
174 /* we can't really give back callbacks on RO files, since the
175 * server only tracks them on a per-volume basis, and we don't
176 * know whether we still have some other files from the same
178 if ((avc->states & CRO) == 0 && avc->callback) {
181 ObtainWriteLock(&afs_xcbhash, 460);
182 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
183 avc->states &= ~(CStatd | CUnique);
184 ReleaseWriteLock(&afs_xcbhash);
185 afs_symhint_inval(avc);
186 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
187 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
189 osi_dnlc_purgevp (avc);
192 * Next, keep track of which vnodes we've deleted for create's
193 * optimistic synchronization algorithm
196 if (avc->fid.Fid.Vnode & 1) afs_oddZaps++;
199 #if !defined(AFS_OSF_ENV)
200 /* put the entry in the free list */
201 avc->nextfree = freeVCList;
203 if (avc->vlruq.prev || avc->vlruq.next) {
204 refpanic ("LRU vs. Free inconsistency");
207 /* This should put it back on the vnode free list since usecount is 1 */
210 if (avc->vrefCount > 0) {
211 VN_UNLOCK((struct vnode *)avc);
212 AFS_RELE((struct vnode *)avc);
214 if (afs_norefpanic) {
215 printf ("flush vc refcnt < 1");
217 (void) vgone(avc, VX_NOSLEEP, (struct vnodeops *) 0);
219 VN_UNLOCK((struct vnode *)avc);
221 else osi_Panic ("flush vc refcnt < 1");
223 #endif /* AFS_OSF_ENV */
224 avc->states |= CVFlushed;
229 VN_UNLOCK((struct vnode *)avc);
233 } /*afs_FlushVCache*/
239 * The core of the inactive vnode op for all but IRIX.
241 void afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred)
243 extern afs_rwlock_t afs_xdcache, afs_xvcache;
245 AFS_STATCNT(afs_inactive);
246 if (avc->states & CDirty) {
247 /* we can't keep trying to push back dirty data forever. Give up. */
248 afs_InvalidateAllSegments(avc, 1/*set lock*/); /* turns off dirty bit */
250 avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
251 avc->states &= ~CDirty; /* Turn it off */
252 if (avc->states & CUnlinked) {
253 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
254 avc->states |= CUnlinkedDel;
257 afs_remunlink(avc, 1); /* ignore any return code */
266 * Description: allocate a callback return structure from the
267 * free list and return it.
269 * Env: The alloc and free routines are both called with the afs_xvcb lock
270 * held, so we don't have to worry about blocking in osi_Alloc.
272 static struct afs_cbr *afs_cbrSpace = 0;
273 struct afs_cbr *afs_AllocCBR() {
274 register struct afs_cbr *tsp;
277 while (!afs_cbrSpace) {
278 if (afs_stats_cmperf.CallBackAlloced >= 2) {
279 /* don't allocate more than 2 * AFS_NCBRS for now */
281 afs_stats_cmperf.CallBackFlushes++;
285 tsp = (struct afs_cbr *) afs_osi_Alloc(AFS_NCBRS * sizeof(struct afs_cbr));
286 for(i=0; i < AFS_NCBRS-1; i++) {
287 tsp[i].next = &tsp[i+1];
289 tsp[AFS_NCBRS-1].next = 0;
291 afs_stats_cmperf.CallBackAlloced++;
295 afs_cbrSpace = tsp->next;
302 * Description: free a callback return structure.
305 * asp -- the address of the structure to free.
307 * Environment: the xvcb lock is held over these calls.
310 register struct afs_cbr *asp; {
311 asp->next = afs_cbrSpace;
319 * Description: flush all queued callbacks to all servers.
323 * Environment: holds xvcb lock over RPC to guard against race conditions
324 * when a new callback is granted for the same file later on.
326 afs_int32 afs_FlushVCBs (afs_int32 lockit)
328 struct AFSFid tfids[AFS_MAXCBRSCALL];
329 struct AFSCallBack callBacks[1];
330 struct AFSCBFids fidArray;
331 struct AFSCBs cbArray;
333 struct afs_cbr *tcbrp;
337 struct vrequest treq;
339 int safety1, safety2, safety3;
340 extern int afs_totalServers;
343 if (code = afs_InitReq(&treq, &afs_osi_cred)) return code;
344 treq.flags |= O_NONBLOCK;
346 if (lockit) MObtainWriteLock(&afs_xvcb,273);
347 ObtainReadLock(&afs_xserver);
348 for(i=0; i<NSERVERS; i++) {
349 for(safety1 = 0, tsp = afs_servers[i];
350 tsp && safety1 < afs_totalServers+10; tsp=tsp->next, safety1++) {
352 if (tsp->cbrs == (struct afs_cbr *) 0) continue;
354 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
355 * and make an RPC, over and over again.
357 tcount = 0; /* number found so far */
358 for (safety2 = 0; safety2 < afs_cacheStats ; safety2++) {
359 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
360 /* if buffer is full, or we've queued all we're going
361 * to from this server, we should flush out the
364 fidArray.AFSCBFids_len = tcount;
365 fidArray.AFSCBFids_val = (struct AFSFid *) tfids;
366 cbArray.AFSCBs_len = 1;
367 cbArray.AFSCBs_val = callBacks;
368 callBacks[0].CallBackType = CB_EXCLUSIVE;
369 for (safety3 = 0; safety3 < MAXHOSTS*2; safety3++) {
370 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
371 tsp->cell->cell, &treq, 0,
374 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
375 #ifdef RX_ENABLE_LOCKS
377 #endif /* RX_ENABLE_LOCKS */
378 code = RXAFS_GiveUpCallBacks(tc->id, &fidArray,
380 #ifdef RX_ENABLE_LOCKS
382 #endif /* RX_ENABLE_LOCKS */
386 if (!afs_Analyze(tc, code, 0, &treq,
387 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS,
388 SHARED_LOCK, tsp->cell)) {
392 /* ignore return code, since callbacks may have
393 * been returned anyway, we shouldn't leave them
394 * around to be returned again.
396 * Next, see if we are done with this server, and if so,
397 * break to deal with the next one.
399 if (!tsp->cbrs) break;
401 } /* if to flush full buffer */
402 /* if we make it here, we have an entry at the head of cbrs,
403 * which we should copy to the file ID array and then free.
406 tfids[tcount++] = tcbrp->fid;
407 tsp->cbrs = tcbrp->next;
409 } /* while loop for this one server */
410 if (safety2 > afs_cacheStats) {
411 afs_warn("possible internal error afs_flushVCBs (%d)\n", safety2);
413 } /* for loop for this hash chain */
414 } /* loop through all hash chains */
415 if (safety1 > afs_totalServers+2) {
416 afs_warn("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n", safety1, afs_totalServers+2);
418 osi_Panic("afs_flushVCBS safety1");
421 ReleaseReadLock(&afs_xserver);
422 if (lockit) MReleaseWriteLock(&afs_xvcb);
430 * Queue a callback on the given fid.
436 * Locks the xvcb lock.
437 * Called when the xvcache lock is already held.
440 static afs_int32 afs_QueueVCB(struct vcache *avc)
442 register struct server *tsp;
443 register struct afs_cbr *tcbp;
445 AFS_STATCNT(afs_QueueVCB);
446 /* The callback is really just a struct server ptr. */
447 tsp = (struct server *)(avc->callback);
449 /* we now have a pointer to the server, so we just allocate
450 * a queue entry and queue it.
452 MObtainWriteLock(&afs_xvcb,274);
453 tcbp = afs_AllocCBR();
454 tcbp->fid = avc->fid.Fid;
455 tcbp->next = tsp->cbrs;
458 /* now release locks and return */
459 MReleaseWriteLock(&afs_xvcb);
468 * Remove a queued callback by looking through all the servers
469 * to see if any have this callback queued.
472 * afid: The fid we want cleansed of queued callbacks.
475 * Locks xvcb and xserver locks.
476 * Typically called with xdcache, xvcache and/or individual vcache
481 register struct VenusFid *afid;
486 register struct server *tsp;
487 register struct afs_cbr *tcbrp;
488 struct afs_cbr **lcbrpp;
490 AFS_STATCNT(afs_RemoveVCB);
491 MObtainWriteLock(&afs_xvcb,275);
492 ObtainReadLock(&afs_xserver);
493 for(i=0;i<NSERVERS;i++) {
494 for(tsp=afs_servers[i]; tsp; tsp=tsp->next) {
495 /* if cell is known, and is wrong, then skip this server */
496 if (tsp->cell && tsp->cell->cell != afid->Cell) continue;
499 * Otherwise, iterate through file IDs we're sending to the
502 lcbrpp = &tsp->cbrs; /* first queued return callback */
503 for(tcbrp = *lcbrpp; tcbrp; lcbrpp = &tcbrp->next, tcbrp = *lcbrpp) {
504 if (afid->Fid.Volume == tcbrp->fid.Volume &&
505 afid->Fid.Unique == tcbrp->fid.Unique &&
506 afid->Fid.Vnode == tcbrp->fid.Vnode) {
507 *lcbrpp = tcbrp->next; /* unthread from list */
515 ReleaseReadLock(&afs_xserver);
516 MReleaseWriteLock(&afs_xvcb);
527 * This routine is responsible for allocating a new cache entry
528 * from the free list. It formats the cache entry and inserts it
529 * into the appropriate hash tables. It must be called with
530 * afs_xvcache write-locked so as to prevent several processes from
531 * trying to create a new cache entry simultaneously.
534 * afid : The file id of the file whose cache entry is being
537 /* LOCK: afs_NewVCache afs_xvcache W */
538 struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp,
539 afs_int32 lockit, afs_int32 locktype)
543 afs_int32 anumber = VCACHE_FREE;
545 struct gnode *gnodepnt;
548 struct vm_info * vm_info_ptr;
549 #endif /* AFS_MACH_ENV */
552 #endif /* AFS_OSF_ENV */
553 struct afs_q *tq, *uq;
556 AFS_STATCNT(afs_NewVCache);
557 #ifdef AFS_LINUX22_ENV
559 /* Free some if possible. */
560 struct afs_q *tq, *uq;
561 int i; char *panicstr;
562 int vmax = 2 * afs_cacheStats;
563 int vn = VCACHE_FREE;
566 for(tq = VLRU.prev; tq != &VLRU && vn > 0; tq = uq) {
569 if (tvc->states & CVFlushed)
570 refpanic ("CVFlushed on VLRU");
572 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
573 else if (QNext(uq) != tq)
574 refpanic ("VLRU inconsistent");
576 if (tvc == afs_globalVp)
579 if ( tvc->vrefCount && tvc->opens == 0 ) {
580 struct inode *ip = (struct inode*)tvc;
581 if (list_empty(&ip->i_dentry)) {
585 struct list_head *cur;
586 struct list_head *head = &ip->i_dentry;
589 #if defined(AFS_LINUX24_ENV)
590 spin_lock(&dcache_lock);
593 while ((cur = cur->next) != head) {
594 struct dentry *dentry = list_entry(cur, struct dentry, d_alias);
595 #if defined(AFS_LINUX24_ENV)
596 if (!atomic_read(&dentry->d_count)) {
598 if (!dentry->d_count) {
601 #if defined(AFS_LINUX24_ENV)
603 spin_unlock(&dcache_lock);
616 #if defined(AFS_LINUX24_ENV)
617 spin_unlock(&dcache_lock);
625 #endif /* AFS_LINUX22_ENV */
628 if (afs_vcount >= afs_maxvcount)
631 * If we are using > 33 % of the total system vnodes for AFS vcache
632 * entries or we are using the maximum number of vcache entries,
633 * then free some. (if our usage is > 33% we should free some, if
634 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
635 * we _must_ free some -- no choice).
637 if ( (( 3 * afs_vcount ) > nvnode) || ( afs_vcount >= afs_maxvcount ))
640 struct afs_q *tq, *uq;
641 int i; char *panicstr;
644 for(tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
647 if (tvc->states & CVFlushed)
648 refpanic ("CVFlushed on VLRU");
649 else if (i++ > afs_maxvcount)
650 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
651 else if (QNext(uq) != tq)
652 refpanic ("VLRU inconsistent");
653 else if (tvc->vrefCount < 1)
654 refpanic ("refcnt 0 on VLRU");
656 if ( tvc->vrefCount == 1 && tvc->opens == 0
657 && (tvc->states & CUnlinkedDel) == 0) {
658 code = afs_FlushVCache(tvc, &fv_slept);
665 continue; /* start over - may have raced. */
670 if (anumber == VCACHE_FREE) {
671 printf("NewVCache: warning none freed, using %d of %d\n",
672 afs_vcount, afs_maxvcount);
673 if (afs_vcount >= afs_maxvcount) {
674 osi_Panic("NewVCache - none freed");
675 /* XXX instead of panicing, should do afs_maxvcount++
676 and magic up another one */
682 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
683 /* What should we do ???? */
684 osi_Panic("afs_NewVCache: no more vnodes");
689 tvc->nextfree = (struct vcache *)0;
691 #else /* AFS_OSF_ENV */
692 /* pull out a free cache entry */
695 for(tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
699 if (tvc->states & CVFlushed)
700 refpanic("CVFlushed on VLRU");
701 else if (i++ > 2*afs_cacheStats) /* even allowing for a few xallocs...*/
702 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
703 else if (QNext(uq) != tq)
704 refpanic("VLRU inconsistent");
706 if (tvc->vrefCount == 0 && tvc->opens == 0
707 && (tvc->states & CUnlinkedDel) == 0) {
708 code = afs_FlushVCache(tvc, &fv_slept);
715 continue; /* start over - may have raced. */
718 if (tq == uq ) break;
722 /* none free, making one is better than a panic */
723 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
724 tvc = (struct vcache *) afs_osi_Alloc(sizeof (struct vcache));
726 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
729 /* In case it still comes here we need to fill this */
730 tvc->v.v_vm_info = VM_INFO_NULL;
731 vm_info_init(tvc->v.v_vm_info);
732 /* perhaps we should also do close_flush on non-NeXT mach systems;
733 * who knows; we don't currently have the sources.
735 #endif /* AFS_MACH_ENV */
736 #if defined(AFS_SGI_ENV)
737 { char name[METER_NAMSZ];
738 bzero(tvc, sizeof(struct vcache));
739 tvc->v.v_number = ++afsvnumbers;
740 tvc->vc_rwlockid = OSI_NO_LOCKID;
741 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
742 #ifndef AFS_SGI53_ENV
743 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
745 #ifndef AFS_SGI62_ENV
746 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
749 #endif /* AFS_SGI_ENV */
752 tvc = freeVCList; /* take from free list */
753 freeVCList = tvc->nextfree;
754 tvc->nextfree = (struct vcache *)0;
756 #endif /* AFS_OSF_ENV */
759 vm_info_ptr = tvc->v.v_vm_info;
760 #endif /* AFS_MACH_ENV */
762 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
763 bzero((char *)tvc, sizeof(struct vcache));
768 RWLOCK_INIT(&tvc->lock, "vcache lock");
769 #if defined(AFS_SUN5_ENV)
770 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
771 #endif /* defined(AFS_SUN5_ENV) */
774 tvc->v.v_vm_info = vm_info_ptr;
775 tvc->v.v_vm_info->pager = MEMORY_OBJECT_NULL;
776 #endif /* AFS_MACH_ENV */
777 tvc->parentVnode = 0;
778 tvc->mvid = (struct VenusFid *) 0;
779 tvc->linkData = (char *) 0;
782 tvc->execsOrWriters = 0;
786 tvc->last_looker = 0;
788 tvc->asynchrony = -1;
790 afs_symhint_inval(tvc);
792 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
795 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
796 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
798 /* Hold it for the LRU (should make count 2) */
799 VN_HOLD((struct vnode *)tvc);
800 #else /* AFS_OSF_ENV */
801 tvc->vrefCount = 1; /* us */
802 #endif /* AFS_OSF_ENV */
804 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
805 tvc->vmh = tvc->segid = NULL;
808 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
809 #if defined(AFS_SUN5_ENV)
810 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
812 #if defined(AFS_SUN55_ENV)
813 /* This is required if the kaio (kernel aynchronous io)
814 ** module is installed. Inside the kernel, the function
815 ** check_vp( common/os/aio.c) checks to see if the kernel has
816 ** to provide asynchronous io for this vnode. This
817 ** function extracts the device number by following the
818 ** v_data field of the vnode. If we do not set this field
819 ** then the system panics. The value of the v_data field
820 ** is not really important for AFS vnodes because the kernel
821 ** does not do asynchronous io for regular files. Hence,
822 ** for the time being, we fill up the v_data field with the
823 ** vnode pointer itself. */
824 tvc->v.v_data = (char *)tvc;
825 #endif /* AFS_SUN55_ENV */
827 afs_BozonInit(&tvc->pvnLock, tvc);
831 tvc->callback = serverp; /* to minimize chance that clear
833 /* initialize vnode data, note vrefCount is v.v_count */
835 /* Don't forget to free the gnode space */
836 tvc->v.v_gnode = gnodepnt = (struct gnode *) osi_AllocSmallSpace(sizeof(struct gnode));
837 bzero((char *)gnodepnt, sizeof(struct gnode));
840 bzero((void*)&(tvc->vc_bhv_desc), sizeof(tvc->vc_bhv_desc));
841 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
843 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
844 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
846 bhv_head_init(&(tvc->v.v_bh));
847 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
850 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion*)tvc;
852 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
854 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
856 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
857 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
859 vnode_pcache_init(&tvc->v);
860 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
861 /* Above define is never true execpt in SGI test kernels. */
862 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
865 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
868 SetAfsVnode((struct vnode *)tvc);
869 #endif /* AFS_SGI64_ENV */
871 * The proper value for mvstat (for root fids) is setup by the caller.
874 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
876 if (afs_globalVFS == 0) osi_Panic("afs globalvfs");
877 vSetVfsp(tvc, afs_globalVFS);
880 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
881 tvc->v.v_vfsprev = NULL;
882 afs_globalVFS->vfs_vnodes = &tvc->v;
883 if (tvc->v.v_vfsnext != NULL)
884 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
885 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us!*/
886 gnodepnt->gn_vnode = &tvc->v;
889 tvc->v.g_dev = ((struct mount *)afs_globalVFS->vfs_data)->m_dev;
891 #if defined(AFS_DUX40_ENV)
892 insmntque(tvc, afs_globalVFS, &afs_ubcops);
895 /* Is this needed??? */
896 insmntque(tvc, afs_globalVFS);
897 #endif /* AFS_OSF_ENV */
898 #endif /* AFS_DUX40_ENV */
899 #if defined(AFS_SGI_ENV)
900 VN_SET_DPAGES(&(tvc->v), (struct pfdat*)NULL);
901 osi_Assert((tvc->v.v_flag & VINACT) == 0);
903 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
904 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
905 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
906 osi_Assert(tvc->v.v_filocks == NULL);
907 #if !defined(AFS_SGI65_ENV)
908 osi_Assert(tvc->v.v_filocksem == NULL);
910 osi_Assert(tvc->cred == NULL);
912 vnode_pcache_reinit(&tvc->v);
913 tvc->v.v_rdev = NODEV;
915 vn_initlist((struct vnlist *)&tvc->v);
917 #endif /* AFS_SGI_ENV */
918 #if defined(AFS_LINUX22_ENV)
920 struct inode *ip = (struct inode*)tvc;
921 sema_init(&ip->i_sem, 1);
922 #if defined(AFS_LINUX24_ENV)
923 sema_init(&ip->i_zombie, 1);
924 init_waitqueue_head(&ip->i_wait);
925 spin_lock_init(&ip->i_data.i_shared_lock);
926 INIT_LIST_HEAD(&ip->i_data.clean_pages);
927 INIT_LIST_HEAD(&ip->i_data.dirty_pages);
928 INIT_LIST_HEAD(&ip->i_data.locked_pages);
929 INIT_LIST_HEAD(&ip->i_dirty_buffers);
930 ip->i_data.host = (void*) ip;
931 ip->i_mapping = &ip->i_data;
933 sema_init(&ip->i_atomic_write, 1);
934 init_waitqueue(&ip->i_wait);
936 INIT_LIST_HEAD(&ip->i_hash);
937 INIT_LIST_HEAD(&ip->i_dentry);
939 ip->i_dev = afs_globalVFS->s_dev;
940 ip->i_sb = afs_globalVFS;
945 osi_dnlc_purgedp(tvc); /* this may be overkill */
946 bzero((char *)&(tvc->quick),sizeof(struct vtodc));
947 bzero((char *)&(tvc->callsort),sizeof(struct afs_q));
948 tvc->slocks = (struct SimpleLocks *)0;
951 tvc->hnext = afs_vhashT[i];
953 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
954 refpanic ("NewVCache VLRU inconsistent");
956 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
957 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
958 refpanic ("NewVCache VLRU inconsistent2");
960 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
961 refpanic ("NewVCache VLRU inconsistent3");
963 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
964 refpanic ("NewVCache VLRU inconsistent4");
974 * afs_FlushActiveVcaches
980 * doflocks : Do we handle flocks?
982 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
984 afs_FlushActiveVcaches(doflocks)
985 register afs_int32 doflocks;
987 { /*afs_FlushActiveVcaches*/
989 register struct vcache *tvc;
991 register struct conn *tc;
992 register afs_int32 code;
993 register struct AFS_UCRED *cred;
994 struct vrequest treq, ureq;
995 struct AFSVolSync tsync;
999 AFS_STATCNT(afs_FlushActiveVcaches);
1000 ObtainReadLock(&afs_xvcache);
1001 for(i=0;i<VCSIZE;i++) {
1002 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
1003 if (doflocks && tvc->flockCount != 0) {
1004 /* if this entry has an flock, send a keep-alive call out */
1006 ReleaseReadLock(&afs_xvcache);
1007 ObtainWriteLock(&tvc->lock,51);
1009 afs_InitReq(&treq, &afs_osi_cred);
1010 treq.flags |= O_NONBLOCK;
1012 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1014 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1015 #ifdef RX_ENABLE_LOCKS
1017 #endif /* RX_ENABLE_LOCKS */
1019 RXAFS_ExtendLock(tc->id,
1020 (struct AFSFid *) &tvc->fid.Fid,
1022 #ifdef RX_ENABLE_LOCKS
1024 #endif /* RX_ENABLE_LOCKS */
1029 (afs_Analyze(tc, code, &tvc->fid, &treq,
1030 AFS_STATS_FS_RPCIDX_EXTENDLOCK,
1031 SHARED_LOCK, (struct cell *)0));
1033 ReleaseWriteLock(&tvc->lock);
1034 ObtainReadLock(&afs_xvcache);
1038 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1040 * Don't let it evaporate in case someone else is in
1041 * this code. Also, drop the afs_xvcache lock while
1042 * getting vcache locks.
1045 ReleaseReadLock(&afs_xvcache);
1046 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1047 afs_BozonLock(&tvc->pvnLock, tvc);
1049 #if defined(AFS_SGI_ENV)
1051 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1053 osi_Assert(tvc->vrefCount > 0);
1054 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1056 ObtainWriteLock(&tvc->lock,52);
1057 if (tvc->states & CCore) {
1058 tvc->states &= ~CCore;
1059 /* XXXX Find better place-holder for cred XXXX */
1060 cred = (struct AFS_UCRED *) tvc->linkData;
1061 tvc->linkData = (char *) 0; /* XXX */
1062 afs_InitReq(&ureq, cred);
1063 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1064 ICL_TYPE_POINTER, tvc,
1065 ICL_TYPE_INT32, tvc->execsOrWriters);
1066 code = afs_StoreOnLastReference(tvc, &ureq);
1067 ReleaseWriteLock(&tvc->lock);
1068 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1069 afs_BozonUnlock(&tvc->pvnLock, tvc);
1071 hzero(tvc->flushDV);
1074 if (code && code != VNOVNODE) {
1075 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1076 /* /dev/console */ 1);
1078 } else if (tvc->states & CUnlinkedDel) {
1082 ReleaseWriteLock(&tvc->lock);
1083 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1084 afs_BozonUnlock(&tvc->pvnLock, tvc);
1086 #if defined(AFS_SGI_ENV)
1087 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1089 afs_remunlink(tvc, 0);
1090 #if defined(AFS_SGI_ENV)
1091 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1095 /* lost (or won, perhaps) the race condition */
1096 ReleaseWriteLock(&tvc->lock);
1097 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1098 afs_BozonUnlock(&tvc->pvnLock, tvc);
1101 #if defined(AFS_SGI_ENV)
1102 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1104 ObtainReadLock(&afs_xvcache);
1110 AFS_RELE((struct vnode *)tvc);
1112 /* Matches write code setting CCore flag */
1118 ReleaseReadLock(&afs_xvcache);
1120 } /*afs_FlushActiveVcaches*/
1127 * Make sure a cache entry is up-to-date status-wise.
1129 * NOTE: everywhere that calls this can potentially be sped up
1130 * by checking CStatd first, and avoiding doing the InitReq
1131 * if this is up-to-date.
1133 * Anymore, the only places that call this KNOW already that the
1134 * vcache is not up-to-date, so we don't screw around.
1137 * avc : Ptr to vcache entry to verify.
1141 int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1143 register struct vcache *tvc;
1145 AFS_STATCNT(afs_VerifyVCache);
1147 #if defined(AFS_OSF_ENV)
1148 ObtainReadLock(&avc->lock);
1149 if (afs_IsWired(avc)) {
1150 ReleaseReadLock(&avc->lock);
1153 ReleaseReadLock(&avc->lock);
1154 #endif /* AFS_OSF_ENV */
1155 /* otherwise we must fetch the status info */
1157 ObtainWriteLock(&avc->lock,53);
1158 if (avc->states & CStatd) {
1159 ReleaseWriteLock(&avc->lock);
1162 ObtainWriteLock(&afs_xcbhash, 461);
1163 avc->states &= ~( CStatd | CUnique );
1164 avc->callback = (struct server *)0;
1165 afs_DequeueCallback(avc);
1166 ReleaseWriteLock(&afs_xcbhash);
1167 ReleaseWriteLock(&avc->lock);
1169 /* since we've been called back, or the callback has expired,
1170 * it's possible that the contents of this directory, or this
1171 * file's name have changed, thus invalidating the dnlc contents.
1173 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1174 osi_dnlc_purgedp (avc);
1176 osi_dnlc_purgevp (avc);
1178 /* fetch the status info */
1179 tvc = afs_GetVCache(&avc->fid, areq, (afs_int32*)0, avc, READ_LOCK);
1180 if (!tvc) return ENOENT;
1181 /* Put it back; caller has already incremented vrefCount */
1182 afs_PutVCache(tvc, READ_LOCK);
1185 } /*afs_VerifyVCache*/
1192 * Simple copy of stat info into cache.
1195 * avc : Ptr to vcache entry involved.
1196 * astat : Ptr to stat info to copy.
1199 * Nothing interesting.
1201 * Callers: as of 1992-04-29, only called by WriteVCache
1204 afs_SimpleVStat(avc, astat, areq)
1205 register struct vcache *avc;
1206 register struct AFSFetchStatus *astat;
1207 struct vrequest *areq;
1208 { /*afs_SimpleVStat*/
1210 AFS_STATCNT(afs_SimpleVStat);
1213 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1214 && !AFS_VN_MAPPED((vnode_t*)avc))
1216 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1220 #if defined(AFS_SGI_ENV)
1221 osi_Assert((valusema(&avc->vc_rwlock) <= 0) &&
1222 (OSI_GET_LOCKID() == avc->vc_rwlockid));
1223 if (astat->Length < avc->m.Length) {
1224 vnode_t *vp = (vnode_t *)avc;
1226 osi_Assert(WriteLocked(&avc->lock));
1227 ReleaseWriteLock(&avc->lock);
1229 PTOSSVP(vp, (off_t)astat->Length, (off_t)MAXLONG);
1231 ObtainWriteLock(&avc->lock,67);
1234 /* if writing the file, don't fetch over this value */
1235 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT,
1236 ICL_TYPE_POINTER, avc,
1237 ICL_TYPE_INT32, avc->m.Length,
1238 ICL_TYPE_INT32, astat->Length);
1239 avc->m.Length = astat->Length;
1240 avc->m.Date = astat->ClientModTime;
1242 avc->m.Owner = astat->Owner;
1243 avc->m.Group = astat->Group;
1244 avc->m.Mode = astat->UnixModeBits;
1245 if (vType(avc) == VREG) {
1246 avc->m.Mode |= S_IFREG;
1248 else if (vType(avc) == VDIR) {
1249 avc->m.Mode |= S_IFDIR;
1251 else if (vType(avc) == VLNK) {
1255 avc->m.Mode |= S_IFLNK;
1256 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1258 if (avc->states & CForeign) {
1259 struct axscache *ac;
1260 avc->anyAccess = astat->AnonymousAccess;
1262 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1264 * Caller has at least one bit not covered by anonymous, and
1265 * thus may have interesting rights.
1267 * HOWEVER, this is a really bad idea, because any access query
1268 * for bits which aren't covered by anonymous, on behalf of a user
1269 * who doesn't have any special rights, will result in an answer of
1270 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1271 * It's an especially bad idea under Ultrix, since (due to the lack of
1272 * a proper access() call) it must perform several afs_access() calls
1273 * in order to create magic mode bits that vary according to who makes
1274 * the call. In other words, _every_ stat() generates a test for
1277 #endif /* badidea */
1278 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1279 ac->axess = astat->CallerAccess;
1280 else /* not found, add a new one if possible */
1281 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1285 } /*afs_SimpleVStat*/
1292 * Store the status info *only* back to the server for a
1296 * avc : Ptr to the vcache entry.
1297 * astatus : Ptr to the status info to store.
1298 * areq : Ptr to the associated vrequest.
1301 * Must be called with a shared lock held on the vnode.
1304 afs_WriteVCache(avc, astatus, areq)
1305 register struct vcache *avc;
1306 register struct AFSStoreStatus *astatus;
1307 struct vrequest *areq;
1309 { /*afs_WriteVCache*/
1312 struct AFSFetchStatus OutStatus;
1313 struct AFSVolSync tsync;
1316 AFS_STATCNT(afs_WriteVCache);
1317 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1318 ICL_TYPE_INT32, avc->m.Length);
1321 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1323 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1324 #ifdef RX_ENABLE_LOCKS
1326 #endif /* RX_ENABLE_LOCKS */
1327 code = RXAFS_StoreStatus(tc->id,
1328 (struct AFSFid *) &avc->fid.Fid,
1329 astatus, &OutStatus, &tsync);
1330 #ifdef RX_ENABLE_LOCKS
1332 #endif /* RX_ENABLE_LOCKS */
1337 (afs_Analyze(tc, code, &avc->fid, areq,
1338 AFS_STATS_FS_RPCIDX_STORESTATUS,
1339 SHARED_LOCK, (struct cell *)0));
1341 UpgradeSToWLock(&avc->lock,20);
1343 /* success, do the changes locally */
1344 afs_SimpleVStat(avc, &OutStatus, areq);
1346 * Update the date, too. SimpleVStat didn't do this, since
1347 * it thought we were doing this after fetching new status
1348 * over a file being written.
1350 avc->m.Date = OutStatus.ClientModTime;
1353 /* failure, set up to check with server next time */
1354 ObtainWriteLock(&afs_xcbhash, 462);
1355 afs_DequeueCallback(avc);
1356 avc->states &= ~( CStatd | CUnique); /* turn off stat valid flag */
1357 ReleaseWriteLock(&afs_xcbhash);
1358 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1359 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
1361 ConvertWToSLock(&avc->lock);
1364 } /*afs_WriteVCache*/
1370 * Copy astat block into vcache info
1373 * avc : Ptr to vcache entry.
1374 * astat : Ptr to stat block to copy in.
1375 * areq : Ptr to associated request.
1378 * Must be called under a write lock
1380 * Note: this code may get dataversion and length out of sync if the file has
1381 * been modified. This is less than ideal. I haven't thought about
1382 * it sufficiently to be certain that it is adequate.
1385 afs_ProcessFS(avc, astat, areq)
1386 register struct vcache *avc;
1387 struct vrequest *areq;
1388 register struct AFSFetchStatus *astat;
1393 AFS_STATCNT(afs_ProcessFS);
1395 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1396 * number for each bulk status request. Under no circumstances
1397 * should afs_DoBulkStat store a sequence number if the new
1398 * length will be ignored when afs_ProcessFS is called with
1399 * new stats. If you change the following conditional then you
1400 * also need to change the conditional in afs_DoBulkStat. */
1402 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1403 && !AFS_VN_MAPPED((vnode_t*)avc))
1405 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1408 /* if we're writing or mapping this file, don't fetch over these
1411 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1412 ICL_TYPE_INT32, avc->m.Length,
1413 ICL_TYPE_INT32, astat->Length);
1414 avc->m.Length = astat->Length;
1415 avc->m.Date = astat->ClientModTime;
1417 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1418 avc->m.Owner = astat->Owner;
1419 avc->m.Mode = astat->UnixModeBits;
1420 avc->m.Group = astat->Group;
1421 avc->m.LinkCount = astat->LinkCount;
1422 if (astat->FileType == File) {
1423 vSetType(avc, VREG);
1424 avc->m.Mode |= S_IFREG;
1426 else if (astat->FileType == Directory) {
1427 vSetType(avc, VDIR);
1428 avc->m.Mode |= S_IFDIR;
1430 else if (astat->FileType == SymbolicLink) {
1431 vSetType(avc, VLNK);
1432 avc->m.Mode |= S_IFLNK;
1433 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1435 avc->anyAccess = astat->AnonymousAccess;
1437 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1439 * Caller has at least one bit not covered by anonymous, and
1440 * thus may have interesting rights.
1442 * HOWEVER, this is a really bad idea, because any access query
1443 * for bits which aren't covered by anonymous, on behalf of a user
1444 * who doesn't have any special rights, will result in an answer of
1445 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1446 * It's an especially bad idea under Ultrix, since (due to the lack of
1447 * a proper access() call) it must perform several afs_access() calls
1448 * in order to create magic mode bits that vary according to who makes
1449 * the call. In other words, _every_ stat() generates a test for
1452 #endif /* badidea */
1454 struct axscache *ac;
1455 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1456 ac->axess = astat->CallerAccess;
1457 else /* not found, add a new one if possible */
1458 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1461 #ifdef AFS_LINUX22_ENV
1462 vcache2inode(avc); /* Set the inode attr cache */
1468 afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp)
1469 register struct VenusFid *afid;
1470 struct vrequest *areq;
1472 struct VenusFid *nfid;
1473 struct AFSFetchStatus *OutStatusp;
1474 struct AFSCallBack *CallBackp;
1475 struct server **serverp;
1476 struct AFSVolSync *tsyncp;
1479 register struct vcache *tvc;
1482 register struct conn *tc;
1483 struct AFSFetchStatus OutDirStatus;
1486 if (!name) name = ""; /* XXX */
1488 tc = afs_Conn(afid, areq, SHARED_LOCK);
1490 if (serverp) *serverp = tc->srvr->server;
1492 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1493 #ifdef RX_ENABLE_LOCKS
1495 #endif /* RX_ENABLE_LOCKS */
1496 code = RXAFS_Lookup(tc->id, (struct AFSFid *) &afid->Fid, name,
1497 (struct AFSFid *) &nfid->Fid,
1498 OutStatusp, &OutDirStatus, CallBackp, tsyncp);
1499 #ifdef RX_ENABLE_LOCKS
1501 #endif /* RX_ENABLE_LOCKS */
1506 (afs_Analyze(tc, code, afid, areq,
1507 AFS_STATS_FS_RPCIDX_XLOOKUP,
1508 SHARED_LOCK, (struct cell *)0));
1518 * Given a file id and a vrequest structure, fetch the status
1519 * information associated with the file.
1523 * areq : Ptr to associated vrequest structure, specifying the
1524 * user whose authentication tokens will be used.
1525 * avc : caller may already have a vcache for this file, which is
1529 * The cache entry is returned with an increased vrefCount field.
1530 * The entry must be discarded by calling afs_PutVCache when you
1531 * are through using the pointer to the cache entry.
1533 * You should not hold any locks when calling this function, except
1534 * locks on other vcache entries. If you lock more than one vcache
1535 * entry simultaneously, you should lock them in this order:
1537 * 1. Lock all files first, then directories.
1538 * 2. Within a particular type, lock entries in Fid.Vnode order.
1540 * This locking hierarchy is convenient because it allows locking
1541 * of a parent dir cache entry, given a file (to check its access
1542 * control list). It also allows renames to be handled easily by
1543 * locking directories in a constant order.
1544 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1546 struct vcache *afs_GetVCache(afid, areq, cached, avc, locktype)
1547 register struct VenusFid *afid;
1548 struct vrequest *areq;
1551 struct vcache *avc; /* might have a vcache structure already, which must
1552 * already be held by the caller */
1555 afs_int32 code, i, newvcache=0;
1556 register struct vcache *tvc;
1560 AFS_STATCNT(afs_GetVCache);
1562 if (cached) *cached = 0; /* Init just in case */
1565 ObtainSharedLock(&afs_xvcache,5);
1567 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS | DO_VLRU );
1569 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1570 ReleaseSharedLock(&afs_xvcache);
1571 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1579 if (tvc->states & CStatd) {
1580 ReleaseSharedLock(&afs_xvcache);
1585 UpgradeSToWLock(&afs_xvcache,21);
1587 /* no cache entry, better grab one */
1588 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1591 ConvertWToSLock(&afs_xvcache);
1592 afs_stats_cmperf.vcacheMisses++;
1595 ReleaseSharedLock(&afs_xvcache);
1597 ObtainWriteLock(&tvc->lock,54);
1599 if (tvc->states & CStatd) {
1600 #ifdef AFS_LINUX22_ENV
1603 ReleaseWriteLock(&tvc->lock);
1607 #if defined(AFS_OSF_ENV)
1608 if (afs_IsWired(tvc)) {
1609 ReleaseWriteLock(&tvc->lock);
1612 #endif /* AFS_OSF_ENV */
1614 ObtainWriteLock(&afs_xcbhash, 464);
1615 tvc->states &= ~CUnique;
1617 afs_DequeueCallback(tvc);
1618 ReleaseWriteLock(&afs_xcbhash);
1620 /* It is always appropriate to throw away all the access rights? */
1621 afs_FreeAllAxs(&(tvc->Access));
1622 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1624 if ((tvp->states & VForeign)) {
1625 if (newvcache) tvc->states |= CForeign;
1626 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1627 && (tvp->rootUnique == afid->Fid.Unique)) {
1631 if (tvp->states & VRO) tvc->states |= CRO;
1632 if (tvp->states & VBackup) tvc->states |= CBackup;
1633 /* now copy ".." entry back out of volume structure, if necessary */
1634 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1636 tvc->mvid = (struct VenusFid *)
1637 osi_AllocSmallSpace(sizeof(struct VenusFid));
1638 *tvc->mvid = tvp->dotdot;
1640 afs_PutVolume(tvp, READ_LOCK);
1644 afs_RemoveVCB(afid);
1646 struct AFSFetchStatus OutStatus;
1647 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1651 ReleaseWriteLock(&tvc->lock);
1653 ObtainReadLock(&afs_xvcache);
1655 ReleaseReadLock(&afs_xvcache);
1656 return (struct vcache *) 0;
1659 ReleaseWriteLock(&tvc->lock);
1666 struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1667 afs_int32 *cached, afs_int32 locktype,
1668 struct vcache *adp, char *aname)
1670 afs_int32 code, now, newvcache=0, hash;
1671 struct VenusFid nfid;
1672 register struct vcache *tvc;
1674 struct AFSFetchStatus OutStatus;
1675 struct AFSCallBack CallBack;
1676 struct AFSVolSync tsync;
1677 struct server *serverp = 0;
1681 AFS_STATCNT(afs_GetVCache);
1682 if (cached) *cached = 0; /* Init just in case */
1685 ObtainReadLock(&afs_xvcache);
1686 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS /* no vlru */);
1689 ReleaseReadLock(&afs_xvcache);
1691 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1692 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1696 ObtainReadLock(&tvc->lock);
1698 if (tvc->states & CStatd) {
1702 ReleaseReadLock(&tvc->lock);
1705 tvc->states &= ~CUnique;
1707 ReleaseReadLock(&tvc->lock);
1708 ObtainReadLock(&afs_xvcache);
1712 ReleaseReadLock(&afs_xvcache);
1714 /* lookup the file */
1717 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1718 code = afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1722 ObtainSharedLock(&afs_xvcache,6);
1723 tvc = afs_FindVCache(&nfid, 0, 0, &retry, DO_VLRU /* no xstats now*/);
1725 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1726 ReleaseSharedLock(&afs_xvcache);
1727 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1733 /* no cache entry, better grab one */
1734 UpgradeSToWLock(&afs_xvcache,22);
1735 tvc = afs_NewVCache(&nfid, (struct server *)0, 1, WRITE_LOCK);
1737 ConvertWToSLock(&afs_xvcache);
1740 ReleaseSharedLock(&afs_xvcache);
1741 ObtainWriteLock(&tvc->lock,55);
1743 /* It is always appropriate to throw away all the access rights? */
1744 afs_FreeAllAxs(&(tvc->Access));
1745 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1747 if ((tvp->states & VForeign)) {
1748 if (newvcache) tvc->states |= CForeign;
1749 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1750 && (tvp->rootUnique == afid->Fid.Unique))
1753 if (tvp->states & VRO) tvc->states |= CRO;
1754 if (tvp->states & VBackup) tvc->states |= CBackup;
1755 /* now copy ".." entry back out of volume structure, if necessary */
1756 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1758 tvc->mvid = (struct VenusFid *)
1759 osi_AllocSmallSpace(sizeof(struct VenusFid));
1760 *tvc->mvid = tvp->dotdot;
1765 ObtainWriteLock(&afs_xcbhash, 465);
1766 afs_DequeueCallback(tvc);
1767 tvc->states &= ~( CStatd | CUnique );
1768 ReleaseWriteLock(&afs_xcbhash);
1769 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1770 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1772 afs_PutVolume(tvp, READ_LOCK);
1773 ReleaseWriteLock(&tvc->lock);
1774 ObtainReadLock(&afs_xvcache);
1776 ReleaseReadLock(&afs_xvcache);
1777 return (struct vcache *) 0;
1780 ObtainWriteLock(&afs_xcbhash, 466);
1781 if (origCBs == afs_allCBs) {
1782 if (CallBack.ExpirationTime) {
1783 tvc->callback = serverp;
1784 tvc->cbExpires = CallBack.ExpirationTime+now;
1785 tvc->states |= CStatd | CUnique;
1786 tvc->states &= ~CBulkFetching;
1787 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1788 } else if (tvc->states & CRO) {
1789 /* adapt gives us an hour. */
1790 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
1791 tvc->states |= CStatd | CUnique;
1792 tvc->states &= ~CBulkFetching;
1793 afs_QueueCallback(tvc, CBHash(3600), tvp);
1795 tvc->callback = (struct server *)0;
1796 afs_DequeueCallback(tvc);
1797 tvc->states &= ~(CStatd | CUnique);
1798 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1799 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1802 afs_DequeueCallback(tvc);
1803 tvc->states &= ~CStatd;
1804 tvc->states &= ~CUnique;
1805 tvc->callback = (struct server *)0;
1806 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1807 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1809 ReleaseWriteLock(&afs_xcbhash);
1811 afs_PutVolume(tvp, READ_LOCK);
1812 afs_ProcessFS(tvc, &OutStatus, areq);
1814 ReleaseWriteLock(&tvc->lock);
1819 struct vcache *afs_GetRootVCache(struct VenusFid *afid,
1820 struct vrequest *areq, afs_int32 *cached,
1821 struct volume *tvolp, afs_int32 locktype)
1823 afs_int32 code, i, newvcache = 0, haveStatus = 0;
1824 afs_int32 getNewFid = 0;
1826 struct VenusFid nfid;
1827 register struct vcache *tvc;
1828 struct server *serverp = 0;
1829 struct AFSFetchStatus OutStatus;
1830 struct AFSCallBack CallBack;
1831 struct AFSVolSync tsync;
1837 if (!tvolp->rootVnode || getNewFid) {
1838 struct VenusFid tfid;
1841 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1842 origCBs = afs_allCBs; /* ignore InitCallBackState */
1843 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid,
1844 &OutStatus, &CallBack, &serverp, &tsync);
1846 return (struct vcache *)0;
1848 /* ReleaseReadLock(&tvolp->lock); */
1849 ObtainWriteLock(&tvolp->lock,56);
1850 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
1851 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
1852 ReleaseWriteLock(&tvolp->lock);
1853 /* ObtainReadLock(&tvolp->lock);*/
1856 afid->Fid.Vnode = tvolp->rootVnode;
1857 afid->Fid.Unique = tvolp->rootUnique;
1860 ObtainSharedLock(&afs_xvcache,7);
1862 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1863 if (!FidCmp(&(tvc->fid), afid)) {
1865 /* Grab this vnode, possibly reactivating from the free list */
1866 /* for the present (95.05.25) everything on the hash table is
1867 * definitively NOT in the free list -- at least until afs_reclaim
1868 * can be safely implemented */
1871 vg = vget((struct vnode *)tvc); /* this bumps ref count */
1875 #endif /* AFS_OSF_ENV */
1880 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
1881 /* Mount point no longer stat'd or unknown. FID may have changed. */
1886 tvc = (struct vcache*)0;
1888 ReleaseSharedLock(&afs_xvcache);
1893 UpgradeSToWLock(&afs_xvcache,23);
1894 /* no cache entry, better grab one */
1895 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1897 afs_stats_cmperf.vcacheMisses++;
1900 if (cached) *cached = 1;
1901 afs_stats_cmperf.vcacheHits++;
1903 /* we already bumped the ref count in the for loop above */
1904 #else /* AFS_OSF_ENV */
1907 UpgradeSToWLock(&afs_xvcache,24);
1908 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1909 refpanic ("GRVC VLRU inconsistent0");
1911 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1912 refpanic ("GRVC VLRU inconsistent1");
1914 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1915 refpanic ("GRVC VLRU inconsistent2");
1917 QRemove(&tvc->vlruq); /* move to lruq head */
1918 QAdd(&VLRU, &tvc->vlruq);
1919 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1920 refpanic ("GRVC VLRU inconsistent3");
1922 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1923 refpanic ("GRVC VLRU inconsistent4");
1925 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1926 refpanic ("GRVC VLRU inconsistent5");
1931 ReleaseWriteLock(&afs_xvcache);
1933 if (tvc->states & CStatd) {
1937 ObtainReadLock(&tvc->lock);
1938 tvc->states &= ~CUnique;
1939 tvc->callback = (struct server *)0; /* redundant, perhaps */
1940 ReleaseReadLock(&tvc->lock);
1943 ObtainWriteLock(&tvc->lock,57);
1945 /* It is always appropriate to throw away all the access rights? */
1946 afs_FreeAllAxs(&(tvc->Access));
1948 if (newvcache) tvc->states |= CForeign;
1949 if (tvolp->states & VRO) tvc->states |= CRO;
1950 if (tvolp->states & VBackup) tvc->states |= CBackup;
1951 /* now copy ".." entry back out of volume structure, if necessary */
1952 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
1953 && (tvolp->rootUnique == afid->Fid.Unique)) {
1956 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
1958 tvc->mvid = (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid));
1959 *tvc->mvid = tvolp->dotdot;
1963 afs_RemoveVCB(afid);
1966 struct VenusFid tfid;
1969 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1970 origCBs = afs_allCBs; /* ignore InitCallBackState */
1971 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid, &OutStatus,
1972 &CallBack, &serverp, &tsync);
1976 ObtainWriteLock(&afs_xcbhash, 467);
1977 afs_DequeueCallback(tvc);
1978 tvc->callback = (struct server *)0;
1979 tvc->states &= ~(CStatd|CUnique);
1980 ReleaseWriteLock(&afs_xcbhash);
1981 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1982 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1983 ReleaseWriteLock(&tvc->lock);
1984 ObtainReadLock(&afs_xvcache);
1986 ReleaseReadLock(&afs_xvcache);
1987 return (struct vcache *) 0;
1990 ObtainWriteLock(&afs_xcbhash, 468);
1991 if (origCBs == afs_allCBs) {
1992 tvc->states |= CTruth;
1993 tvc->callback = serverp;
1994 if (CallBack.ExpirationTime != 0) {
1995 tvc->cbExpires = CallBack.ExpirationTime+start;
1996 tvc->states |= CStatd;
1997 tvc->states &= ~CBulkFetching;
1998 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
1999 } else if (tvc->states & CRO) {
2000 /* adapt gives us an hour. */
2001 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2002 tvc->states |= CStatd;
2003 tvc->states &= ~CBulkFetching;
2004 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2007 afs_DequeueCallback(tvc);
2008 tvc->callback = (struct server *)0;
2009 tvc->states &= ~(CStatd | CUnique);
2010 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2011 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2013 ReleaseWriteLock(&afs_xcbhash);
2014 afs_ProcessFS(tvc, &OutStatus, areq);
2016 ReleaseWriteLock(&tvc->lock);
2023 * must be called with avc write-locked
2024 * don't absolutely have to invalidate the hint unless the dv has
2025 * changed, but be sure to get it right else there will be consistency bugs.
2027 afs_int32 afs_FetchStatus(struct vcache *avc, struct VenusFid *afid,
2028 struct vrequest *areq, struct AFSFetchStatus *Outsp)
2032 register struct conn *tc;
2033 struct AFSCallBack CallBack;
2034 struct AFSVolSync tsync;
2035 struct volume* volp;
2039 tc = afs_Conn(afid, areq, SHARED_LOCK);
2040 avc->quick.stamp = 0; avc->h1.dchint = NULL; /* invalidate hints */
2042 avc->callback = tc->srvr->server;
2044 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2045 #ifdef RX_ENABLE_LOCKS
2047 #endif /* RX_ENABLE_LOCKS */
2048 code = RXAFS_FetchStatus(tc->id,
2049 (struct AFSFid *) &afid->Fid,
2050 Outsp, &CallBack, &tsync);
2051 #ifdef RX_ENABLE_LOCKS
2053 #endif /* RX_ENABLE_LOCKS */
2060 (afs_Analyze(tc, code, afid, areq,
2061 AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2062 SHARED_LOCK, (struct cell *)0));
2065 afs_ProcessFS(avc, Outsp, areq);
2066 volp = afs_GetVolume(afid, areq, READ_LOCK);
2067 ObtainWriteLock(&afs_xcbhash, 469);
2068 avc->states |= CTruth;
2069 if (avc->callback /* check for race */) {
2070 if (CallBack.ExpirationTime != 0) {
2071 avc->cbExpires = CallBack.ExpirationTime+start;
2072 avc->states |= CStatd;
2073 avc->states &= ~CBulkFetching;
2074 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2076 else if (avc->states & CRO)
2077 { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2078 avc->cbExpires = 3600+start;
2079 avc->states |= CStatd;
2080 avc->states &= ~CBulkFetching;
2081 afs_QueueCallback(avc, CBHash(3600), volp);
2084 afs_DequeueCallback(avc);
2085 avc->callback = (struct server *)0;
2086 avc->states &= ~(CStatd|CUnique);
2087 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2088 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2092 afs_DequeueCallback(avc);
2093 avc->callback = (struct server *)0;
2094 avc->states &= ~(CStatd|CUnique);
2095 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2096 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2098 ReleaseWriteLock(&afs_xcbhash);
2100 afs_PutVolume(volp, READ_LOCK);
2102 else { /* used to undo the local callback, but that's too extreme.
2103 * There are plenty of good reasons that fetchstatus might return
2104 * an error, such as EPERM. If we have the vnode cached, statd,
2105 * with callback, might as well keep track of the fact that we
2106 * don't have access...
2108 if (code == EPERM || code == EACCES) {
2109 struct axscache *ac;
2110 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2112 else /* not found, add a new one if possible */
2113 afs_AddAxs(avc->Access, areq->uid, 0);
2123 * Stuff some information into the vcache for the given file.
2126 * afid : File in question.
2127 * OutStatus : Fetch status on the file.
2128 * CallBack : Callback info.
2129 * tc : RPC connection involved.
2130 * areq : vrequest involved.
2133 * Nothing interesting.
2136 afs_StuffVcache(afid, OutStatus, CallBack, tc, areq)
2137 register struct VenusFid *afid;
2138 struct AFSFetchStatus *OutStatus;
2139 struct AFSCallBack *CallBack;
2140 register struct conn *tc;
2141 struct vrequest *areq;
2143 { /*afs_StuffVcache*/
2145 register afs_int32 code, i, newvcache=0;
2146 register struct vcache *tvc;
2147 struct AFSVolSync tsync;
2149 struct axscache *ac;
2152 AFS_STATCNT(afs_StuffVcache);
2153 #ifdef IFS_VCACHECOUNT
2158 ObtainSharedLock(&afs_xvcache,8);
2160 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_VLRU /* no stats */);
2162 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2163 ReleaseSharedLock(&afs_xvcache);
2164 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2170 /* no cache entry, better grab one */
2171 UpgradeSToWLock(&afs_xvcache,25);
2172 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
2174 ConvertWToSLock(&afs_xvcache);
2177 ReleaseSharedLock(&afs_xvcache);
2178 ObtainWriteLock(&tvc->lock,58);
2180 tvc->states &= ~CStatd;
2181 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2182 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2184 /* Is it always appropriate to throw away all the access rights? */
2185 afs_FreeAllAxs(&(tvc->Access));
2187 /*Copy useful per-volume info*/
2188 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2190 if (newvcache && (tvp->states & VForeign)) tvc->states |= CForeign;
2191 if (tvp->states & VRO) tvc->states |= CRO;
2192 if (tvp->states & VBackup) tvc->states |= CBackup;
2194 * Now, copy ".." entry back out of volume structure, if
2197 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2198 if (!tvc->mvid) tvc->mvid =
2199 (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid));
2200 *tvc->mvid = tvp->dotdot;
2203 /* store the stat on the file */
2204 afs_RemoveVCB(afid);
2205 afs_ProcessFS(tvc, OutStatus, areq);
2206 tvc->callback = tc->srvr->server;
2208 /* we use osi_Time twice below. Ideally, we would use the time at which
2209 * the FetchStatus call began, instead, but we don't have it here. So we
2210 * make do with "now". In the CRO case, it doesn't really matter. In
2211 * the other case, we hope that the difference between "now" and when the
2212 * call actually began execution on the server won't be larger than the
2213 * padding which the server keeps. Subtract 1 second anyway, to be on
2214 * the safe side. Can't subtract more because we don't know how big
2215 * ExpirationTime is. Possible consistency problems may arise if the call
2216 * timeout period becomes longer than the server's expiration padding. */
2217 ObtainWriteLock(&afs_xcbhash, 470);
2218 if (CallBack->ExpirationTime != 0) {
2219 tvc->cbExpires = CallBack->ExpirationTime+osi_Time()-1;
2220 tvc->states |= CStatd;
2221 tvc->states &= ~CBulkFetching;
2222 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2224 else if (tvc->states & CRO) {
2225 /* old-fashioned AFS 3.2 style */
2226 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2227 tvc->states |= CStatd;
2228 tvc->states &= ~CBulkFetching;
2229 afs_QueueCallback(tvc, CBHash(3600), tvp);
2232 afs_DequeueCallback(tvc);
2233 tvc->callback = (struct server *)0;
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);
2240 afs_PutVolume(tvp, READ_LOCK);
2242 /* look in per-pag cache */
2243 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2244 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2245 else /* not found, add a new one if possible */
2246 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2248 ReleaseWriteLock(&tvc->lock);
2249 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2250 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32, tvc->cbExpires,
2251 ICL_TYPE_INT32, tvc->cbExpires-osi_Time());
2253 * Release ref count... hope this guy stays around...
2255 afs_PutVCache(tvc, WRITE_LOCK);
2256 } /*afs_StuffVcache*/
2262 * Decrements the reference count on a cache entry.
2265 * avc : Pointer to the cache entry to decrement.
2268 * Nothing interesting.
2271 afs_PutVCache(avc, locktype)
2272 register struct vcache *avc;
2276 AFS_STATCNT(afs_PutVCache);
2278 * Can we use a read lock here?
2280 ObtainReadLock(&afs_xvcache);
2282 ReleaseReadLock(&afs_xvcache);
2289 * Find a vcache entry given a fid.
2292 * afid : Pointer to the fid whose cache entry we desire.
2293 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2294 * unlock the vnode, and try again.
2295 * flags: bit 1 to specify whether to compute hit statistics. Not
2296 * set if FindVCache is called as part of internal bookkeeping.
2299 * Must be called with the afs_xvcache lock at least held at
2300 * the read level. In order to do the VLRU adjustment, the xvcache lock
2301 * must be shared-- we upgrade it here.
2304 struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit,
2305 afs_int32 locktype, afs_int32 *retry, afs_int32 flag)
2308 register struct vcache *tvc;
2311 AFS_STATCNT(afs_FindVCache);
2314 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2315 if (FidMatches(afid, tvc)) {
2317 /* Grab this vnode, possibly reactivating from the free list */
2320 vg = vget((struct vnode *)tvc);
2324 #endif /* AFS_OSF_ENV */
2329 /* should I have a read lock on the vnode here? */
2331 if (retry) *retry = 0;
2332 #if !defined(AFS_OSF_ENV)
2333 osi_vnhold(tvc, retry); /* already held, above */
2334 if (retry && *retry)
2338 * only move to front of vlru if we have proper vcache locking)
2340 if (flag & DO_VLRU) {
2341 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2342 refpanic ("FindVC VLRU inconsistent1");
2344 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2345 refpanic ("FindVC VLRU inconsistent1");
2347 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2348 refpanic ("FindVC VLRU inconsistent2");
2350 UpgradeSToWLock(&afs_xvcache,26);
2351 QRemove(&tvc->vlruq);
2352 QAdd(&VLRU, &tvc->vlruq);
2353 ConvertWToSLock(&afs_xvcache);
2354 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2355 refpanic ("FindVC VLRU inconsistent1");
2357 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2358 refpanic ("FindVC VLRU inconsistent2");
2360 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2361 refpanic ("FindVC VLRU inconsistent3");
2367 if (flag & DO_STATS) {
2368 if (tvc) afs_stats_cmperf.vcacheHits++;
2369 else afs_stats_cmperf.vcacheMisses++;
2370 if (afid->Cell == LOCALCELL)
2371 afs_stats_cmperf.vlocalAccesses++;
2373 afs_stats_cmperf.vremoteAccesses++;
2376 #ifdef AFS_LINUX22_ENV
2377 if (tvc && (tvc->states & CStatd))
2378 vcache2inode(tvc); /* mainly to reset i_nlink */
2381 } /*afs_FindVCache*/
2387 * Find a vcache entry given a fid. Does a wildcard match on what we
2388 * have for the fid. If more than one entry, don't return anything.
2391 * avcp : Fill in pointer if we found one and only one.
2392 * afid : Pointer to the fid whose cache entry we desire.
2393 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2394 * unlock the vnode, and try again.
2395 * flags: bit 1 to specify whether to compute hit statistics. Not
2396 * set if FindVCache is called as part of internal bookkeeping.
2399 * Must be called with the afs_xvcache lock at least held at
2400 * the read level. In order to do the VLRU adjustment, the xvcache lock
2401 * must be shared-- we upgrade it here.
2404 * number of matches found.
2407 int afs_duplicate_nfs_fids=0;
2409 afs_int32 afs_NFSFindVCache(avcp, afid, lockit)
2410 struct vcache **avcp;
2411 struct VenusFid *afid;
2413 { /*afs_FindVCache*/
2415 register struct vcache *tvc;
2417 afs_int32 retry = 0;
2418 afs_int32 count = 0;
2419 struct vcache *found_tvc = NULL;
2421 AFS_STATCNT(afs_FindVCache);
2425 ObtainSharedLock(&afs_xvcache,331);
2428 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2429 /* Match only on what we have.... */
2430 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2431 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2432 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2433 && (tvc->fid.Cell == afid->Cell)) {
2435 /* Grab this vnode, possibly reactivating from the free list */
2438 vg = vget((struct vnode *)tvc);
2441 /* This vnode no longer exists. */
2444 #endif /* AFS_OSF_ENV */
2449 /* Drop our reference counts. */
2450 vrele((struct vnode *)tvc);
2451 vrele((struct vnode *)found_tvc);
2453 afs_duplicate_nfs_fids++;
2454 ReleaseSharedLock(&afs_xvcache);
2462 /* should I have a read lock on the vnode here? */
2464 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2465 osi_vnhold(tvc, &retry);
2468 found_tvc = (struct vcache*)0;
2469 ReleaseSharedLock(&afs_xvcache);
2470 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2474 #if !defined(AFS_OSF_ENV)
2475 osi_vnhold(tvc, (int*)0); /* already held, above */
2479 * We obtained the xvcache lock above.
2481 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2482 refpanic ("FindVC VLRU inconsistent1");
2484 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2485 refpanic ("FindVC VLRU inconsistent1");
2487 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2488 refpanic ("FindVC VLRU inconsistent2");
2490 UpgradeSToWLock(&afs_xvcache,568);
2491 QRemove(&tvc->vlruq);
2492 QAdd(&VLRU, &tvc->vlruq);
2493 ConvertWToSLock(&afs_xvcache);
2494 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2495 refpanic ("FindVC VLRU inconsistent1");
2497 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2498 refpanic ("FindVC VLRU inconsistent2");
2500 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2501 refpanic ("FindVC VLRU inconsistent3");
2506 if (tvc) afs_stats_cmperf.vcacheHits++;
2507 else afs_stats_cmperf.vcacheMisses++;
2508 if (afid->Cell == LOCALCELL)
2509 afs_stats_cmperf.vlocalAccesses++;
2511 afs_stats_cmperf.vremoteAccesses++;
2513 *avcp = tvc; /* May be null */
2515 ReleaseSharedLock(&afs_xvcache);
2516 return (tvc ? 1 : 0);
2518 } /*afs_NFSFindVCache*/
2526 * Initialize vcache related variables
2528 void afs_vcacheInit(int astatSize)
2530 register struct vcache *tvp;
2532 #if defined(AFS_OSF_ENV)
2533 if (!afs_maxvcount) {
2534 #if defined(AFS_OSF30_ENV)
2535 afs_maxvcount = max_vnodes/2; /* limit ourselves to half the total */
2537 afs_maxvcount = nvnode/2; /* limit ourselves to half the total */
2539 if (astatSize < afs_maxvcount) {
2540 afs_maxvcount = astatSize;
2543 #else /* AFS_OSF_ENV */
2544 freeVCList = (struct vcache *)0;
2547 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2548 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2550 #if !defined(AFS_OSF_ENV)
2551 /* Allocate and thread the struct vcache entries */
2552 tvp = (struct vcache *) afs_osi_Alloc(astatSize * sizeof(struct vcache));
2553 bzero((char *)tvp, sizeof(struct vcache)*astatSize);
2555 Initial_freeVCList = tvp;
2556 freeVCList = &(tvp[0]);
2557 for(i=0; i < astatSize-1; i++) {
2558 tvp[i].nextfree = &(tvp[i+1]);
2560 tvp[astatSize-1].nextfree = (struct vcache *) 0;
2561 #ifdef AFS_AIX32_ENV
2562 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2567 #if defined(AFS_SGI_ENV)
2568 for(i=0; i < astatSize; i++) {
2569 char name[METER_NAMSZ];
2570 struct vcache *tvc = &tvp[i];
2572 tvc->v.v_number = ++afsvnumbers;
2573 tvc->vc_rwlockid = OSI_NO_LOCKID;
2574 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
2575 #ifndef AFS_SGI53_ENV
2576 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2578 #ifndef AFS_SGI62_ENV
2579 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2580 #endif /* AFS_SGI62_ENV */
2593 void shutdown_vcache(void)
2596 struct afs_cbr *tsp, *nsp;
2598 * XXX We may potentially miss some of the vcaches because if when there're no
2599 * free vcache entries and all the vcache entries are active ones then we allocate
2600 * an additional one - admittedly we almost never had that occur.
2602 #if !defined(AFS_OSF_ENV)
2603 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2605 #ifdef AFS_AIX32_ENV
2606 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2610 register struct afs_q *tq, *uq;
2611 register struct vcache *tvc;
2612 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2616 osi_FreeSmallSpace(tvc->mvid);
2617 tvc->mvid = (struct VenusFid*)0;
2620 aix_gnode_rele((struct vnode *)tvc);
2622 if (tvc->linkData) {
2623 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2628 * Also free the remaining ones in the Cache
2630 for (i=0; i < VCSIZE; i++) {
2631 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2633 osi_FreeSmallSpace(tvc->mvid);
2634 tvc->mvid = (struct VenusFid*)0;
2638 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2639 #ifdef AFS_AIX32_ENV
2642 vms_delete(tvc->segid);
2644 tvc->segid = tvc->vmh = NULL;
2645 if (tvc->vrefCount) osi_Panic("flushVcache: vm race");
2653 #if defined(AFS_SUN5_ENV)
2659 if (tvc->linkData) {
2660 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2664 afs_FreeAllAxs(&(tvc->Access));
2670 * Free any leftover callback queue
2672 for (tsp = afs_cbrSpace; tsp; tsp = nsp ) {
2674 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2678 #if !defined(AFS_OSF_ENV)
2679 freeVCList = Initial_freeVCList = 0;
2681 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2682 LOCK_INIT(&afs_xvcb, "afs_xvcb");