From nobody Fri Jan 12 12:02:48 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 4TBKt05m5Cz56gyb; Fri, 12 Jan 2024 12:02: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 4TBKt02vqwz4tKT; Fri, 12 Jan 2024 12:02:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705060968; 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=9+N8u0S9pNc0NHeAXQTBhZvP5ROMevOhF3GOCSR8W6g=; b=KP+DcQQFggHq0HOzylspfE8fzz9g4+OgzYRmnkoR8MSu4K+zyIux4VdgOY2PJbzNU1mt/6 Nyumi0hxR2UQK/Iqc8TwdgFa3EsLICy4zpmJtxo0SsAbF6eZ6vHR/uW8bDrM3zJyzlFmCV kxjpA2tYOwE5zPlwFCb2QWCni6MjN3p1VgrDQqAYBZXdGkagDOrfFTT8AXzvJLEMe4iVzD lTli2Xx/TGXN4Yf4rxPb22YW2t6vq/VhwDoTJpOgCiHoC/pskl/W0yWFLv9JHvsqiaQDZt njPziEE+wzSKH+M3I5+UAZMMHPpaczhx5TOUwRVVIlIwvLGFHTVOZMkA0Pchcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705060968; 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=9+N8u0S9pNc0NHeAXQTBhZvP5ROMevOhF3GOCSR8W6g=; b=lR/PLIHXSk56AIm9M20SmJRvZZip46HMKcnNpLqwVoarNQmIbFjSvmFg4HwYbesuH70TlX iONY9AHa6Ku1zrbDZ+0IQ67uNflRZ6R8OUhcIkflJkemmR3pvHiszqc5laByQf9QNVCDJ4 ixZfvaLCfFOFofhoMj40WnbMod0ByuQBlapKGiMgo6D1IAvRlxymu0xySm4+kRaNBwU3m6 OYfDlQ7geKfpaWtpNEsqrzhubDgtENsoBjso54yfDddKZdNG82zS3iyENCc4Z8xgMhClek A6+GPHBx2NNxHVUywLpcAcXQbiLLMwMgAJDUKhvxOoyXs0PKdyz5LXsfhZij+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705060968; a=rsa-sha256; cv=none; b=RBkQS7Xs2OoIi99/BK/1y915KWdZVJseNBjFf2MjDwJjuNu8MJn0pT7l61ANvo5UngCYH1 +iZGbNqfPSMLlI2z9JrRsMErRQnxw7CkTPRb1yTN9E6Dyb1k75c524Lv0Arq8jts8MGcNe nVqAW3qFFHbovOXtU+9q3QvYzAYfkx+MgyO1sxTgjKlB9fctAnRSwRPKn1V6P0QJiavs8B i+xvat1bporK7aYh5R90V/MSHIhe20O4jLeUhjKC3bDt1YJEzbm8OUhrUlznrfgAaml871 IMOtMWT5FupcAkFXUNe3t4IhAME9I1BzO7htYWT35b7Atr23HJYhEUuUM86oCw== 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 4TBKt01xVBz12Dc; Fri, 12 Jan 2024 12:02:48 +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 40CC2mmF005587; Fri, 12 Jan 2024 12:02:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40CC2mMR005584; Fri, 12 Jan 2024 12:02:48 GMT (envelope-from git) Date: Fri, 12 Jan 2024 12:02:48 GMT Message-Id: <202401121202.40CC2mMR005584@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: cee4d7c22585 - stable/13 - nfsclient: flush dirty pages of the vnode 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cee4d7c22585a736a5d231365ceb62e96d80488a Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=cee4d7c22585a736a5d231365ceb62e96d80488a commit cee4d7c22585a736a5d231365ceb62e96d80488a Author: Konstantin Belousov AuthorDate: 2023-12-30 00:15:50 +0000 Commit: Konstantin Belousov CommitDate: 2024-01-11 16:47:52 +0000 nfsclient: flush dirty pages of the vnode PR: 276002 (cherry picked from commit 47ec00d9d6071bbb0ee5ed0bdca3c4a468334d9d) --- 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 443d8bc6d56b..4ee167cfb5cd 100644 --- a/sys/fs/nfsclient/nfs_clvnops.c +++ b/sys/fs/nfsclient/nfs_clvnops.c @@ -3731,6 +3731,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; @@ -3759,8 +3760,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, NULL); @@ -3800,13 +3808,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 *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; @@ -3816,6 +3825,9 @@ generic_copy: return (ENOSYS); } + invp_lock = LK_SHARED; +relock: + /* Lock both vnodes, avoiding risk of deadlock. */ do { mp = NULL; @@ -3823,14 +3835,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); } @@ -3878,8 +3890,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); @@ -4021,6 +4048,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; @@ -4038,7 +4066,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); @@ -4064,6 +4092,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,