From nobody Mon Mar 04 18:51:47 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TpSTw0ldQz5D6CR; Mon, 4 Mar 2024 18:51:48 +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 4TpSTv6VSHz4bxn; Mon, 4 Mar 2024 18:51:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709578307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bEk9AZZ9CBjWByyAsU1mEt1h3cKjGZbLgr4dycRnWNI=; b=x2AHRyfeJw8sHupYHRnqQIjhMkz+nHTS2PwtLw4U+pnuKwdWht1oU16Ry3UUcq0BbsgymC Zduu7LGF45GHxHSmdATGEkVqxg99v06/BdKcy/IU9lGTZHA2g/C4Ds99QG6UfRaxULyROF 6OBg7mZRNbILOyPQXWz8mNpDkf6be8Spa5D1egHmsdIqcE9T+eQe0dS+P7VVfiF3fuYHgR 3SO6zmL0hVq8Y49J3XamuAp3ifrofo6QHBktHLRmkmtM07Udh7oUuBp6VYF+BkNx+mvYcE ZexaQUMgnCvs2yDWDkiwMnW/eMFCfqxRt4w3FWrWJbi6t59ZS/uKYjOFeSTifw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709578307; a=rsa-sha256; cv=none; b=myOlPLOONkRC5K47eTPPnuE+l+Pf2nuvXlIaCclCSmBUvdZj+QXgRrESRtxGkjG5YAfb4T a3hc6a9wGuDBuD/l3xsyyBhLP0pRiHQxvOET7yLAdJWuf4eQIIzMdq/WrK145olzl0Xziv GmWkNCE91PmVcYM25fI/ITwx2F5d+cR53oaCkybN7nqwAaZc280kCV6fWpdPJec6yKt0Z6 5pBPcQ70cfKiPBSL4zkbJhh7AoBJWH+Jg8Z96EWUL6UMGngiCTnMlFVR54g8a7SIpsuqHr GQ+Qk4UR3bB9LjTyHoRNbrpZUbW7iRPIHkt9BSH8hBJQlOgFmQpaoqYYvudgKA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709578307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bEk9AZZ9CBjWByyAsU1mEt1h3cKjGZbLgr4dycRnWNI=; b=o0mCAhXiX2lUdVzUGMjz5Rk2kCc1HCxbjQeNIfvIVFOEVuES5go/6q0sRAEgNfp8zko4Ml y5FDmhRIMh3/1YNFqEv1HrJRZkF8mtpZivf7PCDxRu74ULFEW3HUf3BadWTxT8ww5leXsR 58PuDNZkSAK0VrfcrGIO8u8Pf8lybryqfs3d7DRb75AoZOD2J6WiRhvPv3YykNXmdop+EH cmlo+GIry6TUxoy5cxZiiZUUSOjJrX2h1TKPGALO/TGT05oHNLLmjFIW9uBgVaOCoc0D3z CdzcwV8JHC91oDiK3tlZNdeCUKinY2tBgKfheD0m80InpSEvfS9hGyR7RPkj/A== 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 4TpSTv66jRzYvv; Mon, 4 Mar 2024 18:51:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 424IplUb009691; Mon, 4 Mar 2024 18:51:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 424IplFj009688; Mon, 4 Mar 2024 18:51:47 GMT (envelope-from git) Date: Mon, 4 Mar 2024 18:51:47 GMT Message-Id: <202403041851.424IplFj009688@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Jason A. Harmening" Subject: git: 9c530578757b - stable/14 - unionfs: upgrade the vnode lock during fsync() if necessary List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jah X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 9c530578757b9e39eeae8e1e03a14652faa7f458 Auto-Submitted: auto-generated The branch stable/14 has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=9c530578757b9e39eeae8e1e03a14652faa7f458 commit 9c530578757b9e39eeae8e1e03a14652faa7f458 Author: Jason A. Harmening AuthorDate: 2023-12-24 04:42:28 +0000 Commit: Jason A. Harmening CommitDate: 2024-03-04 18:31:44 +0000 unionfs: upgrade the vnode lock during fsync() if necessary If the underlying upper FS supports shared locking for write ops, as is the case with ZFS, VOP_FSYNC() may only be called with the vnode lock held shared. In this case, temporarily upgrade the lock for those unionfs maintenance operations which require exclusive locking. While here, make unionfs inherit the upper FS' support for shared write locking. Since the upper FS is the target of VOP_GETWRITEMOUNT() this is what will dictate the locking behavior of any unionfs caller that uses vn_start_write() + vn_lktype_write(), so unionfs must be prepared for the caller to only hold a shared vnode lock in these cases. Found in local testing of unionfs atop ZFS with DEBUG_VFS_LOCKS. Reviewed by: kib, olce Differential Revision: https://reviews.freebsd.org/D43817 (cherry picked from commit 2656fc29be8b0fc1cd9e64ed52aa0a61fe87744c) --- sys/fs/unionfs/union_vfsops.c | 3 ++- sys/fs/unionfs/union_vnops.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/fs/unionfs/union_vfsops.c b/sys/fs/unionfs/union_vfsops.c index c6d459622670..c717b048c6ab 100644 --- a/sys/fs/unionfs/union_vfsops.c +++ b/sys/fs/unionfs/union_vfsops.c @@ -351,7 +351,8 @@ unionfs_domount(struct mount *mp) if ((lowermp->mnt_flag & MNT_LOCAL) != 0 && (uppermp->mnt_flag & MNT_LOCAL) != 0) mp->mnt_flag |= MNT_LOCAL; - mp->mnt_kern_flag |= MNTK_NOMSYNC | MNTK_UNIONFS; + mp->mnt_kern_flag |= MNTK_NOMSYNC | MNTK_UNIONFS | + (ump->um_uppermp->mnt_kern_flag & MNTK_SHARED_WRITES); MNT_IUNLOCK(mp); /* diff --git a/sys/fs/unionfs/union_vnops.c b/sys/fs/unionfs/union_vnops.c index ab277c685e41..ba20bef199e6 100644 --- a/sys/fs/unionfs/union_vnops.c +++ b/sys/fs/unionfs/union_vnops.c @@ -1000,14 +1000,22 @@ unionfs_fsync(struct vop_fsync_args *ap) struct unionfs_node *unp; struct unionfs_node_status *unsp; struct vnode *ovp; + enum unionfs_lkupgrade lkstatus; KASSERT_UNIONFS_VNODE(ap->a_vp); unp = VTOUNIONFS(ap->a_vp); + lkstatus = unionfs_upgrade_lock(ap->a_vp); + if (lkstatus == UNIONFS_LKUPGRADE_DOOMED) { + unionfs_downgrade_lock(ap->a_vp, lkstatus); + return (ENOENT); + } unionfs_get_node_status(unp, ap->a_td, &unsp); ovp = (unsp->uns_upper_opencnt ? unp->un_uppervp : unp->un_lowervp); unionfs_tryrem_node_status(unp, unsp); + unionfs_downgrade_lock(ap->a_vp, lkstatus); + if (ovp == NULLVP) return (EBADF);