From owner-dev-commits-src-branches@freebsd.org Fri Sep 3 01:09:03 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 585A366C28A; Fri, 3 Sep 2021 01:09:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H10731GwBz4Z7Z; Fri, 3 Sep 2021 01:09:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0C2E8233AA; Fri, 3 Sep 2021 01:09:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 183192T1004803; Fri, 3 Sep 2021 01:09:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 183192MO004802; Fri, 3 Sep 2021 01:09:02 GMT (envelope-from git) Date: Fri, 3 Sep 2021 01:09:02 GMT Message-Id: <202109030109.183192MO004802@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: af096248c94d - stable/13 - msdosfs: add doscheckpath lock MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: af096248c94d48f895dc549006045312c13a4209 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Sep 2021 01:09:03 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=af096248c94d48f895dc549006045312c13a4209 commit af096248c94d48f895dc549006045312c13a4209 Author: Konstantin Belousov AuthorDate: 2021-08-07 20:18:26 +0000 Commit: Konstantin Belousov CommitDate: 2021-09-03 01:08:36 +0000 msdosfs: add doscheckpath lock (cherry picked from commit 6ae13c0feb96a1ea97e814213271b41b3d090d2d) --- 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 0ef8e187545d..421afc3ec290 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 };