From nobody Sat Mar 16 01:06:04 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 4TxNGh4mvGz5DMBx; Sat, 16 Mar 2024 01:06:04 +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 4TxNGh4Gnbz4fWv; Sat, 16 Mar 2024 01:06:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710551164; 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=je7LMkduv5t27buMd647aOS8Ns8/wxM03KJn3m9who0=; b=sYaKjjMDTxSgTYFHjVBx6CgI6A0z9MI6k9+VT7gnPMBQ2cGO+GL1R2DRG6ORIRYIeMB5R9 S/o6I6pNtVnJIP4cNqgoDL42j4Y9lUKpDOnvs9moMk5dn22Q+EoWlwcfzgn9Nzb7Zos/OR Gus9kThEHJkijZBKPgf+j3P7Rxl05+bHYgvVIaUlmuRUqgZkSJ2E7qy0BuR7YPEFakhfKv ZczcI3hTO39eENbVO+9bWLfLW7FtZsF7P9dG1PdHoCnn7JQ4STDmaNFMLV7gEPSn5zEBhd Ln/saSGvRDVkP3hhWU633NMtmI9NRmGFFlNVnHS4p//CtaLEP/1nInLEB6BnHQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710551164; a=rsa-sha256; cv=none; b=UdaCKW4GJYddtKV4ioca082W8PUSuyTo2EVLcIQoS/E8sGdRHTXSnmS3T8yjRtJPYJ81AX zxOXbxYr7DR4C0Yu5/mKPioQUcDFwuhSD4aZGqUqzGOOkuJ9/4qLgOkU5byojtXUJYtgy8 A9iHTv8mCXIeucgbQW28QlKNHKEof2PcuWFvgcq8sZn+v8Es0ScMRoKWu3WBDF5D0KhiFN AHaCQez1JyMz8PCyLeMzFffSubOcmeMtuZbpfX5/nfxRFa66tX7mnDfQEq6xaQ9Fu6U0vv Rzi/NTOF4ThYRabOnn296NKNY3oNGteolf0Jdgq570N4iHdK+lkdsQCWC9FR7Q== 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=1710551164; 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=je7LMkduv5t27buMd647aOS8Ns8/wxM03KJn3m9who0=; b=uvkyu5aggp3y4XxsNX+elSIsmqkEJkFraFzYKOj/Y83TxXevcSE9N71l+QDV3FBuu5VuB6 TluVMfvQifqkNyIWQnoGyGoQf8VR+0pxM7mtyo4a3wk7C2NNATY7wuaBPKOKC5h1xZp0Dd 9C/Ah5Kq3Iq3L+9TTMaEcDyRS3Q1AwIh6T846NxLrVNj1kW8z1Sh0pfeQXcv/gn/bDjsYi 7sQhxsizWRmeq12rKCjbAvXAeqcvj1a1sMeVn6sxELoTUNm++cm/3E59JjGMiJ9cLQAGB5 +8C+lO9OM2QHNmKK8qbDnCGrgGRQ4gYSq/ntAtTK/BIdH9oXtGi5a02icUVhLA== 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 4TxNGh3TRCzZPX; Sat, 16 Mar 2024 01:06:04 +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 42G164jZ026717; Sat, 16 Mar 2024 01:06:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42G164vh026714; Sat, 16 Mar 2024 01:06:04 GMT (envelope-from git) Date: Sat, 16 Mar 2024 01:06:04 GMT Message-Id: <202403160106.42G164vh026714@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: 748f56c53f42 - main - nfsd: Add a sysctl to limit NFSv4.2 Copy RPC size 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: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 748f56c53f4286e0b140c1b779ff8ade1cf4fec9 Auto-Submitted: auto-generated The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=748f56c53f4286e0b140c1b779ff8ade1cf4fec9 commit 748f56c53f4286e0b140c1b779ff8ade1cf4fec9 Author: Rick Macklem AuthorDate: 2024-03-16 01:04:37 +0000 Commit: Rick Macklem CommitDate: 2024-03-16 01:04:37 +0000 nfsd: Add a sysctl to limit NFSv4.2 Copy RPC size NFSv4.2 supports a Copy operation, which avoids file data being read to the client and then written back to the server, if both input and output files are on the same NFSv4.2 mount for copy_file_range(2). Unfortunately, this Copy operation can take a long time under certain circumstances. If this occurs concurrently with a RPC that requires an exclusive lock on the nfsd such as ExchangeID done for a new mount, the result can be an nfsd "stall" until the Copy completes. This patch adds a sysctl that can be set to limit the size of a Copy operation or, if set to 0, disable Copy operations. The use of this sysctl and other ways to avoid Copy operations taking too long will be documented in the nfsd.4 man page by a separate commit. MFC after: 2 weeks --- sys/fs/nfsserver/nfs_nfsdserv.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c index 3daee65ab83a..899e88508b60 100644 --- a/sys/fs/nfsserver/nfs_nfsdserv.c +++ b/sys/fs/nfsserver/nfs_nfsdserv.c @@ -97,6 +97,9 @@ static bool nfsrv_doallocate = false; SYSCTL_BOOL(_vfs_nfsd, OID_AUTO, enable_v42allocate, CTLFLAG_RW, &nfsrv_doallocate, 0, "Enable NFSv4.2 Allocate operation"); +static uint64_t nfsrv_maxcopyrange = SSIZE_MAX; +SYSCTL_U64(_vfs_nfsd, OID_AUTO, maxcopyrange, CTLFLAG_RW, + &nfsrv_maxcopyrange, 0, "Max size of a Copy so RPC times reasonable"); /* * This list defines the GSS mechanisms supported. @@ -5598,10 +5601,11 @@ nfsrvd_copy_file_range(struct nfsrv_descript *nd, __unused int isdgram, void *rl_rcookie, *rl_wcookie; rl_rcookie = rl_wcookie = NULL; - if (nfsrv_devidcnt > 0) { + if (nfsrv_maxcopyrange == 0 || nfsrv_devidcnt > 0) { /* * For a pNFS server, reply NFSERR_NOTSUPP so that the client * will do the copy via I/O on the DS(s). + * If vfs.nfsd.maxcopyrange set to 0, disable Copy. */ nd->nd_repstat = NFSERR_NOTSUPP; goto nfsmout; @@ -5764,7 +5768,15 @@ nfsrvd_copy_file_range(struct nfsrv_descript *nd, __unused int isdgram, nd->nd_repstat = error; } - xfer = len; + /* + * Do the actual copy to an upper limit of vfs.nfsd.maxcopyrange. + * This size limit can be set to limit the time a copy RPC will + * take. + */ + if (len > nfsrv_maxcopyrange) + xfer = nfsrv_maxcopyrange; + else + xfer = len; if (nd->nd_repstat == 0) { nd->nd_repstat = vn_copy_file_range(vp, &inoff, tovp, &outoff, &xfer, COPY_FILE_RANGE_TIMEO1SEC, nd->nd_cred, nd->nd_cred,