2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
19 * afs_FlushActiveVcaches
38 #include "../afs/param.h" /*Should be always first*/
39 #include "../afs/sysincludes.h" /*Standard vendor system headers*/
40 #include "../afs/afsincludes.h" /*AFS-based standard headers*/
41 #include "../afs/afs_stats.h"
42 #include "../afs/afs_cbqueue.h"
43 #include "../afs/afs_osidnlc.h"
46 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
47 afs_int32 afs_vcount = 0; /* number of vcache in use now */
48 #if defined(AFS_OSF30_ENV)
49 extern int max_vnodes; /* number of total system vnodes */
51 extern int nvnode; /* number of total system vnodes */
54 extern int numvnodes; /* number vnodes in use now */
56 #endif /* AFS_OSF_ENV */
61 /* Imported variables */
62 extern struct server *afs_servers[NSERVERS];
63 extern afs_rwlock_t afs_xserver;
64 extern afs_rwlock_t afs_xcbhash;
65 extern struct vcache *afs_globalVp;
67 extern struct mount *afs_globalVFS;
68 extern struct vnodeops Afs_vnodeops;
69 #elif defined(AFS_DARWIN_ENV)
70 extern struct mount *afs_globalVFS;
72 extern struct vfs *afs_globalVFS;
73 #endif /* AFS_OSF_ENV */
74 #if defined(AFS_DUX40_ENV)
75 extern struct vfs_ubcops afs_ubcops;
78 extern struct vnodeops Afs_vnodeops;
82 #endif /* AFS_SGI64_ENV */
84 /* Exported variables */
85 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries*/
86 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks*/
87 struct vcache *freeVCList; /*Free list for stat cache entries*/
88 struct vcache *Initial_freeVCList; /*Initial list for above*/
89 struct afs_q VLRU; /*vcache LRU*/
90 afs_int32 vcachegen = 0;
91 unsigned int afs_paniconwarn = 0;
92 struct vcache *afs_vhashT[VCSIZE];
93 afs_int32 afs_bulkStatsLost;
94 int afs_norefpanic = 0;
96 /* Forward declarations */
97 static afs_int32 afs_QueueVCB(struct vcache *avc);
104 * Flush the given vcache entry.
107 * avc : Pointer to vcache entry to flush.
108 * slept : Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
111 * afs_xvcache lock must be held for writing upon entry to
112 * prevent people from changing the vrefCount field, and to
113 * protect the lruq and hnext fields.
114 * LOCK: afs_FlushVCache afs_xvcache W
115 * REFCNT: vcache ref count must be zero on entry except for osf1
116 * RACE: lock is dropped and reobtained, permitting race in caller
119 int afs_FlushVCache(struct vcache *avc, int *slept)
120 { /*afs_FlushVCache*/
122 register afs_int32 i, code;
123 register struct vcache **uvc, *wvc, *tvc;
126 AFS_STATCNT(afs_FlushVCache);
127 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
128 ICL_TYPE_INT32, avc->states);
131 VN_LOCK((struct vnode *)avc);
135 code = osi_VM_FlushVCache(avc, slept);
139 if (avc->states & CVFlushed) {
143 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
144 refpanic ("LRU vs. Free inconsistency");
146 avc->states |= CVFlushed;
147 /* pull the entry out of the lruq and put it on the free list */
148 QRemove(&avc->vlruq);
149 avc->vlruq.prev = avc->vlruq.next = (struct afs_q *) 0;
151 /* keep track of # of files that we bulk stat'd, but never used
152 * before they got recycled.
154 if (avc->states & CBulkStat)
157 /* remove entry from the hash chain */
158 i = VCHash(&avc->fid);
159 uvc = &afs_vhashT[i];
160 for(wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
163 avc->hnext = (struct vcache *) NULL;
167 if (!wvc) osi_Panic("flushvcache"); /* not in correct hash bucket */
168 if (avc->mvid) osi_FreeSmallSpace(avc->mvid);
169 avc->mvid = (struct VenusFid*)0;
171 afs_osi_Free(avc->linkData, strlen(avc->linkData)+1);
172 avc->linkData = NULL;
174 afs_FreeAllAxs(&(avc->Access));
176 /* we can't really give back callbacks on RO files, since the
177 * server only tracks them on a per-volume basis, and we don't
178 * know whether we still have some other files from the same
180 if ((avc->states & CRO) == 0 && avc->callback) {
183 ObtainWriteLock(&afs_xcbhash, 460);
184 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
185 avc->states &= ~(CStatd | CUnique);
186 ReleaseWriteLock(&afs_xcbhash);
187 afs_symhint_inval(avc);
188 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
189 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
191 osi_dnlc_purgevp (avc);
194 * Next, keep track of which vnodes we've deleted for create's
195 * optimistic synchronization algorithm
198 if (avc->fid.Fid.Vnode & 1) afs_oddZaps++;
201 #if !defined(AFS_OSF_ENV)
202 /* put the entry in the free list */
203 avc->nextfree = freeVCList;
205 if (avc->vlruq.prev || avc->vlruq.next) {
206 refpanic ("LRU vs. Free inconsistency");
209 /* This should put it back on the vnode free list since usecount is 1 */
212 if (avc->vrefCount > 0) {
213 VN_UNLOCK((struct vnode *)avc);
214 AFS_RELE((struct vnode *)avc);
216 if (afs_norefpanic) {
217 printf ("flush vc refcnt < 1");
219 (void) vgone(avc, VX_NOSLEEP, (struct vnodeops *) 0);
221 VN_UNLOCK((struct vnode *)avc);
223 else osi_Panic ("flush vc refcnt < 1");
225 #endif /* AFS_OSF_ENV */
226 avc->states |= CVFlushed;
231 VN_UNLOCK((struct vnode *)avc);
235 } /*afs_FlushVCache*/
241 * The core of the inactive vnode op for all but IRIX.
243 void afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred)
245 extern afs_rwlock_t afs_xdcache, afs_xvcache;
247 AFS_STATCNT(afs_inactive);
248 if (avc->states & CDirty) {
249 /* we can't keep trying to push back dirty data forever. Give up. */
250 afs_InvalidateAllSegments(avc, 1/*set lock*/); /* turns off dirty bit */
252 avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
253 avc->states &= ~CDirty; /* Turn it off */
254 if (avc->states & CUnlinked) {
255 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
256 avc->states |= CUnlinkedDel;
259 afs_remunlink(avc, 1); /* ignore any return code */
268 * Description: allocate a callback return structure from the
269 * free list and return it.
271 * Env: The alloc and free routines are both called with the afs_xvcb lock
272 * held, so we don't have to worry about blocking in osi_Alloc.
274 static struct afs_cbr *afs_cbrSpace = 0;
275 struct afs_cbr *afs_AllocCBR() {
276 register struct afs_cbr *tsp;
279 while (!afs_cbrSpace) {
280 if (afs_stats_cmperf.CallBackAlloced >= 2) {
281 /* don't allocate more than 2 * AFS_NCBRS for now */
283 afs_stats_cmperf.CallBackFlushes++;
287 tsp = (struct afs_cbr *) afs_osi_Alloc(AFS_NCBRS * sizeof(struct afs_cbr));
288 for(i=0; i < AFS_NCBRS-1; i++) {
289 tsp[i].next = &tsp[i+1];
291 tsp[AFS_NCBRS-1].next = 0;
293 afs_stats_cmperf.CallBackAlloced++;
297 afs_cbrSpace = tsp->next;
304 * Description: free a callback return structure.
307 * asp -- the address of the structure to free.
309 * Environment: the xvcb lock is held over these calls.
312 register struct afs_cbr *asp; {
313 asp->next = afs_cbrSpace;
321 * Description: flush all queued callbacks to all servers.
325 * Environment: holds xvcb lock over RPC to guard against race conditions
326 * when a new callback is granted for the same file later on.
328 afs_int32 afs_FlushVCBs (afs_int32 lockit)
330 struct AFSFid tfids[AFS_MAXCBRSCALL];
331 struct AFSCallBack callBacks[1];
332 struct AFSCBFids fidArray;
333 struct AFSCBs cbArray;
335 struct afs_cbr *tcbrp;
339 struct vrequest treq;
341 int safety1, safety2, safety3;
342 extern int afs_totalServers;
345 if (code = afs_InitReq(&treq, &afs_osi_cred)) return code;
346 treq.flags |= O_NONBLOCK;
348 if (lockit) MObtainWriteLock(&afs_xvcb,273);
349 ObtainReadLock(&afs_xserver);
350 for(i=0; i<NSERVERS; i++) {
351 for(safety1 = 0, tsp = afs_servers[i];
352 tsp && safety1 < afs_totalServers+10; tsp=tsp->next, safety1++) {
354 if (tsp->cbrs == (struct afs_cbr *) 0) continue;
356 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
357 * and make an RPC, over and over again.
359 tcount = 0; /* number found so far */
360 for (safety2 = 0; safety2 < afs_cacheStats ; safety2++) {
361 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
362 /* if buffer is full, or we've queued all we're going
363 * to from this server, we should flush out the
366 fidArray.AFSCBFids_len = tcount;
367 fidArray.AFSCBFids_val = (struct AFSFid *) tfids;
368 cbArray.AFSCBs_len = 1;
369 cbArray.AFSCBs_val = callBacks;
370 callBacks[0].CallBackType = CB_EXCLUSIVE;
371 for (safety3 = 0; safety3 < MAXHOSTS*2; safety3++) {
372 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
373 tsp->cell->cell, &treq, 0,
376 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
377 #ifdef RX_ENABLE_LOCKS
379 #endif /* RX_ENABLE_LOCKS */
380 code = RXAFS_GiveUpCallBacks(tc->id, &fidArray,
382 #ifdef RX_ENABLE_LOCKS
384 #endif /* RX_ENABLE_LOCKS */
388 if (!afs_Analyze(tc, code, 0, &treq,
389 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS,
390 SHARED_LOCK, tsp->cell)) {
394 /* ignore return code, since callbacks may have
395 * been returned anyway, we shouldn't leave them
396 * around to be returned again.
398 * Next, see if we are done with this server, and if so,
399 * break to deal with the next one.
401 if (!tsp->cbrs) break;
403 } /* if to flush full buffer */
404 /* if we make it here, we have an entry at the head of cbrs,
405 * which we should copy to the file ID array and then free.
408 tfids[tcount++] = tcbrp->fid;
409 tsp->cbrs = tcbrp->next;
411 } /* while loop for this one server */
412 if (safety2 > afs_cacheStats) {
413 afs_warn("possible internal error afs_flushVCBs (%d)\n", safety2);
415 } /* for loop for this hash chain */
416 } /* loop through all hash chains */
417 if (safety1 > afs_totalServers+2) {
418 afs_warn("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n", safety1, afs_totalServers+2);
420 osi_Panic("afs_flushVCBS safety1");
423 ReleaseReadLock(&afs_xserver);
424 if (lockit) MReleaseWriteLock(&afs_xvcb);
432 * Queue a callback on the given fid.
438 * Locks the xvcb lock.
439 * Called when the xvcache lock is already held.
442 static afs_int32 afs_QueueVCB(struct vcache *avc)
444 register struct server *tsp;
445 register struct afs_cbr *tcbp;
447 AFS_STATCNT(afs_QueueVCB);
448 /* The callback is really just a struct server ptr. */
449 tsp = (struct server *)(avc->callback);
451 /* we now have a pointer to the server, so we just allocate
452 * a queue entry and queue it.
454 MObtainWriteLock(&afs_xvcb,274);
455 tcbp = afs_AllocCBR();
456 tcbp->fid = avc->fid.Fid;
457 tcbp->next = tsp->cbrs;
460 /* now release locks and return */
461 MReleaseWriteLock(&afs_xvcb);
470 * Remove a queued callback by looking through all the servers
471 * to see if any have this callback queued.
474 * afid: The fid we want cleansed of queued callbacks.
477 * Locks xvcb and xserver locks.
478 * Typically called with xdcache, xvcache and/or individual vcache
483 register struct VenusFid *afid;
488 register struct server *tsp;
489 register struct afs_cbr *tcbrp;
490 struct afs_cbr **lcbrpp;
492 AFS_STATCNT(afs_RemoveVCB);
493 MObtainWriteLock(&afs_xvcb,275);
494 ObtainReadLock(&afs_xserver);
495 for(i=0;i<NSERVERS;i++) {
496 for(tsp=afs_servers[i]; tsp; tsp=tsp->next) {
497 /* if cell is known, and is wrong, then skip this server */
498 if (tsp->cell && tsp->cell->cell != afid->Cell) continue;
501 * Otherwise, iterate through file IDs we're sending to the
504 lcbrpp = &tsp->cbrs; /* first queued return callback */
505 for(tcbrp = *lcbrpp; tcbrp; lcbrpp = &tcbrp->next, tcbrp = *lcbrpp) {
506 if (afid->Fid.Volume == tcbrp->fid.Volume &&
507 afid->Fid.Unique == tcbrp->fid.Unique &&
508 afid->Fid.Vnode == tcbrp->fid.Vnode) {
509 *lcbrpp = tcbrp->next; /* unthread from list */
517 ReleaseReadLock(&afs_xserver);
518 MReleaseWriteLock(&afs_xvcb);
529 * This routine is responsible for allocating a new cache entry
530 * from the free list. It formats the cache entry and inserts it
531 * into the appropriate hash tables. It must be called with
532 * afs_xvcache write-locked so as to prevent several processes from
533 * trying to create a new cache entry simultaneously.
536 * afid : The file id of the file whose cache entry is being
539 /* LOCK: afs_NewVCache afs_xvcache W */
540 struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp,
541 afs_int32 lockit, afs_int32 locktype)
545 afs_int32 anumber = VCACHE_FREE;
547 struct gnode *gnodepnt;
550 struct vm_info * vm_info_ptr;
551 #endif /* AFS_MACH_ENV */
554 #endif /* AFS_OSF_ENV */
555 struct afs_q *tq, *uq;
558 AFS_STATCNT(afs_NewVCache);
559 #ifdef AFS_LINUX22_ENV
561 /* Free some if possible. */
562 struct afs_q *tq, *uq;
563 int i; char *panicstr;
564 int vmax = 2 * afs_cacheStats;
565 int vn = VCACHE_FREE;
568 for(tq = VLRU.prev; tq != &VLRU && vn > 0; tq = uq) {
571 if (tvc->states & CVFlushed)
572 refpanic ("CVFlushed on VLRU");
574 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
575 else if (QNext(uq) != tq)
576 refpanic ("VLRU inconsistent");
578 if (tvc == afs_globalVp)
581 if ( tvc->vrefCount && tvc->opens == 0 ) {
582 struct inode *ip = (struct inode*)tvc;
583 if (list_empty(&ip->i_dentry)) {
587 struct list_head *cur;
588 struct list_head *head = &ip->i_dentry;
591 #if defined(AFS_LINUX24_ENV)
592 spin_lock(&dcache_lock);
595 while ((cur = cur->next) != head) {
596 struct dentry *dentry = list_entry(cur, struct dentry, d_alias);
597 #if defined(AFS_LINUX24_ENV)
598 if (!atomic_read(&dentry->d_count)) {
600 if (!dentry->d_count) {
603 #if defined(AFS_LINUX24_ENV)
605 spin_unlock(&dcache_lock);
618 #if defined(AFS_LINUX24_ENV)
619 spin_unlock(&dcache_lock);
627 #endif /* AFS_LINUX22_ENV */
630 if (afs_vcount >= afs_maxvcount)
633 * If we are using > 33 % of the total system vnodes for AFS vcache
634 * entries or we are using the maximum number of vcache entries,
635 * then free some. (if our usage is > 33% we should free some, if
636 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
637 * we _must_ free some -- no choice).
639 if ( (( 3 * afs_vcount ) > nvnode) || ( afs_vcount >= afs_maxvcount ))
642 struct afs_q *tq, *uq;
643 int i; char *panicstr;
646 for(tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
649 if (tvc->states & CVFlushed)
650 refpanic ("CVFlushed on VLRU");
651 else if (i++ > afs_maxvcount)
652 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
653 else if (QNext(uq) != tq)
654 refpanic ("VLRU inconsistent");
655 else if (tvc->vrefCount < 1)
656 refpanic ("refcnt 0 on VLRU");
658 if ( tvc->vrefCount == 1 && tvc->opens == 0
659 && (tvc->states & CUnlinkedDel) == 0) {
660 code = afs_FlushVCache(tvc, &fv_slept);
667 continue; /* start over - may have raced. */
672 if (anumber == VCACHE_FREE) {
673 printf("NewVCache: warning none freed, using %d of %d\n",
674 afs_vcount, afs_maxvcount);
675 if (afs_vcount >= afs_maxvcount) {
676 osi_Panic("NewVCache - none freed");
677 /* XXX instead of panicing, should do afs_maxvcount++
678 and magic up another one */
684 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
685 /* What should we do ???? */
686 osi_Panic("afs_NewVCache: no more vnodes");
691 tvc->nextfree = (struct vcache *)0;
693 #else /* AFS_OSF_ENV */
694 /* pull out a free cache entry */
697 for(tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
701 if (tvc->states & CVFlushed)
702 refpanic("CVFlushed on VLRU");
703 else if (i++ > 2*afs_cacheStats) /* even allowing for a few xallocs...*/
704 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
705 else if (QNext(uq) != tq)
706 refpanic("VLRU inconsistent");
708 #ifdef AFS_DARWIN_ENV
709 if (tvc->opens == 0 && ((tvc->states & CUnlinkedDel) == 0) &&
710 tvc->vrefCount == 1 && UBCINFOEXISTS(&tvc->v)) {
711 osi_VM_TryReclaim(tvc, &fv_slept);
715 continue; /* start over - may have raced. */
719 if (tvc->vrefCount == 0 && tvc->opens == 0
720 && (tvc->states & CUnlinkedDel) == 0) {
721 code = afs_FlushVCache(tvc, &fv_slept);
728 continue; /* start over - may have raced. */
731 if (tq == uq ) break;
735 /* none free, making one is better than a panic */
736 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
737 tvc = (struct vcache *) afs_osi_Alloc(sizeof (struct vcache));
739 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
742 /* In case it still comes here we need to fill this */
743 tvc->v.v_vm_info = VM_INFO_NULL;
744 vm_info_init(tvc->v.v_vm_info);
745 /* perhaps we should also do close_flush on non-NeXT mach systems;
746 * who knows; we don't currently have the sources.
748 #endif /* AFS_MACH_ENV */
749 #if defined(AFS_SGI_ENV)
750 { char name[METER_NAMSZ];
751 bzero(tvc, sizeof(struct vcache));
752 tvc->v.v_number = ++afsvnumbers;
753 tvc->vc_rwlockid = OSI_NO_LOCKID;
754 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
755 #ifndef AFS_SGI53_ENV
756 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
758 #ifndef AFS_SGI62_ENV
759 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
762 #endif /* AFS_SGI_ENV */
765 tvc = freeVCList; /* take from free list */
766 freeVCList = tvc->nextfree;
767 tvc->nextfree = (struct vcache *)0;
769 #endif /* AFS_OSF_ENV */
772 vm_info_ptr = tvc->v.v_vm_info;
773 #endif /* AFS_MACH_ENV */
775 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
776 bzero((char *)tvc, sizeof(struct vcache));
781 RWLOCK_INIT(&tvc->lock, "vcache lock");
782 #if defined(AFS_SUN5_ENV)
783 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
784 #endif /* defined(AFS_SUN5_ENV) */
787 tvc->v.v_vm_info = vm_info_ptr;
788 tvc->v.v_vm_info->pager = MEMORY_OBJECT_NULL;
789 #endif /* AFS_MACH_ENV */
790 tvc->parentVnode = 0;
791 tvc->mvid = (struct VenusFid *) 0;
792 tvc->linkData = (char *) 0;
795 tvc->execsOrWriters = 0;
799 tvc->last_looker = 0;
801 tvc->asynchrony = -1;
803 afs_symhint_inval(tvc);
805 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
808 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
809 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
811 /* Hold it for the LRU (should make count 2) */
812 VN_HOLD((struct vnode *)tvc);
813 #else /* AFS_OSF_ENV */
814 tvc->vrefCount = 1; /* us */
815 #endif /* AFS_OSF_ENV */
817 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
818 tvc->vmh = tvc->segid = NULL;
821 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
822 #if defined(AFS_SUN5_ENV)
823 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
825 #if defined(AFS_SUN55_ENV)
826 /* This is required if the kaio (kernel aynchronous io)
827 ** module is installed. Inside the kernel, the function
828 ** check_vp( common/os/aio.c) checks to see if the kernel has
829 ** to provide asynchronous io for this vnode. This
830 ** function extracts the device number by following the
831 ** v_data field of the vnode. If we do not set this field
832 ** then the system panics. The value of the v_data field
833 ** is not really important for AFS vnodes because the kernel
834 ** does not do asynchronous io for regular files. Hence,
835 ** for the time being, we fill up the v_data field with the
836 ** vnode pointer itself. */
837 tvc->v.v_data = (char *)tvc;
838 #endif /* AFS_SUN55_ENV */
840 afs_BozonInit(&tvc->pvnLock, tvc);
844 tvc->callback = serverp; /* to minimize chance that clear
846 /* initialize vnode data, note vrefCount is v.v_count */
848 /* Don't forget to free the gnode space */
849 tvc->v.v_gnode = gnodepnt = (struct gnode *) osi_AllocSmallSpace(sizeof(struct gnode));
850 bzero((char *)gnodepnt, sizeof(struct gnode));
853 bzero((void*)&(tvc->vc_bhv_desc), sizeof(tvc->vc_bhv_desc));
854 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
856 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
857 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
859 bhv_head_init(&(tvc->v.v_bh));
860 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
863 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion*)tvc;
865 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
867 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
869 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
870 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
872 vnode_pcache_init(&tvc->v);
873 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
874 /* Above define is never true execpt in SGI test kernels. */
875 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
878 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
881 SetAfsVnode((struct vnode *)tvc);
882 #endif /* AFS_SGI64_ENV */
883 #ifdef AFS_DARWIN_ENV
884 tvc->v.v_ubcinfo = UBC_INFO_NULL;
885 lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0);
886 cache_purge((struct vnode *)tvc);
889 /* VLISTNONE(&tvc->v); */
890 tvc->v.v_freelist.tqe_next=0;
891 tvc->v.v_freelist.tqe_prev=(struct vnode **)0xdeadb;
892 /*tvc->vrefCount++;*/
895 * The proper value for mvstat (for root fids) is setup by the caller.
898 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
900 if (afs_globalVFS == 0) osi_Panic("afs globalvfs");
901 vSetVfsp(tvc, afs_globalVFS);
904 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
905 tvc->v.v_vfsprev = NULL;
906 afs_globalVFS->vfs_vnodes = &tvc->v;
907 if (tvc->v.v_vfsnext != NULL)
908 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
909 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us!*/
910 gnodepnt->gn_vnode = &tvc->v;
913 tvc->v.g_dev = ((struct mount *)afs_globalVFS->vfs_data)->m_dev;
915 #if defined(AFS_DUX40_ENV)
916 insmntque(tvc, afs_globalVFS, &afs_ubcops);
919 /* Is this needed??? */
920 insmntque(tvc, afs_globalVFS);
921 #endif /* AFS_OSF_ENV */
922 #endif /* AFS_DUX40_ENV */
923 #if defined(AFS_SGI_ENV)
924 VN_SET_DPAGES(&(tvc->v), (struct pfdat*)NULL);
925 osi_Assert((tvc->v.v_flag & VINACT) == 0);
927 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
928 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
929 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
930 osi_Assert(tvc->v.v_filocks == NULL);
931 #if !defined(AFS_SGI65_ENV)
932 osi_Assert(tvc->v.v_filocksem == NULL);
934 osi_Assert(tvc->cred == NULL);
936 vnode_pcache_reinit(&tvc->v);
937 tvc->v.v_rdev = NODEV;
939 vn_initlist((struct vnlist *)&tvc->v);
941 #endif /* AFS_SGI_ENV */
942 #if defined(AFS_LINUX22_ENV)
944 struct inode *ip = (struct inode*)tvc;
945 sema_init(&ip->i_sem, 1);
946 #if defined(AFS_LINUX24_ENV)
947 sema_init(&ip->i_zombie, 1);
948 init_waitqueue_head(&ip->i_wait);
949 spin_lock_init(&ip->i_data.i_shared_lock);
950 INIT_LIST_HEAD(&ip->i_data.clean_pages);
951 INIT_LIST_HEAD(&ip->i_data.dirty_pages);
952 INIT_LIST_HEAD(&ip->i_data.locked_pages);
953 INIT_LIST_HEAD(&ip->i_dirty_buffers);
954 ip->i_data.host = (void*) ip;
955 ip->i_mapping = &ip->i_data;
957 sema_init(&ip->i_atomic_write, 1);
958 init_waitqueue(&ip->i_wait);
960 INIT_LIST_HEAD(&ip->i_hash);
961 INIT_LIST_HEAD(&ip->i_dentry);
963 ip->i_dev = afs_globalVFS->s_dev;
964 ip->i_sb = afs_globalVFS;
969 osi_dnlc_purgedp(tvc); /* this may be overkill */
970 bzero((char *)&(tvc->quick),sizeof(struct vtodc));
971 bzero((char *)&(tvc->callsort),sizeof(struct afs_q));
972 tvc->slocks = (struct SimpleLocks *)0;
975 tvc->hnext = afs_vhashT[i];
977 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
978 refpanic ("NewVCache VLRU inconsistent");
980 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
981 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
982 refpanic ("NewVCache VLRU inconsistent2");
984 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
985 refpanic ("NewVCache VLRU inconsistent3");
987 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
988 refpanic ("NewVCache VLRU inconsistent4");
998 * afs_FlushActiveVcaches
1004 * doflocks : Do we handle flocks?
1006 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1008 afs_FlushActiveVcaches(doflocks)
1009 register afs_int32 doflocks;
1011 { /*afs_FlushActiveVcaches*/
1013 register struct vcache *tvc;
1015 register struct conn *tc;
1016 register afs_int32 code;
1017 register struct AFS_UCRED *cred;
1018 struct vrequest treq, ureq;
1019 struct AFSVolSync tsync;
1023 AFS_STATCNT(afs_FlushActiveVcaches);
1024 ObtainReadLock(&afs_xvcache);
1025 for(i=0;i<VCSIZE;i++) {
1026 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
1027 if (doflocks && tvc->flockCount != 0) {
1028 /* if this entry has an flock, send a keep-alive call out */
1030 ReleaseReadLock(&afs_xvcache);
1031 ObtainWriteLock(&tvc->lock,51);
1033 afs_InitReq(&treq, &afs_osi_cred);
1034 treq.flags |= O_NONBLOCK;
1036 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1038 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1039 #ifdef RX_ENABLE_LOCKS
1041 #endif /* RX_ENABLE_LOCKS */
1043 RXAFS_ExtendLock(tc->id,
1044 (struct AFSFid *) &tvc->fid.Fid,
1046 #ifdef RX_ENABLE_LOCKS
1048 #endif /* RX_ENABLE_LOCKS */
1053 (afs_Analyze(tc, code, &tvc->fid, &treq,
1054 AFS_STATS_FS_RPCIDX_EXTENDLOCK,
1055 SHARED_LOCK, (struct cell *)0));
1057 ReleaseWriteLock(&tvc->lock);
1058 ObtainReadLock(&afs_xvcache);
1062 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1064 * Don't let it evaporate in case someone else is in
1065 * this code. Also, drop the afs_xvcache lock while
1066 * getting vcache locks.
1069 ReleaseReadLock(&afs_xvcache);
1070 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1071 afs_BozonLock(&tvc->pvnLock, tvc);
1073 #if defined(AFS_SGI_ENV)
1075 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1077 osi_Assert(tvc->vrefCount > 0);
1078 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1080 ObtainWriteLock(&tvc->lock,52);
1081 if (tvc->states & CCore) {
1082 tvc->states &= ~CCore;
1083 /* XXXX Find better place-holder for cred XXXX */
1084 cred = (struct AFS_UCRED *) tvc->linkData;
1085 tvc->linkData = (char *) 0; /* XXX */
1086 afs_InitReq(&ureq, cred);
1087 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1088 ICL_TYPE_POINTER, tvc,
1089 ICL_TYPE_INT32, tvc->execsOrWriters);
1090 code = afs_StoreOnLastReference(tvc, &ureq);
1091 ReleaseWriteLock(&tvc->lock);
1092 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1093 afs_BozonUnlock(&tvc->pvnLock, tvc);
1095 hzero(tvc->flushDV);
1098 if (code && code != VNOVNODE) {
1099 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1100 /* /dev/console */ 1);
1102 } else if (tvc->states & CUnlinkedDel) {
1106 ReleaseWriteLock(&tvc->lock);
1107 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1108 afs_BozonUnlock(&tvc->pvnLock, tvc);
1110 #if defined(AFS_SGI_ENV)
1111 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1113 afs_remunlink(tvc, 0);
1114 #if defined(AFS_SGI_ENV)
1115 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1119 /* lost (or won, perhaps) the race condition */
1120 ReleaseWriteLock(&tvc->lock);
1121 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1122 afs_BozonUnlock(&tvc->pvnLock, tvc);
1125 #if defined(AFS_SGI_ENV)
1126 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1128 ObtainReadLock(&afs_xvcache);
1134 AFS_RELE((struct vnode *)tvc);
1136 /* Matches write code setting CCore flag */
1140 #ifdef AFS_DARWIN_ENV
1141 if (tvc->vrefCount == 1 && UBCINFOEXISTS(&tvc->v)) {
1142 if (tvc->opens) panic("flushactive open, hasubc, but refcnt 1");
1143 osi_VM_TryReclaim(tvc,0);
1148 ReleaseReadLock(&afs_xvcache);
1150 } /*afs_FlushActiveVcaches*/
1157 * Make sure a cache entry is up-to-date status-wise.
1159 * NOTE: everywhere that calls this can potentially be sped up
1160 * by checking CStatd first, and avoiding doing the InitReq
1161 * if this is up-to-date.
1163 * Anymore, the only places that call this KNOW already that the
1164 * vcache is not up-to-date, so we don't screw around.
1167 * avc : Ptr to vcache entry to verify.
1171 int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1173 register struct vcache *tvc;
1175 AFS_STATCNT(afs_VerifyVCache);
1177 #if defined(AFS_OSF_ENV)
1178 ObtainReadLock(&avc->lock);
1179 if (afs_IsWired(avc)) {
1180 ReleaseReadLock(&avc->lock);
1183 ReleaseReadLock(&avc->lock);
1184 #endif /* AFS_OSF_ENV */
1185 /* otherwise we must fetch the status info */
1187 ObtainWriteLock(&avc->lock,53);
1188 if (avc->states & CStatd) {
1189 ReleaseWriteLock(&avc->lock);
1192 ObtainWriteLock(&afs_xcbhash, 461);
1193 avc->states &= ~( CStatd | CUnique );
1194 avc->callback = (struct server *)0;
1195 afs_DequeueCallback(avc);
1196 ReleaseWriteLock(&afs_xcbhash);
1197 ReleaseWriteLock(&avc->lock);
1199 /* since we've been called back, or the callback has expired,
1200 * it's possible that the contents of this directory, or this
1201 * file's name have changed, thus invalidating the dnlc contents.
1203 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1204 osi_dnlc_purgedp (avc);
1206 osi_dnlc_purgevp (avc);
1208 /* fetch the status info */
1209 tvc = afs_GetVCache(&avc->fid, areq, (afs_int32*)0, avc, READ_LOCK);
1210 if (!tvc) return ENOENT;
1211 /* Put it back; caller has already incremented vrefCount */
1212 afs_PutVCache(tvc, READ_LOCK);
1215 } /*afs_VerifyVCache*/
1222 * Simple copy of stat info into cache.
1225 * avc : Ptr to vcache entry involved.
1226 * astat : Ptr to stat info to copy.
1229 * Nothing interesting.
1231 * Callers: as of 1992-04-29, only called by WriteVCache
1234 afs_SimpleVStat(avc, astat, areq)
1235 register struct vcache *avc;
1236 register struct AFSFetchStatus *astat;
1237 struct vrequest *areq;
1238 { /*afs_SimpleVStat*/
1240 AFS_STATCNT(afs_SimpleVStat);
1243 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1244 && !AFS_VN_MAPPED((vnode_t*)avc))
1246 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1250 #if defined(AFS_SGI_ENV)
1251 osi_Assert((valusema(&avc->vc_rwlock) <= 0) &&
1252 (OSI_GET_LOCKID() == avc->vc_rwlockid));
1253 if (astat->Length < avc->m.Length) {
1254 vnode_t *vp = (vnode_t *)avc;
1256 osi_Assert(WriteLocked(&avc->lock));
1257 ReleaseWriteLock(&avc->lock);
1259 PTOSSVP(vp, (off_t)astat->Length, (off_t)MAXLONG);
1261 ObtainWriteLock(&avc->lock,67);
1264 /* if writing the file, don't fetch over this value */
1265 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT,
1266 ICL_TYPE_POINTER, avc,
1267 ICL_TYPE_INT32, avc->m.Length,
1268 ICL_TYPE_INT32, astat->Length);
1269 avc->m.Length = astat->Length;
1270 avc->m.Date = astat->ClientModTime;
1272 avc->m.Owner = astat->Owner;
1273 avc->m.Group = astat->Group;
1274 avc->m.Mode = astat->UnixModeBits;
1275 if (vType(avc) == VREG) {
1276 avc->m.Mode |= S_IFREG;
1278 else if (vType(avc) == VDIR) {
1279 avc->m.Mode |= S_IFDIR;
1281 else if (vType(avc) == VLNK) {
1285 avc->m.Mode |= S_IFLNK;
1286 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1288 if (avc->states & CForeign) {
1289 struct axscache *ac;
1290 avc->anyAccess = astat->AnonymousAccess;
1292 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1294 * Caller has at least one bit not covered by anonymous, and
1295 * thus may have interesting rights.
1297 * HOWEVER, this is a really bad idea, because any access query
1298 * for bits which aren't covered by anonymous, on behalf of a user
1299 * who doesn't have any special rights, will result in an answer of
1300 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1301 * It's an especially bad idea under Ultrix, since (due to the lack of
1302 * a proper access() call) it must perform several afs_access() calls
1303 * in order to create magic mode bits that vary according to who makes
1304 * the call. In other words, _every_ stat() generates a test for
1307 #endif /* badidea */
1308 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1309 ac->axess = astat->CallerAccess;
1310 else /* not found, add a new one if possible */
1311 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1315 } /*afs_SimpleVStat*/
1322 * Store the status info *only* back to the server for a
1326 * avc : Ptr to the vcache entry.
1327 * astatus : Ptr to the status info to store.
1328 * areq : Ptr to the associated vrequest.
1331 * Must be called with a shared lock held on the vnode.
1334 afs_WriteVCache(avc, astatus, areq)
1335 register struct vcache *avc;
1336 register struct AFSStoreStatus *astatus;
1337 struct vrequest *areq;
1339 { /*afs_WriteVCache*/
1342 struct AFSFetchStatus OutStatus;
1343 struct AFSVolSync tsync;
1346 AFS_STATCNT(afs_WriteVCache);
1347 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1348 ICL_TYPE_INT32, avc->m.Length);
1351 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1353 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1354 #ifdef RX_ENABLE_LOCKS
1356 #endif /* RX_ENABLE_LOCKS */
1357 code = RXAFS_StoreStatus(tc->id,
1358 (struct AFSFid *) &avc->fid.Fid,
1359 astatus, &OutStatus, &tsync);
1360 #ifdef RX_ENABLE_LOCKS
1362 #endif /* RX_ENABLE_LOCKS */
1367 (afs_Analyze(tc, code, &avc->fid, areq,
1368 AFS_STATS_FS_RPCIDX_STORESTATUS,
1369 SHARED_LOCK, (struct cell *)0));
1371 UpgradeSToWLock(&avc->lock,20);
1373 /* success, do the changes locally */
1374 afs_SimpleVStat(avc, &OutStatus, areq);
1376 * Update the date, too. SimpleVStat didn't do this, since
1377 * it thought we were doing this after fetching new status
1378 * over a file being written.
1380 avc->m.Date = OutStatus.ClientModTime;
1383 /* failure, set up to check with server next time */
1384 ObtainWriteLock(&afs_xcbhash, 462);
1385 afs_DequeueCallback(avc);
1386 avc->states &= ~( CStatd | CUnique); /* turn off stat valid flag */
1387 ReleaseWriteLock(&afs_xcbhash);
1388 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1389 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
1391 ConvertWToSLock(&avc->lock);
1394 } /*afs_WriteVCache*/
1400 * Copy astat block into vcache info
1403 * avc : Ptr to vcache entry.
1404 * astat : Ptr to stat block to copy in.
1405 * areq : Ptr to associated request.
1408 * Must be called under a write lock
1410 * Note: this code may get dataversion and length out of sync if the file has
1411 * been modified. This is less than ideal. I haven't thought about
1412 * it sufficiently to be certain that it is adequate.
1415 afs_ProcessFS(avc, astat, areq)
1416 register struct vcache *avc;
1417 struct vrequest *areq;
1418 register struct AFSFetchStatus *astat;
1423 AFS_STATCNT(afs_ProcessFS);
1425 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1426 * number for each bulk status request. Under no circumstances
1427 * should afs_DoBulkStat store a sequence number if the new
1428 * length will be ignored when afs_ProcessFS is called with
1429 * new stats. If you change the following conditional then you
1430 * also need to change the conditional in afs_DoBulkStat. */
1432 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1433 && !AFS_VN_MAPPED((vnode_t*)avc))
1435 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1438 /* if we're writing or mapping this file, don't fetch over these
1441 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1442 ICL_TYPE_INT32, avc->m.Length,
1443 ICL_TYPE_INT32, astat->Length);
1444 avc->m.Length = astat->Length;
1445 avc->m.Date = astat->ClientModTime;
1447 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1448 avc->m.Owner = astat->Owner;
1449 avc->m.Mode = astat->UnixModeBits;
1450 avc->m.Group = astat->Group;
1451 avc->m.LinkCount = astat->LinkCount;
1452 if (astat->FileType == File) {
1453 vSetType(avc, VREG);
1454 avc->m.Mode |= S_IFREG;
1456 else if (astat->FileType == Directory) {
1457 vSetType(avc, VDIR);
1458 avc->m.Mode |= S_IFDIR;
1460 else if (astat->FileType == SymbolicLink) {
1461 vSetType(avc, VLNK);
1462 avc->m.Mode |= S_IFLNK;
1463 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1465 avc->anyAccess = astat->AnonymousAccess;
1467 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1469 * Caller has at least one bit not covered by anonymous, and
1470 * thus may have interesting rights.
1472 * HOWEVER, this is a really bad idea, because any access query
1473 * for bits which aren't covered by anonymous, on behalf of a user
1474 * who doesn't have any special rights, will result in an answer of
1475 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1476 * It's an especially bad idea under Ultrix, since (due to the lack of
1477 * a proper access() call) it must perform several afs_access() calls
1478 * in order to create magic mode bits that vary according to who makes
1479 * the call. In other words, _every_ stat() generates a test for
1482 #endif /* badidea */
1484 struct axscache *ac;
1485 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1486 ac->axess = astat->CallerAccess;
1487 else /* not found, add a new one if possible */
1488 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1491 #ifdef AFS_LINUX22_ENV
1492 vcache2inode(avc); /* Set the inode attr cache */
1498 afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp)
1499 register struct VenusFid *afid;
1500 struct vrequest *areq;
1502 struct VenusFid *nfid;
1503 struct AFSFetchStatus *OutStatusp;
1504 struct AFSCallBack *CallBackp;
1505 struct server **serverp;
1506 struct AFSVolSync *tsyncp;
1509 register struct vcache *tvc;
1512 register struct conn *tc;
1513 struct AFSFetchStatus OutDirStatus;
1516 if (!name) name = ""; /* XXX */
1518 tc = afs_Conn(afid, areq, SHARED_LOCK);
1520 if (serverp) *serverp = tc->srvr->server;
1522 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1523 #ifdef RX_ENABLE_LOCKS
1525 #endif /* RX_ENABLE_LOCKS */
1526 code = RXAFS_Lookup(tc->id, (struct AFSFid *) &afid->Fid, name,
1527 (struct AFSFid *) &nfid->Fid,
1528 OutStatusp, &OutDirStatus, CallBackp, tsyncp);
1529 #ifdef RX_ENABLE_LOCKS
1531 #endif /* RX_ENABLE_LOCKS */
1536 (afs_Analyze(tc, code, afid, areq,
1537 AFS_STATS_FS_RPCIDX_XLOOKUP,
1538 SHARED_LOCK, (struct cell *)0));
1548 * Given a file id and a vrequest structure, fetch the status
1549 * information associated with the file.
1553 * areq : Ptr to associated vrequest structure, specifying the
1554 * user whose authentication tokens will be used.
1555 * avc : caller may already have a vcache for this file, which is
1559 * The cache entry is returned with an increased vrefCount field.
1560 * The entry must be discarded by calling afs_PutVCache when you
1561 * are through using the pointer to the cache entry.
1563 * You should not hold any locks when calling this function, except
1564 * locks on other vcache entries. If you lock more than one vcache
1565 * entry simultaneously, you should lock them in this order:
1567 * 1. Lock all files first, then directories.
1568 * 2. Within a particular type, lock entries in Fid.Vnode order.
1570 * This locking hierarchy is convenient because it allows locking
1571 * of a parent dir cache entry, given a file (to check its access
1572 * control list). It also allows renames to be handled easily by
1573 * locking directories in a constant order.
1574 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1576 struct vcache *afs_GetVCache(afid, areq, cached, avc, locktype)
1577 register struct VenusFid *afid;
1578 struct vrequest *areq;
1581 struct vcache *avc; /* might have a vcache structure already, which must
1582 * already be held by the caller */
1585 afs_int32 code, i, newvcache=0;
1586 register struct vcache *tvc;
1590 AFS_STATCNT(afs_GetVCache);
1592 if (cached) *cached = 0; /* Init just in case */
1595 ObtainSharedLock(&afs_xvcache,5);
1597 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS | DO_VLRU );
1599 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1600 ReleaseSharedLock(&afs_xvcache);
1601 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1609 if (tvc->states & CStatd) {
1610 ReleaseSharedLock(&afs_xvcache);
1615 UpgradeSToWLock(&afs_xvcache,21);
1617 /* no cache entry, better grab one */
1618 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1621 ConvertWToSLock(&afs_xvcache);
1622 afs_stats_cmperf.vcacheMisses++;
1625 ReleaseSharedLock(&afs_xvcache);
1627 ObtainWriteLock(&tvc->lock,54);
1629 if (tvc->states & CStatd) {
1630 #ifdef AFS_LINUX22_ENV
1633 ReleaseWriteLock(&tvc->lock);
1634 #ifdef AFS_DARWIN_ENV
1640 #if defined(AFS_OSF_ENV)
1641 if (afs_IsWired(tvc)) {
1642 ReleaseWriteLock(&tvc->lock);
1645 #endif /* AFS_OSF_ENV */
1647 ObtainWriteLock(&afs_xcbhash, 464);
1648 tvc->states &= ~CUnique;
1650 afs_DequeueCallback(tvc);
1651 ReleaseWriteLock(&afs_xcbhash);
1653 /* It is always appropriate to throw away all the access rights? */
1654 afs_FreeAllAxs(&(tvc->Access));
1655 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1657 if ((tvp->states & VForeign)) {
1658 if (newvcache) tvc->states |= CForeign;
1659 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1660 && (tvp->rootUnique == afid->Fid.Unique)) {
1664 if (tvp->states & VRO) tvc->states |= CRO;
1665 if (tvp->states & VBackup) tvc->states |= CBackup;
1666 /* now copy ".." entry back out of volume structure, if necessary */
1667 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1669 tvc->mvid = (struct VenusFid *)
1670 osi_AllocSmallSpace(sizeof(struct VenusFid));
1671 *tvc->mvid = tvp->dotdot;
1673 afs_PutVolume(tvp, READ_LOCK);
1677 afs_RemoveVCB(afid);
1679 struct AFSFetchStatus OutStatus;
1680 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1684 ReleaseWriteLock(&tvc->lock);
1686 ObtainReadLock(&afs_xvcache);
1688 ReleaseReadLock(&afs_xvcache);
1689 return (struct vcache *) 0;
1692 ReleaseWriteLock(&tvc->lock);
1693 #ifdef AFS_DARWIN_ENV
1702 struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1703 afs_int32 *cached, afs_int32 locktype,
1704 struct vcache *adp, char *aname)
1706 afs_int32 code, now, newvcache=0, hash;
1707 struct VenusFid nfid;
1708 register struct vcache *tvc;
1710 struct AFSFetchStatus OutStatus;
1711 struct AFSCallBack CallBack;
1712 struct AFSVolSync tsync;
1713 struct server *serverp = 0;
1717 AFS_STATCNT(afs_GetVCache);
1718 if (cached) *cached = 0; /* Init just in case */
1721 ObtainReadLock(&afs_xvcache);
1722 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS /* no vlru */);
1725 ReleaseReadLock(&afs_xvcache);
1727 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1728 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1732 ObtainReadLock(&tvc->lock);
1734 if (tvc->states & CStatd) {
1738 ReleaseReadLock(&tvc->lock);
1741 tvc->states &= ~CUnique;
1743 ReleaseReadLock(&tvc->lock);
1744 ObtainReadLock(&afs_xvcache);
1748 ReleaseReadLock(&afs_xvcache);
1750 /* lookup the file */
1753 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1754 code = afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1758 ObtainSharedLock(&afs_xvcache,6);
1759 tvc = afs_FindVCache(&nfid, 0, 0, &retry, DO_VLRU /* no xstats now*/);
1761 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1762 ReleaseSharedLock(&afs_xvcache);
1763 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1769 /* no cache entry, better grab one */
1770 UpgradeSToWLock(&afs_xvcache,22);
1771 tvc = afs_NewVCache(&nfid, (struct server *)0, 1, WRITE_LOCK);
1773 ConvertWToSLock(&afs_xvcache);
1776 ReleaseSharedLock(&afs_xvcache);
1777 ObtainWriteLock(&tvc->lock,55);
1779 /* It is always appropriate to throw away all the access rights? */
1780 afs_FreeAllAxs(&(tvc->Access));
1781 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1783 if ((tvp->states & VForeign)) {
1784 if (newvcache) tvc->states |= CForeign;
1785 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1786 && (tvp->rootUnique == afid->Fid.Unique))
1789 if (tvp->states & VRO) tvc->states |= CRO;
1790 if (tvp->states & VBackup) tvc->states |= CBackup;
1791 /* now copy ".." entry back out of volume structure, if necessary */
1792 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1794 tvc->mvid = (struct VenusFid *)
1795 osi_AllocSmallSpace(sizeof(struct VenusFid));
1796 *tvc->mvid = tvp->dotdot;
1801 ObtainWriteLock(&afs_xcbhash, 465);
1802 afs_DequeueCallback(tvc);
1803 tvc->states &= ~( CStatd | CUnique );
1804 ReleaseWriteLock(&afs_xcbhash);
1805 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1806 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1808 afs_PutVolume(tvp, READ_LOCK);
1809 ReleaseWriteLock(&tvc->lock);
1810 ObtainReadLock(&afs_xvcache);
1812 ReleaseReadLock(&afs_xvcache);
1813 return (struct vcache *) 0;
1816 ObtainWriteLock(&afs_xcbhash, 466);
1817 if (origCBs == afs_allCBs) {
1818 if (CallBack.ExpirationTime) {
1819 tvc->callback = serverp;
1820 tvc->cbExpires = CallBack.ExpirationTime+now;
1821 tvc->states |= CStatd | CUnique;
1822 tvc->states &= ~CBulkFetching;
1823 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1824 } else if (tvc->states & CRO) {
1825 /* adapt gives us an hour. */
1826 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
1827 tvc->states |= CStatd | CUnique;
1828 tvc->states &= ~CBulkFetching;
1829 afs_QueueCallback(tvc, CBHash(3600), tvp);
1831 tvc->callback = (struct server *)0;
1832 afs_DequeueCallback(tvc);
1833 tvc->states &= ~(CStatd | CUnique);
1834 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1835 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1838 afs_DequeueCallback(tvc);
1839 tvc->states &= ~CStatd;
1840 tvc->states &= ~CUnique;
1841 tvc->callback = (struct server *)0;
1842 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1843 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1845 ReleaseWriteLock(&afs_xcbhash);
1847 afs_PutVolume(tvp, READ_LOCK);
1848 afs_ProcessFS(tvc, &OutStatus, areq);
1850 ReleaseWriteLock(&tvc->lock);
1851 #ifdef AFS_DARWIN_ENV
1858 struct vcache *afs_GetRootVCache(struct VenusFid *afid,
1859 struct vrequest *areq, afs_int32 *cached,
1860 struct volume *tvolp, afs_int32 locktype)
1862 afs_int32 code, i, newvcache = 0, haveStatus = 0;
1863 afs_int32 getNewFid = 0;
1865 struct VenusFid nfid;
1866 register struct vcache *tvc;
1867 struct server *serverp = 0;
1868 struct AFSFetchStatus OutStatus;
1869 struct AFSCallBack CallBack;
1870 struct AFSVolSync tsync;
1876 if (!tvolp->rootVnode || getNewFid) {
1877 struct VenusFid tfid;
1880 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1881 origCBs = afs_allCBs; /* ignore InitCallBackState */
1882 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid,
1883 &OutStatus, &CallBack, &serverp, &tsync);
1885 return (struct vcache *)0;
1887 /* ReleaseReadLock(&tvolp->lock); */
1888 ObtainWriteLock(&tvolp->lock,56);
1889 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
1890 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
1891 ReleaseWriteLock(&tvolp->lock);
1892 /* ObtainReadLock(&tvolp->lock);*/
1895 afid->Fid.Vnode = tvolp->rootVnode;
1896 afid->Fid.Unique = tvolp->rootUnique;
1899 ObtainSharedLock(&afs_xvcache,7);
1901 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1902 if (!FidCmp(&(tvc->fid), afid)) {
1904 /* Grab this vnode, possibly reactivating from the free list */
1905 /* for the present (95.05.25) everything on the hash table is
1906 * definitively NOT in the free list -- at least until afs_reclaim
1907 * can be safely implemented */
1910 vg = vget((struct vnode *)tvc); /* this bumps ref count */
1914 #endif /* AFS_OSF_ENV */
1919 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
1920 /* Mount point no longer stat'd or unknown. FID may have changed. */
1925 tvc = (struct vcache*)0;
1927 ReleaseSharedLock(&afs_xvcache);
1932 UpgradeSToWLock(&afs_xvcache,23);
1933 /* no cache entry, better grab one */
1934 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1936 afs_stats_cmperf.vcacheMisses++;
1939 if (cached) *cached = 1;
1940 afs_stats_cmperf.vcacheHits++;
1942 /* we already bumped the ref count in the for loop above */
1943 #else /* AFS_OSF_ENV */
1946 UpgradeSToWLock(&afs_xvcache,24);
1947 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1948 refpanic ("GRVC VLRU inconsistent0");
1950 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1951 refpanic ("GRVC VLRU inconsistent1");
1953 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1954 refpanic ("GRVC VLRU inconsistent2");
1956 QRemove(&tvc->vlruq); /* move to lruq head */
1957 QAdd(&VLRU, &tvc->vlruq);
1958 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1959 refpanic ("GRVC VLRU inconsistent3");
1961 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1962 refpanic ("GRVC VLRU inconsistent4");
1964 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1965 refpanic ("GRVC VLRU inconsistent5");
1970 ReleaseWriteLock(&afs_xvcache);
1972 if (tvc->states & CStatd) {
1976 ObtainReadLock(&tvc->lock);
1977 tvc->states &= ~CUnique;
1978 tvc->callback = (struct server *)0; /* redundant, perhaps */
1979 ReleaseReadLock(&tvc->lock);
1982 ObtainWriteLock(&tvc->lock,57);
1984 /* It is always appropriate to throw away all the access rights? */
1985 afs_FreeAllAxs(&(tvc->Access));
1987 if (newvcache) tvc->states |= CForeign;
1988 if (tvolp->states & VRO) tvc->states |= CRO;
1989 if (tvolp->states & VBackup) tvc->states |= CBackup;
1990 /* now copy ".." entry back out of volume structure, if necessary */
1991 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
1992 && (tvolp->rootUnique == afid->Fid.Unique)) {
1995 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
1997 tvc->mvid = (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid));
1998 *tvc->mvid = tvolp->dotdot;
2002 afs_RemoveVCB(afid);
2005 struct VenusFid tfid;
2008 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2009 origCBs = afs_allCBs; /* ignore InitCallBackState */
2010 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid, &OutStatus,
2011 &CallBack, &serverp, &tsync);
2015 ObtainWriteLock(&afs_xcbhash, 467);
2016 afs_DequeueCallback(tvc);
2017 tvc->callback = (struct server *)0;
2018 tvc->states &= ~(CStatd|CUnique);
2019 ReleaseWriteLock(&afs_xcbhash);
2020 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2021 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2022 ReleaseWriteLock(&tvc->lock);
2023 ObtainReadLock(&afs_xvcache);
2025 ReleaseReadLock(&afs_xvcache);
2026 return (struct vcache *) 0;
2029 ObtainWriteLock(&afs_xcbhash, 468);
2030 if (origCBs == afs_allCBs) {
2031 tvc->states |= CTruth;
2032 tvc->callback = serverp;
2033 if (CallBack.ExpirationTime != 0) {
2034 tvc->cbExpires = CallBack.ExpirationTime+start;
2035 tvc->states |= CStatd;
2036 tvc->states &= ~CBulkFetching;
2037 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2038 } else if (tvc->states & CRO) {
2039 /* adapt gives us an hour. */
2040 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2041 tvc->states |= CStatd;
2042 tvc->states &= ~CBulkFetching;
2043 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2046 afs_DequeueCallback(tvc);
2047 tvc->callback = (struct server *)0;
2048 tvc->states &= ~(CStatd | CUnique);
2049 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2050 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2052 ReleaseWriteLock(&afs_xcbhash);
2053 afs_ProcessFS(tvc, &OutStatus, areq);
2055 ReleaseWriteLock(&tvc->lock);
2062 * must be called with avc write-locked
2063 * don't absolutely have to invalidate the hint unless the dv has
2064 * changed, but be sure to get it right else there will be consistency bugs.
2066 afs_int32 afs_FetchStatus(struct vcache *avc, struct VenusFid *afid,
2067 struct vrequest *areq, struct AFSFetchStatus *Outsp)
2071 register struct conn *tc;
2072 struct AFSCallBack CallBack;
2073 struct AFSVolSync tsync;
2074 struct volume* volp;
2078 tc = afs_Conn(afid, areq, SHARED_LOCK);
2079 avc->quick.stamp = 0; avc->h1.dchint = NULL; /* invalidate hints */
2081 avc->callback = tc->srvr->server;
2083 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2084 #ifdef RX_ENABLE_LOCKS
2086 #endif /* RX_ENABLE_LOCKS */
2087 code = RXAFS_FetchStatus(tc->id,
2088 (struct AFSFid *) &afid->Fid,
2089 Outsp, &CallBack, &tsync);
2090 #ifdef RX_ENABLE_LOCKS
2092 #endif /* RX_ENABLE_LOCKS */
2099 (afs_Analyze(tc, code, afid, areq,
2100 AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2101 SHARED_LOCK, (struct cell *)0));
2104 afs_ProcessFS(avc, Outsp, areq);
2105 volp = afs_GetVolume(afid, areq, READ_LOCK);
2106 ObtainWriteLock(&afs_xcbhash, 469);
2107 avc->states |= CTruth;
2108 if (avc->callback /* check for race */) {
2109 if (CallBack.ExpirationTime != 0) {
2110 avc->cbExpires = CallBack.ExpirationTime+start;
2111 avc->states |= CStatd;
2112 avc->states &= ~CBulkFetching;
2113 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2115 else if (avc->states & CRO)
2116 { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2117 avc->cbExpires = 3600+start;
2118 avc->states |= CStatd;
2119 avc->states &= ~CBulkFetching;
2120 afs_QueueCallback(avc, CBHash(3600), volp);
2123 afs_DequeueCallback(avc);
2124 avc->callback = (struct server *)0;
2125 avc->states &= ~(CStatd|CUnique);
2126 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2127 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2131 afs_DequeueCallback(avc);
2132 avc->callback = (struct server *)0;
2133 avc->states &= ~(CStatd|CUnique);
2134 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2135 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2137 ReleaseWriteLock(&afs_xcbhash);
2139 afs_PutVolume(volp, READ_LOCK);
2141 else { /* used to undo the local callback, but that's too extreme.
2142 * There are plenty of good reasons that fetchstatus might return
2143 * an error, such as EPERM. If we have the vnode cached, statd,
2144 * with callback, might as well keep track of the fact that we
2145 * don't have access...
2147 if (code == EPERM || code == EACCES) {
2148 struct axscache *ac;
2149 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2151 else /* not found, add a new one if possible */
2152 afs_AddAxs(avc->Access, areq->uid, 0);
2163 * Stuff some information into the vcache for the given file.
2166 * afid : File in question.
2167 * OutStatus : Fetch status on the file.
2168 * CallBack : Callback info.
2169 * tc : RPC connection involved.
2170 * areq : vrequest involved.
2173 * Nothing interesting.
2176 afs_StuffVcache(afid, OutStatus, CallBack, tc, areq)
2177 register struct VenusFid *afid;
2178 struct AFSFetchStatus *OutStatus;
2179 struct AFSCallBack *CallBack;
2180 register struct conn *tc;
2181 struct vrequest *areq;
2183 { /*afs_StuffVcache*/
2185 register afs_int32 code, i, newvcache=0;
2186 register struct vcache *tvc;
2187 struct AFSVolSync tsync;
2189 struct axscache *ac;
2192 AFS_STATCNT(afs_StuffVcache);
2193 #ifdef IFS_VCACHECOUNT
2198 ObtainSharedLock(&afs_xvcache,8);
2200 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_VLRU /* no stats */);
2202 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2203 ReleaseSharedLock(&afs_xvcache);
2204 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2210 /* no cache entry, better grab one */
2211 UpgradeSToWLock(&afs_xvcache,25);
2212 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
2214 ConvertWToSLock(&afs_xvcache);
2217 ReleaseSharedLock(&afs_xvcache);
2218 ObtainWriteLock(&tvc->lock,58);
2220 tvc->states &= ~CStatd;
2221 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2222 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2224 /* Is it always appropriate to throw away all the access rights? */
2225 afs_FreeAllAxs(&(tvc->Access));
2227 /*Copy useful per-volume info*/
2228 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2230 if (newvcache && (tvp->states & VForeign)) tvc->states |= CForeign;
2231 if (tvp->states & VRO) tvc->states |= CRO;
2232 if (tvp->states & VBackup) tvc->states |= CBackup;
2234 * Now, copy ".." entry back out of volume structure, if
2237 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2238 if (!tvc->mvid) tvc->mvid =
2239 (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid));
2240 *tvc->mvid = tvp->dotdot;
2243 /* store the stat on the file */
2244 afs_RemoveVCB(afid);
2245 afs_ProcessFS(tvc, OutStatus, areq);
2246 tvc->callback = tc->srvr->server;
2248 /* we use osi_Time twice below. Ideally, we would use the time at which
2249 * the FetchStatus call began, instead, but we don't have it here. So we
2250 * make do with "now". In the CRO case, it doesn't really matter. In
2251 * the other case, we hope that the difference between "now" and when the
2252 * call actually began execution on the server won't be larger than the
2253 * padding which the server keeps. Subtract 1 second anyway, to be on
2254 * the safe side. Can't subtract more because we don't know how big
2255 * ExpirationTime is. Possible consistency problems may arise if the call
2256 * timeout period becomes longer than the server's expiration padding. */
2257 ObtainWriteLock(&afs_xcbhash, 470);
2258 if (CallBack->ExpirationTime != 0) {
2259 tvc->cbExpires = CallBack->ExpirationTime+osi_Time()-1;
2260 tvc->states |= CStatd;
2261 tvc->states &= ~CBulkFetching;
2262 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2264 else if (tvc->states & CRO) {
2265 /* old-fashioned AFS 3.2 style */
2266 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2267 tvc->states |= CStatd;
2268 tvc->states &= ~CBulkFetching;
2269 afs_QueueCallback(tvc, CBHash(3600), tvp);
2272 afs_DequeueCallback(tvc);
2273 tvc->callback = (struct server *)0;
2274 tvc->states &= ~(CStatd|CUnique);
2275 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2276 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2278 ReleaseWriteLock(&afs_xcbhash);
2280 afs_PutVolume(tvp, READ_LOCK);
2282 /* look in per-pag cache */
2283 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2284 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2285 else /* not found, add a new one if possible */
2286 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2288 ReleaseWriteLock(&tvc->lock);
2289 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2290 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32, tvc->cbExpires,
2291 ICL_TYPE_INT32, tvc->cbExpires-osi_Time());
2293 * Release ref count... hope this guy stays around...
2295 afs_PutVCache(tvc, WRITE_LOCK);
2296 } /*afs_StuffVcache*/
2303 * Decrements the reference count on a cache entry.
2306 * avc : Pointer to the cache entry to decrement.
2309 * Nothing interesting.
2312 afs_PutVCache(avc, locktype)
2313 register struct vcache *avc;
2317 AFS_STATCNT(afs_PutVCache);
2319 * Can we use a read lock here?
2321 ObtainReadLock(&afs_xvcache);
2323 ReleaseReadLock(&afs_xvcache);
2330 * Find a vcache entry given a fid.
2333 * afid : Pointer to the fid whose cache entry we desire.
2334 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2335 * unlock the vnode, and try again.
2336 * flags: bit 1 to specify whether to compute hit statistics. Not
2337 * set if FindVCache is called as part of internal bookkeeping.
2340 * Must be called with the afs_xvcache lock at least held at
2341 * the read level. In order to do the VLRU adjustment, the xvcache lock
2342 * must be shared-- we upgrade it here.
2345 struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit,
2346 afs_int32 locktype, afs_int32 *retry, afs_int32 flag)
2349 register struct vcache *tvc;
2352 AFS_STATCNT(afs_FindVCache);
2355 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2356 if (FidMatches(afid, tvc)) {
2358 /* Grab this vnode, possibly reactivating from the free list */
2361 vg = vget((struct vnode *)tvc);
2365 #endif /* AFS_OSF_ENV */
2370 /* should I have a read lock on the vnode here? */
2372 if (retry) *retry = 0;
2373 #if !defined(AFS_OSF_ENV)
2374 osi_vnhold(tvc, retry); /* already held, above */
2375 if (retry && *retry)
2379 * only move to front of vlru if we have proper vcache locking)
2381 if (flag & DO_VLRU) {
2382 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2383 refpanic ("FindVC VLRU inconsistent1");
2385 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2386 refpanic ("FindVC VLRU inconsistent1");
2388 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2389 refpanic ("FindVC VLRU inconsistent2");
2391 UpgradeSToWLock(&afs_xvcache,26);
2392 QRemove(&tvc->vlruq);
2393 QAdd(&VLRU, &tvc->vlruq);
2394 ConvertWToSLock(&afs_xvcache);
2395 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2396 refpanic ("FindVC VLRU inconsistent1");
2398 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2399 refpanic ("FindVC VLRU inconsistent2");
2401 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2402 refpanic ("FindVC VLRU inconsistent3");
2408 if (flag & DO_STATS) {
2409 if (tvc) afs_stats_cmperf.vcacheHits++;
2410 else afs_stats_cmperf.vcacheMisses++;
2411 if (afid->Cell == LOCALCELL)
2412 afs_stats_cmperf.vlocalAccesses++;
2414 afs_stats_cmperf.vremoteAccesses++;
2417 #ifdef AFS_LINUX22_ENV
2418 if (tvc && (tvc->states & CStatd))
2419 vcache2inode(tvc); /* mainly to reset i_nlink */
2421 #ifdef AFS_DARWIN_ENV
2426 } /*afs_FindVCache*/
2432 * Find a vcache entry given a fid. Does a wildcard match on what we
2433 * have for the fid. If more than one entry, don't return anything.
2436 * avcp : Fill in pointer if we found one and only one.
2437 * afid : Pointer to the fid whose cache entry we desire.
2438 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2439 * unlock the vnode, and try again.
2440 * flags: bit 1 to specify whether to compute hit statistics. Not
2441 * set if FindVCache is called as part of internal bookkeeping.
2444 * Must be called with the afs_xvcache lock at least held at
2445 * the read level. In order to do the VLRU adjustment, the xvcache lock
2446 * must be shared-- we upgrade it here.
2449 * number of matches found.
2452 int afs_duplicate_nfs_fids=0;
2454 afs_int32 afs_NFSFindVCache(avcp, afid, lockit)
2455 struct vcache **avcp;
2456 struct VenusFid *afid;
2458 { /*afs_FindVCache*/
2460 register struct vcache *tvc;
2462 afs_int32 retry = 0;
2463 afs_int32 count = 0;
2464 struct vcache *found_tvc = NULL;
2466 AFS_STATCNT(afs_FindVCache);
2470 ObtainSharedLock(&afs_xvcache,331);
2473 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2474 /* Match only on what we have.... */
2475 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2476 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2477 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2478 && (tvc->fid.Cell == afid->Cell)) {
2480 /* Grab this vnode, possibly reactivating from the free list */
2483 vg = vget((struct vnode *)tvc);
2486 /* This vnode no longer exists. */
2489 #endif /* AFS_OSF_ENV */
2494 /* Drop our reference counts. */
2495 vrele((struct vnode *)tvc);
2496 vrele((struct vnode *)found_tvc);
2498 afs_duplicate_nfs_fids++;
2499 ReleaseSharedLock(&afs_xvcache);
2507 /* should I have a read lock on the vnode here? */
2509 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2510 osi_vnhold(tvc, &retry);
2513 found_tvc = (struct vcache*)0;
2514 ReleaseSharedLock(&afs_xvcache);
2515 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2519 #if !defined(AFS_OSF_ENV)
2520 osi_vnhold(tvc, (int*)0); /* already held, above */
2524 * We obtained the xvcache lock above.
2526 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2527 refpanic ("FindVC VLRU inconsistent1");
2529 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2530 refpanic ("FindVC VLRU inconsistent1");
2532 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2533 refpanic ("FindVC VLRU inconsistent2");
2535 UpgradeSToWLock(&afs_xvcache,568);
2536 QRemove(&tvc->vlruq);
2537 QAdd(&VLRU, &tvc->vlruq);
2538 ConvertWToSLock(&afs_xvcache);
2539 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2540 refpanic ("FindVC VLRU inconsistent1");
2542 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2543 refpanic ("FindVC VLRU inconsistent2");
2545 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2546 refpanic ("FindVC VLRU inconsistent3");
2551 if (tvc) afs_stats_cmperf.vcacheHits++;
2552 else afs_stats_cmperf.vcacheMisses++;
2553 if (afid->Cell == LOCALCELL)
2554 afs_stats_cmperf.vlocalAccesses++;
2556 afs_stats_cmperf.vremoteAccesses++;
2558 *avcp = tvc; /* May be null */
2560 ReleaseSharedLock(&afs_xvcache);
2561 return (tvc ? 1 : 0);
2563 } /*afs_NFSFindVCache*/
2571 * Initialize vcache related variables
2573 void afs_vcacheInit(int astatSize)
2575 register struct vcache *tvp;
2577 #if defined(AFS_OSF_ENV)
2578 if (!afs_maxvcount) {
2579 #if defined(AFS_OSF30_ENV)
2580 afs_maxvcount = max_vnodes/2; /* limit ourselves to half the total */
2582 afs_maxvcount = nvnode/2; /* limit ourselves to half the total */
2584 if (astatSize < afs_maxvcount) {
2585 afs_maxvcount = astatSize;
2588 #else /* AFS_OSF_ENV */
2589 freeVCList = (struct vcache *)0;
2592 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2593 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2595 #if !defined(AFS_OSF_ENV)
2596 /* Allocate and thread the struct vcache entries */
2597 tvp = (struct vcache *) afs_osi_Alloc(astatSize * sizeof(struct vcache));
2598 bzero((char *)tvp, sizeof(struct vcache)*astatSize);
2600 Initial_freeVCList = tvp;
2601 freeVCList = &(tvp[0]);
2602 for(i=0; i < astatSize-1; i++) {
2603 tvp[i].nextfree = &(tvp[i+1]);
2605 tvp[astatSize-1].nextfree = (struct vcache *) 0;
2606 #ifdef AFS_AIX32_ENV
2607 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2612 #if defined(AFS_SGI_ENV)
2613 for(i=0; i < astatSize; i++) {
2614 char name[METER_NAMSZ];
2615 struct vcache *tvc = &tvp[i];
2617 tvc->v.v_number = ++afsvnumbers;
2618 tvc->vc_rwlockid = OSI_NO_LOCKID;
2619 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
2620 #ifndef AFS_SGI53_ENV
2621 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2623 #ifndef AFS_SGI62_ENV
2624 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2625 #endif /* AFS_SGI62_ENV */
2638 void shutdown_vcache(void)
2641 struct afs_cbr *tsp, *nsp;
2643 * XXX We may potentially miss some of the vcaches because if when there're no
2644 * free vcache entries and all the vcache entries are active ones then we allocate
2645 * an additional one - admittedly we almost never had that occur.
2647 #if !defined(AFS_OSF_ENV)
2648 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2650 #ifdef AFS_AIX32_ENV
2651 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2655 register struct afs_q *tq, *uq;
2656 register struct vcache *tvc;
2657 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2661 osi_FreeSmallSpace(tvc->mvid);
2662 tvc->mvid = (struct VenusFid*)0;
2665 aix_gnode_rele((struct vnode *)tvc);
2667 if (tvc->linkData) {
2668 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2673 * Also free the remaining ones in the Cache
2675 for (i=0; i < VCSIZE; i++) {
2676 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2678 osi_FreeSmallSpace(tvc->mvid);
2679 tvc->mvid = (struct VenusFid*)0;
2683 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2684 #ifdef AFS_AIX32_ENV
2687 vms_delete(tvc->segid);
2689 tvc->segid = tvc->vmh = NULL;
2690 if (tvc->vrefCount) osi_Panic("flushVcache: vm race");
2698 #if defined(AFS_SUN5_ENV)
2704 if (tvc->linkData) {
2705 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2709 afs_FreeAllAxs(&(tvc->Access));
2715 * Free any leftover callback queue
2717 for (tsp = afs_cbrSpace; tsp; tsp = nsp ) {
2719 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2723 #if !defined(AFS_OSF_ENV)
2724 freeVCList = Initial_freeVCList = 0;
2726 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2727 LOCK_INIT(&afs_xvcb, "afs_xvcb");