2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
19 * afs_FlushActiveVcaches
38 #include <afsconfig.h>
39 #include "../afs/param.h"
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 (VREFCOUNT(avc) > 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); /* 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);
528 #if defined(AFS_LINUX22_ENV)
529 /* afs_TryFlushDcacheChildren -- Shakes loose vcache references held by
530 * children of the dentry
531 * LOCKS -- Called with afs_xvcache write locked. Drops and reaquires
532 * AFS_GLOCK, so it can call dput, which may call iput, but
533 * keeps afs_xvcache exclusively.
535 * Tree traversal algorithm from fs/dcache.c: select_parent()
537 static void afs_TryFlushDcacheChildren(struct dentry *parent)
539 struct dentry *this_parent = parent;
540 struct list_head *next;
543 next = this_parent->d_subdirs.next;
545 while (next != &this_parent->d_subdirs) {
546 struct list_head *tmp = next;
547 struct dentry *dentry = list_entry(tmp, struct dentry, d_child);
550 if (!DCOUNT(dentry) && !dentry->d_inode) {
562 * Descend a level if the d_subdirs list is non-empty.
564 if (!list_empty(&dentry->d_subdirs)) {
565 this_parent = dentry;
571 * All done at this level ... ascend and resume the search.
573 if (this_parent != parent) {
574 next = this_parent->d_child.next;
575 this_parent = this_parent->d_parent;
580 /* afs_TryFlushDcache -- Shakes loose vcache references held by the Linux
583 * LOCKS -- Called with afs_xvcache write locked. Drops and reaquires
584 * AFS_GLOCK, so it can call dput, which may call iput, but
585 * keeps afs_xvcache exclusively.
587 static void afs_TryFlushDcache(struct vcache *vcp)
589 struct inode *ip = (struct inode *) vcp;
593 if (!list_empty(&ip->i_dentry)) {
594 struct list_head *cur, *head = &ip->i_dentry;
596 while ((cur = cur->next) != head) {
597 struct dentry *dentry = list_entry(cur, struct dentry, d_alias);
599 if (DCOUNT(dentry)) {
600 afs_TryFlushDcacheChildren(dentry);
603 if (!DCOUNT(dentry)) {
623 * This routine is responsible for allocating a new cache entry
624 * from the free list. It formats the cache entry and inserts it
625 * into the appropriate hash tables. It must be called with
626 * afs_xvcache write-locked so as to prevent several processes from
627 * trying to create a new cache entry simultaneously.
630 * afid : The file id of the file whose cache entry is being
633 /* LOCK: afs_NewVCache afs_xvcache W */
634 struct vcache *afs_NewVCache(struct VenusFid *afid, struct server *serverp,
635 afs_int32 lockit, afs_int32 locktype)
639 afs_int32 anumber = VCACHE_FREE;
641 struct gnode *gnodepnt;
644 struct vm_info * vm_info_ptr;
645 #endif /* AFS_MACH_ENV */
648 #endif /* AFS_OSF_ENV */
649 struct afs_q *tq, *uq;
652 AFS_STATCNT(afs_NewVCache);
655 if (afs_vcount >= afs_maxvcount)
658 * If we are using > 33 % of the total system vnodes for AFS vcache
659 * entries or we are using the maximum number of vcache entries,
660 * then free some. (if our usage is > 33% we should free some, if
661 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
662 * we _must_ free some -- no choice).
664 if ( (( 3 * afs_vcount ) > nvnode) || ( afs_vcount >= afs_maxvcount ))
667 struct afs_q *tq, *uq;
668 int i; char *panicstr;
671 for(tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
674 if (tvc->states & CVFlushed)
675 refpanic ("CVFlushed on VLRU");
676 else if (i++ > afs_maxvcount)
677 refpanic ("Exceeded pool of AFS vnodes(VLRU cycle?)");
678 else if (QNext(uq) != tq)
679 refpanic ("VLRU inconsistent");
680 else if (VREFCOUNT(tvc) < 1)
681 refpanic ("refcnt 0 on VLRU");
683 if ( VREFCOUNT(tvc) == 1 && tvc->opens == 0
684 && (tvc->states & CUnlinkedDel) == 0) {
685 code = afs_FlushVCache(tvc, &fv_slept);
692 continue; /* start over - may have raced. */
697 if (anumber == VCACHE_FREE) {
698 printf("NewVCache: warning none freed, using %d of %d\n",
699 afs_vcount, afs_maxvcount);
700 if (afs_vcount >= afs_maxvcount) {
701 osi_Panic("NewVCache - none freed");
702 /* XXX instead of panicing, should do afs_maxvcount++
703 and magic up another one */
709 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
710 /* What should we do ???? */
711 osi_Panic("afs_NewVCache: no more vnodes");
716 tvc->nextfree = (struct vcache *)0;
718 #else /* AFS_OSF_ENV */
719 /* pull out a free cache entry */
722 for(tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
726 if (tvc->states & CVFlushed)
727 refpanic("CVFlushed on VLRU");
728 else if (i++ > 2*afs_cacheStats) /* even allowing for a few xallocs...*/
729 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
730 else if (QNext(uq) != tq)
731 refpanic("VLRU inconsistent");
733 #ifdef AFS_DARWIN_ENV
734 if (tvc->opens == 0 && ((tvc->states & CUnlinkedDel) == 0) &&
735 VREFCOUNT(tvc) == 1 && UBCINFOEXISTS(&tvc->v)) {
736 osi_VM_TryReclaim(tvc, &fv_slept);
740 continue; /* start over - may have raced. */
744 #if defined(AFS_LINUX22_ENV)
745 if (tvc != afs_globalVp && VREFCOUNT(tvc) && tvc->opens == 0)
746 afs_TryFlushDcache(tvc);
748 if (VREFCOUNT(tvc) == 0 && tvc->opens == 0
749 && (tvc->states & CUnlinkedDel) == 0) {
750 code = afs_FlushVCache(tvc, &fv_slept);
757 continue; /* start over - may have raced. */
760 if (tq == uq ) break;
764 /* none free, making one is better than a panic */
765 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
766 tvc = (struct vcache *) afs_osi_Alloc(sizeof (struct vcache));
768 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
771 /* In case it still comes here we need to fill this */
772 tvc->v.v_vm_info = VM_INFO_NULL;
773 vm_info_init(tvc->v.v_vm_info);
774 /* perhaps we should also do close_flush on non-NeXT mach systems;
775 * who knows; we don't currently have the sources.
777 #endif /* AFS_MACH_ENV */
778 #if defined(AFS_SGI_ENV)
779 { char name[METER_NAMSZ];
780 memset(tvc, 0, sizeof(struct vcache));
781 tvc->v.v_number = ++afsvnumbers;
782 tvc->vc_rwlockid = OSI_NO_LOCKID;
783 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
784 #ifndef AFS_SGI53_ENV
785 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
787 #ifndef AFS_SGI62_ENV
788 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
791 #endif /* AFS_SGI_ENV */
794 tvc = freeVCList; /* take from free list */
795 freeVCList = tvc->nextfree;
796 tvc->nextfree = (struct vcache *)0;
798 #endif /* AFS_OSF_ENV */
801 vm_info_ptr = tvc->v.v_vm_info;
802 #endif /* AFS_MACH_ENV */
804 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
805 memset((char *)tvc, 0, sizeof(struct vcache));
810 RWLOCK_INIT(&tvc->lock, "vcache lock");
811 #if defined(AFS_SUN5_ENV)
812 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
813 #endif /* defined(AFS_SUN5_ENV) */
816 tvc->v.v_vm_info = vm_info_ptr;
817 tvc->v.v_vm_info->pager = MEMORY_OBJECT_NULL;
818 #endif /* AFS_MACH_ENV */
819 tvc->parentVnode = 0;
820 tvc->mvid = (struct VenusFid *) 0;
821 tvc->linkData = (char *) 0;
824 tvc->execsOrWriters = 0;
828 tvc->last_looker = 0;
830 tvc->asynchrony = -1;
832 afs_symhint_inval(tvc);
834 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
837 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
838 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
840 /* Hold it for the LRU (should make count 2) */
841 VN_HOLD((struct vnode *)tvc);
842 #else /* AFS_OSF_ENV */
843 VREFCOUNT_SET(tvc, 1); /* us */
844 #endif /* AFS_OSF_ENV */
846 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
847 tvc->vmh = tvc->segid = NULL;
850 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV) || defined(AFS_SUN5_ENV)
851 #if defined(AFS_SUN5_ENV)
852 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
854 #if defined(AFS_SUN55_ENV)
855 /* This is required if the kaio (kernel aynchronous io)
856 ** module is installed. Inside the kernel, the function
857 ** check_vp( common/os/aio.c) checks to see if the kernel has
858 ** to provide asynchronous io for this vnode. This
859 ** function extracts the device number by following the
860 ** v_data field of the vnode. If we do not set this field
861 ** then the system panics. The value of the v_data field
862 ** is not really important for AFS vnodes because the kernel
863 ** does not do asynchronous io for regular files. Hence,
864 ** for the time being, we fill up the v_data field with the
865 ** vnode pointer itself. */
866 tvc->v.v_data = (char *)tvc;
867 #endif /* AFS_SUN55_ENV */
869 afs_BozonInit(&tvc->pvnLock, tvc);
873 tvc->callback = serverp; /* to minimize chance that clear
875 /* initialize vnode data, note vrefCount is v.v_count */
877 /* Don't forget to free the gnode space */
878 tvc->v.v_gnode = gnodepnt = (struct gnode *) osi_AllocSmallSpace(sizeof(struct gnode));
879 memset((char *)gnodepnt, 0, sizeof(struct gnode));
882 memset((void*)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc));
883 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
885 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
886 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
888 bhv_head_init(&(tvc->v.v_bh));
889 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
892 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion*)tvc;
894 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
896 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
898 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
899 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
901 vnode_pcache_init(&tvc->v);
902 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
903 /* Above define is never true execpt in SGI test kernels. */
904 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
907 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
910 SetAfsVnode((struct vnode *)tvc);
911 #endif /* AFS_SGI64_ENV */
912 #ifdef AFS_DARWIN_ENV
913 tvc->v.v_ubcinfo = UBC_INFO_NULL;
914 lockinit(&tvc->rwlock, PINOD, "vcache rwlock", 0, 0);
915 cache_purge((struct vnode *)tvc);
918 /* VLISTNONE(&tvc->v); */
919 tvc->v.v_freelist.tqe_next=0;
920 tvc->v.v_freelist.tqe_prev=(struct vnode **)0xdeadb;
921 /*tvc->vrefCount++;*/
924 * The proper value for mvstat (for root fids) is setup by the caller.
927 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
929 if (afs_globalVFS == 0) osi_Panic("afs globalvfs");
930 vSetVfsp(tvc, afs_globalVFS);
933 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
934 tvc->v.v_vfsprev = NULL;
935 afs_globalVFS->vfs_vnodes = &tvc->v;
936 if (tvc->v.v_vfsnext != NULL)
937 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
938 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us!*/
939 gnodepnt->gn_vnode = &tvc->v;
942 tvc->v.g_dev = ((struct mount *)afs_globalVFS->vfs_data)->m_dev;
944 #if defined(AFS_DUX40_ENV)
945 insmntque(tvc, afs_globalVFS, &afs_ubcops);
948 /* Is this needed??? */
949 insmntque(tvc, afs_globalVFS);
950 #endif /* AFS_OSF_ENV */
951 #endif /* AFS_DUX40_ENV */
952 #if defined(AFS_SGI_ENV)
953 VN_SET_DPAGES(&(tvc->v), (struct pfdat*)NULL);
954 osi_Assert((tvc->v.v_flag & VINACT) == 0);
956 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
957 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
958 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
959 osi_Assert(tvc->v.v_filocks == NULL);
960 #if !defined(AFS_SGI65_ENV)
961 osi_Assert(tvc->v.v_filocksem == NULL);
963 osi_Assert(tvc->cred == NULL);
965 vnode_pcache_reinit(&tvc->v);
966 tvc->v.v_rdev = NODEV;
968 vn_initlist((struct vnlist *)&tvc->v);
970 #endif /* AFS_SGI_ENV */
971 #if defined(AFS_LINUX22_ENV)
973 struct inode *ip = (struct inode*)tvc;
974 sema_init(&ip->i_sem, 1);
975 #if defined(AFS_LINUX24_ENV)
976 sema_init(&ip->i_zombie, 1);
977 init_waitqueue_head(&ip->i_wait);
978 spin_lock_init(&ip->i_data.i_shared_lock);
979 #ifdef STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK
980 spin_lock_init(&ip->i_data.page_lock);
982 INIT_LIST_HEAD(&ip->i_data.clean_pages);
983 INIT_LIST_HEAD(&ip->i_data.dirty_pages);
984 INIT_LIST_HEAD(&ip->i_data.locked_pages);
985 INIT_LIST_HEAD(&ip->i_dirty_buffers);
986 #ifdef STRUCT_INODE_HAS_I_DIRTY_DATA_BUFFERS
987 INIT_LIST_HEAD(&ip->i_dirty_data_buffers);
989 #ifdef STRUCT_INODE_HAS_I_DEVICES
990 INIT_LIST_HEAD(&ip->i_devices);
992 ip->i_data.host = (void*) ip;
993 ip->i_mapping = &ip->i_data;
994 #ifdef STRUCT_INODE_HAS_I_TRUNCATE_SEM
995 init_rwsem(&ip->i_truncate_sem);
998 sema_init(&ip->i_atomic_write, 1);
999 init_waitqueue(&ip->i_wait);
1001 INIT_LIST_HEAD(&ip->i_hash);
1002 INIT_LIST_HEAD(&ip->i_dentry);
1003 if (afs_globalVFS) {
1004 ip->i_dev = afs_globalVFS->s_dev;
1005 ip->i_sb = afs_globalVFS;
1010 osi_dnlc_purgedp(tvc); /* this may be overkill */
1011 memset((char *)&(tvc->quick), 0, sizeof(struct vtodc));
1012 memset((char *)&(tvc->callsort), 0, sizeof(struct afs_q));
1013 tvc->slocks = (struct SimpleLocks *)0;
1016 tvc->hnext = afs_vhashT[i];
1017 afs_vhashT[i] = tvc;
1018 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1019 refpanic ("NewVCache VLRU inconsistent");
1021 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
1022 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1023 refpanic ("NewVCache VLRU inconsistent2");
1025 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1026 refpanic ("NewVCache VLRU inconsistent3");
1028 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1029 refpanic ("NewVCache VLRU inconsistent4");
1039 * afs_FlushActiveVcaches
1045 * doflocks : Do we handle flocks?
1047 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1049 afs_FlushActiveVcaches(doflocks)
1050 register afs_int32 doflocks;
1052 { /*afs_FlushActiveVcaches*/
1054 register struct vcache *tvc;
1056 register struct conn *tc;
1057 register afs_int32 code;
1058 register struct AFS_UCRED *cred;
1059 struct vrequest treq, ureq;
1060 struct AFSVolSync tsync;
1064 AFS_STATCNT(afs_FlushActiveVcaches);
1065 ObtainReadLock(&afs_xvcache);
1066 for(i=0;i<VCSIZE;i++) {
1067 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
1068 if (doflocks && tvc->flockCount != 0) {
1069 /* if this entry has an flock, send a keep-alive call out */
1071 ReleaseReadLock(&afs_xvcache);
1072 ObtainWriteLock(&tvc->lock,51);
1074 afs_InitReq(&treq, &afs_osi_cred);
1075 treq.flags |= O_NONBLOCK;
1077 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1079 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1080 #ifdef RX_ENABLE_LOCKS
1082 #endif /* RX_ENABLE_LOCKS */
1084 RXAFS_ExtendLock(tc->id,
1085 (struct AFSFid *) &tvc->fid.Fid,
1087 #ifdef RX_ENABLE_LOCKS
1089 #endif /* RX_ENABLE_LOCKS */
1094 (afs_Analyze(tc, code, &tvc->fid, &treq,
1095 AFS_STATS_FS_RPCIDX_EXTENDLOCK,
1096 SHARED_LOCK, (struct cell *)0));
1098 ReleaseWriteLock(&tvc->lock);
1099 ObtainReadLock(&afs_xvcache);
1103 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1105 * Don't let it evaporate in case someone else is in
1106 * this code. Also, drop the afs_xvcache lock while
1107 * getting vcache locks.
1110 ReleaseReadLock(&afs_xvcache);
1111 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1112 afs_BozonLock(&tvc->pvnLock, tvc);
1114 #if defined(AFS_SGI_ENV)
1116 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1118 osi_Assert(VREFCOUNT(tvc) > 0);
1119 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1121 ObtainWriteLock(&tvc->lock,52);
1122 if (tvc->states & CCore) {
1123 tvc->states &= ~CCore;
1124 /* XXXX Find better place-holder for cred XXXX */
1125 cred = (struct AFS_UCRED *) tvc->linkData;
1126 tvc->linkData = (char *) 0; /* XXX */
1127 afs_InitReq(&ureq, cred);
1128 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1129 ICL_TYPE_POINTER, tvc,
1130 ICL_TYPE_INT32, tvc->execsOrWriters);
1131 code = afs_StoreOnLastReference(tvc, &ureq);
1132 ReleaseWriteLock(&tvc->lock);
1133 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1134 afs_BozonUnlock(&tvc->pvnLock, tvc);
1136 hzero(tvc->flushDV);
1139 if (code && code != VNOVNODE) {
1140 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1141 /* /dev/console */ 1);
1143 } else if (tvc->states & CUnlinkedDel) {
1147 ReleaseWriteLock(&tvc->lock);
1148 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1149 afs_BozonUnlock(&tvc->pvnLock, tvc);
1151 #if defined(AFS_SGI_ENV)
1152 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1154 afs_remunlink(tvc, 0);
1155 #if defined(AFS_SGI_ENV)
1156 AFS_RWLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1160 /* lost (or won, perhaps) the race condition */
1161 ReleaseWriteLock(&tvc->lock);
1162 #if defined(AFS_SUN_ENV) || defined(AFS_ALPHA_ENV)
1163 afs_BozonUnlock(&tvc->pvnLock, tvc);
1166 #if defined(AFS_SGI_ENV)
1167 AFS_RWUNLOCK((vnode_t *)tvc, VRWLOCK_WRITE);
1169 ObtainReadLock(&afs_xvcache);
1175 AFS_RELE((struct vnode *)tvc);
1177 /* Matches write code setting CCore flag */
1181 #ifdef AFS_DARWIN_ENV
1182 if (VREFCOUNT(tvc) == 1 && UBCINFOEXISTS(&tvc->v)) {
1183 if (tvc->opens) panic("flushactive open, hasubc, but refcnt 1");
1184 osi_VM_TryReclaim(tvc,0);
1189 ReleaseReadLock(&afs_xvcache);
1191 } /*afs_FlushActiveVcaches*/
1198 * Make sure a cache entry is up-to-date status-wise.
1200 * NOTE: everywhere that calls this can potentially be sped up
1201 * by checking CStatd first, and avoiding doing the InitReq
1202 * if this is up-to-date.
1204 * Anymore, the only places that call this KNOW already that the
1205 * vcache is not up-to-date, so we don't screw around.
1208 * avc : Ptr to vcache entry to verify.
1212 int afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1214 register struct vcache *tvc;
1216 AFS_STATCNT(afs_VerifyVCache);
1218 #if defined(AFS_OSF_ENV)
1219 ObtainReadLock(&avc->lock);
1220 if (afs_IsWired(avc)) {
1221 ReleaseReadLock(&avc->lock);
1224 ReleaseReadLock(&avc->lock);
1225 #endif /* AFS_OSF_ENV */
1226 /* otherwise we must fetch the status info */
1228 ObtainWriteLock(&avc->lock,53);
1229 if (avc->states & CStatd) {
1230 ReleaseWriteLock(&avc->lock);
1233 ObtainWriteLock(&afs_xcbhash, 461);
1234 avc->states &= ~( CStatd | CUnique );
1235 avc->callback = (struct server *)0;
1236 afs_DequeueCallback(avc);
1237 ReleaseWriteLock(&afs_xcbhash);
1238 ReleaseWriteLock(&avc->lock);
1240 /* since we've been called back, or the callback has expired,
1241 * it's possible that the contents of this directory, or this
1242 * file's name have changed, thus invalidating the dnlc contents.
1244 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1245 osi_dnlc_purgedp (avc);
1247 osi_dnlc_purgevp (avc);
1249 /* fetch the status info */
1250 tvc = afs_GetVCache(&avc->fid, areq, (afs_int32*)0, avc, READ_LOCK);
1251 if (!tvc) return ENOENT;
1252 /* Put it back; caller has already incremented vrefCount */
1253 afs_PutVCache(tvc, READ_LOCK);
1256 } /*afs_VerifyVCache*/
1263 * Simple copy of stat info into cache.
1266 * avc : Ptr to vcache entry involved.
1267 * astat : Ptr to stat info to copy.
1270 * Nothing interesting.
1272 * Callers: as of 1992-04-29, only called by WriteVCache
1275 afs_SimpleVStat(avc, astat, areq)
1276 register struct vcache *avc;
1277 register struct AFSFetchStatus *astat;
1278 struct vrequest *areq;
1279 { /*afs_SimpleVStat*/
1282 AFS_STATCNT(afs_SimpleVStat);
1285 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1286 && !AFS_VN_MAPPED((vnode_t*)avc))
1288 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1292 #ifdef AFS_64BIT_ClIENT
1293 FillInt64(length, astat->Length_hi, astat->Length);
1294 #else /* AFS_64BIT_CLIENT */
1295 length = astat->Length;
1296 #endif /* AFS_64BIT_CLIENT */
1297 #if defined(AFS_SGI_ENV)
1298 osi_Assert((valusema(&avc->vc_rwlock) <= 0) &&
1299 (OSI_GET_LOCKID() == avc->vc_rwlockid));
1300 if (length < avc->m.Length) {
1301 vnode_t *vp = (vnode_t *)avc;
1303 osi_Assert(WriteLocked(&avc->lock));
1304 ReleaseWriteLock(&avc->lock);
1306 PTOSSVP(vp, (off_t)length, (off_t)MAXLONG);
1308 ObtainWriteLock(&avc->lock,67);
1311 /* if writing the file, don't fetch over this value */
1312 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT,
1313 ICL_TYPE_POINTER, avc,
1314 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1315 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1316 avc->m.Length = length;
1317 avc->m.Date = astat->ClientModTime;
1319 avc->m.Owner = astat->Owner;
1320 avc->m.Group = astat->Group;
1321 avc->m.Mode = astat->UnixModeBits;
1322 if (vType(avc) == VREG) {
1323 avc->m.Mode |= S_IFREG;
1325 else if (vType(avc) == VDIR) {
1326 avc->m.Mode |= S_IFDIR;
1328 else if (vType(avc) == VLNK) {
1332 avc->m.Mode |= S_IFLNK;
1333 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1335 if (avc->states & CForeign) {
1336 struct axscache *ac;
1337 avc->anyAccess = astat->AnonymousAccess;
1339 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1341 * Caller has at least one bit not covered by anonymous, and
1342 * thus may have interesting rights.
1344 * HOWEVER, this is a really bad idea, because any access query
1345 * for bits which aren't covered by anonymous, on behalf of a user
1346 * who doesn't have any special rights, will result in an answer of
1347 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1348 * It's an especially bad idea under Ultrix, since (due to the lack of
1349 * a proper access() call) it must perform several afs_access() calls
1350 * in order to create magic mode bits that vary according to who makes
1351 * the call. In other words, _every_ stat() generates a test for
1354 #endif /* badidea */
1355 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1356 ac->axess = astat->CallerAccess;
1357 else /* not found, add a new one if possible */
1358 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1362 } /*afs_SimpleVStat*/
1369 * Store the status info *only* back to the server for a
1373 * avc : Ptr to the vcache entry.
1374 * astatus : Ptr to the status info to store.
1375 * areq : Ptr to the associated vrequest.
1378 * Must be called with a shared lock held on the vnode.
1381 afs_WriteVCache(avc, astatus, areq)
1382 register struct vcache *avc;
1383 register struct AFSStoreStatus *astatus;
1384 struct vrequest *areq;
1386 { /*afs_WriteVCache*/
1389 struct AFSFetchStatus OutStatus;
1390 struct AFSVolSync tsync;
1393 AFS_STATCNT(afs_WriteVCache);
1394 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1395 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length));
1398 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1400 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1401 #ifdef RX_ENABLE_LOCKS
1403 #endif /* RX_ENABLE_LOCKS */
1404 code = RXAFS_StoreStatus(tc->id,
1405 (struct AFSFid *) &avc->fid.Fid,
1406 astatus, &OutStatus, &tsync);
1407 #ifdef RX_ENABLE_LOCKS
1409 #endif /* RX_ENABLE_LOCKS */
1414 (afs_Analyze(tc, code, &avc->fid, areq,
1415 AFS_STATS_FS_RPCIDX_STORESTATUS,
1416 SHARED_LOCK, (struct cell *)0));
1418 UpgradeSToWLock(&avc->lock,20);
1420 /* success, do the changes locally */
1421 afs_SimpleVStat(avc, &OutStatus, areq);
1423 * Update the date, too. SimpleVStat didn't do this, since
1424 * it thought we were doing this after fetching new status
1425 * over a file being written.
1427 avc->m.Date = OutStatus.ClientModTime;
1430 /* failure, set up to check with server next time */
1431 ObtainWriteLock(&afs_xcbhash, 462);
1432 afs_DequeueCallback(avc);
1433 avc->states &= ~( CStatd | CUnique); /* turn off stat valid flag */
1434 ReleaseWriteLock(&afs_xcbhash);
1435 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1436 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
1438 ConvertWToSLock(&avc->lock);
1441 } /*afs_WriteVCache*/
1447 * Copy astat block into vcache info
1450 * avc : Ptr to vcache entry.
1451 * astat : Ptr to stat block to copy in.
1452 * areq : Ptr to associated request.
1455 * Must be called under a write lock
1457 * Note: this code may get dataversion and length out of sync if the file has
1458 * been modified. This is less than ideal. I haven't thought about
1459 * it sufficiently to be certain that it is adequate.
1462 afs_ProcessFS(avc, astat, areq)
1463 register struct vcache *avc;
1464 struct vrequest *areq;
1465 register struct AFSFetchStatus *astat;
1471 AFS_STATCNT(afs_ProcessFS);
1473 #ifdef AFS_64BIT_CLIENT
1474 FillInt64(length, astat->Length_hi, astat->Length);
1475 #else /* AFS_64BIT_CLIENT */
1476 length = astat->Length;
1477 #endif /* AFS_64BIT_CLIENT */
1478 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1479 * number for each bulk status request. Under no circumstances
1480 * should afs_DoBulkStat store a sequence number if the new
1481 * length will be ignored when afs_ProcessFS is called with
1482 * new stats. If you change the following conditional then you
1483 * also need to change the conditional in afs_DoBulkStat. */
1485 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1486 && !AFS_VN_MAPPED((vnode_t*)avc))
1488 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc))
1491 /* if we're writing or mapping this file, don't fetch over these
1494 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1495 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1496 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1497 avc->m.Length = length;
1498 avc->m.Date = astat->ClientModTime;
1500 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1501 avc->m.Owner = astat->Owner;
1502 avc->m.Mode = astat->UnixModeBits;
1503 avc->m.Group = astat->Group;
1504 avc->m.LinkCount = astat->LinkCount;
1505 if (astat->FileType == File) {
1506 vSetType(avc, VREG);
1507 avc->m.Mode |= S_IFREG;
1509 else if (astat->FileType == Directory) {
1510 vSetType(avc, VDIR);
1511 avc->m.Mode |= S_IFDIR;
1513 else if (astat->FileType == SymbolicLink) {
1514 vSetType(avc, VLNK);
1515 avc->m.Mode |= S_IFLNK;
1516 if ((avc->m.Mode & 0111) == 0) avc->mvstat = 1;
1518 avc->anyAccess = astat->AnonymousAccess;
1520 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1522 * Caller has at least one bit not covered by anonymous, and
1523 * thus may have interesting rights.
1525 * HOWEVER, this is a really bad idea, because any access query
1526 * for bits which aren't covered by anonymous, on behalf of a user
1527 * who doesn't have any special rights, will result in an answer of
1528 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1529 * It's an especially bad idea under Ultrix, since (due to the lack of
1530 * a proper access() call) it must perform several afs_access() calls
1531 * in order to create magic mode bits that vary according to who makes
1532 * the call. In other words, _every_ stat() generates a test for
1535 #endif /* badidea */
1537 struct axscache *ac;
1538 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1539 ac->axess = astat->CallerAccess;
1540 else /* not found, add a new one if possible */
1541 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1544 #ifdef AFS_LINUX22_ENV
1545 vcache2inode(avc); /* Set the inode attr cache */
1551 afs_RemoteLookup(afid, areq, name, nfid, OutStatusp, CallBackp, serverp, tsyncp)
1552 register struct VenusFid *afid;
1553 struct vrequest *areq;
1555 struct VenusFid *nfid;
1556 struct AFSFetchStatus *OutStatusp;
1557 struct AFSCallBack *CallBackp;
1558 struct server **serverp;
1559 struct AFSVolSync *tsyncp;
1562 register struct vcache *tvc;
1565 register struct conn *tc;
1566 struct AFSFetchStatus OutDirStatus;
1569 if (!name) name = ""; /* XXX */
1571 tc = afs_Conn(afid, areq, SHARED_LOCK);
1573 if (serverp) *serverp = tc->srvr->server;
1575 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1576 #ifdef RX_ENABLE_LOCKS
1578 #endif /* RX_ENABLE_LOCKS */
1579 code = RXAFS_Lookup(tc->id, (struct AFSFid *) &afid->Fid, name,
1580 (struct AFSFid *) &nfid->Fid,
1581 OutStatusp, &OutDirStatus, CallBackp, tsyncp);
1582 #ifdef RX_ENABLE_LOCKS
1584 #endif /* RX_ENABLE_LOCKS */
1589 (afs_Analyze(tc, code, afid, areq,
1590 AFS_STATS_FS_RPCIDX_XLOOKUP,
1591 SHARED_LOCK, (struct cell *)0));
1601 * Given a file id and a vrequest structure, fetch the status
1602 * information associated with the file.
1606 * areq : Ptr to associated vrequest structure, specifying the
1607 * user whose authentication tokens will be used.
1608 * avc : caller may already have a vcache for this file, which is
1612 * The cache entry is returned with an increased vrefCount field.
1613 * The entry must be discarded by calling afs_PutVCache when you
1614 * are through using the pointer to the cache entry.
1616 * You should not hold any locks when calling this function, except
1617 * locks on other vcache entries. If you lock more than one vcache
1618 * entry simultaneously, you should lock them in this order:
1620 * 1. Lock all files first, then directories.
1621 * 2. Within a particular type, lock entries in Fid.Vnode order.
1623 * This locking hierarchy is convenient because it allows locking
1624 * of a parent dir cache entry, given a file (to check its access
1625 * control list). It also allows renames to be handled easily by
1626 * locking directories in a constant order.
1627 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1629 struct vcache *afs_GetVCache(afid, areq, cached, avc, locktype)
1630 register struct VenusFid *afid;
1631 struct vrequest *areq;
1634 struct vcache *avc; /* might have a vcache structure already, which must
1635 * already be held by the caller */
1638 afs_int32 code, i, newvcache=0;
1639 register struct vcache *tvc;
1643 AFS_STATCNT(afs_GetVCache);
1645 if (cached) *cached = 0; /* Init just in case */
1648 ObtainSharedLock(&afs_xvcache,5);
1650 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS | DO_VLRU );
1652 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1653 ReleaseSharedLock(&afs_xvcache);
1654 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1662 if (tvc->states & CStatd) {
1663 ReleaseSharedLock(&afs_xvcache);
1668 UpgradeSToWLock(&afs_xvcache,21);
1670 /* no cache entry, better grab one */
1671 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1674 ConvertWToSLock(&afs_xvcache);
1675 afs_stats_cmperf.vcacheMisses++;
1678 ReleaseSharedLock(&afs_xvcache);
1680 ObtainWriteLock(&tvc->lock,54);
1682 if (tvc->states & CStatd) {
1683 #ifdef AFS_LINUX22_ENV
1686 ReleaseWriteLock(&tvc->lock);
1687 #ifdef AFS_DARWIN_ENV
1693 #if defined(AFS_OSF_ENV)
1694 if (afs_IsWired(tvc)) {
1695 ReleaseWriteLock(&tvc->lock);
1698 #endif /* AFS_OSF_ENV */
1700 ObtainWriteLock(&afs_xcbhash, 464);
1701 tvc->states &= ~CUnique;
1703 afs_DequeueCallback(tvc);
1704 ReleaseWriteLock(&afs_xcbhash);
1706 /* It is always appropriate to throw away all the access rights? */
1707 afs_FreeAllAxs(&(tvc->Access));
1708 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1710 if ((tvp->states & VForeign)) {
1711 if (newvcache) tvc->states |= CForeign;
1712 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1713 && (tvp->rootUnique == afid->Fid.Unique)) {
1717 if (tvp->states & VRO) tvc->states |= CRO;
1718 if (tvp->states & VBackup) tvc->states |= CBackup;
1719 /* now copy ".." entry back out of volume structure, if necessary */
1720 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1722 tvc->mvid = (struct VenusFid *)
1723 osi_AllocSmallSpace(sizeof(struct VenusFid));
1724 *tvc->mvid = tvp->dotdot;
1726 afs_PutVolume(tvp, READ_LOCK);
1730 afs_RemoveVCB(afid);
1732 struct AFSFetchStatus OutStatus;
1734 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1735 afs_ProcessFS(tvc, &OutStatus, areq);
1736 tvc->states |= CStatd | CUnique;
1739 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1744 ReleaseWriteLock(&tvc->lock);
1746 ObtainReadLock(&afs_xvcache);
1748 ReleaseReadLock(&afs_xvcache);
1749 return (struct vcache *) 0;
1752 ReleaseWriteLock(&tvc->lock);
1753 #ifdef AFS_DARWIN_ENV
1762 struct vcache *afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1763 afs_int32 *cached, afs_int32 locktype,
1764 struct vcache *adp, char *aname)
1766 afs_int32 code, now, newvcache=0, hash;
1767 struct VenusFid nfid;
1768 register struct vcache *tvc;
1770 struct AFSFetchStatus OutStatus;
1771 struct AFSCallBack CallBack;
1772 struct AFSVolSync tsync;
1773 struct server *serverp = 0;
1777 AFS_STATCNT(afs_GetVCache);
1778 if (cached) *cached = 0; /* Init just in case */
1781 ObtainReadLock(&afs_xvcache);
1782 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_STATS /* no vlru */);
1785 ReleaseReadLock(&afs_xvcache);
1787 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1788 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1792 ObtainReadLock(&tvc->lock);
1794 if (tvc->states & CStatd) {
1798 ReleaseReadLock(&tvc->lock);
1801 tvc->states &= ~CUnique;
1803 ReleaseReadLock(&tvc->lock);
1804 ObtainReadLock(&afs_xvcache);
1808 ReleaseReadLock(&afs_xvcache);
1810 /* lookup the file */
1813 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1814 code = afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1818 ObtainSharedLock(&afs_xvcache,6);
1819 tvc = afs_FindVCache(&nfid, 0, 0, &retry, DO_VLRU /* no xstats now*/);
1821 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1822 ReleaseSharedLock(&afs_xvcache);
1823 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1829 /* no cache entry, better grab one */
1830 UpgradeSToWLock(&afs_xvcache,22);
1831 tvc = afs_NewVCache(&nfid, (struct server *)0, 1, WRITE_LOCK);
1833 ConvertWToSLock(&afs_xvcache);
1836 ReleaseSharedLock(&afs_xvcache);
1837 ObtainWriteLock(&tvc->lock,55);
1839 /* It is always appropriate to throw away all the access rights? */
1840 afs_FreeAllAxs(&(tvc->Access));
1841 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1843 if ((tvp->states & VForeign)) {
1844 if (newvcache) tvc->states |= CForeign;
1845 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1846 && (tvp->rootUnique == afid->Fid.Unique))
1849 if (tvp->states & VRO) tvc->states |= CRO;
1850 if (tvp->states & VBackup) tvc->states |= CBackup;
1851 /* now copy ".." entry back out of volume structure, if necessary */
1852 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1854 tvc->mvid = (struct VenusFid *)
1855 osi_AllocSmallSpace(sizeof(struct VenusFid));
1856 *tvc->mvid = tvp->dotdot;
1861 ObtainWriteLock(&afs_xcbhash, 465);
1862 afs_DequeueCallback(tvc);
1863 tvc->states &= ~( CStatd | CUnique );
1864 ReleaseWriteLock(&afs_xcbhash);
1865 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1866 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1868 afs_PutVolume(tvp, READ_LOCK);
1869 ReleaseWriteLock(&tvc->lock);
1870 ObtainReadLock(&afs_xvcache);
1872 ReleaseReadLock(&afs_xvcache);
1873 return (struct vcache *) 0;
1876 ObtainWriteLock(&afs_xcbhash, 466);
1877 if (origCBs == afs_allCBs) {
1878 if (CallBack.ExpirationTime) {
1879 tvc->callback = serverp;
1880 tvc->cbExpires = CallBack.ExpirationTime+now;
1881 tvc->states |= CStatd | CUnique;
1882 tvc->states &= ~CBulkFetching;
1883 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1884 } else if (tvc->states & CRO) {
1885 /* adapt gives us an hour. */
1886 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
1887 tvc->states |= CStatd | CUnique;
1888 tvc->states &= ~CBulkFetching;
1889 afs_QueueCallback(tvc, CBHash(3600), tvp);
1891 tvc->callback = (struct server *)0;
1892 afs_DequeueCallback(tvc);
1893 tvc->states &= ~(CStatd | CUnique);
1894 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1895 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1898 afs_DequeueCallback(tvc);
1899 tvc->states &= ~CStatd;
1900 tvc->states &= ~CUnique;
1901 tvc->callback = (struct server *)0;
1902 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1903 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
1905 ReleaseWriteLock(&afs_xcbhash);
1907 afs_PutVolume(tvp, READ_LOCK);
1908 afs_ProcessFS(tvc, &OutStatus, areq);
1910 ReleaseWriteLock(&tvc->lock);
1911 #ifdef AFS_DARWIN_ENV
1918 struct vcache *afs_GetRootVCache(struct VenusFid *afid,
1919 struct vrequest *areq, afs_int32 *cached,
1920 struct volume *tvolp, afs_int32 locktype)
1922 afs_int32 code, i, newvcache = 0, haveStatus = 0;
1923 afs_int32 getNewFid = 0;
1925 struct VenusFid nfid;
1926 register struct vcache *tvc;
1927 struct server *serverp = 0;
1928 struct AFSFetchStatus OutStatus;
1929 struct AFSCallBack CallBack;
1930 struct AFSVolSync tsync;
1936 if (!tvolp->rootVnode || getNewFid) {
1937 struct VenusFid tfid;
1940 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
1941 origCBs = afs_allCBs; /* ignore InitCallBackState */
1942 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid,
1943 &OutStatus, &CallBack, &serverp, &tsync);
1945 return (struct vcache *)0;
1947 /* ReleaseReadLock(&tvolp->lock); */
1948 ObtainWriteLock(&tvolp->lock,56);
1949 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
1950 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
1951 ReleaseWriteLock(&tvolp->lock);
1952 /* ObtainReadLock(&tvolp->lock);*/
1955 afid->Fid.Vnode = tvolp->rootVnode;
1956 afid->Fid.Unique = tvolp->rootUnique;
1959 ObtainSharedLock(&afs_xvcache,7);
1961 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1962 if (!FidCmp(&(tvc->fid), afid)) {
1964 /* Grab this vnode, possibly reactivating from the free list */
1965 /* for the present (95.05.25) everything on the hash table is
1966 * definitively NOT in the free list -- at least until afs_reclaim
1967 * can be safely implemented */
1970 vg = vget((struct vnode *)tvc); /* this bumps ref count */
1974 #endif /* AFS_OSF_ENV */
1979 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
1980 /* Mount point no longer stat'd or unknown. FID may have changed. */
1985 tvc = (struct vcache*)0;
1987 ReleaseSharedLock(&afs_xvcache);
1992 UpgradeSToWLock(&afs_xvcache,23);
1993 /* no cache entry, better grab one */
1994 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
1996 afs_stats_cmperf.vcacheMisses++;
1999 if (cached) *cached = 1;
2000 afs_stats_cmperf.vcacheHits++;
2002 /* we already bumped the ref count in the for loop above */
2003 #else /* AFS_OSF_ENV */
2006 UpgradeSToWLock(&afs_xvcache,24);
2007 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2008 refpanic ("GRVC VLRU inconsistent0");
2010 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2011 refpanic ("GRVC VLRU inconsistent1");
2013 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2014 refpanic ("GRVC VLRU inconsistent2");
2016 QRemove(&tvc->vlruq); /* move to lruq head */
2017 QAdd(&VLRU, &tvc->vlruq);
2018 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2019 refpanic ("GRVC VLRU inconsistent3");
2021 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2022 refpanic ("GRVC VLRU inconsistent4");
2024 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2025 refpanic ("GRVC VLRU inconsistent5");
2030 ReleaseWriteLock(&afs_xvcache);
2032 if (tvc->states & CStatd) {
2036 ObtainReadLock(&tvc->lock);
2037 tvc->states &= ~CUnique;
2038 tvc->callback = (struct server *)0; /* redundant, perhaps */
2039 ReleaseReadLock(&tvc->lock);
2042 ObtainWriteLock(&tvc->lock,57);
2044 /* It is always appropriate to throw away all the access rights? */
2045 afs_FreeAllAxs(&(tvc->Access));
2047 if (newvcache) tvc->states |= CForeign;
2048 if (tvolp->states & VRO) tvc->states |= CRO;
2049 if (tvolp->states & VBackup) tvc->states |= CBackup;
2050 /* now copy ".." entry back out of volume structure, if necessary */
2051 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2052 && (tvolp->rootUnique == afid->Fid.Unique)) {
2055 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2057 tvc->mvid = (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid));
2058 *tvc->mvid = tvolp->dotdot;
2062 afs_RemoveVCB(afid);
2065 struct VenusFid tfid;
2068 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2069 origCBs = afs_allCBs; /* ignore InitCallBackState */
2070 code = afs_RemoteLookup(&tfid, areq, (char *)0, &nfid, &OutStatus,
2071 &CallBack, &serverp, &tsync);
2075 ObtainWriteLock(&afs_xcbhash, 467);
2076 afs_DequeueCallback(tvc);
2077 tvc->callback = (struct server *)0;
2078 tvc->states &= ~(CStatd|CUnique);
2079 ReleaseWriteLock(&afs_xcbhash);
2080 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2081 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2082 ReleaseWriteLock(&tvc->lock);
2083 ObtainReadLock(&afs_xvcache);
2085 ReleaseReadLock(&afs_xvcache);
2086 return (struct vcache *) 0;
2089 ObtainWriteLock(&afs_xcbhash, 468);
2090 if (origCBs == afs_allCBs) {
2091 tvc->states |= CTruth;
2092 tvc->callback = serverp;
2093 if (CallBack.ExpirationTime != 0) {
2094 tvc->cbExpires = CallBack.ExpirationTime+start;
2095 tvc->states |= CStatd;
2096 tvc->states &= ~CBulkFetching;
2097 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2098 } else if (tvc->states & CRO) {
2099 /* adapt gives us an hour. */
2100 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2101 tvc->states |= CStatd;
2102 tvc->states &= ~CBulkFetching;
2103 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2106 afs_DequeueCallback(tvc);
2107 tvc->callback = (struct server *)0;
2108 tvc->states &= ~(CStatd | CUnique);
2109 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2110 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2112 ReleaseWriteLock(&afs_xcbhash);
2113 afs_ProcessFS(tvc, &OutStatus, areq);
2115 ReleaseWriteLock(&tvc->lock);
2122 * must be called with avc write-locked
2123 * don't absolutely have to invalidate the hint unless the dv has
2124 * changed, but be sure to get it right else there will be consistency bugs.
2126 afs_int32 afs_FetchStatus(struct vcache *avc, struct VenusFid *afid,
2127 struct vrequest *areq, struct AFSFetchStatus *Outsp)
2131 register struct conn *tc;
2132 struct AFSCallBack CallBack;
2133 struct AFSVolSync tsync;
2134 struct volume* volp;
2138 tc = afs_Conn(afid, areq, SHARED_LOCK);
2139 avc->quick.stamp = 0; avc->h1.dchint = NULL; /* invalidate hints */
2141 avc->callback = tc->srvr->server;
2143 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2144 #ifdef RX_ENABLE_LOCKS
2146 #endif /* RX_ENABLE_LOCKS */
2147 code = RXAFS_FetchStatus(tc->id,
2148 (struct AFSFid *) &afid->Fid,
2149 Outsp, &CallBack, &tsync);
2150 #ifdef RX_ENABLE_LOCKS
2152 #endif /* RX_ENABLE_LOCKS */
2159 (afs_Analyze(tc, code, afid, areq,
2160 AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2161 SHARED_LOCK, (struct cell *)0));
2164 afs_ProcessFS(avc, Outsp, areq);
2165 volp = afs_GetVolume(afid, areq, READ_LOCK);
2166 ObtainWriteLock(&afs_xcbhash, 469);
2167 avc->states |= CTruth;
2168 if (avc->callback /* check for race */) {
2169 if (CallBack.ExpirationTime != 0) {
2170 avc->cbExpires = CallBack.ExpirationTime+start;
2171 avc->states |= CStatd;
2172 avc->states &= ~CBulkFetching;
2173 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2175 else if (avc->states & CRO)
2176 { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2177 avc->cbExpires = 3600+start;
2178 avc->states |= CStatd;
2179 avc->states &= ~CBulkFetching;
2180 afs_QueueCallback(avc, CBHash(3600), volp);
2183 afs_DequeueCallback(avc);
2184 avc->callback = (struct server *)0;
2185 avc->states &= ~(CStatd|CUnique);
2186 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2187 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2191 afs_DequeueCallback(avc);
2192 avc->callback = (struct server *)0;
2193 avc->states &= ~(CStatd|CUnique);
2194 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2195 osi_dnlc_purgedp (avc); /* if it (could be) a directory */
2197 ReleaseWriteLock(&afs_xcbhash);
2199 afs_PutVolume(volp, READ_LOCK);
2201 else { /* used to undo the local callback, but that's too extreme.
2202 * There are plenty of good reasons that fetchstatus might return
2203 * an error, such as EPERM. If we have the vnode cached, statd,
2204 * with callback, might as well keep track of the fact that we
2205 * don't have access...
2207 if (code == EPERM || code == EACCES) {
2208 struct axscache *ac;
2209 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2211 else /* not found, add a new one if possible */
2212 afs_AddAxs(avc->Access, areq->uid, 0);
2223 * Stuff some information into the vcache for the given file.
2226 * afid : File in question.
2227 * OutStatus : Fetch status on the file.
2228 * CallBack : Callback info.
2229 * tc : RPC connection involved.
2230 * areq : vrequest involved.
2233 * Nothing interesting.
2236 afs_StuffVcache(afid, OutStatus, CallBack, tc, areq)
2237 register struct VenusFid *afid;
2238 struct AFSFetchStatus *OutStatus;
2239 struct AFSCallBack *CallBack;
2240 register struct conn *tc;
2241 struct vrequest *areq;
2243 { /*afs_StuffVcache*/
2245 register afs_int32 code, i, newvcache=0;
2246 register struct vcache *tvc;
2247 struct AFSVolSync tsync;
2249 struct axscache *ac;
2252 AFS_STATCNT(afs_StuffVcache);
2253 #ifdef IFS_VCACHECOUNT
2258 ObtainSharedLock(&afs_xvcache,8);
2260 tvc = afs_FindVCache(afid, 0, 0, &retry, DO_VLRU /* no stats */);
2262 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2263 ReleaseSharedLock(&afs_xvcache);
2264 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2270 /* no cache entry, better grab one */
2271 UpgradeSToWLock(&afs_xvcache,25);
2272 tvc = afs_NewVCache(afid, (struct server *)0, 1, WRITE_LOCK);
2274 ConvertWToSLock(&afs_xvcache);
2277 ReleaseSharedLock(&afs_xvcache);
2278 ObtainWriteLock(&tvc->lock,58);
2280 tvc->states &= ~CStatd;
2281 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2282 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2284 /* Is it always appropriate to throw away all the access rights? */
2285 afs_FreeAllAxs(&(tvc->Access));
2287 /*Copy useful per-volume info*/
2288 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2290 if (newvcache && (tvp->states & VForeign)) tvc->states |= CForeign;
2291 if (tvp->states & VRO) tvc->states |= CRO;
2292 if (tvp->states & VBackup) tvc->states |= CBackup;
2294 * Now, copy ".." entry back out of volume structure, if
2297 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2298 if (!tvc->mvid) tvc->mvid =
2299 (struct VenusFid *) osi_AllocSmallSpace(sizeof(struct VenusFid));
2300 *tvc->mvid = tvp->dotdot;
2303 /* store the stat on the file */
2304 afs_RemoveVCB(afid);
2305 afs_ProcessFS(tvc, OutStatus, areq);
2306 tvc->callback = tc->srvr->server;
2308 /* we use osi_Time twice below. Ideally, we would use the time at which
2309 * the FetchStatus call began, instead, but we don't have it here. So we
2310 * make do with "now". In the CRO case, it doesn't really matter. In
2311 * the other case, we hope that the difference between "now" and when the
2312 * call actually began execution on the server won't be larger than the
2313 * padding which the server keeps. Subtract 1 second anyway, to be on
2314 * the safe side. Can't subtract more because we don't know how big
2315 * ExpirationTime is. Possible consistency problems may arise if the call
2316 * timeout period becomes longer than the server's expiration padding. */
2317 ObtainWriteLock(&afs_xcbhash, 470);
2318 if (CallBack->ExpirationTime != 0) {
2319 tvc->cbExpires = CallBack->ExpirationTime+osi_Time()-1;
2320 tvc->states |= CStatd;
2321 tvc->states &= ~CBulkFetching;
2322 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2324 else if (tvc->states & CRO) {
2325 /* old-fashioned AFS 3.2 style */
2326 tvc->cbExpires = 3600+osi_Time(); /*XXX*/
2327 tvc->states |= CStatd;
2328 tvc->states &= ~CBulkFetching;
2329 afs_QueueCallback(tvc, CBHash(3600), tvp);
2332 afs_DequeueCallback(tvc);
2333 tvc->callback = (struct server *)0;
2334 tvc->states &= ~(CStatd|CUnique);
2335 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2336 osi_dnlc_purgedp (tvc); /* if it (could be) a directory */
2338 ReleaseWriteLock(&afs_xcbhash);
2340 afs_PutVolume(tvp, READ_LOCK);
2342 /* look in per-pag cache */
2343 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2344 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2345 else /* not found, add a new one if possible */
2346 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2348 ReleaseWriteLock(&tvc->lock);
2349 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2350 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32, tvc->cbExpires,
2351 ICL_TYPE_INT32, tvc->cbExpires-osi_Time());
2353 * Release ref count... hope this guy stays around...
2355 afs_PutVCache(tvc, WRITE_LOCK);
2356 } /*afs_StuffVcache*/
2363 * Decrements the reference count on a cache entry.
2366 * avc : Pointer to the cache entry to decrement.
2369 * Nothing interesting.
2372 afs_PutVCache(avc, locktype)
2373 register struct vcache *avc;
2377 AFS_STATCNT(afs_PutVCache);
2379 * Can we use a read lock here?
2381 ObtainReadLock(&afs_xvcache);
2383 ReleaseReadLock(&afs_xvcache);
2390 * Find a vcache entry given a fid.
2393 * afid : Pointer to the fid whose cache entry we desire.
2394 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2395 * unlock the vnode, and try again.
2396 * flags: bit 1 to specify whether to compute hit statistics. Not
2397 * set if FindVCache is called as part of internal bookkeeping.
2400 * Must be called with the afs_xvcache lock at least held at
2401 * the read level. In order to do the VLRU adjustment, the xvcache lock
2402 * must be shared-- we upgrade it here.
2405 struct vcache *afs_FindVCache(struct VenusFid *afid, afs_int32 lockit,
2406 afs_int32 locktype, afs_int32 *retry, afs_int32 flag)
2409 register struct vcache *tvc;
2412 AFS_STATCNT(afs_FindVCache);
2415 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2416 if (FidMatches(afid, tvc)) {
2418 /* Grab this vnode, possibly reactivating from the free list */
2421 vg = vget((struct vnode *)tvc);
2425 #endif /* AFS_OSF_ENV */
2430 /* should I have a read lock on the vnode here? */
2432 if (retry) *retry = 0;
2433 #if !defined(AFS_OSF_ENV)
2434 osi_vnhold(tvc, retry); /* already held, above */
2435 if (retry && *retry)
2439 * only move to front of vlru if we have proper vcache locking)
2441 if (flag & DO_VLRU) {
2442 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2443 refpanic ("FindVC VLRU inconsistent1");
2445 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2446 refpanic ("FindVC VLRU inconsistent1");
2448 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2449 refpanic ("FindVC VLRU inconsistent2");
2451 UpgradeSToWLock(&afs_xvcache,26);
2452 QRemove(&tvc->vlruq);
2453 QAdd(&VLRU, &tvc->vlruq);
2454 ConvertWToSLock(&afs_xvcache);
2455 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2456 refpanic ("FindVC VLRU inconsistent1");
2458 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2459 refpanic ("FindVC VLRU inconsistent2");
2461 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2462 refpanic ("FindVC VLRU inconsistent3");
2468 if (flag & DO_STATS) {
2469 if (tvc) afs_stats_cmperf.vcacheHits++;
2470 else afs_stats_cmperf.vcacheMisses++;
2471 if (afid->Cell == LOCALCELL)
2472 afs_stats_cmperf.vlocalAccesses++;
2474 afs_stats_cmperf.vremoteAccesses++;
2477 #ifdef AFS_LINUX22_ENV
2478 if (tvc && (tvc->states & CStatd))
2479 vcache2inode(tvc); /* mainly to reset i_nlink */
2481 #ifdef AFS_DARWIN_ENV
2486 } /*afs_FindVCache*/
2492 * Find a vcache entry given a fid. Does a wildcard match on what we
2493 * have for the fid. If more than one entry, don't return anything.
2496 * avcp : Fill in pointer if we found one and only one.
2497 * afid : Pointer to the fid whose cache entry we desire.
2498 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2499 * unlock the vnode, and try again.
2500 * flags: bit 1 to specify whether to compute hit statistics. Not
2501 * set if FindVCache is called as part of internal bookkeeping.
2504 * Must be called with the afs_xvcache lock at least held at
2505 * the read level. In order to do the VLRU adjustment, the xvcache lock
2506 * must be shared-- we upgrade it here.
2509 * number of matches found.
2512 int afs_duplicate_nfs_fids=0;
2514 afs_int32 afs_NFSFindVCache(avcp, afid, lockit)
2515 struct vcache **avcp;
2516 struct VenusFid *afid;
2518 { /*afs_FindVCache*/
2520 register struct vcache *tvc;
2522 afs_int32 retry = 0;
2523 afs_int32 count = 0;
2524 struct vcache *found_tvc = NULL;
2526 AFS_STATCNT(afs_FindVCache);
2530 ObtainSharedLock(&afs_xvcache,331);
2533 for(tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2534 /* Match only on what we have.... */
2535 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2536 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2537 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2538 && (tvc->fid.Cell == afid->Cell)) {
2540 /* Grab this vnode, possibly reactivating from the free list */
2543 vg = vget((struct vnode *)tvc);
2546 /* This vnode no longer exists. */
2549 #endif /* AFS_OSF_ENV */
2554 /* Drop our reference counts. */
2555 vrele((struct vnode *)tvc);
2556 vrele((struct vnode *)found_tvc);
2558 afs_duplicate_nfs_fids++;
2559 ReleaseSharedLock(&afs_xvcache);
2567 /* should I have a read lock on the vnode here? */
2569 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2570 osi_vnhold(tvc, &retry);
2573 found_tvc = (struct vcache*)0;
2574 ReleaseSharedLock(&afs_xvcache);
2575 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2579 #if !defined(AFS_OSF_ENV)
2580 osi_vnhold(tvc, (int*)0); /* already held, above */
2584 * We obtained the xvcache lock above.
2586 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2587 refpanic ("FindVC VLRU inconsistent1");
2589 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2590 refpanic ("FindVC VLRU inconsistent1");
2592 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2593 refpanic ("FindVC VLRU inconsistent2");
2595 UpgradeSToWLock(&afs_xvcache,568);
2596 QRemove(&tvc->vlruq);
2597 QAdd(&VLRU, &tvc->vlruq);
2598 ConvertWToSLock(&afs_xvcache);
2599 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2600 refpanic ("FindVC VLRU inconsistent1");
2602 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2603 refpanic ("FindVC VLRU inconsistent2");
2605 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2606 refpanic ("FindVC VLRU inconsistent3");
2611 if (tvc) afs_stats_cmperf.vcacheHits++;
2612 else afs_stats_cmperf.vcacheMisses++;
2613 if (afid->Cell == LOCALCELL)
2614 afs_stats_cmperf.vlocalAccesses++;
2616 afs_stats_cmperf.vremoteAccesses++;
2618 *avcp = tvc; /* May be null */
2620 ReleaseSharedLock(&afs_xvcache);
2621 return (tvc ? 1 : 0);
2623 } /*afs_NFSFindVCache*/
2631 * Initialize vcache related variables
2633 void afs_vcacheInit(int astatSize)
2635 register struct vcache *tvp;
2637 #if defined(AFS_OSF_ENV)
2638 if (!afs_maxvcount) {
2639 #if defined(AFS_OSF30_ENV)
2640 afs_maxvcount = max_vnodes/2; /* limit ourselves to half the total */
2642 afs_maxvcount = nvnode/2; /* limit ourselves to half the total */
2644 if (astatSize < afs_maxvcount) {
2645 afs_maxvcount = astatSize;
2648 #else /* AFS_OSF_ENV */
2649 freeVCList = (struct vcache *)0;
2652 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2653 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2655 #if !defined(AFS_OSF_ENV)
2656 /* Allocate and thread the struct vcache entries */
2657 tvp = (struct vcache *) afs_osi_Alloc(astatSize * sizeof(struct vcache));
2658 memset((char *)tvp, 0, sizeof(struct vcache)*astatSize);
2660 Initial_freeVCList = tvp;
2661 freeVCList = &(tvp[0]);
2662 for(i=0; i < astatSize-1; i++) {
2663 tvp[i].nextfree = &(tvp[i+1]);
2665 tvp[astatSize-1].nextfree = (struct vcache *) 0;
2666 #ifdef AFS_AIX32_ENV
2667 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2672 #if defined(AFS_SGI_ENV)
2673 for(i=0; i < astatSize; i++) {
2674 char name[METER_NAMSZ];
2675 struct vcache *tvc = &tvp[i];
2677 tvc->v.v_number = ++afsvnumbers;
2678 tvc->vc_rwlockid = OSI_NO_LOCKID;
2679 initnsema(&tvc->vc_rwlock, 1, makesname(name, "vrw", tvc->v.v_number));
2680 #ifndef AFS_SGI53_ENV
2681 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2683 #ifndef AFS_SGI62_ENV
2684 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2685 #endif /* AFS_SGI62_ENV */
2698 void shutdown_vcache(void)
2701 struct afs_cbr *tsp, *nsp;
2703 * XXX We may potentially miss some of the vcaches because if when there're no
2704 * free vcache entries and all the vcache entries are active ones then we allocate
2705 * an additional one - admittedly we almost never had that occur.
2707 #if !defined(AFS_OSF_ENV)
2708 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2710 #ifdef AFS_AIX32_ENV
2711 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2715 register struct afs_q *tq, *uq;
2716 register struct vcache *tvc;
2717 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2721 osi_FreeSmallSpace(tvc->mvid);
2722 tvc->mvid = (struct VenusFid*)0;
2725 aix_gnode_rele((struct vnode *)tvc);
2727 if (tvc->linkData) {
2728 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2733 * Also free the remaining ones in the Cache
2735 for (i=0; i < VCSIZE; i++) {
2736 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2738 osi_FreeSmallSpace(tvc->mvid);
2739 tvc->mvid = (struct VenusFid*)0;
2743 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2744 #ifdef AFS_AIX32_ENV
2747 vms_delete(tvc->segid);
2749 tvc->segid = tvc->vmh = NULL;
2750 if (VREFCOUNT(tvc)) osi_Panic("flushVcache: vm race");
2758 #if defined(AFS_SUN5_ENV)
2764 if (tvc->linkData) {
2765 afs_osi_Free(tvc->linkData, strlen(tvc->linkData)+1);
2769 afs_FreeAllAxs(&(tvc->Access));
2775 * Free any leftover callback queue
2777 for (tsp = afs_cbrSpace; tsp; tsp = nsp ) {
2779 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2783 #if !defined(AFS_OSF_ENV)
2784 freeVCList = Initial_freeVCList = 0;
2786 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2787 LOCK_INIT(&afs_xvcb, "afs_xvcb");