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 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 */
72 if ((afs_strtoi_r(data, &endptr, &cellnum) == 0) &&
74 tcell = afs_GetCell(cellnum, READ_LOCK);
76 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 /* Still not found. If we are looking for the RO, then perhaps the RW
204 * doesn't exist? Try adding ".readonly" to volname and look for that.
205 * Don't know why we do this. Would have still found it in above call - jpm.
207 if (!tvp && (prefetch == 2) && len < AFS_SMALLOCSIZ - 10) {
208 buf = (char *)osi_AllocSmallSpace(len + 10);
210 strcpy(buf, volnamep);
211 afs_strcat(buf, ".readonly");
213 tvp = afs_GetVolumeByName(buf, mtptCell, 1, areq, WRITE_LOCK);
215 /* Try the associated linked cell if failed */
216 if (!tvp && hac && areq->volumeError) {
217 tvp = afs_GetVolumeByName(buf, assocCell, 1, areq, WRITE_LOCK);
219 osi_FreeSmallSpace(buf);
221 /* done with volname */
225 return ENODEV; /* Couldn't find the volume */
229 /* Don't cross mountpoint from a BK to a BK volume */
230 if ((states & CBackup) && (tvp->states & VBackup)) {
231 afs_PutVolume(tvp, WRITE_LOCK);
235 /* If we want (prefetched) the BK and it exists, then drop the RW volume
237 * Otherwise, if we want (prefetched0 the RO and it exists, then drop the
238 * RW volume and get the RO.
239 * Otherwise, go with the RW.
241 if ((prefetch == 3) && tvp->backVol) {
242 tfid.Fid.Volume = tvp->backVol; /* remember BK volume */
243 tfid.Cell = tvp->cell;
244 afs_PutVolume(tvp, WRITE_LOCK); /* release old volume */
245 tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */
247 return ENODEV; /* oops, can't do it */
248 } else if ((prefetch >= 2) && tvp->roVol) {
249 tfid.Fid.Volume = tvp->roVol; /* remember RO volume */
250 tfid.Cell = tvp->cell;
251 afs_PutVolume(tvp, WRITE_LOCK); /* release old volume */
252 tvp = afs_GetVolume(&tfid, areq, WRITE_LOCK); /* get the new one */
254 return ENODEV; /* oops, can't do it */
259 *acellidxp = cellidx;
269 afs_PutVolume(tvp, WRITE_LOCK);
274 EvalMountPoint(struct vcache *avc, struct vcache *advc,
275 struct volume **avolpp, struct vrequest *areq)
278 afs_uint32 avnoid, auniq;
280 AFS_STATCNT(EvalMountPoint);
282 if (avc->mvid && (avc->f.states & CMValid))
283 return 0; /* done while racing */
286 code = afs_HandleLink(avc, areq);
290 /* Determine which cell and volume the mointpoint goes to */
291 code = EvalMountData(avc->linkData[0], avc->linkData + 1,
292 avc->f.states, avc->f.fid.Cell, avolpp, areq, 0, 0,
294 if (code) return code;
304 (struct VenusFid *)osi_AllocSmallSpace(sizeof(struct VenusFid));
305 avc->mvid->Cell = (*avolpp)->cell;
306 avc->mvid->Fid.Volume = (*avolpp)->volume;
307 avc->mvid->Fid.Vnode = avnoid;
308 avc->mvid->Fid.Unique = auniq;
309 avc->f.states |= CMValid;
311 /* Used to: if the mount point is stored within a backup volume,
312 * then we should only update the parent pointer information if
313 * there's none already set, so as to avoid updating a volume's ..
314 * info with something in an OldFiles directory.
316 * Next two lines used to be under this if:
318 * if (!(avc->f.states & CBackup) || tvp->dotdot.Fid.Volume == 0)
320 * Now: update mount point back pointer on every call, so that we handle
321 * multiple mount points better. This way, when du tries to go back
322 * via chddir(".."), it will end up exactly where it started, yet
323 * cd'ing via a new path to a volume will reset the ".." pointer
326 (*avolpp)->mtpoint = avc->f.fid; /* setup back pointer to mtpoint */
329 (*avolpp)->dotdot = advc->f.fid;
337 * Must be called on an afs_fakestat_state object before calling
338 * afs_EvalFakeStat or afs_PutFakeStat. Calling afs_PutFakeStat
339 * without calling afs_EvalFakeStat is legal, as long as this
340 * function is called.
343 afs_InitFakeStat(struct afs_fakestat_state *state)
345 if (!afs_fakestat_enable)
350 state->need_release = 0;
354 * afs_EvalFakeStat_int
356 * The actual implementation of afs_EvalFakeStat and afs_TryEvalFakeStat,
357 * which is called by those wrapper functions.
359 * Only issues RPCs if canblock is non-zero.
362 afs_EvalFakeStat_int(struct vcache **avcp, struct afs_fakestat_state *state,
363 struct vrequest *areq, int canblock)
365 struct vcache *tvc, *root_vp;
366 struct volume *tvolp = NULL;
369 if (!afs_fakestat_enable)
372 osi_Assert(state->valid == 1);
373 osi_Assert(state->did_eval == 0);
377 if (tvc->mvstat != 1)
381 /* Is the call to VerifyVCache really necessary? */
382 code = afs_VerifyVCache(tvc, areq);
386 ObtainWriteLock(&tvc->lock, 599);
387 code = EvalMountPoint(tvc, NULL, &tvolp, areq);
388 ReleaseWriteLock(&tvc->lock);
392 tvolp->dotdot = tvc->f.fid;
393 tvolp->dotdot.Fid.Vnode = tvc->f.parent.vnode;
394 tvolp->dotdot.Fid.Unique = tvc->f.parent.unique;
397 if (tvc->mvid && (tvc->f.states & CMValid)) {
403 ObtainWriteLock(&afs_xvcache, 597);
404 root_vp = afs_FindVCache(tvc->mvid, &retry, IS_WLOCK);
405 if (root_vp && retry) {
406 ReleaseWriteLock(&afs_xvcache);
407 afs_PutVCache(root_vp);
409 } while (root_vp && retry);
410 ReleaseWriteLock(&afs_xvcache);
412 root_vp = afs_GetVCache(tvc->mvid, areq, NULL, NULL);
415 code = canblock ? ENOENT : 0;
418 #ifdef AFS_DARWIN80_ENV
419 root_vp->f.m.Type = VDIR;
421 code = afs_darwin_finalizevnode(root_vp, NULL, NULL, 0, 0);
424 vnode_ref(AFSTOV(root_vp));
426 if (tvolp && !afs_InReadDir(root_vp)) {
427 /* Is this always kosher? Perhaps we should instead use
428 * NBObtainWriteLock to avoid potential deadlock.
430 ObtainWriteLock(&root_vp->lock, 598);
432 root_vp->mvid = osi_AllocSmallSpace(sizeof(struct VenusFid));
433 *root_vp->mvid = tvolp->dotdot;
434 ReleaseWriteLock(&root_vp->lock);
436 state->need_release = 1;
437 state->root_vp = root_vp;
441 code = canblock ? ENOENT : 0;
446 afs_PutVolume(tvolp, WRITE_LOCK);
453 * Automatically does the equivalent of EvalMountPoint for vcache entries
454 * which are mount points. Remembers enough state to properly release
455 * the volume root vcache when afs_PutFakeStat() is called.
457 * State variable must be initialized by afs_InitFakeState() beforehand.
459 * Returns 0 when everything succeeds and *avcp points to the vcache entry
460 * that should be used for the real vnode operation. Returns non-zero if
461 * something goes wrong and the error code should be returned to the user.
464 afs_EvalFakeStat(struct vcache **avcp, struct afs_fakestat_state *state,
465 struct vrequest *areq)
467 return afs_EvalFakeStat_int(avcp, state, areq, 1);
471 * afs_TryEvalFakeStat
473 * Same as afs_EvalFakeStat, but tries not to talk to remote servers
474 * and only evaluate the mount point if all the data is already in
477 * Returns 0 if everything succeeds and *avcp points to a valid
478 * vcache entry (possibly evaluated).
481 afs_TryEvalFakeStat(struct vcache **avcp, struct afs_fakestat_state *state,
482 struct vrequest *areq)
484 return afs_EvalFakeStat_int(avcp, state, areq, 0);
490 * Perform any necessary cleanup at the end of a vnode op, given that
491 * afs_InitFakeStat was previously called with this state.
494 afs_PutFakeStat(struct afs_fakestat_state *state)
496 if (!afs_fakestat_enable)
499 osi_Assert(state->valid == 1);
500 if (state->need_release)
501 afs_PutVCache(state->root_vp);
506 afs_ENameOK(char *aname)
510 AFS_STATCNT(ENameOK);
511 tlen = strlen(aname);
512 if (tlen >= 4 && strcmp(aname + tlen - 4, "@sys") == 0)
518 afs_getsysname(struct vrequest *areq, struct vcache *adp,
519 char *bufp, int *num, char **sysnamelist[])
524 AFS_STATCNT(getsysname);
526 *sysnamelist = afs_sysnamelist;
528 if (!afs_nfsexporter)
529 strcpy(bufp, (*sysnamelist)[0]);
531 au = afs_GetUser(areq->uid, adp->f.fid.Cell, READ_LOCK);
533 error = EXP_SYSNAME(au->exporter, (char *)0, sysnamelist, num, 0);
535 strcpy(bufp, "@sys");
536 afs_PutUser(au, READ_LOCK);
539 strcpy(bufp, (*sysnamelist)[0]);
542 strcpy(bufp, afs_sysname);
543 afs_PutUser(au, READ_LOCK);
549 Check_AtSys(struct vcache *avc, const char *aname,
550 struct sysname_info *state, struct vrequest *areq)
553 char **sysnamelist[MAXNUMSYSNAMES];
555 if (AFS_EQ_ATSYS(aname)) {
557 state->name = (char *)osi_AllocLargeSpace(MAXSYSNAME);
560 afs_getsysname(areq, avc, state->name, &num, sysnamelist);
565 state->name = (char *)aname;
570 Next_AtSys(struct vcache *avc, struct vrequest *areq,
571 struct sysname_info *state)
573 int num = afs_sysnamecount;
574 char **sysnamelist[MAXNUMSYSNAMES];
576 if (state->index == -1)
577 return 0; /* No list */
579 /* Check for the initial state of aname != "@sys" in Check_AtSys */
580 if (state->offset == -1 && state->allocked == 0) {
583 /* Check for .*@sys */
584 for (tname = state->name; *tname; tname++)
585 /*Move to the end of the string */ ;
587 if ((tname > state->name + 4) && (AFS_EQ_ATSYS(tname - 4))) {
588 state->offset = (tname - 4) - state->name;
589 tname = (char *)osi_AllocLargeSpace(AFS_LRALLOCSIZ);
590 strncpy(tname, state->name, state->offset);
595 afs_getsysname(areq, avc, state->name + state->offset, &num,
599 return 0; /* .*@sys doesn't match either */
604 *sysnamelist = afs_sysnamelist;
606 if (afs_nfsexporter) {
607 au = afs_GetUser(areq->uid, avc->f.fid.Cell, READ_LOCK);
610 EXP_SYSNAME(au->exporter, (char *)0, sysnamelist, &num, 0);
612 afs_PutUser(au, READ_LOCK);
616 afs_PutUser(au, READ_LOCK);
618 if (++(state->index) >= num || !(*sysnamelist)[(unsigned int)state->index])
619 return 0; /* end of list */
621 strcpy(state->name + state->offset, (*sysnamelist)[(unsigned int)state->index]);
625 extern int BlobScan(struct dcache * afile, afs_int32 ablob);
627 /* called with an unlocked directory and directory cookie. Areqp
628 * describes who is making the call.
629 * Scans the next N (about 30, typically) directory entries, and does
630 * a bulk stat call to stat them all.
632 * Must be very careful when merging in RPC responses, since we dont
633 * want to overwrite newer info that was added by a file system mutating
634 * call that ran concurrently with our bulk stat call.
636 * We do that, as described below, by not merging in our info (always
637 * safe to skip the merge) if the status info is valid in the vcache entry.
639 * If adapt ever implements the bulk stat RPC, then this code will need to
640 * ensure that vcaches created for failed RPC's to older servers have the
643 static struct vcache *BStvc = NULL;
646 afs_DoBulkStat(struct vcache *adp, long dirCookie, struct vrequest *areqp)
648 int nentries; /* # of entries to prefetch */
649 int nskip; /* # of slots in the LRU queue to skip */
650 #ifdef AFS_DARWIN80_ENV
654 struct vcache *lruvcp; /* vcache ptr of our goal pos in LRU queue */
655 struct dcache *dcp; /* chunk containing the dir block */
656 afs_size_t temp; /* temp for holding chunk length, &c. */
657 struct AFSFid *fidsp; /* file IDs were collecting */
658 struct AFSCallBack *cbsp; /* call back pointers */
659 struct AFSCallBack *tcbp; /* temp callback ptr */
660 struct AFSFetchStatus *statsp; /* file status info */
661 struct AFSVolSync volSync; /* vol sync return info */
662 struct vcache *tvcp; /* temp vcp */
663 struct afs_q *tq; /* temp queue variable */
664 AFSCBFids fidParm; /* file ID parm for bulk stat */
665 AFSBulkStats statParm; /* stat info parm for bulk stat */
666 int fidIndex = 0; /* which file were stating */
667 struct afs_conn *tcp = 0; /* conn for call */
668 AFSCBs cbParm; /* callback parm for bulk stat */
669 struct server *hostp = 0; /* host we got callback from */
670 long startTime; /* time we started the call,
671 * for callback expiration base
673 int ftype[4] = {VNON, VREG, VDIR, VLNK}; /* verify type is as expected */
674 afs_size_t statSeqNo = 0; /* Valued of file size to detect races */
675 int code; /* error code */
676 long newIndex; /* new index in the dir */
677 struct DirBuffer entry; /* Buffer for dir manipulation */
678 struct DirEntry *dirEntryp; /* dir entry we are examining */
680 struct VenusFid afid; /* file ID we are using now */
681 struct VenusFid tfid; /* another temp. file ID */
682 afs_int32 retry; /* handle low-level SGI MP race conditions */
683 long volStates; /* flags from vol structure */
684 struct volume *volp = 0; /* volume ptr */
685 struct VenusFid dotdot = {0, {0, 0, 0}};
686 int flagIndex = 0; /* First file with bulk fetch flag set */
687 int inlinebulk = 0; /* Did we use InlineBulk RPC or not? */
688 struct rx_connection *rxconn;
691 dotdot.Fid.Unique = 0;
692 dotdot.Fid.Vnode = 0;
694 /* first compute some basic parameters. We dont want to prefetch more
695 * than a fraction of the cache in any given call, and we want to preserve
696 * a portion of the LRU queue in any event, so as to avoid thrashing
697 * the entire stat cache (we will at least leave some of it alone).
698 * presently dont stat more than 1/8 the cache in any one call. */
699 nentries = afs_cacheStats / 8;
701 /* dont bother prefetching more than one calls worth of info */
702 if (nentries > AFSCBMAX)
705 /* heuristic to make sure that things fit in 4K. This means that
706 * we shouldnt make it any bigger than 47 entries. I am typically
707 * going to keep it a little lower, since we don't want to load
708 * too much of the stat cache.
713 /* now, to reduce the stack size, well allocate two 4K blocks,
714 * one for fids and callbacks, and one for stat info. Well set
715 * up our pointers to the memory from there, too.
717 statsp = (AFSFetchStatus *)
718 osi_Alloc(AFSCBMAX * sizeof(AFSFetchStatus));
719 fidsp = (AFSFid *) osi_AllocLargeSpace(nentries * sizeof(AFSFid));
720 cbsp = (AFSCallBack *)
721 osi_Alloc(AFSCBMAX * sizeof(AFSCallBack));
723 /* next, we must iterate over the directory, starting from the specified
724 * cookie offset (dirCookie), and counting out nentries file entries.
725 * We skip files that already have stat cache entries, since we
726 * dont want to bulk stat files that are already in the cache.
729 code = afs_VerifyVCache(adp, areqp);
733 dcp = afs_GetDCache(adp, (afs_size_t) 0, areqp, &temp, &temp, 1);
739 /* lock the directory cache entry */
740 ObtainReadLock(&adp->lock);
741 ObtainReadLock(&dcp->lock);
744 * Make sure that the data in the cache is current. There are two
745 * cases we need to worry about:
746 * 1. The cache data is being fetched by another process.
747 * 2. The cache data is no longer valid
749 while ((adp->f.states & CStatd)
750 && (dcp->dflags & DFFetching)
751 && hsame(adp->f.m.DataVersion, dcp->f.versionNo)) {
752 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING,
753 __FILE__, ICL_TYPE_INT32, __LINE__, ICL_TYPE_POINTER, dcp,
754 ICL_TYPE_INT32, dcp->dflags);
755 ReleaseReadLock(&dcp->lock);
756 ReleaseReadLock(&adp->lock);
757 afs_osi_Sleep(&dcp->validPos);
758 ObtainReadLock(&adp->lock);
759 ObtainReadLock(&dcp->lock);
761 if (!(adp->f.states & CStatd)
762 || !hsame(adp->f.m.DataVersion, dcp->f.versionNo)) {
763 ReleaseReadLock(&dcp->lock);
764 ReleaseReadLock(&adp->lock);
769 /* Generate a sequence number so we can tell whether we should
770 * store the attributes when processing the response. This number is
771 * stored in the file size when we set the CBulkFetching bit. If the
772 * CBulkFetching is still set and this value hasn't changed, then
773 * we know we were the last to set CBulkFetching bit for this file,
774 * and it is safe to set the status information for this file.
776 statSeqNo = bulkStatCounter++;
777 /* ensure against wrapping */
779 statSeqNo = bulkStatCounter++;
781 /* now we have dir data in the cache, so scan the dir page */
784 while (1) { /* Should probably have some constant bound */
785 /* look for first safe entry to examine in the directory. BlobScan
786 * looks for a the 1st allocated dir after the dirCookie slot.
788 newIndex = BlobScan(dcp, (dirCookie >> 5));
792 /* remember the updated directory cookie */
793 dirCookie = newIndex << 5;
795 /* get a ptr to the dir entry */
796 code = afs_dir_GetBlob(dcp, newIndex, &entry);
799 dirEntryp = (struct DirEntry *)entry.data;
801 /* dont copy more than we have room for */
802 if (fidIndex >= nentries) {
807 /* now, if the dir entry looks good, copy it out to our list. Vnode
808 * 0 means deleted, although it should also be free were it deleted.
810 if (dirEntryp->fid.vnode != 0) {
811 /* dont copy entries we have in our cache. This check will
812 * also make us skip "." and probably "..", unless it has
813 * disappeared from the cache since we did our namei call.
815 tfid.Cell = adp->f.fid.Cell;
816 tfid.Fid.Volume = adp->f.fid.Fid.Volume;
817 tfid.Fid.Vnode = ntohl(dirEntryp->fid.vnode);
818 tfid.Fid.Unique = ntohl(dirEntryp->fid.vunique);
821 ObtainWriteLock(&afs_xvcache, 130);
822 tvcp = afs_FindVCache(&tfid, &retry, IS_WLOCK /* no stats | LRU */ );
824 ReleaseWriteLock(&afs_xvcache);
827 } while (tvcp && retry);
828 if (!tvcp) { /* otherwise, create manually */
829 tvcp = afs_NewBulkVCache(&tfid, hostp, statSeqNo);
832 ObtainWriteLock(&tvcp->lock, 505);
833 #ifdef AFS_DARWIN80_ENV
834 /* use even/odd hack to guess file versus dir.
835 let links be reaped. oh well. */
836 if (dirEntryp->fid.vnode & 1)
837 tvcp->f.m.Type = VDIR;
839 tvcp->f.m.Type = VREG;
840 /* finalize to a best guess */
841 afs_darwin_finalizevnode(tvcp, VTOAFS(adp), NULL, 0, 1);
842 /* re-acquire usecount that finalizevnode disposed of */
843 vnode_ref(AFSTOV(tvcp));
845 ReleaseWriteLock(&afs_xvcache);
846 afs_RemoveVCB(&tfid);
847 ReleaseWriteLock(&tvcp->lock);
849 ReleaseWriteLock(&afs_xvcache);
852 ReleaseWriteLock(&afs_xvcache);
857 ReleaseReadLock(&dcp->lock);
858 ReleaseReadLock(&adp->lock);
860 goto done; /* can happen if afs_NewVCache fails */
863 /* WARNING: afs_DoBulkStat uses the Length field to store a
864 * sequence number for each bulk status request. Under no
865 * circumstances should afs_DoBulkStat store a sequence number
866 * if the new length will be ignored when afs_ProcessFS is
867 * called with new stats. */
869 if (!(tvcp->f.states & CStatd)
870 && (!((tvcp->f.states & CBulkFetching) &&
871 (tvcp->f.m.Length != statSeqNo)))
872 && (tvcp->execsOrWriters <= 0)
873 && !afs_DirtyPages(tvcp)
874 && !AFS_VN_MAPPED((vnode_t *) tvcp))
876 if (!(tvcp->f.states & CStatd)
877 && (!((tvcp->f.states & CBulkFetching) &&
878 (tvcp->f.m.Length != statSeqNo)))
879 && (tvcp->execsOrWriters <= 0)
880 && !afs_DirtyPages(tvcp))
884 /* this entry doesnt exist in the cache, and is not
885 * already being fetched by someone else, so add it to the
886 * list of file IDs to obtain.
888 * We detect a callback breaking race condition by checking the
889 * CBulkFetching state bit and the value in the file size.
890 * It is safe to set the status only if the CBulkFetching
891 * flag is still set and the value in the file size does
892 * not change. NewBulkVCache sets us up for the new ones.
893 * Set up the rest here.
895 * Don't fetch status for dirty files. We need to
896 * preserve the value of the file size. We could
897 * flush the pages, but it wouldn't be worthwhile.
899 if (!(tvcp->f.states & CBulkFetching)) {
900 tvcp->f.states |= CBulkFetching;
901 tvcp->f.m.Length = statSeqNo;
903 memcpy((char *)(fidsp + fidIndex), (char *)&tfid.Fid,
910 /* if dir vnode has non-zero entry */
911 /* move to the next dir entry by adding in the # of entries
912 * used by this dir entry.
914 temp = afs_dir_NameBlobs(dirEntryp->name) << 5;
919 } /* while loop over all dir entries */
921 /* now release the dir lock and prepare to make the bulk RPC */
922 ReleaseReadLock(&dcp->lock);
923 ReleaseReadLock(&adp->lock);
925 /* release the chunk */
928 /* dont make a null call */
933 /* setup the RPC parm structures */
934 fidParm.AFSCBFids_len = fidIndex;
935 fidParm.AFSCBFids_val = fidsp;
936 statParm.AFSBulkStats_len = fidIndex;
937 statParm.AFSBulkStats_val = statsp;
938 cbParm.AFSCBs_len = fidIndex;
939 cbParm.AFSCBs_val = cbsp;
941 /* start the timer; callback expirations are relative to this */
942 startTime = osi_Time();
944 tcp = afs_Conn(&adp->f.fid, areqp, SHARED_LOCK, &rxconn);
946 hostp = tcp->parent->srvr->server;
948 for (i = 0; i < fidIndex; i++) {
949 /* we must set tvcp->callback before the BulkStatus call, so
950 * we can detect concurrent InitCallBackState's */
952 afid.Cell = adp->f.fid.Cell;
953 afid.Fid.Volume = adp->f.fid.Fid.Volume;
954 afid.Fid.Vnode = fidsp[i].Vnode;
955 afid.Fid.Unique = fidsp[i].Unique;
959 ObtainReadLock(&afs_xvcache);
960 tvcp = afs_FindVCache(&afid, &retry, 0 /* !stats&!lru */);
961 ReleaseReadLock(&afs_xvcache);
962 } while (tvcp && retry);
968 if ((tvcp->f.states & CBulkFetching) &&
969 (tvcp->f.m.Length == statSeqNo)) {
970 tvcp->callback = hostp;
977 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_BULKSTATUS);
979 if (!(tcp->parent->srvr->server->flags & SNO_INLINEBULK)) {
983 RXAFS_InlineBulkStatus(rxconn, &fidParm, &statParm,
986 if (code == RXGEN_OPCODE) {
987 tcp->parent->srvr->server->flags |= SNO_INLINEBULK;
991 RXAFS_BulkStatus(rxconn, &fidParm, &statParm,
996 if (!code && ((&statsp[0])->errorCode)) {
998 * If this is an error needing retry, do so.
999 * Retryable errors are all whole-volume or
1002 if (afs_Analyze(tcp, rxconn, (&statsp[0])->errorCode,
1004 AFS_STATS_FS_RPCIDX_BULKSTATUS,
1005 SHARED_LOCK, NULL) != 0)
1013 RXAFS_BulkStatus(rxconn, &fidParm, &statParm, &cbParm,
1020 } while (afs_Analyze
1021 (tcp, rxconn, code, &adp->f.fid, areqp, AFS_STATS_FS_RPCIDX_BULKSTATUS,
1022 SHARED_LOCK, NULL));
1024 /* now, if we didnt get the info, bail out. */
1028 /* we need vol flags to create the entries properly */
1029 dotdot.Fid.Volume = 0;
1030 volp = afs_GetVolume(&adp->f.fid, areqp, READ_LOCK);
1032 volStates = volp->states;
1033 if (volp->dotdot.Fid.Volume != 0)
1034 dotdot = volp->dotdot;
1038 /* find the place to merge the info into We do this by skipping
1039 * nskip entries in the LRU queue. The more we skip, the more
1040 * we preserve, since the head of the VLRU queue is the most recently
1044 nskip = afs_cacheStats / 2; /* preserved fraction of the cache */
1045 ObtainReadLock(&afs_xvcache);
1046 #ifdef AFS_DARWIN80_ENV
1049 if (QEmpty(&VLRU)) {
1050 /* actually a serious error, probably should panic. Probably will
1051 * panic soon, oh well. */
1052 ReleaseReadLock(&afs_xvcache);
1053 afs_warnuser("afs_DoBulkStat: VLRU empty!");
1056 if ((VLRU.next->prev != &VLRU) || (VLRU.prev->next != &VLRU)) {
1057 refpanic("Bulkstat VLRU inconsistent");
1059 for (tq = VLRU.next; tq != &VLRU; tq = QNext(tq)) {
1061 #ifdef AFS_DARWIN80_ENV
1062 if ((!(QTOV(tq)->f.states & CDeadVnode)&&!(QTOV(tq)->f.states & CVInit)))
1066 if (QNext(QPrev(tq)) != tq) {
1068 refpanic("BulkStat VLRU inconsistent");
1074 lruvcp = QTOV(VLRU.next);
1076 /* now we have to hold this entry, so that it does not get moved
1077 * into the free list while we're running. It could still get
1078 * moved within the lru queue, but hopefully that will be rare; it
1079 * doesn't hurt nearly as much.
1082 #ifdef AFS_DARWIN80_ENV
1083 if (((lruvcp->f.states & CDeadVnode)||(lruvcp->f.states & CVInit))) {
1089 panic("Can't find non-dead vnode in VLRU\n");
1091 lruvp = AFSTOV(lruvcp);
1092 if (vnode_get(lruvp)) /* this bumps ref count */
1094 else if (vnode_ref(lruvp)) {
1096 /* AFSTOV(lruvcp) may be NULL */
1102 osi_vnhold(lruvcp, &retry);
1104 ReleaseReadLock(&afs_xvcache); /* could be read lock */
1108 /* otherwise, merge in the info. We have to be quite careful here,
1109 * since we need to ensure that we don't merge old info over newer
1110 * stuff in a stat cache entry. We're very conservative here: we don't
1111 * do the merge at all unless we ourselves create the stat cache
1112 * entry. That's pretty safe, and should work pretty well, since we
1113 * typically expect to do the stat cache creation ourselves.
1115 * We also have to take into account racing token revocations.
1117 for (i = 0; i < fidIndex; i++) {
1118 if ((&statsp[i])->errorCode)
1120 afid.Cell = adp->f.fid.Cell;
1121 afid.Fid.Volume = adp->f.fid.Fid.Volume;
1122 afid.Fid.Vnode = fidsp[i].Vnode;
1123 afid.Fid.Unique = fidsp[i].Unique;
1126 ObtainReadLock(&afs_xvcache);
1127 tvcp = afs_FindVCache(&afid, &retry, 0/* !stats&!lru */);
1128 ReleaseReadLock(&afs_xvcache);
1129 } while (tvcp && retry);
1131 /* The entry may no longer exist */
1136 /* now we have the entry held, but we need to fill it in */
1137 ObtainWriteLock(&tvcp->lock, 131);
1139 /* if CBulkFetching is not set, or if the file size no longer
1140 * matches the value we placed there when we set the CBulkFetching
1141 * flag, then someone else has done something with this node,
1142 * and we may not have the latest status information for this
1143 * file. Leave the entry alone. There's also a file type
1144 * change here, for OSX bulkstat support.
1146 if (!(tvcp->f.states & CBulkFetching)
1147 || (tvcp->f.m.Length != statSeqNo)
1148 || (ftype[(&statsp[i])->FileType] != vType(tvcp))) {
1150 ReleaseWriteLock(&tvcp->lock);
1151 afs_PutVCache(tvcp);
1155 /* now copy ".." entry back out of volume structure, if necessary */
1156 if (tvcp->mvstat == 2 && (dotdot.Fid.Volume != 0)) {
1158 tvcp->mvid = (struct VenusFid *)
1159 osi_AllocSmallSpace(sizeof(struct VenusFid));
1160 *tvcp->mvid = 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);
1256 tvcp->f.states &= ~(CStatd | CUnique);
1257 afs_DequeueCallback(tvcp);
1258 if ((tvcp->f.states & CForeign) || (vType(tvcp) == VDIR))
1259 osi_dnlc_purgedp(tvcp); /* if it (could be) a directory */
1261 #ifdef AFS_DARWIN80_ENV
1262 /* reclaim->FlushVCache will need xcbhash */
1263 if (((tvcp->f.states & CDeadVnode)||(tvcp->f.states & CVInit))) {
1264 ReleaseWriteLock(&afs_xcbhash);
1265 /* passing in a parent hangs getting the vnode lock */
1266 code = afs_darwin_finalizevnode(tvcp, NULL, NULL, 0, 1);
1268 /* It's gonna get recycled - shouldn't happen */
1270 tvcp->f.states &= ~(CStatd | CUnique);
1271 afs_DequeueCallback(tvcp);
1272 if ((tvcp->f.states & CForeign) || (vType(tvcp) == VDIR))
1273 osi_dnlc_purgedp(tvcp); /* if it (could be) a directory */
1275 /* re-acquire the usecount that finalizevnode disposed of */
1276 vnode_ref(AFSTOV(tvcp));
1279 ReleaseWriteLock(&afs_xcbhash);
1281 ReleaseWriteLock(&tvcp->lock);
1282 /* finally, we're done with the entry */
1283 afs_PutVCache(tvcp);
1284 } /* for all files we got back */
1286 /* finally return the pointer into the LRU queue */
1287 #ifdef AFS_DARWIN80_ENV
1288 if (((lruvcp->f.states & CDeadVnode)||(lruvcp->f.states & CVInit)))
1289 panic("vlru control point went dead before put\n");
1295 afs_PutVCache(lruvcp);
1299 /* Be sure to turn off the CBulkFetching flags */
1300 for (i = flagIndex; i < fidIndex; i++) {
1301 afid.Cell = adp->f.fid.Cell;
1302 afid.Fid.Volume = adp->f.fid.Fid.Volume;
1303 afid.Fid.Vnode = fidsp[i].Vnode;
1304 afid.Fid.Unique = fidsp[i].Unique;
1307 ObtainReadLock(&afs_xvcache);
1308 tvcp = afs_FindVCache(&afid, &retry, 0 /* !stats&!lru */);
1309 ReleaseReadLock(&afs_xvcache);
1310 } while (tvcp && retry);
1312 if ((tvcp->f.states & CBulkFetching)
1313 && (tvcp->f.m.Length == statSeqNo)) {
1314 tvcp->f.states &= ~CBulkFetching;
1316 afs_PutVCache(tvcp);
1320 afs_PutVolume(volp, READ_LOCK);
1322 /* If we did the InlineBulk RPC pull out the return code */
1323 if (inlinebulk && code == 0) {
1324 if ((&statsp[0])->errorCode) {
1325 afs_Analyze(tcp, rxconn, (&statsp[0])->errorCode, &adp->f.fid, areqp,
1326 AFS_STATS_FS_RPCIDX_BULKSTATUS, SHARED_LOCK, NULL);
1327 code = (&statsp[0])->errorCode;
1333 osi_FreeLargeSpace((char *)fidsp);
1334 osi_Free((char *)statsp, AFSCBMAX * sizeof(AFSFetchStatus));
1335 osi_Free((char *)cbsp, AFSCBMAX * sizeof(AFSCallBack));
1339 /* was: (AFS_DEC_ENV) || defined(AFS_OSF30_ENV) || defined(AFS_NCR_ENV) */
1340 #ifdef AFS_DARWIN80_ENV
1343 static int AFSDOBULK = 1;
1347 osi_lookup_isdot(const char *aname)
1351 /* in Solaris, we can get passed "" as a path component if we are the
1352 * root directory, e.g. after a call to chroot. It is equivalent to
1356 #endif /* AFS_SUN5_ENV */
1357 if (aname[0] == '.' && !aname[1]) {
1364 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
1365 afs_lookup(OSI_VC_DECL(adp), char *aname, struct vcache **avcp, struct pathname *pnp, int flags, struct vnode *rdir, afs_ucred_t *acred)
1366 #elif defined(UKERNEL)
1367 afs_lookup(OSI_VC_DECL(adp), char *aname, struct vcache **avcp, afs_ucred_t *acred, int flags)
1369 afs_lookup(OSI_VC_DECL(adp), char *aname, struct vcache **avcp, afs_ucred_t *acred)
1372 struct vrequest treq;
1374 struct vcache *tvc = 0;
1376 afs_int32 bulkcode = 0;
1377 int pass = 0, hit = 0;
1378 int force_eval = afs_fakestat_enable ? 0 : 1;
1380 extern afs_int32 afs_mariner; /*Writing activity to log? */
1381 afs_hyper_t versionNo;
1382 int no_read_access = 0;
1383 struct sysname_info sysState; /* used only for @sys checking */
1384 int dynrootRetry = 1;
1385 struct afs_fakestat_state fakestate;
1386 int tryEvalOnly = 0;
1387 OSI_VC_CONVERT(adp);
1389 AFS_STATCNT(afs_lookup);
1390 afs_InitFakeStat(&fakestate);
1394 if ((code = afs_InitReq(&treq, acred)))
1397 if (afs_fakestat_enable && adp->mvstat == 1) {
1398 if (strcmp(aname, ".directory") == 0)
1402 #if defined(AFS_DARWIN_ENV)
1403 /* Workaround for MacOSX Finder, which tries to look for
1404 * .DS_Store and Contents under every directory.
1406 if (afs_fakestat_enable && adp->mvstat == 1) {
1407 if (strcmp(aname, ".DS_Store") == 0)
1409 if (strcmp(aname, "Contents") == 0)
1412 if (afs_fakestat_enable && adp->mvstat == 2) {
1413 if (strncmp(aname, "._", 2) == 0)
1419 code = afs_TryEvalFakeStat(&adp, &fakestate, &treq);
1421 code = afs_EvalFakeStat(&adp, &fakestate, &treq);
1423 /*printf("Code is %d\n", code);*/
1425 if (tryEvalOnly && adp->mvstat == 1)
1430 *avcp = NULL; /* Since some callers don't initialize it */
1432 /* come back to here if we encounter a non-existent object in a read-only
1433 * volume's directory */
1436 *avcp = NULL; /* Since some callers don't initialize it */
1439 if (!(adp->f.states & CStatd) && !afs_InReadDir(adp)) {
1440 if ((code = afs_VerifyVCache2(adp, &treq))) {
1446 /* watch for ".." in a volume root */
1447 if (adp->mvstat == 2 && aname[0] == '.' && aname[1] == '.' && !aname[2]) {
1448 /* looking up ".." in root via special hacks */
1449 if (adp->mvid == (struct VenusFid *)0 || adp->mvid->Fid.Volume == 0) {
1453 /* otherwise we have the fid here, so we use it */
1454 /*printf("Getting vcache\n");*/
1455 tvc = afs_GetVCache(adp->mvid, &treq, NULL, NULL);
1456 afs_Trace3(afs_iclSetp, CM_TRACE_GETVCDOTDOT, ICL_TYPE_FID, adp->mvid,
1457 ICL_TYPE_POINTER, tvc, ICL_TYPE_INT32, code);
1459 code = (tvc ? 0 : ENOENT);
1461 if (tvc && !VREFCOUNT_GT(tvc, 0)) {
1465 /*printf("LOOKUP GETVCDOTDOT -> %d\n", code); */
1470 /* now check the access */
1471 if (treq.uid != adp->last_looker) {
1472 if (!afs_AccessOK(adp, PRSFS_LOOKUP, &treq, CHECK_MODE_BITS)) {
1477 adp->last_looker = treq.uid;
1480 /* Check for read access as well. We need read access in order to
1481 * stat files, but not to stat subdirectories. */
1482 if (!afs_AccessOK(adp, PRSFS_READ, &treq, CHECK_MODE_BITS))
1485 /* special case lookup of ".". Can we check for it sooner in this code,
1486 * for instance, way up before "redo:" ??
1487 * I'm not fiddling with the LRUQ here, either, perhaps I should, or else
1488 * invent a lightweight version of GetVCache.
1490 if (osi_lookup_isdot(aname)) { /* special case */
1491 ObtainReadLock(&afs_xvcache);
1493 ReleaseReadLock(&afs_xvcache);
1494 #ifdef AFS_DARWIN80_ENV
1495 vnode_get(AFSTOV(adp));
1500 if (adp && !VREFCOUNT_GT(adp, 0)) {
1507 * Special case lookup of ".." in the dynamic mount directory.
1508 * The parent of this directory is _always_ the AFS root volume.
1510 if (afs_IsDynrootMount(adp) &&
1511 aname[0] == '.' && aname[1] == '.' && !aname[2]) {
1513 ObtainReadLock(&afs_xvcache);
1514 osi_vnhold(afs_globalVp, 0);
1515 ReleaseReadLock(&afs_xvcache);
1516 #ifdef AFS_DARWIN80_ENV
1517 vnode_get(AFSTOV(afs_globalVp));
1520 *avcp = tvc = afs_globalVp;
1526 * Special case lookups in the dynamic mount directory.
1527 * The names here take the form cell:volume, similar to a mount point.
1528 * EvalMountData parses that and returns a cell and volume ID, which
1529 * we use to construct the appropriate dynroot Fid.
1531 if (afs_IsDynrootMount(adp)) {
1532 struct VenusFid tfid;
1533 afs_uint32 cellidx, volid, vnoid, uniq;
1535 code = EvalMountData('%', aname, 0, 0, NULL, &treq, &cellidx, &volid, &vnoid, &uniq);
1538 /* If a vnode was returned, it's not a real mount point */
1540 struct cell *tcell = afs_GetCellByIndex(cellidx, READ_LOCK);
1541 tfid.Cell = tcell->cellNum;
1542 afs_PutCell(tcell, READ_LOCK);
1543 tfid.Fid.Vnode = vnoid;
1544 tfid.Fid.Volume = volid;
1545 tfid.Fid.Unique = uniq;
1547 afs_GetDynrootMountFid(&tfid);
1548 tfid.Fid.Vnode = VNUM_FROM_TYPEID(VN_TYPE_MOUNT, cellidx << 2);
1549 tfid.Fid.Unique = volid;
1551 *avcp = tvc = afs_GetVCache(&tfid, &treq, NULL, NULL);
1552 code = (tvc ? 0 : ENOENT);
1557 #ifdef AFS_LINUX26_ENV
1559 * Special case of the dynamic mount volume in a static root.
1560 * This is really unfortunate, but we need this for the translator.
1562 if (adp == afs_globalVp && !afs_GetDynrootEnable() &&
1563 !strcmp(aname, AFS_DYNROOT_MOUNTNAME)) {
1564 struct VenusFid tfid;
1566 afs_GetDynrootMountFid(&tfid);
1567 *avcp = tvc = afs_GetVCache(&tfid, &treq, NULL, NULL);
1574 Check_AtSys(adp, aname, &sysState, &treq);
1575 tname = sysState.name;
1577 /* 1st Check_AtSys and lookup by tname is required here, for now,
1578 * because the dnlc is *not* told to remove entries for the parent
1579 * dir of file/dir op that afs_LocalHero likes, but dnlc is informed
1580 * if the cached entry for the parent dir is invalidated for a
1582 * Otherwise, we'd be able to do a dnlc lookup on an entry ending
1583 * w/@sys and know the dnlc was consistent with reality. */
1584 tvc = osi_dnlc_lookup(adp, tname, WRITE_LOCK);
1585 *avcp = tvc; /* maybe wasn't initialized, but it is now */
1587 if (no_read_access && vType(tvc) != VDIR && vType(tvc) != VLNK) {
1588 /* need read access on dir to stat non-directory / non-link */
1594 #ifdef AFS_LINUX22_ENV
1595 if (tvc->mvstat == 2) { /* we don't trust the dnlc for root vcaches */
1596 AFS_RELE(AFSTOV(tvc));
1603 #else /* non - LINUX */
1607 #endif /* linux22 */
1610 { /* sub-block just to reduce stack usage */
1612 afs_size_t dirOffset, dirLen;
1613 struct VenusFid tfid;
1615 /* now we have to lookup the next fid */
1616 if (afs_InReadDir(adp))
1617 tdc = adp->dcreaddir;
1619 tdc = afs_GetDCache(adp, (afs_size_t) 0, &treq,
1620 &dirOffset, &dirLen, 1);
1622 *avcp = NULL; /* redundant, but harmless */
1627 /* now we will just call dir package with appropriate inode.
1628 * Dirs are always fetched in their entirety for now */
1629 ObtainReadLock(&adp->lock);
1630 ObtainReadLock(&tdc->lock);
1633 * Make sure that the data in the cache is current. There are two
1634 * cases we need to worry about:
1635 * 1. The cache data is being fetched by another process.
1636 * 2. The cache data is no longer valid
1638 * If a readdir is in progress _in this thread_, it has a shared
1639 * lock on the vcache and has obtained current data, so we just
1640 * use that. This eliminates several possible deadlocks.
1642 if (!afs_InReadDir(adp)) {
1643 while ((adp->f.states & CStatd)
1644 && (tdc->dflags & DFFetching)
1645 && hsame(adp->f.m.DataVersion, tdc->f.versionNo)) {
1646 ReleaseReadLock(&tdc->lock);
1647 ReleaseReadLock(&adp->lock);
1648 afs_osi_Sleep(&tdc->validPos);
1649 ObtainReadLock(&adp->lock);
1650 ObtainReadLock(&tdc->lock);
1652 if (!(adp->f.states & CStatd)
1653 || !hsame(adp->f.m.DataVersion, tdc->f.versionNo)) {
1654 ReleaseReadLock(&tdc->lock);
1655 ReleaseReadLock(&adp->lock);
1657 if (tname && tname != aname)
1658 osi_FreeLargeSpace(tname);
1663 /* Save the version number for when we call osi_dnlc_enter */
1664 hset(versionNo, tdc->f.versionNo);
1667 * check for, and handle "@sys" if it's there. We should be able
1668 * to avoid the alloc and the strcpy with a little work, but it's
1669 * not pressing. If there aren't any remote users (ie, via the
1670 * NFS translator), we have a slightly easier job.
1671 * the faster way to do this is to check for *aname == '@' and if
1672 * it's there, check for @sys, otherwise, assume there's no @sys
1673 * then, if the lookup fails, check for .*@sys...
1675 /* above now implemented by Check_AtSys and Next_AtSys */
1677 /* lookup the name in the appropriate dir, and return a cache entry
1678 * on the resulting fid */
1680 afs_dir_LookupOffset(tdc, sysState.name, &tfid.Fid,
1683 /* If the first lookup doesn't succeed, maybe it's got @sys in the name */
1684 while (code == ENOENT && Next_AtSys(adp, &treq, &sysState))
1686 afs_dir_LookupOffset(tdc, sysState.name, &tfid.Fid,
1688 tname = sysState.name;
1690 ReleaseReadLock(&tdc->lock);
1691 if (!afs_InReadDir(adp))
1693 if (code == ENOENT && afs_IsDynroot(adp) && dynrootRetry && !tryEvalOnly) {
1695 char *cn = (tname[0] == '.') ? tname + 1 : tname;
1696 ReleaseReadLock(&adp->lock);
1697 /* confirm it's not just hushed */
1698 tc = afs_GetCellByName(cn, WRITE_LOCK);
1700 if (tc->states & CHush) {
1701 tc->states &= ~CHush;
1702 ReleaseWriteLock(&tc->lock);
1703 afs_DynrootInvalidate();
1706 ReleaseWriteLock(&tc->lock);
1708 /* Allow a second dynroot retry if the cell was hushed before */
1710 if (tname[0] == '.')
1711 afs_LookupAFSDB(tname + 1);
1713 afs_LookupAFSDB(tname);
1714 if (tname && tname != aname)
1715 osi_FreeLargeSpace(tname);
1718 ReleaseReadLock(&adp->lock);
1721 /* new fid has same cell and volume */
1722 tfid.Cell = adp->f.fid.Cell;
1723 tfid.Fid.Volume = adp->f.fid.Fid.Volume;
1724 afs_Trace4(afs_iclSetp, CM_TRACE_LOOKUP, ICL_TYPE_POINTER, adp,
1725 ICL_TYPE_STRING, tname, ICL_TYPE_FID, &tfid,
1726 ICL_TYPE_INT32, code);
1729 if (code != ENOENT) {
1730 /*printf("LOOKUP dirLookupOff -> %d\n", code);*/
1735 /* prefetch some entries, if the dir is currently open. The variable
1736 * dirCookie tells us where to start prefetching from.
1738 if (!AFS_IS_DISCONNECTED &&
1739 AFSDOBULK && adp->opens > 0 && !(adp->f.states & CForeign)
1740 && !afs_IsDynroot(adp) && !afs_InReadDir(adp)) {
1742 /* if the entry is not in the cache, or is in the cache,
1743 * but hasn't been statd, then do a bulk stat operation.
1747 ObtainReadLock(&afs_xvcache);
1748 tvc = afs_FindVCache(&tfid, &retry, 0 /* !stats,!lru */ );
1749 ReleaseReadLock(&afs_xvcache);
1750 } while (tvc && retry);
1752 if (!tvc || !(tvc->f.states & CStatd))
1753 bulkcode = afs_DoBulkStat(adp, dirCookie, &treq);
1757 /* if the vcache isn't usable, release it */
1758 if (tvc && !(tvc->f.states & CStatd)) {
1767 /* now get the status info, if we don't already have it */
1768 /* This is kind of weird, but we might wind up accidentally calling
1769 * RXAFS_Lookup because we happened upon a file which legitimately
1770 * has a 0 uniquifier. That is the result of allowing unique to wrap
1771 * to 0. This was fixed in AFS 3.4. For CForeign, Unique == 0 means that
1772 * the file has not yet been looked up.
1775 afs_int32 cached = 0;
1776 if (!tfid.Fid.Unique && (adp->f.states & CForeign)) {
1777 tvc = afs_LookupVCache(&tfid, &treq, &cached, adp, tname);
1779 if (!tvc && !bulkcode) { /* lookup failed or wasn't called */
1780 tvc = afs_GetVCache(&tfid, &treq, &cached, NULL);
1783 } /* sub-block just to reduce stack usage */
1786 if (adp->f.states & CForeign)
1787 tvc->f.states |= CForeign;
1788 tvc->f.parent.vnode = adp->f.fid.Fid.Vnode;
1789 tvc->f.parent.unique = adp->f.fid.Fid.Unique;
1790 tvc->f.states &= ~CBulkStat;
1792 if (afs_fakestat_enable == 2 && tvc->mvstat == 1) {
1793 ObtainSharedLock(&tvc->lock, 680);
1794 if (!tvc->linkData) {
1795 UpgradeSToWLock(&tvc->lock, 681);
1796 code = afs_HandleLink(tvc, &treq);
1797 ConvertWToRLock(&tvc->lock);
1799 ConvertSToRLock(&tvc->lock);
1802 if (!code && !afs_strchr(tvc->linkData, ':'))
1804 ReleaseReadLock(&tvc->lock);
1806 if (tvc->mvstat == 1 && (tvc->f.states & CMValid) && tvc->mvid != NULL)
1807 force_eval = 1; /* This is now almost for free, get it correct */
1809 #if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS)
1810 if (!(flags & AFS_LOOKUP_NOEVAL))
1811 /* don't eval mount points */
1812 #endif /* UKERNEL && AFS_WEB_ENHANCEMENTS */
1813 if (tvc->mvstat == 1 && force_eval) {
1814 /* a mt point, possibly unevaluated */
1815 struct volume *tvolp;
1817 ObtainWriteLock(&tvc->lock, 133);
1818 code = EvalMountPoint(tvc, adp, &tvolp, &treq);
1819 ReleaseWriteLock(&tvc->lock);
1824 afs_PutVolume(tvolp, WRITE_LOCK);
1828 /* next, we want to continue using the target of the mt point */
1829 if (tvc->mvid && (tvc->f.states & CMValid)) {
1831 /* now lookup target, to set .. pointer */
1832 afs_Trace2(afs_iclSetp, CM_TRACE_LOOKUP1,
1833 ICL_TYPE_POINTER, tvc, ICL_TYPE_FID,
1835 uvc = tvc; /* remember for later */
1837 if (tvolp && (tvolp->states & VForeign)) {
1838 /* XXXX tvolp has ref cnt on but not locked! XXX */
1840 afs_GetRootVCache(tvc->mvid, &treq, NULL, tvolp);
1842 tvc = afs_GetVCache(tvc->mvid, &treq, NULL, NULL);
1844 afs_PutVCache(uvc); /* we're done with it */
1849 afs_PutVolume(tvolp, WRITE_LOCK);
1854 /* now, if we came via a new mt pt (say because of a new
1855 * release of a R/O volume), we must reevaluate the ..
1856 * ptr to point back to the appropriate place */
1858 ObtainWriteLock(&tvc->lock, 134);
1859 if (tvc->mvid == NULL) {
1860 tvc->mvid = (struct VenusFid *)
1861 osi_AllocSmallSpace(sizeof(struct VenusFid));
1863 /* setup backpointer */
1864 *tvc->mvid = tvolp->dotdot;
1865 ReleaseWriteLock(&tvc->lock);
1866 afs_PutVolume(tvolp, WRITE_LOCK);
1872 afs_PutVolume(tvolp, WRITE_LOCK);
1877 if (tvc && !VREFCOUNT_GT(tvc, 0)) {
1882 /* if we get here, we found something in a directory that couldn't
1883 * be located (a Multics "connection failure"). If the volume is
1884 * read-only, we try flushing this entry from the cache and trying
1886 if (!AFS_IS_DISCONNECTED) {
1889 tv = afs_GetVolume(&adp->f.fid, &treq, READ_LOCK);
1891 if (tv->states & VRO) {
1892 pass = 1; /* try this *once* */
1893 ObtainWriteLock(&afs_xcbhash, 495);
1894 afs_DequeueCallback(adp);
1895 /* re-stat to get later version */
1896 adp->f.states &= ~CStatd;
1897 ReleaseWriteLock(&afs_xcbhash);
1898 osi_dnlc_purgedp(adp);
1899 afs_PutVolume(tv, READ_LOCK);
1902 afs_PutVolume(tv, READ_LOCK);
1912 /* put the network buffer back, if need be */
1913 if (tname != aname && tname)
1914 osi_FreeLargeSpace(tname);
1918 afs_AddMarinerName(aname, tvc);
1920 #if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS)
1921 if (!(flags & AFS_LOOKUP_NOEVAL)) {
1922 /* Here we don't enter the name into the DNLC because we want the
1923 * evaluated mount dir to be there (the vcache for the mounted
1924 * volume) rather than the vc of the mount point itself. We can
1925 * still find the mount point's vc in the vcache by its fid. */
1926 #endif /* UKERNEL && AFS_WEB_ENHANCEMENTS */
1927 if (!hit && force_eval) {
1928 osi_dnlc_enter(adp, aname, tvc, &versionNo);
1930 #ifdef AFS_LINUX20_ENV
1931 /* So Linux inode cache is up to date. */
1932 code = afs_VerifyVCache(tvc, &treq);
1934 afs_PutFakeStat(&fakestate);
1935 AFS_DISCON_UNLOCK();
1936 return 0; /* can't have been any errors if hit and !code */
1939 #if defined(UKERNEL) && defined(AFS_WEB_ENHANCEMENTS)
1946 code = afs_CheckCode(code, &treq, 19);
1948 /* If there is an error, make sure *avcp is null.
1949 * Alphas panic otherwise - defect 10719.
1954 afs_PutFakeStat(&fakestate);
1955 AFS_DISCON_UNLOCK();