From owner-dev-commits-src-main@freebsd.org Tue Jul 27 16:59:02 2021 Return-Path: Delivered-To: dev-commits-src-main@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 DA3DD663B69; Tue, 27 Jul 2021 16:59:02 +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 4GZ30k546Yz4nDB; Tue, 27 Jul 2021 16:59:02 +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 64D096709; Tue, 27 Jul 2021 16:59:02 +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 16RGx2Xo083594; Tue, 27 Jul 2021 16:59:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16RGx2Tq083592; Tue, 27 Jul 2021 16:59:02 GMT (envelope-from git) Date: Tue, 27 Jul 2021 16:59:02 GMT Message-Id: <202107271659.16RGx2Tq083592@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4eaf9609fe42 - main - nullfs: provide custom null_rename bypass 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/main X-Git-Reftype: branch X-Git-Commit: 4eaf9609fe42878eccaaf5fe1873f792074a62e4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Jul 2021 16:59:03 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4eaf9609fe42878eccaaf5fe1873f792074a62e4 commit 4eaf9609fe42878eccaaf5fe1873f792074a62e4 Author: Konstantin Belousov AuthorDate: 2021-07-24 15:05:58 +0000 Commit: Konstantin Belousov CommitDate: 2021-07-27 16:58:48 +0000 nullfs: provide custom null_rename bypass fdvp and fvp vnodes are not locked, and race with reclaim cannot be handled by the generic bypass routine. Reported and tested by: pho Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31310 --- sys/fs/nullfs/null_vnops.c | 68 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/sys/fs/nullfs/null_vnops.c b/sys/fs/nullfs/null_vnops.c index ce67d2760418..e3a320a22bfa 100644 --- a/sys/fs/nullfs/null_vnops.c +++ b/sys/fs/nullfs/null_vnops.c @@ -656,32 +656,78 @@ static int null_rename(struct vop_rename_args *ap) { struct vnode *fdvp, *fvp, *tdvp, *tvp; - struct null_node *tnn; + struct vnode *lfdvp, *lfvp, *ltdvp, *ltvp; + struct null_node *fdnn, *fnn, *tdnn, *tnn; + int error; tdvp = ap->a_tdvp; fvp = ap->a_fvp; fdvp = ap->a_fdvp; tvp = ap->a_tvp; + lfdvp = NULL; /* Check for cross-device rename. */ if ((fvp->v_mount != tdvp->v_mount) || (tvp != NULL && fvp->v_mount != tvp->v_mount)) { - if (tdvp == tvp) - vrele(tdvp); - else - vput(tdvp); - if (tvp) - vput(tvp); - vrele(fdvp); - vrele(fvp); - return (EXDEV); + error = EXDEV; + goto upper_err; + } + + VI_LOCK(fdvp); + fdnn = VTONULL(fdvp); + if (fdnn == NULL) { /* fdvp is not locked, can be doomed */ + VI_UNLOCK(fdvp); + error = ENOENT; + goto upper_err; } + lfdvp = fdnn->null_lowervp; + vref(lfdvp); + VI_UNLOCK(fdvp); + + VI_LOCK(fvp); + fnn = VTONULL(fvp); + if (fnn == NULL) { + VI_UNLOCK(fvp); + error = ENOENT; + goto upper_err; + } + lfvp = fnn->null_lowervp; + vref(lfvp); + VI_UNLOCK(fvp); + + tdnn = VTONULL(tdvp); + ltdvp = tdnn->null_lowervp; + vref(ltdvp); if (tvp != NULL) { tnn = VTONULL(tvp); + ltvp = tnn->null_lowervp; + vref(ltvp); tnn->null_flags |= NULLV_DROP; + } else { + ltvp = NULL; } - return (null_bypass((struct vop_generic_args *)ap)); + + error = VOP_RENAME(lfdvp, lfvp, ap->a_fcnp, ltdvp, ltvp, ap->a_tcnp); + vrele(fdvp); + vrele(fvp); + vrele(tdvp); + if (tvp != NULL) + vrele(tvp); + return (error); + +upper_err: + if (tdvp == tvp) + vrele(tdvp); + else + vput(tdvp); + if (tvp) + vput(tvp); + if (lfdvp != NULL) + vrele(lfdvp); + vrele(fdvp); + vrele(fvp); + return (error); } static int