Index: sys/fs/autofs/autofs_vnops.c =================================================================== --- sys/fs/autofs/autofs_vnops.c +++ sys/fs/autofs/autofs_vnops.c @@ -214,7 +214,7 @@ struct autofs_mount *amp; struct autofs_node *anp, *child; struct componentname *cnp; - int error, lock_flags; + int error; dvp = ap->a_dvp; vpp = ap->a_vpp; @@ -257,23 +257,16 @@ return (error); if (newvp != NULL) { - error = VOP_LOOKUP(newvp, ap->a_vpp, ap->a_cnp); - /* - * Instead of figuring out whether our vnode should - * be locked or not given the error and cnp flags, - * just "copy" the lock status from vnode returned - * by mounted filesystem's VOP_LOOKUP(). Get rid - * of that new vnode afterwards. + * The target filesystem got automounted. Make + * the lookup(9) go around with a new parent vnode + * and the same path component. */ - lock_flags = VOP_ISLOCKED(newvp); - if (lock_flags == 0) { - VOP_UNLOCK(dvp, 0); - vrele(newvp); - } else { - vput(newvp); - } - return (error); + vput(newvp); + vref(dvp); + *vpp = dvp; + + return (EDOOFUS); } } Index: sys/kern/vfs_lookup.c =================================================================== --- sys/kern/vfs_lookup.c +++ sys/kern/vfs_lookup.c @@ -495,6 +495,7 @@ int rdonly; /* lookup read-only flag bit */ int error = 0; int dpunlocked = 0; /* dp has already been unlocked */ + int relookup = 0; /* do not consume the path component */ struct componentname *cnp = &ndp->ni_cnd; int lkflags_save; int ni_dvp_unlocked; @@ -728,6 +729,14 @@ cnp->cn_flags); if ((error = VOP_LOOKUP(dp, &ndp->ni_vp, cnp)) != 0) { cnp->cn_lkflags = lkflags_save; + + if (error == EDOOFUS && + strcmp(dp->v_mount->mnt_vfc->vfc_name, "autofs") == 0) { + error = 0; + relookup = 1; + goto good; + } + KASSERT(ndp->ni_vp == NULL, ("leaf should be empty")); #ifdef NAMEI_DIAGNOSTIC printf("not found\n"); @@ -775,8 +784,10 @@ VREF(ndp->ni_startdir); } goto success; - } else - cnp->cn_lkflags = lkflags_save; + } + +good: + cnp->cn_lkflags = lkflags_save; #ifdef NAMEI_DIAGNOSTIC printf("found\n"); #endif @@ -856,6 +867,14 @@ */ KASSERT((cnp->cn_flags & ISLASTCN) || *ndp->ni_next == '/', ("lookup: invalid path state.")); + if (relookup) { + relookup = 0; + if (ndp->ni_dvp != dp) + vput(ndp->ni_dvp); + else + vrele(ndp->ni_dvp); + goto dirloop; + } if (*ndp->ni_next == '/') { cnp->cn_nameptr = ndp->ni_next; while (*cnp->cn_nameptr == '/') {