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 <afsconfig.h>
43 #include "../afs/sysincludes.h" /*Standard vendor system headers*/
44 #include "../afs/afsincludes.h" /*AFS-based standard headers*/
45 #include "../afs/afs_stats.h"
46 #include "../afs/afs_cbqueue.h"
47 #include "../afs/afs_osidnlc.h"
50 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
51 afs_int32 afs_vcount = 0; /* number of vcache in use now */
52 #if defined(AFS_OSF30_ENV)
53 extern int max_vnodes; /* number of total system vnodes */
55 extern int nvnode; /* number of total system vnodes */
58 extern int numvnodes; /* number vnodes in use now */
60 #endif /* AFS_OSF_ENV */
65 /* Imported variables */
66 extern struct server *afs_servers[NSERVERS];
67 extern afs_rwlock_t afs_xserver;
68 extern afs_rwlock_t afs_xcbhash;
69 extern struct vcache *afs_globalVp;
71 extern struct mount *afs_globalVFS;
72 extern struct vnodeops Afs_vnodeops;
73 #elif defined(AFS_DARWIN_ENV)
74 extern struct mount *afs_globalVFS;
76 extern struct vfs *afs_globalVFS;
77 #endif /* AFS_OSF_ENV */
78 #if defined(AFS_DUX40_ENV)
79 extern struct vfs_ubcops afs_ubcops;
82 extern struct vnodeops Afs_vnodeops;
86 #endif /* AFS_SGI64_ENV */
88 /* Exported variables */
89 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries*/
90 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks*/
91 struct vcache *freeVCList; /*Free list for stat cache entries*/
92 struct vcache *Initial_freeVCList; /*Initial list for above*/
93 struct afs_q VLRU; /*vcache LRU*/
94 afs_int32 vcachegen = 0;
95 unsigned int afs_paniconwarn = 0;
96 struct vcache *afs_vhashT[VCSIZE];
97 afs_int32 afs_bulkStatsLost;
98 int afs_norefpanic = 0;
100 /* Forward declarations */
101 static afs_int32 afs_QueueVCB(struct vcache *avc);
108 * Flush the given vcache entry.
111 * avc : Pointer to vcache entry to flush.
112 * slept : Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
115 * afs_xvcache lock must be held for writing upon entry to
116 * prevent people from changing the vrefCount field, and to
117 * protect the lruq and hnext fields.
118 * LOCK: afs_FlushVCache afs_xvcache W
119 * REFCNT: vcache ref count must be zero on entry except for osf1
120 * RACE: lock is dropped and reobtained, permitting race in caller
123 int afs_FlushVCache(struct vcache *avc, int *slept)
124 { /*afs_FlushVCache*/
126 register afs_int32 i, code;
127 register struct vcache **uvc, *wvc, *tvc;
130 AFS_STATCNT(afs_FlushVCache);
131 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
132 ICL_TYPE_INT32, avc->states);
135 VN_LOCK((struct vnode *)avc);
139 code = osi_VM_FlushVCache(avc, slept);
143 if (avc->states & CVFlushed) {
147 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
148 refpanic ("LRU vs. Free inconsistency");
150 avc->states |= CVFlushed;
151 /* pull the entry out of the lruq and put it on the free list */
152 QRemove(&avc->vlruq);
153 avc->vlruq.prev = avc->vlruq.next = (struct afs_q *) 0;
155 /* keep track of # of files that we bulk stat'd, but never used
156 * before they got recycled.
158 if (avc->states & CBulkStat)
161 /* remove entry from the hash chain */
162 i = VCHash(&avc->fid);
163 uvc = &afs_vhashT[i];
164 for(wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
167 avc->hnext = (struct vcache *) NULL;
171 if (!wvc) osi_Panic("flushvcache"); /* not in correct hash bucket */
172 if (avc->mvid) osi_FreeSmallSpace(avc->mvid);
173 avc->mvid = (struct VenusFid*)0;
175 afs_osi_Free(avc->linkData, strlen(avc->linkData)+1);
176 avc->linkData = NULL;
178 afs_FreeAllAxs(&(avc->Access));
180 /* we can't really give back callbacks on RO files, since the
181 * server only tracks them on a per-volume basis, and we don't
182 * know whether we still have some other files from the same
184 if ((avc->states & CRO) == 0 && avc->callback) {
187 ObtainWriteLock(&afs_xcbhash, 460);
188 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
189 avc->states &= ~(CStatd | CUnique);
190 ReleaseWriteLock(&afs_xcbhash);
191 afs_symhint_inval(avc);
192 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
193 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
195 osi_dnlc_purgevp (avc);
198 * Next, keep track of which vnodes we've deleted for create's
199 * optimistic synchronization algorithm
202 if (avc->fid.Fid.Vnode & 1) afs_oddZaps++;
205 #if !defined(AFS_OSF_ENV)
206 /* put the entry in the free list */
207 avc->nextfree = freeVCList;
209 if (avc->vlruq.prev || avc->vlruq.next) {
210 refpanic ("LRU vs. Free inconsistency");
213 /* This should put it back on the vnode free list since usecount is 1 */
216 if (avc->vrefCount > 0) {
217 VN_UNLOCK((struct vnode *)avc);
218 AFS_RELE((struct vnode *)avc);
220 if (afs_norefpanic) {
221 printf ("flush vc refcnt < 1");
223 (void) vgone(avc, VX_NOSLEEP, (struct vnodeops *) 0);
225 VN_UNLOCK((struct vnode *)avc);
227 else osi_Panic ("flush vc refcnt < 1");
229 #endif /* AFS_OSF_ENV */
230 avc->states |= CVFlushed;
235 VN_UNLOCK((struct vnode *)avc);
239 } /*afs_FlushVCache*/
245 * The core of the inactive vnode op for all but IRIX.
247 void afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred)
249 extern afs_rwlock_t afs_xdcache, afs_xvcache;
251 AFS_STATCNT(afs_inactive);
252 if (avc->states & CDirty) {
253 /* we can't keep trying to push back dirty data forever. Give up. */
254 afs_InvalidateAllSegments(avc, 1/*set lock*/); /* turns off dirty bit */
256 avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
257 avc->states &= ~CDirty; /* Turn it off */
258 if (avc->states & CUnlinked) {
259 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
260 avc->states |= CUnlinkedDel;
263 afs_remunlink(avc, 1); /* ignore any return code */
272 * Description: allocate a callback return structure from the
273 * free list and return it.
275 * Env: The alloc and free routines are both called with the afs_xvcb lock
276 * held, so we don't have to worry about blocking in osi_Alloc.
278 static struct afs_cbr *afs_cbrSpace = 0;
279 struct afs_cbr *afs_AllocCBR() {
280 register struct afs_cbr *tsp;
283 while (!afs_cbrSpace) {
284 if (afs_stats_cmperf.CallBackAlloced >= 2) {
285 /* don't allocate more than 2 * AFS_NCBRS for now */
287 afs_stats_cmperf.CallBackFlushes++;
291 tsp = (struct afs_cbr *) afs_osi_Alloc(AFS_NCBRS * sizeof(struct afs_cbr));
292 for(i=0; i < AFS_NCBRS-1; i++) {
293 tsp[i].next = &tsp[i+1];
295 tsp[AFS_NCBRS-1].next = 0;
297 afs_stats_cmperf.CallBackAlloced++;
301 afs_cbrSpace = tsp->next;
308 * Description: free a callback return structure.
311 * asp -- the address of the structure to free.
313 * Environment: the xvcb lock is held over these calls.
316 register struct afs_cbr *asp; {
317 asp->next = afs_cbrSpace;
325 * Description: flush all queued callbacks to all servers.
329 * Environment: holds xvcb lock over RPC to guard against race conditions
330 * when a new callback is granted for the same file later on.
332 afs_int32 afs_FlushVCBs (afs_int32 lockit)
334 struct AFSFid tfids[AFS_MAXCBRSCALL];
335 struct AFSCallBack callBacks[1];
336 struct AFSCBFids fidArray;
337 struct AFSCBs cbArray;
339 struct afs_cbr *tcbrp;
343 struct vrequest treq;
345 int safety1, safety2, safety3;
346 extern int afs_totalServers;
349 if (code = afs_InitReq(&treq, &afs_osi_cred)) return code;
350 treq.flags |= O_NONBLOCK;
352 if (lockit) MObtainWriteLock(&afs_xvcb,273);
353 ObtainReadLock(&afs_xserver);
354 for(i=0; i<NSERVERS; i++) {
355 for(safety1 = 0, tsp = afs_servers[i];
356 tsp && safety1 < afs_totalServers+10; tsp=tsp->next, safety1++) {
358 if (tsp->cbrs == (struct afs_cbr *) 0) continue;
360 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
361 * and make an RPC, over and over again.
363 tcount = 0; /* number found so far */
364 for (safety2 = 0; safety2 < afs_cacheStats ; safety2++) {
365 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
366 /* if buffer is full, or we've queued all we're going
367 * to from this server, we should flush out the
370 fidArray.AFSCBFids_len = tcount;
371 fidArray.AFSCBFids_val = (struct AFSFid *) tfids;
372 cbArray.AFSCBs_len = 1;
373 cbArray.AFSCBs_val = callBacks;
374 callBacks[0].CallBackType = CB_EXCLUSIVE;
375 for (safety3 = 0; safety3 < MAXHOSTS*2; safety3++) {
376 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
377 tsp->cell->cell, &treq, 0,
380 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
381 #ifdef RX_ENABLE_LOCKS
383 #endif /* RX_ENABLE_LOCKS */
384 code = RXAFS_GiveUpCallBacks(tc->id, &fidArray,
386 #ifdef RX_ENABLE_LOCKS
388 #endif /* RX_ENABLE_LOCKS */
392 if (!afs_Analyze(tc, code, 0, &treq,
393 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS,
394 SHARED_LOCK, tsp->cell)) {
398 /* ignore return code, since callbacks may have
399 * been returned anyway, we shouldn't leave them
400 * around to be returned again.
402 * Next, see if we are done with this server, and if so,
403 * break to deal with the next one.
405 if (!tsp->cbrs) break;
407 } /* if to flush full buffer */
408 /* if we make it here, we have an entry at the head of cbrs,
409 * which we should copy to the file ID array and then free.
412 tfids[tcount++] = tcbrp->fid;
413 tsp->cbrs = tcbrp->next;
415 } /* while loop for this one server */
416 if (safety2 > afs_cacheStats) {
417 afs_warn("possible internal error afs_flushVCBs (%d)\n", safety2);
419 } /* for loop for this hash chain */
420 } /* loop through all hash chains */
421 if (safety1 > afs_totalServers+2) {
422 afs_warn("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n", safety1, afs_totalServers+2);
424 osi_Panic("afs_flushVCBS safety1");
427 ReleaseReadLock(&afs_xserver);
428 if (lockit) MReleaseWriteLock(&afs_xvcb);
436 * Queue a callback on the given fid.
442 * Locks the xvcb lock.
443 * Called when the xvcache lock is already held.
446 static afs_int32 afs_QueueVCB(struct vcache *avc)
448 register struct server *tsp;
449 register struct afs_cbr *tcbp;
451 AFS_STATCNT(afs_QueueVCB);
452 /* The callback is really just a struct server ptr. */
453 tsp = (struct server *)(avc->callback);
455 /* we now have a pointer to the server, so we just allocate
456 * a queue entry and queue it.
458 MObtainWriteLock(&afs_xvcb,274);
459 tcbp = afs_AllocCBR();
460 tcbp->fid = avc->fid.Fid;
461 tcbp->next = tsp->cbrs;
464 /* now release locks and return */
465 MReleaseWriteLock(&afs_xvcb);
474 * Remove a queued callback by looking through all the servers
475 * to see if any have this callback queued.
478 * afid: The fid we want cleansed of queued callbacks.
481 * Locks xvcb and xserver locks.
482 * Typically called with xdcache, xvcache and/or individual vcache
487 register struct VenusFid *afid;
492 register struct server *tsp;
493 register struct afs_cbr *tcbrp;
494 struct afs_cbr **lcbrpp;
496 AFS_STATCNT(afs_RemoveVCB);
497 MObtainWriteLock(&afs_xvcb,275);
498 ObtainReadLock(&afs_xserver);
499 for(i=0;i<NSERVERS;i++) {
500 for(tsp=afs_servers[i]; tsp; tsp=tsp->next) {
501 /* if cell is known, and is wrong, then skip this server */
502 if (tsp->cell && tsp->cell->cell != afid->Cell) continue;
505 * Otherwise, iterate through file IDs we're sending to the
508 lcbrpp = &tsp->cbrs; /* first queued return callback */
509 for(tcbrp = *lcbrpp; tcbrp; lcbrpp = &tcbrp->next, tcbrp = *lcbrpp) {
510 if (afid->Fid.Volume == tcbrp->fid.Volume &&
511 afid->Fid.Unique == tcbrp->fid.Unique &&
512 afid->Fid.Vnode == tcbrp->fid.Vnode) {
513 *lcbrpp = tcbrp->next; /* unthread from list */
521 ReleaseReadLock(&afs_xserver);
522 MReleaseWriteLock(&afs_xvcb);
533 * This routine is responsible for allocating a new cache entry
534 * from the free list. It formats the cache entry and inserts it
535 * into the appropriate hash tables. It must be called with
536 * afs_xvcache write-locked so as to prevent several processes from
537 * trying to create a new cache entry simultaneously.
540 * afid : The file id of the file whose cache entry is being
543 /* LOCK: afs_NewVCache afs_xvcache W */
544 struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp,
545 afs_int32 lockit, afs_int32 locktype)
549 afs_int32 anumber = VCACHE_FREE;
551 struct gnode *gnodepnt;
554 struct vm_info * vm_info_ptr;
555 #endif /* AFS_MACH_ENV */
558 #endif /* AFS_OSF_ENV */
559 struct afs_q *tq, *uq;
562 AFS_STATCNT(afs_NewVCache);
563 #ifdef AFS_LINUX22_ENV
565 /* Free some if possible. */
566 struct afs_q *tq, *uq;
567 int i; char *panicstr;
568 int vmax = 2 * afs_cacheStats;
569 int vn = VCACHE_FREE;
572 for(tq = VLRU.prev; tq != &VLRU && vn > 0; tq = uq) {
575 if (tvc->states & CVFlushed)
576 refpanic ("CVFlushed on VLRU");
578 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
579 else if (QNext(uq) != tq)
580 refpanic ("VLRU inconsistent");
582 if (tvc == afs_globalVp)
585 if ( tvc->vrefCount && tvc->opens == 0 ) {
586 struct inode *ip = (struct inode*)tvc;
587 if (list_empty(&ip->i_dentry)) {
591 struct list_head *cur;
592 struct list_head *head = &ip->i_dentry;
595 #if defined(AFS_LINUX24_ENV)
596 spin_lock(&dcache_lock);
599 while ((cur = cur->next) != head) {
600 struct dentry *dentry = list_entry(cur, struct dentry, d_alias);
601 #if defined(AFS_LINUX24_ENV)
602 if (!atomic_read(&dentry->d_count)) {
604 if (!dentry->d_count) {
607 #if defined(AFS_LINUX24_ENV)
609 spin_unlock(&dcache_lock);
622 #if defined(AFS_LINUX24_ENV)
623 spin_unlock(&dcache_lock);
631 #endif /* AFS_LINUX22_ENV */
634 if (afs_vcount >= afs_maxvcount)
637 * If we are using > 33 % of the total system vnodes for AFS vcache
638 * entries or we are using the maximum number of vcache entries,
639 * then free some. (if our usage is > 33% we should free some, if
640 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
641 * we _must_ free some -- no choice).
643 if ( (( 3 * afs_vcount ) > nvnode) || ( afs_vcount >= afs_maxvcount ))
646 struct afs_q *tq, *uq;
647 int i; char *panicstr;
650 for(tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
653 if (tvc->states & CVFlushed)
654 refpanic ("CVFlushed on VLRU");
655 else if (i++ > afs_maxvcount)
656 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
657 else if (QNext(uq) != tq)
658 refpanic ("VLRU inconsistent");
659 else if (tvc->vrefCount < 1)
660 refpanic ("refcnt 0 on VLRU");
662 if ( tvc->vrefCount == 1 && tvc->opens == 0
663 && (tvc->states & CUnlinkedDel) == 0) {
664 code = afs_FlushVCache(tvc, &fv_slept);
671 continue; /* start over - may have raced. */
676 if (anumber == VCACHE_FREE) {
677 printf("NewVCache: warning none freed, using %d of %d\n",
678 afs_vcount, afs_maxvcount);
679 if (afs_vcount >= afs_maxvcount) {
680 osi_Panic("NewVCache - none freed");
681 /* XXX instead of panicing, should do afs_maxvcount++
682 and magic up another one */
688 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
689 /* What should we do ???? */
690 osi_Panic("afs_NewVCache: no more vnodes");
695 tvc->nextfree = (struct vcache *)0;
697 #else /* AFS_OSF_ENV */
698 /* pull out a free cache entry */
701 for(tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
705 if (tvc->states & CVFlushed)
706 refpanic("CVFlushed on VLRU");
707 else if (i++ > 2*afs_cacheStats) /* even allowing for a few xallocs...*/
708 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
709 else if (QNext(uq) != tq)
710 refpanic("VLRU inconsistent");
712 #ifdef AFS_DARWIN_ENV
713 if (tvc->opens == 0 && ((tvc->states & CUnlinkedDel) == 0) &&
714 tvc->vrefCount == 1 && UBCINFOEXISTS(&tvc->v)) {
715 osi_VM_TryReclaim(tvc, &fv_slept);
719 continue; /* start over - may have raced. */
723 if (tvc->vrefCount == 0 && tvc->opens == 0
724 && (tvc->states & CUnlinkedDel) == 0) {
725 code = afs_FlushVCache(tvc, &fv_slept);
732 continue; /* start over - may have raced. */
735 if (tq == uq ) break;
739 /* none free, making one is better than a panic */
740 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
741 tvc = (struct vcache *) afs_osi_Alloc(sizeof (struct vcache));
743 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
746 /* In case it still comes here we need to fill this */
747 tvc->v.v_vm_info = VM_INFO_NULL;
748 vm_info_init(tvc->v.v_vm_info);
749 /* perhaps we should also do close_flush on non-NeXT mach systems;
750 * who knows; we don't currently have the sources.
752 #endif /* AFS_MACH_ENV */
753 #if defined(AFS_SGI_ENV)
754 { char name[METER_NAMSZ];
755 bzero(tvc, sizeof(struct vcache));
756 tvc->v.v_number = ++afsvnumbers;
757 tvc->vc_rwlockid = OSI_NO_LOCKID;
758 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
759 #ifndef AFS_SGI53_ENV
760 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
762 #ifndef AFS_SGI62_ENV
763 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
766 #endif /* AFS_SGI_ENV */
769 tvc = freeVCList; /* take from free list */
770 freeVCList = tvc->nextfree;
771 tvc->nextfree = (struct vcache *)0;
773 #endif /* AFS_OSF_ENV */
776 vm_info_ptr = tvc->v.v_vm_info;
777 #endif /* AFS_MACH_ENV */
779 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
780 bzero((char *)tvc, sizeof(struct vcache));
785 RWLOCK_INIT(&tvc->lock, "vcache lock");
786 #if defined(AFS_SUN5_ENV)
787 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
788 #endif /* defined(AFS_SUN5_ENV) */
791 tvc->v.v_vm_info = vm_info_ptr;
792 tvc->v.v_vm_info->pager = MEMORY_OBJECT_NULL;
793 #endif /* AFS_MACH_ENV */
794 tvc->parentVnode = 0;
795 tvc->mvid = (struct VenusFid *) 0;
796 tvc->linkData = (char *) 0;
799 tvc->execsOrWriters = 0;
803 tvc->last_looker = 0;
805 tvc->asynchrony = -1;
807 afs_symhint_inval(tvc);
809 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
812 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
813 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
815 /* Hold it for the LRU (should make count 2) */
816 VN_HOLD((struct vnode *)tvc);
817 #else /* AFS_OSF_ENV */
818 tvc->vrefCount = 1; /* us */
819 #endif /* AFS_OSF_ENV */
821 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
822 tvc->vmh = tvc->segid = NULL;
825 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
826 #if defined(AFS_SUN5_ENV)
827 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
829 #if defined(AFS_SUN55_ENV)
830 /* This is required if the kaio (kernel aynchronous io)
831 ** module is installed. Inside the kernel, the function
832 ** check_vp( common/os/aio.c) checks to see if the kernel has
833 ** to provide asynchronous io for this vnode. This
834 ** function extracts the device number by following the
835 ** v_data field of the vnode. If we do not set this field
836 ** then the system panics. The value of the v_data field
837 ** is not really important for AFS vnodes because the kernel
838 ** does not do asynchronous io for regular files. Hence,
839 ** for the time being, we fill up the v_data field with the
840 ** vnode pointer itself. */
841 tvc->v.v_data = (char *)tvc;
842 #endif /* AFS_SUN55_ENV */
844 afs_BozonInit(&tvc->pvnLock, tvc);
848 tvc->callback = serverp; /* to minimize chance that clear
850 /* initialize vnode data, note vrefCount is v.v_count */
852 /* Don't forget to free the gnode space */
853 tvc->v.v_gnode = gnodepnt = (struct gnode *) osi_AllocSmallSpace(sizeof(struct gnode));
854 bzero((char *)gnodepnt, sizeof(struct gnode));
857 bzero((void*)&(tvc->vc_bhv_desc), sizeof(tvc->vc_bhv_desc));
858 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
860 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
861 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
863 bhv_head_init(&(tvc->v.v_bh));
864 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
867 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion*)tvc;
869 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
871 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
873 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
874 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
876 vnode_pcache_init(&tvc->v);
877 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
878 /* Above define is never true execpt in SGI test kernels. */
879 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
882 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
885 SetAfsVnode((struct vnode *)tvc);
886 #endif /* AFS_SGI64_ENV */
887 #ifdef AFS_DARWIN_ENV
888 tvc->v.v_ubcinfo = UBC_INFO_NULL;
889 lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0);
890 cache_purge((struct vnode *)tvc);
893 /* VLISTNONE(&tvc->v); */
894 tvc->v.v_freelist.tqe_next=0;
895 tvc->v.v_freelist.tqe_prev=(struct vnode **)0xdeadb;
896 /*tvc->vrefCount++;*/
899 * The proper value for mvstat (for root fids) is setup by the caller.
902 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
904 if (afs_globalVFS == 0) osi_Panic("afs globalvfs");
905 vSetVfsp(tvc, afs_globalVFS);
908 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
909 tvc->v.v_vfsprev = NULL;
910 afs_globalVFS->vfs_vnodes = &tvc->v;
911 if (tvc->v.v_vfsnext != NULL)
912 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
913 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us!*/
914 gnodepnt->gn_vnode = &tvc->v;
917 tvc->v.g_dev = ((struct mount *)afs_globalVFS->vfs_data)->m_dev;
919 #if defined(AFS_DUX40_ENV)
920 insmntque(tvc, afs_globalVFS, &afs_ubcops);
923 /* Is this needed??? */
924 insmntque(tvc, afs_globalVFS);
925 #endif /* AFS_OSF_ENV */
926 #endif /* AFS_DUX40_ENV */
927 #if defined(AFS_SGI_ENV)
928 VN_SET_DPAGES(&(tvc->v), (struct pfdat*)NULL);
929 osi_Assert((tvc->v.v_flag & VINACT) == 0);
931 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
932 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
933 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
934 osi_Assert(tvc->v.v_filocks == NULL);
935 #if !defined(AFS_SGI65_ENV)
936 osi_Assert(tvc->v.v_filocksem == NULL);
938 osi_Assert(tvc->cred == NULL);
940 vnode_pcache_reinit(&tvc->v);
941 tvc->v.v_rdev = NODEV;
943 vn_initlist((struct vnlist *)&tvc->v);
945 #endif /* AFS_SGI_ENV */
946 #if defined(AFS_LINUX22_ENV)
948 struct inode *ip = (struct inode*)tvc;
949 sema_init(&ip->i_sem, 1);
950 #if defined(AFS_LINUX24_ENV)
951 sema_init(&ip->i_zombie, 1);
952 init_waitqueue_head(&ip->i_wait);
953 spin_lock_init(&ip->i_data.i_shared_lock);
954 INIT_LIST_HEAD(&ip->i_data.clean_pages);
955 INIT_LIST_HEAD(&ip->i_data.dirty_pages);
956 INIT_LIST_HEAD(&ip->i_data.locked_pages);
957 INIT_LIST_HEAD(&ip->i_dirty_buffers);
958 ip->i_data.host = (void*) ip;
959 ip->i_mapping = &ip->i_data;
961 sema_init(&ip->i_atomic_write, 1);
962 init_waitqueue(&ip->i_wait);
964 INIT_LIST_HEAD(&ip->i_hash);
965 INIT_LIST_HEAD(&ip->i_dentry);
967 ip->i_dev = afs_globalVFS->s_dev;
968 ip->i_sb = afs_globalVFS;
973 osi_dnlc_purgedp(tvc); /* this may be overkill */
974 bzero((char *)&(tvc->quick),sizeof(struct vtodc));
975 bzero((char *)&(tvc->callsort),sizeof(struct afs_q));
976 tvc->slocks = (struct SimpleLocks *)0;
979 tvc->hnext = afs_vhashT[i];
981 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
982 refpanic ("NewVCache VLRU inconsistent");
984 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
985 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
986 refpanic ("NewVCache VLRU inconsistent2");
988 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
989 refpanic ("NewVCache VLRU inconsistent3");
991 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
992 refpanic ("NewVCache VLRU inconsistent4");
1002 * afs_FlushActiveVcaches
1008 * doflocks : Do we handle flocks?
1010 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1012 afs_FlushActiveVcaches(doflocks)
1013 register afs_int32 doflocks;
1015 { /*afs_FlushActiveVcaches*/
1017 register struct vcache *tvc;
1019 register struct conn *tc;
1020 register afs_int32 code;
1021 register struct AFS_UCRED *cred;
1022 struct vrequest treq, ureq;
1023 struct AFSVolSync tsync;
1027 AFS_STATCNT(afs_FlushActiveVcaches);
1028 ObtainReadLock(&afs_xvcache);
1029 for(i=0;i<VCSIZE;i++) {
1030 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
1031 if (doflocks && tvc->flockCount != 0) {
1032 /* if this entry has an flock, send a keep-alive call out */
1034 ReleaseReadLock(&afs_xvcache);
1035 ObtainWriteLock(&tvc->lock,51);
1037 afs_InitReq(&treq, &afs_osi_cred);
1038 treq.flags |= O_NONBLOCK;
1040 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1042 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1043 #ifdef RX_ENABLE_LOCKS
1045 #endif /* RX_ENABLE_LOCKS */
1047 RXAFS_ExtendLock(tc->id,
1048 (struct AFSFid *) &tvc->fid.Fid,
1050 #ifdef RX_ENABLE_LOCKS
1052 #endif /* RX_ENABLE_LOCKS */
1057 (afs_Analyze(tc, code, &tvc->fid, &treq,
1058 AFS_STATS_FS_RPCIDX_EXTENDLOCK,
1059 SHARED_LOCK, (struct cell *)0));
1061 ReleaseWriteLock(&tvc->lock);
1062 ObtainReadLock(&afs_xvcache);
1066 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1068 * Don't let it evaporate in case someone else is in
1069 * this code. Also, drop the afs_xvcache lock while
1070 * getting vcache locks.
1073 ReleaseReadLock(&afs_xvcache);
1074 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1075 afs_BozonLock(&tvc->pvnLock, tvc);
1077 #if defined(AFS_SGI_ENV)
1079 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1081 osi_Assert(tvc->vrefCount > 0);
1082 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1084 ObtainWriteLock(&tvc->lock,52);
1085 if (tvc->states & CCore) {
1086 tvc->states &= ~CCore;
1087 /* XXXX Find better place-holder for cred XXXX */
1088 cred = (struct AFS_UCRED *) tvc->linkData;
1089 tvc->linkData = (char *) 0; /* XXX */
1090 afs_InitReq(&ureq, cred);
1091 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1092 ICL_TYPE_POINTER, tvc,
1093 ICL_TYPE_INT32, tvc->execsOrWriters);
1094 code = afs_StoreOnLastReference(tvc, &ureq);
1095 ReleaseWriteLock(&tvc->lock);
1096 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1097 afs_BozonUnlock(&tvc->pvnLock, tvc);
1099 hzero(tvc->flushDV);
1102 if (code && code != VNOVNODE) {
1103 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1104 /* /dev/console */ 1);
1106 } else if (tvc->states & CUnlinkedDel) {
1110 ReleaseWriteLock(&tvc->lock);
1111 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1112 afs_BozonUnlock(&tvc->pvnLock, tvc);
1114 #if defined(AFS_SGI_ENV)
1115 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1117 afs_remunlink(tvc, 0);
1118 #if defined(AFS_SGI_ENV)
1119 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1123 /* lost (or won, perhaps) the race condition */
1124 ReleaseWriteLock(&tvc->lock);
1125 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1126 afs_BozonUnlock(&tvc->pvnLock, tvc);
1129 #if defined(AFS_SGI_ENV)
1130 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1132 ObtainReadLock(&afs_xvcache);
1138 AFS_RELE((struct vnode *)tvc);
1140 /* Matches write code setting CCore flag */
1144 #ifdef AFS_DARWIN_ENV
1145 if (tvc->vrefCount == 1 && UBCINFOEXISTS(&tvc->v)) {
1146 if (tvc->opens) panic("flushactive open, hasubc, but refcnt 1");
1147 osi_VM_TryReclaim(tvc,0);
1152 ReleaseReadLock(&afs_xvcache);
1154 } /*afs_FlushActiveVcaches*/
1161 * Make sure a cache entry is up-to-date status-wise.
1163 * NOTE: everywhere that calls this can potentially be sped up
1164 * by checking CStatd first, and avoiding doing the InitReq
1165 * if this is up-to-date.
1167 * Anymore, the only places that call this KNOW already that the
1168 * vcache is not up-to-date, so we don't screw around.
1171 * avc : Ptr to vcache entry to verify.
1175 int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1177 register struct vcache *tvc;
1179 AFS_STATCNT(afs_VerifyVCache);
1181 #if defined(AFS_OSF_ENV)
1182 ObtainReadLock(&avc->lock);
1183 if (afs_IsWired(avc)) {
1184 ReleaseReadLock(&avc->lock);
1187 ReleaseReadLock(&avc->lock);
1188 #endif /* AFS_OSF_ENV */
1189 /* otherwise we must fetch the status info */
1191 ObtainWriteLock(&avc->lock,53);
1192 if (avc->states & CStatd) {
1193 ReleaseWriteLock(&avc->lock);
1196 ObtainWriteLock(&afs_xcbhash, 461);
1197 avc->states &= ~( CStatd | CUnique );
1198 avc->callback = (struct server *)0;
1199 afs_DequeueCallback(avc);
1200 ReleaseWriteLock(&afs_xcbhash);
1201 ReleaseWriteLock(&avc->lock);
1203 /* since we've been called back, or the callback has expired,
1204 * it's possible that the contents of this directory, or this
1205 * file's name have changed, thus invalidating the dnlc contents.
1207 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1208 osi_dnlc_purgedp (avc);
1210 osi_dnlc_purgevp (avc);
1212 /* fetch the status info */
1213 tvc = afs_GetVCache(&avc->fid, areq, (afs_int32*)0, avc, READ_LOCK);
1214 if (!tvc) return ENOENT;
1215 /* Put it back; caller has already incremented vrefCount */
1216 afs_PutVCache(tvc, READ_LOCK);
1219 } /*afs_VerifyVCache*/
1226 * Simple copy of stat info into cache.
1229 * avc : Ptr to vcache entry involved.
1230 * astat : Ptr to stat info to copy.
1233 * Nothing interesting.
1235 * Callers: as of 1992-04-29, only called by WriteVCache
1238 afs_SimpleVStat(avc, astat, areq)
1239 register struct vcache *avc;
1240 register struct AFSFetchStatus *astat;
1241 struct vrequest *areq;
1242 { /*afs_SimpleVStat*/
1244 AFS_STATCNT(afs_SimpleVStat);
1247 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1248 && !AFS_VN_MAPPED((vnode_t*)avc))
1250 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1254 #if defined(AFS_SGI_ENV)
1255 osi_Assert((valusema(&avc->vc_rwlock) <= 0) &&
1256 (OSI_GET_LOCKID() == avc->vc_rwlockid));
1257 if (astat->Length < avc->m.Length) {
1258 vnode_t *vp = (vnode_t *)avc;
1260 osi_Assert(WriteLocked(&avc->lock));
1261 ReleaseWriteLock(&avc->lock);
1263 PTOSSVP(vp, (off_t)astat->Length, (off_t)MAXLONG);
1265 ObtainWriteLock(&avc->lock,67);
1268 /* if writing the file, don't fetch over this value */
1269 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT,
1270 ICL_TYPE_POINTER, avc,
1271 ICL_TYPE_INT32, avc->m.Length,
1272 ICL_TYPE_INT32, astat->Length);
1273 avc->m.Length = astat->Length;
1274 avc->m.Date = astat->ClientModTime;
1276 avc->m.Owner = astat->Owner;
1277 avc->m.Group = astat->Group;
1278 avc->m.Mode = astat->UnixModeBits;
1279 if (vType(avc) == VREG) {
1280 avc->m.Mode |= S_IFREG;
1282 else if (vType(avc) == VDIR) {
1283 avc->m.Mode |= S_IFDIR;
1285 else if (vType(avc) == VLNK) {
1289 avc->m.Mode |= S_IFLNK;
1290 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1292 if (avc->states & CForeign) {
1293 struct axscache *ac;
1294 avc->anyAccess = astat->AnonymousAccess;
1296 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1298 * Caller has at least one bit not covered by anonymous, and
1299 * thus may have interesting rights.
1301 * HOWEVER, this is a really bad idea, because any access query
1302 * for bits which aren't covered by anonymous, on behalf of a user
1303 * who doesn't have any special rights, will result in an answer of
1304 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1305 * It's an especially bad idea under Ultrix, since (due to the lack of
1306 * a proper access() call) it must perform several afs_access() calls
1307 * in order to create magic mode bits that vary according to who makes
1308 * the call. In other words, _every_ stat() generates a test for
1311 #endif /* badidea */
1312 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1313 ac->axess = astat->CallerAccess;
1314 else /* not found, add a new one if possible */
1315 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1319 } /*afs_SimpleVStat*/
1326 * Store the status info *only* back to the server for a
1330 * avc : Ptr to the vcache entry.
1331 * astatus : Ptr to the status info to store.
1332 * areq : Ptr to the associated vrequest.
1335 * Must be called with a shared lock held on the vnode.
1338 afs_WriteVCache(avc, astatus, areq)
1339 register struct vcache *avc;
1340 register struct AFSStoreStatus *astatus;
1341 struct vrequest *areq;
1343 { /*afs_WriteVCache*/
1346 struct AFSFetchStatus OutStatus;
1347 struct AFSVolSync tsync;
1350 AFS_STATCNT(afs_WriteVCache);
1351 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1352 ICL_TYPE_INT32, avc->m.Length);
1355 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1357 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1358 #ifdef RX_ENABLE_LOCKS
1360 #endif /* RX_ENABLE_LOCKS */
1361 code = RXAFS_StoreStatus(tc->id,
1362 (struct AFSFid *) &avc->fid.Fid,
1363 astatus, &OutStatus, &tsync);
1364 #ifdef RX_ENABLE_LOCKS
1366 #endif /* RX_ENABLE_LOCKS */
1371 (afs_Analyze(tc, code, &avc->fid, areq,
1372 AFS_STATS_FS_RPCIDX_STORESTATUS,
1373 SHARED_LOCK, (struct cell *)0));
1375 UpgradeSToWLock(&avc->lock,20);
1377 /* success, do the changes locally */
1378 afs_SimpleVStat(avc, &OutStatus, areq);
1380 * Update the date, too. SimpleVStat didn't do this, since
1381 * it thought we were doing this after fetching new status
1382 * over a file being written.
1384 avc->m.Date = OutStatus.ClientModTime;
1387 /* failure, set up to check with server next time */
1388 ObtainWriteLock(&afs_xcbhash, 462);
1389 afs_DequeueCallback(avc);
1390 avc->states &= ~( CStatd | CUnique); /* turn off stat valid flag */
1391 ReleaseWriteLock(&afs_xcbhash);
1392 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1393 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
1395 ConvertWToSLock(&avc->lock);
1398 } /*afs_WriteVCache*/
1404 * Copy astat block into vcache info
1407 * avc : Ptr to vcache entry.
1408 * astat : Ptr to stat block to copy in.
1409 * areq : Ptr to associated request.
1412 * Must be called under a write lock
1414 * Note: this code may get dataversion and length out of sync if the file has
1415 * been modified. This is less than ideal. I haven't thought about
1416 * it sufficiently to be certain that it is adequate.
1419 afs_ProcessFS(avc, astat, areq)
1420 register struct vcache *avc;
1421 struct vrequest *areq;
1422 register struct AFSFetchStatus *astat;
1427 AFS_STATCNT(afs_ProcessFS);
1429 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1430 * number for each bulk status request. Under no circumstances
1431 * should afs_DoBulkStat store a sequence number if the new
1432 * length will be ignored when afs_ProcessFS is called with
1433 * new stats. If you change the following conditional then you
1434 * also need to change the conditional in afs_DoBulkStat. */
1436 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1437 && !AFS_VN_MAPPED((vnode_t*)avc))
1439 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1442 /* if we're writing or mapping this file, don't fetch over these
1445 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1446 ICL_TYPE_INT32, avc->m.Length,
1447 ICL_TYPE_INT32, astat->Length);
1448 avc->m.Length = astat->Length;
1449 avc->m.Date = astat->ClientModTime;
1451 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1452 avc->m.Owner = astat->Owner;
1453 avc->m.Mode = astat->UnixModeBits;
1454 avc->m.Group = astat->Group;
1455 avc->m.LinkCount = astat->LinkCount;
1456 if (astat->FileType == File) {
1457 vSetType(avc, VREG);
1458 avc->m.Mode |= S_IFREG;
1460 else if (astat->FileType == Directory) {
1461 vSetType(avc, VDIR);
1462 avc->m.Mode |= S_IFDIR;
1464 else if (astat->FileType == SymbolicLink) {
1465 vSetType(avc, VLNK);
1466 avc->m.Mode |= S_IFLNK;
1467 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1469 avc->anyAccess = astat->AnonymousAccess;
1471 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1473 * Caller has at least one bit not covered by anonymous, and
1474 * thus may have interesting rights.
1476 * HOWEVER, this is a really bad idea, because any access query
1477 * for bits which aren't covered by anonymous, on behalf of a user
1478 * who doesn't have any special rights, will result in an answer of
1479 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1480 * It's an especially bad idea under Ultrix, since (due to the lack of
1481 * a proper access() call) it must perform several afs_access() calls
1482 * in order to create magic mode bits that vary according to who makes
1483 * the call. In other words, _every_ stat() generates a test for
1486 #endif /* badidea */
1488 struct axscache *ac;
1489 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1490 ac->axess = astat->CallerAccess;
1491 else /* not found, add a new one if possible */
1492 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1495 #ifdef AFS_LINUX22_ENV
1496 vcache2inode(avc); /* Set the inode attr cache */
1502 afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp)
1503 register struct VenusFid *afid;
1504 struct vrequest *areq;
1506 struct VenusFid *nfid;
1507 struct AFSFetchStatus *OutStatusp;
1508 struct AFSCallBack *CallBackp;
1509 struct server **serverp;
1510 struct AFSVolSync *tsyncp;
1513 register struct vcache *tvc;
1516 register struct conn *tc;
1517 struct AFSFetchStatus OutDirStatus;
1520 if (!name) name = ""; /* XXX */
1522 tc = afs_Conn(afid, areq, SHARED_LOCK);
1524 if (serverp) *serverp = tc->srvr->server;
1526 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1527 #ifdef RX_ENABLE_LOCKS
1529 #endif /* RX_ENABLE_LOCKS */
1530 code = RXAFS_Lookup(tc->id, (struct AFSFid *) &afid->Fid, name,
1531 (struct AFSFid *) &nfid->Fid,
1532 OutStatusp, &OutDirStatus, CallBackp, tsyncp);
1533 #ifdef RX_ENABLE_LOCKS
1535 #endif /* RX_ENABLE_LOCKS */
1540 (afs_Analyze(tc, code, afid, areq,
1541 AFS_STATS_FS_RPCIDX_XLOOKUP,
1542 SHARED_LOCK, (struct cell *)0));
1552 * Given a file id and a vrequest structure, fetch the status
1553 * information associated with the file.
1557 * areq : Ptr to associated vrequest structure, specifying the
1558 * user whose authentication tokens will be used.
1559 * avc : caller may already have a vcache for this file, which is
1563 * The cache entry is returned with an increased vrefCount field.
1564 * The entry must be discarded by calling afs_PutVCache when you
1565 * are through using the pointer to the cache entry.
1567 * You should not hold any locks when calling this function, except
1568 * locks on other vcache entries. If you lock more than one vcache
1569 * entry simultaneously, you should lock them in this order:
1571 * 1. Lock all files first, then directories.
1572 * 2. Within a particular type, lock entries in Fid.Vnode order.
1574 * This locking hierarchy is convenient because it allows locking
1575 * of a parent dir cache entry, given a file (to check its access
1576 * control list). It also allows renames to be handled easily by
1577 * locking directories in a constant order.
1578 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1580 struct vcache *afs_GetVCache(afid, areq, cached, avc, locktype)
1581 register struct VenusFid *afid;
1582 struct vrequest *areq;
1585 struct vcache *avc; /* might have a vcache structure already, which must
1586 * already be held by the caller */
1589 afs_int32 code, i, newvcache=0;
1590 register struct vcache *tvc;
1594 AFS_STATCNT(afs_GetVCache);
1596 if (cached) *cached = 0; /* Init just in case */
1599 ObtainSharedLock(&afs_xvcache,5);
1601 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS | DO_VLRU );
1603 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1604 ReleaseSharedLock(&afs_xvcache);
1605 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1613 if (tvc->states & CStatd) {
1614 ReleaseSharedLock(&afs_xvcache);
1619 UpgradeSToWLock(&afs_xvcache,21);
1621 /* no cache entry, better grab one */
1622 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1625 ConvertWToSLock(&afs_xvcache);
1626 afs_stats_cmperf.vcacheMisses++;
1629 ReleaseSharedLock(&afs_xvcache);
1631 ObtainWriteLock(&tvc->lock,54);
1633 if (tvc->states & CStatd) {
1634 #ifdef AFS_LINUX22_ENV
1637 ReleaseWriteLock(&tvc->lock);
1638 #ifdef AFS_DARWIN_ENV
1644 #if defined(AFS_OSF_ENV)
1645 if (afs_IsWired(tvc)) {
1646 ReleaseWriteLock(&tvc->lock);
1649 #endif /* AFS_OSF_ENV */
1651 ObtainWriteLock(&afs_xcbhash, 464);
1652 tvc->states &= ~CUnique;
1654 afs_DequeueCallback(tvc);
1655 ReleaseWriteLock(&afs_xcbhash);
1657 /* It is always appropriate to throw away all the access rights? */
1658 afs_FreeAllAxs(&(tvc->Access));
1659 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1661 if ((tvp->states & VForeign)) {
1662 if (newvcache) tvc->states |= CForeign;
1663 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1664 && (tvp->rootUnique == afid->Fid.Unique)) {
1668 if (tvp->states & VRO) tvc->states |= CRO;
1669 if (tvp->states & VBackup) tvc->states |= CBackup;
1670 /* now copy ".." entry back out of volume structure, if necessary */
1671 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1673 tvc->mvid = (struct VenusFid *)
1674 osi_AllocSmallSpace(sizeof(struct VenusFid));
1675 *tvc->mvid = tvp->dotdot;
1677 afs_PutVolume(tvp, READ_LOCK);
1681 afs_RemoveVCB(afid);
1683 struct AFSFetchStatus OutStatus;
1684 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1688 ReleaseWriteLock(&tvc->lock);
1690 ObtainReadLock(&afs_xvcache);
1692 ReleaseReadLock(&afs_xvcache);
1693 return (struct vcache *) 0;
1696 ReleaseWriteLock(&tvc->lock);
1697 #ifdef AFS_DARWIN_ENV
1706 struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1707 afs_int32 *cached, afs_int32 locktype,
1708 struct vcache *adp, char *aname)
1710 afs_int32 code, now, newvcache=0, hash;
1711 struct VenusFid nfid;
1712 register struct vcache *tvc;
1714 struct AFSFetchStatus OutStatus;
1715 struct AFSCallBack CallBack;
1716 struct AFSVolSync tsync;
1717 struct server *serverp = 0;
1721 AFS_STATCNT(afs_GetVCache);
1722 if (cached) *cached = 0; /* Init just in case */
1725 ObtainReadLock(&afs_xvcache);
1726 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS /* no vlru */);
1729 ReleaseReadLock(&afs_xvcache);
1731 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1732 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1736 ObtainReadLock(&tvc->lock);
1738 if (tvc->states & CStatd) {
1742 ReleaseReadLock(&tvc->lock);
1745 tvc->states &= ~CUnique;
1747 ReleaseReadLock(&tvc->lock);
1748 ObtainReadLock(&afs_xvcache);
1752 ReleaseReadLock(&afs_xvcache);
1754 /* lookup the file */
1757 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1758 code = afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1762 ObtainSharedLock(&afs_xvcache,6);
1763 tvc = afs_FindVCache(&nfid, 0, 0, &retry, DO_VLRU /* no xstats now*/);
1765 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1766 ReleaseSharedLock(&afs_xvcache);
1767 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1773 /* no cache entry, better grab one */
1774 UpgradeSToWLock(&afs_xvcache,22);
1775 tvc = afs_NewVCache(&nfid, (struct server *)0, 1, WRITE_LOCK);
1777 ConvertWToSLock(&afs_xvcache);
1780 ReleaseSharedLock(&afs_xvcache);
1781 ObtainWriteLock(&tvc->lock,55);
1783 /* It is always appropriate to throw away all the access rights? */
1784 afs_FreeAllAxs(&(tvc->Access));
1785 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1787 if ((tvp->states & VForeign)) {
1788 if (newvcache) tvc->states |= CForeign;
1789 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1790 && (tvp->rootUnique == afid->Fid.Unique))
1793 if (tvp->states & VRO) tvc->states |= CRO;
1794 if (tvp->states & VBackup) tvc->states |= CBackup;
1795 /* now copy ".." entry back out of volume structure, if necessary */
1796 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1798 tvc->mvid = (struct VenusFid *)
1799 osi_AllocSmallSpace(sizeof(struct VenusFid));
1800 *tvc->mvid = tvp->dotdot;
1805 ObtainWriteLock(&afs_xcbhash, 465);
1806 afs_DequeueCallback(tvc);
1807 tvc->states &= ~( CStatd | CUnique );
1808 ReleaseWriteLock(&afs_xcbhash);
1809 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1810 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1812 afs_PutVolume(tvp, READ_LOCK);
1813 ReleaseWriteLock(&tvc->lock);
1814 ObtainReadLock(&afs_xvcache);
1816 ReleaseReadLock(&afs_xvcache);
1817 return (struct vcache *) 0;
1820 ObtainWriteLock(&afs_xcbhash, 466);
1821 if (origCBs == afs_allCBs) {
1822 if (CallBack.ExpirationTime) {
1823 tvc->callback = serverp;
1824 tvc->cbExpires = CallBack.ExpirationTime+now;
1825 tvc->states |= CStatd | CUnique;
1826 tvc->states &= ~CBulkFetching;
1827 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1828 } else if (tvc->states & CRO) {
1829 /* adapt gives us an hour. */
1830 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
1831 tvc->states |= CStatd | CUnique;
1832 tvc->states &= ~CBulkFetching;
1833 afs_QueueCallback(tvc, CBHash(3600), tvp);
1835 tvc->callback = (struct server *)0;
1836 afs_DequeueCallback(tvc);
1837 tvc->states &= ~(CStatd | CUnique);
1838 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1839 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1842 afs_DequeueCallback(tvc);
1843 tvc->states &= ~CStatd;
1844 tvc->states &= ~CUnique;
1845 tvc->callback = (struct server *)0;
1846 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1847 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1849 ReleaseWriteLock(&afs_xcbhash);
1851 afs_PutVolume(tvp, READ_LOCK);
1852 afs_ProcessFS(tvc, &OutStatus, areq);
1854 ReleaseWriteLock(&tvc->lock);
1855 #ifdef AFS_DARWIN_ENV
1862 struct vcache *afs_GetRootVCache(struct VenusFid *afid,
1863 struct vrequest *areq, afs_int32 *cached,
1864 struct volume *tvolp, afs_int32 locktype)
1866 afs_int32 code, i, newvcache = 0, haveStatus = 0;
1867 afs_int32 getNewFid = 0;
1869 struct VenusFid nfid;
1870 register struct vcache *tvc;
1871 struct server *serverp = 0;
1872 struct AFSFetchStatus OutStatus;
1873 struct AFSCallBack CallBack;
1874 struct AFSVolSync tsync;
1880 if (!tvolp->rootVnode || getNewFid) {
1881 struct VenusFid tfid;
1884 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1885 origCBs = afs_allCBs; /* ignore InitCallBackState */
1886 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid,
1887 &OutStatus, &CallBack, &serverp, &tsync);
1889 return (struct vcache *)0;
1891 /* ReleaseReadLock(&tvolp->lock); */
1892 ObtainWriteLock(&tvolp->lock,56);
1893 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
1894 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
1895 ReleaseWriteLock(&tvolp->lock);
1896 /* ObtainReadLock(&tvolp->lock);*/
1899 afid->Fid.Vnode = tvolp->rootVnode;
1900 afid->Fid.Unique = tvolp->rootUnique;
1903 ObtainSharedLock(&afs_xvcache,7);
1905 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1906 if (!FidCmp(&(tvc->fid), afid)) {
1908 /* Grab this vnode, possibly reactivating from the free list */
1909 /* for the present (95.05.25) everything on the hash table is
1910 * definitively NOT in the free list -- at least until afs_reclaim
1911 * can be safely implemented */
1914 vg = vget((struct vnode *)tvc); /* this bumps ref count */
1918 #endif /* AFS_OSF_ENV */
1923 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
1924 /* Mount point no longer stat'd or unknown. FID may have changed. */
1929 tvc = (struct vcache*)0;
1931 ReleaseSharedLock(&afs_xvcache);
1936 UpgradeSToWLock(&afs_xvcache,23);
1937 /* no cache entry, better grab one */
1938 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1940 afs_stats_cmperf.vcacheMisses++;
1943 if (cached) *cached = 1;
1944 afs_stats_cmperf.vcacheHits++;
1946 /* we already bumped the ref count in the for loop above */
1947 #else /* AFS_OSF_ENV */
1950 UpgradeSToWLock(&afs_xvcache,24);
1951 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1952 refpanic ("GRVC VLRU inconsistent0");
1954 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1955 refpanic ("GRVC VLRU inconsistent1");
1957 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1958 refpanic ("GRVC VLRU inconsistent2");
1960 QRemove(&tvc->vlruq); /* move to lruq head */
1961 QAdd(&VLRU, &tvc->vlruq);
1962 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1963 refpanic ("GRVC VLRU inconsistent3");
1965 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1966 refpanic ("GRVC VLRU inconsistent4");
1968 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1969 refpanic ("GRVC VLRU inconsistent5");
1974 ReleaseWriteLock(&afs_xvcache);
1976 if (tvc->states & CStatd) {
1980 ObtainReadLock(&tvc->lock);
1981 tvc->states &= ~CUnique;
1982 tvc->callback = (struct server *)0; /* redundant, perhaps */
1983 ReleaseReadLock(&tvc->lock);
1986 ObtainWriteLock(&tvc->lock,57);
1988 /* It is always appropriate to throw away all the access rights? */
1989 afs_FreeAllAxs(&(tvc->Access));
1991 if (newvcache) tvc->states |= CForeign;
1992 if (tvolp->states & VRO) tvc->states |= CRO;
1993 if (tvolp->states & VBackup) tvc->states |= CBackup;
1994 /* now copy ".." entry back out of volume structure, if necessary */
1995 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
1996 && (tvolp->rootUnique == afid->Fid.Unique)) {
1999 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2001 tvc->mvid = (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid));
2002 *tvc->mvid = tvolp->dotdot;
2006 afs_RemoveVCB(afid);
2009 struct VenusFid tfid;
2012 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2013 origCBs = afs_allCBs; /* ignore InitCallBackState */
2014 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid, &OutStatus,
2015 &CallBack, &serverp, &tsync);
2019 ObtainWriteLock(&afs_xcbhash, 467);
2020 afs_DequeueCallback(tvc);
2021 tvc->callback = (struct server *)0;
2022 tvc->states &= ~(CStatd|CUnique);
2023 ReleaseWriteLock(&afs_xcbhash);
2024 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2025 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2026 ReleaseWriteLock(&tvc->lock);
2027 ObtainReadLock(&afs_xvcache);
2029 ReleaseReadLock(&afs_xvcache);
2030 return (struct vcache *) 0;
2033 ObtainWriteLock(&afs_xcbhash, 468);
2034 if (origCBs == afs_allCBs) {
2035 tvc->states |= CTruth;
2036 tvc->callback = serverp;
2037 if (CallBack.ExpirationTime != 0) {
2038 tvc->cbExpires = CallBack.ExpirationTime+start;
2039 tvc->states |= CStatd;
2040 tvc->states &= ~CBulkFetching;
2041 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2042 } else if (tvc->states & CRO) {
2043 /* adapt gives us an hour. */
2044 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2045 tvc->states |= CStatd;
2046 tvc->states &= ~CBulkFetching;
2047 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2050 afs_DequeueCallback(tvc);
2051 tvc->callback = (struct server *)0;
2052 tvc->states &= ~(CStatd | CUnique);
2053 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2054 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2056 ReleaseWriteLock(&afs_xcbhash);
2057 afs_ProcessFS(tvc, &OutStatus, areq);
2059 ReleaseWriteLock(&tvc->lock);
2066 * must be called with avc write-locked
2067 * don't absolutely have to invalidate the hint unless the dv has
2068 * changed, but be sure to get it right else there will be consistency bugs.
2070 afs_int32 afs_FetchStatus(struct vcache *avc, struct VenusFid *afid,
2071 struct vrequest *areq, struct AFSFetchStatus *Outsp)
2075 register struct conn *tc;
2076 struct AFSCallBack CallBack;
2077 struct AFSVolSync tsync;
2078 struct volume* volp;
2082 tc = afs_Conn(afid, areq, SHARED_LOCK);
2083 avc->quick.stamp = 0; avc->h1.dchint = NULL; /* invalidate hints */
2085 avc->callback = tc->srvr->server;
2087 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2088 #ifdef RX_ENABLE_LOCKS
2090 #endif /* RX_ENABLE_LOCKS */
2091 code = RXAFS_FetchStatus(tc->id,
2092 (struct AFSFid *) &afid->Fid,
2093 Outsp, &CallBack, &tsync);
2094 #ifdef RX_ENABLE_LOCKS
2096 #endif /* RX_ENABLE_LOCKS */
2103 (afs_Analyze(tc, code, afid, areq,
2104 AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2105 SHARED_LOCK, (struct cell *)0));
2108 afs_ProcessFS(avc, Outsp, areq);
2109 volp = afs_GetVolume(afid, areq, READ_LOCK);
2110 ObtainWriteLock(&afs_xcbhash, 469);
2111 avc->states |= CTruth;
2112 if (avc->callback /* check for race */) {
2113 if (CallBack.ExpirationTime != 0) {
2114 avc->cbExpires = CallBack.ExpirationTime+start;
2115 avc->states |= CStatd;
2116 avc->states &= ~CBulkFetching;
2117 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2119 else if (avc->states & CRO)
2120 { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2121 avc->cbExpires = 3600+start;
2122 avc->states |= CStatd;
2123 avc->states &= ~CBulkFetching;
2124 afs_QueueCallback(avc, CBHash(3600), volp);
2127 afs_DequeueCallback(avc);
2128 avc->callback = (struct server *)0;
2129 avc->states &= ~(CStatd|CUnique);
2130 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2131 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2135 afs_DequeueCallback(avc);
2136 avc->callback = (struct server *)0;
2137 avc->states &= ~(CStatd|CUnique);
2138 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2139 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2141 ReleaseWriteLock(&afs_xcbhash);
2143 afs_PutVolume(volp, READ_LOCK);
2145 else { /* used to undo the local callback, but that's too extreme.
2146 * There are plenty of good reasons that fetchstatus might return
2147 * an error, such as EPERM. If we have the vnode cached, statd,
2148 * with callback, might as well keep track of the fact that we
2149 * don't have access...
2151 if (code == EPERM || code == EACCES) {
2152 struct axscache *ac;
2153 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2155 else /* not found, add a new one if possible */
2156 afs_AddAxs(avc->Access, areq->uid, 0);
2167 * Stuff some information into the vcache for the given file.
2170 * afid : File in question.
2171 * OutStatus : Fetch status on the file.
2172 * CallBack : Callback info.
2173 * tc : RPC connection involved.
2174 * areq : vrequest involved.
2177 * Nothing interesting.
2180 afs_StuffVcache(afid, OutStatus, CallBack, tc, areq)
2181 register struct VenusFid *afid;
2182 struct AFSFetchStatus *OutStatus;
2183 struct AFSCallBack *CallBack;
2184 register struct conn *tc;
2185 struct vrequest *areq;
2187 { /*afs_StuffVcache*/
2189 register afs_int32 code, i, newvcache=0;
2190 register struct vcache *tvc;
2191 struct AFSVolSync tsync;
2193 struct axscache *ac;
2196 AFS_STATCNT(afs_StuffVcache);
2197 #ifdef IFS_VCACHECOUNT
2202 ObtainSharedLock(&afs_xvcache,8);
2204 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_VLRU /* no stats */);
2206 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2207 ReleaseSharedLock(&afs_xvcache);
2208 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2214 /* no cache entry, better grab one */
2215 UpgradeSToWLock(&afs_xvcache,25);
2216 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
2218 ConvertWToSLock(&afs_xvcache);
2221 ReleaseSharedLock(&afs_xvcache);
2222 ObtainWriteLock(&tvc->lock,58);
2224 tvc->states &= ~CStatd;
2225 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2226 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2228 /* Is it always appropriate to throw away all the access rights? */
2229 afs_FreeAllAxs(&(tvc->Access));
2231 /*Copy useful per-volume info*/
2232 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2234 if (newvcache && (tvp->states & VForeign)) tvc->states |= CForeign;
2235 if (tvp->states & VRO) tvc->states |= CRO;
2236 if (tvp->states & VBackup) tvc->states |= CBackup;
2238 * Now, copy ".." entry back out of volume structure, if
2241 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2242 if (!tvc->mvid) tvc->mvid =
2243 (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid));
2244 *tvc->mvid = tvp->dotdot;
2247 /* store the stat on the file */
2248 afs_RemoveVCB(afid);
2249 afs_ProcessFS(tvc, OutStatus, areq);
2250 tvc->callback = tc->srvr->server;
2252 /* we use osi_Time twice below. Ideally, we would use the time at which
2253 * the FetchStatus call began, instead, but we don't have it here. So we
2254 * make do with "now". In the CRO case, it doesn't really matter. In
2255 * the other case, we hope that the difference between "now" and when the
2256 * call actually began execution on the server won't be larger than the
2257 * padding which the server keeps. Subtract 1 second anyway, to be on
2258 * the safe side. Can't subtract more because we don't know how big
2259 * ExpirationTime is. Possible consistency problems may arise if the call
2260 * timeout period becomes longer than the server's expiration padding. */
2261 ObtainWriteLock(&afs_xcbhash, 470);
2262 if (CallBack->ExpirationTime != 0) {
2263 tvc->cbExpires = CallBack->ExpirationTime+osi_Time()-1;
2264 tvc->states |= CStatd;
2265 tvc->states &= ~CBulkFetching;
2266 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2268 else if (tvc->states & CRO) {
2269 /* old-fashioned AFS 3.2 style */
2270 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2271 tvc->states |= CStatd;
2272 tvc->states &= ~CBulkFetching;
2273 afs_QueueCallback(tvc, CBHash(3600), tvp);
2276 afs_DequeueCallback(tvc);
2277 tvc->callback = (struct server *)0;
2278 tvc->states &= ~(CStatd|CUnique);
2279 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2280 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2282 ReleaseWriteLock(&afs_xcbhash);
2284 afs_PutVolume(tvp, READ_LOCK);
2286 /* look in per-pag cache */
2287 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2288 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2289 else /* not found, add a new one if possible */
2290 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2292 ReleaseWriteLock(&tvc->lock);
2293 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2294 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32, tvc->cbExpires,
2295 ICL_TYPE_INT32, tvc->cbExpires-osi_Time());
2297 * Release ref count... hope this guy stays around...
2299 afs_PutVCache(tvc, WRITE_LOCK);
2300 } /*afs_StuffVcache*/
2307 * Decrements the reference count on a cache entry.
2310 * avc : Pointer to the cache entry to decrement.
2313 * Nothing interesting.
2316 afs_PutVCache(avc, locktype)
2317 register struct vcache *avc;
2321 AFS_STATCNT(afs_PutVCache);
2323 * Can we use a read lock here?
2325 ObtainReadLock(&afs_xvcache);
2327 ReleaseReadLock(&afs_xvcache);
2334 * Find a vcache entry given a fid.
2337 * afid : Pointer to the fid whose cache entry we desire.
2338 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2339 * unlock the vnode, and try again.
2340 * flags: bit 1 to specify whether to compute hit statistics. Not
2341 * set if FindVCache is called as part of internal bookkeeping.
2344 * Must be called with the afs_xvcache lock at least held at
2345 * the read level. In order to do the VLRU adjustment, the xvcache lock
2346 * must be shared-- we upgrade it here.
2349 struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit,
2350 afs_int32 locktype, afs_int32 *retry, afs_int32 flag)
2353 register struct vcache *tvc;
2356 AFS_STATCNT(afs_FindVCache);
2359 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2360 if (FidMatches(afid, tvc)) {
2362 /* Grab this vnode, possibly reactivating from the free list */
2365 vg = vget((struct vnode *)tvc);
2369 #endif /* AFS_OSF_ENV */
2374 /* should I have a read lock on the vnode here? */
2376 if (retry) *retry = 0;
2377 #if !defined(AFS_OSF_ENV)
2378 osi_vnhold(tvc, retry); /* already held, above */
2379 if (retry && *retry)
2383 * only move to front of vlru if we have proper vcache locking)
2385 if (flag & DO_VLRU) {
2386 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2387 refpanic ("FindVC VLRU inconsistent1");
2389 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2390 refpanic ("FindVC VLRU inconsistent1");
2392 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2393 refpanic ("FindVC VLRU inconsistent2");
2395 UpgradeSToWLock(&afs_xvcache,26);
2396 QRemove(&tvc->vlruq);
2397 QAdd(&VLRU, &tvc->vlruq);
2398 ConvertWToSLock(&afs_xvcache);
2399 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2400 refpanic ("FindVC VLRU inconsistent1");
2402 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2403 refpanic ("FindVC VLRU inconsistent2");
2405 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2406 refpanic ("FindVC VLRU inconsistent3");
2412 if (flag & DO_STATS) {
2413 if (tvc) afs_stats_cmperf.vcacheHits++;
2414 else afs_stats_cmperf.vcacheMisses++;
2415 if (afid->Cell == LOCALCELL)
2416 afs_stats_cmperf.vlocalAccesses++;
2418 afs_stats_cmperf.vremoteAccesses++;
2421 #ifdef AFS_LINUX22_ENV
2422 if (tvc && (tvc->states & CStatd))
2423 vcache2inode(tvc); /* mainly to reset i_nlink */
2425 #ifdef AFS_DARWIN_ENV
2430 } /*afs_FindVCache*/
2436 * Find a vcache entry given a fid. Does a wildcard match on what we
2437 * have for the fid. If more than one entry, don't return anything.
2440 * avcp : Fill in pointer if we found one and only one.
2441 * afid : Pointer to the fid whose cache entry we desire.
2442 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2443 * unlock the vnode, and try again.
2444 * flags: bit 1 to specify whether to compute hit statistics. Not
2445 * set if FindVCache is called as part of internal bookkeeping.
2448 * Must be called with the afs_xvcache lock at least held at
2449 * the read level. In order to do the VLRU adjustment, the xvcache lock
2450 * must be shared-- we upgrade it here.
2453 * number of matches found.
2456 int afs_duplicate_nfs_fids=0;
2458 afs_int32 afs_NFSFindVCache(avcp, afid, lockit)
2459 struct vcache **avcp;
2460 struct VenusFid *afid;
2462 { /*afs_FindVCache*/
2464 register struct vcache *tvc;
2466 afs_int32 retry = 0;
2467 afs_int32 count = 0;
2468 struct vcache *found_tvc = NULL;
2470 AFS_STATCNT(afs_FindVCache);
2474 ObtainSharedLock(&afs_xvcache,331);
2477 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2478 /* Match only on what we have.... */
2479 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2480 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2481 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2482 && (tvc->fid.Cell == afid->Cell)) {
2484 /* Grab this vnode, possibly reactivating from the free list */
2487 vg = vget((struct vnode *)tvc);
2490 /* This vnode no longer exists. */
2493 #endif /* AFS_OSF_ENV */
2498 /* Drop our reference counts. */
2499 vrele((struct vnode *)tvc);
2500 vrele((struct vnode *)found_tvc);
2502 afs_duplicate_nfs_fids++;
2503 ReleaseSharedLock(&afs_xvcache);
2511 /* should I have a read lock on the vnode here? */
2513 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2514 osi_vnhold(tvc, &retry);
2517 found_tvc = (struct vcache*)0;
2518 ReleaseSharedLock(&afs_xvcache);
2519 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2523 #if !defined(AFS_OSF_ENV)
2524 osi_vnhold(tvc, (int*)0); /* already held, above */
2528 * We obtained the xvcache lock above.
2530 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2531 refpanic ("FindVC VLRU inconsistent1");
2533 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2534 refpanic ("FindVC VLRU inconsistent1");
2536 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2537 refpanic ("FindVC VLRU inconsistent2");
2539 UpgradeSToWLock(&afs_xvcache,568);
2540 QRemove(&tvc->vlruq);
2541 QAdd(&VLRU, &tvc->vlruq);
2542 ConvertWToSLock(&afs_xvcache);
2543 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2544 refpanic ("FindVC VLRU inconsistent1");
2546 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2547 refpanic ("FindVC VLRU inconsistent2");
2549 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2550 refpanic ("FindVC VLRU inconsistent3");
2555 if (tvc) afs_stats_cmperf.vcacheHits++;
2556 else afs_stats_cmperf.vcacheMisses++;
2557 if (afid->Cell == LOCALCELL)
2558 afs_stats_cmperf.vlocalAccesses++;
2560 afs_stats_cmperf.vremoteAccesses++;
2562 *avcp = tvc; /* May be null */
2564 ReleaseSharedLock(&afs_xvcache);
2565 return (tvc ? 1 : 0);
2567 } /*afs_NFSFindVCache*/
2575 * Initialize vcache related variables
2577 void afs_vcacheInit(int astatSize)
2579 register struct vcache *tvp;
2581 #if defined(AFS_OSF_ENV)
2582 if (!afs_maxvcount) {
2583 #if defined(AFS_OSF30_ENV)
2584 afs_maxvcount = max_vnodes/2; /* limit ourselves to half the total */
2586 afs_maxvcount = nvnode/2; /* limit ourselves to half the total */
2588 if (astatSize < afs_maxvcount) {
2589 afs_maxvcount = astatSize;
2592 #else /* AFS_OSF_ENV */
2593 freeVCList = (struct vcache *)0;
2596 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2597 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2599 #if !defined(AFS_OSF_ENV)
2600 /* Allocate and thread the struct vcache entries */
2601 tvp = (struct vcache *) afs_osi_Alloc(astatSize * sizeof(struct vcache));
2602 bzero((char *)tvp, sizeof(struct vcache)*astatSize);
2604 Initial_freeVCList = tvp;
2605 freeVCList = &(tvp[0]);
2606 for(i=0; i < astatSize-1; i++) {
2607 tvp[i].nextfree = &(tvp[i+1]);
2609 tvp[astatSize-1].nextfree = (struct vcache *) 0;
2610 #ifdef AFS_AIX32_ENV
2611 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2616 #if defined(AFS_SGI_ENV)
2617 for(i=0; i < astatSize; i++) {
2618 char name[METER_NAMSZ];
2619 struct vcache *tvc = &tvp[i];
2621 tvc->v.v_number = ++afsvnumbers;
2622 tvc->vc_rwlockid = OSI_NO_LOCKID;
2623 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
2624 #ifndef AFS_SGI53_ENV
2625 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2627 #ifndef AFS_SGI62_ENV
2628 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2629 #endif /* AFS_SGI62_ENV */
2642 void shutdown_vcache(void)
2645 struct afs_cbr *tsp, *nsp;
2647 * XXX We may potentially miss some of the vcaches because if when there're no
2648 * free vcache entries and all the vcache entries are active ones then we allocate
2649 * an additional one - admittedly we almost never had that occur.
2651 #if !defined(AFS_OSF_ENV)
2652 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2654 #ifdef AFS_AIX32_ENV
2655 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2659 register struct afs_q *tq, *uq;
2660 register struct vcache *tvc;
2661 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2665 osi_FreeSmallSpace(tvc->mvid);
2666 tvc->mvid = (struct VenusFid*)0;
2669 aix_gnode_rele((struct vnode *)tvc);
2671 if (tvc->linkData) {
2672 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2677 * Also free the remaining ones in the Cache
2679 for (i=0; i < VCSIZE; i++) {
2680 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2682 osi_FreeSmallSpace(tvc->mvid);
2683 tvc->mvid = (struct VenusFid*)0;
2687 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2688 #ifdef AFS_AIX32_ENV
2691 vms_delete(tvc->segid);
2693 tvc->segid = tvc->vmh = NULL;
2694 if (tvc->vrefCount) osi_Panic("flushVcache: vm race");
2702 #if defined(AFS_SUN5_ENV)
2708 if (tvc->linkData) {
2709 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2713 afs_FreeAllAxs(&(tvc->Access));
2719 * Free any leftover callback queue
2721 for (tsp = afs_cbrSpace; tsp; tsp = nsp ) {
2723 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2727 #if !defined(AFS_OSF_ENV)
2728 freeVCList = Initial_freeVCList = 0;
2730 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2731 LOCK_INIT(&afs_xvcb, "afs_xvcb");