From patchwork Sun Dec 19 01:37:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C417FC433EF for ; Sun, 19 Dec 2021 01:44:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231693AbhLSBow (ORCPT ); Sat, 18 Dec 2021 20:44:52 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60812 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233942AbhLSBov (ORCPT ); Sat, 18 Dec 2021 20:44:51 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 561C260C63 for ; Sun, 19 Dec 2021 01:44:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A7AC36AE5; Sun, 19 Dec 2021 01:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878290; bh=puqq6gkqJQQwR9QpNHLUq+p4MgUyq0Ts5PtO6DVqyvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ehdLOSBH/b/V7+He7hcZ6zPZNNnG8CvEAHeTGP9RGphvRX2t56ttTjoHB6DMjv0MB ND9QMsWRzvdto+8ujFFggpA0Mf7TjM/m8zc9HRsyorhLUN74vU+OcrjQdEt2K0KBpp gG+ciSWLtFIAbFN7q5geWsBckh4dbKggod32xtmnK9tOFq7+l+iVEt8ApaADaWGg1N 4V/KDHk3ZfWChwHz53TVcWlkFd1Bk2lRGGpX21lQeZS1PAhIsS1nkj22zbrY/BAf2r YcVcWAaBvFf9bnNIF7eyUAT/qfN/ylpnimxVAld77obgq9wafrQ85nhdZ8NFImo0NS Sj1RsaH+GdUCw== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 01/10] nfsd: map EBADF Date: Sat, 18 Dec 2021 20:37:54 -0500 Message-Id: <20211219013803.324724-2-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-1-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Peng Tao Now that we have open file cache, it is possible that another client deletes the file and DP will not know about it. Then IO to MDS would fail with BADSTATEID and knfsd would start state recovery, which should fail as well and then nfs read/write will fail with EBADF. And it triggers a WARN() in nfserrno(). -----------[ cut here ]------------ WARNING: CPU: 0 PID: 13529 at fs/nfsd/nfsproc.c:758 nfserrno+0x58/0x70 [nfsd]() nfsd: non-standard errno: -9 modules linked in: nfsv3 nfs_layout_flexfiles rpcsec_gss_krb5 nfsv4 dns_resolver nfs fscache ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_connt pata_acpi floppy CPU: 0 PID: 13529 Comm: nfsd Tainted: G W 4.1.5-00307-g6e6579b #7 Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 09/30/2014 0000000000000000 00000000464e6c9c ffff88079085fba8 ffffffff81789936 0000000000000000 ffff88079085fc00 ffff88079085fbe8 ffffffff810a08ea ffff88079085fbe8 ffff88080f45c900 ffff88080f627d50 ffff880790c46a48 all Trace: [] dump_stack+0x45/0x57 [] warn_slowpath_common+0x8a/0xc0 [] warn_slowpath_fmt+0x55/0x70 [] ? splice_direct_to_actor+0x148/0x230 [] ? fsid_source+0x60/0x60 [nfsd] [] nfserrno+0x58/0x70 [nfsd] [] nfsd_finish_read+0x97/0xb0 [nfsd] [] nfsd_splice_read+0x76/0xa0 [nfsd] [] nfsd_read+0xc1/0xd0 [nfsd] [] ? svc_tcp_adjust_wspace+0x12/0x30 [sunrpc] [] nfsd3_proc_read+0xba/0x150 [nfsd] [] nfsd_dispatch+0xc3/0x210 [nfsd] [] ? svc_tcp_adjust_wspace+0x12/0x30 [sunrpc] [] svc_process_common+0x453/0x6f0 [sunrpc] [] svc_process+0x113/0x1b0 [sunrpc] [] nfsd+0xff/0x170 [nfsd] [] ? nfsd_destroy+0x80/0x80 [nfsd] [] kthread+0xd8/0xf0 [] ? kthread_create_on_node+0x1b0/0x1b0 [] ret_from_fork+0x42/0x70 [] ? kthread_create_on_node+0x1b0/0x1b0 Signed-off-by: Peng Tao Signed-off-by: Lance Shelton Signed-off-by: Trond Myklebust --- fs/nfsd/nfsproc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index eea5b59b6a6c..0a2b2795585f 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -850,6 +850,7 @@ nfserrno (int errno) { nfserr_io, -EIO }, { nfserr_nxio, -ENXIO }, { nfserr_fbig, -E2BIG }, + { nfserr_stale, -EBADF }, { nfserr_acces, -EACCES }, { nfserr_exist, -EEXIST }, { nfserr_xdev, -EXDEV }, From patchwork Sun Dec 19 01:37:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686577 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70D01C433FE for ; Sun, 19 Dec 2021 01:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233962AbhLSBow (ORCPT ); Sat, 18 Dec 2021 20:44:52 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60816 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233950AbhLSBow (ORCPT ); Sat, 18 Dec 2021 20:44:52 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DFDB460C63 for ; Sun, 19 Dec 2021 01:44:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1213C36AE2; Sun, 19 Dec 2021 01:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878291; bh=0Jsk7Zr5sI+GMlFYYqBo32v096qFNJVtL/py9XyTCjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I9IRTRHzb/heiR4TOyI+QcYeNAgAsVHxxCDC5qLX1jZg4/eCb6h3dSXiiIs4F4eLq vdDZ/QYTl1opaYG9hwlMQf6vjv9WXrHikphgaBYMupbK/HO61cH7Fb8/2XJwzdpsah hoGLmS81mrACudFFPtCg5lqbuia2a7zYoHo4EeOnMHez9yJn827RO7GK49H84kSgVG 8QNt/qVEk8fAeqLJVqIVjBDQIyu3+8wZht9RJLYHQEuFvTUWxmh89sg4Zxvr5zsbFt +VXG5mVK+89U5LogvspYQmAQoaagpIPj0nvrsSgGOogng5Ccygr9L6zd2ej0eCUqDN s9rpusBap2srw== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 02/10] nfsd: Add errno mapping for EREMOTEIO Date: Sat, 18 Dec 2021 20:37:55 -0500 Message-Id: <20211219013803.324724-3-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-2-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Jeff Layton The NFS client can occasionally return EREMOTEIO when signalling issues with the server. ...map to NFSERR_IO. Signed-off-by: Jeff Layton Signed-off-by: Lance Shelton Signed-off-by: Trond Myklebust --- fs/nfsd/nfsproc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index 0a2b2795585f..83bd11be8406 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -879,6 +879,7 @@ nfserrno (int errno) { nfserr_toosmall, -ETOOSMALL }, { nfserr_serverfault, -ESERVERFAULT }, { nfserr_serverfault, -ENFILE }, + { nfserr_io, -EREMOTEIO }, { nfserr_io, -EUCLEAN }, { nfserr_perm, -ENOKEY }, { nfserr_no_grace, -ENOGRACE}, From patchwork Sun Dec 19 01:37:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E9FFC433EF for ; Sun, 19 Dec 2021 01:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233972AbhLSBoz (ORCPT ); Sat, 18 Dec 2021 20:44:55 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:54020 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233942AbhLSBoz (ORCPT ); Sat, 18 Dec 2021 20:44:55 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3B5D1B80BA8 for ; Sun, 19 Dec 2021 01:44:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85E96C36AEA; Sun, 19 Dec 2021 01:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878291; bh=thcxrZL9ujNH8aHpmoqJoe5Dmbw4qiY9pDab0Oti7dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hN0rene+lHsGrb+J2T3ioW5QfQ0aRKodMRLAHcMEXg7iGywcEte6i5qF1VOEFubuW bYSNhWuJyCswVY6VfSopsEleoHGpeQxdOkaAIpBFyEPEPaLCjucWpvABLq5AtmofgF yRWGla7CCo0jeYwg5gBgiftzLlFwj03GlM56OSU2OaIcGmcGcGUX3eaEkrXyVVVboH +mN914Dc76VkQndOIjvORLT+mQ9qBT6T1RWMhFKLINptqtUh0kutBlg2Kg9ZVQReoH +vWa0QpsNRvgjHEAIZwcv62au2ae+T96XAXIP4e0X1OXW0pzIe7T/7nQuZBKPXH+CE OmF+Z75HgDuUw== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 03/10] nfsd: Retry once in nfsd_open on an -EOPENSTALE return Date: Sat, 18 Dec 2021 20:37:56 -0500 Message-Id: <20211219013803.324724-4-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-3-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Jeff Layton If we get back -EOPENSTALE from an NFSv4 open, then we either got some unhandled error or the inode we got back was not the same as the one associated with the dentry. We really have no recourse in that situation other than to retry the open, and if it fails to just return nfserr_stale back to the client. Signed-off-by: Jeff Layton Signed-off-by: Lance Shelton Signed-off-by: Trond Myklebust --- fs/nfsd/nfsproc.c | 1 + fs/nfsd/vfs.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c index 83bd11be8406..01c1e8f7b766 100644 --- a/fs/nfsd/nfsproc.c +++ b/fs/nfsd/nfsproc.c @@ -880,6 +880,7 @@ nfserrno (int errno) { nfserr_serverfault, -ESERVERFAULT }, { nfserr_serverfault, -ENFILE }, { nfserr_io, -EREMOTEIO }, + { nfserr_stale, -EOPENSTALE }, { nfserr_io, -EUCLEAN }, { nfserr_perm, -ENOKEY }, { nfserr_no_grace, -ENOGRACE}, diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index c99857689e2c..0faa3839ea6c 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -777,6 +777,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int may_flags, struct file **filp) { __be32 err; + bool retried = false; validate_process_creds(); /* @@ -792,9 +793,16 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, */ if (type == S_IFREG) may_flags |= NFSD_MAY_OWNER_OVERRIDE; +retry: err = fh_verify(rqstp, fhp, type, may_flags); - if (!err) + if (!err) { err = __nfsd_open(rqstp, fhp, type, may_flags, filp); + if (err == nfserr_stale && !retried) { + retried = true; + fh_put(fhp); + goto retry; + } + } validate_process_creds(); return err; } From patchwork Sun Dec 19 01:37:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E524BC4332F for ; Sun, 19 Dec 2021 01:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233950AbhLSBox (ORCPT ); Sat, 18 Dec 2021 20:44:53 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60820 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233942AbhLSBox (ORCPT ); Sat, 18 Dec 2021 20:44:53 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A36EC60C63 for ; Sun, 19 Dec 2021 01:44:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E79DC36AE0; Sun, 19 Dec 2021 01:44:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878292; bh=jpjmEyyljh0ZZe/TeyZ7Z6L5jk/Ri/e+zsFtxMLj+CM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ravsgWtLK8B8G5+fkWU5BX2e3J5taxYsEWVFJhE25m7U8rYHlB+GEIAqW+ZcPH/1a utSPrypSPfTOh0RKrd7YiT981AiLXG8sPGPXru4GO6cJ9Eju2tf1SOpS/bGZpWFm/b 9g+xHnb9uxV7c/A2floUyDGOJ3sNDN5JCxIsa7A9B9sm4wCeKu0mRO/HlyTbH36E3x q6knx7eGVq5mpGR4pINVCxi+6CiYiu4whvlznDOd+ytP6izmKHbVEqEylAMSV1l2dn W9iC8vw+1dgjK24pqTuGQHLL5M4ibH5UJCT/jTstZoGaq+PaAV8DY4KCbDn23CGglM +69J58jncYbAw== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 04/10] nfsd: Distinguish between required and optional NFSv3 post-op attributes Date: Sat, 18 Dec 2021 20:37:57 -0500 Message-Id: <20211219013803.324724-5-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-4-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> <20211219013803.324724-4-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust The fhp->fh_no_wcc flag is automatically set in nfsd_set_fh_dentry() when the EXPORT_OP_NOWCC flag is set. In svcxdr_encode_post_op_attr(), this then causes nfsd to skip returning the post-op attributes. The problem is that some of these post-op attributes are not really optional. In particular, we do want LOOKUP to always return post-op attributes for the file that is being looked up. The solution is therefore to explicitly label the attributes that we can safely opt out from, and only apply the 'fhp->fh_no_wcc' test in that case. Signed-off-by: Trond Myklebust Signed-off-by: Lance Shelton Signed-off-by: Trond Myklebust --- fs/nfsd/nfs3xdr.c | 77 +++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c index c3ac1b6aa3aa..6adfc40722fa 100644 --- a/fs/nfsd/nfs3xdr.c +++ b/fs/nfsd/nfs3xdr.c @@ -415,19 +415,9 @@ svcxdr_encode_pre_op_attr(struct xdr_stream *xdr, const struct svc_fh *fhp) return svcxdr_encode_wcc_attr(xdr, fhp); } -/** - * svcxdr_encode_post_op_attr - Encode NFSv3 post-op attributes - * @rqstp: Context of a completed RPC transaction - * @xdr: XDR stream - * @fhp: File handle to encode - * - * Return values: - * %false: Send buffer space was exhausted - * %true: Success - */ -bool -svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, - const struct svc_fh *fhp) +static bool +__svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, + const struct svc_fh *fhp, bool force) { struct dentry *dentry = fhp->fh_dentry; struct kstat stat; @@ -437,7 +427,7 @@ svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, * stale file handle. In this case, no attributes are * returned. */ - if (fhp->fh_no_wcc || !dentry || !d_really_is_positive(dentry)) + if (!force || !dentry || !d_really_is_positive(dentry)) goto no_post_op_attrs; if (fh_getattr(fhp, &stat) != nfs_ok) goto no_post_op_attrs; @@ -454,6 +444,31 @@ svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, return xdr_stream_encode_item_absent(xdr) > 0; } +/** + * svcxdr_encode_post_op_attr - Encode NFSv3 post-op attributes + * @rqstp: Context of a completed RPC transaction + * @xdr: XDR stream + * @fhp: File handle to encode + * + * Return values: + * %false: Send buffer space was exhausted + * %true: Success + */ +bool +svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, + const struct svc_fh *fhp) +{ + return __svcxdr_encode_post_op_attr(rqstp, xdr, fhp, true); +} + +static bool +svcxdr_encode_post_op_attr_opportunistic(struct svc_rqst *rqstp, + struct xdr_stream *xdr, + const struct svc_fh *fhp) +{ + return __svcxdr_encode_post_op_attr(rqstp, xdr, fhp, !fhp->fh_no_wcc); +} + /* * Encode weak cache consistency data */ @@ -481,7 +496,7 @@ svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr, neither: if (xdr_stream_encode_item_absent(xdr) < 0) return false; - if (!svcxdr_encode_post_op_attr(rqstp, xdr, fhp)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, fhp)) return false; return true; @@ -854,11 +869,13 @@ nfs3svc_encode_lookupres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) return false; - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->dirfh)) return false; break; default: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->dirfh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->dirfh)) return false; } @@ -875,13 +892,15 @@ nfs3svc_encode_accessres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; switch (resp->status) { case nfs_ok: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; if (xdr_stream_encode_u32(xdr, resp->access) < 0) return false; break; default: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; } @@ -899,7 +918,8 @@ nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; switch (resp->status) { case nfs_ok: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; if (xdr_stream_encode_u32(xdr, resp->len) < 0) return false; @@ -908,7 +928,8 @@ nfs3svc_encode_readlinkres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; break; default: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; } @@ -926,7 +947,8 @@ nfs3svc_encode_readres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; switch (resp->status) { case nfs_ok: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; if (xdr_stream_encode_u32(xdr, resp->count) < 0) return false; @@ -940,7 +962,8 @@ nfs3svc_encode_readres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; break; default: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; } @@ -1032,7 +1055,8 @@ nfs3svc_encode_readdirres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; switch (resp->status) { case nfs_ok: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; if (!svcxdr_encode_cookieverf3(xdr, resp->verf)) return false; @@ -1044,7 +1068,8 @@ nfs3svc_encode_readdirres(struct svc_rqst *rqstp, struct xdr_stream *xdr) return false; break; default: - if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh)) + if (!svcxdr_encode_post_op_attr_opportunistic(rqstp, xdr, + &resp->fh)) return false; } @@ -1188,7 +1213,7 @@ svcxdr_encode_entry3_plus(struct nfsd3_readdirres *resp, const char *name, if (compose_entry_fh(resp, fhp, name, namlen, ino) != nfs_ok) goto out_noattrs; - if (!svcxdr_encode_post_op_attr(resp->rqstp, xdr, fhp)) + if (!svcxdr_encode_post_op_attr_opportunistic(resp->rqstp, xdr, fhp)) goto out; if (!svcxdr_encode_post_op_fh3(xdr, fhp)) goto out; From patchwork Sun Dec 19 01:37:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEE54C43219 for ; Sun, 19 Dec 2021 01:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233942AbhLSBo4 (ORCPT ); Sat, 18 Dec 2021 20:44:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234000AbhLSBoz (ORCPT ); Sat, 18 Dec 2021 20:44:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4F8DC061574 for ; Sat, 18 Dec 2021 17:44:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 370E860C63 for ; Sun, 19 Dec 2021 01:44:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB14BC36AE9; Sun, 19 Dec 2021 01:44:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878293; bh=mcewRnT0CEgizuQUK0rKMjzB+cN1Q8v+6KeMfTTrBao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZpHsCYxUzEObughhcOI5aw9kZn+Iyc5/9ckkDn5ba3YMxwFxWzAsYo7LBpVA6xku5 B2oRjNCfdEJ/NVwPM7Kg8ueyIWwYQ8ZHWNgc+g6ijWYEc9L4G1a201xRgqTWHJxcdn 4TlVxtdavwV5EI+BU8M2Hr56gzKy8LbXESfGw9YezDVB3mvXiY7phRygCiJm92X/nj HVLld+C2/Lxzzluhfh18nkHSaMWSHC8llFTaR2NXt+in2EpgiBqj62Hze9ADYSy82J h/bW5XEvs/cR+eCkMfxo5tif+CMLi7nMpD080lxc65VlHqhdpwdQQUw9ffYFGd6QP6 4wzxBX8dHoEMA== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 05/10] nfs: Add export support for weak cache consistency attributes Date: Sat, 18 Dec 2021 20:37:58 -0500 Message-Id: <20211219013803.324724-6-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-5-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> <20211219013803.324724-4-trondmy@kernel.org> <20211219013803.324724-5-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Allow knfsd to request weak cache consistency attributes on files that have delegations and/or have up to date attribute caches by propagating the information to NFS that the attributes being requested are optional. Signed-off-by: Trond Myklebust Signed-off-by: Lance Shelton Signed-off-by: Trond Myklebust --- fs/nfs/export.c | 24 ++++++++++++++++++++++++ fs/nfsd/nfs3xdr.c | 8 ++++++-- fs/nfsd/nfs4xdr.c | 6 +++--- fs/nfsd/vfs.c | 14 ++++++++++++++ fs/nfsd/vfs.h | 5 +++-- include/linux/exportfs.h | 3 +++ 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/fs/nfs/export.c b/fs/nfs/export.c index 171c424cb6d5..967f8902c49b 100644 --- a/fs/nfs/export.c +++ b/fs/nfs/export.c @@ -151,10 +151,34 @@ static u64 nfs_fetch_iversion(struct inode *inode) return inode_peek_iversion_raw(inode); } +static int nfs_exp_getattr(struct path *path, struct kstat *stat, bool force) +{ + const unsigned long check_valid = + NFS_INO_INVALID_CHANGE | NFS_INO_INVALID_ATIME | + NFS_INO_INVALID_CTIME | NFS_INO_INVALID_MTIME | + NFS_INO_INVALID_SIZE | /* NFS_INO_INVALID_BLOCKS | */ + NFS_INO_INVALID_OTHER | NFS_INO_INVALID_NLINK; + struct inode *inode = d_inode(path->dentry); + int flags = force ? AT_STATX_SYNC_AS_STAT : AT_STATX_DONT_SYNC; + int ret, ret2 = 0; + + if (!force && nfs_check_cache_invalid(inode, check_valid)) + ret2 = -EAGAIN; + ret = vfs_getattr(path, stat, STATX_BASIC_STATS & ~STATX_BLOCKS, flags); + if (ret < 0) + return ret; + stat->blocks = nfs_calc_block_size(stat->size); + if (S_ISDIR(inode->i_mode)) + stat->blksize = NFS_SERVER(inode)->dtsize; + stat->result_mask |= STATX_BLOCKS; + return ret2; +} + const struct export_operations nfs_export_ops = { .encode_fh = nfs_encode_fh, .fh_to_dentry = nfs_fh_to_dentry, .get_parent = nfs_get_parent, + .getattr = nfs_exp_getattr, .fetch_iversion = nfs_fetch_iversion, .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK| EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS| diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c index 6adfc40722fa..df6e29796494 100644 --- a/fs/nfsd/nfs3xdr.c +++ b/fs/nfsd/nfs3xdr.c @@ -420,6 +420,9 @@ __svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct svc_fh *fhp, bool force) { struct dentry *dentry = fhp->fh_dentry; + struct path path = { + .dentry = dentry, + }; struct kstat stat; /* @@ -427,9 +430,10 @@ __svcxdr_encode_post_op_attr(struct svc_rqst *rqstp, struct xdr_stream *xdr, * stale file handle. In this case, no attributes are * returned. */ - if (!force || !dentry || !d_really_is_positive(dentry)) + if (!dentry || !d_really_is_positive(dentry)) goto no_post_op_attrs; - if (fh_getattr(fhp, &stat) != nfs_ok) + path.mnt = fhp->fh_export->ex_path.mnt; + if (nfsd_getattr(&path, &stat, force) != nfs_ok) goto no_post_op_attrs; if (xdr_stream_encode_item_present(xdr) < 0) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 5a93a5db4fb0..8026925c121f 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2862,9 +2862,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, goto out; } - err = vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); - if (err) - goto out_nfserr; + status = nfsd_getattr(&path, &stat, true); + if (status) + goto out; if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 0faa3839ea6c..eb9818432149 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -2411,3 +2411,17 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp, return err? nfserrno(err) : 0; } + + +__be32 +nfsd_getattr(struct path *p, struct kstat *stat, bool force) +{ + const struct export_operations *ops = p->dentry->d_sb->s_export_op; + int err; + + if (ops->getattr) + err = ops->getattr(p, stat, force); + else + err = vfs_getattr(p, stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); + return err ? nfserrno(err) : 0; +} diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index b21b76e6b9a8..6edae1b9a96e 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -132,6 +132,8 @@ __be32 nfsd_statfs(struct svc_rqst *, struct svc_fh *, __be32 nfsd_permission(struct svc_rqst *, struct svc_export *, struct dentry *, int); +__be32 nfsd_getattr(struct path *p, struct kstat *, bool); + static inline int fh_want_write(struct svc_fh *fh) { int ret; @@ -156,8 +158,7 @@ static inline __be32 fh_getattr(const struct svc_fh *fh, struct kstat *stat) { struct path p = {.mnt = fh->fh_export->ex_path.mnt, .dentry = fh->fh_dentry}; - return nfserrno(vfs_getattr(&p, stat, STATX_BASIC_STATS, - AT_STATX_SYNC_AS_STAT)); + return nfsd_getattr(&p, stat, true); } static inline int nfsd_create_is_exclusive(int createmode) diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h index 3260fe714846..58f36022787e 100644 --- a/include/linux/exportfs.h +++ b/include/linux/exportfs.h @@ -10,6 +10,8 @@ struct inode; struct iomap; struct super_block; struct vfsmount; +struct path; +struct kstat; /* limit the handle size to NFSv4 handle size now */ #define MAX_HANDLE_SZ 128 @@ -224,6 +226,7 @@ struct export_operations { #define EXPORT_OP_SYNC_LOCKS (0x20) /* Filesystem can't do asychronous blocking locks */ unsigned long flags; + int (*getattr)(struct path *, struct kstat *, bool); }; extern int exportfs_encode_inode_fh(struct inode *inode, struct fid *fid, From patchwork Sun Dec 19 01:37:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3700EC433F5 for ; Sun, 19 Dec 2021 01:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234005AbhLSBoz (ORCPT ); Sat, 18 Dec 2021 20:44:55 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60846 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233972AbhLSBoy (ORCPT ); Sat, 18 Dec 2021 20:44:54 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 385A260C8A for ; Sun, 19 Dec 2021 01:44:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 434FDC36AE0; Sun, 19 Dec 2021 01:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878293; bh=2WBd1a/R+kOPNcrOMAPEOIqxzIKowQ0ajdYxNr1LgLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fXZmAqp0AMgH7COo/PEHErYpB7BtfJuLEkllsCgl6oGjH/ipR/gThI4Ye7ViapWPf 2bBPhl9hwXA1TQNff8opamw7eO5s9K5yIUoit3mRnVyebtj0sKwSuY5XIKg3n6lPBL U3lg9zqwN07W6tw+TuHkwxu9g9zSXeTwVqlrdgrefth65Wf6WeKTsGuOlkkr0Vk1/b nD0ZM6YD51q/ICECe1tfRAVOK43OcLj2i9NMw548IdPWKaC35w5mK4Nwu1HHUTKRdi nA+1Hdx1wNB537hI/4pihe85P9EkL7hXOEpy8Wtv7UsDullocCTF0Q8P2ykSRXKuG+ gayWY19IvyCZg== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 06/10] nfsd: NFSv3 should allow zero length writes Date: Sat, 18 Dec 2021 20:37:59 -0500 Message-Id: <20211219013803.324724-7-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-6-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> <20211219013803.324724-4-trondmy@kernel.org> <20211219013803.324724-5-trondmy@kernel.org> <20211219013803.324724-6-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust According to RFC1813: "If count is 0, the WRITE will succeed and return a count of 0, barring errors due to permissions checking." Signed-off-by: Trond Myklebust --- fs/nfsd/vfs.c | 3 +++ net/sunrpc/svc.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index eb9818432149..85e579aa6944 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -967,6 +967,9 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, trace_nfsd_write_opened(rqstp, fhp, offset, *cnt); + if (!*cnt) + return nfs_ok; + if (sb->s_export_op) exp_op_flags = sb->s_export_op->flags; diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 4292278a9552..72a7822fd257 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c @@ -1638,7 +1638,7 @@ unsigned int svc_fill_write_vector(struct svc_rqst *rqstp, * entirely in rq_arg.pages. In this case, @first is empty. */ i = 0; - if (first->iov_len) { + if (first->iov_len || !total) { vec[i].iov_base = first->iov_base; vec[i].iov_len = min_t(size_t, total, first->iov_len); total -= vec[i].iov_len; From patchwork Sun Dec 19 01:38:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0D0EC4321E for ; Sun, 19 Dec 2021 01:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234030AbhLSBo5 (ORCPT ); Sat, 18 Dec 2021 20:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234021AbhLSBo4 (ORCPT ); Sat, 18 Dec 2021 20:44:56 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 906CAC061574 for ; Sat, 18 Dec 2021 17:44:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 52F62B80B6E for ; Sun, 19 Dec 2021 01:44:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCB65C36AE2; Sun, 19 Dec 2021 01:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878294; bh=BvSDEGwdFBH9f2Xi8QRnyZsuu2wjIdn/ctEuHwDexkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qSRhGzdWUBfXF0Ndg0ZWsAmM4zTtzxmuivWfDXh80kwCc15kbd16O8/m1GQAwpQeq JQE+eW6H/uvDsZWjaBkIpxwVLn/u1my+32HmBj6EJRcD2pFcnXjATf3YndhuCdOgbA 9AeP27eFB6lwE+5zQvtgRSXSq+0O9Gyi4aeSzJN/VY4wcTKPZ524Y5yFmVOrQFd98c 7RBMG6VixVtIRoARf8Ndol5NqXHKYiunre4aq53L4tFnyPPhM3QZGY182UsA+9h7wI NWsd+LGbMhXZI/Vxw3LGb0K0P1vjqPjfI4WMPi4kqaibKdxGVxnNNU1crpX4NUjR+M h5+XfVvyypqZQ== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 07/10] nfsd: Add a tracepoint for errors in nfsd4_clone_file_range() Date: Sat, 18 Dec 2021 20:38:00 -0500 Message-Id: <20211219013803.324724-8-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-7-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> <20211219013803.324724-4-trondmy@kernel.org> <20211219013803.324724-5-trondmy@kernel.org> <20211219013803.324724-6-trondmy@kernel.org> <20211219013803.324724-7-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Since a clone error commit can cause the boot verifier to change, we should trace those errors. Signed-off-by: Trond Myklebust --- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/trace.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/vfs.c | 18 +++++++++++++++-- fs/nfsd/vfs.h | 3 ++- 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index a36261f89bdf..35f33959a083 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1101,7 +1101,7 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, if (status) goto out; - status = nfsd4_clone_file_range(src, clone->cl_src_pos, + status = nfsd4_clone_file_range(rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count, EX_ISSYNC(cstate->current_fh.fh_export)); diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h index f1e0d3c51bc2..001444d9829d 100644 --- a/fs/nfsd/trace.h +++ b/fs/nfsd/trace.h @@ -413,6 +413,56 @@ TRACE_EVENT(nfsd_dirent, ) ) +DECLARE_EVENT_CLASS(nfsd_copy_err_class, + TP_PROTO(struct svc_rqst *rqstp, + struct svc_fh *src_fhp, + loff_t src_offset, + struct svc_fh *dst_fhp, + loff_t dst_offset, + u64 count, + int status), + TP_ARGS(rqstp, src_fhp, src_offset, dst_fhp, dst_offset, count, status), + TP_STRUCT__entry( + __field(u32, xid) + __field(u32, src_fh_hash) + __field(loff_t, src_offset) + __field(u32, dst_fh_hash) + __field(loff_t, dst_offset) + __field(u64, count) + __field(int, status) + ), + TP_fast_assign( + __entry->xid = be32_to_cpu(rqstp->rq_xid); + __entry->src_fh_hash = knfsd_fh_hash(&src_fhp->fh_handle); + __entry->src_offset = src_offset; + __entry->dst_fh_hash = knfsd_fh_hash(&dst_fhp->fh_handle); + __entry->dst_offset = dst_offset; + __entry->count = count; + __entry->status = status; + ), + TP_printk("xid=0x%08x src_fh_hash=0x%08x src_offset=%lld " + "dst_fh_hash=0x%08x dst_offset=%lld " + "count=%llu status=%d", + __entry->xid, __entry->src_fh_hash, __entry->src_offset, + __entry->dst_fh_hash, __entry->dst_offset, + (unsigned long long)__entry->count, + __entry->status) +) + +#define DEFINE_NFSD_COPY_ERR_EVENT(name) \ +DEFINE_EVENT(nfsd_copy_err_class, nfsd_##name, \ + TP_PROTO(struct svc_rqst *rqstp, \ + struct svc_fh *src_fhp, \ + loff_t src_offset, \ + struct svc_fh *dst_fhp, \ + loff_t dst_offset, \ + u64 count, \ + int status), \ + TP_ARGS(rqstp, src_fhp, src_offset, dst_fhp, dst_offset, \ + count, status)) + +DEFINE_NFSD_COPY_ERR_EVENT(clone_file_range_err); + #include "state.h" #include "filecache.h" #include "vfs.h" diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 85e579aa6944..4d2964d08097 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -40,6 +40,7 @@ #include "../internal.h" #include "acl.h" #include "idmap.h" +#include "xdr4.h" #endif /* CONFIG_NFSD_V4 */ #include "nfsd.h" @@ -517,8 +518,15 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, } #endif -__be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos, - struct nfsd_file *nf_dst, u64 dst_pos, u64 count, bool sync) +static struct nfsd4_compound_state *nfsd4_get_cstate(struct svc_rqst *rqstp) +{ + return &((struct nfsd4_compoundres *)rqstp->rq_resp)->cstate; +} + +__be32 nfsd4_clone_file_range(struct svc_rqst *rqstp, + struct nfsd_file *nf_src, u64 src_pos, + struct nfsd_file *nf_dst, u64 dst_pos, + u64 count, bool sync) { struct file *src = nf_src->nf_file; struct file *dst = nf_dst->nf_file; @@ -542,6 +550,12 @@ __be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos, if (!status) status = commit_inode_metadata(file_inode(src)); if (status < 0) { + trace_nfsd_clone_file_range_err(rqstp, + &nfsd4_get_cstate(rqstp)->save_fh, + src_pos, + &nfsd4_get_cstate(rqstp)->current_fh, + dst_pos, + count, status); nfsd_reset_boot_verifier(net_generic(nf_dst->nf_net, nfsd_net_id)); ret = nfserrno(status); diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index 6edae1b9a96e..3dba6397d452 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -57,7 +57,8 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *); __be32 nfsd4_vfs_fallocate(struct svc_rqst *, struct svc_fh *, struct file *, loff_t, loff_t, int); -__be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos, +__be32 nfsd4_clone_file_range(struct svc_rqst *, + struct nfsd_file *nf_src, u64 src_pos, struct nfsd_file *nf_dst, u64 dst_pos, u64 count, bool sync); #endif /* CONFIG_NFSD_V4 */ From patchwork Sun Dec 19 01:38:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 628E9C43217 for ; Sun, 19 Dec 2021 01:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234000AbhLSBo4 (ORCPT ); Sat, 18 Dec 2021 20:44:56 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60862 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234021AbhLSBo4 (ORCPT ); Sat, 18 Dec 2021 20:44:56 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8EA6760C8A for ; Sun, 19 Dec 2021 01:44:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4A4FC36AE5; Sun, 19 Dec 2021 01:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878295; bh=0s/YrDE9wWIpyqHRdcF+SoTQu3BUO7YN1DUITLJ5H+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=atTd80dyC0P2W98e7u1/8UqpKZFU8pzdpm0mwul3RHwncO0rAygFo2bzbjrTInE+Z XPSxiWztMuauuvUiBWTj5MEF361VoAsqnPalyb2wtvIaiRIn4U0JpNbFMKwWoxOrdO gsMwTXMNLztA8kuPo7KnS91G9FN8CY50NVVVaH9qbI2R7Sqzx6Wcji6z42+Ri2qMTM Y69mhn7AruzEoFYO8DtKdGqfWqoCajYaAdUbC1HM3vnc3KSwOGbGxWUyPyxSmTQDqW EosG7l3Z5bL8JTd55tb5K2KuhclkaPHXHIeiVo/K31FSJkpeXy65YHN/3svEwMCtSq XeYeXVZ221pEQ== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 08/10] nfsd: Replace use of rwsem with errseq_t Date: Sat, 18 Dec 2021 20:38:01 -0500 Message-Id: <20211219013803.324724-9-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-8-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> <20211219013803.324724-4-trondmy@kernel.org> <20211219013803.324724-5-trondmy@kernel.org> <20211219013803.324724-6-trondmy@kernel.org> <20211219013803.324724-7-trondmy@kernel.org> <20211219013803.324724-8-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust The nfsd_file nf_rwsem is currently being used to separate file write and commit instances to ensure that we catch errors and apply them to the correct write/commit. We can improve scalability at the expense of a little accuracy (some extra false positives) by replacing the nf_rwsem with more careful use of the errseq_t mechanism to track errors across the different operations. Signed-off-by: Trond Myklebust --- fs/nfsd/filecache.c | 1 - fs/nfsd/filecache.h | 1 - fs/nfsd/nfs4proc.c | 16 +++++++++------- fs/nfsd/vfs.c | 40 +++++++++++++++------------------------- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index fdf89fcf1a0c..36f5a06d1067 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -194,7 +194,6 @@ nfsd_file_alloc(struct inode *inode, unsigned int may, unsigned int hashval, __set_bit(NFSD_FILE_BREAK_READ, &nf->nf_flags); } nf->nf_mark = NULL; - init_rwsem(&nf->nf_rwsem); trace_nfsd_file_alloc(nf); } return nf; diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index 7872df5a0fe3..435ceab27897 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -46,7 +46,6 @@ struct nfsd_file { refcount_t nf_ref; unsigned char nf_may; struct nfsd_file_mark *nf_mark; - struct rw_semaphore nf_rwsem; }; int nfsd_file_cache_init(void); diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 35f33959a083..8d2b9ad3b84a 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1510,6 +1510,9 @@ static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync) static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) { + struct file *dst = copy->nf_dst->nf_file; + struct file *src = copy->nf_src->nf_file; + errseq_t since; ssize_t bytes_copied = 0; u64 bytes_total = copy->cp_count; u64 src_pos = copy->cp_src_pos; @@ -1522,9 +1525,8 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) do { if (kthread_should_stop()) break; - bytes_copied = nfsd_copy_file_range(copy->nf_src->nf_file, - src_pos, copy->nf_dst->nf_file, dst_pos, - bytes_total); + bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos, + bytes_total); if (bytes_copied <= 0) break; bytes_total -= bytes_copied; @@ -1534,11 +1536,11 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) } while (bytes_total > 0 && !copy->cp_synchronous); /* for a non-zero asynchronous copy do a commit of data */ if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) { - down_write(©->nf_dst->nf_rwsem); - status = vfs_fsync_range(copy->nf_dst->nf_file, - copy->cp_dst_pos, + since = READ_ONCE(dst->f_wb_err); + status = vfs_fsync_range(dst, copy->cp_dst_pos, copy->cp_res.wr_bytes_written, 0); - up_write(©->nf_dst->nf_rwsem); + if (!status) + status = filemap_check_wb_err(dst->f_mapping, since); if (!status) copy->committed = true; } diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 4d2964d08097..8a48bf18028c 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -530,10 +530,11 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp, { struct file *src = nf_src->nf_file; struct file *dst = nf_dst->nf_file; + errseq_t since; loff_t cloned; __be32 ret = 0; - down_write(&nf_dst->nf_rwsem); + since = READ_ONCE(dst->f_wb_err); cloned = vfs_clone_file_range(src, src_pos, dst, dst_pos, count, 0); if (cloned < 0) { ret = nfserrno(cloned); @@ -547,6 +548,8 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp, loff_t dst_end = count ? dst_pos + count - 1 : LLONG_MAX; int status = vfs_fsync_range(dst, dst_pos, dst_end, 0); + if (!status) + status = filemap_check_wb_err(dst->f_mapping, since); if (!status) status = commit_inode_metadata(file_inode(src)); if (status < 0) { @@ -562,7 +565,6 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp, } } out_err: - up_write(&nf_dst->nf_rwsem); return ret; } @@ -970,6 +972,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, struct super_block *sb = file_inode(file)->i_sb; struct svc_export *exp; struct iov_iter iter; + errseq_t since; __be32 nfserr; int host_err; int use_wgather; @@ -1010,21 +1013,18 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, flags |= RWF_SYNC; iov_iter_kvec(&iter, WRITE, vec, vlen, *cnt); + since = READ_ONCE(file->f_wb_err); if (flags & RWF_SYNC) { - down_write(&nf->nf_rwsem); host_err = vfs_iter_write(file, &iter, &pos, flags); if (host_err < 0) nfsd_reset_boot_verifier(net_generic(SVC_NET(rqstp), nfsd_net_id)); - up_write(&nf->nf_rwsem); } else { - down_read(&nf->nf_rwsem); if (verf) nfsd_copy_boot_verifier(verf, net_generic(SVC_NET(rqstp), nfsd_net_id)); host_err = vfs_iter_write(file, &iter, &pos, flags); - up_read(&nf->nf_rwsem); } if (host_err < 0) { nfsd_reset_boot_verifier(net_generic(SVC_NET(rqstp), @@ -1034,6 +1034,9 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, *cnt = host_err; nfsd_stats_io_write_add(exp, *cnt); fsnotify_modify(file); + host_err = filemap_check_wb_err(file->f_mapping, since); + if (host_err < 0) + goto out_nfserr; if (stable && use_wgather) { host_err = wait_for_concurrent_writes(file); @@ -1114,19 +1117,6 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset, } #ifdef CONFIG_NFSD_V3 -static int -nfsd_filemap_write_and_wait_range(struct nfsd_file *nf, loff_t offset, - loff_t end) -{ - struct address_space *mapping = nf->nf_file->f_mapping; - int ret = filemap_fdatawrite_range(mapping, offset, end); - - if (ret) - return ret; - filemap_fdatawait_range_keep_errors(mapping, offset, end); - return 0; -} - /* * Commit all pending writes to stable storage. * @@ -1157,25 +1147,25 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, if (err) goto out; if (EX_ISSYNC(fhp->fh_export)) { - int err2 = nfsd_filemap_write_and_wait_range(nf, offset, end); + errseq_t since = READ_ONCE(nf->nf_file->f_wb_err); + int err2; - down_write(&nf->nf_rwsem); - if (!err2) - err2 = vfs_fsync_range(nf->nf_file, offset, end, 0); + err2 = vfs_fsync_range(nf->nf_file, offset, end, 0); switch (err2) { case 0: nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net, nfsd_net_id)); + err2 = filemap_check_wb_err(nf->nf_file->f_mapping, + since); break; case -EINVAL: err = nfserr_notsupp; break; default: - err = nfserrno(err2); nfsd_reset_boot_verifier(net_generic(nf->nf_net, nfsd_net_id)); } - up_write(&nf->nf_rwsem); + err = nfserrno(err2); } else nfsd_copy_boot_verifier(verf, net_generic(nf->nf_net, nfsd_net_id)); From patchwork Sun Dec 19 01:38:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4669C433EF for ; Sun, 19 Dec 2021 01:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234021AbhLSBo6 (ORCPT ); Sat, 18 Dec 2021 20:44:58 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:54040 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234054AbhLSBo5 (ORCPT ); Sat, 18 Dec 2021 20:44:57 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CFDC5B80B34 for ; Sun, 19 Dec 2021 01:44:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B92AC36AE9; Sun, 19 Dec 2021 01:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878295; bh=NFPiGcI5+jhgO7Yw7iIAoTjRnRVhh56UZHrfSFk0oVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NcyCinINkHqq8ffam4HxB6MV13VKFdLXsk5dKKgcgtRfRJRwFSvZaQUZr5p3TKzFN OI6JIiwnxMS2ud92ePr2jxGn8xHo54RNecMks5wc5H+DBcnUP0MvFn2lJvQKUa2QaP 5mhpXdXesNT9W+Xq+js4StCvJ9zK+7Hfsr90VKUmbtVUe18RWlJhebGXHczwGVXmYP 8gdNttCnF85P7gVjdjuitzm7ylynSH1Z3KCnXN7JwUmuRLWX6MESeFJIuYap8Gll0C bka35qnR3GjzQivlj4N1Wwcf1PGm6WdZcZFHAhvtII8Vcl3BnUrbk6HVm8Pbs+9rLa Ea0QsbvnFlx+w== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 09/10] nfsd: allow lockd to be forcibly disabled Date: Sat, 18 Dec 2021 20:38:02 -0500 Message-Id: <20211219013803.324724-10-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-9-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> <20211219013803.324724-4-trondmy@kernel.org> <20211219013803.324724-5-trondmy@kernel.org> <20211219013803.324724-6-trondmy@kernel.org> <20211219013803.324724-7-trondmy@kernel.org> <20211219013803.324724-8-trondmy@kernel.org> <20211219013803.324724-9-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Jeff Layton In some cases, we may want to use a userland NLM server which will require that we turn off lockd. Signed-off-by: Jeff Layton Signed-off-by: Lance Shelton Signed-off-by: Trond Myklebust --- fs/nfsd/nfssvc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index 80431921e5d7..6815c70b06af 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -340,8 +340,19 @@ static void nfsd_shutdown_generic(void) nfsd_file_cache_shutdown(); } +/* + * Allow admin to disable lockd. This would typically be used to allow (e.g.) + * a userspace NLM server of some sort to be used. + */ +static bool nfsd_disable_lockd = false; +module_param(nfsd_disable_lockd, bool, 0644); +MODULE_PARM_DESC(nfsd_disable_lockd, "Allow lockd to be manually disabled."); + static bool nfsd_needs_lockd(struct nfsd_net *nn) { + if (nfsd_disable_lockd) + return false; + return nfsd_vers(nn, 2, NFSD_TEST) || nfsd_vers(nn, 3, NFSD_TEST); } From patchwork Sun Dec 19 01:38:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12686591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7F5FC433FE for ; Sun, 19 Dec 2021 01:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234040AbhLSBo5 (ORCPT ); Sat, 18 Dec 2021 20:44:57 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:60876 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234030AbhLSBo4 (ORCPT ); Sat, 18 Dec 2021 20:44:56 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 514AB60C8A for ; Sun, 19 Dec 2021 01:44:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6901C36AE2; Sun, 19 Dec 2021 01:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639878296; bh=D24gjaXjPSH939n63F3M3T7h43bCH/npwFAnsjzM28A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IOCQxcYnyeKJ0rEGyr7ACKFgx9Fuoh1ddOKiawpcFdAbMq6WkKR55TEWQ0D+p1pOS y6K7lJI2sb6jwC9OjLJxsDdGsAgqqb5vAmaqh8ULBBVhZrwzMe0QdaqToOF8hqxg7h 1kflQoNFQbFxcOf19wyA0eFh8s7B69KpgbLz3k+fTp0EY2LQP7u7dV3X7+b9/f0r7C 1HDyf5Y4H4I4rQ/Epf2yzt+8CrZd83nFxPTxhvPtDgDCoYFF++RsGYhiE6Lre/i1DH 2PZ0aWhsE1rQueqTJN/TKahtBOD7VJIyoNri/HLc1AKErPMPsTyDGl7xBzJnfZSAoT FfC0z+t7ScLwQ== From: trondmy@kernel.org To: Chuck Lever , "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 10/10] nfsd: Ignore rpcbind errors on nfsd startup Date: Sat, 18 Dec 2021 20:38:03 -0500 Message-Id: <20211219013803.324724-11-trondmy@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211219013803.324724-10-trondmy@kernel.org> References: <20211219013803.324724-1-trondmy@kernel.org> <20211219013803.324724-2-trondmy@kernel.org> <20211219013803.324724-3-trondmy@kernel.org> <20211219013803.324724-4-trondmy@kernel.org> <20211219013803.324724-5-trondmy@kernel.org> <20211219013803.324724-6-trondmy@kernel.org> <20211219013803.324724-7-trondmy@kernel.org> <20211219013803.324724-8-trondmy@kernel.org> <20211219013803.324724-9-trondmy@kernel.org> <20211219013803.324724-10-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust NFSv4 doesn't need rpcbind, so let's not refuse to start up just because the rpcbind registration failed. Signed-off-by: Trond Myklebust --- fs/nfsd/nfsctl.c | 7 ++++++- fs/nfsd/nfsd.h | 1 + fs/nfsd/nfssvc.c | 18 ++++++++++++++++-- include/linux/sunrpc/svcsock.h | 5 +++-- net/sunrpc/svcsock.c | 14 ++++++++------ 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 51a49e0cfe37..da9760479acd 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -727,6 +727,7 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred char *mesg = buf; int fd, err; struct nfsd_net *nn = net_generic(net, nfsd_net_id); + int flags = SVC_SOCK_DEFAULTS; err = get_int(&mesg, &fd); if (err != 0 || fd < 0) @@ -741,7 +742,11 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred if (err != 0) return err; - err = svc_addsock(nn->nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT, cred); + if (!nfsd_rpcbind_error_is_fatal()) + flags |= SVC_SOCK_RPCBIND_NOERR; + + err = svc_addsock(nn->nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT, + flags, cred); if (err < 0) { nfsd_destroy(net); return err; diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h index 498e5a489826..e0356d3ecf65 100644 --- a/fs/nfsd/nfsd.h +++ b/fs/nfsd/nfsd.h @@ -134,6 +134,7 @@ int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change); int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change); void nfsd_reset_versions(struct nfsd_net *nn); int nfsd_create_serv(struct net *net); +extern bool nfsd_rpcbind_error_is_fatal(void); extern int nfsd_max_blksize; diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index 6815c70b06af..6f22c72f340d 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -289,17 +289,21 @@ static int nfsd_init_socks(struct net *net, const struct cred *cred) { int error; struct nfsd_net *nn = net_generic(net, nfsd_net_id); + int flags = SVC_SOCK_DEFAULTS; if (!list_empty(&nn->nfsd_serv->sv_permsocks)) return 0; + if (!nfsd_rpcbind_error_is_fatal()) + flags |= SVC_SOCK_RPCBIND_NOERR; + error = svc_create_xprt(nn->nfsd_serv, "udp", net, PF_INET, NFS_PORT, - SVC_SOCK_DEFAULTS, cred); + flags, cred); if (error < 0) return error; error = svc_create_xprt(nn->nfsd_serv, "tcp", net, PF_INET, NFS_PORT, - SVC_SOCK_DEFAULTS, cred); + flags, cred); if (error < 0) return error; @@ -340,6 +344,16 @@ static void nfsd_shutdown_generic(void) nfsd_file_cache_shutdown(); } +static bool nfsd_rpcbind_error_fatal = false; +module_param(nfsd_rpcbind_error_fatal, bool, 0644); +MODULE_PARM_DESC(nfsd_rpcbind_error_fatal, + "rpcbind errors are fatal when starting nfsd."); + +bool nfsd_rpcbind_error_is_fatal(void) +{ + return nfsd_rpcbind_error_fatal; +} + /* * Allow admin to disable lockd. This would typically be used to allow (e.g.) * a userspace NLM server of some sort to be used. diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h index bcc555c7ae9c..f34c222cee9d 100644 --- a/include/linux/sunrpc/svcsock.h +++ b/include/linux/sunrpc/svcsock.h @@ -61,8 +61,8 @@ void svc_drop(struct svc_rqst *); void svc_sock_update_bufs(struct svc_serv *serv); bool svc_alien_sock(struct net *net, int fd); int svc_addsock(struct svc_serv *serv, const int fd, - char *name_return, const size_t len, - const struct cred *cred); + char *name_return, const size_t len, int flags, + const struct cred *cred); void svc_init_xprt_sock(void); void svc_cleanup_xprt_sock(void); struct svc_xprt *svc_sock_create(struct svc_serv *serv, int prot); @@ -74,5 +74,6 @@ void svc_sock_destroy(struct svc_xprt *); #define SVC_SOCK_DEFAULTS (0U) #define SVC_SOCK_ANONYMOUS (1U << 0) /* don't register with pmap */ #define SVC_SOCK_TEMPORARY (1U << 1) /* flag socket as temporary */ +#define SVC_SOCK_RPCBIND_NOERR (1U << 2) /* Ignore pmap errors */ #endif /* SUNRPC_SVCSOCK_H */ diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 478f857cdaed..7f5b12a50bf9 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -1309,14 +1309,15 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv, inet = sock->sk; /* Register socket with portmapper */ - if (pmap_register) + if (pmap_register) { err = svc_register(serv, sock_net(sock->sk), inet->sk_family, inet->sk_protocol, ntohs(inet_sk(inet)->inet_sport)); - if (err < 0) { - kfree(svsk); - return ERR_PTR(err); + if (err < 0 && !(flags & SVC_SOCK_RPCBIND_NOERR)) { + kfree(svsk); + return ERR_PTR(err); + } } svsk->sk_sock = sock; @@ -1364,6 +1365,7 @@ EXPORT_SYMBOL_GPL(svc_alien_sock); * @fd: file descriptor of the new listener * @name_return: pointer to buffer to fill in with name of listener * @len: size of the buffer + * @flags: flags argument for svc_setup_socket() * @cred: credential * * Fills in socket name and returns positive length of name if successful. @@ -1371,7 +1373,7 @@ EXPORT_SYMBOL_GPL(svc_alien_sock); * value. */ int svc_addsock(struct svc_serv *serv, const int fd, char *name_return, - const size_t len, const struct cred *cred) + const size_t len, int flags, const struct cred *cred) { int err = 0; struct socket *so = sockfd_lookup(fd, &err); @@ -1395,7 +1397,7 @@ int svc_addsock(struct svc_serv *serv, const int fd, char *name_return, err = -ENOENT; if (!try_module_get(THIS_MODULE)) goto out; - svsk = svc_setup_socket(serv, so, SVC_SOCK_DEFAULTS); + svsk = svc_setup_socket(serv, so, flags); if (IS_ERR(svsk)) { module_put(THIS_MODULE); err = PTR_ERR(svsk);