diff mbox series

[v1,14/42] NFSD: Update the NFSv3 PATHCONF3res encoder to use struct xdr_stream

Message ID 161461180307.8508.9954286154242416300.stgit@klimt.1015granger.net (mailing list archive)
State New
Headers show
Series NFSv2/3 XDR encoder overhaul | expand

Commit Message

Chuck Lever III March 1, 2021, 3:16 p.m. UTC
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs3xdr.c |   44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

Comments

Christoph Hellwig March 3, 2021, 7:13 a.m. UTC | #1
On Mon, Mar 01, 2021 at 10:16:43AM -0500, Chuck Lever wrote:
> +	*p++ = resp->p_no_trunc ? xdr_one : xdr_zero;
> +	*p++ = resp->p_chown_restricted ? xdr_one : xdr_zero;
> +	*p++ = resp->p_case_insensitive ? xdr_one : xdr_zero;
> +	*p = resp->p_case_preserving ? xdr_one : xdr_zero;

Wouldn't a little xdr_encode_bool helper for this common pattern be
nice?
Chuck Lever III March 3, 2021, 3:34 p.m. UTC | #2
> On Mar 3, 2021, at 2:13 AM, Christoph Hellwig <hch@infradead.org> wrote:
> 
> On Mon, Mar 01, 2021 at 10:16:43AM -0500, Chuck Lever wrote:
>> +	*p++ = resp->p_no_trunc ? xdr_one : xdr_zero;
>> +	*p++ = resp->p_chown_restricted ? xdr_one : xdr_zero;
>> +	*p++ = resp->p_case_insensitive ? xdr_one : xdr_zero;
>> +	*p = resp->p_case_preserving ? xdr_one : xdr_zero;
> 
> Wouldn't a little xdr_encode_bool helper for this common pattern be
> nice?

Sure. In include/linux/sunrpc/xdr.h, I've now added:

/**
 * xdr_encode_bool - Encode a boolean item
 * @p: address in a buffer into which to encode
 * @n: boolean value to encode
 *
 * Return value:
 *   Address of item following the encoded boolean
 */
static inline __be32 *xdr_encode_bool(__be32 *p, u32 n)
{
       *p = n ? xdr_one : xdr_zero;
       return p++;
}

and xdr_stream_encode_bool() has been changed to use this helper.

In fs/nfsd/nfs3xdr.c, the PATHCONF result encoder now uses
xdr_encode_bool() to encode the four boolean fields in struct
PATHCONF3resok.

--
Chuck Lever
diff mbox series

Patch

diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 514f53ad7302..8485ab50ff3f 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -1501,25 +1501,47 @@  nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p)
 	return 1;
 }
 
+static bool
+svcxdr_encode_pathconf3resok(struct xdr_stream *xdr,
+			     const struct nfsd3_pathconfres *resp)
+{
+	__be32 *p;
+
+	p = xdr_reserve_space(xdr, XDR_UNIT * 6);
+	if (!p)
+		return false;
+	*p++ = cpu_to_be32(resp->p_link_max);
+	*p++ = cpu_to_be32(resp->p_name_max);
+	*p++ = resp->p_no_trunc ? xdr_one : xdr_zero;
+	*p++ = resp->p_chown_restricted ? xdr_one : xdr_zero;
+	*p++ = resp->p_case_insensitive ? xdr_one : xdr_zero;
+	*p = resp->p_case_preserving ? xdr_one : xdr_zero;
+
+	return true;
+}
+
 /* PATHCONF */
 int
 nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p)
 {
+	struct xdr_stream *xdr = &rqstp->rq_res_stream;
 	struct nfsd3_pathconfres *resp = rqstp->rq_resp;
 
-	*p++ = resp->status;
-	*p++ = xdr_zero;	/* no post_op_attr */
-
-	if (resp->status == 0) {
-		*p++ = htonl(resp->p_link_max);
-		*p++ = htonl(resp->p_name_max);
-		*p++ = htonl(resp->p_no_trunc);
-		*p++ = htonl(resp->p_chown_restricted);
-		*p++ = htonl(resp->p_case_insensitive);
-		*p++ = htonl(resp->p_case_preserving);
+	if (!svcxdr_encode_nfsstat3(xdr, resp->status))
+		return 0;
+	switch (resp->status) {
+	case nfs_ok:
+		if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
+			return 0;
+		if (!svcxdr_encode_pathconf3resok(xdr, resp))
+			return 0;
+		break;
+	default:
+		if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
+			return 0;
 	}
 
-	return xdr_ressize_check(rqstp, p);
+	return 1;
 }
 
 /* COMMIT */