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"
44 #include "afs/sysincludes.h" /*Standard vendor system headers */
45 #include "afsincludes.h" /*AFS-based standard headers */
46 #include "afs/afs_stats.h"
47 #include "afs/afs_cbqueue.h"
48 #include "afs/afs_osidnlc.h"
51 afs_int32 afs_maxvcount = 0; /* max number of vcache entries */
52 afs_int32 afs_vcount = 0; /* number of vcache in use now */
53 #endif /* AFS_OSF_ENV */
61 #endif /* AFS_SGI64_ENV */
63 /* Exported variables */
64 afs_rwlock_t afs_xvcache; /*Lock: alloc new stat cache entries */
65 afs_lock_t afs_xvcb; /*Lock: fids on which there are callbacks */
66 struct vcache *freeVCList; /*Free list for stat cache entries */
67 struct vcache *Initial_freeVCList; /*Initial list for above */
68 struct afs_q VLRU; /*vcache LRU */
69 afs_int32 vcachegen = 0;
70 unsigned int afs_paniconwarn = 0;
71 struct vcache *afs_vhashT[VCSIZE];
72 struct vcache *afs_vhashTV[VCSIZE];
73 static struct afs_cbr *afs_cbrHashT[CBRSIZE];
74 afs_int32 afs_bulkStatsLost;
75 int afs_norefpanic = 0;
77 /* Forward declarations */
78 static afs_int32 afs_QueueVCB(struct vcache *avc);
83 * Generate an index into the hash table for a given Fid.
86 afs_HashCBRFid(struct AFSFid *fid)
88 return (fid->Volume + fid->Vnode + fid->Unique) % CBRSIZE;
94 * Insert a CBR entry into the hash table.
95 * Must be called with afs_xvcb held.
98 afs_InsertHashCBR(struct afs_cbr *cbr)
100 int slot = afs_HashCBRFid(&cbr->fid);
102 cbr->hash_next = afs_cbrHashT[slot];
103 if (afs_cbrHashT[slot])
104 afs_cbrHashT[slot]->hash_pprev = &cbr->hash_next;
106 cbr->hash_pprev = &afs_cbrHashT[slot];
107 afs_cbrHashT[slot] = cbr;
114 * Flush the given vcache entry.
117 * avc : Pointer to vcache entry to flush.
118 * slept : Pointer to int to set 1 if we sleep/drop locks, 0 if we don't.
121 * afs_xvcache lock must be held for writing upon entry to
122 * prevent people from changing the vrefCount field, and to
123 * protect the lruq and hnext fields.
124 * LOCK: afs_FlushVCache afs_xvcache W
125 * REFCNT: vcache ref count must be zero on entry except for osf1
126 * RACE: lock is dropped and reobtained, permitting race in caller
130 afs_FlushVCache(struct vcache *avc, int *slept)
131 { /*afs_FlushVCache */
133 afs_int32 i, code, j;
134 struct vcache **uvc, *wvc, **uvc2, *wvc2;
137 AFS_STATCNT(afs_FlushVCache);
138 afs_Trace2(afs_iclSetp, CM_TRACE_FLUSHV, ICL_TYPE_POINTER, avc,
139 ICL_TYPE_INT32, avc->states);
142 VN_LOCK(AFSTOV(avc));
146 code = osi_VM_FlushVCache(avc, slept);
150 if (avc->states & CVFlushed) {
154 if (avc->nextfree || !avc->vlruq.prev || !avc->vlruq.next) { /* qv afs.h */
155 refpanic("LRU vs. Free inconsistency");
157 avc->states |= CVFlushed;
158 /* pull the entry out of the lruq and put it on the free list */
159 QRemove(&avc->vlruq);
160 avc->vlruq.prev = avc->vlruq.next = (struct afs_q *)0;
162 /* keep track of # of files that we bulk stat'd, but never used
163 * before they got recycled.
165 if (avc->states & CBulkStat)
168 /* remove entry from the hash chain */
169 i = VCHash(&avc->fid);
170 uvc = &afs_vhashT[i];
171 for (wvc = *uvc; wvc; uvc = &wvc->hnext, wvc = *uvc) {
174 avc->hnext = (struct vcache *)NULL;
179 /* remove entry from the volume hash table */
180 j = VCHashV(&avc->fid);
181 uvc2 = &afs_vhashTV[j];
182 for (wvc2 = *uvc2; wvc2; uvc2 = &wvc2->vhnext, wvc2 = *uvc2) {
185 avc->vhnext = (struct vcache *)NULL;
190 osi_Panic("flushvcache"); /* not in correct hash bucket */
192 osi_FreeSmallSpace(avc->mvid);
193 avc->mvid = (struct VenusFid *)0;
195 afs_osi_Free(avc->linkData, strlen(avc->linkData) + 1);
196 avc->linkData = NULL;
198 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
199 /* OK, there are no internal vrefCounts, so there shouldn't
200 * be any more refs here. */
202 avc->v->v_data = NULL; /* remove from vnode */
203 avc->v = NULL; /* also drop the ptr to vnode */
206 afs_FreeAllAxs(&(avc->Access));
208 /* we can't really give back callbacks on RO files, since the
209 * server only tracks them on a per-volume basis, and we don't
210 * know whether we still have some other files from the same
212 if ((avc->states & CRO) == 0 && avc->callback) {
215 ObtainWriteLock(&afs_xcbhash, 460);
216 afs_DequeueCallback(avc); /* remove it from queued callbacks list */
217 avc->states &= ~(CStatd | CUnique);
218 ReleaseWriteLock(&afs_xcbhash);
219 afs_symhint_inval(avc);
220 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
221 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
223 osi_dnlc_purgevp(avc);
226 * Next, keep track of which vnodes we've deleted for create's
227 * optimistic synchronization algorithm
230 if (avc->fid.Fid.Vnode & 1)
235 #if !defined(AFS_OSF_ENV)
236 /* put the entry in the free list */
237 avc->nextfree = freeVCList;
239 if (avc->vlruq.prev || avc->vlruq.next) {
240 refpanic("LRU vs. Free inconsistency");
243 /* This should put it back on the vnode free list since usecount is 1 */
246 if (VREFCOUNT(avc) > 0) {
247 VN_UNLOCK(AFSTOV(avc));
248 AFS_RELE(AFSTOV(avc));
250 if (afs_norefpanic) {
251 printf("flush vc refcnt < 1");
253 (void)vgone(avc, VX_NOSLEEP, NULL);
255 VN_UNLOCK(AFSTOV(avc));
257 osi_Panic("flush vc refcnt < 1");
259 #endif /* AFS_OSF_ENV */
260 avc->states |= CVFlushed;
265 VN_UNLOCK(AFSTOV(avc));
269 } /*afs_FlushVCache */
275 * The core of the inactive vnode op for all but IRIX.
278 afs_InactiveVCache(struct vcache *avc, struct AFS_UCRED *acred)
280 AFS_STATCNT(afs_inactive);
281 if (avc->states & CDirty) {
282 /* we can't keep trying to push back dirty data forever. Give up. */
283 afs_InvalidateAllSegments(avc); /* turns off dirty bit */
285 avc->states &= ~CMAPPED; /* mainly used by SunOS 4.0.x */
286 avc->states &= ~CDirty; /* Turn it off */
287 if (avc->states & CUnlinked) {
288 if (CheckLock(&afs_xvcache) || CheckLock(&afs_xdcache)) {
289 avc->states |= CUnlinkedDel;
292 afs_remunlink(avc, 1); /* ignore any return code */
301 * Description: allocate a callback return structure from the
302 * free list and return it.
304 * Env: The alloc and free routines are both called with the afs_xvcb lock
305 * held, so we don't have to worry about blocking in osi_Alloc.
307 static struct afs_cbr *afs_cbrSpace = 0;
311 register struct afs_cbr *tsp;
314 while (!afs_cbrSpace) {
315 if (afs_stats_cmperf.CallBackAlloced >= 2) {
316 /* don't allocate more than 2 * AFS_NCBRS for now */
318 afs_stats_cmperf.CallBackFlushes++;
322 (struct afs_cbr *)afs_osi_Alloc(AFS_NCBRS *
323 sizeof(struct afs_cbr));
324 for (i = 0; i < AFS_NCBRS - 1; i++) {
325 tsp[i].next = &tsp[i + 1];
327 tsp[AFS_NCBRS - 1].next = 0;
329 afs_stats_cmperf.CallBackAlloced++;
333 afs_cbrSpace = tsp->next;
340 * Description: free a callback return structure, removing it from all lists.
343 * asp -- the address of the structure to free.
345 * Environment: the xvcb lock is held over these calls.
348 afs_FreeCBR(register struct afs_cbr *asp)
350 *(asp->pprev) = asp->next;
352 asp->next->pprev = asp->pprev;
354 *(asp->hash_pprev) = asp->hash_next;
356 asp->hash_next->hash_pprev = asp->hash_pprev;
358 asp->next = afs_cbrSpace;
366 * Description: flush all queued callbacks to all servers.
370 * Environment: holds xvcb lock over RPC to guard against race conditions
371 * when a new callback is granted for the same file later on.
374 afs_FlushVCBs(afs_int32 lockit)
376 struct AFSFid *tfids;
377 struct AFSCallBack callBacks[1];
378 struct AFSCBFids fidArray;
379 struct AFSCBs cbArray;
381 struct afs_cbr *tcbrp;
385 struct vrequest treq;
387 int safety1, safety2, safety3;
389 if ((code = afs_InitReq(&treq, afs_osi_credp)))
391 treq.flags |= O_NONBLOCK;
392 tfids = afs_osi_Alloc(sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
395 MObtainWriteLock(&afs_xvcb, 273);
396 ObtainReadLock(&afs_xserver);
397 for (i = 0; i < NSERVERS; i++) {
398 for (safety1 = 0, tsp = afs_servers[i];
399 tsp && safety1 < afs_totalServers + 10;
400 tsp = tsp->next, safety1++) {
402 if (tsp->cbrs == (struct afs_cbr *)0)
405 /* otherwise, grab a block of AFS_MAXCBRSCALL from the list
406 * and make an RPC, over and over again.
408 tcount = 0; /* number found so far */
409 for (safety2 = 0; safety2 < afs_cacheStats; safety2++) {
410 if (tcount >= AFS_MAXCBRSCALL || !tsp->cbrs) {
411 /* if buffer is full, or we've queued all we're going
412 * to from this server, we should flush out the
415 fidArray.AFSCBFids_len = tcount;
416 fidArray.AFSCBFids_val = (struct AFSFid *)tfids;
417 cbArray.AFSCBs_len = 1;
418 cbArray.AFSCBs_val = callBacks;
419 memset(&callBacks[0], 0, sizeof(callBacks[0]));
420 callBacks[0].CallBackType = CB_EXCLUSIVE;
421 for (safety3 = 0; safety3 < MAXHOSTS * 2; safety3++) {
422 tc = afs_ConnByHost(tsp, tsp->cell->fsport,
423 tsp->cell->cellNum, &treq, 0,
427 (AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS);
430 RXAFS_GiveUpCallBacks(tc->id, &fidArray,
438 AFS_STATS_FS_RPCIDX_GIVEUPCALLBACKS, SHARED_LOCK,
443 /* ignore return code, since callbacks may have
444 * been returned anyway, we shouldn't leave them
445 * around to be returned again.
447 * Next, see if we are done with this server, and if so,
448 * break to deal with the next one.
454 /* if to flush full buffer */
455 /* if we make it here, we have an entry at the head of cbrs,
456 * which we should copy to the file ID array and then free.
459 tfids[tcount++] = tcbrp->fid;
461 /* Freeing the CBR will unlink it from the server's CBR list */
463 } /* while loop for this one server */
464 if (safety2 > afs_cacheStats) {
465 afs_warn("possible internal error afs_flushVCBs (%d)\n",
468 } /* for loop for this hash chain */
469 } /* loop through all hash chains */
470 if (safety1 > afs_totalServers + 2) {
472 ("AFS internal error (afs_flushVCBs) (%d > %d), continuing...\n",
473 safety1, afs_totalServers + 2);
475 osi_Panic("afs_flushVCBS safety1");
478 ReleaseReadLock(&afs_xserver);
480 MReleaseWriteLock(&afs_xvcb);
481 afs_osi_Free(tfids, sizeof(struct AFSFid) * AFS_MAXCBRSCALL);
489 * Queue a callback on the given fid.
495 * Locks the xvcb lock.
496 * Called when the xvcache lock is already held.
500 afs_QueueVCB(struct vcache *avc)
503 struct afs_cbr *tcbp;
505 AFS_STATCNT(afs_QueueVCB);
506 /* The callback is really just a struct server ptr. */
507 tsp = (struct server *)(avc->callback);
509 /* we now have a pointer to the server, so we just allocate
510 * a queue entry and queue it.
512 MObtainWriteLock(&afs_xvcb, 274);
513 tcbp = afs_AllocCBR();
514 tcbp->fid = avc->fid.Fid;
516 tcbp->next = tsp->cbrs;
518 tsp->cbrs->pprev = &tcbp->next;
521 tcbp->pprev = &tsp->cbrs;
523 afs_InsertHashCBR(tcbp);
525 /* now release locks and return */
526 MReleaseWriteLock(&afs_xvcb);
535 * Remove a queued callback for a given Fid.
538 * afid: The fid we want cleansed of queued callbacks.
541 * Locks xvcb and xserver locks.
542 * Typically called with xdcache, xvcache and/or individual vcache
547 afs_RemoveVCB(struct VenusFid *afid)
550 struct afs_cbr *cbr, *ncbr;
552 AFS_STATCNT(afs_RemoveVCB);
553 MObtainWriteLock(&afs_xvcb, 275);
555 slot = afs_HashCBRFid(&afid->Fid);
556 ncbr = afs_cbrHashT[slot];
560 ncbr = cbr->hash_next;
562 if (afid->Fid.Volume == cbr->fid.Volume &&
563 afid->Fid.Vnode == cbr->fid.Vnode &&
564 afid->Fid.Unique == cbr->fid.Unique) {
569 MReleaseWriteLock(&afs_xvcb);
576 * This routine is responsible for allocating a new cache entry
577 * from the free list. It formats the cache entry and inserts it
578 * into the appropriate hash tables. It must be called with
579 * afs_xvcache write-locked so as to prevent several processes from
580 * trying to create a new cache entry simultaneously.
583 * afid : The file id of the file whose cache entry is being
586 /* LOCK: afs_NewVCache afs_xvcache W */
588 afs_NewVCache(struct VenusFid *afid, struct server *serverp)
592 afs_int32 anumber = VCACHE_FREE;
594 struct gnode *gnodepnt;
598 #endif /* AFS_OSF_ENV */
599 struct afs_q *tq, *uq;
602 AFS_STATCNT(afs_NewVCache);
605 if (afs_vcount >= afs_maxvcount) {
608 * If we are using > 33 % of the total system vnodes for AFS vcache
609 * entries or we are using the maximum number of vcache entries,
610 * then free some. (if our usage is > 33% we should free some, if
611 * our usage is > afs_maxvcount, set elsewhere to 0.5*nvnode,
612 * we _must_ free some -- no choice).
614 if (((3 * afs_vcount) > nvnode) || (afs_vcount >= afs_maxvcount)) {
616 struct afs_q *tq, *uq;
621 for (tq = VLRU.prev; tq != &VLRU && anumber > 0; tq = uq) {
624 if (tvc->states & CVFlushed)
625 refpanic("CVFlushed on VLRU");
626 else if (i++ > afs_maxvcount)
627 refpanic("Exceeded pool of AFS vnodes(VLRU cycle?)");
628 else if (QNext(uq) != tq)
629 refpanic("VLRU inconsistent");
630 else if (VREFCOUNT(tvc) < 1)
631 refpanic("refcnt 0 on VLRU");
633 if (VREFCOUNT(tvc) == 1 && tvc->opens == 0
634 && (tvc->states & CUnlinkedDel) == 0) {
635 code = afs_FlushVCache(tvc, &fv_slept);
642 continue; /* start over - may have raced. */
648 if (anumber == VCACHE_FREE) {
649 printf("NewVCache: warning none freed, using %d of %d\n",
650 afs_vcount, afs_maxvcount);
651 if (afs_vcount >= afs_maxvcount) {
652 osi_Panic("NewVCache - none freed");
653 /* XXX instead of panicing, should do afs_maxvcount++
654 * and magic up another one */
660 if (getnewvnode(MOUNT_AFS, &Afs_vnodeops, &nvc)) {
661 /* What should we do ???? */
662 osi_Panic("afs_NewVCache: no more vnodes");
667 tvc->nextfree = NULL;
669 #else /* AFS_OSF_ENV */
670 /* pull out a free cache entry */
673 for (tq = VLRU.prev; (anumber > 0) && (tq != &VLRU); tq = uq) {
677 if (tvc->states & CVFlushed) {
678 refpanic("CVFlushed on VLRU");
680 } else if (i++ > 2 * afs_cacheStats) { /* even allowing for a few xallocs... */
681 refpanic("Increase -stat parameter of afsd(VLRU cycle?)");
683 } else if (QNext(uq) != tq) {
684 refpanic("VLRU inconsistent");
686 #if defined(AFS_LINUX22_ENV)
687 if (tvc != afs_globalVp && VREFCOUNT(tvc) && tvc->opens == 0) {
688 struct dentry *dentry;
689 struct list_head *cur, *head = &(AFSTOI(tvc))->i_dentry;
694 #if defined(AFS_LINUX24_ENV)
695 spin_lock(&dcache_lock);
698 while ((cur = cur->next) != head) {
699 dentry = list_entry(cur, struct dentry, d_alias);
701 if (d_unhashed(dentry))
706 #if defined(AFS_LINUX24_ENV)
707 spin_unlock(&dcache_lock);
709 if (d_invalidate(dentry) == -EBUSY) {
711 /* perhaps lock and try to continue? (use cur as head?) */
717 #if defined(AFS_LINUX24_ENV)
718 spin_unlock(&dcache_lock);
726 if (((VREFCOUNT(tvc) == 0)
727 #if defined(AFS_DARWIN_ENV) && !defined(UKERNEL)
728 || ((VREFCOUNT(tvc) == 1) &&
729 (UBCINFOEXISTS(AFSTOV(tvc))))
731 ) && tvc->opens == 0 && (tvc->states & CUnlinkedDel) == 0) {
732 #if defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
734 * vgone() reclaims the vnode, which calls afs_FlushVCache(),
735 * then it puts the vnode on the free list.
736 * If we don't do this we end up with a cleaned vnode that's
737 * not on the free list.
738 * XXX assume FreeBSD is the same for now.
745 code = afs_FlushVCache(tvc, &fv_slept);
753 continue; /* start over - may have raced. */
761 /* none free, making one is better than a panic */
762 afs_stats_cmperf.vcacheXAllocs++; /* count in case we have a leak */
763 if (afs_cacheStats == afs_stats_cmperf.vcacheXAllocs) printf("would vlru cycle panic\n");
764 tvc = (struct vcache *)afs_osi_Alloc(sizeof(struct vcache));
765 #if defined(AFS_DARWIN_ENV) && !defined(UKERNEL)
766 tvc->v = NULL; /* important to clean this, or use memset 0 */
768 #ifdef KERNEL_HAVE_PIN
769 pin((char *)tvc, sizeof(struct vcache)); /* XXX */
771 #if defined(AFS_SGI_ENV)
773 char name[METER_NAMSZ];
774 memset(tvc, 0, sizeof(struct vcache));
775 tvc->v.v_number = ++afsvnumbers;
776 tvc->vc_rwlockid = OSI_NO_LOCKID;
777 initnsema(&tvc->vc_rwlock, 1,
778 makesname(name, "vrw", tvc->v.v_number));
779 #ifndef AFS_SGI53_ENV
780 initnsema(&tvc->v.v_sync, 0,
781 makesname(name, "vsy", tvc->v.v_number));
783 #ifndef AFS_SGI62_ENV
784 initnlock(&tvc->v.v_lock,
785 makesname(name, "vlk", tvc->v.v_number));
788 #endif /* AFS_SGI_ENV */
790 tvc = freeVCList; /* take from free list */
791 freeVCList = tvc->nextfree;
792 tvc->nextfree = NULL;
794 #endif /* AFS_OSF_ENV */
796 #if defined(AFS_XBSD_ENV) || defined(AFS_DARWIN_ENV)
798 panic("afs_NewVCache(): free vcache with vnode attached");
801 #if !defined(AFS_SGI_ENV) && !defined(AFS_OSF_ENV)
802 memset((char *)tvc, 0, sizeof(struct vcache));
807 RWLOCK_INIT(&tvc->lock, "vcache lock");
808 #if defined(AFS_SUN5_ENV)
809 RWLOCK_INIT(&tvc->vlock, "vcache vlock");
810 #endif /* defined(AFS_SUN5_ENV) */
814 afs_nbsd_getnewvnode(tvc); /* includes one refcount */
816 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
818 #ifdef AFS_DARWIN_ENV
820 afs_darwin_getnewvnode(tvc); /* includes one refcount */
822 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
829 #if defined(AFS_FBSD60_ENV)
830 if (getnewvnode(MOUNT_AFS, afs_globalVFS, &afs_vnodeops, &vp))
831 #elif defined(AFS_FBSD50_ENV)
832 if (getnewvnode(MOUNT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
834 if (getnewvnode(VT_AFS, afs_globalVFS, afs_vnodeop_p, &vp))
836 panic("afs getnewvnode"); /* can't happen */
838 if (tvc->v != NULL) {
839 /* I'd like to know if this ever happens...
840 * We don't drop global for the rest of this function,
841 * so if we do lose the race, the other thread should
842 * have found the same vnode and finished initializing
843 * the vcache entry. Is it conceivable that this vcache
844 * entry could be recycled during this interval? If so,
845 * then there probably needs to be some sort of additional
846 * mutual exclusion (an Embryonic flag would suffice).
848 printf("afs_NewVCache: lost the race\n");
852 tvc->v->v_data = tvc;
853 lockinit(&tvc->rwlock, PINOD, "vcache", 0, 0);
856 tvc->parentVnode = 0;
858 tvc->linkData = NULL;
861 tvc->execsOrWriters = 0;
865 tvc->last_looker = 0;
867 tvc->asynchrony = -1;
869 afs_symhint_inval(tvc);
871 tvc->flushDV.low = tvc->flushDV.high = AFS_MAXDV;
874 tvc->truncPos = AFS_NOTRUNC; /* don't truncate until we need to */
875 hzero(tvc->m.DataVersion); /* in case we copy it into flushDV */
876 #if defined(AFS_LINUX22_ENV)
878 struct inode *ip = AFSTOI(tvc);
879 #if defined(AFS_LINUX24_ENV)
880 struct address_space *mapping = &ip->i_data;
883 #if defined(AFS_LINUX26_ENV)
886 sema_init(&ip->i_sem, 1);
887 INIT_LIST_HEAD(&ip->i_hash);
888 INIT_LIST_HEAD(&ip->i_dentry);
889 #if defined(AFS_LINUX24_ENV)
890 sema_init(&ip->i_zombie, 1);
891 init_waitqueue_head(&ip->i_wait);
892 spin_lock_init(&ip->i_data.i_shared_lock);
893 #ifdef STRUCT_ADDRESS_SPACE_HAS_PAGE_LOCK
894 spin_lock_init(&ip->i_data.page_lock);
896 INIT_LIST_HEAD(&ip->i_data.clean_pages);
897 INIT_LIST_HEAD(&ip->i_data.dirty_pages);
898 INIT_LIST_HEAD(&ip->i_data.locked_pages);
899 INIT_LIST_HEAD(&ip->i_dirty_buffers);
900 #ifdef STRUCT_INODE_HAS_I_DIRTY_DATA_BUFFERS
901 INIT_LIST_HEAD(&ip->i_dirty_data_buffers);
903 #ifdef STRUCT_INODE_HAS_I_DEVICES
904 INIT_LIST_HEAD(&ip->i_devices);
906 #ifdef STRUCT_INODE_HAS_I_TRUNCATE_SEM
907 init_rwsem(&ip->i_truncate_sem);
909 #ifdef STRUCT_INODE_HAS_I_ALLOC_SEM
910 init_rwsem(&ip->i_alloc_sem);
913 #else /* AFS_LINUX22_ENV */
914 sema_init(&ip->i_atomic_write, 1);
915 init_waitqueue(&ip->i_wait);
919 #if defined(AFS_LINUX24_ENV)
921 ip->i_mapping = mapping;
922 #ifdef STRUCT_ADDRESS_SPACE_HAS_GFP_MASK
923 ip->i_data.gfp_mask = GFP_HIGHUSER;
925 #if defined(AFS_LINUX26_ENV)
926 mapping_set_gfp_mask(mapping, GFP_HIGHUSER);
928 extern struct backing_dev_info afs_backing_dev_info;
930 mapping->backing_dev_info = &afs_backing_dev_info;
935 #if !defined(AFS_LINUX26_ENV)
937 ip->i_dev = afs_globalVFS->s_dev;
939 #ifdef STRUCT_INODE_HAS_I_SECURITY
940 ip->i_security = NULL;
941 if (security_inode_alloc(ip))
942 panic("Cannot allocate inode security");
945 ip->i_sb = afs_globalVFS;
946 put_inode_on_dummy_list(ip);
947 #ifdef STRUCT_INODE_HAS_I_SB_LIST
948 list_add(&ip->i_sb_list, &ip->i_sb->s_inodes);
950 #if defined(STRUCT_INODE_HAS_INOTIFY_LOCK) || defined(STRUCT_INODE_HAS_INOTIFY_SEM)
951 INIT_LIST_HEAD(&ip->inotify_watches);
952 #if defined(STRUCT_INODE_HAS_INOTIFY_SEM)
953 sema_init(&ip->inotify_sem, 1);
955 spin_lock_init(&ip->inotify_lock);
962 /* Hold it for the LRU (should make count 2) */
963 VN_HOLD(AFSTOV(tvc));
964 #else /* AFS_OSF_ENV */
965 #if !(defined (AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV))
966 VREFCOUNT_SET(tvc, 1); /* us */
967 #endif /* AFS_XBSD_ENV */
968 #endif /* AFS_OSF_ENV */
970 LOCK_INIT(&tvc->pvmlock, "vcache pvmlock");
971 tvc->vmh = tvc->segid = NULL;
974 #ifdef AFS_BOZONLOCK_ENV
975 #if defined(AFS_SUN5_ENV)
976 rw_init(&tvc->rwlock, "vcache rwlock", RW_DEFAULT, NULL);
978 #if defined(AFS_SUN55_ENV)
979 /* This is required if the kaio (kernel aynchronous io)
980 ** module is installed. Inside the kernel, the function
981 ** check_vp( common/os/aio.c) checks to see if the kernel has
982 ** to provide asynchronous io for this vnode. This
983 ** function extracts the device number by following the
984 ** v_data field of the vnode. If we do not set this field
985 ** then the system panics. The value of the v_data field
986 ** is not really important for AFS vnodes because the kernel
987 ** does not do asynchronous io for regular files. Hence,
988 ** for the time being, we fill up the v_data field with the
989 ** vnode pointer itself. */
990 tvc->v.v_data = (char *)tvc;
991 #endif /* AFS_SUN55_ENV */
993 afs_BozonInit(&tvc->pvnLock, tvc);
997 tvc->callback = serverp; /* to minimize chance that clear
999 /* initialize vnode data, note vrefCount is v.v_count */
1001 /* Don't forget to free the gnode space */
1002 tvc->v.v_gnode = gnodepnt =
1003 (struct gnode *)osi_AllocSmallSpace(sizeof(struct gnode));
1004 memset((char *)gnodepnt, 0, sizeof(struct gnode));
1006 #ifdef AFS_SGI64_ENV
1007 memset((void *)&(tvc->vc_bhv_desc), 0, sizeof(tvc->vc_bhv_desc));
1008 bhv_desc_init(&(tvc->vc_bhv_desc), tvc, tvc, &Afs_vnodeops);
1009 #ifdef AFS_SGI65_ENV
1010 vn_bhv_head_init(&(tvc->v.v_bh), "afsvp");
1011 vn_bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1013 bhv_head_init(&(tvc->v.v_bh));
1014 bhv_insert_initial(&(tvc->v.v_bh), &(tvc->vc_bhv_desc));
1016 #ifdef AFS_SGI65_ENV
1017 tvc->v.v_mreg = tvc->v.v_mregb = (struct pregion *)tvc;
1018 #ifdef VNODE_TRACING
1019 tvc->v.v_trace = ktrace_alloc(VNODE_TRACE_SIZE, 0);
1021 init_bitlock(&tvc->v.v_pcacheflag, VNODE_PCACHE_LOCKBIT, "afs_pcache",
1023 init_mutex(&tvc->v.v_filocksem, MUTEX_DEFAULT, "afsvfl", (long)tvc);
1024 init_mutex(&tvc->v.v_buf_lock, MUTEX_DEFAULT, "afsvnbuf", (long)tvc);
1026 vnode_pcache_init(&tvc->v);
1027 #if defined(DEBUG) && defined(VNODE_INIT_BITLOCK)
1028 /* Above define is never true execpt in SGI test kernels. */
1029 init_bitlock(&(tvc->v.v_flag, VLOCK, "vnode", tvc->v.v_number);
1031 #ifdef INTR_KTHREADS
1032 AFS_VN_INIT_BUF_LOCK(&(tvc->v));
1035 SetAfsVnode(AFSTOV(tvc));
1036 #endif /* AFS_SGI64_ENV */
1038 * The proper value for mvstat (for root fids) is setup by the caller.
1041 if (afid->Fid.Vnode == 1 && afid->Fid.Unique == 1)
1043 if (afs_globalVFS == 0)
1044 osi_Panic("afs globalvfs");
1045 vSetVfsp(tvc, afs_globalVFS);
1046 vSetType(tvc, VREG);
1048 tvc->v.v_vfsnext = afs_globalVFS->vfs_vnodes; /* link off vfs */
1049 tvc->v.v_vfsprev = NULL;
1050 afs_globalVFS->vfs_vnodes = &tvc->v;
1051 if (tvc->v.v_vfsnext != NULL)
1052 tvc->v.v_vfsnext->v_vfsprev = &tvc->v;
1053 tvc->v.v_next = gnodepnt->gn_vnode; /*Single vnode per gnode for us! */
1054 gnodepnt->gn_vnode = &tvc->v;
1056 #if defined(AFS_DUX40_ENV)
1057 insmntque(tvc, afs_globalVFS, &afs_ubcops);
1060 /* Is this needed??? */
1061 insmntque(tvc, afs_globalVFS);
1062 #endif /* AFS_OSF_ENV */
1063 #endif /* AFS_DUX40_ENV */
1064 #if defined(AFS_SGI_ENV)
1065 VN_SET_DPAGES(&(tvc->v), (struct pfdat *)NULL);
1066 osi_Assert((tvc->v.v_flag & VINACT) == 0);
1068 osi_Assert(VN_GET_PGCNT(&(tvc->v)) == 0);
1069 osi_Assert(tvc->mapcnt == 0 && tvc->vc_locktrips == 0);
1070 osi_Assert(tvc->vc_rwlockid == OSI_NO_LOCKID);
1071 osi_Assert(tvc->v.v_filocks == NULL);
1072 #if !defined(AFS_SGI65_ENV)
1073 osi_Assert(tvc->v.v_filocksem == NULL);
1075 osi_Assert(tvc->cred == NULL);
1076 #ifdef AFS_SGI64_ENV
1077 vnode_pcache_reinit(&tvc->v);
1078 tvc->v.v_rdev = NODEV;
1080 vn_initlist((struct vnlist *)&tvc->v);
1082 #endif /* AFS_SGI_ENV */
1084 osi_dnlc_purgedp(tvc); /* this may be overkill */
1085 memset((char *)&(tvc->quick), 0, sizeof(struct vtodc));
1086 memset((char *)&(tvc->callsort), 0, sizeof(struct afs_q));
1091 tvc->hnext = afs_vhashT[i];
1092 tvc->vhnext = afs_vhashTV[j];
1093 afs_vhashT[i] = afs_vhashTV[j] = tvc;
1095 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1096 refpanic("NewVCache VLRU inconsistent");
1098 QAdd(&VLRU, &tvc->vlruq); /* put in lruq */
1099 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1100 refpanic("NewVCache VLRU inconsistent2");
1102 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
1103 refpanic("NewVCache VLRU inconsistent3");
1105 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
1106 refpanic("NewVCache VLRU inconsistent4");
1112 } /*afs_NewVCache */
1116 * afs_FlushActiveVcaches
1122 * doflocks : Do we handle flocks?
1124 /* LOCK: afs_FlushActiveVcaches afs_xvcache N */
1126 afs_FlushActiveVcaches(register afs_int32 doflocks)
1128 register struct vcache *tvc;
1130 register struct conn *tc;
1131 register afs_int32 code;
1132 register struct AFS_UCRED *cred = NULL;
1133 struct vrequest treq, ureq;
1134 struct AFSVolSync tsync;
1137 AFS_STATCNT(afs_FlushActiveVcaches);
1138 ObtainReadLock(&afs_xvcache);
1139 for (i = 0; i < VCSIZE; i++) {
1140 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
1141 if (doflocks && tvc->flockCount != 0) {
1142 /* if this entry has an flock, send a keep-alive call out */
1144 ReleaseReadLock(&afs_xvcache);
1145 ObtainWriteLock(&tvc->lock, 51);
1147 afs_InitReq(&treq, afs_osi_credp);
1148 treq.flags |= O_NONBLOCK;
1150 tc = afs_Conn(&tvc->fid, &treq, SHARED_LOCK);
1152 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_EXTENDLOCK);
1155 RXAFS_ExtendLock(tc->id,
1156 (struct AFSFid *)&tvc->fid.Fid,
1162 } while (afs_Analyze
1163 (tc, code, &tvc->fid, &treq,
1164 AFS_STATS_FS_RPCIDX_EXTENDLOCK, SHARED_LOCK, NULL));
1166 ReleaseWriteLock(&tvc->lock);
1167 ObtainReadLock(&afs_xvcache);
1171 if ((tvc->states & CCore) || (tvc->states & CUnlinkedDel)) {
1173 * Don't let it evaporate in case someone else is in
1174 * this code. Also, drop the afs_xvcache lock while
1175 * getting vcache locks.
1178 ReleaseReadLock(&afs_xvcache);
1179 #ifdef AFS_BOZONLOCK_ENV
1180 afs_BozonLock(&tvc->pvnLock, tvc);
1182 #if defined(AFS_SGI_ENV)
1184 * That's because if we come in via the CUnlinkedDel bit state path we'll be have 0 refcnt
1186 osi_Assert(VREFCOUNT(tvc) > 0);
1187 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1189 ObtainWriteLock(&tvc->lock, 52);
1190 if (tvc->states & CCore) {
1191 tvc->states &= ~CCore;
1192 /* XXXX Find better place-holder for cred XXXX */
1193 cred = (struct AFS_UCRED *)tvc->linkData;
1194 tvc->linkData = NULL; /* XXX */
1195 afs_InitReq(&ureq, cred);
1196 afs_Trace2(afs_iclSetp, CM_TRACE_ACTCCORE,
1197 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32,
1198 tvc->execsOrWriters);
1199 code = afs_StoreOnLastReference(tvc, &ureq);
1200 ReleaseWriteLock(&tvc->lock);
1201 #ifdef AFS_BOZONLOCK_ENV
1202 afs_BozonUnlock(&tvc->pvnLock, tvc);
1204 hzero(tvc->flushDV);
1207 if (code && code != VNOVNODE) {
1208 afs_StoreWarn(code, tvc->fid.Fid.Volume,
1209 /* /dev/console */ 1);
1211 } else if (tvc->states & CUnlinkedDel) {
1215 ReleaseWriteLock(&tvc->lock);
1216 #ifdef AFS_BOZONLOCK_ENV
1217 afs_BozonUnlock(&tvc->pvnLock, tvc);
1219 #if defined(AFS_SGI_ENV)
1220 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1222 afs_remunlink(tvc, 0);
1223 #if defined(AFS_SGI_ENV)
1224 AFS_RWLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1227 /* lost (or won, perhaps) the race condition */
1228 ReleaseWriteLock(&tvc->lock);
1229 #ifdef AFS_BOZONLOCK_ENV
1230 afs_BozonUnlock(&tvc->pvnLock, tvc);
1233 #if defined(AFS_SGI_ENV)
1234 AFS_RWUNLOCK((vnode_t *) tvc, VRWLOCK_WRITE);
1236 ObtainReadLock(&afs_xvcache);
1239 AFS_RELE(AFSTOV(tvc));
1240 /* Matches write code setting CCore flag */
1246 ReleaseReadLock(&afs_xvcache);
1254 * Make sure a cache entry is up-to-date status-wise.
1256 * NOTE: everywhere that calls this can potentially be sped up
1257 * by checking CStatd first, and avoiding doing the InitReq
1258 * if this is up-to-date.
1260 * Anymore, the only places that call this KNOW already that the
1261 * vcache is not up-to-date, so we don't screw around.
1264 * avc : Ptr to vcache entry to verify.
1269 afs_VerifyVCache2(struct vcache *avc, struct vrequest *areq)
1271 register struct vcache *tvc;
1273 AFS_STATCNT(afs_VerifyVCache);
1275 #if defined(AFS_OSF_ENV)
1276 ObtainReadLock(&avc->lock);
1277 if (afs_IsWired(avc)) {
1278 ReleaseReadLock(&avc->lock);
1281 ReleaseReadLock(&avc->lock);
1282 #endif /* AFS_OSF_ENV */
1283 /* otherwise we must fetch the status info */
1285 ObtainWriteLock(&avc->lock, 53);
1286 if (avc->states & CStatd) {
1287 ReleaseWriteLock(&avc->lock);
1290 ObtainWriteLock(&afs_xcbhash, 461);
1291 avc->states &= ~(CStatd | CUnique);
1292 avc->callback = NULL;
1293 afs_DequeueCallback(avc);
1294 ReleaseWriteLock(&afs_xcbhash);
1295 ReleaseWriteLock(&avc->lock);
1297 /* since we've been called back, or the callback has expired,
1298 * it's possible that the contents of this directory, or this
1299 * file's name have changed, thus invalidating the dnlc contents.
1301 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1302 osi_dnlc_purgedp(avc);
1304 osi_dnlc_purgevp(avc);
1306 /* fetch the status info */
1307 tvc = afs_GetVCache(&avc->fid, areq, NULL, avc);
1310 /* Put it back; caller has already incremented vrefCount */
1314 } /*afs_VerifyVCache */
1321 * Simple copy of stat info into cache.
1324 * avc : Ptr to vcache entry involved.
1325 * astat : Ptr to stat info to copy.
1328 * Nothing interesting.
1330 * Callers: as of 1992-04-29, only called by WriteVCache
1333 afs_SimpleVStat(register struct vcache *avc,
1334 register struct AFSFetchStatus *astat, struct vrequest *areq)
1337 AFS_STATCNT(afs_SimpleVStat);
1340 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1341 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1343 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1345 #ifdef AFS_64BIT_CLIENT
1346 FillInt64(length, astat->Length_hi, astat->Length);
1347 #else /* AFS_64BIT_CLIENT */
1348 length = astat->Length;
1349 #endif /* AFS_64BIT_CLIENT */
1350 #if defined(AFS_SGI_ENV)
1351 osi_Assert((valusema(&avc->vc_rwlock) <= 0)
1352 && (OSI_GET_LOCKID() == avc->vc_rwlockid));
1353 if (length < avc->m.Length) {
1354 vnode_t *vp = (vnode_t *) avc;
1356 osi_Assert(WriteLocked(&avc->lock));
1357 ReleaseWriteLock(&avc->lock);
1359 PTOSSVP(vp, (off_t) length, (off_t) MAXLONG);
1361 ObtainWriteLock(&avc->lock, 67);
1364 /* if writing the file, don't fetch over this value */
1365 afs_Trace3(afs_iclSetp, CM_TRACE_SIMPLEVSTAT, ICL_TYPE_POINTER, avc,
1366 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1367 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1368 avc->m.Length = length;
1369 avc->m.Date = astat->ClientModTime;
1371 avc->m.Owner = astat->Owner;
1372 avc->m.Group = astat->Group;
1373 avc->m.Mode = astat->UnixModeBits;
1374 if (vType(avc) == VREG) {
1375 avc->m.Mode |= S_IFREG;
1376 } else if (vType(avc) == VDIR) {
1377 avc->m.Mode |= S_IFDIR;
1378 } else if (vType(avc) == VLNK) {
1379 avc->m.Mode |= S_IFLNK;
1380 if ((avc->m.Mode & 0111) == 0)
1383 if (avc->states & CForeign) {
1384 struct axscache *ac;
1385 avc->anyAccess = astat->AnonymousAccess;
1387 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1389 * Caller has at least one bit not covered by anonymous, and
1390 * thus may have interesting rights.
1392 * HOWEVER, this is a really bad idea, because any access query
1393 * for bits which aren't covered by anonymous, on behalf of a user
1394 * who doesn't have any special rights, will result in an answer of
1395 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1396 * It's an especially bad idea under Ultrix, since (due to the lack of
1397 * a proper access() call) it must perform several afs_access() calls
1398 * in order to create magic mode bits that vary according to who makes
1399 * the call. In other words, _every_ stat() generates a test for
1402 #endif /* badidea */
1403 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1404 ac->axess = astat->CallerAccess;
1405 else /* not found, add a new one if possible */
1406 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1410 } /*afs_SimpleVStat */
1417 * Store the status info *only* back to the server for a
1421 * avc : Ptr to the vcache entry.
1422 * astatus : Ptr to the status info to store.
1423 * areq : Ptr to the associated vrequest.
1426 * Must be called with a shared lock held on the vnode.
1430 afs_WriteVCache(register struct vcache *avc,
1431 register struct AFSStoreStatus *astatus,
1432 struct vrequest *areq)
1436 struct AFSFetchStatus OutStatus;
1437 struct AFSVolSync tsync;
1439 AFS_STATCNT(afs_WriteVCache);
1440 afs_Trace2(afs_iclSetp, CM_TRACE_WVCACHE, ICL_TYPE_POINTER, avc,
1441 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length));
1444 tc = afs_Conn(&avc->fid, areq, SHARED_LOCK);
1446 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
1449 RXAFS_StoreStatus(tc->id, (struct AFSFid *)&avc->fid.Fid,
1450 astatus, &OutStatus, &tsync);
1455 } while (afs_Analyze
1456 (tc, code, &avc->fid, areq, AFS_STATS_FS_RPCIDX_STORESTATUS,
1457 SHARED_LOCK, NULL));
1459 UpgradeSToWLock(&avc->lock, 20);
1461 /* success, do the changes locally */
1462 afs_SimpleVStat(avc, &OutStatus, areq);
1464 * Update the date, too. SimpleVStat didn't do this, since
1465 * it thought we were doing this after fetching new status
1466 * over a file being written.
1468 avc->m.Date = OutStatus.ClientModTime;
1470 /* failure, set up to check with server next time */
1471 ObtainWriteLock(&afs_xcbhash, 462);
1472 afs_DequeueCallback(avc);
1473 avc->states &= ~(CStatd | CUnique); /* turn off stat valid flag */
1474 ReleaseWriteLock(&afs_xcbhash);
1475 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
1476 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
1478 ConvertWToSLock(&avc->lock);
1481 } /*afs_WriteVCache */
1487 * Copy astat block into vcache info
1490 * avc : Ptr to vcache entry.
1491 * astat : Ptr to stat block to copy in.
1492 * areq : Ptr to associated request.
1495 * Must be called under a write lock
1497 * Note: this code may get dataversion and length out of sync if the file has
1498 * been modified. This is less than ideal. I haven't thought about
1499 * it sufficiently to be certain that it is adequate.
1502 afs_ProcessFS(register struct vcache *avc,
1503 register struct AFSFetchStatus *astat, struct vrequest *areq)
1506 AFS_STATCNT(afs_ProcessFS);
1508 #ifdef AFS_64BIT_CLIENT
1509 FillInt64(length, astat->Length_hi, astat->Length);
1510 #else /* AFS_64BIT_CLIENT */
1511 length = astat->Length;
1512 #endif /* AFS_64BIT_CLIENT */
1513 /* WARNING: afs_DoBulkStat uses the Length field to store a sequence
1514 * number for each bulk status request. Under no circumstances
1515 * should afs_DoBulkStat store a sequence number if the new
1516 * length will be ignored when afs_ProcessFS is called with
1517 * new stats. If you change the following conditional then you
1518 * also need to change the conditional in afs_DoBulkStat. */
1520 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)
1521 && !AFS_VN_MAPPED((vnode_t *) avc)) {
1523 if ((avc->execsOrWriters <= 0) && !afs_DirtyPages(avc)) {
1525 /* if we're writing or mapping this file, don't fetch over these
1528 afs_Trace3(afs_iclSetp, CM_TRACE_PROCESSFS, ICL_TYPE_POINTER, avc,
1529 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(avc->m.Length),
1530 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(length));
1531 avc->m.Length = length;
1532 avc->m.Date = astat->ClientModTime;
1534 hset64(avc->m.DataVersion, astat->dataVersionHigh, astat->DataVersion);
1535 avc->m.Owner = astat->Owner;
1536 avc->m.Mode = astat->UnixModeBits;
1537 avc->m.Group = astat->Group;
1538 avc->m.LinkCount = astat->LinkCount;
1539 if (astat->FileType == File) {
1540 vSetType(avc, VREG);
1541 avc->m.Mode |= S_IFREG;
1542 } else if (astat->FileType == Directory) {
1543 vSetType(avc, VDIR);
1544 avc->m.Mode |= S_IFDIR;
1545 } else if (astat->FileType == SymbolicLink) {
1546 if (afs_fakestat_enable && (avc->m.Mode & 0111) == 0) {
1547 vSetType(avc, VDIR);
1548 avc->m.Mode |= S_IFDIR;
1550 vSetType(avc, VLNK);
1551 avc->m.Mode |= S_IFLNK;
1553 if ((avc->m.Mode & 0111) == 0) {
1557 avc->anyAccess = astat->AnonymousAccess;
1559 if ((astat->CallerAccess & ~astat->AnonymousAccess))
1561 * Caller has at least one bit not covered by anonymous, and
1562 * thus may have interesting rights.
1564 * HOWEVER, this is a really bad idea, because any access query
1565 * for bits which aren't covered by anonymous, on behalf of a user
1566 * who doesn't have any special rights, will result in an answer of
1567 * the form "I don't know, lets make a FetchStatus RPC and find out!"
1568 * It's an especially bad idea under Ultrix, since (due to the lack of
1569 * a proper access() call) it must perform several afs_access() calls
1570 * in order to create magic mode bits that vary according to who makes
1571 * the call. In other words, _every_ stat() generates a test for
1574 #endif /* badidea */
1576 struct axscache *ac;
1577 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
1578 ac->axess = astat->CallerAccess;
1579 else /* not found, add a new one if possible */
1580 afs_AddAxs(avc->Access, areq->uid, astat->CallerAccess);
1582 #ifdef AFS_LINUX22_ENV
1583 vcache2inode(avc); /* Set the inode attr cache */
1586 } /*afs_ProcessFS */
1590 afs_RemoteLookup(register struct VenusFid *afid, struct vrequest *areq,
1591 char *name, struct VenusFid *nfid,
1592 struct AFSFetchStatus *OutStatusp,
1593 struct AFSCallBack *CallBackp, struct server **serverp,
1594 struct AFSVolSync *tsyncp)
1598 register struct conn *tc;
1599 struct AFSFetchStatus OutDirStatus;
1602 name = ""; /* XXX */
1604 tc = afs_Conn(afid, areq, SHARED_LOCK);
1607 *serverp = tc->srvr->server;
1609 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_XLOOKUP);
1612 RXAFS_Lookup(tc->id, (struct AFSFid *)&afid->Fid, name,
1613 (struct AFSFid *)&nfid->Fid, OutStatusp,
1614 &OutDirStatus, CallBackp, tsyncp);
1619 } while (afs_Analyze
1620 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_XLOOKUP, SHARED_LOCK,
1631 * Given a file id and a vrequest structure, fetch the status
1632 * information associated with the file.
1636 * areq : Ptr to associated vrequest structure, specifying the
1637 * user whose authentication tokens will be used.
1638 * avc : caller may already have a vcache for this file, which is
1642 * The cache entry is returned with an increased vrefCount field.
1643 * The entry must be discarded by calling afs_PutVCache when you
1644 * are through using the pointer to the cache entry.
1646 * You should not hold any locks when calling this function, except
1647 * locks on other vcache entries. If you lock more than one vcache
1648 * entry simultaneously, you should lock them in this order:
1650 * 1. Lock all files first, then directories.
1651 * 2. Within a particular type, lock entries in Fid.Vnode order.
1653 * This locking hierarchy is convenient because it allows locking
1654 * of a parent dir cache entry, given a file (to check its access
1655 * control list). It also allows renames to be handled easily by
1656 * locking directories in a constant order.
1657 * NB. NewVCache -> FlushVCache presently (4/10/95) drops the xvcache lock.
1659 /* might have a vcache structure already, which must
1660 * already be held by the caller */
1663 afs_GetVCache(register struct VenusFid *afid, struct vrequest *areq,
1664 afs_int32 * cached, struct vcache *avc)
1667 afs_int32 code, newvcache = 0;
1668 register struct vcache *tvc;
1672 AFS_STATCNT(afs_GetVCache);
1675 *cached = 0; /* Init just in case */
1677 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1681 ObtainSharedLock(&afs_xvcache, 5);
1683 tvc = afs_FindVCache(afid, &retry, DO_STATS | DO_VLRU);
1685 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1686 ReleaseSharedLock(&afs_xvcache);
1687 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1695 if (tvc->states & CStatd) {
1696 ReleaseSharedLock(&afs_xvcache);
1700 UpgradeSToWLock(&afs_xvcache, 21);
1702 /* no cache entry, better grab one */
1703 tvc = afs_NewVCache(afid, NULL);
1706 ConvertWToSLock(&afs_xvcache);
1707 afs_stats_cmperf.vcacheMisses++;
1710 ReleaseSharedLock(&afs_xvcache);
1712 ObtainWriteLock(&tvc->lock, 54);
1714 if (tvc->states & CStatd) {
1715 #ifdef AFS_LINUX22_ENV
1718 ReleaseWriteLock(&tvc->lock);
1721 #if defined(AFS_OSF_ENV)
1722 if (afs_IsWired(tvc)) {
1723 ReleaseWriteLock(&tvc->lock);
1726 #endif /* AFS_OSF_ENV */
1727 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
1729 * XXX - I really don't like this. Should try to understand better.
1730 * It seems that sometimes, when we get called, we already hold the
1731 * lock on the vnode (e.g., from afs_getattr via afs_VerifyVCache).
1732 * We can't drop the vnode lock, because that could result in a race.
1733 * Sometimes, though, we get here and don't hold the vnode lock.
1734 * I hate code paths that sometimes hold locks and sometimes don't.
1735 * In any event, the dodge we use here is to check whether the vnode
1736 * is locked, and if it isn't, then we gain and drop it around the call
1737 * to vinvalbuf; otherwise, we leave it alone.
1740 struct vnode *vp = AFSTOV(tvc);
1743 #if defined(AFS_DARWIN_ENV)
1744 iheldthelock = VOP_ISLOCKED(vp);
1746 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, current_proc());
1747 /* this is messy. we can call fsync which will try to reobtain this */
1748 if (VTOAFS(vp) == tvc)
1749 ReleaseWriteLock(&tvc->lock);
1750 if (UBCINFOEXISTS(vp)) {
1751 vinvalbuf(vp, V_SAVE, &afs_osi_cred, current_proc(), PINOD, 0);
1753 if (VTOAFS(vp) == tvc)
1754 ObtainWriteLock(&tvc->lock, 954);
1756 VOP_UNLOCK(vp, LK_EXCLUSIVE, current_proc());
1757 #elif defined(AFS_FBSD60_ENV)
1758 iheldthelock = VOP_ISLOCKED(vp, curthread);
1760 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1761 vinvalbuf(vp, V_SAVE, curthread, PINOD, 0);
1763 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1764 #elif defined(AFS_FBSD50_ENV)
1765 iheldthelock = VOP_ISLOCKED(vp, curthread);
1767 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
1768 vinvalbuf(vp, V_SAVE, osi_curcred(), curthread, PINOD, 0);
1770 VOP_UNLOCK(vp, LK_EXCLUSIVE, curthread);
1771 #elif defined(AFS_FBSD40_ENV)
1772 iheldthelock = VOP_ISLOCKED(vp, curproc);
1774 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1775 vinvalbuf(vp, V_SAVE, osi_curcred(), curproc, PINOD, 0);
1777 VOP_UNLOCK(vp, LK_EXCLUSIVE, curproc);
1778 #elif defined(AFS_OBSD_ENV)
1779 iheldthelock = VOP_ISLOCKED(vp, curproc);
1781 VOP_LOCK(vp, LK_EXCLUSIVE | LK_RETRY, curproc);
1782 uvm_vnp_uncache(vp);
1784 VOP_UNLOCK(vp, 0, curproc);
1789 ObtainWriteLock(&afs_xcbhash, 464);
1790 tvc->states &= ~CUnique;
1792 afs_DequeueCallback(tvc);
1793 ReleaseWriteLock(&afs_xcbhash);
1795 /* It is always appropriate to throw away all the access rights? */
1796 afs_FreeAllAxs(&(tvc->Access));
1797 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-volume info */
1799 if ((tvp->states & VForeign)) {
1801 tvc->states |= CForeign;
1802 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1803 && (tvp->rootUnique == afid->Fid.Unique)) {
1807 if (tvp->states & VRO)
1809 if (tvp->states & VBackup)
1810 tvc->states |= CBackup;
1811 /* now copy ".." entry back out of volume structure, if necessary */
1812 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1814 tvc->mvid = (struct VenusFid *)
1815 osi_AllocSmallSpace(sizeof(struct VenusFid));
1816 *tvc->mvid = tvp->dotdot;
1818 afs_PutVolume(tvp, READ_LOCK);
1822 afs_RemoveVCB(afid);
1824 struct AFSFetchStatus OutStatus;
1826 if (afs_DynrootNewVnode(tvc, &OutStatus)) {
1827 afs_ProcessFS(tvc, &OutStatus, areq);
1828 tvc->states |= CStatd | CUnique;
1831 code = afs_FetchStatus(tvc, afid, areq, &OutStatus);
1836 ReleaseWriteLock(&tvc->lock);
1838 ObtainReadLock(&afs_xvcache);
1840 ReleaseReadLock(&afs_xvcache);
1844 ReleaseWriteLock(&tvc->lock);
1847 } /*afs_GetVCache */
1852 afs_LookupVCache(struct VenusFid *afid, struct vrequest *areq,
1853 afs_int32 * cached, struct vcache *adp, char *aname)
1855 afs_int32 code, now, newvcache = 0;
1856 struct VenusFid nfid;
1857 register struct vcache *tvc;
1859 struct AFSFetchStatus OutStatus;
1860 struct AFSCallBack CallBack;
1861 struct AFSVolSync tsync;
1862 struct server *serverp = 0;
1866 AFS_STATCNT(afs_GetVCache);
1868 *cached = 0; /* Init just in case */
1870 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1874 ObtainReadLock(&afs_xvcache);
1875 tvc = afs_FindVCache(afid, &retry, DO_STATS /* no vlru */ );
1878 ReleaseReadLock(&afs_xvcache);
1880 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1881 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1885 ObtainReadLock(&tvc->lock);
1887 if (tvc->states & CStatd) {
1891 ReleaseReadLock(&tvc->lock);
1894 tvc->states &= ~CUnique;
1896 ReleaseReadLock(&tvc->lock);
1897 ObtainReadLock(&afs_xvcache);
1901 ReleaseReadLock(&afs_xvcache);
1903 /* lookup the file */
1906 origCBs = afs_allCBs; /* if anything changes, we don't have a cb */
1908 afs_RemoteLookup(&adp->fid, areq, aname, &nfid, &OutStatus, &CallBack,
1911 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1915 ObtainSharedLock(&afs_xvcache, 6);
1916 tvc = afs_FindVCache(&nfid, &retry, DO_VLRU /* no xstats now */ );
1918 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
1919 ReleaseSharedLock(&afs_xvcache);
1920 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
1926 /* no cache entry, better grab one */
1927 UpgradeSToWLock(&afs_xvcache, 22);
1928 tvc = afs_NewVCache(&nfid, serverp);
1930 ConvertWToSLock(&afs_xvcache);
1933 ReleaseSharedLock(&afs_xvcache);
1934 ObtainWriteLock(&tvc->lock, 55);
1936 /* It is always appropriate to throw away all the access rights? */
1937 afs_FreeAllAxs(&(tvc->Access));
1938 tvp = afs_GetVolume(afid, areq, READ_LOCK); /* copy useful per-vol info */
1940 if ((tvp->states & VForeign)) {
1942 tvc->states |= CForeign;
1943 if (newvcache && (tvp->rootVnode == afid->Fid.Vnode)
1944 && (tvp->rootUnique == afid->Fid.Unique))
1947 if (tvp->states & VRO)
1949 if (tvp->states & VBackup)
1950 tvc->states |= CBackup;
1951 /* now copy ".." entry back out of volume structure, if necessary */
1952 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
1954 tvc->mvid = (struct VenusFid *)
1955 osi_AllocSmallSpace(sizeof(struct VenusFid));
1956 *tvc->mvid = tvp->dotdot;
1961 ObtainWriteLock(&afs_xcbhash, 465);
1962 afs_DequeueCallback(tvc);
1963 tvc->states &= ~(CStatd | CUnique);
1964 ReleaseWriteLock(&afs_xcbhash);
1965 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1966 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1968 afs_PutVolume(tvp, READ_LOCK);
1969 ReleaseWriteLock(&tvc->lock);
1970 ObtainReadLock(&afs_xvcache);
1972 ReleaseReadLock(&afs_xvcache);
1976 ObtainWriteLock(&afs_xcbhash, 466);
1977 if (origCBs == afs_allCBs) {
1978 if (CallBack.ExpirationTime) {
1979 tvc->callback = serverp;
1980 tvc->cbExpires = CallBack.ExpirationTime + now;
1981 tvc->states |= CStatd | CUnique;
1982 tvc->states &= ~CBulkFetching;
1983 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvp);
1984 } else if (tvc->states & CRO) {
1985 /* adapt gives us an hour. */
1986 tvc->cbExpires = 3600 + osi_Time();
1987 /*XXX*/ tvc->states |= CStatd | CUnique;
1988 tvc->states &= ~CBulkFetching;
1989 afs_QueueCallback(tvc, CBHash(3600), tvp);
1991 tvc->callback = NULL;
1992 afs_DequeueCallback(tvc);
1993 tvc->states &= ~(CStatd | CUnique);
1994 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
1995 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
1998 afs_DequeueCallback(tvc);
1999 tvc->states &= ~CStatd;
2000 tvc->states &= ~CUnique;
2001 tvc->callback = NULL;
2002 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2003 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2005 ReleaseWriteLock(&afs_xcbhash);
2007 afs_PutVolume(tvp, READ_LOCK);
2008 afs_ProcessFS(tvc, &OutStatus, areq);
2010 ReleaseWriteLock(&tvc->lock);
2016 afs_GetRootVCache(struct VenusFid *afid, struct vrequest *areq,
2017 afs_int32 * cached, struct volume *tvolp)
2019 afs_int32 code = 0, i, newvcache = 0, haveStatus = 0;
2020 afs_int32 getNewFid = 0;
2022 struct VenusFid nfid;
2023 register struct vcache *tvc;
2024 struct server *serverp = 0;
2025 struct AFSFetchStatus OutStatus;
2026 struct AFSCallBack CallBack;
2027 struct AFSVolSync tsync;
2033 if (!tvolp->rootVnode || getNewFid) {
2034 struct VenusFid tfid;
2037 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2038 origCBs = afs_allCBs; /* ignore InitCallBackState */
2040 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2045 /* ReleaseReadLock(&tvolp->lock); */
2046 ObtainWriteLock(&tvolp->lock, 56);
2047 tvolp->rootVnode = afid->Fid.Vnode = nfid.Fid.Vnode;
2048 tvolp->rootUnique = afid->Fid.Unique = nfid.Fid.Unique;
2049 ReleaseWriteLock(&tvolp->lock);
2050 /* ObtainReadLock(&tvolp->lock);*/
2053 afid->Fid.Vnode = tvolp->rootVnode;
2054 afid->Fid.Unique = tvolp->rootUnique;
2057 ObtainSharedLock(&afs_xvcache, 7);
2059 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2060 if (!FidCmp(&(tvc->fid), afid)) {
2062 /* Grab this vnode, possibly reactivating from the free list */
2063 /* for the present (95.05.25) everything on the hash table is
2064 * definitively NOT in the free list -- at least until afs_reclaim
2065 * can be safely implemented */
2068 vg = vget(AFSTOV(tvc)); /* this bumps ref count */
2072 #endif /* AFS_OSF_ENV */
2077 if (!haveStatus && (!tvc || !(tvc->states & CStatd))) {
2078 /* Mount point no longer stat'd or unknown. FID may have changed. */
2081 AFS_RELE(AFSTOV(tvc));
2085 ReleaseSharedLock(&afs_xvcache);
2090 UpgradeSToWLock(&afs_xvcache, 23);
2091 /* no cache entry, better grab one */
2092 tvc = afs_NewVCache(afid, NULL);
2094 afs_stats_cmperf.vcacheMisses++;
2098 afs_stats_cmperf.vcacheHits++;
2100 /* we already bumped the ref count in the for loop above */
2101 #else /* AFS_OSF_ENV */
2104 UpgradeSToWLock(&afs_xvcache, 24);
2105 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2106 refpanic("GRVC VLRU inconsistent0");
2108 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2109 refpanic("GRVC VLRU inconsistent1");
2111 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2112 refpanic("GRVC VLRU inconsistent2");
2114 QRemove(&tvc->vlruq); /* move to lruq head */
2115 QAdd(&VLRU, &tvc->vlruq);
2116 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2117 refpanic("GRVC VLRU inconsistent3");
2119 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2120 refpanic("GRVC VLRU inconsistent4");
2122 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2123 refpanic("GRVC VLRU inconsistent5");
2128 ReleaseWriteLock(&afs_xvcache);
2130 if (tvc->states & CStatd) {
2134 ObtainReadLock(&tvc->lock);
2135 tvc->states &= ~CUnique;
2136 tvc->callback = NULL; /* redundant, perhaps */
2137 ReleaseReadLock(&tvc->lock);
2140 ObtainWriteLock(&tvc->lock, 57);
2142 /* It is always appropriate to throw away all the access rights? */
2143 afs_FreeAllAxs(&(tvc->Access));
2146 tvc->states |= CForeign;
2147 if (tvolp->states & VRO)
2149 if (tvolp->states & VBackup)
2150 tvc->states |= CBackup;
2151 /* now copy ".." entry back out of volume structure, if necessary */
2152 if (newvcache && (tvolp->rootVnode == afid->Fid.Vnode)
2153 && (tvolp->rootUnique == afid->Fid.Unique)) {
2156 if (tvc->mvstat == 2 && tvolp->dotdot.Fid.Volume != 0) {
2158 tvc->mvid = (struct VenusFid *)
2159 osi_AllocSmallSpace(sizeof(struct VenusFid));
2160 *tvc->mvid = tvolp->dotdot;
2164 afs_RemoveVCB(afid);
2167 struct VenusFid tfid;
2170 tfid.Fid.Vnode = 0; /* Means get rootfid of volume */
2171 origCBs = afs_allCBs; /* ignore InitCallBackState */
2173 afs_RemoteLookup(&tfid, areq, NULL, &nfid, &OutStatus, &CallBack,
2178 ObtainWriteLock(&afs_xcbhash, 467);
2179 afs_DequeueCallback(tvc);
2180 tvc->callback = NULL;
2181 tvc->states &= ~(CStatd | CUnique);
2182 ReleaseWriteLock(&afs_xcbhash);
2183 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2184 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2185 ReleaseWriteLock(&tvc->lock);
2186 ObtainReadLock(&afs_xvcache);
2188 ReleaseReadLock(&afs_xvcache);
2192 ObtainWriteLock(&afs_xcbhash, 468);
2193 if (origCBs == afs_allCBs) {
2194 tvc->states |= CTruth;
2195 tvc->callback = serverp;
2196 if (CallBack.ExpirationTime != 0) {
2197 tvc->cbExpires = CallBack.ExpirationTime + start;
2198 tvc->states |= CStatd;
2199 tvc->states &= ~CBulkFetching;
2200 afs_QueueCallback(tvc, CBHash(CallBack.ExpirationTime), tvolp);
2201 } else if (tvc->states & CRO) {
2202 /* adapt gives us an hour. */
2203 tvc->cbExpires = 3600 + osi_Time();
2204 /*XXX*/ tvc->states |= CStatd;
2205 tvc->states &= ~CBulkFetching;
2206 afs_QueueCallback(tvc, CBHash(3600), tvolp);
2209 afs_DequeueCallback(tvc);
2210 tvc->callback = NULL;
2211 tvc->states &= ~(CStatd | CUnique);
2212 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2213 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2215 ReleaseWriteLock(&afs_xcbhash);
2216 afs_ProcessFS(tvc, &OutStatus, areq);
2218 ReleaseWriteLock(&tvc->lock);
2225 * must be called with avc write-locked
2226 * don't absolutely have to invalidate the hint unless the dv has
2227 * changed, but be sure to get it right else there will be consistency bugs.
2230 afs_FetchStatus(struct vcache * avc, struct VenusFid * afid,
2231 struct vrequest * areq, struct AFSFetchStatus * Outsp)
2234 afs_uint32 start = 0;
2235 register struct conn *tc;
2236 struct AFSCallBack CallBack;
2237 struct AFSVolSync tsync;
2238 struct volume *volp;
2241 tc = afs_Conn(afid, areq, SHARED_LOCK);
2242 avc->quick.stamp = 0;
2243 avc->h1.dchint = NULL; /* invalidate hints */
2245 avc->callback = tc->srvr->server;
2247 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
2250 RXAFS_FetchStatus(tc->id, (struct AFSFid *)&afid->Fid, Outsp,
2258 } while (afs_Analyze
2259 (tc, code, afid, areq, AFS_STATS_FS_RPCIDX_FETCHSTATUS,
2260 SHARED_LOCK, NULL));
2263 afs_ProcessFS(avc, Outsp, areq);
2264 volp = afs_GetVolume(afid, areq, READ_LOCK);
2265 ObtainWriteLock(&afs_xcbhash, 469);
2266 avc->states |= CTruth;
2267 if (avc->callback /* check for race */ ) {
2268 if (CallBack.ExpirationTime != 0) {
2269 avc->cbExpires = CallBack.ExpirationTime + start;
2270 avc->states |= CStatd;
2271 avc->states &= ~CBulkFetching;
2272 afs_QueueCallback(avc, CBHash(CallBack.ExpirationTime), volp);
2273 } else if (avc->states & CRO) { /* ordinary callback on a read-only volume -- AFS 3.2 style */
2274 avc->cbExpires = 3600 + start;
2275 avc->states |= CStatd;
2276 avc->states &= ~CBulkFetching;
2277 afs_QueueCallback(avc, CBHash(3600), volp);
2279 afs_DequeueCallback(avc);
2280 avc->callback = NULL;
2281 avc->states &= ~(CStatd | CUnique);
2282 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2283 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2286 afs_DequeueCallback(avc);
2287 avc->callback = NULL;
2288 avc->states &= ~(CStatd | CUnique);
2289 if ((avc->states & CForeign) || (avc->fid.Fid.Vnode & 1))
2290 osi_dnlc_purgedp(avc); /* if it (could be) a directory */
2292 ReleaseWriteLock(&afs_xcbhash);
2294 afs_PutVolume(volp, READ_LOCK);
2296 /* used to undo the local callback, but that's too extreme.
2297 * There are plenty of good reasons that fetchstatus might return
2298 * an error, such as EPERM. If we have the vnode cached, statd,
2299 * with callback, might as well keep track of the fact that we
2300 * don't have access...
2302 if (code == EPERM || code == EACCES) {
2303 struct axscache *ac;
2304 if (avc->Access && (ac = afs_FindAxs(avc->Access, areq->uid)))
2306 else /* not found, add a new one if possible */
2307 afs_AddAxs(avc->Access, areq->uid, 0);
2318 * Stuff some information into the vcache for the given file.
2321 * afid : File in question.
2322 * OutStatus : Fetch status on the file.
2323 * CallBack : Callback info.
2324 * tc : RPC connection involved.
2325 * areq : vrequest involved.
2328 * Nothing interesting.
2331 afs_StuffVcache(register struct VenusFid *afid,
2332 struct AFSFetchStatus *OutStatus,
2333 struct AFSCallBack *CallBack, register struct conn *tc,
2334 struct vrequest *areq)
2336 register afs_int32 code, i, newvcache = 0;
2337 register struct vcache *tvc;
2338 struct AFSVolSync tsync;
2340 struct axscache *ac;
2343 AFS_STATCNT(afs_StuffVcache);
2344 #ifdef IFS_VCACHECOUNT
2349 ObtainSharedLock(&afs_xvcache, 8);
2351 tvc = afs_FindVCache(afid, &retry, DO_VLRU /* no stats */ );
2353 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2354 ReleaseSharedLock(&afs_xvcache);
2355 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2361 /* no cache entry, better grab one */
2362 UpgradeSToWLock(&afs_xvcache, 25);
2363 tvc = afs_NewVCache(afid, NULL);
2365 ConvertWToSLock(&afs_xvcache);
2368 ReleaseSharedLock(&afs_xvcache);
2369 ObtainWriteLock(&tvc->lock, 58);
2371 tvc->states &= ~CStatd;
2372 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2373 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2375 /* Is it always appropriate to throw away all the access rights? */
2376 afs_FreeAllAxs(&(tvc->Access));
2378 /*Copy useful per-volume info */
2379 tvp = afs_GetVolume(afid, areq, READ_LOCK);
2381 if (newvcache && (tvp->states & VForeign))
2382 tvc->states |= CForeign;
2383 if (tvp->states & VRO)
2385 if (tvp->states & VBackup)
2386 tvc->states |= CBackup;
2388 * Now, copy ".." entry back out of volume structure, if
2391 if (tvc->mvstat == 2 && tvp->dotdot.Fid.Volume != 0) {
2393 tvc->mvid = (struct VenusFid *)
2394 osi_AllocSmallSpace(sizeof(struct VenusFid));
2395 *tvc->mvid = tvp->dotdot;
2398 /* store the stat on the file */
2399 afs_RemoveVCB(afid);
2400 afs_ProcessFS(tvc, OutStatus, areq);
2401 tvc->callback = tc->srvr->server;
2403 /* we use osi_Time twice below. Ideally, we would use the time at which
2404 * the FetchStatus call began, instead, but we don't have it here. So we
2405 * make do with "now". In the CRO case, it doesn't really matter. In
2406 * the other case, we hope that the difference between "now" and when the
2407 * call actually began execution on the server won't be larger than the
2408 * padding which the server keeps. Subtract 1 second anyway, to be on
2409 * the safe side. Can't subtract more because we don't know how big
2410 * ExpirationTime is. Possible consistency problems may arise if the call
2411 * timeout period becomes longer than the server's expiration padding. */
2412 ObtainWriteLock(&afs_xcbhash, 470);
2413 if (CallBack->ExpirationTime != 0) {
2414 tvc->cbExpires = CallBack->ExpirationTime + osi_Time() - 1;
2415 tvc->states |= CStatd;
2416 tvc->states &= ~CBulkFetching;
2417 afs_QueueCallback(tvc, CBHash(CallBack->ExpirationTime), tvp);
2418 } else if (tvc->states & CRO) {
2419 /* old-fashioned AFS 3.2 style */
2420 tvc->cbExpires = 3600 + osi_Time();
2421 /*XXX*/ tvc->states |= CStatd;
2422 tvc->states &= ~CBulkFetching;
2423 afs_QueueCallback(tvc, CBHash(3600), tvp);
2425 afs_DequeueCallback(tvc);
2426 tvc->callback = NULL;
2427 tvc->states &= ~(CStatd | CUnique);
2428 if ((tvc->states & CForeign) || (tvc->fid.Fid.Vnode & 1))
2429 osi_dnlc_purgedp(tvc); /* if it (could be) a directory */
2431 ReleaseWriteLock(&afs_xcbhash);
2433 afs_PutVolume(tvp, READ_LOCK);
2435 /* look in per-pag cache */
2436 if (tvc->Access && (ac = afs_FindAxs(tvc->Access, areq->uid)))
2437 ac->axess = OutStatus->CallerAccess; /* substitute pags */
2438 else /* not found, add a new one if possible */
2439 afs_AddAxs(tvc->Access, areq->uid, OutStatus->CallerAccess);
2441 ReleaseWriteLock(&tvc->lock);
2442 afs_Trace4(afs_iclSetp, CM_TRACE_STUFFVCACHE, ICL_TYPE_POINTER, tvc,
2443 ICL_TYPE_POINTER, tvc->callback, ICL_TYPE_INT32,
2444 tvc->cbExpires, ICL_TYPE_INT32, tvc->cbExpires - osi_Time());
2446 * Release ref count... hope this guy stays around...
2449 } /*afs_StuffVcache */
2456 * Decrements the reference count on a cache entry.
2459 * avc : Pointer to the cache entry to decrement.
2462 * Nothing interesting.
2465 afs_PutVCache(register struct vcache *avc)
2467 AFS_STATCNT(afs_PutVCache);
2469 * Can we use a read lock here?
2471 ObtainReadLock(&afs_xvcache);
2473 ReleaseReadLock(&afs_xvcache);
2474 } /*afs_PutVCache */
2480 * Find a vcache entry given a fid.
2483 * afid : Pointer to the fid whose cache entry we desire.
2484 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2485 * unlock the vnode, and try again.
2486 * flags: bit 1 to specify whether to compute hit statistics. Not
2487 * set if FindVCache is called as part of internal bookkeeping.
2490 * Must be called with the afs_xvcache lock at least held at
2491 * the read level. In order to do the VLRU adjustment, the xvcache lock
2492 * must be shared-- we upgrade it here.
2496 afs_FindVCache(struct VenusFid *afid, afs_int32 * retry, afs_int32 flag)
2499 register struct vcache *tvc;
2502 AFS_STATCNT(afs_FindVCache);
2505 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2506 if (FidMatches(afid, tvc)) {
2508 /* Grab this vnode, possibly reactivating from the free list */
2511 vg = vget(AFSTOV(tvc));
2515 #endif /* AFS_OSF_ENV */
2520 /* should I have a read lock on the vnode here? */
2524 #if !defined(AFS_OSF_ENV)
2525 osi_vnhold(tvc, retry); /* already held, above */
2526 if (retry && *retry)
2529 #ifdef AFS_DARWIN_ENV
2530 tvc->states |= CUBCinit;
2532 if (UBCINFOMISSING(AFSTOV(tvc)) ||
2533 UBCINFORECLAIMED(AFSTOV(tvc))) {
2534 ubc_info_init(AFSTOV(tvc));
2537 tvc->states &= ~CUBCinit;
2540 * only move to front of vlru if we have proper vcache locking)
2542 if (flag & DO_VLRU) {
2543 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2544 refpanic("FindVC VLRU inconsistent1");
2546 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2547 refpanic("FindVC VLRU inconsistent1");
2549 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2550 refpanic("FindVC VLRU inconsistent2");
2552 UpgradeSToWLock(&afs_xvcache, 26);
2553 QRemove(&tvc->vlruq);
2554 QAdd(&VLRU, &tvc->vlruq);
2555 ConvertWToSLock(&afs_xvcache);
2556 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2557 refpanic("FindVC VLRU inconsistent1");
2559 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2560 refpanic("FindVC VLRU inconsistent2");
2562 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2563 refpanic("FindVC VLRU inconsistent3");
2569 if (flag & DO_STATS) {
2571 afs_stats_cmperf.vcacheHits++;
2573 afs_stats_cmperf.vcacheMisses++;
2574 if (afs_IsPrimaryCellNum(afid->Cell))
2575 afs_stats_cmperf.vlocalAccesses++;
2577 afs_stats_cmperf.vremoteAccesses++;
2579 #ifdef AFS_LINUX22_ENV
2580 if (tvc && (tvc->states & CStatd))
2581 vcache2inode(tvc); /* mainly to reset i_nlink */
2584 } /*afs_FindVCache */
2590 * Find a vcache entry given a fid. Does a wildcard match on what we
2591 * have for the fid. If more than one entry, don't return anything.
2594 * avcp : Fill in pointer if we found one and only one.
2595 * afid : Pointer to the fid whose cache entry we desire.
2596 * retry: (SGI-specific) tell the caller to drop the lock on xvcache,
2597 * unlock the vnode, and try again.
2598 * flags: bit 1 to specify whether to compute hit statistics. Not
2599 * set if FindVCache is called as part of internal bookkeeping.
2602 * Must be called with the afs_xvcache lock at least held at
2603 * the read level. In order to do the VLRU adjustment, the xvcache lock
2604 * must be shared-- we upgrade it here.
2607 * number of matches found.
2610 int afs_duplicate_nfs_fids = 0;
2613 afs_NFSFindVCache(struct vcache **avcp, struct VenusFid *afid)
2615 register struct vcache *tvc;
2617 afs_int32 count = 0;
2618 struct vcache *found_tvc = NULL;
2620 AFS_STATCNT(afs_FindVCache);
2622 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2626 ObtainSharedLock(&afs_xvcache, 331);
2629 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2630 /* Match only on what we have.... */
2631 if (((tvc->fid.Fid.Vnode & 0xffff) == afid->Fid.Vnode)
2632 && (tvc->fid.Fid.Volume == afid->Fid.Volume)
2633 && ((tvc->fid.Fid.Unique & 0xffffff) == afid->Fid.Unique)
2634 && (tvc->fid.Cell == afid->Cell)) {
2636 /* Grab this vnode, possibly reactivating from the free list */
2639 vg = vget(AFSTOV(tvc));
2642 /* This vnode no longer exists. */
2645 #endif /* AFS_OSF_ENV */
2650 /* Drop our reference counts. */
2652 vrele(AFSTOV(found_tvc));
2654 afs_duplicate_nfs_fids++;
2655 ReleaseSharedLock(&afs_xvcache);
2663 /* should I have a read lock on the vnode here? */
2665 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI53_ENV)
2666 afs_int32 retry = 0;
2667 osi_vnhold(tvc, &retry);
2670 found_tvc = (struct vcache *)0;
2671 ReleaseSharedLock(&afs_xvcache);
2672 spunlock_psema(tvc->v.v_lock, retry, &tvc->v.v_sync, PINOD);
2676 #if !defined(AFS_OSF_ENV)
2677 osi_vnhold(tvc, (int *)0); /* already held, above */
2681 * We obtained the xvcache lock above.
2683 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2684 refpanic("FindVC VLRU inconsistent1");
2686 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2687 refpanic("FindVC VLRU inconsistent1");
2689 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2690 refpanic("FindVC VLRU inconsistent2");
2692 UpgradeSToWLock(&afs_xvcache, 568);
2693 QRemove(&tvc->vlruq);
2694 QAdd(&VLRU, &tvc->vlruq);
2695 ConvertWToSLock(&afs_xvcache);
2696 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
2697 refpanic("FindVC VLRU inconsistent1");
2699 if (tvc->vlruq.next->prev != &(tvc->vlruq)) {
2700 refpanic("FindVC VLRU inconsistent2");
2702 if (tvc->vlruq.prev->next != &(tvc->vlruq)) {
2703 refpanic("FindVC VLRU inconsistent3");
2709 afs_stats_cmperf.vcacheHits++;
2711 afs_stats_cmperf.vcacheMisses++;
2712 if (afs_IsPrimaryCellNum(afid->Cell))
2713 afs_stats_cmperf.vlocalAccesses++;
2715 afs_stats_cmperf.vremoteAccesses++;
2717 *avcp = tvc; /* May be null */
2719 ReleaseSharedLock(&afs_xvcache);
2720 return (tvc ? 1 : 0);
2722 } /*afs_NFSFindVCache */
2730 * Initialize vcache related variables
2733 afs_vcacheInit(int astatSize)
2735 register struct vcache *tvp;
2737 #if defined(AFS_OSF_ENV)
2738 if (!afs_maxvcount) {
2739 #if defined(AFS_OSF30_ENV)
2740 afs_maxvcount = max_vnodes / 2; /* limit ourselves to half the total */
2742 afs_maxvcount = nvnode / 2; /* limit ourselves to half the total */
2744 if (astatSize < afs_maxvcount) {
2745 afs_maxvcount = astatSize;
2748 #else /* AFS_OSF_ENV */
2752 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2753 LOCK_INIT(&afs_xvcb, "afs_xvcb");
2755 #if !defined(AFS_OSF_ENV)
2756 #ifdef AFS_LINUX26_ENV
2757 printf("old style would have needed %d contiguous bytes\n", astatSize *
2758 sizeof(struct vcache));
2759 Initial_freeVCList = freeVCList = tvp = (struct vcache *)
2760 afs_osi_Alloc(sizeof(struct vcache));
2761 for (i = 0; i < astatSize; i++) {
2762 tvp->nextfree = (struct vcache *) afs_osi_Alloc(sizeof(struct vcache));
2763 tvp = tvp->nextfree;
2765 tvp->nextfree = NULL;
2767 /* Allocate and thread the struct vcache entries */
2768 tvp = (struct vcache *)afs_osi_Alloc(astatSize * sizeof(struct vcache));
2769 memset((char *)tvp, 0, sizeof(struct vcache) * astatSize);
2771 Initial_freeVCList = tvp;
2772 freeVCList = &(tvp[0]);
2773 for (i = 0; i < astatSize - 1; i++) {
2774 tvp[i].nextfree = &(tvp[i + 1]);
2776 tvp[astatSize - 1].nextfree = NULL;
2777 #ifdef KERNEL_HAVE_PIN
2778 pin((char *)tvp, astatSize * sizeof(struct vcache)); /* XXX */
2783 #if defined(AFS_SGI_ENV)
2784 for (i = 0; i < astatSize; i++) {
2785 char name[METER_NAMSZ];
2786 struct vcache *tvc = &tvp[i];
2788 tvc->v.v_number = ++afsvnumbers;
2789 tvc->vc_rwlockid = OSI_NO_LOCKID;
2790 initnsema(&tvc->vc_rwlock, 1,
2791 makesname(name, "vrw", tvc->v.v_number));
2792 #ifndef AFS_SGI53_ENV
2793 initnsema(&tvc->v.v_sync, 0, makesname(name, "vsy", tvc->v.v_number));
2795 #ifndef AFS_SGI62_ENV
2796 initnlock(&tvc->v.v_lock, makesname(name, "vlk", tvc->v.v_number));
2797 #endif /* AFS_SGI62_ENV */
2811 shutdown_vcache(void)
2814 struct afs_cbr *tsp, *nsp;
2816 * XXX We may potentially miss some of the vcaches because if when there're no
2817 * free vcache entries and all the vcache entries are active ones then we allocate
2818 * an additional one - admittedly we almost never had that occur.
2822 register struct afs_q *tq, *uq;
2823 register struct vcache *tvc;
2824 for (tq = VLRU.prev; tq != &VLRU; tq = uq) {
2828 osi_FreeSmallSpace(tvc->mvid);
2829 tvc->mvid = (struct VenusFid *)0;
2832 aix_gnode_rele(AFSTOV(tvc));
2834 if (tvc->linkData) {
2835 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2840 * Also free the remaining ones in the Cache
2842 for (i = 0; i < VCSIZE; i++) {
2843 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
2845 osi_FreeSmallSpace(tvc->mvid);
2846 tvc->mvid = (struct VenusFid *)0;
2850 afs_osi_Free(tvc->v.v_gnode, sizeof(struct gnode));
2851 #ifdef AFS_AIX32_ENV
2854 vms_delete(tvc->segid);
2856 tvc->segid = tvc->vmh = NULL;
2858 osi_Panic("flushVcache: vm race");
2866 #if defined(AFS_SUN5_ENV)
2872 if (tvc->linkData) {
2873 afs_osi_Free(tvc->linkData, strlen(tvc->linkData) + 1);
2877 afs_FreeAllAxs(&(tvc->Access));
2879 afs_vhashT[i] = afs_vhashTV[i] = 0;
2883 * Free any leftover callback queue
2885 for (tsp = afs_cbrSpace; tsp; tsp = nsp) {
2887 afs_osi_Free((char *)tsp, AFS_NCBRS * sizeof(struct afs_cbr));
2891 #ifdef AFS_LINUX26_ENV
2893 struct vcache *tvp = Initial_freeVCList;
2895 struct vcache *next = tvp->nextfree;
2897 afs_osi_Free(tvp, sizeof(struct vcache));
2902 #ifdef KERNEL_HAVE_PIN
2903 unpin(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2905 #if !defined(AFS_OSF_ENV)
2906 afs_osi_Free(Initial_freeVCList, afs_cacheStats * sizeof(struct vcache));
2910 #if !defined(AFS_OSF_ENV)
2911 freeVCList = Initial_freeVCList = 0;
2913 RWLOCK_INIT(&afs_xvcache, "afs_xvcache");
2914 LOCK_INIT(&afs_xvcb, "afs_xvcb");