From nobody Fri Jan 05 05:00:47 2024 X-Original-To: dev-commits-src-main@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 4T5rrH5NQ5z56HZd; Fri, 5 Jan 2024 05:00:47 +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 4T5rrH4dQYz4Wmj; Fri, 5 Jan 2024 05:00:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704430847; 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=gz23VTFBRtYPzEvHl8+2LvE7alCT0idNOWNdSFOpc4I=; b=A0CzK4MrzYeoql/M2IoT65Jo1sc42LEJyTJxONE8zSZYefr8MXX4S+JFf+yS9LHxMw6Urn zFAV/uIhCZ0P5u/bYlDMROqgi42x5PY09FPp6IIqGs4I9QiGpPNLeboPTqGetnSe0WUDN3 1g1xB2URlyi5INr4GRyKLTsEnPYhYiUvFo/wL5ukKMfaClaIK4ID2aW6PJA2ItdnTFniSS t2VxZ3DLEoGv6FhoJszduqafRa3qJ1gbSAGP5vid0rn/m6uBhuCHGrEtLgHnxw2/sP/Gy3 zUiDgkn7gSMoqwuvy8IA4uOQhPz+dXtSrfxcvzxNdLl6d0qQuXsNhyuVWEybCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704430847; 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=gz23VTFBRtYPzEvHl8+2LvE7alCT0idNOWNdSFOpc4I=; b=P2FVpxN74s64KkCgJSiVY1KC4ZjSUtAZ7TBwvIskKTShn6z2IjaHLhdVIPMt4o0MdK1LvT JxRjTMA2dp0RJuP8zYO7pd8gWqxtuhwsWUf6EocMVHMkumN0yccxERKOneNn832Ne/m62n hfOeBydEZGp0rnKnyLHIq2gMFLEF/h0QegfiJ7VGAoNVWSAVFqTFx1GH80lRz4bSnya//L DYyhMr/sdxWhgJix0jpAR/oIeP7Wi1EQjHqf3daLCJKW7Cb1Ay9UI1ec1Rt6dpRxlJ/LMs TvFqYTpPKoJf9qL6FQ/QTeyUcyh+F6GBFdiwwnN5r3CIzgEmOXdQUA2TwrGnjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704430847; a=rsa-sha256; cv=none; b=h6UFFoJiCgx3vTbzEV9HQeA/luuzdM/826SaLyelPBU28x3wYYbEZq8HCnS+fqCEiuoxXt V4fWjvBSNnDM7uGgi7BItNJSCaDjctmIKNeaSM+JkbV8frcvybgzDlnproX9VjF+VuS4od 1QwkyQ7MVJvJlI1SnQvX7U8+3Sx/5SqSFJZlZBjvzs8knAfmW6y2W04TqGe7MUZGFdjf/C WwYEq/D1HvWE8VRwATB6wmQQWQQooWABvZQPk3r7cNuoX2XkIe1id3d6H2eXkLtn5rK1Yz got2LtU4q/IlKHQNSfHmXw2PRc0M7cZRrYBfRFtxrOhisSorCRcK6S9uqg7rWw== 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 4T5rrH3l9czkRY; Fri, 5 Jan 2024 05:00: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 40550lrX090193; Fri, 5 Jan 2024 05:00:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40550lTc090190; Fri, 5 Jan 2024 05:00:47 GMT (envelope-from git) Date: Fri, 5 Jan 2024 05:00:47 GMT Message-Id: <202401050500.40550lTc090190@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: 47ec00d9d607 - main - nfsclient: flush dirty pages of the vnode List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org 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: 47ec00d9d6071bbb0ee5ed0bdca3c4a468334d9d Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=47ec00d9d6071bbb0ee5ed0bdca3c4a468334d9d commit 47ec00d9d6071bbb0ee5ed0bdca3c4a468334d9d Author: Konstantin Belousov AuthorDate: 2023-12-30 00:15:50 +0000 Commit: Konstantin Belousov CommitDate: 2024-01-05 04:56:30 +0000 nfsclient: flush dirty pages of the vnode before ncl_flush() when done to ensure that the server sees our cached data, because it potentially changes the server response. This is relevant for copy_file_range(), seek(), and allocate(). Convert LK_SHARED invp lock into LK_EXCLUSIVE if needed to properly call vm_object_page_clean(). Reported by: asomers PR: 276002 Noted and reviewed by: rmacklem Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D43250 --- sys/fs/nfsclient/nfs_clvnops.c | 45 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c index f86ecd53ad4e..36ab5485d807 100644 --- a/sys/fs/nfsclient/nfs_clvnops.c +++ b/sys/fs/nfsclient/nfs_clvnops.c @@ -3705,6 +3705,7 @@ nfs_allocate(struct vop_allocate_args *ap) { struct vnode *vp = ap->a_vp; struct thread *td = curthread; + vm_object_t obj; struct nfsvattr nfsva; struct nfsmount *nmp; struct nfsnode *np; @@ -3733,8 +3734,15 @@ nfs_allocate(struct vop_allocate_args *ap) * Flush first to ensure that the allocate adds to the * file's allocation on the server. */ - if (error == 0) + if (error == 0) { + obj = vp->v_object; + if (obj != NULL) { + VM_OBJECT_WLOCK(obj); + vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); + VM_OBJECT_WUNLOCK(obj); + } error = ncl_flush(vp, MNT_WAIT, td, 1, 0); + } if (error == 0) error = nfsrpc_allocate(vp, *ap->a_offset, alen, &nfsva, &attrflag, ap->a_cred, td); @@ -3872,13 +3880,14 @@ nfs_copy_file_range(struct vop_copy_file_range_args *ap) struct vnode *invp = ap->a_invp; struct vnode *outvp = ap->a_outvp; struct mount *mp; + vm_object_t invp_obj; struct nfsvattr innfsva, outnfsva; struct vattr va, *vap; struct uio io; struct nfsmount *nmp; size_t len, len2; ssize_t r; - int error, inattrflag, outattrflag, ret, ret2; + int error, inattrflag, outattrflag, ret, ret2, invp_lock; off_t inoff, outoff; bool consecutive, must_commit, tryoutcred; @@ -3891,6 +3900,9 @@ generic_copy: return (ENOSYS); } + invp_lock = LK_SHARED; +relock: + /* Lock both vnodes, avoiding risk of deadlock. */ do { mp = NULL; @@ -3898,14 +3910,14 @@ generic_copy: if (error == 0) { error = vn_lock(outvp, LK_EXCLUSIVE); if (error == 0) { - error = vn_lock(invp, LK_SHARED | LK_NOWAIT); + error = vn_lock(invp, invp_lock | LK_NOWAIT); if (error == 0) break; VOP_UNLOCK(outvp); if (mp != NULL) vn_finished_write(mp); mp = NULL; - error = vn_lock(invp, LK_SHARED); + error = vn_lock(invp, invp_lock); if (error == 0) VOP_UNLOCK(invp); } @@ -3953,8 +3965,23 @@ generic_copy: * stable storage before the Copy RPC. This is done in case the * server reboots during the Copy and needs to be redone. */ - if (error == 0) + if (error == 0) { + invp_obj = invp->v_object; + if (invp_obj != NULL && vm_object_mightbedirty(invp_obj)) { + if (invp_lock != LK_EXCLUSIVE) { + invp_lock = LK_EXCLUSIVE; + VOP_UNLOCK(invp); + VOP_UNLOCK(outvp); + if (mp != NULL) + vn_finished_write(mp); + goto relock; + } + VM_OBJECT_WLOCK(invp_obj); + vm_object_page_clean(invp_obj, 0, 0, OBJPC_SYNC); + VM_OBJECT_WUNLOCK(invp_obj); + } error = ncl_flush(invp, MNT_WAIT, curthread, 1, 0); + } if (error == 0) error = ncl_vinvalbuf(outvp, V_SAVE, curthread, 0); @@ -4110,6 +4137,7 @@ static int nfs_ioctl(struct vop_ioctl_args *ap) { struct vnode *vp = ap->a_vp; + vm_object_t obj; struct nfsvattr nfsva; struct nfsmount *nmp; int attrflag, content, error, ret; @@ -4127,7 +4155,7 @@ nfs_ioctl(struct vop_ioctl_args *ap) return (ENOTTY); } - error = vn_lock(vp, LK_SHARED); + error = vn_lock(vp, LK_EXCLUSIVE); if (error != 0) return (EBADF); @@ -4153,6 +4181,11 @@ nfs_ioctl(struct vop_ioctl_args *ap) * server, the LayoutCommit will be done to ensure the file * size is up to date on the Metadata Server. */ + + obj = vp->v_object; + VM_OBJECT_WLOCK(obj); + vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); + VM_OBJECT_WUNLOCK(obj); error = ncl_flush(vp, MNT_WAIT, ap->a_td, 1, 0); if (error == 0) error = nfsrpc_seek(vp, (off_t *)ap->a_data, &eof,