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
17 #include <afsconfig.h>
18 #include "afs/param.h"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
21 #include "afsincludes.h" /* Afs-based standard headers */
22 #include "afs/afs_stats.h" /* statistics */
23 #include "afs/afs_cbqueue.h"
24 #include "afs/nfsclient.h"
25 #include "afs/exporter.h"
26 #include "afs/afs_osidnlc.h"
27 #include "afs/afs_dynroot.h"
29 extern struct vcache *afs_globalVp;
31 afs_int32 afs_bkvolpref = 0;
32 afs_int32 afs_bulkStatsDone;
33 static int bulkStatCounter = 0; /* counter for bulk stat seq. numbers */
34 int afs_fakestat_enable = 0; /* 1: fakestat-all, 2: fakestat-crosscell */
37 /* this would be faster if it did comparison as int32word, but would be
38 * dependant on byte-order and alignment, and I haven't figured out
39 * what "@sys" is in binary... */
40 #define AFS_EQ_ATSYS(name) (((name)[0]=='@')&&((name)[1]=='s')&&((name)[2]=='y')&&((name)[3]=='s')&&(!(name)[4]))
42 /* call under write lock, evaluate mvid.target_root field from a mt pt.
43 * avc is the vnode of the mount point object; must be write-locked.
44 * advc is the vnode of the containing directory (optional; if NULL and
45 * EvalMountPoint succeeds, caller must initialize *avolpp->dotdot)
46 * avolpp is where we return a pointer to the volume named by the mount pt, if success
47 * areq is the identity of the caller.
49 * NOTE: this function returns a held volume structure in *volpp if it returns 0!
52 EvalMountData(char type, char *data, afs_uint32 states, afs_uint32 cellnum,
53 struct volume **avolpp, struct vrequest *areq,
54 afs_uint32 *acellidxp, afs_uint32 *avolnump,
55 afs_uint32 *avnoidp, afs_uint32 *auniqp)
57 struct volume *tvp = 0;
60 char *cpos, *volnamep = NULL;
62 afs_int32 prefetch; /* 1=>None 2=>RO 3=>BK */
63 afs_int32 mtptCell, assocCell = 0, hac = 0;
64 afs_int32 samecell, roname, len;
65 afs_uint32 volid = 0, cellidx, vnoid = 0, uniq = 0;
67 /* Start by figuring out and finding the cell */
68 cpos = afs_strchr(data, ':'); /* if cell name present */
70 afs_uint32 mtptCellnum;
73 if ((afs_strtoi_r(data, &endptr, &mtptCellnum) == 0) &&
75 tcell = afs_GetCell(mtptCellnum, READ_LOCK);
77 tcell = afs_GetCellByName(data, READ_LOCK);
82 tcell = afs_GetCell(cellnum, READ_LOCK);
84 /* No cellname or cellnum; return ENODEV */
88 /* no cell found; return ENODEV */
92 cellidx = tcell->cellIndex;
93 mtptCell = tcell->cellNum; /* The cell for the mountpoint */
95 hac = 1; /* has associated cell */
96 assocCell = tcell->lcellp->cellNum; /* The associated cell */
98 afs_PutCell(tcell, READ_LOCK);
100 /* If there's nothing to look up, we can't proceed */
104 /* cell found. figure out volume */
105 cpos = afs_strchr(volnamep, ':');
109 /* Look for an all-numeric volume ID */
110 if ((afs_strtoi_r(volnamep, &endptr, &volid) == 0) &&
111 ((endptr == cpos) || (!*endptr)))
113 /* Ok. Is there a vnode and uniq? */
115 char *vnodep = (char *)(cpos + 1);
117 if ((!*vnodep) /* no vnode after colon */
118 || !(uniqp = afs_strchr(vnodep, ':')) /* no colon for uniq */
119 || (!*(++uniqp)) /* no uniq after colon */
120 || (afs_strtoi_r(vnodep, &endptr, &vnoid) != 0) /* bad vno */
121 || (*endptr != ':') /* bad vnode field */
122 || (afs_strtoi_r(uniqp, &endptr, &uniq) != 0) /* bad uniq */
123 || (*endptr)) /* anything after uniq */
126 /* sorry. vnode and uniq, or nothing */
134 * If the volume ID was all-numeric, and they didn't ask for a
135 * pointer to the volume structure, then just return the number
136 * as-is. This is currently only used for handling name lookups
137 * in the dynamic mount directory.
139 if (volid && !avolpp) {
146 * If the volume ID was all-numeric, and the type was '%', then
147 * assume whoever made the mount point knew what they were doing,
148 * and don't second-guess them by forcing use of a RW volume when
149 * they gave the ID of something else.
151 if (volid && type == '%') {
152 tfid.Fid.Volume = volid; /* remember BK volume */
153 tfid.Cell = mtptCell;
154 tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */
155 if (cpos) /* one way or another we're done */
158 return ENODEV; /* afs_GetVolume failed; return ENODEV */
162 /* Is volume name a "<n>.backup" or "<n>.readonly" name */
163 len = strlen(volnamep);
164 roname = ((len > 9) && (strcmp(&volnamep[len - 9], ".readonly") == 0))
165 || ((len > 7) && (strcmp(&volnamep[len - 7], ".backup") == 0));
167 /* When we cross mountpoint, do we stay in the same cell */
168 samecell = (cellnum == mtptCell) || (hac && (cellnum == assocCell));
170 /* Decide whether to prefetch the BK, or RO. Also means we want the BK or
172 * If this is a regular mountpoint with a RW volume name
173 * - If BK preference is enabled AND we remain within the same cell AND
174 * start from a BK volume, then we will want to prefetch the BK volume.
175 * - If we cross a cell boundary OR start from a RO volume, then we will
176 * want to prefetch the RO volume.
178 if ((type == '#') && !roname) {
179 if (afs_bkvolpref && samecell && (states & CBackup))
180 prefetch = 3; /* Prefetch the BK */
181 else if (!samecell || (states & CRO))
182 prefetch = 2; /* Prefetch the RO */
184 prefetch = 1; /* Do not prefetch */
186 prefetch = 1; /* Do not prefetch */
189 /* Get the volume struct. Unless this volume name has ".readonly" or
190 * ".backup" in it, this will get the volume struct for the RW volume.
191 * The RO volume will be prefetched if requested (but not returned).
192 * Set up to use volname first.
194 tvp = afs_GetVolumeByName(volnamep, mtptCell, prefetch, areq, WRITE_LOCK);
196 /* If no volume was found in this cell, try the associated linked cell */
197 if (!tvp && hac && areq->volumeError) {
199 afs_GetVolumeByName(volnamep, assocCell, prefetch, areq,
203 /* done with volname */
207 return ENODEV; /* Couldn't find the volume */
211 /* Don't cross mountpoint from a BK to a BK volume */
212 if ((states & CBackup) && (tvp->states & VBackup)) {
213 afs_PutVolume(tvp, WRITE_LOCK);
217 /* If we want (prefetched) the BK and it exists, then drop the RW volume
219 * Otherwise, if we want (prefetched0 the RO and it exists, then drop the
220 * RW volume and get the RO.
221 * Otherwise, go with the RW.
223 if ((prefetch == 3) && tvp->backVol) {
224 tfid.Fid.Volume = tvp->backVol; /* remember BK volume */
225 tfid.Cell = tvp->cell;
226 afs_PutVolume(tvp, WRITE_LOCK); /* release old volume */
227 tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */
229 return ENODEV; /* oops, can't do it */
230 } else if ((prefetch >= 2) && tvp->roVol) {
231 tfid.Fid.Volume = tvp->roVol; /* remember RO volume */
232 tfid.Cell = tvp->cell;
233 afs_PutVolume(tvp, WRITE_LOCK); /* release old volume */
234 tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */
236 return ENODEV; /* oops, can't do it */
241 *acellidxp = cellidx;
251 afs_PutVolume(tvp, WRITE_LOCK);
256 EvalMountPoint(struct vcache *avc, struct vcache *advc,
257 struct volume **avolpp, struct vrequest *areq)
260 afs_uint32 avnoid, auniq;
262 AFS_STATCNT(EvalMountPoint);
264 code = afs_HandleLink(avc, areq);
268 /* Determine which cell and volume the mointpoint goes to */
269 code = EvalMountData(avc->linkData[0], avc->linkData + 1,
270 avc->f.states, avc->f.fid.Cell, avolpp, areq, 0, 0,
272 if (code) return code;
280 if (avc->mvid.target_root == NULL)
281 avc->mvid.target_root = osi_AllocSmallSpace(sizeof(struct VenusFid));
282 avc->mvid.target_root->Cell = (*avolpp)->cell;
283 avc->mvid.target_root->Fid.Volume = (*avolpp)->volume;
284 avc->mvid.target_root->Fid.Vnode = avnoid;
285 avc->mvid.target_root->Fid.Unique = auniq;
286 avc->f.states |= CMValid;
288 /* Used to: if the mount point is stored within a backup volume,
289 * then we should only update the parent pointer information if
290 * there's none already set, so as to avoid updating a volume's ..
291 * info with something in an OldFiles directory.
293 * Next two lines used to be under this if:
295 * if (!(avc->f.states & CBackup) || tvp->dotdot.Fid.Volume == 0)
297 * Now: update mount point back pointer on every call, so that we handle
298 * multiple mount points better. This way, when du tries to go back
299 * via chddir(".."), it will end up exactly where it started, yet
300 * cd'ing via a new path to a volume will reset the ".." pointer
303 (*avolpp)->mtpoint = avc->f.fid; /* setup back pointer to mtpoint */
306 (*avolpp)->dotdot = advc->f.fid;
314 * Must be called on an afs_fakestat_state object before calling
315 * afs_EvalFakeStat or afs_PutFakeStat. Calling afs_PutFakeStat
316 * without calling afs_EvalFakeStat is legal, as long as this
317 * function is called.
320 afs_InitFakeStat(struct afs_fakestat_state *state)
322 if (!afs_fakestat_enable)
327 state->need_release = 0;
331 * afs_EvalFakeStat_int
333 * The actual implementation of afs_EvalFakeStat and afs_TryEvalFakeStat,
334 * which is called by those wrapper functions.
336 * Only issues RPCs if canblock is non-zero.
339 afs_EvalFakeStat_int(struct vcache **avcp, struct afs_fakestat_state *state,
340 struct vrequest *areq, int canblock)
342 struct vcache *tvc, *root_vp;
343 struct volume *tvolp = NULL;
346 if (!afs_fakestat_enable)
349 osi_Assert(state->valid == 1);
350 osi_Assert(state->did_eval == 0);
354 if (tvc->mvstat != AFS_MVSTAT_MTPT)
358 /* Is the call to VerifyVCache really necessary? */
359 code = afs_VerifyVCache(tvc, areq);
363 ObtainWriteLock(&tvc->lock, 599);
364 code = EvalMountPoint(tvc, NULL, &tvolp, areq);
365 ReleaseWriteLock(&tvc->lock);
369 tvolp->dotdot = tvc->f.fid;
370 tvolp->dotdot.Fid.Vnode = tvc->f.parent.vnode;
371 tvolp->dotdot.Fid.Unique = tvc->f.parent.unique;
374 if (tvc->mvid.target_root && (tvc->f.states & CMValid)) {
380 ObtainReadLock(&afs_xvcache);
381 root_vp = afs_FindVCache(tvc->mvid.target_root, &retry, 0);
382 if (root_vp && retry) {
383 ReleaseReadLock(&afs_xvcache);
384 afs_PutVCache(root_vp);
386 } while (root_vp && retry);
387 ReleaseReadLock(&afs_xvcache);
389 root_vp = afs_GetVCache(tvc->mvid.target_root, areq);
392 code = canblock ? EIO : 0;
395 #ifdef AFS_DARWIN80_ENV
396 root_vp->f.m.Type = VDIR;
398 code = afs_darwin_finalizevnode(root_vp, NULL, NULL, 0, 0);
401 vnode_ref(AFSTOV(root_vp));
403 if (tvolp && !afs_InReadDir(root_vp)) {
404 /* Is this always kosher? Perhaps we should instead use
405 * NBObtainWriteLock to avoid potential deadlock.
407 ObtainWriteLock(&root_vp->lock, 598);
408 if (!root_vp->mvid.parent)
409 root_vp->mvid.parent = osi_AllocSmallSpace(sizeof(struct VenusFid));
410 *root_vp->mvid.parent = tvolp->dotdot;
411 ReleaseWriteLock(&root_vp->lock);
413 state->need_release = 1;
414 state->root_vp = root_vp;
418 code = canblock ? EIO : 0;
423 afs_PutVolume(tvolp, WRITE_LOCK);
430 * Automatically does the equivalent of EvalMountPoint for vcache entries
431 * which are mount points. Remembers enough state to properly release
432 * the volume root vcache when afs_PutFakeStat() is called.
434 * State variable must be initialized by afs_InitFakeState() beforehand.
436 * Returns 0 when everything succeeds and *avcp points to the vcache entry
437 * that should be used for the real vnode operation. Returns non-zero if
438 * something goes wrong and the error code should be returned to the user.
441 afs_EvalFakeStat(struct vcache **avcp, struct afs_fakestat_state *state,
442 struct vrequest *areq)
444 return afs_EvalFakeStat_int(avcp, state, areq, 1);
448 * afs_TryEvalFakeStat
450 * Same as afs_EvalFakeStat, but tries not to talk to remote servers
451 * and only evaluate the mount point if all the data is already in
454 * Returns 0 if everything succeeds and *avcp points to a valid
455 * vcache entry (possibly evaluated).
458 afs_TryEvalFakeStat(struct vcache **avcp, struct afs_fakestat_state *state,
459 struct vrequest *areq)
461 return afs_EvalFakeStat_int(avcp, state, areq, 0);
467 * Perform any necessary cleanup at the end of a vnode op, given that
468 * afs_InitFakeStat was previously called with this state.
471 afs_PutFakeStat(struct afs_fakestat_state *state)
473 if (!afs_fakestat_enable)
476 osi_Assert(state->valid == 1);
477 if (state->need_release)
478 afs_PutVCache(state->root_vp);
483 afs_ENameOK(char *aname)
487 AFS_STATCNT(ENameOK);
488 tlen = strlen(aname);
489 if (tlen >= 4 && strcmp(aname + tlen - 4, "@sys") == 0)
495 afs_getsysname(struct vrequest *areq, struct vcache *adp,
496 char *bufp, int *num, char **sysnamelist[])
501 AFS_STATCNT(getsysname);
503 *sysnamelist = afs_sysnamelist;
505 if (!afs_nfsexporter)
506 strcpy(bufp, (*sysnamelist)[0]);
508 au = afs_GetUser(areq->uid, adp->f.fid.Cell, READ_LOCK);
510 error = EXP_SYSNAME(au->exporter, (char *)0, sysnamelist, num, 0);
512 strcpy(bufp, "@sys");
513 afs_PutUser(au, READ_LOCK);
516 strcpy(bufp, (*sysnamelist)[0]);
519 strcpy(bufp, afs_sysname);
520 afs_PutUser(au, READ_LOCK);
526 Check_AtSys(struct vcache *avc, const char *aname,
527 struct sysname_info *state, struct vrequest *areq)
530 char **sysnamelist[MAXNUMSYSNAMES];
532 if (AFS_EQ_ATSYS(aname)) {
534 state->name = osi_AllocLargeSpace(MAXSYSNAME);
537 afs_getsysname(areq, avc, state->name, &num, sysnamelist);
542 state->name = (char *)aname;
547 Next_AtSys(struct vcache *avc, struct vrequest *areq,
548 struct sysname_info *state)
550 int num = afs_sysnamecount;
551 char **sysnamelist[MAXNUMSYSNAMES];
553 if (state->index == -1)
554 return 0; /* No list */
556 /* Check for the initial state of aname != "@sys" in Check_AtSys */
557 if (state->offset == -1 && state->allocked == 0) {
560 /* Check for .*@sys */
561 for (tname = state->name; *tname; tname++)
562 /*Move to the end of the string */ ;
564 if ((tname > state->name + 4) && (AFS_EQ_ATSYS(tname - 4))) {
565 state->offset = (tname - 4) - state->name;
566 tname = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
567 strncpy(tname, state->name, state->offset);
572 afs_getsysname(areq, avc, state->name + state->offset, &num,
576 return 0; /* .*@sys doesn't match either */
581 *sysnamelist = afs_sysnamelist;
583 if (afs_nfsexporter) {
584 au = afs_GetUser(areq->uid, avc->f.fid.Cell, READ_LOCK);
587 EXP_SYSNAME(au->exporter, (char *)0, sysnamelist, &num, 0);
589 afs_PutUser(au, READ_LOCK);
593 afs_PutUser(au, READ_LOCK);
595 if (++(state->index) >= num || !(*sysnamelist)[(unsigned int)state->index])
596 return 0; /* end of list */
598 strcpy(state->name + state->offset, (*sysnamelist)[(unsigned int)state->index]);
603 afs_CheckBulkStatus(struct afs_conn *tc, int nFids, AFSBulkStats *statParm,
609 if (statParm->AFSBulkStats_len != nFids || cbParm->AFSCBs_len != nFids) {
610 afs_warn("afs: BulkFetchStatus length %u/%u, expected %u\n",
611 (unsigned)statParm->AFSBulkStats_len,
612 (unsigned)cbParm->AFSCBs_len, nFids);
613 afs_BadFetchStatus(tc);
616 for (i = 0; i < nFids; i++) {
617 if (statParm->AFSBulkStats_val[i].errorCode) {
620 code = afs_CheckFetchStatus(tc, &statParm->AFSBulkStats_val[i]);
629 extern int BlobScan(struct dcache * afile, afs_int32 ablob, afs_int32 *ablobOut);
631 /* called with an unlocked directory and directory cookie. Areqp
632 * describes who is making the call.
633 * Scans the next N (about 30, typically) directory entries, and does
634 * a bulk stat call to stat them all.
636 * Must be very careful when merging in RPC responses, since we dont
637 * want to overwrite newer info that was added by a file system mutating
638 * call that ran concurrently with our bulk stat call.
640 * We do that, as described below, by not merging in our info (always
641 * safe to skip the merge) if the status info is valid in the vcache entry.
643 * If adapt ever implements the bulk stat RPC, then this code will need to
644 * ensure that vcaches created for failed RPC's to older servers have the
647 static struct vcache *BStvc = NULL;
650 afs_DoBulkStat(struct vcache *adp, long dirCookie, struct vrequest *areqp)
652 int nentries; /* # of entries to prefetch */
653 int nskip; /* # of slots in the LRU queue to skip */
654 #ifdef AFS_DARWIN80_ENV
658 struct vcache *lruvcp; /* vcache ptr of our goal pos in LRU queue */
659 struct dcache *dcp; /* chunk containing the dir block */
660 afs_size_t temp; /* temp for holding chunk length, &c. */
661 struct AFSFid *fidsp; /* file IDs were collecting */
662 struct AFSCallBack *cbsp; /* call back pointers */
663 struct AFSCallBack *tcbp; /* temp callback ptr */
664 struct AFSFetchStatus *statsp; /* file status info */
665 struct AFSVolSync volSync; /* vol sync return info */
666 struct vcache *tvcp; /* temp vcp */
667 struct afs_q *tq; /* temp queue variable */
668 AFSCBFids fidParm; /* file ID parm for bulk stat */
669 AFSBulkStats statParm; /* stat info parm for bulk stat */
670 int fidIndex = 0; /* which file were stating */
671 struct afs_conn *tcp = 0; /* conn for call */
672 AFSCBs cbParm; /* callback parm for bulk stat */
673 struct server *hostp = 0; /* host we got callback from */
674 long startTime; /* time we started the call,
675 * for callback expiration base
677 #if defined(AFS_DARWIN_ENV)
678 int ftype[4] = {VNON, VREG, VDIR, VLNK}; /* verify type is as expected */
680 afs_size_t statSeqNo = 0; /* Valued of file size to detect races */
681 int code; /* error code */
682 afs_int32 newIndex; /* new index in the dir */
683 struct DirBuffer entry; /* Buffer for dir manipulation */
684 struct DirEntry *dirEntryp; /* dir entry we are examining */
686 struct VenusFid afid; /* file ID we are using now */
687 struct VenusFid tfid; /* another temp. file ID */
688 afs_int32 retry; /* handle low-level SGI MP race conditions */
689 long volStates; /* flags from vol structure */
690 struct volume *volp = 0; /* volume ptr */
691 struct VenusFid dotdot = {0, {0, 0, 0}};
692 int flagIndex = 0; /* First file with bulk fetch flag set */
693 struct rx_connection *rxconn;
696 dotdot.Fid.Unique = 0;
697 dotdot.Fid.Vnode = 0;
699 /* first compute some basic parameters. We dont want to prefetch more
700 * than a fraction of the cache in any given call, and we want to preserve
701 * a portion of the LRU queue in any event, so as to avoid thrashing
702 * the entire stat cache (we will at least leave some of it alone).
703 * presently dont stat more than 1/8 the cache in any one call. */
704 nentries = afs_cacheStats / 8;
706 /* dont bother prefetching more than one calls worth of info */
707 if (nentries > AFSCBMAX)
710 /* heuristic to make sure that things fit in 4K. This means that
711 * we shouldnt make it any bigger than 47 entries. I am typically
712 * going to keep it a little lower, since we don't want to load
713 * too much of the stat cache.
718 /* now, to reduce the stack size, well allocate two 4K blocks,
719 * one for fids and callbacks, and one for stat info. Well set
720 * up our pointers to the memory from there, too.
722 statsp = osi_Alloc(AFSCBMAX * sizeof(AFSFetchStatus));
723 fidsp = osi_AllocLargeSpace(nentries * sizeof(AFSFid));
724 cbsp = osi_Alloc(AFSCBMAX * sizeof(AFSCallBack));
726 /* next, we must iterate over the directory, starting from the specified
727 * cookie offset (dirCookie), and counting out nentries file entries.
728 * We skip files that already have stat cache entries, since we
729 * dont want to bulk stat files that are already in the cache.
732 code = afs_VerifyVCache(adp, areqp);
736 dcp = afs_GetDCache(adp, (afs_size_t) 0, areqp, &temp, &temp, 1);
742 /* lock the directory cache entry */
743 ObtainReadLock(&adp->lock);
744 ObtainReadLock(&dcp->lock);
747 * Make sure that the data in the cache is current. There are two
748 * cases we need to worry about:
749 * 1. The cache data is being fetched by another process.
750 * 2. The cache data is no longer valid
752 while ((adp->f.states & CStatd)
753 && (dcp->dflags & DFFetching)
754 && afs_IsDCacheFresh(dcp, adp)) {
755 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING,
756 __FILE__, ICL_TYPE_INT32, __LINE__, ICL_TYPE_POINTER, dcp,
757 ICL_TYPE_INT32, dcp->dflags);
758 ReleaseReadLock(&dcp->lock);
759 ReleaseReadLock(&adp->lock);
760 afs_osi_Sleep(&dcp->validPos);
761 ObtainReadLock(&adp->lock);
762 ObtainReadLock(&dcp->lock);
764 if (!(adp->f.states & CStatd)
765 || !afs_IsDCacheFresh(dcp, adp)) {
766 ReleaseReadLock(&dcp->lock);
767 ReleaseReadLock(&adp->lock);
772 /* Generate a sequence number so we can tell whether we should
773 * store the attributes when processing the response. This number is
774 * stored in the file size when we set the CBulkFetching bit. If the
775 * CBulkFetching is still set and this value hasn't changed, then
776 * we know we were the last to set CBulkFetching bit for this file,
777 * and it is safe to set the status information for this file.
779 statSeqNo = bulkStatCounter++;
780 /* ensure against wrapping */
782 statSeqNo = bulkStatCounter++;
784 /* now we have dir data in the cache, so scan the dir page */
787 while (1) { /* Should probably have some constant bound */
788 /* look for first safe entry to examine in the directory. BlobScan
789 * looks for a the 1st allocated dir after the dirCookie slot.
791 code = BlobScan(dcp, (dirCookie >> 5), &newIndex);
792 if (code || newIndex == 0)
795 /* remember the updated directory cookie */
796 dirCookie = newIndex << 5;
798 /* get a ptr to the dir entry */
799 code = afs_dir_GetBlob(dcp, newIndex, &entry);
802 dirEntryp = (struct DirEntry *)entry.data;
804 /* dont copy more than we have room for */
805 if (fidIndex >= nentries) {
810 /* now, if the dir entry looks good, copy it out to our list. Vnode
811 * 0 means deleted, although it should also be free were it deleted.
813 if (dirEntryp->fid.vnode != 0) {
814 /* dont copy entries we have in our cache. This check will
815 * also make us skip "." and probably "..", unless it has
816 * disappeared from the cache since we did our namei call.
818 tfid.Cell = adp->f.fid.Cell;
819 tfid.Fid.Volume = adp->f.fid.Fid.Volume;
820 tfid.Fid.Vnode = ntohl(dirEntryp->fid.vnode);
821 tfid.Fid.Unique = ntohl(dirEntryp->fid.vunique);
824 ObtainSharedLock(&afs_xvcache, 130);
825 tvcp = afs_FindVCache(&tfid, &retry, IS_SLOCK /* no stats | LRU */ );
827 ReleaseSharedLock(&afs_xvcache);
830 } while (tvcp && retry);
831 if (!tvcp) { /* otherwise, create manually */
832 UpgradeSToWLock(&afs_xvcache, 129);
833 tvcp = afs_NewBulkVCache(&tfid, hostp, statSeqNo);
836 ObtainWriteLock(&tvcp->lock, 505);
837 #ifdef AFS_DARWIN80_ENV
838 /* use even/odd hack to guess file versus dir.
839 let links be reaped. oh well. */
840 if (dirEntryp->fid.vnode & 1)
841 tvcp->f.m.Type = VDIR;
843 tvcp->f.m.Type = VREG;
844 /* finalize to a best guess */
845 afs_darwin_finalizevnode(tvcp, AFSTOV(adp), NULL, 0, 1);
846 /* re-acquire usecount that finalizevnode disposed of */
847 vnode_ref(AFSTOV(tvcp));
849 ReleaseWriteLock(&afs_xvcache);
850 afs_RemoveVCB(&tfid);
851 ReleaseWriteLock(&tvcp->lock);
853 ReleaseWriteLock(&afs_xvcache);
856 ReleaseSharedLock(&afs_xvcache);
861 ReleaseReadLock(&dcp->lock);
862 ReleaseReadLock(&adp->lock);
864 goto done; /* can happen if afs_NewVCache fails */
867 /* WARNING: afs_DoBulkStat uses the Length field to store a
868 * sequence number for each bulk status request. Under no
869 * circumstances should afs_DoBulkStat store a sequence number
870 * if the new length will be ignored when afs_ProcessFS is
871 * called with new stats. */
873 if (!(tvcp->f.states & CStatd)
874 && (!((tvcp->f.states & CBulkFetching) &&
875 (tvcp->f.m.Length != statSeqNo)))
876 && (tvcp->execsOrWriters <= 0)
877 && !afs_DirtyPages(tvcp)
878 && !AFS_VN_MAPPED((vnode_t *) tvcp))
880 if (!(tvcp->f.states & CStatd)
881 && (!((tvcp->f.states & CBulkFetching) &&
882 (tvcp->f.m.Length != statSeqNo)))
883 && (tvcp->execsOrWriters <= 0)
884 && !afs_DirtyPages(tvcp))
888 /* this entry doesnt exist in the cache, and is not
889 * already being fetched by someone else, so add it to the
890 * list of file IDs to obtain.
892 * We detect a callback breaking race condition by checking the
893 * CBulkFetching state bit and the value in the file size.
894 * It is safe to set the status only if the CBulkFetching
895 * flag is still set and the value in the file size does
896 * not change. NewBulkVCache sets us up for the new ones.
897 * Set up the rest here.
899 * Don't fetch status for dirty files. We need to
900 * preserve the value of the file size. We could
901 * flush the pages, but it wouldn't be worthwhile.
903 if (!(tvcp->f.states & CBulkFetching)) {
904 tvcp->f.states |= CBulkFetching;
905 tvcp->f.m.Length = statSeqNo;
907 memcpy((char *)(fidsp + fidIndex), (char *)&tfid.Fid,
914 /* if dir vnode has non-zero entry */
915 /* move to the next dir entry by adding in the # of entries
916 * used by this dir entry.
918 temp = afs_dir_NameBlobs(dirEntryp->name) << 5;
923 } /* while loop over all dir entries */
925 /* now release the dir lock and prepare to make the bulk RPC */
926 ReleaseReadLock(&dcp->lock);
927 ReleaseReadLock(&adp->lock);
929 /* release the chunk */
932 /* dont make a null call */
937 /* setup the RPC parm structures */
938 fidParm.AFSCBFids_len = fidIndex;
939 fidParm.AFSCBFids_val = fidsp;
940 statParm.AFSBulkStats_len = fidIndex;
941 statParm.AFSBulkStats_val = statsp;
942 cbParm.AFSCBs_len = fidIndex;
943 cbParm.AFSCBs_val = cbsp;
945 /* start the timer; callback expirations are relative to this */
946 startTime = osi_Time();
948 tcp = afs_Conn(&adp->f.fid, areqp, SHARED_LOCK, &rxconn);
950 hostp = tcp->parent->srvr->server;
952 for (i = 0; i < fidIndex; i++) {
953 /* we must set tvcp->callback before the BulkStatus call, so
954 * we can detect concurrent InitCallBackState's */
956 afid.Cell = adp->f.fid.Cell;
957 afid.Fid.Volume = adp->f.fid.Fid.Volume;
958 afid.Fid.Vnode = fidsp[i].Vnode;
959 afid.Fid.Unique = fidsp[i].Unique;
963 ObtainReadLock(&afs_xvcache);
964 tvcp = afs_FindVCache(&afid, &retry, 0 /* !stats&!lru */);
965 ReleaseReadLock(&afs_xvcache);
966 } while (tvcp && retry);
972 if ((tvcp->f.states & CBulkFetching) &&
973 (tvcp->f.m.Length == statSeqNo)) {
974 tvcp->callback = hostp;
981 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_BULKSTATUS);
983 if (!(tcp->parent->srvr->server->flags & SNO_INLINEBULK)) {
986 RXAFS_InlineBulkStatus(rxconn, &fidParm, &statParm,
989 if (code == RXGEN_OPCODE) {
990 tcp->parent->srvr->server->flags |= SNO_INLINEBULK;
993 RXAFS_BulkStatus(rxconn, &fidParm, &statParm,
1000 RXAFS_BulkStatus(rxconn, &fidParm, &statParm, &cbParm,
1007 code = afs_CheckBulkStatus(tcp, fidIndex, &statParm, &cbParm);
1011 /* make sure we give afs_Analyze a chance to retry,
1012 * but if the RPC succeeded we may have entries to merge.
1013 * if we wipe code with one entry's status we get bogus failures.
1015 } while (afs_Analyze
1016 (tcp, rxconn, code ? code : (&statsp[0])->errorCode,
1017 &adp->f.fid, areqp, AFS_STATS_FS_RPCIDX_BULKSTATUS,
1018 SHARED_LOCK, NULL));
1020 /* now, if we didnt get the info, bail out. */
1024 /* we need vol flags to create the entries properly */
1025 dotdot.Fid.Volume = 0;
1026 volp = afs_GetVolume(&adp->f.fid, areqp, READ_LOCK);
1028 volStates = volp->states;
1029 if (volp->dotdot.Fid.Volume != 0)
1030 dotdot = volp->dotdot;
1034 /* find the place to merge the info into We do this by skipping
1035 * nskip entries in the LRU queue. The more we skip, the more
1036 * we preserve, since the head of the VLRU queue is the most recently
1040 nskip = afs_cacheStats / 2; /* preserved fraction of the cache */
1041 ObtainReadLock(&afs_xvcache);
1042 #ifdef AFS_DARWIN80_ENV
1045 if (QEmpty(&VLRU)) {
1046 /* actually a serious error, probably should panic. Probably will
1047 * panic soon, oh well. */
1048 ReleaseReadLock(&afs_xvcache);
1049 afs_warnuser("afs_DoBulkStat: VLRU empty!");
1052 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1053 refpanic("Bulkstat VLRU inconsistent");
1055 for (tq = VLRU.next; tq != &VLRU; tq = QNext(tq)) {
1057 #ifdef AFS_DARWIN80_ENV
1058 if ((!(QTOV(tq)->f.states & CDeadVnode)&&!(QTOV(tq)->f.states & CVInit)))
1062 if (QNext(QPrev(tq)) != tq) {
1064 refpanic("BulkStat VLRU inconsistent");
1070 lruvcp = QTOV(VLRU.next);
1072 /* now we have to hold this entry, so that it does not get moved
1073 * into the free list while we're running. It could still get
1074 * moved within the lru queue, but hopefully that will be rare; it
1075 * doesn't hurt nearly as much.
1078 #ifdef AFS_DARWIN80_ENV
1079 if (((lruvcp->f.states & CDeadVnode)||(lruvcp->f.states & CVInit))) {
1085 panic("Can't find non-dead vnode in VLRU\n");
1087 lruvp = AFSTOV(lruvcp);
1088 if (vnode_get(lruvp)) /* this bumps ref count */
1090 else if (vnode_ref(lruvp)) {
1092 /* AFSTOV(lruvcp) may be NULL */
1098 if (osi_vnhold(lruvcp) != 0) {
1102 ReleaseReadLock(&afs_xvcache); /* could be read lock */
1106 /* otherwise, merge in the info. We have to be quite careful here,
1107 * since we need to ensure that we don't merge old info over newer
1108 * stuff in a stat cache entry. We're very conservative here: we don't
1109 * do the merge at all unless we ourselves create the stat cache
1110 * entry. That's pretty safe, and should work pretty well, since we
1111 * typically expect to do the stat cache creation ourselves.
1113 * We also have to take into account racing token revocations.
1115 for (i = 0; i < fidIndex; i++) {
1116 if ((&statsp[i])->errorCode)
1118 afid.Cell = adp->f.fid.Cell;
1119 afid.Fid.Volume = adp->f.fid.Fid.Volume;
1120 afid.Fid.Vnode = fidsp[i].Vnode;
1121 afid.Fid.Unique = fidsp[i].Unique;
1124 ObtainReadLock(&afs_xvcache);
1125 tvcp = afs_FindVCache(&afid, &retry, 0/* !stats&!lru */);
1126 ReleaseReadLock(&afs_xvcache);
1127 } while (tvcp && retry);
1129 /* The entry may no longer exist */
1134 /* now we have the entry held, but we need to fill it in */
1135 ObtainWriteLock(&tvcp->lock, 131);
1137 /* if CBulkFetching is not set, or if the file size no longer
1138 * matches the value we placed there when we set the CBulkFetching
1139 * flag, then someone else has done something with this node,
1140 * and we may not have the latest status information for this
1141 * file. Leave the entry alone. There's also a file type
1142 * change here, for OSX bulkstat support.
1144 if (!(tvcp->f.states & CBulkFetching)
1145 || (tvcp->f.m.Length != statSeqNo)
1146 #if defined(AFS_DARWIN_ENV)
1147 || (ftype[(&statsp[i])->FileType] != vType(tvcp))
1151 ReleaseWriteLock(&tvcp->lock);
1152 afs_PutVCache(tvcp);
1156 /* now copy ".." entry back out of volume structure, if necessary */
1157 if (tvcp->mvstat == AFS_MVSTAT_ROOT && (dotdot.Fid.Volume != 0)) {
1158 if (!tvcp->mvid.parent)
1159 tvcp->mvid.parent = osi_AllocSmallSpace(sizeof(struct VenusFid));
1160 *tvcp->mvid.parent = dotdot;
1163 #ifdef AFS_DARWIN80_ENV
1164 if (((lruvcp->f.states & CDeadVnode)||(lruvcp->f.states & CVInit)))
1165 panic("vlru control point went dead\n");
1168 ObtainWriteLock(&afs_xvcache, 132);
1169 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1170 refpanic("Bulkstat VLRU inconsistent2");
1172 if ((QNext(QPrev(&tvcp->vlruq)) != &tvcp->vlruq)
1173 || (QPrev(QNext(&tvcp->vlruq)) != &tvcp->vlruq)) {
1174 refpanic("Bulkstat VLRU inconsistent4");
1176 if ((QNext(QPrev(&lruvcp->vlruq)) != &lruvcp->vlruq)
1177 || (QPrev(QNext(&lruvcp->vlruq)) != &lruvcp->vlruq)) {
1178 refpanic("Bulkstat VLRU inconsistent5");
1181 if (tvcp != lruvcp) { /* if they are == don't move it, don't corrupt vlru */
1182 QRemove(&tvcp->vlruq);
1183 QAdd(&lruvcp->vlruq, &tvcp->vlruq);
1186 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1187 refpanic("Bulkstat VLRU inconsistent3");
1189 if ((QNext(QPrev(&tvcp->vlruq)) != &tvcp->vlruq)
1190 || (QPrev(QNext(&tvcp->vlruq)) != &tvcp->vlruq)) {
1191 refpanic("Bulkstat VLRU inconsistent5");
1193 if ((QNext(QPrev(&lruvcp->vlruq)) != &lruvcp->vlruq)
1194 || (QPrev(QNext(&lruvcp->vlruq)) != &lruvcp->vlruq)) {
1195 refpanic("Bulkstat VLRU inconsistent6");
1197 ReleaseWriteLock(&afs_xvcache);
1199 ObtainWriteLock(&afs_xcbhash, 494);
1201 /* We need to check the flags again. We may have missed
1202 * something while we were waiting for a lock.
1204 if (!(tvcp->f.states & CBulkFetching) || (tvcp->f.m.Length != statSeqNo)) {
1206 ReleaseWriteLock(&tvcp->lock);
1207 ReleaseWriteLock(&afs_xcbhash);
1208 afs_PutVCache(tvcp);
1212 /* now merge in the resulting status back into the vnode.
1213 * We only do this if the entry looks clear.
1215 afs_ProcessFS(tvcp, &statsp[i], areqp);
1216 #if defined(AFS_LINUX22_ENV)
1217 afs_fill_inode(AFSTOV(tvcp), NULL); /* reset inode operations */
1220 /* do some accounting for bulk stats: mark this entry as
1221 * loaded, so we can tell if we use it before it gets
1224 tvcp->f.states |= CBulkStat;
1225 tvcp->f.states &= ~CBulkFetching;
1227 afs_bulkStatsDone++;
1229 /* merge in vol info */
1230 if (volStates & VRO)
1231 tvcp->f.states |= CRO;
1232 if (volStates & VBackup)
1233 tvcp->f.states |= CBackup;
1234 if (volStates & VForeign)
1235 tvcp->f.states |= CForeign;
1237 /* merge in the callback info */
1238 tvcp->f.states |= CTruth;
1240 /* get ptr to the callback we are interested in */
1243 if (tcbp->ExpirationTime != 0) {
1244 tvcp->cbExpires = tcbp->ExpirationTime + startTime;
1245 tvcp->callback = hostp;
1246 tvcp->f.states |= CStatd;
1247 afs_QueueCallback(tvcp, CBHash(tcbp->ExpirationTime), volp);
1248 } else if (tvcp->f.states & CRO) {
1249 /* ordinary callback on a read-only volume -- AFS 3.2 style */
1250 tvcp->cbExpires = 3600 + startTime;
1251 tvcp->callback = hostp;
1252 tvcp->f.states |= CStatd;
1253 afs_QueueCallback(tvcp, CBHash(3600), volp);
1255 afs_StaleVCacheFlags(tvcp,
1256 AFS_STALEVC_CBLOCKED | AFS_STALEVC_CLEARCB,
1259 #ifdef AFS_DARWIN80_ENV
1260 /* reclaim->FlushVCache will need xcbhash */
1261 if (((tvcp->f.states & CDeadVnode)||(tvcp->f.states & CVInit))) {
1262 ReleaseWriteLock(&afs_xcbhash);
1263 /* passing in a parent hangs getting the vnode lock */
1264 code = afs_darwin_finalizevnode(tvcp, NULL, NULL, 0, 1);
1266 /* It's gonna get recycled - shouldn't happen */
1267 afs_StaleVCacheFlags(tvcp,
1268 AFS_STALEVC_CBLOCKED | AFS_STALEVC_CLEARCB,
1271 /* re-acquire the usecount that finalizevnode disposed of */
1272 vnode_ref(AFSTOV(tvcp));
1275 ReleaseWriteLock(&afs_xcbhash);
1277 ReleaseWriteLock(&tvcp->lock);
1278 /* finally, we're done with the entry */
1279 afs_PutVCache(tvcp);
1280 } /* for all files we got back */
1282 /* finally return the pointer into the LRU queue */
1283 #ifdef AFS_DARWIN80_ENV
1284 if (((lruvcp->f.states & CDeadVnode)||(lruvcp->f.states & CVInit)))
1285 panic("vlru control point went dead before put\n");
1291 afs_PutVCache(lruvcp);
1295 /* Be sure to turn off the CBulkFetching flags */
1296 for (i = flagIndex; i < fidIndex; i++) {
1297 afid.Cell = adp->f.fid.Cell;
1298 afid.Fid.Volume = adp->f.fid.Fid.Volume;
1299 afid.Fid.Vnode = fidsp[i].Vnode;
1300 afid.Fid.Unique = fidsp[i].Unique;
1303 ObtainReadLock(&afs_xvcache);
1304 tvcp = afs_FindVCache(&afid, &retry, 0 /* !stats&!lru */);
1305 ReleaseReadLock(&afs_xvcache);
1306 } while (tvcp && retry);
1308 if ((tvcp->f.states & CBulkFetching)
1309 && (tvcp->f.m.Length == statSeqNo)) {
1310 tvcp->f.states &= ~CBulkFetching;
1312 afs_PutVCache(tvcp);
1316 afs_PutVolume(volp, READ_LOCK);
1319 osi_FreeLargeSpace((char *)fidsp);
1320 osi_Free((char *)statsp, AFSCBMAX * sizeof(AFSFetchStatus));
1321 osi_Free((char *)cbsp, AFSCBMAX * sizeof(AFSCallBack));
1325 #ifdef AFS_DARWIN80_ENV
1330 afs_ShouldTryBulkStat(struct vcache *adp)
1332 #ifdef AFS_DARWIN80_ENV
1337 if (AFS_IS_DISCONNECTED) {
1338 /* We can't prefetch entries if we're offline. */
1341 if (adp->opens < 1) {
1342 /* Don't bother prefetching entries if nobody is holding the dir open
1343 * while we're doing a lookup. */
1346 if ((adp->f.states & CForeign)) {
1347 /* Don't bulkstat for dfs xlator dirs. */
1350 if (afs_IsDynroot(adp)) {
1351 /* Don't prefetch dynroot entries; that's pointless, since we generate
1355 if (afs_InReadDir(adp)) {
1356 /* Don't bulkstat if we're in the middle of servicing a readdir() in
1357 * the same process. */
1364 osi_lookup_isdot(const char *aname)
1368 /* in Solaris, we can get passed "" as a path component if we are the
1369 * root directory, e.g. after a call to chroot. It is equivalent to
1373 #endif /* AFS_SUN5_ENV */
1374 if (aname[0] == '.' && !aname[1]) {
1381 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
1382 afs_lookup(OSI_VC_DECL(adp), char *aname, struct vcache **avcp, struct pathname *pnp, int flags, struct vnode *rdir, afs_ucred_t *acred)
1383 #elif defined(UKERNEL)
1384 afs_lookup(OSI_VC_DECL(adp), char *aname, struct vcache **avcp, afs_ucred_t *acred, int flags)
1386 afs_lookup(OSI_VC_DECL(adp), char *aname, struct vcache **avcp, afs_ucred_t *acred)
1389 struct vrequest *treq = NULL;
1391 struct vcache *tvc = 0;
1393 afs_int32 bulkcode = 0;
1394 int pass = 0, hit = 0;
1395 int force_eval = afs_fakestat_enable ? 0 : 1;
1397 afs_hyper_t versionNo;
1398 int no_read_access = 0;
1399 struct sysname_info sysState; /* used only for @sys checking */
1400 int dynrootRetry = 1;
1401 struct afs_fakestat_state fakestate;
1402 int tryEvalOnly = 0;
1404 /* Don't allow ENOENT errors, except for a specific code path where
1405 * 'enoent_prohibited' is cleared below. */
1406 int enoent_prohibited = 1;
1408 OSI_VC_CONVERT(adp);
1410 AFS_STATCNT(afs_lookup);
1411 afs_InitFakeStat(&fakestate);
1415 if ((code = afs_CreateReq(&treq, acred)))
1418 if (afs_fakestat_enable && adp->mvstat == AFS_MVSTAT_MTPT) {
1419 if (strcmp(aname, ".directory") == 0)
1423 #if defined(AFS_DARWIN_ENV)
1424 /* Workaround for MacOSX Finder, which tries to look for
1425 * .DS_Store and Contents under every directory.
1427 if (afs_fakestat_enable && adp->mvstat == AFS_MVSTAT_MTPT) {
1428 if (strcmp(aname, ".DS_Store") == 0)
1430 if (strcmp(aname, "Contents") == 0)
1433 if (afs_fakestat_enable && adp->mvstat == AFS_MVSTAT_ROOT) {
1434 if (strncmp(aname, "._", 2) == 0)
1440 code = afs_TryEvalFakeStat(&adp, &fakestate, treq);
1442 code = afs_EvalFakeStat(&adp, &fakestate, treq);
1444 /*printf("Code is %d\n", code);*/
1446 if (tryEvalOnly && adp->mvstat == AFS_MVSTAT_MTPT)
1451 /* come back to here if we encounter a non-existent object in a read-only
1452 * volume's directory */
1454 *avcp = NULL; /* Since some callers don't initialize it */
1457 if (!(adp->f.states & CStatd) && !afs_InReadDir(adp)) {
1458 if ((code = afs_VerifyVCache2(adp, treq))) {
1464 /* watch for ".." in a volume root */
1465 if (adp->mvstat == AFS_MVSTAT_ROOT && aname[0] == '.' && aname[1] == '.' && !aname[2]) {
1466 /* looking up ".." in root via special hacks */
1467 if (adp->mvid.parent == (struct VenusFid *)0 || adp->mvid.parent->Fid.Volume == 0) {
1471 /* otherwise we have the fid here, so we use it */
1472 /*printf("Getting vcache\n");*/
1473 tvc = afs_GetVCache(adp->mvid.parent, treq);
1474 afs_Trace3(afs_iclSetp, CM_TRACE_GETVCDOTDOT, ICL_TYPE_FID, adp->mvid.parent,
1475 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, code);
1477 code = (tvc ? 0 : EIO);
1479 if (tvc && !VREFCOUNT_GT(tvc, 0)) {
1483 /*printf("LOOKUP GETVCDOTDOT -> %d\n", code); */
1488 /* now check the access */
1489 if (treq->uid != adp->last_looker) {
1490 if (!afs_AccessOK(adp, PRSFS_LOOKUP, treq, CHECK_MODE_BITS)) {
1495 adp->last_looker = treq->uid;
1498 /* Check for read access as well. We need read access in order to
1499 * stat files, but not to stat subdirectories. */
1500 if (!afs_AccessOK(adp, PRSFS_READ, treq, CHECK_MODE_BITS))
1503 /* special case lookup of ".". Can we check for it sooner in this code,
1504 * for instance, way up before "redo:" ??
1505 * I'm not fiddling with the LRUQ here, either, perhaps I should, or else
1506 * invent a lightweight version of GetVCache.
1508 if (osi_lookup_isdot(aname)) { /* special case */
1509 ObtainReadLock(&afs_xvcache);
1510 if (osi_vnhold(adp) != 0) {
1511 ReleaseReadLock(&afs_xvcache);
1515 ReleaseReadLock(&afs_xvcache);
1516 #ifdef AFS_DARWIN80_ENV
1517 vnode_get(AFSTOV(adp));
1522 if (adp && !VREFCOUNT_GT(adp, 0)) {
1529 * Special case lookup of ".." in the dynamic mount directory.
1530 * The parent of this directory is _always_ the AFS root volume.
1532 if (afs_IsDynrootMount(adp) &&
1533 aname[0] == '.' && aname[1] == '.' && !aname[2]) {
1535 ObtainReadLock(&afs_xvcache);
1536 if (osi_vnhold(afs_globalVp) != 0) {
1537 ReleaseReadLock(&afs_xvcache);
1541 ReleaseReadLock(&afs_xvcache);
1542 #ifdef AFS_DARWIN80_ENV
1543 vnode_get(AFSTOV(afs_globalVp));
1546 *avcp = tvc = afs_globalVp;
1552 * Special case lookups in the dynamic mount directory.
1553 * The names here take the form cell:volume, similar to a mount point.
1554 * EvalMountData parses that and returns a cell and volume ID, which
1555 * we use to construct the appropriate dynroot Fid.
1557 if (afs_IsDynrootMount(adp)) {
1558 struct VenusFid tfid;
1559 afs_uint32 cellidx, volid, vnoid, uniq;
1561 code = EvalMountData('%', aname, 0, 0, NULL, treq, &cellidx, &volid, &vnoid, &uniq);
1564 /* If a vnode was returned, it's not a real mount point */
1566 struct cell *tcell = afs_GetCellByIndex(cellidx, READ_LOCK);
1567 tfid.Cell = tcell->cellNum;
1568 afs_PutCell(tcell, READ_LOCK);
1569 tfid.Fid.Vnode = vnoid;
1570 tfid.Fid.Volume = volid;
1571 tfid.Fid.Unique = uniq;
1573 afs_GetDynrootMountFid(&tfid);
1574 tfid.Fid.Vnode = VNUM_FROM_TYPEID(VN_TYPE_MOUNT, cellidx << 2);
1575 tfid.Fid.Unique = volid;
1577 *avcp = tvc = afs_GetVCache(&tfid, treq);
1578 code = (tvc ? 0 : EIO);
1583 #ifdef AFS_LINUX26_ENV
1585 * Special case of the dynamic mount volume in a static root.
1586 * This is really unfortunate, but we need this for the translator.
1588 if (adp == afs_globalVp && !afs_GetDynrootEnable() &&
1589 !strcmp(aname, AFS_DYNROOT_MOUNTNAME)) {
1590 struct VenusFid tfid;
1592 afs_GetDynrootMountFid(&tfid);
1593 *avcp = tvc = afs_GetVCache(&tfid, treq);
1600 Check_AtSys(adp, aname, &sysState, treq);
1601 tname = sysState.name;
1603 /* 1st Check_AtSys and lookup by tname is required here, for now,
1604 * because the dnlc is *not* told to remove entries for the parent
1605 * dir of file/dir op that afs_LocalHero likes, but dnlc is informed
1606 * if the cached entry for the parent dir is invalidated for a
1608 * Otherwise, we'd be able to do a dnlc lookup on an entry ending
1609 * w/@sys and know the dnlc was consistent with reality. */
1610 tvc = osi_dnlc_lookup(adp, tname, WRITE_LOCK);
1611 *avcp = tvc; /* maybe wasn't initialized, but it is now */
1613 if (no_read_access && vType(tvc) != VDIR && vType(tvc) != VLNK) {
1614 /* need read access on dir to stat non-directory / non-link */
1620 #ifdef AFS_LINUX22_ENV
1621 if (tvc->mvstat == AFS_MVSTAT_ROOT) { /* we don't trust the dnlc for root vcaches */
1622 AFS_RELE(AFSTOV(tvc));
1629 #else /* non - LINUX */
1633 #endif /* linux22 */
1636 { /* sub-block just to reduce stack usage */
1638 afs_size_t dirOffset, dirLen;
1639 struct VenusFid tfid;
1641 /* now we have to lookup the next fid */
1642 if (afs_InReadDir(adp))
1643 tdc = adp->dcreaddir;
1645 tdc = afs_GetDCache(adp, (afs_size_t) 0, treq,
1646 &dirOffset, &dirLen, 1);
1648 *avcp = NULL; /* redundant, but harmless */
1653 /* now we will just call dir package with appropriate inode.
1654 * Dirs are always fetched in their entirety for now */
1655 ObtainReadLock(&adp->lock);
1656 ObtainReadLock(&tdc->lock);
1659 * Make sure that the data in the cache is current. There are two
1660 * cases we need to worry about:
1661 * 1. The cache data is being fetched by another process.
1662 * 2. The cache data is no longer valid
1664 * If a readdir is in progress _in this thread_, it has a shared
1665 * lock on the vcache and has obtained current data, so we just
1666 * use that. This eliminates several possible deadlocks.
1668 if (!afs_InReadDir(adp)) {
1669 while ((adp->f.states & CStatd)
1670 && (tdc->dflags & DFFetching)
1671 && afs_IsDCacheFresh(tdc, adp)) {
1672 ReleaseReadLock(&tdc->lock);
1673 ReleaseReadLock(&adp->lock);
1674 afs_osi_Sleep(&tdc->validPos);
1675 ObtainReadLock(&adp->lock);
1676 ObtainReadLock(&tdc->lock);
1678 if (!(adp->f.states & CStatd)
1679 || !afs_IsDCacheFresh(tdc, adp)) {
1680 ReleaseReadLock(&tdc->lock);
1681 ReleaseReadLock(&adp->lock);
1683 if (tname && tname != aname)
1684 osi_FreeLargeSpace(tname);
1689 /* Save the version number for when we call osi_dnlc_enter */
1690 hset(versionNo, tdc->f.versionNo);
1693 * check for, and handle "@sys" if it's there. We should be able
1694 * to avoid the alloc and the strcpy with a little work, but it's
1695 * not pressing. If there aren't any remote users (ie, via the
1696 * NFS translator), we have a slightly easier job.
1697 * the faster way to do this is to check for *aname == '@' and if
1698 * it's there, check for @sys, otherwise, assume there's no @sys
1699 * then, if the lookup fails, check for .*@sys...
1701 /* above now implemented by Check_AtSys and Next_AtSys */
1703 /* lookup the name in the appropriate dir, and return a cache entry
1704 * on the resulting fid */
1706 afs_dir_LookupOffset(tdc, sysState.name, &tfid.Fid,
1709 /* If the first lookup doesn't succeed, maybe it's got @sys in the name */
1710 while (code == ENOENT && Next_AtSys(adp, treq, &sysState))
1712 afs_dir_LookupOffset(tdc, sysState.name, &tfid.Fid,
1714 tname = sysState.name;
1716 ReleaseReadLock(&tdc->lock);
1717 if (!afs_InReadDir(adp))
1719 if (code == ENOENT && afs_IsDynroot(adp) && dynrootRetry && !tryEvalOnly) {
1721 char *cn = (tname[0] == '.') ? tname + 1 : tname;
1722 ReleaseReadLock(&adp->lock);
1723 /* confirm it's not just hushed */
1724 tc = afs_GetCellByName(cn, WRITE_LOCK);
1726 if (tc->states & CHush) {
1727 tc->states &= ~CHush;
1728 ReleaseWriteLock(&tc->lock);
1729 afs_DynrootInvalidate();
1732 ReleaseWriteLock(&tc->lock);
1734 /* Allow a second dynroot retry if the cell was hushed before */
1736 if (tname[0] == '.')
1737 afs_LookupAFSDB(tname + 1);
1739 afs_LookupAFSDB(tname);
1740 if (tname && tname != aname)
1741 osi_FreeLargeSpace(tname);
1744 ReleaseReadLock(&adp->lock);
1747 /* new fid has same cell and volume */
1748 tfid.Cell = adp->f.fid.Cell;
1749 tfid.Fid.Volume = adp->f.fid.Fid.Volume;
1750 afs_Trace4(afs_iclSetp, CM_TRACE_LOOKUP, ICL_TYPE_POINTER, adp,
1751 ICL_TYPE_STRING, tname, ICL_TYPE_FID, &tfid,
1752 ICL_TYPE_INT32, code);
1755 if (code == ENOENT) {
1756 /* The target name really doesn't exist (according to
1757 * afs_dir_LookupOffset, anyway). */
1758 enoent_prohibited = 0;
1763 /* prefetch some entries, if the dir is currently open. The variable
1764 * dirCookie tells us where to start prefetching from.
1766 if (afs_ShouldTryBulkStat(adp)) {
1768 /* if the entry is not in the cache, or is in the cache,
1769 * but hasn't been statd, then do a bulk stat operation.
1773 ObtainReadLock(&afs_xvcache);
1774 tvc = afs_FindVCache(&tfid, &retry, 0 /* !stats,!lru */ );
1775 ReleaseReadLock(&afs_xvcache);
1776 } while (tvc && retry);
1778 if (!tvc || !(tvc->f.states & CStatd))
1779 bulkcode = afs_DoBulkStat(adp, dirCookie, treq);
1783 /* if the vcache isn't usable, release it */
1784 if (tvc && !(tvc->f.states & CStatd)) {
1793 /* now get the status info, if we don't already have it */
1794 /* This is kind of weird, but we might wind up accidentally calling
1795 * RXAFS_Lookup because we happened upon a file which legitimately
1796 * has a 0 uniquifier. That is the result of allowing unique to wrap
1797 * to 0. This was fixed in AFS 3.4. For CForeign, Unique == 0 means that
1798 * the file has not yet been looked up.
1801 if (!tfid.Fid.Unique && (adp->f.states & CForeign)) {
1802 tvc = afs_LookupVCache(&tfid, treq, adp, tname);
1804 if (!tvc && !bulkcode) { /* lookup failed or wasn't called */
1805 tvc = afs_GetVCache(&tfid, treq);
1808 } /* sub-block just to reduce stack usage */
1811 if (adp->f.states & CForeign)
1812 tvc->f.states |= CForeign;
1813 tvc->f.parent.vnode = adp->f.fid.Fid.Vnode;
1814 tvc->f.parent.unique = adp->f.fid.Fid.Unique;
1815 tvc->f.states &= ~CBulkStat;
1817 if (afs_fakestat_enable == 2 && tvc->mvstat == AFS_MVSTAT_MTPT) {
1818 ObtainSharedLock(&tvc->lock, 680);
1819 if (!tvc->linkData) {
1820 UpgradeSToWLock(&tvc->lock, 681);
1821 code = afs_HandleLink(tvc, treq);
1822 ConvertWToRLock(&tvc->lock);
1824 ConvertSToRLock(&tvc->lock);
1827 if (!code && !afs_strchr(tvc->linkData, ':'))
1829 ReleaseReadLock(&tvc->lock);
1831 if (tvc->mvstat == AFS_MVSTAT_MTPT && (tvc->f.states & CMValid) && tvc->mvid.target_root != NULL)
1832 force_eval = 1; /* This is now almost for free, get it correct */
1834 #if defined(UKERNEL)
1835 if (!(flags & AFS_LOOKUP_NOEVAL))
1836 /* don't eval mount points */
1837 #endif /* UKERNEL */
1838 if (tvc->mvstat == AFS_MVSTAT_MTPT && force_eval) {
1839 /* a mt point, possibly unevaluated */
1840 struct volume *tvolp;
1842 ObtainWriteLock(&tvc->lock, 133);
1843 code = EvalMountPoint(tvc, adp, &tvolp, treq);
1844 ReleaseWriteLock(&tvc->lock);
1849 afs_PutVolume(tvolp, WRITE_LOCK);
1853 /* next, we want to continue using the target of the mt point */
1854 if (tvc->mvid.target_root && (tvc->f.states & CMValid)) {
1856 /* now lookup target, to set .. pointer */
1857 afs_Trace2(afs_iclSetp, CM_TRACE_LOOKUP1,
1858 ICL_TYPE_POINTER, tvc, ICL_TYPE_FID,
1860 uvc = tvc; /* remember for later */
1862 if (tvolp && (tvolp->states & VForeign)) {
1863 /* XXXX tvolp has ref cnt on but not locked! XXX */
1865 afs_GetRootVCache(tvc->mvid.target_root, treq, tvolp);
1867 tvc = afs_GetVCache(tvc->mvid.target_root, treq);
1869 afs_PutVCache(uvc); /* we're done with it */
1874 afs_PutVolume(tvolp, WRITE_LOCK);
1879 /* now, if we came via a new mt pt (say because of a new
1880 * release of a R/O volume), we must reevaluate the ..
1881 * ptr to point back to the appropriate place */
1883 ObtainWriteLock(&tvc->lock, 134);
1884 if (tvc->mvid.parent == NULL) {
1886 osi_AllocSmallSpace(sizeof(struct VenusFid));
1888 /* setup backpointer */
1889 *tvc->mvid.parent = tvolp->dotdot;
1890 ReleaseWriteLock(&tvc->lock);
1891 afs_PutVolume(tvolp, WRITE_LOCK);
1897 afs_PutVolume(tvolp, WRITE_LOCK);
1902 if (tvc && !VREFCOUNT_GT(tvc, 0)) {
1907 /* if we get here, we found something in a directory that couldn't
1908 * be located (a Multics "connection failure"). If the volume is
1909 * read-only, we try flushing this entry from the cache and trying
1911 if (!AFS_IS_DISCONNECTED) {
1914 tv = afs_GetVolume(&adp->f.fid, treq, READ_LOCK);
1916 if (tv->states & VRO) {
1917 pass = 1; /* try this *once* */
1918 /* re-stat to get later version */
1919 afs_StaleVCache(adp);
1920 afs_PutVolume(tv, READ_LOCK);
1923 afs_PutVolume(tv, READ_LOCK);
1933 /* put the network buffer back, if need be */
1934 if (tname != aname && tname)
1935 osi_FreeLargeSpace(tname);
1939 afs_AddMarinerName(aname, tvc);
1941 #if defined(UKERNEL)
1942 if (!(flags & AFS_LOOKUP_NOEVAL)) {
1943 /* Here we don't enter the name into the DNLC because we want the
1944 * evaluated mount dir to be there (the vcache for the mounted
1945 * volume) rather than the vc of the mount point itself. We can
1946 * still find the mount point's vc in the vcache by its fid. */
1947 #endif /* UKERNEL */
1948 if (!hit && (force_eval || tvc->mvstat != AFS_MVSTAT_MTPT)) {
1949 osi_dnlc_enter(adp, aname, tvc, &versionNo);
1951 #ifdef AFS_LINUX20_ENV
1952 /* So Linux inode cache is up to date. */
1953 code = afs_VerifyVCache(tvc, treq);
1955 afs_PutFakeStat(&fakestate);
1956 afs_DestroyReq(treq);
1957 AFS_DISCON_UNLOCK();
1958 return 0; /* can't have been any errors if hit and !code */
1961 #if defined(UKERNEL)
1968 code = afs_CheckCode(code, treq, 19);
1970 /* If there is an error, make sure *avcp is null.
1971 * Alphas panic otherwise - defect 10719.
1975 if (code == ENOENT && enoent_prohibited) {
1977 * We got an ENOENT error, but we didn't get it while looking up the
1978 * dir entry in the relevant dir blob. That means we likely hit some
1979 * other internal error; don't allow us to return ENOENT in this case,
1980 * since some platforms cache ENOENT errors, and the target path name
1981 * may actually exist.
1986 afs_PutFakeStat(&fakestate);
1987 afs_DestroyReq(treq);
1988 AFS_DISCON_UNLOCK();