The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=6ae13c0feb96a1ea97e814213271b41b3d090d2d

commit 6ae13c0feb96a1ea97e814213271b41b3d090d2d
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2021-08-07 20:18:26 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2021-08-27 15:39:45 +0000

    msdosfs: add doscheckpath lock
    
    Similar to the UFS revision 8df4bc48c89a130207
    
    Reviewed by:    mckusick
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D31464
---
 sys/fs/msdosfs/msdosfs_lookup.c |  1 +
 sys/fs/msdosfs/msdosfs_vfsops.c |  3 +++
 sys/fs/msdosfs/msdosfs_vnops.c  | 11 ++++++++++-
 sys/fs/msdosfs/msdosfsmount.h   |  1 +
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c
index 2c3d02db37a0..9940800a72c2 100644
--- a/sys/fs/msdosfs/msdosfs_lookup.c
+++ b/sys/fs/msdosfs/msdosfs_lookup.c
@@ -813,6 +813,7 @@ doscheckpath(struct denode *source, struct denode *target, 
daddr_t *wait_scn)
        *wait_scn = 0;
 
        pmp = target->de_pmp;
+       lockmgr_assert(&pmp->pm_checkpath_lock, KA_XLOCKED);
        KASSERT(pmp == source->de_pmp,
            ("doscheckpath: source and target on different filesystems"));
 
diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c
index 68c8a93a18af..0f6d41b3c77c 100644
--- a/sys/fs/msdosfs/msdosfs_vfsops.c
+++ b/sys/fs/msdosfs/msdosfs_vfsops.c
@@ -469,6 +469,7 @@ mountmsdosfs(struct vnode *devvp, struct mount *mp)
        pmp->pm_bo = bo;
 
        lockinit(&pmp->pm_fatlock, 0, msdosfs_lock_msg, 0, 0);
+       lockinit(&pmp->pm_checkpath_lock, 0, "msdoscp", 0, 0);
 
        /*
         * Initialize ownerships and permissions, since nothing else will
@@ -740,6 +741,7 @@ error_exit:
        }
        if (pmp) {
                lockdestroy(&pmp->pm_fatlock);
+               lockdestroy(&pmp->pm_checkpath_lock);
                free(pmp->pm_inusemap, M_MSDOSFSFAT);
                free(pmp, M_MSDOSFSMNT);
                mp->mnt_data = NULL;
@@ -829,6 +831,7 @@ msdosfs_unmount(struct mount *mp, int mntflags)
        dev_rel(pmp->pm_dev);
        free(pmp->pm_inusemap, M_MSDOSFSFAT);
        lockdestroy(&pmp->pm_fatlock);
+       lockdestroy(&pmp->pm_checkpath_lock);
        free(pmp, M_MSDOSFSMNT);
        mp->mnt_data = NULL;
        MNT_ILOCK(mp);
diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c
index c81e192a6158..6197340e8943 100644
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -942,7 +942,7 @@ msdosfs_rename(struct vop_rename_args *ap)
        struct denode *fdip, *fip, *tdip, *tip, *nip;
        u_char toname[12], oldname[11];
        u_long from_diroffset, to_diroffset;
-       bool doingdirectory, newparent;
+       bool checkpath_locked, doingdirectory, newparent;
        u_char to_count;
        int error;
        u_long cn, pcl, blkoff;
@@ -991,6 +991,8 @@ msdosfs_rename(struct vop_rename_args *ap)
        if (tvp != NULL && tvp != tdvp)
                VOP_UNLOCK(tvp);
 
+       checkpath_locked = false;
+
 relock:
        doingdirectory = newparent = false;
 
@@ -1113,8 +1115,12 @@ relock:
        if (doingdirectory && newparent) {
                if (error != 0) /* write access check above */
                        goto unlock;
+               lockmgr(&pmp->pm_checkpath_lock, LK_EXCLUSIVE, NULL);
+               checkpath_locked = true;
                error = doscheckpath(fip, tdip, &wait_scn);
                if (wait_scn != 0) {
+                       lockmgr(&pmp->pm_checkpath_lock, LK_RELEASE, NULL);
+                       checkpath_locked = false;
                        VOP_UNLOCK(fdvp);
                        VOP_UNLOCK(tdvp);
                        VOP_UNLOCK(fvp);
@@ -1268,6 +1274,8 @@ relock:
        cache_purge(fvp);
 
 unlock:
+       if (checkpath_locked)
+               lockmgr(&pmp->pm_checkpath_lock, LK_RELEASE, NULL);
        vput(fdvp);
        vput(fvp);
        if (tvp != NULL) {
@@ -1279,6 +1287,7 @@ unlock:
        vput(tdvp);
        return (error);
 releout:
+       MPASS(!checkpath_locked);
        vrele(tdvp);
        if (tvp != NULL)
                vrele(tvp);
diff --git a/sys/fs/msdosfs/msdosfsmount.h b/sys/fs/msdosfs/msdosfsmount.h
index 75b187860270..46a02e611cf5 100644
--- a/sys/fs/msdosfs/msdosfsmount.h
+++ b/sys/fs/msdosfs/msdosfsmount.h
@@ -114,6 +114,7 @@ struct msdosfsmount {
        void *pm_d2u;   /* DOS->Local iconv handle */
 #ifndef MAKEFS
        struct lock pm_fatlock; /* lockmgr protecting allocations */
+       struct lock pm_checkpath_lock; /* protects doscheckpath result */
 #endif
 };
 
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to