1 /* Copyright (C) 1995, 1989, 1998 Transarc Corporation - All rights reserved */
3 * For copyright information, see IPL which you accepted in order to
4 * download this software.
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;
590 while ((cur = cur->next) != head) {
591 struct dentry *dentry = list_entry(cur, struct dentry, d_alias);
592 if (!dentry->d_count) {
610 #endif /* AFS_LINUX22_ENV */
613 if (afs_vcount >= afs_maxvcount)
616 * If we are using > 33 % of the total system vnodes for AFS vcache
617 * entries or we are using the maximum number of vcache entries,
618 * then free some. (if our usage is > 33% we should free some, if
619 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
620 * we _must_ free some -- no choice).
622 if ( (( 3 * afs_vcount ) > nvnode) || ( afs_vcount >= afs_maxvcount ))
625 struct afs_q *tq, *uq;
626 int i; char *panicstr;
629 for(tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
632 if (tvc->states & CVFlushed)
633 refpanic ("CVFlushed on VLRU");
634 else if (i++ > afs_maxvcount)
635 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
636 else if (QNext(uq) != tq)
637 refpanic ("VLRU inconsistent");
638 else if (tvc->vrefCount < 1)
639 refpanic ("refcnt 0 on VLRU");
641 if ( tvc->vrefCount == 1 && tvc->opens == 0
642 && (tvc->states & CUnlinkedDel) == 0) {
643 code = afs_FlushVCache(tvc, &fv_slept);
650 continue; /* start over - may have raced. */
655 if (anumber == VCACHE_FREE) {
656 printf("NewVCache: warning none freed, using %d of %d\n",
657 afs_vcount, afs_maxvcount);
658 if (afs_vcount >= afs_maxvcount) {
659 osi_Panic("NewVCache - none freed");
660 /* XXX instead of panicing, should do afs_maxvcount++
661 and magic up another one */
667 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
668 /* What should we do ???? */
669 osi_Panic("afs_NewVCache: no more vnodes");
674 tvc->nextfree = (struct vcache *)0;
676 #else /* AFS_OSF_ENV */
677 /* pull out a free cache entry */
680 for(tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
684 if (tvc->states & CVFlushed)
685 refpanic("CVFlushed on VLRU");
686 else if (i++ > 2*afs_cacheStats) /* even allowing for a few xallocs...*/
687 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
688 else if (QNext(uq) != tq)
689 refpanic("VLRU inconsistent");
691 if (tvc->vrefCount == 0 && tvc->opens == 0
692 && (tvc->states & CUnlinkedDel) == 0) {
693 code = afs_FlushVCache(tvc, &fv_slept);
700 continue; /* start over - may have raced. */
703 if (tq == uq ) break;
707 /* none free, making one is better than a panic */
708 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
709 tvc = (struct vcache *) afs_osi_Alloc(sizeof (struct vcache));
711 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
714 /* In case it still comes here we need to fill this */
715 tvc->v.v_vm_info = VM_INFO_NULL;
716 vm_info_init(tvc->v.v_vm_info);
717 /* perhaps we should also do close_flush on non-NeXT mach systems;
718 * who knows; we don't currently have the sources.
720 #endif /* AFS_MACH_ENV */
721 #if defined(AFS_SGI_ENV)
722 { char name[METER_NAMSZ];
723 bzero(tvc, sizeof(struct vcache));
724 tvc->v.v_number = ++afsvnumbers;
725 tvc->vc_rwlockid = OSI_NO_LOCKID;
726 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
727 #ifndef AFS_SGI53_ENV
728 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
730 #ifndef AFS_SGI62_ENV
731 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
734 #endif /* AFS_SGI_ENV */
737 tvc = freeVCList; /* take from free list */
738 freeVCList = tvc->nextfree;
739 tvc->nextfree = (struct vcache *)0;
741 #endif /* AFS_OSF_ENV */
744 vm_info_ptr = tvc->v.v_vm_info;
745 #endif /* AFS_MACH_ENV */
747 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
748 bzero((char *)tvc, sizeof(struct vcache));
753 RWLOCK_INIT(&tvc->lock, "vcache lock");
754 #if defined(AFS_SUN5_ENV)
755 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
756 #endif /* defined(AFS_SUN5_ENV) */
759 tvc->v.v_vm_info = vm_info_ptr;
760 tvc->v.v_vm_info->pager = MEMORY_OBJECT_NULL;
761 #endif /* AFS_MACH_ENV */
762 tvc->parentVnode = 0;
763 tvc->mvid = (struct VenusFid *) 0;
764 tvc->linkData = (char *) 0;
767 tvc->execsOrWriters = 0;
771 tvc->last_looker = 0;
773 tvc->asynchrony = -1;
775 afs_symhint_inval(tvc);
777 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
780 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
781 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
783 /* Hold it for the LRU (should make count 2) */
784 VN_HOLD((struct vnode *)tvc);
785 #else /* AFS_OSF_ENV */
786 tvc->vrefCount = 1; /* us */
787 #endif /* AFS_OSF_ENV */
789 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
790 tvc->vmh = tvc->segid = NULL;
793 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
794 #if defined(AFS_SUN5_ENV)
795 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
797 #if defined(AFS_SUN55_ENV)
798 /* This is required if the kaio (kernel aynchronous io)
799 ** module is installed. Inside the kernel, the function
800 ** check_vp( common/os/aio.c) checks to see if the kernel has
801 ** to provide asynchronous io for this vnode. This
802 ** function extracts the device number by following the
803 ** v_data field of the vnode. If we do not set this field
804 ** then the system panics. The value of the v_data field
805 ** is not really important for AFS vnodes because the kernel
806 ** does not do asynchronous io for regular files. Hence,
807 ** for the time being, we fill up the v_data field with the
808 ** vnode pointer itself. */
809 tvc->v.v_data = (char *)tvc;
810 #endif /* AFS_SUN55_ENV */
812 afs_BozonInit(&tvc->pvnLock, tvc);
816 tvc->callback = serverp; /* to minimize chance that clear
818 /* initialize vnode data, note vrefCount is v.v_count */
820 /* Don't forget to free the gnode space */
821 tvc->v.v_gnode = gnodepnt = (struct gnode *) osi_AllocSmallSpace(sizeof(struct gnode));
822 bzero((char *)gnodepnt, sizeof(struct gnode));
825 bzero((void*)&(tvc->vc_bhv_desc), sizeof(tvc->vc_bhv_desc));
826 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
828 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
829 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
831 bhv_head_init(&(tvc->v.v_bh));
832 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
835 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion*)tvc;
837 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
839 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
841 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
842 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
844 vnode_pcache_init(&tvc->v);
845 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
846 /* Above define is never true execpt in SGI test kernels. */
847 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
850 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
853 SetAfsVnode((struct vnode *)tvc);
854 #endif /* AFS_SGI64_ENV */
856 * The proper value for mvstat (for root fids) is setup by the caller.
859 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
861 if (afs_globalVFS == 0) osi_Panic("afs globalvfs");
862 vSetVfsp(tvc, afs_globalVFS);
865 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
866 tvc->v.v_vfsprev = NULL;
867 afs_globalVFS->vfs_vnodes = &tvc->v;
868 if (tvc->v.v_vfsnext != NULL)
869 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
870 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us!*/
871 gnodepnt->gn_vnode = &tvc->v;
874 tvc->v.g_dev = ((struct mount *)afs_globalVFS->vfs_data)->m_dev;
876 #if defined(AFS_DUX40_ENV)
877 insmntque(tvc, afs_globalVFS, &afs_ubcops);
880 /* Is this needed??? */
881 insmntque(tvc, afs_globalVFS);
882 #endif /* AFS_OSF_ENV */
883 #endif /* AFS_DUX40_ENV */
884 #if defined(AFS_SGI_ENV)
885 VN_SET_DPAGES(&(tvc->v), (struct pfdat*)NULL);
886 osi_Assert((tvc->v.v_flag & VINACT) == 0);
888 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
889 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
890 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
891 osi_Assert(tvc->v.v_filocks == NULL);
892 #if !defined(AFS_SGI65_ENV)
893 osi_Assert(tvc->v.v_filocksem == NULL);
895 osi_Assert(tvc->cred == NULL);
897 vnode_pcache_reinit(&tvc->v);
898 tvc->v.v_rdev = NODEV;
900 vn_initlist((struct vnlist *)&tvc->v);
902 #endif /* AFS_SGI_ENV */
903 #if defined(AFS_LINUX22_ENV)
905 struct inode *ip = (struct inode*)tvc;
906 sema_init(&ip->i_sem, 1);
907 sema_init(&ip->i_atomic_write, 1);
908 init_waitqueue(&ip->i_wait);
909 INIT_LIST_HEAD(&ip->i_hash);
910 INIT_LIST_HEAD(&ip->i_dentry);
912 ip->i_dev = afs_globalVFS->s_dev;
913 ip->i_sb = afs_globalVFS;
918 osi_dnlc_purgedp(tvc); /* this may be overkill */
919 bzero((char *)&(tvc->quick),sizeof(struct vtodc));
920 bzero((char *)&(tvc->callsort),sizeof(struct afs_q));
921 tvc->slocks = (struct SimpleLocks *)0;
924 tvc->hnext = afs_vhashT[i];
926 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
927 refpanic ("NewVCache VLRU inconsistent");
929 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
930 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
931 refpanic ("NewVCache VLRU inconsistent2");
933 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
934 refpanic ("NewVCache VLRU inconsistent3");
936 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
937 refpanic ("NewVCache VLRU inconsistent4");
947 * afs_FlushActiveVcaches
953 * doflocks : Do we handle flocks?
955 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
957 afs_FlushActiveVcaches(doflocks)
958 register afs_int32 doflocks;
960 { /*afs_FlushActiveVcaches*/
962 register struct vcache *tvc;
964 register struct conn *tc;
965 register afs_int32 code;
966 register struct AFS_UCRED *cred;
967 struct vrequest treq, ureq;
968 struct AFSVolSync tsync;
972 AFS_STATCNT(afs_FlushActiveVcaches);
973 ObtainReadLock(&afs_xvcache);
974 for(i=0;i<VCSIZE;i++) {
975 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
976 if (doflocks && tvc->flockCount != 0) {
977 /* if this entry has an flock, send a keep-alive call out */
979 ReleaseReadLock(&afs_xvcache);
980 ObtainWriteLock(&tvc->lock,51);
982 afs_InitReq(&treq, &afs_osi_cred);
983 treq.flags |= O_NONBLOCK;
985 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
987 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
988 #ifdef RX_ENABLE_LOCKS
990 #endif /* RX_ENABLE_LOCKS */
992 RXAFS_ExtendLock(tc->id,
993 (struct AFSFid *) &tvc->fid.Fid,
995 #ifdef RX_ENABLE_LOCKS
997 #endif /* RX_ENABLE_LOCKS */
1002 (afs_Analyze(tc, code, &tvc->fid, &treq,
1003 AFS_STATS_FS_RPCIDX_EXTENDLOCK,
1004 SHARED_LOCK, (struct cell *)0));
1006 ReleaseWriteLock(&tvc->lock);
1007 ObtainReadLock(&afs_xvcache);
1011 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1013 * Don't let it evaporate in case someone else is in
1014 * this code. Also, drop the afs_xvcache lock while
1015 * getting vcache locks.
1018 ReleaseReadLock(&afs_xvcache);
1019 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1020 afs_BozonLock(&tvc->pvnLock, tvc);
1022 #if defined(AFS_SGI_ENV)
1024 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1026 osi_Assert(tvc->vrefCount > 0);
1027 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1029 ObtainWriteLock(&tvc->lock,52);
1030 if (tvc->states & CCore) {
1031 tvc->states &= ~CCore;
1032 /* XXXX Find better place-holder for cred XXXX */
1033 cred = (struct AFS_UCRED *) tvc->linkData;
1034 tvc->linkData = (char *) 0; /* XXX */
1035 afs_InitReq(&ureq, cred);
1036 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1037 ICL_TYPE_POINTER, tvc,
1038 ICL_TYPE_INT32, tvc->execsOrWriters);
1039 code = afs_StoreOnLastReference(tvc, &ureq);
1040 ReleaseWriteLock(&tvc->lock);
1041 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1042 afs_BozonUnlock(&tvc->pvnLock, tvc);
1044 hzero(tvc->flushDV);
1047 if (code && code != VNOVNODE) {
1048 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1049 /* /dev/console */ 1);
1051 } else if (tvc->states & CUnlinkedDel) {
1055 ReleaseWriteLock(&tvc->lock);
1056 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1057 afs_BozonUnlock(&tvc->pvnLock, tvc);
1059 #if defined(AFS_SGI_ENV)
1060 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1062 afs_remunlink(tvc, 0);
1063 #if defined(AFS_SGI_ENV)
1064 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1068 /* lost (or won, perhaps) the race condition */
1069 ReleaseWriteLock(&tvc->lock);
1070 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1071 afs_BozonUnlock(&tvc->pvnLock, tvc);
1074 #if defined(AFS_SGI_ENV)
1075 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1077 ObtainReadLock(&afs_xvcache);
1083 AFS_RELE((struct vnode *)tvc);
1085 /* Matches write code setting CCore flag */
1091 ReleaseReadLock(&afs_xvcache);
1093 } /*afs_FlushActiveVcaches*/
1100 * Make sure a cache entry is up-to-date status-wise.
1102 * NOTE: everywhere that calls this can potentially be sped up
1103 * by checking CStatd first, and avoiding doing the InitReq
1104 * if this is up-to-date.
1106 * Anymore, the only places that call this KNOW already that the
1107 * vcache is not up-to-date, so we don't screw around.
1110 * avc : Ptr to vcache entry to verify.
1114 int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1116 register struct vcache *tvc;
1118 AFS_STATCNT(afs_VerifyVCache);
1120 #if defined(AFS_OSF_ENV)
1121 ObtainReadLock(&avc->lock);
1122 if (afs_IsWired(avc)) {
1123 ReleaseReadLock(&avc->lock);
1126 ReleaseReadLock(&avc->lock);
1127 #endif /* AFS_OSF_ENV */
1128 /* otherwise we must fetch the status info */
1130 ObtainWriteLock(&avc->lock,53);
1131 if (avc->states & CStatd) {
1132 ReleaseWriteLock(&avc->lock);
1135 ObtainWriteLock(&afs_xcbhash, 461);
1136 avc->states &= ~( CStatd | CUnique );
1137 avc->callback = (struct server *)0;
1138 afs_DequeueCallback(avc);
1139 ReleaseWriteLock(&afs_xcbhash);
1140 ReleaseWriteLock(&avc->lock);
1142 /* since we've been called back, or the callback has expired,
1143 * it's possible that the contents of this directory, or this
1144 * file's name have changed, thus invalidating the dnlc contents.
1146 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1147 osi_dnlc_purgedp (avc);
1149 osi_dnlc_purgevp (avc);
1151 /* fetch the status info */
1152 tvc = afs_GetVCache(&avc->fid, areq, (afs_int32*)0, avc, READ_LOCK);
1153 if (!tvc) return ENOENT;
1154 /* Put it back; caller has already incremented vrefCount */
1155 afs_PutVCache(tvc, READ_LOCK);
1158 } /*afs_VerifyVCache*/
1165 * Simple copy of stat info into cache.
1168 * avc : Ptr to vcache entry involved.
1169 * astat : Ptr to stat info to copy.
1172 * Nothing interesting.
1174 * Callers: as of 1992-04-29, only called by WriteVCache
1177 afs_SimpleVStat(avc, astat, areq)
1178 register struct vcache *avc;
1179 register struct AFSFetchStatus *astat;
1180 struct vrequest *areq;
1181 { /*afs_SimpleVStat*/
1183 AFS_STATCNT(afs_SimpleVStat);
1186 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1187 && !AFS_VN_MAPPED((vnode_t*)avc))
1189 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1193 #if defined(AFS_SGI_ENV)
1194 osi_Assert((valusema(&avc->vc_rwlock) <= 0) &&
1195 (OSI_GET_LOCKID() == avc->vc_rwlockid));
1196 if (astat->Length < avc->m.Length) {
1197 vnode_t *vp = (vnode_t *)avc;
1199 osi_Assert(WriteLocked(&avc->lock));
1200 ReleaseWriteLock(&avc->lock);
1202 PTOSSVP(vp, (off_t)astat->Length, (off_t)MAXLONG);
1204 ObtainWriteLock(&avc->lock,67);
1207 /* if writing the file, don't fetch over this value */
1208 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT,
1209 ICL_TYPE_POINTER, avc,
1210 ICL_TYPE_INT32, avc->m.Length,
1211 ICL_TYPE_INT32, astat->Length);
1212 avc->m.Length = astat->Length;
1213 avc->m.Date = astat->ClientModTime;
1215 avc->m.Owner = astat->Owner;
1216 avc->m.Group = astat->Group;
1217 avc->m.Mode = astat->UnixModeBits;
1218 if (vType(avc) == VREG) {
1219 avc->m.Mode |= S_IFREG;
1221 else if (vType(avc) == VDIR) {
1222 avc->m.Mode |= S_IFDIR;
1224 else if (vType(avc) == VLNK) {
1228 avc->m.Mode |= S_IFLNK;
1229 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1231 if (avc->states & CForeign) {
1232 struct axscache *ac;
1233 avc->anyAccess = astat->AnonymousAccess;
1235 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1237 * Caller has at least one bit not covered by anonymous, and
1238 * thus may have interesting rights.
1240 * HOWEVER, this is a really bad idea, because any access query
1241 * for bits which aren't covered by anonymous, on behalf of a user
1242 * who doesn't have any special rights, will result in an answer of
1243 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1244 * It's an especially bad idea under Ultrix, since (due to the lack of
1245 * a proper access() call) it must perform several afs_access() calls
1246 * in order to create magic mode bits that vary according to who makes
1247 * the call. In other words, _every_ stat() generates a test for
1250 #endif /* badidea */
1251 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1252 ac->axess = astat->CallerAccess;
1253 else /* not found, add a new one if possible */
1254 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1258 } /*afs_SimpleVStat*/
1265 * Store the status info *only* back to the server for a
1269 * avc : Ptr to the vcache entry.
1270 * astatus : Ptr to the status info to store.
1271 * areq : Ptr to the associated vrequest.
1274 * Must be called with a shared lock held on the vnode.
1277 afs_WriteVCache(avc, astatus, areq)
1278 register struct vcache *avc;
1279 register struct AFSStoreStatus *astatus;
1280 struct vrequest *areq;
1282 { /*afs_WriteVCache*/
1285 struct AFSFetchStatus OutStatus;
1286 struct AFSVolSync tsync;
1289 AFS_STATCNT(afs_WriteVCache);
1290 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1291 ICL_TYPE_INT32, avc->m.Length);
1294 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1296 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1297 #ifdef RX_ENABLE_LOCKS
1299 #endif /* RX_ENABLE_LOCKS */
1300 code = RXAFS_StoreStatus(tc->id,
1301 (struct AFSFid *) &avc->fid.Fid,
1302 astatus, &OutStatus, &tsync);
1303 #ifdef RX_ENABLE_LOCKS
1305 #endif /* RX_ENABLE_LOCKS */
1310 (afs_Analyze(tc, code, &avc->fid, areq,
1311 AFS_STATS_FS_RPCIDX_STORESTATUS,
1312 SHARED_LOCK, (struct cell *)0));
1314 UpgradeSToWLock(&avc->lock,20);
1316 /* success, do the changes locally */
1317 afs_SimpleVStat(avc, &OutStatus, areq);
1319 * Update the date, too. SimpleVStat didn't do this, since
1320 * it thought we were doing this after fetching new status
1321 * over a file being written.
1323 avc->m.Date = OutStatus.ClientModTime;
1326 /* failure, set up to check with server next time */
1327 ObtainWriteLock(&afs_xcbhash, 462);
1328 afs_DequeueCallback(avc);
1329 avc->states &= ~( CStatd | CUnique); /* turn off stat valid flag */
1330 ReleaseWriteLock(&afs_xcbhash);
1331 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1332 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
1334 ConvertWToSLock(&avc->lock);
1337 } /*afs_WriteVCache*/
1343 * Copy astat block into vcache info
1346 * avc : Ptr to vcache entry.
1347 * astat : Ptr to stat block to copy in.
1348 * areq : Ptr to associated request.
1351 * Must be called under a write lock
1353 * Note: this code may get dataversion and length out of sync if the file has
1354 * been modified. This is less than ideal. I haven't thought about
1355 * it sufficiently to be certain that it is adequate.
1358 afs_ProcessFS(avc, astat, areq)
1359 register struct vcache *avc;
1360 struct vrequest *areq;
1361 register struct AFSFetchStatus *astat;
1366 AFS_STATCNT(afs_ProcessFS);
1368 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1369 * number for each bulk status request. Under no circumstances
1370 * should afs_DoBulkStat store a sequence number if the new
1371 * length will be ignored when afs_ProcessFS is called with
1372 * new stats. If you change the following conditional then you
1373 * also need to change the conditional in afs_DoBulkStat. */
1375 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1376 && !AFS_VN_MAPPED((vnode_t*)avc))
1378 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1381 /* if we're writing or mapping this file, don't fetch over these
1384 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1385 ICL_TYPE_INT32, avc->m.Length,
1386 ICL_TYPE_INT32, astat->Length);
1387 avc->m.Length = astat->Length;
1388 avc->m.Date = astat->ClientModTime;
1390 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1391 avc->m.Owner = astat->Owner;
1392 avc->m.Mode = astat->UnixModeBits;
1393 avc->m.Group = astat->Group;
1394 avc->m.LinkCount = astat->LinkCount;
1395 if (astat->FileType == File) {
1396 vSetType(avc, VREG);
1397 avc->m.Mode |= S_IFREG;
1399 else if (astat->FileType == Directory) {
1400 vSetType(avc, VDIR);
1401 avc->m.Mode |= S_IFDIR;
1403 else if (astat->FileType == SymbolicLink) {
1404 vSetType(avc, VLNK);
1405 avc->m.Mode |= S_IFLNK;
1406 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
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 */
1427 struct axscache *ac;
1428 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1429 ac->axess = astat->CallerAccess;
1430 else /* not found, add a new one if possible */
1431 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1434 #ifdef AFS_LINUX22_ENV
1435 vcache2inode(avc); /* Set the inode attr cache */
1441 afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp)
1442 register struct VenusFid *afid;
1443 struct vrequest *areq;
1445 struct VenusFid *nfid;
1446 struct AFSFetchStatus *OutStatusp;
1447 struct AFSCallBack *CallBackp;
1448 struct server **serverp;
1449 struct AFSVolSync *tsyncp;
1452 register struct vcache *tvc;
1455 register struct conn *tc;
1456 struct AFSFetchStatus OutDirStatus;
1459 if (!name) name = ""; /* XXX */
1461 tc = afs_Conn(afid, areq, SHARED_LOCK);
1463 if (serverp) *serverp = tc->srvr->server;
1465 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1466 #ifdef RX_ENABLE_LOCKS
1468 #endif /* RX_ENABLE_LOCKS */
1469 code = RXAFS_Lookup(tc->id, (struct AFSFid *) &afid->Fid, name,
1470 (struct AFSFid *) &nfid->Fid,
1471 OutStatusp, &OutDirStatus, CallBackp, tsyncp);
1472 #ifdef RX_ENABLE_LOCKS
1474 #endif /* RX_ENABLE_LOCKS */
1479 (afs_Analyze(tc, code, afid, areq,
1480 AFS_STATS_FS_RPCIDX_XLOOKUP,
1481 SHARED_LOCK, (struct cell *)0));
1491 * Given a file id and a vrequest structure, fetch the status
1492 * information associated with the file.
1496 * areq : Ptr to associated vrequest structure, specifying the
1497 * user whose authentication tokens will be used.
1498 * avc : caller may already have a vcache for this file, which is
1502 * The cache entry is returned with an increased vrefCount field.
1503 * The entry must be discarded by calling afs_PutVCache when you
1504 * are through using the pointer to the cache entry.
1506 * You should not hold any locks when calling this function, except
1507 * locks on other vcache entries. If you lock more than one vcache
1508 * entry simultaneously, you should lock them in this order:
1510 * 1. Lock all files first, then directories.
1511 * 2. Within a particular type, lock entries in Fid.Vnode order.
1513 * This locking hierarchy is convenient because it allows locking
1514 * of a parent dir cache entry, given a file (to check its access
1515 * control list). It also allows renames to be handled easily by
1516 * locking directories in a constant order.
1517 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1519 struct vcache *afs_GetVCache(afid, areq, cached, avc, locktype)
1520 register struct VenusFid *afid;
1521 struct vrequest *areq;
1524 struct vcache *avc; /* might have a vcache structure already, which must
1525 * already be held by the caller */
1528 afs_int32 code, i, newvcache=0;
1529 register struct vcache *tvc;
1533 AFS_STATCNT(afs_GetVCache);
1535 if (cached) *cached = 0; /* Init just in case */
1538 ObtainSharedLock(&afs_xvcache,5);
1540 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS | DO_VLRU );
1542 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1543 ReleaseSharedLock(&afs_xvcache);
1544 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1552 if (tvc->states & CStatd) {
1553 ReleaseSharedLock(&afs_xvcache);
1558 UpgradeSToWLock(&afs_xvcache,21);
1560 /* no cache entry, better grab one */
1561 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1564 ConvertWToSLock(&afs_xvcache);
1565 afs_stats_cmperf.vcacheMisses++;
1568 ReleaseSharedLock(&afs_xvcache);
1570 ObtainWriteLock(&tvc->lock,54);
1572 if (tvc->states & CStatd) {
1573 #ifdef AFS_LINUX22_ENV
1576 ReleaseWriteLock(&tvc->lock);
1580 #if defined(AFS_OSF_ENV)
1581 if (afs_IsWired(tvc)) {
1582 ReleaseWriteLock(&tvc->lock);
1585 #endif /* AFS_OSF_ENV */
1587 ObtainWriteLock(&afs_xcbhash, 464);
1588 tvc->states &= ~CUnique;
1590 afs_DequeueCallback(tvc);
1591 ReleaseWriteLock(&afs_xcbhash);
1593 /* It is always appropriate to throw away all the access rights? */
1594 afs_FreeAllAxs(&(tvc->Access));
1595 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1597 if ((tvp->states & VForeign)) {
1598 if (newvcache) tvc->states |= CForeign;
1599 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1600 && (tvp->rootUnique == afid->Fid.Unique)) {
1604 if (tvp->states & VRO) tvc->states |= CRO;
1605 if (tvp->states & VBackup) tvc->states |= CBackup;
1606 /* now copy ".." entry back out of volume structure, if necessary */
1607 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1609 tvc->mvid = (struct VenusFid *)
1610 osi_AllocSmallSpace(sizeof(struct VenusFid));
1611 *tvc->mvid = tvp->dotdot;
1613 afs_PutVolume(tvp, READ_LOCK);
1617 afs_RemoveVCB(afid);
1619 struct AFSFetchStatus OutStatus;
1620 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1624 ReleaseWriteLock(&tvc->lock);
1626 ObtainReadLock(&afs_xvcache);
1628 ReleaseReadLock(&afs_xvcache);
1629 return (struct vcache *) 0;
1632 ReleaseWriteLock(&tvc->lock);
1639 struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1640 afs_int32 *cached, afs_int32 locktype,
1641 struct vcache *adp, char *aname)
1643 afs_int32 code, now, newvcache=0, hash;
1644 struct VenusFid nfid;
1645 register struct vcache *tvc;
1647 struct AFSFetchStatus OutStatus;
1648 struct AFSCallBack CallBack;
1649 struct AFSVolSync tsync;
1650 struct server *serverp = 0;
1654 AFS_STATCNT(afs_GetVCache);
1655 if (cached) *cached = 0; /* Init just in case */
1658 ObtainReadLock(&afs_xvcache);
1659 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS /* no vlru */);
1662 ReleaseReadLock(&afs_xvcache);
1664 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1665 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1669 ObtainReadLock(&tvc->lock);
1671 if (tvc->states & CStatd) {
1675 ReleaseReadLock(&tvc->lock);
1678 tvc->states &= ~CUnique;
1680 ReleaseReadLock(&tvc->lock);
1681 ObtainReadLock(&afs_xvcache);
1685 ReleaseReadLock(&afs_xvcache);
1687 /* lookup the file */
1690 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1691 code = afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1695 ObtainSharedLock(&afs_xvcache,6);
1696 tvc = afs_FindVCache(&nfid, 0, 0, &retry, DO_VLRU /* no xstats now*/);
1698 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1699 ReleaseSharedLock(&afs_xvcache);
1700 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1706 /* no cache entry, better grab one */
1707 UpgradeSToWLock(&afs_xvcache,22);
1708 tvc = afs_NewVCache(&nfid, (struct server *)0, 1, WRITE_LOCK);
1710 ConvertWToSLock(&afs_xvcache);
1713 ReleaseSharedLock(&afs_xvcache);
1714 ObtainWriteLock(&tvc->lock,55);
1716 /* It is always appropriate to throw away all the access rights? */
1717 afs_FreeAllAxs(&(tvc->Access));
1718 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1720 if ((tvp->states & VForeign)) {
1721 if (newvcache) tvc->states |= CForeign;
1722 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1723 && (tvp->rootUnique == afid->Fid.Unique))
1726 if (tvp->states & VRO) tvc->states |= CRO;
1727 if (tvp->states & VBackup) tvc->states |= CBackup;
1728 /* now copy ".." entry back out of volume structure, if necessary */
1729 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1731 tvc->mvid = (struct VenusFid *)
1732 osi_AllocSmallSpace(sizeof(struct VenusFid));
1733 *tvc->mvid = tvp->dotdot;
1738 ObtainWriteLock(&afs_xcbhash, 465);
1739 afs_DequeueCallback(tvc);
1740 tvc->states &= ~( CStatd | CUnique );
1741 ReleaseWriteLock(&afs_xcbhash);
1742 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1743 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1745 afs_PutVolume(tvp, READ_LOCK);
1746 ReleaseWriteLock(&tvc->lock);
1747 ObtainReadLock(&afs_xvcache);
1749 ReleaseReadLock(&afs_xvcache);
1750 return (struct vcache *) 0;
1753 ObtainWriteLock(&afs_xcbhash, 466);
1754 if (origCBs == afs_allCBs) {
1755 if (CallBack.ExpirationTime) {
1756 tvc->callback = serverp;
1757 tvc->cbExpires = CallBack.ExpirationTime+now;
1758 tvc->states |= CStatd | CUnique;
1759 tvc->states &= ~CBulkFetching;
1760 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1761 } else if (tvc->states & CRO) {
1762 /* adapt gives us an hour. */
1763 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
1764 tvc->states |= CStatd | CUnique;
1765 tvc->states &= ~CBulkFetching;
1766 afs_QueueCallback(tvc, CBHash(3600), tvp);
1768 tvc->callback = (struct server *)0;
1769 afs_DequeueCallback(tvc);
1770 tvc->states &= ~(CStatd | CUnique);
1771 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1772 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1775 afs_DequeueCallback(tvc);
1776 tvc->states &= ~CStatd;
1777 tvc->states &= ~CUnique;
1778 tvc->callback = (struct server *)0;
1779 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1780 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1782 ReleaseWriteLock(&afs_xcbhash);
1784 afs_PutVolume(tvp, READ_LOCK);
1785 afs_ProcessFS(tvc, &OutStatus, areq);
1787 ReleaseWriteLock(&tvc->lock);
1792 struct vcache *afs_GetRootVCache(struct VenusFid *afid,
1793 struct vrequest *areq, afs_int32 *cached,
1794 struct volume *tvolp, afs_int32 locktype)
1796 afs_int32 code, i, newvcache = 0, haveStatus = 0;
1797 afs_int32 getNewFid = 0;
1799 struct VenusFid nfid;
1800 register struct vcache *tvc;
1801 struct server *serverp = 0;
1802 struct AFSFetchStatus OutStatus;
1803 struct AFSCallBack CallBack;
1804 struct AFSVolSync tsync;
1810 if (!tvolp->rootVnode || getNewFid) {
1811 struct VenusFid tfid;
1814 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1815 origCBs = afs_allCBs; /* ignore InitCallBackState */
1816 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid,
1817 &OutStatus, &CallBack, &serverp, &tsync);
1819 return (struct vcache *)0;
1821 /* ReleaseReadLock(&tvolp->lock); */
1822 ObtainWriteLock(&tvolp->lock,56);
1823 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
1824 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
1825 ReleaseWriteLock(&tvolp->lock);
1826 /* ObtainReadLock(&tvolp->lock);*/
1829 afid->Fid.Vnode = tvolp->rootVnode;
1830 afid->Fid.Unique = tvolp->rootUnique;
1833 ObtainSharedLock(&afs_xvcache,7);
1835 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1836 if (!FidCmp(&(tvc->fid), afid)) {
1838 /* Grab this vnode, possibly reactivating from the free list */
1839 /* for the present (95.05.25) everything on the hash table is
1840 * definitively NOT in the free list -- at least until afs_reclaim
1841 * can be safely implemented */
1844 vg = vget((struct vnode *)tvc); /* this bumps ref count */
1848 #endif /* AFS_OSF_ENV */
1853 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
1854 /* Mount point no longer stat'd or unknown. FID may have changed. */
1859 tvc = (struct vcache*)0;
1861 ReleaseSharedLock(&afs_xvcache);
1866 UpgradeSToWLock(&afs_xvcache,23);
1867 /* no cache entry, better grab one */
1868 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1870 afs_stats_cmperf.vcacheMisses++;
1873 if (cached) *cached = 1;
1874 afs_stats_cmperf.vcacheHits++;
1876 /* we already bumped the ref count in the for loop above */
1877 #else /* AFS_OSF_ENV */
1880 UpgradeSToWLock(&afs_xvcache,24);
1881 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1882 refpanic ("GRVC VLRU inconsistent0");
1884 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1885 refpanic ("GRVC VLRU inconsistent1");
1887 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1888 refpanic ("GRVC VLRU inconsistent2");
1890 QRemove(&tvc->vlruq); /* move to lruq head */
1891 QAdd(&VLRU, &tvc->vlruq);
1892 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1893 refpanic ("GRVC VLRU inconsistent3");
1895 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1896 refpanic ("GRVC VLRU inconsistent4");
1898 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1899 refpanic ("GRVC VLRU inconsistent5");
1904 ReleaseWriteLock(&afs_xvcache);
1906 if (tvc->states & CStatd) {
1910 ObtainReadLock(&tvc->lock);
1911 tvc->states &= ~CUnique;
1912 tvc->callback = (struct server *)0; /* redundant, perhaps */
1913 ReleaseReadLock(&tvc->lock);
1916 ObtainWriteLock(&tvc->lock,57);
1918 /* It is always appropriate to throw away all the access rights? */
1919 afs_FreeAllAxs(&(tvc->Access));
1921 if (newvcache) tvc->states |= CForeign;
1922 if (tvolp->states & VRO) tvc->states |= CRO;
1923 if (tvolp->states & VBackup) tvc->states |= CBackup;
1924 /* now copy ".." entry back out of volume structure, if necessary */
1925 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
1926 && (tvolp->rootUnique == afid->Fid.Unique)) {
1929 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
1931 tvc->mvid = (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid));
1932 *tvc->mvid = tvolp->dotdot;
1936 afs_RemoveVCB(afid);
1939 struct VenusFid tfid;
1942 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1943 origCBs = afs_allCBs; /* ignore InitCallBackState */
1944 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid, &OutStatus,
1945 &CallBack, &serverp, &tsync);
1949 ObtainWriteLock(&afs_xcbhash, 467);
1950 afs_DequeueCallback(tvc);
1951 tvc->callback = (struct server *)0;
1952 tvc->states &= ~(CStatd|CUnique);
1953 ReleaseWriteLock(&afs_xcbhash);
1954 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1955 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1956 ReleaseWriteLock(&tvc->lock);
1957 ObtainReadLock(&afs_xvcache);
1959 ReleaseReadLock(&afs_xvcache);
1960 return (struct vcache *) 0;
1963 ObtainWriteLock(&afs_xcbhash, 468);
1964 if (origCBs == afs_allCBs) {
1965 tvc->states |= CTruth;
1966 tvc->callback = serverp;
1967 if (CallBack.ExpirationTime != 0) {
1968 tvc->cbExpires = CallBack.ExpirationTime+start;
1969 tvc->states |= CStatd;
1970 tvc->states &= ~CBulkFetching;
1971 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
1972 } else if (tvc->states & CRO) {
1973 /* adapt gives us an hour. */
1974 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
1975 tvc->states |= CStatd;
1976 tvc->states &= ~CBulkFetching;
1977 afs_QueueCallback(tvc, CBHash(3600), tvolp);
1980 afs_DequeueCallback(tvc);
1981 tvc->callback = (struct server *)0;
1982 tvc->states &= ~(CStatd | CUnique);
1983 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1984 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1986 ReleaseWriteLock(&afs_xcbhash);
1987 afs_ProcessFS(tvc, &OutStatus, areq);
1989 ReleaseWriteLock(&tvc->lock);
1996 * must be called with avc write-locked
1997 * don't absolutely have to invalidate the hint unless the dv has
1998 * changed, but be sure to get it right else there will be consistency bugs.
2000 afs_int32 afs_FetchStatus(struct vcache *avc, struct VenusFid *afid,
2001 struct vrequest *areq, struct AFSFetchStatus *Outsp)
2005 register struct conn *tc;
2006 struct AFSCallBack CallBack;
2007 struct AFSVolSync tsync;
2008 struct volume* volp;
2012 tc = afs_Conn(afid, areq, SHARED_LOCK);
2013 avc->quick.stamp = 0; avc->h1.dchint = NULL; /* invalidate hints */
2015 avc->callback = tc->srvr->server;
2017 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2018 #ifdef RX_ENABLE_LOCKS
2020 #endif /* RX_ENABLE_LOCKS */
2021 code = RXAFS_FetchStatus(tc->id,
2022 (struct AFSFid *) &afid->Fid,
2023 Outsp, &CallBack, &tsync);
2024 #ifdef RX_ENABLE_LOCKS
2026 #endif /* RX_ENABLE_LOCKS */
2033 (afs_Analyze(tc, code, afid, areq,
2034 AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2035 SHARED_LOCK, (struct cell *)0));
2038 afs_ProcessFS(avc, Outsp, areq);
2039 volp = afs_GetVolume(afid, areq, READ_LOCK);
2040 ObtainWriteLock(&afs_xcbhash, 469);
2041 avc->states |= CTruth;
2042 if (avc->callback /* check for race */) {
2043 if (CallBack.ExpirationTime != 0) {
2044 avc->cbExpires = CallBack.ExpirationTime+start;
2045 avc->states |= CStatd;
2046 avc->states &= ~CBulkFetching;
2047 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2049 else if (avc->states & CRO)
2050 { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2051 avc->cbExpires = 3600+start;
2052 avc->states |= CStatd;
2053 avc->states &= ~CBulkFetching;
2054 afs_QueueCallback(avc, CBHash(3600), volp);
2057 afs_DequeueCallback(avc);
2058 avc->callback = (struct server *)0;
2059 avc->states &= ~(CStatd|CUnique);
2060 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2061 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2065 afs_DequeueCallback(avc);
2066 avc->callback = (struct server *)0;
2067 avc->states &= ~(CStatd|CUnique);
2068 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2069 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2071 ReleaseWriteLock(&afs_xcbhash);
2073 afs_PutVolume(volp, READ_LOCK);
2075 else { /* used to undo the local callback, but that's too extreme.
2076 * There are plenty of good reasons that fetchstatus might return
2077 * an error, such as EPERM. If we have the vnode cached, statd,
2078 * with callback, might as well keep track of the fact that we
2079 * don't have access...
2081 if (code == EPERM || code == EACCES) {
2082 struct axscache *ac;
2083 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2085 else /* not found, add a new one if possible */
2086 afs_AddAxs(avc->Access, areq->uid, 0);
2096 * Stuff some information into the vcache for the given file.
2099 * afid : File in question.
2100 * OutStatus : Fetch status on the file.
2101 * CallBack : Callback info.
2102 * tc : RPC connection involved.
2103 * areq : vrequest involved.
2106 * Nothing interesting.
2109 afs_StuffVcache(afid, OutStatus, CallBack, tc, areq)
2110 register struct VenusFid *afid;
2111 struct AFSFetchStatus *OutStatus;
2112 struct AFSCallBack *CallBack;
2113 register struct conn *tc;
2114 struct vrequest *areq;
2116 { /*afs_StuffVcache*/
2118 register afs_int32 code, i, newvcache=0;
2119 register struct vcache *tvc;
2120 struct AFSVolSync tsync;
2122 struct axscache *ac;
2125 AFS_STATCNT(afs_StuffVcache);
2126 #ifdef IFS_VCACHECOUNT
2131 ObtainSharedLock(&afs_xvcache,8);
2133 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_VLRU /* no stats */);
2135 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2136 ReleaseSharedLock(&afs_xvcache);
2137 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2143 /* no cache entry, better grab one */
2144 UpgradeSToWLock(&afs_xvcache,25);
2145 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
2147 ConvertWToSLock(&afs_xvcache);
2150 ReleaseSharedLock(&afs_xvcache);
2151 ObtainWriteLock(&tvc->lock,58);
2153 tvc->states &= ~CStatd;
2154 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2155 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2157 /* Is it always appropriate to throw away all the access rights? */
2158 afs_FreeAllAxs(&(tvc->Access));
2160 /*Copy useful per-volume info*/
2161 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2163 if (newvcache && (tvp->states & VForeign)) tvc->states |= CForeign;
2164 if (tvp->states & VRO) tvc->states |= CRO;
2165 if (tvp->states & VBackup) tvc->states |= CBackup;
2167 * Now, copy ".." entry back out of volume structure, if
2170 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2171 if (!tvc->mvid) tvc->mvid =
2172 (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid));
2173 *tvc->mvid = tvp->dotdot;
2176 /* store the stat on the file */
2177 afs_RemoveVCB(afid);
2178 afs_ProcessFS(tvc, OutStatus, areq);
2179 tvc->callback = tc->srvr->server;
2181 /* we use osi_Time twice below. Ideally, we would use the time at which
2182 * the FetchStatus call began, instead, but we don't have it here. So we
2183 * make do with "now". In the CRO case, it doesn't really matter. In
2184 * the other case, we hope that the difference between "now" and when the
2185 * call actually began execution on the server won't be larger than the
2186 * padding which the server keeps. Subtract 1 second anyway, to be on
2187 * the safe side. Can't subtract more because we don't know how big
2188 * ExpirationTime is. Possible consistency problems may arise if the call
2189 * timeout period becomes longer than the server's expiration padding. */
2190 ObtainWriteLock(&afs_xcbhash, 470);
2191 if (CallBack->ExpirationTime != 0) {
2192 tvc->cbExpires = CallBack->ExpirationTime+osi_Time()-1;
2193 tvc->states |= CStatd;
2194 tvc->states &= ~CBulkFetching;
2195 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2197 else if (tvc->states & CRO) {
2198 /* old-fashioned AFS 3.2 style */
2199 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2200 tvc->states |= CStatd;
2201 tvc->states &= ~CBulkFetching;
2202 afs_QueueCallback(tvc, CBHash(3600), tvp);
2205 afs_DequeueCallback(tvc);
2206 tvc->callback = (struct server *)0;
2207 tvc->states &= ~(CStatd|CUnique);
2208 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2209 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2211 ReleaseWriteLock(&afs_xcbhash);
2213 afs_PutVolume(tvp, READ_LOCK);
2215 /* look in per-pag cache */
2216 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2217 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2218 else /* not found, add a new one if possible */
2219 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2221 ReleaseWriteLock(&tvc->lock);
2222 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2223 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32, tvc->cbExpires,
2224 ICL_TYPE_INT32, tvc->cbExpires-osi_Time());
2226 * Release ref count... hope this guy stays around...
2228 afs_PutVCache(tvc, WRITE_LOCK);
2229 } /*afs_StuffVcache*/
2235 * Decrements the reference count on a cache entry.
2238 * avc : Pointer to the cache entry to decrement.
2241 * Nothing interesting.
2244 afs_PutVCache(avc, locktype)
2245 register struct vcache *avc;
2249 AFS_STATCNT(afs_PutVCache);
2251 * Can we use a read lock here?
2253 ObtainReadLock(&afs_xvcache);
2255 ReleaseReadLock(&afs_xvcache);
2262 * Find a vcache entry given a fid.
2265 * afid : Pointer to the fid whose cache entry we desire.
2266 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2267 * unlock the vnode, and try again.
2268 * flags: bit 1 to specify whether to compute hit statistics. Not
2269 * set if FindVCache is called as part of internal bookkeeping.
2272 * Must be called with the afs_xvcache lock at least held at
2273 * the read level. In order to do the VLRU adjustment, the xvcache lock
2274 * must be shared-- we upgrade it here.
2277 struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit,
2278 afs_int32 locktype, afs_int32 *retry, afs_int32 flag)
2281 register struct vcache *tvc;
2284 AFS_STATCNT(afs_FindVCache);
2287 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2288 if (FidMatches(afid, tvc)) {
2290 /* Grab this vnode, possibly reactivating from the free list */
2293 vg = vget((struct vnode *)tvc);
2297 #endif /* AFS_OSF_ENV */
2302 /* should I have a read lock on the vnode here? */
2304 if (retry) *retry = 0;
2305 #if !defined(AFS_OSF_ENV)
2306 osi_vnhold(tvc, retry); /* already held, above */
2307 if (retry && *retry)
2311 * only move to front of vlru if we have proper vcache locking)
2313 if (flag & DO_VLRU) {
2314 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2315 refpanic ("FindVC VLRU inconsistent1");
2317 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2318 refpanic ("FindVC VLRU inconsistent1");
2320 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2321 refpanic ("FindVC VLRU inconsistent2");
2323 UpgradeSToWLock(&afs_xvcache,26);
2324 QRemove(&tvc->vlruq);
2325 QAdd(&VLRU, &tvc->vlruq);
2326 ConvertWToSLock(&afs_xvcache);
2327 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2328 refpanic ("FindVC VLRU inconsistent1");
2330 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2331 refpanic ("FindVC VLRU inconsistent2");
2333 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2334 refpanic ("FindVC VLRU inconsistent3");
2340 if (flag & DO_STATS) {
2341 if (tvc) afs_stats_cmperf.vcacheHits++;
2342 else afs_stats_cmperf.vcacheMisses++;
2343 if (afid->Cell == LOCALCELL)
2344 afs_stats_cmperf.vlocalAccesses++;
2346 afs_stats_cmperf.vremoteAccesses++;
2349 #ifdef AFS_LINUX22_ENV
2350 if (tvc && (tvc->states & CStatd))
2351 vcache2inode(tvc); /* mainly to reset i_nlink */
2354 } /*afs_FindVCache*/
2360 * Find a vcache entry given a fid. Does a wildcard match on what we
2361 * have for the fid. If more than one entry, don't return anything.
2364 * avcp : Fill in pointer if we found one and only one.
2365 * afid : Pointer to the fid whose cache entry we desire.
2366 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2367 * unlock the vnode, and try again.
2368 * flags: bit 1 to specify whether to compute hit statistics. Not
2369 * set if FindVCache is called as part of internal bookkeeping.
2372 * Must be called with the afs_xvcache lock at least held at
2373 * the read level. In order to do the VLRU adjustment, the xvcache lock
2374 * must be shared-- we upgrade it here.
2377 * number of matches found.
2380 int afs_duplicate_nfs_fids=0;
2382 afs_int32 afs_NFSFindVCache(avcp, afid, lockit)
2383 struct vcache **avcp;
2384 struct VenusFid *afid;
2386 { /*afs_FindVCache*/
2388 register struct vcache *tvc;
2390 afs_int32 retry = 0;
2391 afs_int32 count = 0;
2392 struct vcache *found_tvc = NULL;
2394 AFS_STATCNT(afs_FindVCache);
2398 ObtainSharedLock(&afs_xvcache,331);
2401 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2402 /* Match only on what we have.... */
2403 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2404 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2405 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2406 && (tvc->fid.Cell == afid->Cell)) {
2408 /* Grab this vnode, possibly reactivating from the free list */
2411 vg = vget((struct vnode *)tvc);
2414 /* This vnode no longer exists. */
2417 #endif /* AFS_OSF_ENV */
2422 /* Drop our reference counts. */
2423 vrele((struct vnode *)tvc);
2424 vrele((struct vnode *)found_tvc);
2426 afs_duplicate_nfs_fids++;
2427 ReleaseSharedLock(&afs_xvcache);
2435 /* should I have a read lock on the vnode here? */
2437 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2438 osi_vnhold(tvc, &retry);
2441 found_tvc = (struct vcache*)0;
2442 ReleaseSharedLock(&afs_xvcache);
2443 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2447 #if !defined(AFS_OSF_ENV)
2448 osi_vnhold(tvc, (int*)0); /* already held, above */
2452 * We obtained the xvcache lock above.
2454 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2455 refpanic ("FindVC VLRU inconsistent1");
2457 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2458 refpanic ("FindVC VLRU inconsistent1");
2460 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2461 refpanic ("FindVC VLRU inconsistent2");
2463 UpgradeSToWLock(&afs_xvcache,568);
2464 QRemove(&tvc->vlruq);
2465 QAdd(&VLRU, &tvc->vlruq);
2466 ConvertWToSLock(&afs_xvcache);
2467 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2468 refpanic ("FindVC VLRU inconsistent1");
2470 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2471 refpanic ("FindVC VLRU inconsistent2");
2473 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2474 refpanic ("FindVC VLRU inconsistent3");
2479 if (tvc) afs_stats_cmperf.vcacheHits++;
2480 else afs_stats_cmperf.vcacheMisses++;
2481 if (afid->Cell == LOCALCELL)
2482 afs_stats_cmperf.vlocalAccesses++;
2484 afs_stats_cmperf.vremoteAccesses++;
2486 *avcp = tvc; /* May be null */
2488 ReleaseSharedLock(&afs_xvcache);
2489 return (tvc ? 1 : 0);
2491 } /*afs_NFSFindVCache*/
2499 * Initialize vcache related variables
2501 void afs_vcacheInit(int astatSize)
2503 register struct vcache *tvp;
2505 #if defined(AFS_OSF_ENV)
2506 if (!afs_maxvcount) {
2507 #if defined(AFS_OSF30_ENV)
2508 afs_maxvcount = max_vnodes/2; /* limit ourselves to half the total */
2510 afs_maxvcount = nvnode/2; /* limit ourselves to half the total */
2512 if (astatSize < afs_maxvcount) {
2513 afs_maxvcount = astatSize;
2516 #else /* AFS_OSF_ENV */
2517 freeVCList = (struct vcache *)0;
2520 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2521 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2523 #if !defined(AFS_OSF_ENV)
2524 /* Allocate and thread the struct vcache entries */
2525 tvp = (struct vcache *) afs_osi_Alloc(astatSize * sizeof(struct vcache));
2526 bzero((char *)tvp, sizeof(struct vcache)*astatSize);
2528 Initial_freeVCList = tvp;
2529 freeVCList = &(tvp[0]);
2530 for(i=0; i < astatSize-1; i++) {
2531 tvp[i].nextfree = &(tvp[i+1]);
2533 tvp[astatSize-1].nextfree = (struct vcache *) 0;
2534 #ifdef AFS_AIX32_ENV
2535 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2540 #if defined(AFS_SGI_ENV)
2541 for(i=0; i < astatSize; i++) {
2542 char name[METER_NAMSZ];
2543 struct vcache *tvc = &tvp[i];
2545 tvc->v.v_number = ++afsvnumbers;
2546 tvc->vc_rwlockid = OSI_NO_LOCKID;
2547 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
2548 #ifndef AFS_SGI53_ENV
2549 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2551 #ifndef AFS_SGI62_ENV
2552 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2553 #endif /* AFS_SGI62_ENV */
2566 void shutdown_vcache(void)
2569 struct afs_cbr *tsp, *nsp;
2571 * XXX We may potentially miss some of the vcaches because if when there're no
2572 * free vcache entries and all the vcache entries are active ones then we allocate
2573 * an additional one - admittedly we almost never had that occur.
2575 #if !defined(AFS_OSF_ENV)
2576 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2578 #ifdef AFS_AIX32_ENV
2579 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2583 register struct afs_q *tq, *uq;
2584 register struct vcache *tvc;
2585 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2589 osi_FreeSmallSpace(tvc->mvid);
2590 tvc->mvid = (struct VenusFid*)0;
2593 aix_gnode_rele((struct vnode *)tvc);
2595 if (tvc->linkData) {
2596 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2601 * Also free the remaining ones in the Cache
2603 for (i=0; i < VCSIZE; i++) {
2604 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2606 osi_FreeSmallSpace(tvc->mvid);
2607 tvc->mvid = (struct VenusFid*)0;
2611 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2612 #ifdef AFS_AIX32_ENV
2615 vms_delete(tvc->segid);
2617 tvc->segid = tvc->vmh = NULL;
2618 if (tvc->vrefCount) osi_Panic("flushVcache: vm race");
2626 #if defined(AFS_SUN5_ENV)
2632 if (tvc->linkData) {
2633 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2637 afs_FreeAllAxs(&(tvc->Access));
2643 * Free any leftover callback queue
2645 for (tsp = afs_cbrSpace; tsp; tsp = nsp ) {
2647 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2651 #if !defined(AFS_OSF_ENV)
2652 freeVCList = Initial_freeVCList = 0;
2654 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2655 LOCK_INIT(&afs_xvcb, "afs_xvcb");