From patchwork Wed Oct 4 13:41:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13408794 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 59B63E7B617 for ; Wed, 4 Oct 2023 13:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233066AbjJDNlt (ORCPT ); Wed, 4 Oct 2023 09:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233255AbjJDNlt (ORCPT ); Wed, 4 Oct 2023 09:41:49 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3989B for ; Wed, 4 Oct 2023 06:41:46 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BECEDC433C8; Wed, 4 Oct 2023 13:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696426906; bh=Z2+uKJSDcWzdABCM+PJV9Cu3GHRam6rVRAWlWfgswxc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=X4aHUNpwEsLLyDYs4JScHoF6cTpuwiynkfyjz7Jtyij61SkV8ZXeYcUu8bP+IBIHi 9ixc5A9BYEbgB1MZRnrCWAdy4p97gDPv59Kh5V0OMjUUKKm3nQvme5qTB67mEWg7Zm 2bUto5W+/NuC3YdgD9WEjy82HsZkOFW8znB/OtTT6kmMRQBKnRwlxfcRzoBI+dqk8z CfdwUV7d7nmIDZQBH9A9sQYewBUTZ4WUHa0zwLefAMAoiB9r0TMvraB0Cjb64nvDQG jfwo61us1MgW3yLnqaXKZkUydF6asTq1T3xm4+iu/pdnTrm0SQdJCKwveG2KX9v0jR jLXvfD5nixT1A== Subject: [PATCH v1 1/5] NFSD: Rename nfsd4_encode_dirent() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Wed, 04 Oct 2023 09:41:44 -0400 Message-ID: <169642690474.7503.14994605453994505408.stgit@klimt.1015granger.net> In-Reply-To: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> References: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Rename nfsd4_encode_dirent() to match the naming convention already used in the NFSv2 and NFSv3 readdir paths. The new name reflects the name of the spec-defined XDR data type for an NFSv4 directory entry. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index f1f0b707c7d9..a6b6ff5819e9 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3670,8 +3670,8 @@ static inline int attributes_need_mount(u32 *bmval) } static __be32 -nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, - const char *name, int namlen) +nfsd4_encode_entry4_fattr(struct nfsd4_readdir *cd, const char *name, + int namlen) { struct svc_export *exp = cd->rd_fhp->fh_export; struct dentry *dentry; @@ -3714,7 +3714,7 @@ nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, } out_encode: - nfserr = nfsd4_encode_fattr4(cd->rd_rqstp, xdr, NULL, exp, dentry, + nfserr = nfsd4_encode_fattr4(cd->rd_rqstp, cd->xdr, NULL, exp, dentry, cd->rd_bmval, ignore_crossmnt); out_put: dput(dentry); @@ -3740,7 +3740,7 @@ nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) } static int -nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, +nfsd4_encode_entry4(void *ccdv, const char *name, int namlen, loff_t offset, u64 ino, unsigned int d_type) { struct readdir_cd *ccd = ccdv; @@ -3777,7 +3777,7 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, p = xdr_encode_hyper(p, OFFSET_MAX); /* offset of next entry */ p = xdr_encode_array(p, name, namlen); /* name length & name */ - nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen); + nfserr = nfsd4_encode_entry4_fattr(cd, name, namlen); switch (nfserr) { case nfs_ok: break; @@ -4489,9 +4489,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, readdir->cookie_offset = 0; offset = readdir->rd_cookie; - nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, - &offset, - &readdir->common, nfsd4_encode_dirent); + nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, &offset, + &readdir->common, nfsd4_encode_entry4); if (nfserr == nfs_ok && readdir->common.err == nfserr_toosmall && xdr->buf->len == starting_len + 8) { From patchwork Wed Oct 4 13:41:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13408795 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 B7BE6E7B616 for ; Wed, 4 Oct 2023 13:41:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233368AbjJDNl4 (ORCPT ); Wed, 4 Oct 2023 09:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233328AbjJDNlz (ORCPT ); Wed, 4 Oct 2023 09:41:55 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE530BD for ; Wed, 4 Oct 2023 06:41:52 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C712C433C8; Wed, 4 Oct 2023 13:41:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696426912; bh=3QfietrAj3DTSx1qAZKGOWQZTTO2iq8xFKdPuQhHQ0Y=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Du5ClrtbOYHPy3rsCydG3n/89TanY7uM5h/jEtIrn4TQn6vKz+aAgjITnq4Gqg70l f2T++7HsnO6217VJ5gk/cL8eMH7cBC75DY9b9tcE2lTltAWXxf8rxPYL7ovzkXj+3N zU8u6JvJjKcnpN7UYNjU5MkujpbIYJ+WKddHy9qBWGbYdF+spzO0nsgp979qNPb+q1 ZT97/7qg4UuM5AXeWkkc8pMA1gMmTLk/Fb2k6Oj6jBEqGCCvQeuVX2NegcR52DRb5r kfinbGFjEDybjGerfU2qNBYke1TUcrccTtLJodNyB6yUzuJX0O5BRoH0eQgUZEdLej 8plwUqT/qOyxA== Subject: [PATCH v1 2/5] NFSD: Clean up nfsd4_encode_rdattr_error() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Wed, 04 Oct 2023 09:41:51 -0400 Message-ID: <169642691116.7503.5603118483366668621.stgit@klimt.1015granger.net> In-Reply-To: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> References: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever No need for specialized code here, as this function is invoked only rarely. Convert it to encode to xdr_stream using conventional XDR helpers. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index a6b6ff5819e9..26a9391d7766 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3722,21 +3722,22 @@ nfsd4_encode_entry4_fattr(struct nfsd4_readdir *cd, const char *name, return nfserr; } -static __be32 * -nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) +static __be32 +nfsd4_encode_entry4_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) { - __be32 *p; - - p = xdr_reserve_space(xdr, 20); - if (!p) - return NULL; - *p++ = htonl(2); - *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ - *p++ = htonl(0); /* bmval1 */ + __be32 status; - *p++ = htonl(4); /* attribute length */ - *p++ = nfserr; /* no htonl */ - return p; + /* attrmask */ + status = nfsd4_encode_bitmap4(xdr, FATTR4_WORD0_RDATTR_ERROR, 0, 0); + if (status != nfs_ok) + return status; + /* attr_vals */ + if (xdr_stream_encode_u32(xdr, XDR_UNIT) != XDR_UNIT) + return nfserr_resource; + /* rdattr_error */ + if (xdr_stream_encode_be32(xdr, nfserr) != XDR_UNIT) + return nfserr_resource; + return nfs_ok; } static int @@ -3808,8 +3809,7 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen, */ if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) goto fail; - p = nfsd4_encode_rdattr_error(xdr, nfserr); - if (p == NULL) { + if (nfsd4_encode_entry4_rdattr_error(xdr, nfserr)) { nfserr = nfserr_toosmall; goto fail; } From patchwork Wed Oct 4 13:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13408796 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 8FCA5E7B611 for ; Wed, 4 Oct 2023 13:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233338AbjJDNmC (ORCPT ); Wed, 4 Oct 2023 09:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233328AbjJDNmB (ORCPT ); Wed, 4 Oct 2023 09:42:01 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE7F8A9 for ; Wed, 4 Oct 2023 06:41:58 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C8E8C433CA; Wed, 4 Oct 2023 13:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696426918; bh=QsxiiP8P1LIewrRuytc8A8q6Tv7U/XL9DsRPg4me2aI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=m1zJmBL1UYwE920Ds09sUYCysWqw8CQb/7uX8bRjjlb46Qc5eCncSdFT+iT23fuuo 1FelI8gw85v/3U4LDHfzlxin7+dQitNHNh/WoK2LDGuKs4EpoKZewiGLCYLM5Ed8Sc rGMHPjExCdeh50PrH5dqWxpruSPXMV13AFN+o0Bs3v8OM44fdMz0j18+Gi4XB2hVs2 UREnODEZrKSvFqnvJizP8z/KGh8aY0N7iQOzm/jbiU3Pi1VopreUkySQbPRIo3cCJd iZ8ebBW/I/+oA0nn+Kb8d15NwPcNIRp3jhqy0T2R8BEcADOuo1c9UYaFPcQnFCSQnw v7fm33fyHgB8w== Subject: [PATCH v1 3/5] NFSD: Add an nfsd4_encode_nfs_cookie4() helper From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Wed, 04 Oct 2023 09:41:57 -0400 Message-ID: <169642691755.7503.7423015225006996766.stgit@klimt.1015granger.net> In-Reply-To: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> References: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever De-duplicate the entry4 cookie encoder, similar to the arrangement for the NFSv2 and NFSv3 directory entry encoders. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 26a9391d7766..3eba3f316d97 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3660,6 +3660,22 @@ __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, return ret; } +/* + * The buffer space for this field was reserved during a previous + * call to nfsd4_encode_entry4(). + */ +static void nfsd4_encode_entry4_nfs_cookie4(const struct nfsd4_readdir *readdir, + u64 offset) +{ + __be64 cookie = cpu_to_be64(offset); + struct xdr_stream *xdr = readdir->xdr; + + if (!readdir->cookie_offset) + return; + write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, &cookie, + sizeof(cookie)); +} + static inline int attributes_need_mount(u32 *bmval) { if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) @@ -3752,7 +3768,6 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen, u32 name_and_cookie; int entry_bytes; __be32 nfserr = nfserr_toosmall; - __be64 wire_offset; __be32 *p; /* In nfsv4, "." and ".." never make it onto the wire.. */ @@ -3761,11 +3776,8 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen, return 0; } - if (cd->cookie_offset) { - wire_offset = cpu_to_be64(offset); - write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset, - &wire_offset, 8); - } + /* Encode the previous entry's cookie value */ + nfsd4_encode_entry4_nfs_cookie4(cd, offset); p = xdr_reserve_space(xdr, 4); if (!p) @@ -4447,7 +4459,6 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, int maxcount; int bytes_left; loff_t offset; - __be64 wire_offset; struct xdr_stream *xdr = resp->xdr; int starting_len = xdr->buf->len; __be32 *p; @@ -4505,11 +4516,8 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, if (nfserr) goto err_no_verf; - if (readdir->cookie_offset) { - wire_offset = cpu_to_be64(offset); - write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, - &wire_offset, 8); - } + /* Encode the final entry's cookie value */ + nfsd4_encode_entry4_nfs_cookie4(readdir, offset); p = xdr_reserve_space(xdr, 8); if (!p) { From patchwork Wed Oct 4 13:42:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13408797 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 D4C46E7B616 for ; Wed, 4 Oct 2023 13:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233328AbjJDNmK (ORCPT ); Wed, 4 Oct 2023 09:42:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233381AbjJDNmJ (ORCPT ); Wed, 4 Oct 2023 09:42:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57488C4 for ; Wed, 4 Oct 2023 06:42:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF589C433C7; Wed, 4 Oct 2023 13:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696426925; bh=jGIIFqsFyWBFrl7eSU/+kAyOvRi7vHJXfbgImCUAHsE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=hfMdm+p0dOoL+AZwOClHPzZ+2LJzSF9+ukzgddmnVaH51l2m3X5vuL1ZFEcXkta5q +BPd0+WeMQZ0lg6DHBwnJd+1ozzkicaqGqFMNmfSf1QyqEUbabny+A+dR5bE6PrKTl AnLYHqoXpuwQbdROsaMk/IeDi90lxi/XfVNHyqgiRD3fmqpUEoEpf4sjGFqg5fDBZd JrZhYXLqS8EF5GNjvIexOKsvM7RlwHhuc7NWILu6fSw3QN/4itKNjaaPdmu/DzgOkc yb9hM3VyCK4RTZvikHiLkA1Q8nwhsQn4XAU8zIwlA8OGQ/+0uqz6qruMljpgKICFao 7O5KUda0se+0Q== Subject: [PATCH v1 4/5] NFSD: Clean up nfsd4_encode_entry4() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Wed, 04 Oct 2023 09:42:03 -0400 Message-ID: <169642692381.7503.16200002695655143315.stgit@klimt.1015granger.net> In-Reply-To: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> References: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Reshape nfsd4_encode_entry4() to be more like the legacy dirent encoders, which were recently rewritten to use xdr_stream. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 15 ++++++--------- fs/nfsd/xdr4.h | 3 +++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index 3eba3f316d97..cfc8e241e8fb 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -3768,7 +3768,6 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen, u32 name_and_cookie; int entry_bytes; __be32 nfserr = nfserr_toosmall; - __be32 *p; /* In nfsv4, "." and ".." never make it onto the wire.. */ if (name && isdotent(name, namlen)) { @@ -3779,17 +3778,15 @@ nfsd4_encode_entry4(void *ccdv, const char *name, int namlen, /* Encode the previous entry's cookie value */ nfsd4_encode_entry4_nfs_cookie4(cd, offset); - p = xdr_reserve_space(xdr, 4); - if (!p) + if (xdr_stream_encode_item_present(xdr) != XDR_UNIT) goto fail; - *p++ = xdr_one; /* mark entry present */ + + /* Reserve send buffer space for this entry's cookie value. */ cookie_offset = xdr->buf->len; - p = xdr_reserve_space(xdr, 3*4 + namlen); - if (!p) + if (nfsd4_encode_nfs_cookie4(xdr, OFFSET_MAX) != nfs_ok) + goto fail; + if (nfsd4_encode_component4(xdr, name, namlen) != nfs_ok) goto fail; - p = xdr_encode_hyper(p, OFFSET_MAX); /* offset of next entry */ - p = xdr_encode_array(p, name, namlen); /* name length & name */ - nfserr = nfsd4_encode_entry4_fattr(cd, name, namlen); switch (nfserr) { case nfs_ok: diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index cd124969589e..6f5c3f4b4ca3 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -120,6 +120,7 @@ nfsd4_encode_uint64_t(struct xdr_stream *xdr, u64 val) } #define nfsd4_encode_changeid4(x, v) nfsd4_encode_uint64_t(x, v) +#define nfsd4_encode_nfs_cookie4(x, v) nfsd4_encode_uint64_t(x, v) #define nfsd4_encode_length4(x, v) nfsd4_encode_uint64_t(x, v) #define nfsd4_encode_offset4(x, v) nfsd4_encode_uint64_t(x, v) @@ -174,6 +175,8 @@ nfsd4_encode_opaque(struct xdr_stream *xdr, const void *data, size_t size) return nfs_ok; } +#define nfsd4_encode_component4(x, d, s) nfsd4_encode_opaque(x, d, s) + struct nfsd4_compound_state { struct svc_fh current_fh; struct svc_fh save_fh; From patchwork Wed Oct 4 13:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13408798 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 F1819E7B616 for ; Wed, 4 Oct 2023 13:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233329AbjJDNmP (ORCPT ); Wed, 4 Oct 2023 09:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233345AbjJDNmP (ORCPT ); Wed, 4 Oct 2023 09:42:15 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1829CC for ; Wed, 4 Oct 2023 06:42:11 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CAEDC433C7; Wed, 4 Oct 2023 13:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696426931; bh=7bdhWdU/hZv4YE1RRzOgpa/HAfERUY0aI2bNaGaycEI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=LesEWZXriHhXQRq95XtQ4rJZXywe+4IaSEZ6ZAs4Q+R2+GsiUQ/Lg5wd3B9LnrsqT WLwxVkqdoiK0W6BtbGhnAKUcP8atQ2oSgM7AgQG+PVpNyManqsIUl5yxSrRi4LbwLI 3Q9ftNNhGgznFKx5cmcXwXST3p8Eu8/4ET/qV0aLHsZVWvLkjlnWmYrZUa6zVfuxpT 6qpUy6LCnY6nDDCKgfPVx4Rt8mpfUv1GeGCGs7UGl9mAwmRb9MxgPnSUNVrY2mhdsL tOsO97crrbZvCl1F0HSRCZGK5IwL4fddZADROXnjuGTWfRyVavmZf0Bo9wLOQzICJL 0BrD5Nn9FEsbw== Subject: [PATCH v1 5/5] NFSD: Clean up nfsd4_encode_readdir() From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: Chuck Lever Date: Wed, 04 Oct 2023 09:42:10 -0400 Message-ID: <169642693016.7503.11226063374751505918.stgit@klimt.1015granger.net> In-Reply-To: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> References: <169642681764.7503.2925922561588558142.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Chuck Lever Untangle nfsd4_encode_readdir() so it is more clear what XDR data item is being encoded by which piece of code. Signed-off-by: Chuck Lever --- fs/nfsd/nfs4xdr.c | 112 ++++++++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index cfc8e241e8fb..5efcd9691e5d 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -4448,85 +4448,83 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, return nfserr; } -static __be32 -nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, - union nfsd4_op_u *u) +static __be32 nfsd4_encode_dirlist4(struct xdr_stream *xdr, + struct nfsd4_readdir *readdir, + u32 max_payload) { - struct nfsd4_readdir *readdir = &u->readdir; - int maxcount; - int bytes_left; + int bytes_left, maxcount, starting_len = xdr->buf->len; loff_t offset; - struct xdr_stream *xdr = resp->xdr; - int starting_len = xdr->buf->len; - __be32 *p; - - nfserr = nfsd4_encode_verifier4(xdr, &readdir->rd_verf); - if (nfserr != nfs_ok) - return nfserr; + __be32 status; /* * Number of bytes left for directory entries allowing for the - * final 8 bytes of the readdir and a following failed op: + * final 8 bytes of the readdir and a following failed op. */ - bytes_left = xdr->buf->buflen - xdr->buf->len - - COMPOUND_ERR_SLACK_SPACE - 8; - if (bytes_left < 0) { - nfserr = nfserr_resource; - goto err_no_verf; - } - maxcount = svc_max_payload(resp->rqstp); - maxcount = min_t(u32, readdir->rd_maxcount, maxcount); + bytes_left = xdr->buf->buflen - xdr->buf->len - + COMPOUND_ERR_SLACK_SPACE - XDR_UNIT * 2; + if (bytes_left < 0) + return nfserr_resource; + maxcount = min_t(u32, readdir->rd_maxcount, max_payload); + /* - * Note the rfc defines rd_maxcount as the size of the - * READDIR4resok structure, which includes the verifier above - * and the 8 bytes encoded at the end of this function: + * The RFC defines rd_maxcount as the size of the + * READDIR4resok structure, which includes the verifier + * and the 8 bytes encoded at the end of this function. */ - if (maxcount < 16) { - nfserr = nfserr_toosmall; - goto err_no_verf; - } - maxcount = min_t(int, maxcount-16, bytes_left); + if (maxcount < XDR_UNIT * 4) + return nfserr_toosmall; + maxcount = min_t(int, maxcount - XDR_UNIT * 4, bytes_left); - /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ + /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0 */ if (!readdir->rd_dircount) - readdir->rd_dircount = svc_max_payload(resp->rqstp); + readdir->rd_dircount = max_payload; + /* *entries */ readdir->xdr = xdr; readdir->rd_maxcount = maxcount; readdir->common.err = 0; readdir->cookie_offset = 0; - offset = readdir->rd_cookie; - nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, &offset, + status = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, &offset, &readdir->common, nfsd4_encode_entry4); - if (nfserr == nfs_ok && - readdir->common.err == nfserr_toosmall && - xdr->buf->len == starting_len + 8) { - /* nothing encoded; which limit did we hit?: */ - if (maxcount - 16 < bytes_left) - /* It was the fault of rd_maxcount: */ - nfserr = nfserr_toosmall; - else - /* We ran out of buffer space: */ - nfserr = nfserr_resource; + if (status) + return status; + if (readdir->common.err == nfserr_toosmall && + xdr->buf->len == starting_len) { + /* No entries were encoded. Which limit did we hit? */ + if (maxcount - XDR_UNIT * 4 < bytes_left) + /* It was the fault of rd_maxcount */ + return nfserr_toosmall; + /* We ran out of buffer space */ + return nfserr_resource; } - if (nfserr) - goto err_no_verf; - /* Encode the final entry's cookie value */ nfsd4_encode_entry4_nfs_cookie4(readdir, offset); + /* No entries follow */ + if (xdr_stream_encode_item_absent(xdr) != XDR_UNIT) + return nfserr_resource; - p = xdr_reserve_space(xdr, 8); - if (!p) { - WARN_ON_ONCE(1); - goto err_no_verf; - } - *p++ = 0; /* no more entries */ - *p++ = htonl(readdir->common.err == nfserr_eof); + /* eof */ + return nfsd4_encode_bool(xdr, readdir->common.err == nfserr_eof); +} - return 0; -err_no_verf: - xdr_truncate_encode(xdr, starting_len); +static __be32 +nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, + union nfsd4_op_u *u) +{ + struct nfsd4_readdir *readdir = &u->readdir; + struct xdr_stream *xdr = resp->xdr; + int starting_len = xdr->buf->len; + + /* cookieverf */ + nfserr = nfsd4_encode_verifier4(xdr, &readdir->rd_verf); + if (nfserr != nfs_ok) + return nfserr; + + /* reply */ + nfserr = nfsd4_encode_dirlist4(xdr, readdir, svc_max_payload(resp->rqstp)); + if (nfserr != nfs_ok) + xdr_truncate_encode(xdr, starting_len); return nfserr; }