diff --git a/sys/fs/msdosfs/denode.h b/sys/fs/msdosfs/denode.h index f57e014ef1df..f7ba83bc1b17 100644 --- a/sys/fs/msdosfs/denode.h +++ b/sys/fs/msdosfs/denode.h @@ -135,7 +135,6 @@ struct fatcache { * contained within a vnode. */ struct denode { - struct lock de_lock; /* denode lock >Keep this first< */ struct denode *de_next; /* Hash chain forward */ struct denode **de_prev; /* Hash chain back */ struct vnode *de_vnode; /* addr of vnode we are part of */ diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c index 0122f6bd8e14..37fe66789d56 100644 --- a/sys/fs/msdosfs/msdosfs_denode.c +++ b/sys/fs/msdosfs/msdosfs_denode.c @@ -264,7 +264,8 @@ deget(pmp, dirclust, diroffset, depp) return error; } bzero((caddr_t)ldep, sizeof *ldep); - lockinit(&ldep->de_lock, PINOD, "denode", 0, 0); + lockinit(&nvp->v_lock, PINOD, "denode", 0, 0); + nvp->v_vnlock = &nvp->v_lock; nvp->v_data = ldep; ldep->de_vnode = nvp; ldep->de_flag = 0; @@ -280,7 +281,7 @@ deget(pmp, dirclust, diroffset, depp) * of at the start of msdosfs_hashins() so that reinsert() can * call msdosfs_hashins() with a locked denode. */ - if (lockmgr(&ldep->de_lock, LK_EXCLUSIVE, (struct mtx *)0, p)) + if (VOP_LOCK(nvp, LK_EXCLUSIVE, p) != 0) panic("deget: unexpected lock failure"); /* @@ -662,7 +663,7 @@ msdosfs_reclaim(ap) #if 0 /* XXX */ dep->de_flag = 0; #endif - lockdestroy(&dep->de_lock); + lockdestroy(&vp->v_lock); FREE(dep, M_MSDOSFSNODE); vp->v_data = NULL; diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c index edb71a69a0fe..776559d8b05e 100644 --- a/sys/fs/msdosfs/msdosfs_lookup.c +++ b/sys/fs/msdosfs/msdosfs_lookup.c @@ -116,6 +116,7 @@ msdosfs_lookup(ap) int wincnt = 1; int chksum = -1; int olddos = 1; + cnp->cn_flags &= ~PDIRUNLOCK; #ifdef MSDOSFS_DEBUG printf("msdosfs_lookup(): looking for %s\n", cnp->cn_nameptr); @@ -363,8 +364,10 @@ notfound: * information cannot be used. */ cnp->cn_flags |= SAVENAME; - if (!lockparent) + if (!lockparent) { VOP_UNLOCK(vdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } return (EJUSTRETURN); } /* @@ -452,8 +455,10 @@ foundroot: if (error) return (error); *vpp = DETOV(tdp); - if (!lockparent) + if (!lockparent) { VOP_UNLOCK(vdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } return (0); } @@ -483,8 +488,10 @@ foundroot: return (error); *vpp = DETOV(tdp); cnp->cn_flags |= SAVENAME; - if (!lockparent) + if (!lockparent) { VOP_UNLOCK(vdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } return (0); } @@ -510,15 +517,20 @@ foundroot: pdp = vdp; if (flags & ISDOTDOT) { VOP_UNLOCK(pdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; error = deget(pmp, cluster, blkoff, &tdp); if (error) { vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, p); + cnp->cn_flags &= ~PDIRUNLOCK; return (error); } - if (lockparent && (flags & ISLASTCN) && - (error = vn_lock(pdp, LK_EXCLUSIVE, p))) { - vput(DETOV(tdp)); - return (error); + if (lockparent && (flags & ISLASTCN)) { + error = vn_lock(pdp, LK_EXCLUSIVE, p); + if (error) { + vput(DETOV(tdp)); + return (error); + } + cnp->cn_flags &= ~PDIRUNLOCK; } *vpp = DETOV(tdp); } else if (dp->de_StartCluster == scn && isadir) { @@ -527,8 +539,10 @@ foundroot: } else { if ((error = deget(pmp, cluster, blkoff, &tdp)) != 0) return (error); - if (!lockparent || !(flags & ISLASTCN)) + if (!lockparent || !(flags & ISLASTCN)) { VOP_UNLOCK(pdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } *vpp = DETOV(tdp); } diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index 37a57ea0327a..48824af97024 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -1830,7 +1830,7 @@ msdosfs_print(ap) "tag VT_MSDOSFS, startcluster %lu, dircluster %lu, diroffset %lu ", dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset); printf(" dev %d, %d", major(dep->de_dev), minor(dep->de_dev)); - lockmgr_printinfo(&dep->de_lock); + lockmgr_printinfo(&ap->a_vp->v_lock); printf("\n"); return (0); } diff --git a/sys/msdosfs/denode.h b/sys/msdosfs/denode.h index f57e014ef1df..f7ba83bc1b17 100644 --- a/sys/msdosfs/denode.h +++ b/sys/msdosfs/denode.h @@ -135,7 +135,6 @@ struct fatcache { * contained within a vnode. */ struct denode { - struct lock de_lock; /* denode lock >Keep this first< */ struct denode *de_next; /* Hash chain forward */ struct denode **de_prev; /* Hash chain back */ struct vnode *de_vnode; /* addr of vnode we are part of */ diff --git a/sys/msdosfs/msdosfs_denode.c b/sys/msdosfs/msdosfs_denode.c index 0122f6bd8e14..37fe66789d56 100644 --- a/sys/msdosfs/msdosfs_denode.c +++ b/sys/msdosfs/msdosfs_denode.c @@ -264,7 +264,8 @@ deget(pmp, dirclust, diroffset, depp) return error; } bzero((caddr_t)ldep, sizeof *ldep); - lockinit(&ldep->de_lock, PINOD, "denode", 0, 0); + lockinit(&nvp->v_lock, PINOD, "denode", 0, 0); + nvp->v_vnlock = &nvp->v_lock; nvp->v_data = ldep; ldep->de_vnode = nvp; ldep->de_flag = 0; @@ -280,7 +281,7 @@ deget(pmp, dirclust, diroffset, depp) * of at the start of msdosfs_hashins() so that reinsert() can * call msdosfs_hashins() with a locked denode. */ - if (lockmgr(&ldep->de_lock, LK_EXCLUSIVE, (struct mtx *)0, p)) + if (VOP_LOCK(nvp, LK_EXCLUSIVE, p) != 0) panic("deget: unexpected lock failure"); /* @@ -662,7 +663,7 @@ msdosfs_reclaim(ap) #if 0 /* XXX */ dep->de_flag = 0; #endif - lockdestroy(&dep->de_lock); + lockdestroy(&vp->v_lock); FREE(dep, M_MSDOSFSNODE); vp->v_data = NULL; diff --git a/sys/msdosfs/msdosfs_lookup.c b/sys/msdosfs/msdosfs_lookup.c index edb71a69a0fe..776559d8b05e 100644 --- a/sys/msdosfs/msdosfs_lookup.c +++ b/sys/msdosfs/msdosfs_lookup.c @@ -116,6 +116,7 @@ msdosfs_lookup(ap) int wincnt = 1; int chksum = -1; int olddos = 1; + cnp->cn_flags &= ~PDIRUNLOCK; #ifdef MSDOSFS_DEBUG printf("msdosfs_lookup(): looking for %s\n", cnp->cn_nameptr); @@ -363,8 +364,10 @@ notfound: * information cannot be used. */ cnp->cn_flags |= SAVENAME; - if (!lockparent) + if (!lockparent) { VOP_UNLOCK(vdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } return (EJUSTRETURN); } /* @@ -452,8 +455,10 @@ foundroot: if (error) return (error); *vpp = DETOV(tdp); - if (!lockparent) + if (!lockparent) { VOP_UNLOCK(vdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } return (0); } @@ -483,8 +488,10 @@ foundroot: return (error); *vpp = DETOV(tdp); cnp->cn_flags |= SAVENAME; - if (!lockparent) + if (!lockparent) { VOP_UNLOCK(vdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } return (0); } @@ -510,15 +517,20 @@ foundroot: pdp = vdp; if (flags & ISDOTDOT) { VOP_UNLOCK(pdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; error = deget(pmp, cluster, blkoff, &tdp); if (error) { vn_lock(pdp, LK_EXCLUSIVE | LK_RETRY, p); + cnp->cn_flags &= ~PDIRUNLOCK; return (error); } - if (lockparent && (flags & ISLASTCN) && - (error = vn_lock(pdp, LK_EXCLUSIVE, p))) { - vput(DETOV(tdp)); - return (error); + if (lockparent && (flags & ISLASTCN)) { + error = vn_lock(pdp, LK_EXCLUSIVE, p); + if (error) { + vput(DETOV(tdp)); + return (error); + } + cnp->cn_flags &= ~PDIRUNLOCK; } *vpp = DETOV(tdp); } else if (dp->de_StartCluster == scn && isadir) { @@ -527,8 +539,10 @@ foundroot: } else { if ((error = deget(pmp, cluster, blkoff, &tdp)) != 0) return (error); - if (!lockparent || !(flags & ISLASTCN)) + if (!lockparent || !(flags & ISLASTCN)) { VOP_UNLOCK(pdp, 0, p); + cnp->cn_flags |= PDIRUNLOCK; + } *vpp = DETOV(tdp); } diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c index 37a57ea0327a..48824af97024 100644 --- a/sys/msdosfs/msdosfs_vnops.c +++ b/sys/msdosfs/msdosfs_vnops.c @@ -1830,7 +1830,7 @@ msdosfs_print(ap) "tag VT_MSDOSFS, startcluster %lu, dircluster %lu, diroffset %lu ", dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset); printf(" dev %d, %d", major(dep->de_dev), minor(dep->de_dev)); - lockmgr_printinfo(&dep->de_lock); + lockmgr_printinfo(&ap->a_vp->v_lock); printf("\n"); return (0); }