Linux NFS development
 help / color / mirror / Atom feed
* [PATCH v1 00/52] Modernize nfsd4_encode_fattr()
@ 2023-09-18 13:56 Chuck Lever
  2023-09-18 13:56 ` [PATCH v1 01/52] NFSD: Add simple u32, u64, and bool encoders Chuck Lever
                   ` (52 more replies)
  0 siblings, 53 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:56 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

This series restructures the server's fattr4 encoder. It is largely
a maintenance improvement (ie, only 2nd-order benefits). There are
no new features or performance benefits, and I hope there will be no
changes in behavior.

The goals:
* Better alignment with spec
* Easier to read and audit
* Less brittle
* Some code de-duplication

This series applies to v6.6-rc2. Minor adjustment will be needed to
apply it to nfsd-next. I apologize for the number of patches, but
each of them (with only a couple of exceptions) is small and
mechanical, and therefore easily digested.

A branch containing these patches is available in this repo:

  https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git

See the "nfsd4-encoder-overhaul" branch.

---

Chuck Lever (52):
      NFSD: Add simple u32, u64, and bool encoders
      NFSD: Rename nfsd4_encode_bitmap()
      NFSD: Clean up nfsd4_encode_setattr()
      NFSD: Add struct nfsd4_fattr_args
      NFSD: Add nfsd4_encode_fattr4__true()
      NFSD: Add nfsd4_encode_fattr4__false()
      NFSD: Add nfsd4_encode_fattr4_supported_attrs()
      NFSD: Add nfsd4_encode_fattr4_type()
      NFSD: Add nfsd4_encode_fattr4_fh_expire_type()
      NFSD: Add nfsd4_encode_fattr4_change()
      NFSD: Add nfsd4_encode_fattr4_size()
      NFSD: Add nfsd4_encode_fattr4_fsid()
      NFSD: Add nfsd4_encode_fattr4_lease_time()
      NFSD: Add nfsd4_encode_fattr4_rdattr_error()
      NFSD: Add nfsd4_encode_fattr4_aclsupport()
      NFSD: Add nfsd4_encode_nfsace4()
      NFSD: Add nfsd4_encode_fattr4_acl()
      NFSD: Add nfsd4_encode_fattr4_filehandle()
      NFSD: Add nfsd4_encode_fattr4_fileid()
      NFSD: Add nfsd4_encode_fattr4_files_avail()
      NFSD: Add nfsd4_encode_fattr4_files_free()
      NFSD: Add nfsd4_encode_fattr4_files_total()
      NFSD: Add nfsd4_encode_fattr4_fs_locations()
      NFSD: Add nfsd4_encode_fattr4_maxfilesize()
      NFSD: Add nfsd4_encode_fattr4_maxlink()
      NFSD: Add nfsd4_encode_fattr4_maxname()
      NFSD: Add nfsd4_encode_fattr4_maxread()
      NFSD: Add nfsd4_encode_fattr4_maxwrite()
      NFSD: Add nfsd4_encode_fattr4_mode()
      NFSD: Add nfsd4_encode_fattr4_numlinks()
      NFSD: Add nfsd4_encode_fattr4_owner()
      NFSD: Add nfsd4_encode_fattr4_owner_group()
      NFSD: Add nfsd4_encode_fattr4_rawdev()
      NFSD: Add nfsd4_encode_fattr4_space_avail()
      NFSD: Add nfsd4_encode_fattr4_space_free()
      NFSD: Add nfsd4_encode_fattr4_space_total()
      NFSD: Add nfsd4_encode_fattr4_space_used()
      NFSD: Add nfsd4_encode_fattr4_time_access()
      NFSD: Add nfsd4_encode_fattr4_time_create()
      NFSD: Add nfsd4_encode_fattr4_time_delta()
      NFSD: Add nfsd4_encode_fattr4_time_metadata()
      NFSD: Add nfsd4_encode_fattr4_time_modify()
      NFSD: Add nfsd4_encode_fattr4_mounted_on_fileid()
      NFSD: Add nfsd4_encode_fattr4_fs_layout_types()
      NFSD: Add nfsd4_encode_fattr4_layout_types()
      NFSD: Add nfsd4_encode_fattr4_layout_blksize()
      NFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat()
      NFSD: Add nfsd4_encode_fattr4_sec_label()
      NFSD: Add nfsd4_encode_fattr4_xattr_support()
      NFSD: Copy FATTR4 bit number definitions from RFCs
      NFSD: Use a bitmask loop to encode FATTR4 results
      NFSD: Rename nfsd4_encode_fattr()


 fs/nfsd/nfs4xdr.c        | 1419 +++++++++++++++++++++-----------------
 fs/nfsd/nfsfh.c          |    2 +-
 fs/nfsd/nfsfh.h          |    3 +-
 fs/nfsd/xdr4.h           |  119 ++++
 include/linux/iversion.h |    2 +-
 include/linux/nfs4.h     |  260 +++++--
 6 files changed, 1085 insertions(+), 720 deletions(-)

--
Chuck Lever


^ permalink raw reply	[flat|nested] 54+ messages in thread

* [PATCH v1 01/52] NFSD: Add simple u32, u64, and bool encoders
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
@ 2023-09-18 13:56 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 02/52] NFSD: Rename nfsd4_encode_bitmap() Chuck Lever
                   ` (51 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:56 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

The generic XDR encoders return a length or a negative errno. NFSv4
encoders want to know simply whether the encode ran out of stream
buffer space. The return values for server-side encoding are either
nfs_ok or nfserr_resource.

So far I've found it adds a lot of duplicate code to try to use the
generic XDR encoder utilities when encoding the simple data types in
the NFSv4 operation encoders.

Add a set of NFSv4-specific utilities that handle the basic XDR data
types. These are added in xdr4.h so they might eventually be used by
the callback server and pNFS driver encoders too.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/xdr4.h |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)

diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 9d918a79dc16..5c3eb3691f8b 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -50,6 +50,117 @@
 #define HAS_CSTATE_FLAG(c, f) ((c)->sid_flags & (f))
 #define CLEAR_CSTATE_FLAG(c, f) ((c)->sid_flags &= ~(f))
 
+/**
+ * nfsd4_encode_bool - Encode an XDR bool type result
+ * @xdr: target XDR stream
+ * @val: boolean value to encode
+ *
+ * Return values:
+ *    %nfs_ok: @val encoded; @xdr advanced to next position
+ *    %nfserr_resource: stream buffer space exhausted
+ */
+static __always_inline __be32
+nfsd4_encode_bool(struct xdr_stream *xdr, bool val)
+{
+	__be32 *p = xdr_reserve_space(xdr, XDR_UNIT);
+
+	if (unlikely(p == NULL))
+		return nfserr_resource;
+	*p = val ? xdr_one : xdr_zero;
+	return nfs_ok;
+}
+
+/**
+ * nfsd4_encode_uint32_t - Encode an XDR uint32_t type result
+ * @xdr: target XDR stream
+ * @val: integer value to encode
+ *
+ * Return values:
+ *    %nfs_ok: @val encoded; @xdr advanced to next position
+ *    %nfserr_resource: stream buffer space exhausted
+ */
+static __always_inline __be32
+nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
+{
+	__be32 *p = xdr_reserve_space(xdr, XDR_UNIT);
+
+	if (unlikely(p == NULL))
+		return nfserr_resource;
+	*p = cpu_to_be32(val);
+	return nfs_ok;
+}
+
+/**
+ * nfsd4_encode_uint64_t - Encode an XDR uint64_t type result
+ * @xdr: target XDR stream
+ * @val: integer value to encode
+ *
+ * Return values:
+ *    %nfs_ok: @val encoded; @xdr advanced to next position
+ *    %nfserr_resource: stream buffer space exhausted
+ */
+static __always_inline __be32
+nfsd4_encode_uint64_t(struct xdr_stream *xdr, u64 val)
+{
+	__be32 *p = xdr_reserve_space(xdr, XDR_UNIT * 2);
+
+	if (unlikely(p == NULL))
+		return nfserr_resource;
+	put_unaligned_be64(val, p);
+	return nfs_ok;
+}
+
+/**
+ * nfsd4_encode_opaque_fixed - Encode a fixed-length XDR opaque type result
+ * @xdr: target XDR stream
+ * @data: pointer to data
+ * @size: length of data in bytes
+ *
+ * Return values:
+ *    %nfs_ok: @data encoded; @xdr advanced to next position
+ *    %nfserr_resource: stream buffer space exhausted
+ */
+static __always_inline __be32
+nfsd4_encode_opaque_fixed(struct xdr_stream *xdr, const void *data,
+			  size_t size)
+{
+	__be32 *p = xdr_reserve_space(xdr, xdr_align_size(size));
+	size_t pad = xdr_pad_size(size);
+
+	if (unlikely(p == NULL))
+		return nfserr_resource;
+	memcpy(p, data, size);
+	if (pad)
+		memset((char *)p + size, 0, pad);
+	return nfs_ok;
+}
+
+/**
+ * nfsd4_encode_opaque - Encode a variable-length XDR opaque type result
+ * @xdr: target XDR stream
+ * @data: pointer to data
+ * @size: length of data in bytes
+ *
+ * Return values:
+ *    %nfs_ok: @data encoded; @xdr advanced to next position
+ *    %nfserr_resource: stream buffer space exhausted
+ */
+static __always_inline __be32
+nfsd4_encode_opaque(struct xdr_stream *xdr, const void *data, size_t size)
+{
+	size_t pad = xdr_pad_size(size);
+	__be32 *p;
+
+	p = xdr_reserve_space(xdr, XDR_UNIT + xdr_align_size(size));
+	if (unlikely(p == NULL))
+		return nfserr_resource;
+	*p++ = cpu_to_be32(size);
+	memcpy(p, data, size);
+	if (pad)
+		memset((char *)p + size, 0, pad);
+	return nfs_ok;
+}
+
 struct nfsd4_compound_state {
 	struct svc_fh		current_fh;
 	struct svc_fh		save_fh;



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 02/52] NFSD: Rename nfsd4_encode_bitmap()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
  2023-09-18 13:56 ` [PATCH v1 01/52] NFSD: Add simple u32, u64, and bool encoders Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 03/52] NFSD: Clean up nfsd4_encode_setattr() Chuck Lever
                   ` (50 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

For alignment with the specification, the name of NFSD's encoder
function should match the name of the XDR type.

I've also replaced a few "naked integers" with symbolic constants
that better reflect the usage of these values.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 2e40c74d2f72..84df0f36c15b 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2906,12 +2906,12 @@ static int nfsd4_get_mounted_on_ino(struct svc_export *exp, u64 *pino)
 }
 
 static __be32
-nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
+nfsd4_encode_bitmap4(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
 {
 	__be32 *p;
 
 	if (bmval2) {
-		p = xdr_reserve_space(xdr, 16);
+		p = xdr_reserve_space(xdr, XDR_UNIT * 4);
 		if (!p)
 			goto out_resource;
 		*p++ = cpu_to_be32(3);
@@ -2919,21 +2919,21 @@ nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
 		*p++ = cpu_to_be32(bmval1);
 		*p++ = cpu_to_be32(bmval2);
 	} else if (bmval1) {
-		p = xdr_reserve_space(xdr, 12);
+		p = xdr_reserve_space(xdr, XDR_UNIT * 3);
 		if (!p)
 			goto out_resource;
 		*p++ = cpu_to_be32(2);
 		*p++ = cpu_to_be32(bmval0);
 		*p++ = cpu_to_be32(bmval1);
 	} else {
-		p = xdr_reserve_space(xdr, 8);
+		p = xdr_reserve_space(xdr, XDR_UNIT * 2);
 		if (!p)
 			goto out_resource;
 		*p++ = cpu_to_be32(1);
 		*p++ = cpu_to_be32(bmval0);
 	}
 
-	return 0;
+	return nfs_ok;
 out_resource:
 	return nfserr_resource;
 }
@@ -3046,7 +3046,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	}
 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
 
-	status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2);
+	status = nfsd4_encode_bitmap4(xdr, bmval0, bmval1, bmval2);
 	if (status)
 		goto out;
 
@@ -3443,7 +3443,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1;
 		supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2;
 
-		status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]);
+		status = nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
 		if (status)
 			goto out;
 	}
@@ -3802,11 +3802,13 @@ nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr,
 	struct nfsd4_create *create = &u->create;
 	struct xdr_stream *xdr = resp->xdr;
 
+	/* cinfo */
 	nfserr = nfsd4_encode_change_info4(xdr, &create->cr_cinfo);
 	if (nfserr)
 		return nfserr;
-	return nfsd4_encode_bitmap(xdr, create->cr_bmval[0],
-			create->cr_bmval[1], create->cr_bmval[2]);
+	/* attrset */
+	return nfsd4_encode_bitmap4(xdr, create->cr_bmval[0],
+				    create->cr_bmval[1], create->cr_bmval[2]);
 }
 
 static __be32
@@ -3944,8 +3946,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr,
 	if (xdr_stream_encode_u32(xdr, open->op_rflags) < 0)
 		return nfserr_resource;
 
-	nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1],
-					open->op_bmval[2]);
+	nfserr = nfsd4_encode_bitmap4(xdr, open->op_bmval[0],
+				      open->op_bmval[1], open->op_bmval[2]);
 	if (nfserr)
 		return nfserr;
 
@@ -4529,14 +4531,14 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
 		break;
 	case SP4_MACH_CRED:
 		/* spo_must_enforce bitmap: */
-		nfserr = nfsd4_encode_bitmap(xdr,
+		nfserr = nfsd4_encode_bitmap4(xdr,
 					exid->spo_must_enforce[0],
 					exid->spo_must_enforce[1],
 					exid->spo_must_enforce[2]);
 		if (nfserr)
 			return nfserr;
 		/* spo_must_allow bitmap: */
-		nfserr = nfsd4_encode_bitmap(xdr,
+		nfserr = nfsd4_encode_bitmap4(xdr,
 					exid->spo_must_allow[0],
 					exid->spo_must_allow[1],
 					exid->spo_must_allow[2]);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 03/52] NFSD: Clean up nfsd4_encode_setattr()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
  2023-09-18 13:56 ` [PATCH v1 01/52] NFSD: Add simple u32, u64, and bool encoders Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 02/52] NFSD: Rename nfsd4_encode_bitmap() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 04/52] NFSD: Add struct nfsd4_fattr_args Chuck Lever
                   ` (49 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

De-duplicate the encoding of bitmap4 results in
nfsd4_encode_setattr().

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 84df0f36c15b..8715a43a70c4 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -4427,34 +4427,25 @@ nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr,
 	return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp);
 }
 
-/*
- * The SETATTR encode routine is special -- it always encodes a bitmap,
- * regardless of the error status.
- */
 static __be32
 nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr,
 		     union nfsd4_op_u *u)
 {
 	struct nfsd4_setattr *setattr = &u->setattr;
-	struct xdr_stream *xdr = resp->xdr;
-	__be32 *p;
+	__be32 status;
 
-	p = xdr_reserve_space(xdr, 16);
-	if (!p)
-		return nfserr_resource;
-	if (nfserr) {
-		*p++ = cpu_to_be32(3);
-		*p++ = cpu_to_be32(0);
-		*p++ = cpu_to_be32(0);
-		*p++ = cpu_to_be32(0);
-	}
-	else {
-		*p++ = cpu_to_be32(3);
-		*p++ = cpu_to_be32(setattr->sa_bmval[0]);
-		*p++ = cpu_to_be32(setattr->sa_bmval[1]);
-		*p++ = cpu_to_be32(setattr->sa_bmval[2]);
+	switch (nfserr) {
+	case nfs_ok:
+		/* attrsset */
+		status = nfsd4_encode_bitmap4(resp->xdr, setattr->sa_bmval[0],
+					      setattr->sa_bmval[1],
+					      setattr->sa_bmval[2]);
+		break;
+	default:
+		/* attrsset */
+		status = nfsd4_encode_bitmap4(resp->xdr, 0, 0, 0);
 	}
-	return nfserr;
+	return status != nfs_ok ? status : nfserr;
 }
 
 static __be32



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 04/52] NFSD: Add struct nfsd4_fattr_args
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (2 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 03/52] NFSD: Clean up nfsd4_encode_setattr() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 05/52] NFSD: Add nfsd4_encode_fattr4__true() Chuck Lever
                   ` (48 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

I'm about to split nfsd4_encode_fattr() into a number of smaller
functions. Instead of passing a large number of arguments to each of
the smaller functions, create a struct that can gather the common
argument variables into something with a convenient handle on it.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |  111 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 62 insertions(+), 49 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 8715a43a70c4..85466b959c51 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2938,6 +2938,15 @@ nfsd4_encode_bitmap4(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
 	return nfserr_resource;
 }
 
+struct nfsd4_fattr_args {
+	struct svc_fh		*fhp;
+	struct kstat		stat;
+	struct kstatfs		statfs;
+	struct nfs4_acl		*acl;
+	u32			rdattr_err;
+	bool			contextsupport;
+};
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -2948,26 +2957,22 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		struct dentry *dentry, u32 *bmval,
 		struct svc_rqst *rqstp, int ignore_crossmnt)
 {
+	struct nfsd4_fattr_args args;
 	u32 bmval0 = bmval[0];
 	u32 bmval1 = bmval[1];
 	u32 bmval2 = bmval[2];
-	struct kstat stat;
 	struct svc_fh *tempfh = NULL;
-	struct kstatfs statfs;
 	__be32 *p, *attrlen_p;
 	int starting_len = xdr->buf->len;
 	int attrlen_offset;
 	u32 dummy;
 	u64 dummy64;
-	u32 rdattr_err = 0;
 	__be32 status;
 	int err;
-	struct nfs4_acl *acl = NULL;
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
 	void *context = NULL;
 	int contextlen;
 #endif
-	bool contextsupport = false;
 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
 	u32 minorversion = resp->cstate.minorversion;
 	struct path path = {
@@ -2979,8 +2984,10 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
 	BUG_ON(!nfsd_attrs_supported(minorversion, bmval));
 
+	args.rdattr_err = 0;
 	if (exp->ex_fslocs.migrated) {
-		status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err);
+		status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2,
+						&args.rdattr_err);
 		if (status)
 			goto out;
 	}
@@ -2990,19 +2997,20 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 
-	err = vfs_getattr(&path, &stat,
+	err = vfs_getattr(&path, &args.stat,
 			  STATX_BASIC_STATS | STATX_BTIME | STATX_CHANGE_COOKIE,
 			  AT_STATX_SYNC_AS_STAT);
 	if (err)
 		goto out_nfserr;
-	if (!(stat.result_mask & STATX_BTIME))
+
+	if (!(args.stat.result_mask & STATX_BTIME))
 		/* underlying FS does not offer btime so we can't share it */
 		bmval1 &= ~FATTR4_WORD1_TIME_CREATE;
 	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 |
 		       FATTR4_WORD1_SPACE_TOTAL))) {
-		err = vfs_statfs(&path, &statfs);
+		err = vfs_statfs(&path, &args.statfs);
 		if (err)
 			goto out_nfserr;
 	}
@@ -3015,10 +3023,13 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		status = fh_compose(tempfh, exp, dentry, NULL);
 		if (status)
 			goto out;
-		fhp = tempfh;
-	}
+		args.fhp = tempfh;
+	} else
+		args.fhp = fhp;
+
+	args.acl = NULL;
 	if (bmval0 & FATTR4_WORD0_ACL) {
-		err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
+		err = nfsd4_get_nfs4_acl(rqstp, dentry, &args.acl);
 		if (err == -EOPNOTSUPP)
 			bmval0 &= ~FATTR4_WORD0_ACL;
 		else if (err == -EINVAL) {
@@ -3028,6 +3039,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out_nfserr;
 	}
 
+	args.contextsupport = false;
+
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
 	if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) ||
 	     bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
@@ -3036,7 +3049,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 						&context, &contextlen);
 		else
 			err = -EOPNOTSUPP;
-		contextsupport = (err == 0);
+		args.contextsupport = (err == 0);
 		if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
 			if (err == -EOPNOTSUPP)
 				bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL;
@@ -3062,7 +3075,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 
 		if (!IS_POSIXACL(dentry->d_inode))
 			supp[0] &= ~FATTR4_WORD0_ACL;
-		if (!contextsupport)
+		if (!args.contextsupport)
 			supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
 		if (!supp[2]) {
 			p = xdr_reserve_space(xdr, 12);
@@ -3085,7 +3098,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 4);
 		if (!p)
 			goto out_resource;
-		dummy = nfs4_file_type(stat.mode);
+		dummy = nfs4_file_type(args.stat.mode);
 		if (dummy == NF4BAD) {
 			status = nfserr_serverfault;
 			goto out;
@@ -3106,13 +3119,13 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		p = encode_change(p, &stat, d_inode(dentry), exp);
+		p = encode_change(p, &args.stat, d_inode(dentry), exp);
 	}
 	if (bmval0 & FATTR4_WORD0_SIZE) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		p = xdr_encode_hyper(p, stat.size);
+		p = xdr_encode_hyper(p, args.stat.size);
 	}
 	if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
 		p = xdr_reserve_space(xdr, 4);
@@ -3139,16 +3152,16 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		if (exp->ex_fslocs.migrated) {
 			p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR);
 			p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR);
-		} else switch(fsid_source(fhp)) {
+		} else switch (fsid_source(args.fhp)) {
 		case FSIDSOURCE_FSID:
 			p = xdr_encode_hyper(p, (u64)exp->ex_fsid);
 			p = xdr_encode_hyper(p, (u64)0);
 			break;
 		case FSIDSOURCE_DEV:
 			*p++ = cpu_to_be32(0);
-			*p++ = cpu_to_be32(MAJOR(stat.dev));
+			*p++ = cpu_to_be32(MAJOR(args.stat.dev));
 			*p++ = cpu_to_be32(0);
-			*p++ = cpu_to_be32(MINOR(stat.dev));
+			*p++ = cpu_to_be32(MINOR(args.stat.dev));
 			break;
 		case FSIDSOURCE_UUID:
 			p = xdr_encode_opaque_fixed(p, exp->ex_uuid,
@@ -3172,12 +3185,12 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 4);
 		if (!p)
 			goto out_resource;
-		*p++ = cpu_to_be32(rdattr_err);
+		*p++ = cpu_to_be32(args.rdattr_err);
 	}
 	if (bmval0 & FATTR4_WORD0_ACL) {
 		struct nfs4_ace *ace;
 
-		if (acl == NULL) {
+		if (args.acl == NULL) {
 			p = xdr_reserve_space(xdr, 4);
 			if (!p)
 				goto out_resource;
@@ -3188,9 +3201,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 4);
 		if (!p)
 			goto out_resource;
-		*p++ = cpu_to_be32(acl->naces);
+		*p++ = cpu_to_be32(args.acl->naces);
 
-		for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
+		for (ace = args.acl->aces; ace < args.acl->aces + args.acl->naces; ace++) {
 			p = xdr_reserve_space(xdr, 4*3);
 			if (!p)
 				goto out_resource;
@@ -3236,35 +3249,35 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		*p++ = cpu_to_be32(1);
 	}
 	if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
-		p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4);
+		p = xdr_reserve_space(xdr, args.fhp->fh_handle.fh_size + 4);
 		if (!p)
 			goto out_resource;
-		p = xdr_encode_opaque(p, &fhp->fh_handle.fh_raw,
-					fhp->fh_handle.fh_size);
+		p = xdr_encode_opaque(p, &args.fhp->fh_handle.fh_raw,
+					args.fhp->fh_handle.fh_size);
 	}
 	if (bmval0 & FATTR4_WORD0_FILEID) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		p = xdr_encode_hyper(p, stat.ino);
+		p = xdr_encode_hyper(p, args.stat.ino);
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) statfs.f_ffree);
+		p = xdr_encode_hyper(p, (u64) args.statfs.f_ffree);
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_FREE) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) statfs.f_ffree);
+		p = xdr_encode_hyper(p, (u64) args.statfs.f_ffree);
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) statfs.f_files);
+		p = xdr_encode_hyper(p, (u64) args.statfs.f_files);
 	}
 	if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
 		status = nfsd4_encode_fs_locations(xdr, rqstp, exp);
@@ -3293,7 +3306,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 4);
 		if (!p)
 			goto out_resource;
-		*p++ = cpu_to_be32(statfs.f_namelen);
+		*p++ = cpu_to_be32(args.statfs.f_namelen);
 	}
 	if (bmval0 & FATTR4_WORD0_MAXREAD) {
 		p = xdr_reserve_space(xdr, 8);
@@ -3311,7 +3324,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 4);
 		if (!p)
 			goto out_resource;
-		*p++ = cpu_to_be32(stat.mode & S_IALLUGO);
+		*p++ = cpu_to_be32(args.stat.mode & S_IALLUGO);
 	}
 	if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
 		p = xdr_reserve_space(xdr, 4);
@@ -3323,15 +3336,15 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 4);
 		if (!p)
 			goto out_resource;
-		*p++ = cpu_to_be32(stat.nlink);
+		*p++ = cpu_to_be32(args.stat.nlink);
 	}
 	if (bmval1 & FATTR4_WORD1_OWNER) {
-		status = nfsd4_encode_user(xdr, rqstp, stat.uid);
+		status = nfsd4_encode_user(xdr, rqstp, args.stat.uid);
 		if (status)
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
-		status = nfsd4_encode_group(xdr, rqstp, stat.gid);
+		status = nfsd4_encode_group(xdr, rqstp, args.stat.gid);
 		if (status)
 			goto out;
 	}
@@ -3339,44 +3352,44 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		*p++ = cpu_to_be32((u32) MAJOR(stat.rdev));
-		*p++ = cpu_to_be32((u32) MINOR(stat.rdev));
+		*p++ = cpu_to_be32((u32) MAJOR(args.stat.rdev));
+		*p++ = cpu_to_be32((u32) MINOR(args.stat.rdev));
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
+		dummy64 = (u64)args.statfs.f_bavail * (u64)args.statfs.f_bsize;
 		p = xdr_encode_hyper(p, dummy64);
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
+		dummy64 = (u64)args.statfs.f_bfree * (u64)args.statfs.f_bsize;
 		p = xdr_encode_hyper(p, dummy64);
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
+		dummy64 = (u64)args.statfs.f_blocks * (u64)args.statfs.f_bsize;
 		p = xdr_encode_hyper(p, dummy64);
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_USED) {
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
 			goto out_resource;
-		dummy64 = (u64)stat.blocks << 9;
+		dummy64 = (u64)args.stat.blocks << 9;
 		p = xdr_encode_hyper(p, dummy64);
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
-		status = nfsd4_encode_nfstime4(xdr, &stat.atime);
+		status = nfsd4_encode_nfstime4(xdr, &args.stat.atime);
 		if (status)
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_CREATE) {
-		status = nfsd4_encode_nfstime4(xdr, &stat.btime);
+		status = nfsd4_encode_nfstime4(xdr, &args.stat.btime);
 		if (status)
 			goto out;
 	}
@@ -3387,17 +3400,17 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = encode_time_delta(p, d_inode(dentry));
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
-		status = nfsd4_encode_nfstime4(xdr, &stat.ctime);
+		status = nfsd4_encode_nfstime4(xdr, &args.stat.ctime);
 		if (status)
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
-		status = nfsd4_encode_nfstime4(xdr, &stat.mtime);
+		status = nfsd4_encode_nfstime4(xdr, &args.stat.mtime);
 		if (status)
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
-		u64 ino = stat.ino;
+		u64 ino = args.stat.ino;
 
 		p = xdr_reserve_space(xdr, 8);
 		if (!p)
@@ -3432,7 +3445,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_reserve_space(xdr, 4);
 		if (!p)
 			goto out_resource;
-		*p++ = cpu_to_be32(stat.blksize);
+		*p++ = cpu_to_be32(args.stat.blksize);
 	}
 #endif /* CONFIG_NFSD_PNFS */
 	if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
@@ -3473,7 +3486,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	if (context)
 		security_release_secctx(context, contextlen);
 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
-	kfree(acl);
+	kfree(args.acl);
 	if (tempfh) {
 		fh_put(tempfh);
 		kfree(tempfh);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 05/52] NFSD: Add nfsd4_encode_fattr4__true()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (3 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 04/52] NFSD: Add struct nfsd4_fattr_args Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 06/52] NFSD: Add nfsd4_encode_fattr4__false() Chuck Lever
                   ` (47 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Add an encoding helper that encodes a single boolean "true" value.
Attributes that always return "true" can use this helper.

In a subsequent patch, this helper will be called from a bitmask
loop, so it is given a standardized synopsis.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   55 ++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 85466b959c51..ba07e97c206b 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2947,6 +2947,12 @@ struct nfsd4_fattr_args {
 	bool			contextsupport;
 };
 
+static __be32 nfsd4_encode_fattr4__true(struct xdr_stream *xdr,
+					const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_bool(xdr, true);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3128,16 +3134,14 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		p = xdr_encode_hyper(p, args.stat.size);
 	}
 	if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(1);
+		status = nfsd4_encode_fattr4__true(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(1);
+		status = nfsd4_encode_fattr4__true(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
 		p = xdr_reserve_space(xdr, 4);
@@ -3225,10 +3229,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
 	}
 	if (bmval0 & FATTR4_WORD0_CANSETTIME) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(1);
+		status = nfsd4_encode_fattr4__true(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
 		p = xdr_reserve_space(xdr, 4);
@@ -3237,16 +3240,14 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		*p++ = cpu_to_be32(0);
 	}
 	if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(1);
+		status = nfsd4_encode_fattr4__true(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(1);
+		status = nfsd4_encode_fattr4__true(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
 		p = xdr_reserve_space(xdr, args.fhp->fh_handle.fh_size + 4);
@@ -3285,10 +3286,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(1);
+		status = nfsd4_encode_fattr4__true(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
 		p = xdr_reserve_space(xdr, 8);
@@ -3327,10 +3327,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		*p++ = cpu_to_be32(args.stat.mode & S_IALLUGO);
 	}
 	if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(1);
+		status = nfsd4_encode_fattr4__true(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_NUMLINKS) {
 		p = xdr_reserve_space(xdr, 4);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 06/52] NFSD: Add nfsd4_encode_fattr4__false()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (4 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 05/52] NFSD: Add nfsd4_encode_fattr4__true() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 07/52] NFSD: Add nfsd4_encode_fattr4_supported_attrs() Chuck Lever
                   ` (46 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Add an encoding helper that encodes a single boolean "false" value.
Attributes that always return "false" can use this helper.

In a subsequent patch, this helper will be called from a bitmask
loop, so it is given a standardized synopsis.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index ba07e97c206b..91f3b03f297b 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2953,6 +2953,12 @@ static __be32 nfsd4_encode_fattr4__true(struct xdr_stream *xdr,
 	return nfsd4_encode_bool(xdr, true);
 }
 
+static __be32 nfsd4_encode_fattr4__false(struct xdr_stream *xdr,
+					 const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_bool(xdr, false);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3144,10 +3150,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(0);
+		status = nfsd4_encode_fattr4__false(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FSID) {
 		p = xdr_reserve_space(xdr, 16);
@@ -3174,10 +3179,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		}
 	}
 	if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(0);
+		status = nfsd4_encode_fattr4__false(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
 		p = xdr_reserve_space(xdr, 4);
@@ -3234,10 +3238,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(0);
+		status = nfsd4_encode_fattr4__false(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
 		status = nfsd4_encode_fattr4__true(xdr, &args);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 07/52] NFSD: Add nfsd4_encode_fattr4_supported_attrs()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (5 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 06/52] NFSD: Add nfsd4_encode_fattr4__false() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 08/52] NFSD: Add nfsd4_encode_fattr4_type() Chuck Lever
                   ` (45 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SUPPORTED_ATTRS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 91f3b03f297b..da5df33cac04 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2939,7 +2939,9 @@ nfsd4_encode_bitmap4(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
 }
 
 struct nfsd4_fattr_args {
+	struct svc_rqst		*rqstp;
 	struct svc_fh		*fhp;
+	struct dentry		*dentry;
 	struct kstat		stat;
 	struct kstatfs		statfs;
 	struct nfs4_acl		*acl;
@@ -2959,6 +2961,22 @@ static __be32 nfsd4_encode_fattr4__false(struct xdr_stream *xdr,
 	return nfsd4_encode_bool(xdr, false);
 }
 
+static __be32 nfsd4_encode_fattr4_supported_attrs(struct xdr_stream *xdr,
+						  const struct nfsd4_fattr_args *args)
+{
+	struct nfsd4_compoundres *resp = args->rqstp->rq_resp;
+	u32 minorversion = resp->cstate.minorversion;
+	u32 supp[3];
+
+	memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp));
+	if (!IS_POSIXACL(d_inode(args->dentry)))
+		supp[0] &= ~FATTR4_WORD0_ACL;
+	if (!args->contextsupport)
+		supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
+
+	return nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -2996,6 +3014,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
 	BUG_ON(!nfsd_attrs_supported(minorversion, bmval));
 
+	args.rqstp = rqstp;
+	args.dentry = dentry;
+
 	args.rdattr_err = 0;
 	if (exp->ex_fslocs.migrated) {
 		status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2,
@@ -3081,30 +3102,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		goto out_resource;
 
 	if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
-		u32 supp[3];
-
-		memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp));
-
-		if (!IS_POSIXACL(dentry->d_inode))
-			supp[0] &= ~FATTR4_WORD0_ACL;
-		if (!args.contextsupport)
-			supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
-		if (!supp[2]) {
-			p = xdr_reserve_space(xdr, 12);
-			if (!p)
-				goto out_resource;
-			*p++ = cpu_to_be32(2);
-			*p++ = cpu_to_be32(supp[0]);
-			*p++ = cpu_to_be32(supp[1]);
-		} else {
-			p = xdr_reserve_space(xdr, 16);
-			if (!p)
-				goto out_resource;
-			*p++ = cpu_to_be32(3);
-			*p++ = cpu_to_be32(supp[0]);
-			*p++ = cpu_to_be32(supp[1]);
-			*p++ = cpu_to_be32(supp[2]);
-		}
+		status = nfsd4_encode_fattr4_supported_attrs(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_TYPE) {
 		p = xdr_reserve_space(xdr, 4);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 08/52] NFSD: Add nfsd4_encode_fattr4_type()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (6 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 07/52] NFSD: Add nfsd4_encode_fattr4_supported_attrs() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 09/52] NFSD: Add nfsd4_encode_fattr4_fh_expire_type() Chuck Lever
                   ` (44 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_TYPE into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

In addition, restructure the code so that byte-swapping is done on
constant values rather than at run time. Run-time swapping can be
costly on some platforms, and "type" is a frequently-requested
attribute.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   63 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index da5df33cac04..c1dc6810f043 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2792,20 +2792,6 @@ static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr,
 	return 0;
 }
 
-static u32 nfs4_file_type(umode_t mode)
-{
-	switch (mode & S_IFMT) {
-	case S_IFIFO:	return NF4FIFO;
-	case S_IFCHR:	return NF4CHR;
-	case S_IFDIR:	return NF4DIR;
-	case S_IFBLK:	return NF4BLK;
-	case S_IFLNK:	return NF4LNK;
-	case S_IFREG:	return NF4REG;
-	case S_IFSOCK:	return NF4SOCK;
-	default:	return NF4BAD;
-	}
-}
-
 static inline __be32
 nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp,
 		     struct nfs4_ace *ace)
@@ -2977,6 +2963,44 @@ static __be32 nfsd4_encode_fattr4_supported_attrs(struct xdr_stream *xdr,
 	return nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
 }
 
+static __be32 nfsd4_encode_fattr4_type(struct xdr_stream *xdr,
+				       const struct nfsd4_fattr_args *args)
+{
+	__be32 *p;
+
+	p = xdr_reserve_space(xdr, XDR_UNIT);
+	if (!p)
+		return nfserr_resource;
+
+	switch (args->stat.mode & S_IFMT) {
+	case S_IFIFO:
+		*p = cpu_to_be32(NF4FIFO);
+		break;
+	case S_IFCHR:
+		*p = cpu_to_be32(NF4CHR);
+		break;
+	case S_IFDIR:
+		*p = cpu_to_be32(NF4DIR);
+		break;
+	case S_IFBLK:
+		*p = cpu_to_be32(NF4BLK);
+		break;
+	case S_IFLNK:
+		*p = cpu_to_be32(NF4LNK);
+		break;
+	case S_IFREG:
+		*p = cpu_to_be32(NF4REG);
+		break;
+	case S_IFSOCK:
+		*p = cpu_to_be32(NF4SOCK);
+		break;
+	default:
+		return nfserr_serverfault;
+	}
+
+	return nfs_ok;
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -2995,7 +3019,6 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	__be32 *p, *attrlen_p;
 	int starting_len = xdr->buf->len;
 	int attrlen_offset;
-	u32 dummy;
 	u64 dummy64;
 	__be32 status;
 	int err;
@@ -3107,15 +3130,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_TYPE) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		dummy = nfs4_file_type(args.stat.mode);
-		if (dummy == NF4BAD) {
-			status = nfserr_serverfault;
+		status = nfsd4_encode_fattr4_type(xdr, &args);
+		if (status != nfs_ok)
 			goto out;
-		}
-		*p++ = cpu_to_be32(dummy);
 	}
 	if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
 		p = xdr_reserve_space(xdr, 4);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 09/52] NFSD: Add nfsd4_encode_fattr4_fh_expire_type()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (7 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 08/52] NFSD: Add nfsd4_encode_fattr4_type() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 10/52] NFSD: Add nfsd4_encode_fattr4_change() Chuck Lever
                   ` (43 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FH_EXPIRE_TYPE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index c1dc6810f043..e7f1a856fb0b 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2927,6 +2927,7 @@ nfsd4_encode_bitmap4(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
 struct nfsd4_fattr_args {
 	struct svc_rqst		*rqstp;
 	struct svc_fh		*fhp;
+	struct svc_export	*exp;
 	struct dentry		*dentry;
 	struct kstat		stat;
 	struct kstatfs		statfs;
@@ -3001,6 +3002,17 @@ static __be32 nfsd4_encode_fattr4_type(struct xdr_stream *xdr,
 	return nfs_ok;
 }
 
+static __be32 nfsd4_encode_fattr4_fh_expire_type(struct xdr_stream *xdr,
+						 const struct nfsd4_fattr_args *args)
+{
+	u32 mask;
+
+	mask = NFS4_FH_PERSISTENT;
+	if (!(args->exp->ex_flags & NFSEXP_NOSUBTREECHECK))
+		mask |= NFS4_FH_VOL_RENAME;
+	return nfsd4_encode_uint32_t(xdr, mask);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3038,6 +3050,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	BUG_ON(!nfsd_attrs_supported(minorversion, bmval));
 
 	args.rqstp = rqstp;
+	args.exp = exp;
 	args.dentry = dentry;
 
 	args.rdattr_err = 0;
@@ -3135,14 +3148,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
-			*p++ = cpu_to_be32(NFS4_FH_PERSISTENT);
-		else
-			*p++ = cpu_to_be32(NFS4_FH_PERSISTENT|
-						NFS4_FH_VOL_RENAME);
+		status = nfsd4_encode_fattr4_fh_expire_type(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_CHANGE) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 10/52] NFSD: Add nfsd4_encode_fattr4_change()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (8 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 09/52] NFSD: Add nfsd4_encode_fattr4_fh_expire_type() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:57 ` [PATCH v1 11/52] NFSD: Add nfsd4_encode_fattr4_size() Chuck Lever
                   ` (42 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_CHANGE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

The code is restructured a bit to use the modern xdr_stream flow,
and the encoded cinfo value is made const so that callers of the
encoders can be passed a const cinfo.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c        |   56 +++++++++++++++++++++++++++-------------------
 fs/nfsd/nfsfh.c          |    2 +-
 fs/nfsd/nfsfh.h          |    3 ++
 fs/nfsd/xdr4.h           |    2 ++
 include/linux/iversion.h |    2 +-
 5 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index e7f1a856fb0b..3149cfcdac35 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2530,17 +2530,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
 	return true;
 }
 
-static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
-			     struct svc_export *exp)
-{
-	if (exp->ex_flags & NFSEXP_V4ROOT) {
-		*p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time));
-		*p++ = 0;
-	} else
-		p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode));
-	return p;
-}
-
 static __be32 nfsd4_encode_nfstime4(struct xdr_stream *xdr,
 				    struct timespec64 *tv)
 {
@@ -2581,15 +2570,17 @@ static __be32 *encode_time_delta(__be32 *p, struct inode *inode)
 }
 
 static __be32
-nfsd4_encode_change_info4(struct xdr_stream *xdr, struct nfsd4_change_info *c)
+nfsd4_encode_change_info4(struct xdr_stream *xdr, const struct nfsd4_change_info *c)
 {
-	if (xdr_stream_encode_bool(xdr, c->atomic) < 0)
-		return nfserr_resource;
-	if (xdr_stream_encode_u64(xdr, c->before_change) < 0)
-		return nfserr_resource;
-	if (xdr_stream_encode_u64(xdr, c->after_change) < 0)
-		return nfserr_resource;
-	return nfs_ok;
+	__be32 status;
+
+	status = nfsd4_encode_bool(xdr, c->atomic);
+	if (status != nfs_ok)
+		return status;
+	status = nfsd4_encode_changeid4(xdr, c->before_change);
+	if (status != nfs_ok)
+		return status;
+	return nfsd4_encode_changeid4(xdr, c->after_change);
 }
 
 /* Encode as an array of strings the string given with components
@@ -3013,6 +3004,26 @@ static __be32 nfsd4_encode_fattr4_fh_expire_type(struct xdr_stream *xdr,
 	return nfsd4_encode_uint32_t(xdr, mask);
 }
 
+static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr,
+					 const struct nfsd4_fattr_args *args)
+{
+	const struct svc_export *exp = args->exp;
+	u64 c;
+
+	if (unlikely(exp->ex_flags & NFSEXP_V4ROOT)) {
+		u32 flush_time = convert_to_wallclock(exp->cd->flush_time);
+
+		if (xdr_stream_encode_u32(xdr, flush_time) != XDR_UNIT)
+			return nfserr_resource;
+		if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
+			return nfserr_resource;
+		return nfs_ok;
+	}
+
+	c = nfsd4_change_attribute(&args->stat, d_inode(args->dentry));
+	return nfsd4_encode_changeid4(xdr, c);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3153,10 +3164,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_CHANGE) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = encode_change(p, &args.stat, d_inode(dentry), exp);
+		status = nfsd4_encode_fattr4_change(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_SIZE) {
 		p = xdr_reserve_space(xdr, 8);
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index 355bf0db3235..dbfa0ac13564 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -771,7 +771,7 @@ enum fsid_source fsid_source(const struct svc_fh *fhp)
  * assume that the new change attr is always logged to stable storage in some
  * fashion before the results can be seen.
  */
-u64 nfsd4_change_attribute(struct kstat *stat, struct inode *inode)
+u64 nfsd4_change_attribute(const struct kstat *stat, const struct inode *inode)
 {
 	u64 chattr;
 
diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
index 40426f899e76..6ebdf7ea27bf 100644
--- a/fs/nfsd/nfsfh.h
+++ b/fs/nfsd/nfsfh.h
@@ -293,7 +293,8 @@ static inline void fh_clear_pre_post_attrs(struct svc_fh *fhp)
 	fhp->fh_pre_saved = false;
 }
 
-u64 nfsd4_change_attribute(struct kstat *stat, struct inode *inode);
+u64 nfsd4_change_attribute(const struct kstat *stat,
+			   const struct inode *inode);
 __be32 __must_check fh_fill_pre_attrs(struct svc_fh *fhp);
 __be32 fh_fill_post_attrs(struct svc_fh *fhp);
 __be32 __must_check fh_fill_both_attrs(struct svc_fh *fhp);
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 5c3eb3691f8b..d6059b0549f5 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -110,6 +110,8 @@ nfsd4_encode_uint64_t(struct xdr_stream *xdr, u64 val)
 	return nfs_ok;
 }
 
+#define nfsd4_encode_changeid4(x, v)	nfsd4_encode_uint64_t(x, v)
+
 /**
  * nfsd4_encode_opaque_fixed - Encode a fixed-length XDR opaque type result
  * @xdr: target XDR stream
diff --git a/include/linux/iversion.h b/include/linux/iversion.h
index f174ff1b59ee..8f972eaca2ed 100644
--- a/include/linux/iversion.h
+++ b/include/linux/iversion.h
@@ -256,7 +256,7 @@ inode_peek_iversion(const struct inode *inode)
  * For filesystems without any sort of change attribute, the best we can
  * do is fake one up from the ctime:
  */
-static inline u64 time_to_chattr(struct timespec64 *t)
+static inline u64 time_to_chattr(const struct timespec64 *t)
 {
 	u64 chattr = t->tv_sec;
 



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 11/52] NFSD: Add nfsd4_encode_fattr4_size()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (9 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 10/52] NFSD: Add nfsd4_encode_fattr4_change() Chuck Lever
@ 2023-09-18 13:57 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 12/52] NFSD: Add nfsd4_encode_fattr4_fsid() Chuck Lever
                   ` (41 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:57 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SIZE into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 3149cfcdac35..601b3a0e61d4 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3024,6 +3024,12 @@ static __be32 nfsd4_encode_fattr4_change(struct xdr_stream *xdr,
 	return nfsd4_encode_changeid4(xdr, c);
 }
 
+static __be32 nfsd4_encode_fattr4_size(struct xdr_stream *xdr,
+				       const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, args->stat.size);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3169,10 +3175,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_SIZE) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, args.stat.size);
+		status = nfsd4_encode_fattr4_size(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
 		status = nfsd4_encode_fattr4__true(xdr, &args);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 12/52] NFSD: Add nfsd4_encode_fattr4_fsid()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (10 preceding siblings ...)
  2023-09-18 13:57 ` [PATCH v1 11/52] NFSD: Add nfsd4_encode_fattr4_size() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 13/52] NFSD: Add nfsd4_encode_fattr4_lease_time() Chuck Lever
                   ` (40 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FSID into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   58 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 22 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 601b3a0e61d4..b41bc1b0c12c 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3030,6 +3030,39 @@ static __be32 nfsd4_encode_fattr4_size(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, args->stat.size);
 }
 
+static __be32 nfsd4_encode_fattr4_fsid(struct xdr_stream *xdr,
+				       const struct nfsd4_fattr_args *args)
+{
+	__be32 *p;
+
+	p = xdr_reserve_space(xdr, XDR_UNIT * 2 + XDR_UNIT * 2);
+	if (!p)
+		return nfserr_resource;
+
+	if (unlikely(args->exp->ex_fslocs.migrated)) {
+		p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR);
+		xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR);
+		return nfs_ok;
+	}
+	switch (fsid_source(args->fhp)) {
+	case FSIDSOURCE_FSID:
+		p = xdr_encode_hyper(p, (u64)args->exp->ex_fsid);
+		xdr_encode_hyper(p, (u64)0);
+		break;
+	case FSIDSOURCE_DEV:
+		*p++ = xdr_zero;
+		*p++ = cpu_to_be32(MAJOR(args->stat.dev));
+		*p++ = xdr_zero;
+		*p   = cpu_to_be32(MINOR(args->stat.dev));
+		break;
+	case FSIDSOURCE_UUID:
+		xdr_encode_opaque_fixed(p, args->exp->ex_uuid, EX_UUID_LEN);
+		break;
+	}
+
+	return nfs_ok;
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3195,28 +3228,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FSID) {
-		p = xdr_reserve_space(xdr, 16);
-		if (!p)
-			goto out_resource;
-		if (exp->ex_fslocs.migrated) {
-			p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR);
-			p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR);
-		} else switch (fsid_source(args.fhp)) {
-		case FSIDSOURCE_FSID:
-			p = xdr_encode_hyper(p, (u64)exp->ex_fsid);
-			p = xdr_encode_hyper(p, (u64)0);
-			break;
-		case FSIDSOURCE_DEV:
-			*p++ = cpu_to_be32(0);
-			*p++ = cpu_to_be32(MAJOR(args.stat.dev));
-			*p++ = cpu_to_be32(0);
-			*p++ = cpu_to_be32(MINOR(args.stat.dev));
-			break;
-		case FSIDSOURCE_UUID:
-			p = xdr_encode_opaque_fixed(p, exp->ex_uuid,
-								EX_UUID_LEN);
-			break;
-		}
+		status = nfsd4_encode_fattr4_fsid(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
 		status = nfsd4_encode_fattr4__false(xdr, &args);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 13/52] NFSD: Add nfsd4_encode_fattr4_lease_time()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (11 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 12/52] NFSD: Add nfsd4_encode_fattr4_fsid() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 14/52] NFSD: Add nfsd4_encode_fattr4_rdattr_error() Chuck Lever
                   ` (39 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_LEASE_TIME into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   16 +++++++++++-----
 fs/nfsd/xdr4.h    |    2 ++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index b41bc1b0c12c..15a07f7d9b38 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3063,6 +3063,14 @@ static __be32 nfsd4_encode_fattr4_fsid(struct xdr_stream *xdr,
 	return nfs_ok;
 }
 
+static __be32 nfsd4_encode_fattr4_lease_time(struct xdr_stream *xdr,
+					     const struct nfsd4_fattr_args *args)
+{
+	struct nfsd_net *nn = net_generic(SVC_NET(args->rqstp), nfsd_net_id);
+
+	return nfsd4_encode_nfs_lease4(xdr, nn->nfsd4_lease);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3094,7 +3102,6 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		.mnt	= exp->ex_path.mnt,
 		.dentry	= dentry,
 	};
-	struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
 	BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
 	BUG_ON(!nfsd_attrs_supported(minorversion, bmval));
@@ -3238,10 +3245,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(nn->nfsd4_lease);
+		status = nfsd4_encode_fattr4_lease_time(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
 		p = xdr_reserve_space(xdr, 4);
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index d6059b0549f5..488ecdacc4c6 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -90,6 +90,8 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
 	return nfs_ok;
 }
 
+#define nfsd4_encode_nfs_lease4(x, v)	nfsd4_encode_uint32_t(x, v)
+
 /**
  * nfsd4_encode_uint64_t - Encode an XDR uint64_t type result
  * @xdr: target XDR stream



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 14/52] NFSD: Add nfsd4_encode_fattr4_rdattr_error()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (12 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 13/52] NFSD: Add nfsd4_encode_fattr4_lease_time() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 15/52] NFSD: Add nfsd4_encode_fattr4_aclsupport() Chuck Lever
                   ` (38 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_RDATTR_ERROR into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 15a07f7d9b38..c67b5d942390 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3071,6 +3071,12 @@ static __be32 nfsd4_encode_fattr4_lease_time(struct xdr_stream *xdr,
 	return nfsd4_encode_nfs_lease4(xdr, nn->nfsd4_lease);
 }
 
+static __be32 nfsd4_encode_fattr4_rdattr_error(struct xdr_stream *xdr,
+					       const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint32_t(xdr, args->rdattr_err);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3250,10 +3256,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(args.rdattr_err);
+		status = nfsd4_encode_fattr4_rdattr_error(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_ACL) {
 		struct nfs4_ace *ace;



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 15/52] NFSD: Add nfsd4_encode_fattr4_aclsupport()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (13 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 14/52] NFSD: Add nfsd4_encode_fattr4_rdattr_error() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 16/52] NFSD: Add nfsd4_encode_nfsace4() Chuck Lever
                   ` (37 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_ACLSUPPORT into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index c67b5d942390..6604763bd96c 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3077,6 +3077,17 @@ static __be32 nfsd4_encode_fattr4_rdattr_error(struct xdr_stream *xdr,
 	return nfsd4_encode_uint32_t(xdr, args->rdattr_err);
 }
 
+static __be32 nfsd4_encode_fattr4_aclsupport(struct xdr_stream *xdr,
+					     const struct nfsd4_fattr_args *args)
+{
+	u32 mask;
+
+	mask = 0;
+	if (IS_POSIXACL(d_inode(args->dentry)))
+		mask = ACL4_SUPPORT_ALLOW_ACL | ACL4_SUPPORT_DENY_ACL;
+	return nfsd4_encode_uint32_t(xdr, mask);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3291,11 +3302,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	}
 out_acl:
 	if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ?
-			ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
+		status = nfsd4_encode_fattr4_aclsupport(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_CANSETTIME) {
 		status = nfsd4_encode_fattr4__true(xdr, &args);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 16/52] NFSD: Add nfsd4_encode_nfsace4()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (14 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 15/52] NFSD: Add nfsd4_encode_fattr4_aclsupport() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 17/52] NFSD: Add nfsd4_encode_fattr4_acl() Chuck Lever
                   ` (36 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the ACE encoding helper so that it can eventually be reused
for encoding OPEN results that contain delegation ACEs.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   36 +++++++++++++++++++++---------------
 fs/nfsd/xdr4.h    |    3 +++
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 6604763bd96c..89d3b276a494 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2783,16 +2783,29 @@ static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr,
 	return 0;
 }
 
-static inline __be32
-nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp,
-		     struct nfs4_ace *ace)
+static __be32 nfsd4_encode_nfsace4(struct xdr_stream *xdr, struct svc_rqst *rqstp,
+				   struct nfs4_ace *ace)
 {
+	__be32 status;
+
+	/* type */
+	status = nfsd4_encode_acetype4(xdr, ace->type);
+	if (status != nfs_ok)
+		return nfserr_resource;
+	/* flag */
+	status = nfsd4_encode_aceflag4(xdr, ace->flag);
+	if (status != nfs_ok)
+		return nfserr_resource;
+	/* access mask */
+	status = nfsd4_encode_acemask4(xdr, ace->access_mask & NFS4_ACE_MASK_ALL);
+	if (status != nfs_ok)
+		return nfserr_resource;
+	/* who */
 	if (ace->whotype != NFS4_ACL_WHO_NAMED)
 		return nfs4_acl_write_who(xdr, ace->whotype);
-	else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
+	if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
 		return nfsd4_encode_group(xdr, rqstp, ace->who_gid);
-	else
-		return nfsd4_encode_user(xdr, rqstp, ace->who_uid);
+	return nfsd4_encode_user(xdr, rqstp, ace->who_uid);
 }
 
 static inline __be32
@@ -3288,15 +3301,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		*p++ = cpu_to_be32(args.acl->naces);
 
 		for (ace = args.acl->aces; ace < args.acl->aces + args.acl->naces; ace++) {
-			p = xdr_reserve_space(xdr, 4*3);
-			if (!p)
-				goto out_resource;
-			*p++ = cpu_to_be32(ace->type);
-			*p++ = cpu_to_be32(ace->flag);
-			*p++ = cpu_to_be32(ace->access_mask &
-							NFS4_ACE_MASK_ALL);
-			status = nfsd4_encode_aclname(xdr, rqstp, ace);
-			if (status)
+			status = nfsd4_encode_nfsace4(xdr, args.rqstp, ace);
+			if (status != nfs_ok)
 				goto out;
 		}
 	}
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 488ecdacc4c6..f0866a55fd91 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -90,6 +90,9 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
 	return nfs_ok;
 }
 
+#define nfsd4_encode_aceflag4(x, v)	nfsd4_encode_uint32_t(x, v)
+#define nfsd4_encode_acemask4(x, v)	nfsd4_encode_uint32_t(x, v)
+#define nfsd4_encode_acetype4(x, v)	nfsd4_encode_uint32_t(x, v)
 #define nfsd4_encode_nfs_lease4(x, v)	nfsd4_encode_uint32_t(x, v)
 
 /**



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 17/52] NFSD: Add nfsd4_encode_fattr4_acl()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (15 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 16/52] NFSD: Add nfsd4_encode_nfsace4() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 18/52] NFSD: Add nfsd4_encode_fattr4_filehandle() Chuck Lever
                   ` (35 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_ACL into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   47 ++++++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 89d3b276a494..5e91ed6ae0f7 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3101,6 +3101,29 @@ static __be32 nfsd4_encode_fattr4_aclsupport(struct xdr_stream *xdr,
 	return nfsd4_encode_uint32_t(xdr, mask);
 }
 
+static __be32 nfsd4_encode_fattr4_acl(struct xdr_stream *xdr,
+				      const struct nfsd4_fattr_args *args)
+{
+	struct nfs4_acl *acl = args->acl;
+	struct nfs4_ace *ace;
+	__be32 status;
+
+	/* nfsace4<> */
+	if (!acl) {
+		if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
+			return nfserr_resource;
+	} else {
+		if (xdr_stream_encode_u32(xdr, acl->naces) != XDR_UNIT)
+			return nfserr_resource;
+		for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
+			status = nfsd4_encode_nfsace4(xdr, args->rqstp, ace);
+			if (status != nfs_ok)
+				return status;
+		}
+	}
+	return nfs_ok;
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3285,28 +3308,10 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_ACL) {
-		struct nfs4_ace *ace;
-
-		if (args.acl == NULL) {
-			p = xdr_reserve_space(xdr, 4);
-			if (!p)
-				goto out_resource;
-
-			*p++ = cpu_to_be32(0);
-			goto out_acl;
-		}
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(args.acl->naces);
-
-		for (ace = args.acl->aces; ace < args.acl->aces + args.acl->naces; ace++) {
-			status = nfsd4_encode_nfsace4(xdr, args.rqstp, ace);
-			if (status != nfs_ok)
-				goto out;
-		}
+		status = nfsd4_encode_fattr4_acl(xdr, &args);
+		if (status)
+			goto out;
 	}
-out_acl:
 	if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
 		status = nfsd4_encode_fattr4_aclsupport(xdr, &args);
 		if (status != nfs_ok)



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 18/52] NFSD: Add nfsd4_encode_fattr4_filehandle()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (16 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 17/52] NFSD: Add nfsd4_encode_fattr4_acl() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 19/52] NFSD: Add nfsd4_encode_fattr4_fileid() Chuck Lever
                   ` (34 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FILEHANDLE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

We can de-duplicate the other filehandle encoder (in GETFH) using
our new helper.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 5e91ed6ae0f7..17997bf08139 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2530,6 +2530,12 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
 	return true;
 }
 
+static __be32 nfsd4_encode_nfs_fh4(struct xdr_stream *xdr,
+				   struct knfsd_fh *fh_handle)
+{
+	return nfsd4_encode_opaque(xdr, fh_handle->fh_raw, fh_handle->fh_size);
+}
+
 static __be32 nfsd4_encode_nfstime4(struct xdr_stream *xdr,
 				    struct timespec64 *tv)
 {
@@ -3124,6 +3130,12 @@ static __be32 nfsd4_encode_fattr4_acl(struct xdr_stream *xdr,
 	return nfs_ok;
 }
 
+static __be32 nfsd4_encode_fattr4_filehandle(struct xdr_stream *xdr,
+					     const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_nfs_fh4(xdr, &args->fhp->fh_handle);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3338,11 +3350,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
-		p = xdr_reserve_space(xdr, args.fhp->fh_handle.fh_size + 4);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_opaque(p, &args.fhp->fh_handle.fh_raw,
-					args.fhp->fh_handle.fh_size);
+		status = nfsd4_encode_fattr4_filehandle(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILEID) {
 		p = xdr_reserve_space(xdr, 8);
@@ -3927,18 +3937,11 @@ static __be32
 nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr,
 		   union nfsd4_op_u *u)
 {
-	struct svc_fh **fhpp = &u->getfh;
 	struct xdr_stream *xdr = resp->xdr;
-	struct svc_fh *fhp = *fhpp;
-	unsigned int len;
-	__be32 *p;
+	struct svc_fh *fhp = u->getfh;
 
-	len = fhp->fh_handle.fh_size;
-	p = xdr_reserve_space(xdr, len + 4);
-	if (!p)
-		return nfserr_resource;
-	p = xdr_encode_opaque(p, &fhp->fh_handle.fh_raw, len);
-	return 0;
+	/* object */
+	return nfsd4_encode_nfs_fh4(xdr, &fhp->fh_handle);
 }
 
 /*



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 19/52] NFSD: Add nfsd4_encode_fattr4_fileid()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (17 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 18/52] NFSD: Add nfsd4_encode_fattr4_filehandle() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:58 ` [PATCH v1 20/52] NFSD: Add nfsd4_encode_fattr4_files_avail() Chuck Lever
                   ` (33 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FILEID into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 17997bf08139..e3dd05f8d28f 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3136,6 +3136,12 @@ static __be32 nfsd4_encode_fattr4_filehandle(struct xdr_stream *xdr,
 	return nfsd4_encode_nfs_fh4(xdr, &args->fhp->fh_handle);
 }
 
+static __be32 nfsd4_encode_fattr4_fileid(struct xdr_stream *xdr,
+					 const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, args->stat.ino);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3355,10 +3361,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILEID) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, args.stat.ino);
+		status = nfsd4_encode_fattr4_fileid(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 20/52] NFSD: Add nfsd4_encode_fattr4_files_avail()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (18 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 19/52] NFSD: Add nfsd4_encode_fattr4_fileid() Chuck Lever
@ 2023-09-18 13:58 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 21/52] NFSD: Add nfsd4_encode_fattr4_files_free() Chuck Lever
                   ` (32 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:58 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FILES_AVAIL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index e3dd05f8d28f..737c13c4bf82 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3142,6 +3142,12 @@ static __be32 nfsd4_encode_fattr4_fileid(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, args->stat.ino);
 }
 
+static __be32 nfsd4_encode_fattr4_files_avail(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, args->statfs.f_ffree);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3366,10 +3372,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) args.statfs.f_ffree);
+		status = nfsd4_encode_fattr4_files_avail(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_FREE) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 21/52] NFSD: Add nfsd4_encode_fattr4_files_free()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (19 preceding siblings ...)
  2023-09-18 13:58 ` [PATCH v1 20/52] NFSD: Add nfsd4_encode_fattr4_files_avail() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 22/52] NFSD: Add nfsd4_encode_fattr4_files_total() Chuck Lever
                   ` (31 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FILES_FREE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 737c13c4bf82..ee5fd6ff12e0 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3148,6 +3148,12 @@ static __be32 nfsd4_encode_fattr4_files_avail(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, args->statfs.f_ffree);
 }
 
+static __be32 nfsd4_encode_fattr4_files_free(struct xdr_stream *xdr,
+					     const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, args->statfs.f_ffree);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3377,10 +3383,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_FREE) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) args.statfs.f_ffree);
+		status = nfsd4_encode_fattr4_files_free(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 22/52] NFSD: Add nfsd4_encode_fattr4_files_total()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (20 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 21/52] NFSD: Add nfsd4_encode_fattr4_files_free() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 23/52] NFSD: Add nfsd4_encode_fattr4_fs_locations() Chuck Lever
                   ` (30 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FILES_TOTAL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index ee5fd6ff12e0..e024742abc73 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3154,6 +3154,12 @@ static __be32 nfsd4_encode_fattr4_files_free(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, args->statfs.f_ffree);
 }
 
+static __be32 nfsd4_encode_fattr4_files_total(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, args->statfs.f_files);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3388,10 +3394,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) args.statfs.f_files);
+		status = nfsd4_encode_fattr4_files_total(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
 		status = nfsd4_encode_fs_locations(xdr, rqstp, exp);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 23/52] NFSD: Add nfsd4_encode_fattr4_fs_locations()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (21 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 22/52] NFSD: Add nfsd4_encode_fattr4_files_total() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 24/52] NFSD: Add nfsd4_encode_fattr4_maxfilesize() Chuck Lever
                   ` (29 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FS_LOCATIONS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   66 ++++++++++++++++++++++-------------------------------
 1 file changed, 28 insertions(+), 38 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index e024742abc73..f247fd6f02f5 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2658,9 +2658,6 @@ static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep,
 	return nfsd4_encode_components_esc(xdr, sep, components, 0, 0);
 }
 
-/*
- * encode a location element of a fs_locations structure
- */
 static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr,
 					struct nfsd4_fs_location *location)
 {
@@ -2673,15 +2670,12 @@ static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr,
 	status = nfsd4_encode_components(xdr, '/', location->path);
 	if (status)
 		return status;
-	return 0;
+	return nfs_ok;
 }
 
-/*
- * Encode a path in RFC3530 'pathname4' format
- */
-static __be32 nfsd4_encode_path(struct xdr_stream *xdr,
-				const struct path *root,
-				const struct path *path)
+static __be32 nfsd4_encode_pathname4(struct xdr_stream *xdr,
+				     const struct path *root,
+				     const struct path *path)
 {
 	struct path cur = *path;
 	__be32 *p;
@@ -2749,44 +2743,34 @@ static __be32 nfsd4_encode_path(struct xdr_stream *xdr,
 	return err;
 }
 
-static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr,
-			struct svc_rqst *rqstp, const struct path *path)
+static __be32 nfsd4_encode_fs_locations4(struct xdr_stream *xdr,
+					 struct svc_rqst *rqstp,
+					 struct svc_export *exp)
 {
+	struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
 	struct svc_export *exp_ps;
-	__be32 res;
+	unsigned int i;
+	__be32 status;
 
+	/* fs_root */
 	exp_ps = rqst_find_fsidzero_export(rqstp);
 	if (IS_ERR(exp_ps))
 		return nfserrno(PTR_ERR(exp_ps));
-	res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path);
+	status = nfsd4_encode_pathname4(xdr, &exp_ps->ex_path, &exp->ex_path);
 	exp_put(exp_ps);
-	return res;
-}
-
-/*
- *  encode a fs_locations structure
- */
-static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr,
-			struct svc_rqst *rqstp, struct svc_export *exp)
-{
-	__be32 status;
-	int i;
-	__be32 *p;
-	struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
-
-	status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path);
-	if (status)
+	if (status != nfs_ok)
 		return status;
-	p = xdr_reserve_space(xdr, 4);
-	if (!p)
+
+	/* locations<> */
+	if (xdr_stream_encode_u32(xdr, fslocs->locations_count) != XDR_UNIT)
 		return nfserr_resource;
-	*p++ = cpu_to_be32(fslocs->locations_count);
-	for (i=0; i<fslocs->locations_count; i++) {
+	for (i = 0; i < fslocs->locations_count; i++) {
 		status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]);
-		if (status)
+		if (status != nfs_ok)
 			return status;
 	}
-	return 0;
+
+	return nfs_ok;
 }
 
 static __be32 nfsd4_encode_nfsace4(struct xdr_stream *xdr, struct svc_rqst *rqstp,
@@ -3160,6 +3144,12 @@ static __be32 nfsd4_encode_fattr4_files_total(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, args->statfs.f_files);
 }
 
+static __be32 nfsd4_encode_fattr4_fs_locations(struct xdr_stream *xdr,
+					       const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_fs_locations4(xdr, args->rqstp, args->exp);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3399,8 +3389,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
-		status = nfsd4_encode_fs_locations(xdr, rqstp, exp);
-		if (status)
+		status = nfsd4_encode_fattr4_fs_locations(xdr, &args);
+		if (status != nfs_ok)
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 24/52] NFSD: Add nfsd4_encode_fattr4_maxfilesize()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (22 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 23/52] NFSD: Add nfsd4_encode_fattr4_fs_locations() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 25/52] NFSD: Add nfsd4_encode_fattr4_maxlink() Chuck Lever
                   ` (28 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_MAXFILESIZE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index f247fd6f02f5..eb7bc713f85c 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3150,6 +3150,14 @@ static __be32 nfsd4_encode_fattr4_fs_locations(struct xdr_stream *xdr,
 	return nfsd4_encode_fs_locations4(xdr, args->rqstp, args->exp);
 }
 
+static __be32 nfsd4_encode_fattr4_maxfilesize(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	struct super_block *sb = args->exp->ex_path.mnt->mnt_sb;
+
+	return nfsd4_encode_uint64_t(xdr, sb->s_maxbytes);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3399,10 +3407,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, exp->ex_path.mnt->mnt_sb->s_maxbytes);
+		status = nfsd4_encode_fattr4_maxfilesize(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXLINK) {
 		p = xdr_reserve_space(xdr, 4);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 25/52] NFSD: Add nfsd4_encode_fattr4_maxlink()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (23 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 24/52] NFSD: Add nfsd4_encode_fattr4_maxfilesize() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 26/52] NFSD: Add nfsd4_encode_fattr4_maxname() Chuck Lever
                   ` (27 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_MAXLINK into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index eb7bc713f85c..05d3b4409d03 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3158,6 +3158,12 @@ static __be32 nfsd4_encode_fattr4_maxfilesize(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, sb->s_maxbytes);
 }
 
+static __be32 nfsd4_encode_fattr4_maxlink(struct xdr_stream *xdr,
+					  const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint32_t(xdr, 255);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3412,10 +3418,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXLINK) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(255);
+		status = nfsd4_encode_fattr4_maxlink(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXNAME) {
 		p = xdr_reserve_space(xdr, 4);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 26/52] NFSD: Add nfsd4_encode_fattr4_maxname()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (24 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 25/52] NFSD: Add nfsd4_encode_fattr4_maxlink() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 27/52] NFSD: Add nfsd4_encode_fattr4_maxread() Chuck Lever
                   ` (26 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_MAXNAME into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 05d3b4409d03..546879759c71 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3164,6 +3164,12 @@ static __be32 nfsd4_encode_fattr4_maxlink(struct xdr_stream *xdr,
 	return nfsd4_encode_uint32_t(xdr, 255);
 }
 
+static __be32 nfsd4_encode_fattr4_maxname(struct xdr_stream *xdr,
+					  const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint32_t(xdr, args->statfs.f_namelen);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3423,10 +3429,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXNAME) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(args.statfs.f_namelen);
+		status = nfsd4_encode_fattr4_maxname(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXREAD) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 27/52] NFSD: Add nfsd4_encode_fattr4_maxread()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (25 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 26/52] NFSD: Add nfsd4_encode_fattr4_maxname() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 28/52] NFSD: Add nfsd4_encode_fattr4_maxwrite() Chuck Lever
                   ` (25 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_MAXREAD into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 546879759c71..35911ecccfbd 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3170,6 +3170,12 @@ static __be32 nfsd4_encode_fattr4_maxname(struct xdr_stream *xdr,
 	return nfsd4_encode_uint32_t(xdr, args->statfs.f_namelen);
 }
 
+static __be32 nfsd4_encode_fattr4_maxread(struct xdr_stream *xdr,
+					  const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, svc_max_payload(args->rqstp));
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3434,10 +3440,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXREAD) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp));
+		status = nfsd4_encode_fattr4_maxread(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXWRITE) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 28/52] NFSD: Add nfsd4_encode_fattr4_maxwrite()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (26 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 27/52] NFSD: Add nfsd4_encode_fattr4_maxread() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 29/52] NFSD: Add nfsd4_encode_fattr4_mode() Chuck Lever
                   ` (24 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_MAXWRITE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 35911ecccfbd..39ff6d1bd41d 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3176,6 +3176,12 @@ static __be32 nfsd4_encode_fattr4_maxread(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, svc_max_payload(args->rqstp));
 }
 
+static __be32 nfsd4_encode_fattr4_maxwrite(struct xdr_stream *xdr,
+					   const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, svc_max_payload(args->rqstp));
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3445,10 +3451,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval0 & FATTR4_WORD0_MAXWRITE) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp));
+		status = nfsd4_encode_fattr4_maxwrite(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_MODE) {
 		p = xdr_reserve_space(xdr, 4);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 29/52] NFSD: Add nfsd4_encode_fattr4_mode()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (27 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 28/52] NFSD: Add nfsd4_encode_fattr4_maxwrite() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 13:59 ` [PATCH v1 30/52] NFSD: Add nfsd4_encode_fattr4_numlinks() Chuck Lever
                   ` (23 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_MODE into a helper. In a subsequent
patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 fs/nfsd/xdr4.h    |    1 +
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 39ff6d1bd41d..91f5f154428b 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3182,6 +3182,12 @@ static __be32 nfsd4_encode_fattr4_maxwrite(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, svc_max_payload(args->rqstp));
 }
 
+static __be32 nfsd4_encode_fattr4_mode(struct xdr_stream *xdr,
+				       const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_mode4(xdr, args->stat.mode & S_IALLUGO);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3456,10 +3462,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_MODE) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(args.stat.mode & S_IALLUGO);
+		status = nfsd4_encode_fattr4_mode(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
 		status = nfsd4_encode_fattr4__true(xdr, &args);
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index f0866a55fd91..52322acc1e9f 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -93,6 +93,7 @@ nfsd4_encode_uint32_t(struct xdr_stream *xdr, u32 val)
 #define nfsd4_encode_aceflag4(x, v)	nfsd4_encode_uint32_t(x, v)
 #define nfsd4_encode_acemask4(x, v)	nfsd4_encode_uint32_t(x, v)
 #define nfsd4_encode_acetype4(x, v)	nfsd4_encode_uint32_t(x, v)
+#define nfsd4_encode_mode4(x, v)	nfsd4_encode_uint32_t(x, v)
 #define nfsd4_encode_nfs_lease4(x, v)	nfsd4_encode_uint32_t(x, v)
 
 /**



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 30/52] NFSD: Add nfsd4_encode_fattr4_numlinks()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (28 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 29/52] NFSD: Add nfsd4_encode_fattr4_mode() Chuck Lever
@ 2023-09-18 13:59 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 31/52] NFSD: Add nfsd4_encode_fattr4_owner() Chuck Lever
                   ` (22 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 13:59 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_NUMLINKS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 91f5f154428b..e3d9ec44c817 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3188,6 +3188,12 @@ static __be32 nfsd4_encode_fattr4_mode(struct xdr_stream *xdr,
 	return nfsd4_encode_mode4(xdr, args->stat.mode & S_IALLUGO);
 }
 
+static __be32 nfsd4_encode_fattr4_numlinks(struct xdr_stream *xdr,
+					   const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint32_t(xdr, args->stat.nlink);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3472,10 +3478,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_NUMLINKS) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(args.stat.nlink);
+		status = nfsd4_encode_fattr4_numlinks(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_OWNER) {
 		status = nfsd4_encode_user(xdr, rqstp, args.stat.uid);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 31/52] NFSD: Add nfsd4_encode_fattr4_owner()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (29 preceding siblings ...)
  2023-09-18 13:59 ` [PATCH v1 30/52] NFSD: Add nfsd4_encode_fattr4_numlinks() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 32/52] NFSD: Add nfsd4_encode_fattr4_owner_group() Chuck Lever
                   ` (21 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_OWNER into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index e3d9ec44c817..11922b18f357 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3194,6 +3194,12 @@ static __be32 nfsd4_encode_fattr4_numlinks(struct xdr_stream *xdr,
 	return nfsd4_encode_uint32_t(xdr, args->stat.nlink);
 }
 
+static __be32 nfsd4_encode_fattr4_owner(struct xdr_stream *xdr,
+					const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_user(xdr, args->rqstp, args->stat.uid);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3483,8 +3489,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_OWNER) {
-		status = nfsd4_encode_user(xdr, rqstp, args.stat.uid);
-		if (status)
+		status = nfsd4_encode_fattr4_owner(xdr, &args);
+		if (status != nfs_ok)
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 32/52] NFSD: Add nfsd4_encode_fattr4_owner_group()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (30 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 31/52] NFSD: Add nfsd4_encode_fattr4_owner() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 33/52] NFSD: Add nfsd4_encode_fattr4_rawdev() Chuck Lever
                   ` (20 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_OWNER_GROUP into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 11922b18f357..91ac991dea9d 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3200,6 +3200,12 @@ static __be32 nfsd4_encode_fattr4_owner(struct xdr_stream *xdr,
 	return nfsd4_encode_user(xdr, args->rqstp, args->stat.uid);
 }
 
+static __be32 nfsd4_encode_fattr4_owner_group(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_group(xdr, args->rqstp, args->stat.gid);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3494,8 +3500,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
-		status = nfsd4_encode_group(xdr, rqstp, args.stat.gid);
-		if (status)
+		status = nfsd4_encode_fattr4_owner_group(xdr, &args);
+		if (status != nfs_ok)
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_RAWDEV) {



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 33/52] NFSD: Add nfsd4_encode_fattr4_rawdev()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (31 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 32/52] NFSD: Add nfsd4_encode_fattr4_owner_group() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 34/52] NFSD: Add nfsd4_encode_fattr4_space_avail() Chuck Lever
                   ` (19 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_RAWDEV into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 91ac991dea9d..146ac641ef8e 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2550,6 +2550,17 @@ static __be32 nfsd4_encode_nfstime4(struct xdr_stream *xdr,
 	return nfs_ok;
 }
 
+static __be32 nfsd4_encode_specdata4(struct xdr_stream *xdr,
+				     unsigned int major, unsigned int minor)
+{
+	__be32 status;
+
+	status = nfsd4_encode_uint32_t(xdr, major);
+	if (status != nfs_ok)
+		return status;
+	return nfsd4_encode_uint32_t(xdr, minor);
+}
+
 /*
  * ctime (in NFSv4, time_metadata) is not writeable, and the client
  * doesn't really care what resolution could theoretically be stored by
@@ -3206,6 +3217,13 @@ static __be32 nfsd4_encode_fattr4_owner_group(struct xdr_stream *xdr,
 	return nfsd4_encode_group(xdr, args->rqstp, args->stat.gid);
 }
 
+static __be32 nfsd4_encode_fattr4_rawdev(struct xdr_stream *xdr,
+					 const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_specdata4(xdr, MAJOR(args->stat.rdev),
+				      MINOR(args->stat.rdev));
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3505,11 +3523,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_RAWDEV) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32((u32) MAJOR(args.stat.rdev));
-		*p++ = cpu_to_be32((u32) MINOR(args.stat.rdev));
+		status = nfsd4_encode_fattr4_rawdev(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 34/52] NFSD: Add nfsd4_encode_fattr4_space_avail()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (32 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 33/52] NFSD: Add nfsd4_encode_fattr4_rawdev() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 35/52] NFSD: Add nfsd4_encode_fattr4_space_free() Chuck Lever
                   ` (18 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SPACE_AVAIL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 146ac641ef8e..42ce95b8db43 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3224,6 +3224,14 @@ static __be32 nfsd4_encode_fattr4_rawdev(struct xdr_stream *xdr,
 				      MINOR(args->stat.rdev));
 }
 
+static __be32 nfsd4_encode_fattr4_space_avail(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	u64 avail = (u64)args->statfs.f_bavail * (u64)args->statfs.f_bsize;
+
+	return nfsd4_encode_uint64_t(xdr, avail);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3528,11 +3536,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		dummy64 = (u64)args.statfs.f_bavail * (u64)args.statfs.f_bsize;
-		p = xdr_encode_hyper(p, dummy64);
+		status = nfsd4_encode_fattr4_space_avail(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 35/52] NFSD: Add nfsd4_encode_fattr4_space_free()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (33 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 34/52] NFSD: Add nfsd4_encode_fattr4_space_avail() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 36/52] NFSD: Add nfsd4_encode_fattr4_space_total() Chuck Lever
                   ` (17 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SPACE_FREE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 42ce95b8db43..a9f99f07c904 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3232,6 +3232,14 @@ static __be32 nfsd4_encode_fattr4_space_avail(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, avail);
 }
 
+static __be32 nfsd4_encode_fattr4_space_free(struct xdr_stream *xdr,
+					     const struct nfsd4_fattr_args *args)
+{
+	u64 free = (u64)args->statfs.f_bfree * (u64)args->statfs.f_bsize;
+
+	return nfsd4_encode_uint64_t(xdr, free);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3541,11 +3549,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		dummy64 = (u64)args.statfs.f_bfree * (u64)args.statfs.f_bsize;
-		p = xdr_encode_hyper(p, dummy64);
+		status = nfsd4_encode_fattr4_space_free(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 36/52] NFSD: Add nfsd4_encode_fattr4_space_total()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (34 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 35/52] NFSD: Add nfsd4_encode_fattr4_space_free() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 37/52] NFSD: Add nfsd4_encode_fattr4_space_used() Chuck Lever
                   ` (16 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SPACE_TOTAL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index a9f99f07c904..963fa2ccadd7 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3240,6 +3240,14 @@ static __be32 nfsd4_encode_fattr4_space_free(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, free);
 }
 
+static __be32 nfsd4_encode_fattr4_space_total(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	u64 total = (u64)args->statfs.f_blocks * (u64)args->statfs.f_bsize;
+
+	return nfsd4_encode_uint64_t(xdr, total);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3554,11 +3562,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		dummy64 = (u64)args.statfs.f_blocks * (u64)args.statfs.f_bsize;
-		p = xdr_encode_hyper(p, dummy64);
+		status = nfsd4_encode_fattr4_space_total(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_USED) {
 		p = xdr_reserve_space(xdr, 8);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 37/52] NFSD: Add nfsd4_encode_fattr4_space_used()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (35 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 36/52] NFSD: Add nfsd4_encode_fattr4_space_total() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 38/52] NFSD: Add nfsd4_encode_fattr4_time_access() Chuck Lever
                   ` (15 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SPACE_USED into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 963fa2ccadd7..80be20217402 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3248,6 +3248,12 @@ static __be32 nfsd4_encode_fattr4_space_total(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, total);
 }
 
+static __be32 nfsd4_encode_fattr4_space_used(struct xdr_stream *xdr,
+					     const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint64_t(xdr, (u64)args->stat.blocks << 9);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3266,7 +3272,6 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	__be32 *p, *attrlen_p;
 	int starting_len = xdr->buf->len;
 	int attrlen_offset;
-	u64 dummy64;
 	__be32 status;
 	int err;
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
@@ -3567,11 +3572,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_SPACE_USED) {
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-			goto out_resource;
-		dummy64 = (u64)args.stat.blocks << 9;
-		p = xdr_encode_hyper(p, dummy64);
+		status = nfsd4_encode_fattr4_space_used(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
 		status = nfsd4_encode_nfstime4(xdr, &args.stat.atime);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 38/52] NFSD: Add nfsd4_encode_fattr4_time_access()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (36 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 37/52] NFSD: Add nfsd4_encode_fattr4_space_used() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:00 ` [PATCH v1 39/52] NFSD: Add nfsd4_encode_fattr4_time_create() Chuck Lever
                   ` (14 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_TIME_ACCESS into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 80be20217402..214e2fdcbd89 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2536,16 +2536,16 @@ static __be32 nfsd4_encode_nfs_fh4(struct xdr_stream *xdr,
 	return nfsd4_encode_opaque(xdr, fh_handle->fh_raw, fh_handle->fh_size);
 }
 
+/* This is a frequently-encoded type; open-coded for speed */
 static __be32 nfsd4_encode_nfstime4(struct xdr_stream *xdr,
-				    struct timespec64 *tv)
+				    const struct timespec64 *tv)
 {
 	__be32 *p;
 
 	p = xdr_reserve_space(xdr, XDR_UNIT * 3);
 	if (!p)
 		return nfserr_resource;
-
-	p = xdr_encode_hyper(p, (s64)tv->tv_sec);
+	p = xdr_encode_hyper(p, tv->tv_sec);
 	*p = cpu_to_be32(tv->tv_nsec);
 	return nfs_ok;
 }
@@ -3254,6 +3254,12 @@ static __be32 nfsd4_encode_fattr4_space_used(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, (u64)args->stat.blocks << 9);
 }
 
+static __be32 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_nfstime4(xdr, &args->stat.atime);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3577,7 +3583,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
-		status = nfsd4_encode_nfstime4(xdr, &args.stat.atime);
+		status = nfsd4_encode_fattr4_time_access(xdr, &args);
 		if (status)
 			goto out;
 	}



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 39/52] NFSD: Add nfsd4_encode_fattr4_time_create()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (37 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 38/52] NFSD: Add nfsd4_encode_fattr4_time_access() Chuck Lever
@ 2023-09-18 14:00 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 40/52] NFSD: Add nfsd4_encode_fattr4_time_delta() Chuck Lever
                   ` (13 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:00 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_TIME_CREATE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 214e2fdcbd89..5a98dc3910ef 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3260,6 +3260,12 @@ static __be32 nfsd4_encode_fattr4_time_access(struct xdr_stream *xdr,
 	return nfsd4_encode_nfstime4(xdr, &args->stat.atime);
 }
 
+static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3588,7 +3594,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_CREATE) {
-		status = nfsd4_encode_nfstime4(xdr, &args.stat.btime);
+		status = nfsd4_encode_fattr4_time_create(xdr, &args);
 		if (status)
 			goto out;
 	}



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 40/52] NFSD: Add nfsd4_encode_fattr4_time_delta()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (38 preceding siblings ...)
  2023-09-18 14:00 ` [PATCH v1 39/52] NFSD: Add nfsd4_encode_fattr4_time_create() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 41/52] NFSD: Add nfsd4_encode_fattr4_time_metadata() Chuck Lever
                   ` (12 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_TIME_DELTA into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

fattr4_time_delta is specified as an nfstime4, so de-duplicate this
encoder.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   53 ++++++++++++++++++++++++-----------------------------
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 5a98dc3910ef..28eb777f82d2 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2561,31 +2561,6 @@ static __be32 nfsd4_encode_specdata4(struct xdr_stream *xdr,
 	return nfsd4_encode_uint32_t(xdr, minor);
 }
 
-/*
- * ctime (in NFSv4, time_metadata) is not writeable, and the client
- * doesn't really care what resolution could theoretically be stored by
- * the filesystem.
- *
- * The client cares how close together changes can be while still
- * guaranteeing ctime changes.  For most filesystems (which have
- * timestamps with nanosecond fields) that is limited by the resolution
- * of the time returned from current_time() (which I'm assuming to be
- * 1/HZ).
- */
-static __be32 *encode_time_delta(__be32 *p, struct inode *inode)
-{
-	struct timespec64 ts;
-	u32 ns;
-
-	ns = max_t(u32, NSEC_PER_SEC/HZ, inode->i_sb->s_time_gran);
-	ts = ns_to_timespec64(ns);
-
-	p = xdr_encode_hyper(p, ts.tv_sec);
-	*p++ = cpu_to_be32(ts.tv_nsec);
-
-	return p;
-}
-
 static __be32
 nfsd4_encode_change_info4(struct xdr_stream *xdr, const struct nfsd4_change_info *c)
 {
@@ -3266,6 +3241,27 @@ static __be32 nfsd4_encode_fattr4_time_create(struct xdr_stream *xdr,
 	return nfsd4_encode_nfstime4(xdr, &args->stat.btime);
 }
 
+/*
+ * ctime (in NFSv4, time_metadata) is not writeable, and the client
+ * doesn't really care what resolution could theoretically be stored by
+ * the filesystem.
+ *
+ * The client cares how close together changes can be while still
+ * guaranteeing ctime changes.  For most filesystems (which have
+ * timestamps with nanosecond fields) that is limited by the resolution
+ * of the time returned from current_time() (which I'm assuming to be
+ * 1/HZ).
+ */
+static __be32 nfsd4_encode_fattr4_time_delta(struct xdr_stream *xdr,
+					     const struct nfsd4_fattr_args *args)
+{
+	const struct inode *inode = d_inode(args->dentry);
+	u32 ns = max_t(u32, NSEC_PER_SEC/HZ, inode->i_sb->s_time_gran);
+	struct timespec64 ts = ns_to_timespec64(ns);
+
+	return nfsd4_encode_nfstime4(xdr, &ts);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3599,10 +3595,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
-		p = xdr_reserve_space(xdr, 12);
-		if (!p)
-			goto out_resource;
-		p = encode_time_delta(p, d_inode(dentry));
+		status = nfsd4_encode_fattr4_time_delta(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
 		status = nfsd4_encode_nfstime4(xdr, &args.stat.ctime);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 41/52] NFSD: Add nfsd4_encode_fattr4_time_metadata()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (39 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 40/52] NFSD: Add nfsd4_encode_fattr4_time_delta() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 42/52] NFSD: Add nfsd4_encode_fattr4_time_modify() Chuck Lever
                   ` (11 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_TIME_METADATA into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 28eb777f82d2..75121b4a6020 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3262,6 +3262,12 @@ static __be32 nfsd4_encode_fattr4_time_delta(struct xdr_stream *xdr,
 	return nfsd4_encode_nfstime4(xdr, &ts);
 }
 
+static __be32 nfsd4_encode_fattr4_time_metadata(struct xdr_stream *xdr,
+						const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_nfstime4(xdr, &args->stat.ctime);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3600,7 +3606,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
-		status = nfsd4_encode_nfstime4(xdr, &args.stat.ctime);
+		status = nfsd4_encode_fattr4_time_metadata(xdr, &args);
 		if (status)
 			goto out;
 	}



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 42/52] NFSD: Add nfsd4_encode_fattr4_time_modify()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (40 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 41/52] NFSD: Add nfsd4_encode_fattr4_time_metadata() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 43/52] NFSD: Add nfsd4_encode_fattr4_mounted_on_fileid() Chuck Lever
                   ` (10 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_TIME_MODIFY into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 75121b4a6020..730596c53258 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3268,6 +3268,12 @@ static __be32 nfsd4_encode_fattr4_time_metadata(struct xdr_stream *xdr,
 	return nfsd4_encode_nfstime4(xdr, &args->stat.ctime);
 }
 
+static __be32 nfsd4_encode_fattr4_time_modify(struct xdr_stream *xdr,
+					      const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_nfstime4(xdr, &args->stat.mtime);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3611,7 +3617,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
-		status = nfsd4_encode_nfstime4(xdr, &args.stat.mtime);
+		status = nfsd4_encode_fattr4_time_modify(xdr, &args);
 		if (status)
 			goto out;
 	}



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 43/52] NFSD: Add nfsd4_encode_fattr4_mounted_on_fileid()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (41 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 42/52] NFSD: Add nfsd4_encode_fattr4_time_modify() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 44/52] NFSD: Add nfsd4_encode_fattr4_fs_layout_types() Chuck Lever
                   ` (9 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_MOUNTED_ON_FILEID into a helper. In
a subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 730596c53258..929be84482b9 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2914,6 +2914,7 @@ struct nfsd4_fattr_args {
 	struct nfs4_acl		*acl;
 	u32			rdattr_err;
 	bool			contextsupport;
+	bool			ignore_crossmnt;
 };
 
 static __be32 nfsd4_encode_fattr4__true(struct xdr_stream *xdr,
@@ -3274,6 +3275,23 @@ static __be32 nfsd4_encode_fattr4_time_modify(struct xdr_stream *xdr,
 	return nfsd4_encode_nfstime4(xdr, &args->stat.mtime);
 }
 
+static __be32 nfsd4_encode_fattr4_mounted_on_fileid(struct xdr_stream *xdr,
+						    const struct nfsd4_fattr_args *args)
+{
+	u64 ino;
+	int err;
+
+	if (!args->ignore_crossmnt &&
+	    args->dentry == args->exp->ex_path.mnt->mnt_root) {
+		err = nfsd4_get_mounted_on_ino(args->exp, &ino);
+		if (err)
+			return nfserrno(err);
+	} else
+		ino = args->stat.ino;
+
+	return nfsd4_encode_uint64_t(xdr, ino);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3311,6 +3329,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	args.rqstp = rqstp;
 	args.exp = exp;
 	args.dentry = dentry;
+	args.ignore_crossmnt = (ignore_crossmnt != 0);
 
 	args.rdattr_err = 0;
 	if (exp->ex_fslocs.migrated) {
@@ -3622,23 +3641,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 			goto out;
 	}
 	if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
-		u64 ino = args.stat.ino;
-
-		p = xdr_reserve_space(xdr, 8);
-		if (!p)
-                	goto out_resource;
-		/*
-		 * Get ino of mountpoint in parent filesystem, if not ignoring
-		 * crossmount and this is the root of a cross-mounted
-		 * filesystem.
-		 */
-		if (ignore_crossmnt == 0 &&
-		    dentry == exp->ex_path.mnt->mnt_root) {
-			err = nfsd4_get_mounted_on_ino(exp, &ino);
-			if (err)
-				goto out_nfserr;
-		}
-		p = xdr_encode_hyper(p, ino);
+		status = nfsd4_encode_fattr4_mounted_on_fileid(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 #ifdef CONFIG_NFSD_PNFS
 	if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) {



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 44/52] NFSD: Add nfsd4_encode_fattr4_fs_layout_types()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (42 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 43/52] NFSD: Add nfsd4_encode_fattr4_mounted_on_fileid() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 45/52] NFSD: Add nfsd4_encode_fattr4_layout_types() Chuck Lever
                   ` (8 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_FS_LAYOUT_TYPES into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 929be84482b9..d67fa4b2a2f6 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3292,6 +3292,28 @@ static __be32 nfsd4_encode_fattr4_mounted_on_fileid(struct xdr_stream *xdr,
 	return nfsd4_encode_uint64_t(xdr, ino);
 }
 
+#ifdef CONFIG_NFSD_PNFS
+
+static __be32 nfsd4_encode_fattr4_fs_layout_types(struct xdr_stream *xdr,
+						  const struct nfsd4_fattr_args *args)
+{
+	unsigned long mask = args->exp->ex_layout_types;
+	int i;
+
+	/* Hamming weight of @mask is the number of layout types to return */
+	if (xdr_stream_encode_u32(xdr, hweight_long(mask)) != XDR_UNIT)
+		return nfserr_resource;
+	for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i)
+		if (mask & BIT(i)) {
+			/* layouttype4 */
+			if (xdr_stream_encode_u32(xdr, i) != XDR_UNIT)
+				return nfserr_resource;
+		}
+	return nfs_ok;
+}
+
+#endif
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3647,7 +3669,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	}
 #ifdef CONFIG_NFSD_PNFS
 	if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) {
-		status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types);
+		status = nfsd4_encode_fattr4_fs_layout_types(xdr, &args);
 		if (status)
 			goto out;
 	}



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 45/52] NFSD: Add nfsd4_encode_fattr4_layout_types()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (43 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 44/52] NFSD: Add nfsd4_encode_fattr4_fs_layout_types() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 46/52] NFSD: Add nfsd4_encode_fattr4_layout_blksize() Chuck Lever
                   ` (7 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_LAYOUT_TYPES into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index d67fa4b2a2f6..bc0b5bc3e655 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2784,25 +2784,6 @@ static __be32 nfsd4_encode_nfsace4(struct xdr_stream *xdr, struct svc_rqst *rqst
 	return nfsd4_encode_user(xdr, rqstp, ace->who_uid);
 }
 
-static inline __be32
-nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types)
-{
-	__be32		*p;
-	unsigned long	i = hweight_long(layout_types);
-
-	p = xdr_reserve_space(xdr, 4 + 4 * i);
-	if (!p)
-		return nfserr_resource;
-
-	*p++ = cpu_to_be32(i);
-
-	for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i)
-		if (layout_types & (1 << i))
-			*p++ = cpu_to_be32(i);
-
-	return 0;
-}
-
 #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
 			      FATTR4_WORD0_RDATTR_ERROR)
 #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
@@ -3312,6 +3293,24 @@ static __be32 nfsd4_encode_fattr4_fs_layout_types(struct xdr_stream *xdr,
 	return nfs_ok;
 }
 
+static __be32 nfsd4_encode_fattr4_layout_types(struct xdr_stream *xdr,
+					       const struct nfsd4_fattr_args *args)
+{
+	unsigned long mask = args->exp->ex_layout_types;
+	int i;
+
+	/* Hamming weight of @mask is the number of layout types to return */
+	if (xdr_stream_encode_u32(xdr, hweight_long(mask)) != XDR_UNIT)
+		return nfserr_resource;
+	for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i)
+		if (mask & BIT(i)) {
+			/* layouttype4 */
+			if (xdr_stream_encode_u32(xdr, i) != XDR_UNIT)
+				return nfserr_resource;
+		}
+	return nfs_ok;
+}
+
 #endif
 
 /*
@@ -3675,7 +3674,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	}
 
 	if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) {
-		status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types);
+		status = nfsd4_encode_fattr4_layout_types(xdr, &args);
 		if (status)
 			goto out;
 	}



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 46/52] NFSD: Add nfsd4_encode_fattr4_layout_blksize()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (44 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 45/52] NFSD: Add nfsd4_encode_fattr4_layout_types() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 47/52] NFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat() Chuck Lever
                   ` (6 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_LAYOUT_BLKSIZE into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index bc0b5bc3e655..aca0301dc949 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3311,6 +3311,12 @@ static __be32 nfsd4_encode_fattr4_layout_types(struct xdr_stream *xdr,
 	return nfs_ok;
 }
 
+static __be32 nfsd4_encode_fattr4_layout_blksize(struct xdr_stream *xdr,
+						 const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_uint32_t(xdr, args->stat.blksize);
+}
+
 #endif
 
 /*
@@ -3680,10 +3686,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	}
 
 	if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		*p++ = cpu_to_be32(args.stat.blksize);
+		status = nfsd4_encode_fattr4_layout_blksize(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 #endif /* CONFIG_NFSD_PNFS */
 	if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 47/52] NFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (45 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 46/52] NFSD: Add nfsd4_encode_fattr4_layout_blksize() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 48/52] NFSD: Add nfsd4_encode_fattr4_sec_label() Chuck Lever
                   ` (5 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SUPPATTR_EXCLCREAT into a helper. In
a subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index aca0301dc949..02a28d07d6e4 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3319,6 +3319,20 @@ static __be32 nfsd4_encode_fattr4_layout_blksize(struct xdr_stream *xdr,
 
 #endif
 
+static __be32 nfsd4_encode_fattr4_suppattr_exclcreat(struct xdr_stream *xdr,
+						     const struct nfsd4_fattr_args *args)
+{
+	struct nfsd4_compoundres *resp = args->rqstp->rq_resp;
+	u32 supp[3];
+
+	memcpy(supp, nfsd_suppattrs[resp->cstate.minorversion], sizeof(supp));
+	supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0;
+	supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1;
+	supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2;
+
+	return nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3692,14 +3706,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	}
 #endif /* CONFIG_NFSD_PNFS */
 	if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
-		u32 supp[3];
-
-		memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp));
-		supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0;
-		supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1;
-		supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2;
-
-		status = nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
+		status = nfsd4_encode_fattr4_suppattr_exclcreat(xdr, &args);
 		if (status)
 			goto out;
 	}



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 48/52] NFSD: Add nfsd4_encode_fattr4_sec_label()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (46 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 47/52] NFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:01 ` [PATCH v1 49/52] NFSD: Add nfsd4_encode_fattr4_xattr_support() Chuck Lever
                   ` (4 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_SEC_LABEL into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 02a28d07d6e4..137e7368dbfd 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2893,6 +2893,10 @@ struct nfsd4_fattr_args {
 	struct kstat		stat;
 	struct kstatfs		statfs;
 	struct nfs4_acl		*acl;
+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
+	void			*context;
+	int			contextlen;
+#endif
 	u32			rdattr_err;
 	bool			contextsupport;
 	bool			ignore_crossmnt;
@@ -3333,6 +3337,15 @@ static __be32 nfsd4_encode_fattr4_suppattr_exclcreat(struct xdr_stream *xdr,
 	return nfsd4_encode_bitmap4(xdr, supp[0], supp[1], supp[2]);
 }
 
+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
+static __be32 nfsd4_encode_fattr4_sec_label(struct xdr_stream *xdr,
+					    const struct nfsd4_fattr_args *args)
+{
+	return nfsd4_encode_security_label(xdr, args->rqstp,
+					   args->context, args->contextlen);
+}
+#endif
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3353,10 +3366,6 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	int attrlen_offset;
 	__be32 status;
 	int err;
-#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
-	void *context = NULL;
-	int contextlen;
-#endif
 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
 	u32 minorversion = resp->cstate.minorversion;
 	struct path path = {
@@ -3430,11 +3439,12 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	args.contextsupport = false;
 
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
+	args.context = NULL;
 	if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) ||
 	     bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
 		if (exp->ex_flags & NFSEXP_SECURITY_LABEL)
 			err = security_inode_getsecctx(d_inode(dentry),
-						&context, &contextlen);
+						&args.context, &args.contextlen);
 		else
 			err = -EOPNOTSUPP;
 		args.contextsupport = (err == 0);
@@ -3713,8 +3723,7 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
 	if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
-		status = nfsd4_encode_security_label(xdr, rqstp, context,
-								contextlen);
+		status = nfsd4_encode_fattr4_sec_label(xdr, &args);
 		if (status)
 			goto out;
 	}
@@ -3733,8 +3742,8 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 
 out:
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
-	if (context)
-		security_release_secctx(context, contextlen);
+	if (args.context)
+		security_release_secctx(args.context, args.contextlen);
 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
 	kfree(args.acl);
 	if (tempfh) {



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 49/52] NFSD: Add nfsd4_encode_fattr4_xattr_support()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (47 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 48/52] NFSD: Add nfsd4_encode_fattr4_sec_label() Chuck Lever
@ 2023-09-18 14:01 ` Chuck Lever
  2023-09-18 14:02 ` [PATCH v1 50/52] NFSD: Copy FATTR4 bit number definitions from RFCs Chuck Lever
                   ` (3 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:01 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

Refactor the encoder for FATTR4_XATTR_SUPPORT into a helper. In a
subsequent patch, this helper will be called from a bitmask loop.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 137e7368dbfd..97654a2b876f 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3346,6 +3346,14 @@ static __be32 nfsd4_encode_fattr4_sec_label(struct xdr_stream *xdr,
 }
 #endif
 
+static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr,
+						const struct nfsd4_fattr_args *args)
+{
+	int err = xattr_supports_user_prefix(d_inode(args->dentry));
+
+	return nfsd4_encode_bool(xdr, err == 0);
+}
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3361,10 +3369,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	u32 bmval1 = bmval[1];
 	u32 bmval2 = bmval[2];
 	struct svc_fh *tempfh = NULL;
-	__be32 *p, *attrlen_p;
 	int starting_len = xdr->buf->len;
+	__be32 *attrlen_p, status;
 	int attrlen_offset;
-	__be32 status;
 	int err;
 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
 	u32 minorversion = resp->cstate.minorversion;
@@ -3730,11 +3737,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 #endif
 
 	if (bmval2 & FATTR4_WORD2_XATTR_SUPPORT) {
-		p = xdr_reserve_space(xdr, 4);
-		if (!p)
-			goto out_resource;
-		err = xattr_supports_user_prefix(d_inode(dentry));
-		*p++ = cpu_to_be32(err == 0);
+		status = nfsd4_encode_fattr4_xattr_support(xdr, &args);
+		if (status != nfs_ok)
+			goto out;
 	}
 
 	*attrlen_p = cpu_to_be32(xdr->buf->len - attrlen_offset - XDR_UNIT);



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 50/52] NFSD: Copy FATTR4 bit number definitions from RFCs
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (48 preceding siblings ...)
  2023-09-18 14:01 ` [PATCH v1 49/52] NFSD: Add nfsd4_encode_fattr4_xattr_support() Chuck Lever
@ 2023-09-18 14:02 ` Chuck Lever
  2023-09-18 14:02 ` [PATCH v1 51/52] NFSD: Use a bitmask loop to encode FATTR4 results Chuck Lever
                   ` (2 subsequent siblings)
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:02 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

I'd like to convert nfsd4_encode_fattr() to rotate through the
attrmask using for_each_bit() instead of explicitly testing the
bitmask for each bit value. This means I need the bit numbers, as
defined in the specs, instead of our internal bitmask constants.

As a clean up, use the new spec-derived values to define the WORD#
bitmask constants.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 include/linux/nfs4.h |  260 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 192 insertions(+), 68 deletions(-)

diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
index 730003c4f4af..b23c193523c3 100644
--- a/include/linux/nfs4.h
+++ b/include/linux/nfs4.h
@@ -389,79 +389,203 @@ enum lock_type4 {
 	NFS4_WRITEW_LT = 4
 };
 
+/*
+ * Symbol names and values are from RFC 7531 Section 2.
+ * "XDR Description of NFSv4.0"
+ */
+enum {
+	FATTR4_SUPPORTED_ATTRS		= 0,
+	FATTR4_TYPE			= 1,
+	FATTR4_FH_EXPIRE_TYPE		= 2,
+	FATTR4_CHANGE			= 3,
+	FATTR4_SIZE			= 4,
+	FATTR4_LINK_SUPPORT		= 5,
+	FATTR4_SYMLINK_SUPPORT		= 6,
+	FATTR4_NAMED_ATTR		= 7,
+	FATTR4_FSID			= 8,
+	FATTR4_UNIQUE_HANDLES		= 9,
+	FATTR4_LEASE_TIME		= 10,
+	FATTR4_RDATTR_ERROR		= 11,
+	FATTR4_ACL			= 12,
+	FATTR4_ACLSUPPORT		= 13,
+	FATTR4_ARCHIVE			= 14,
+	FATTR4_CANSETTIME		= 15,
+	FATTR4_CASE_INSENSITIVE		= 16,
+	FATTR4_CASE_PRESERVING		= 17,
+	FATTR4_CHOWN_RESTRICTED		= 18,
+	FATTR4_FILEHANDLE		= 19,
+	FATTR4_FILEID			= 20,
+	FATTR4_FILES_AVAIL		= 21,
+	FATTR4_FILES_FREE		= 22,
+	FATTR4_FILES_TOTAL		= 23,
+	FATTR4_FS_LOCATIONS		= 24,
+	FATTR4_HIDDEN			= 25,
+	FATTR4_HOMOGENEOUS		= 26,
+	FATTR4_MAXFILESIZE		= 27,
+	FATTR4_MAXLINK			= 28,
+	FATTR4_MAXNAME			= 29,
+	FATTR4_MAXREAD			= 30,
+	FATTR4_MAXWRITE			= 31,
+	FATTR4_MIMETYPE			= 32,
+	FATTR4_MODE			= 33,
+	FATTR4_NO_TRUNC			= 34,
+	FATTR4_NUMLINKS			= 35,
+	FATTR4_OWNER			= 36,
+	FATTR4_OWNER_GROUP		= 37,
+	FATTR4_QUOTA_AVAIL_HARD		= 38,
+	FATTR4_QUOTA_AVAIL_SOFT		= 39,
+	FATTR4_QUOTA_USED		= 40,
+	FATTR4_RAWDEV			= 41,
+	FATTR4_SPACE_AVAIL		= 42,
+	FATTR4_SPACE_FREE		= 43,
+	FATTR4_SPACE_TOTAL		= 44,
+	FATTR4_SPACE_USED		= 45,
+	FATTR4_SYSTEM			= 46,
+	FATTR4_TIME_ACCESS		= 47,
+	FATTR4_TIME_ACCESS_SET		= 48,
+	FATTR4_TIME_BACKUP		= 49,
+	FATTR4_TIME_CREATE		= 50,
+	FATTR4_TIME_DELTA		= 51,
+	FATTR4_TIME_METADATA		= 52,
+	FATTR4_TIME_MODIFY		= 53,
+	FATTR4_TIME_MODIFY_SET		= 54,
+	FATTR4_MOUNTED_ON_FILEID	= 55,
+};
+
+/*
+ * Symbol names and values are from RFC 5662 Section 2.
+ * "XDR Description of NFSv4.1"
+ */
+enum {
+	FATTR4_DIR_NOTIF_DELAY		= 56,
+	FATTR4_DIRENT_NOTIF_DELAY	= 57,
+	FATTR4_DACL			= 58,
+	FATTR4_SACL			= 59,
+	FATTR4_CHANGE_POLICY		= 60,
+	FATTR4_FS_STATUS		= 61,
+	FATTR4_FS_LAYOUT_TYPES		= 62,
+	FATTR4_LAYOUT_HINT		= 63,
+	FATTR4_LAYOUT_TYPES		= 64,
+	FATTR4_LAYOUT_BLKSIZE		= 65,
+	FATTR4_LAYOUT_ALIGNMENT		= 66,
+	FATTR4_FS_LOCATIONS_INFO	= 67,
+	FATTR4_MDSTHRESHOLD		= 68,
+	FATTR4_RETENTION_GET		= 69,
+	FATTR4_RETENTION_SET		= 70,
+	FATTR4_RETENTEVT_GET		= 71,
+	FATTR4_RETENTEVT_SET		= 72,
+	FATTR4_RETENTION_HOLD		= 73,
+	FATTR4_MODE_SET_MASKED		= 74,
+	FATTR4_SUPPATTR_EXCLCREAT	= 75,
+	FATTR4_FS_CHARSET_CAP		= 76,
+};
+
+/*
+ * Symbol names and values are from RFC 7863 Section 2.
+ * "XDR Description of NFSv4.2"
+ */
+enum {
+	FATTR4_CLONE_BLKSIZE		= 77,
+	FATTR4_SPACE_FREED		= 78,
+	FATTR4_CHANGE_ATTR_TYPE		= 79,
+	FATTR4_SEC_LABEL		= 80,
+};
+
+/*
+ * Symbol names and values are from RFC 8275 Section 5.
+ * "The mode_umask Attribute"
+ */
+enum {
+	FATTR4_MODE_UMASK		= 81,
+};
+
+/*
+ * Symbol names and values are from RFC 8276 Section 8.6.
+ * "Numeric Values Assigned to Protocol Extensions"
+ */
+enum {
+	FATTR4_XATTR_SUPPORT		= 82,
+};
+
+/*
+ * The following internal definitions enable processing the above
+ * attribute bits within 32-bit word boundaries.
+ */
 
 /* Mandatory Attributes */
-#define FATTR4_WORD0_SUPPORTED_ATTRS    (1UL << 0)
-#define FATTR4_WORD0_TYPE               (1UL << 1)
-#define FATTR4_WORD0_FH_EXPIRE_TYPE     (1UL << 2)
-#define FATTR4_WORD0_CHANGE             (1UL << 3)
-#define FATTR4_WORD0_SIZE               (1UL << 4)
-#define FATTR4_WORD0_LINK_SUPPORT       (1UL << 5)
-#define FATTR4_WORD0_SYMLINK_SUPPORT    (1UL << 6)
-#define FATTR4_WORD0_NAMED_ATTR         (1UL << 7)
-#define FATTR4_WORD0_FSID               (1UL << 8)
-#define FATTR4_WORD0_UNIQUE_HANDLES     (1UL << 9)
-#define FATTR4_WORD0_LEASE_TIME         (1UL << 10)
-#define FATTR4_WORD0_RDATTR_ERROR       (1UL << 11)
+#define FATTR4_WORD0_SUPPORTED_ATTRS    BIT(FATTR4_SUPPORTED_ATTRS)
+#define FATTR4_WORD0_TYPE               BIT(FATTR4_TYPE)
+#define FATTR4_WORD0_FH_EXPIRE_TYPE     BIT(FATTR4_FH_EXPIRE_TYPE)
+#define FATTR4_WORD0_CHANGE             BIT(FATTR4_CHANGE)
+#define FATTR4_WORD0_SIZE               BIT(FATTR4_SIZE)
+#define FATTR4_WORD0_LINK_SUPPORT       BIT(FATTR4_LINK_SUPPORT)
+#define FATTR4_WORD0_SYMLINK_SUPPORT    BIT(FATTR4_SYMLINK_SUPPORT)
+#define FATTR4_WORD0_NAMED_ATTR         BIT(FATTR4_NAMED_ATTR)
+#define FATTR4_WORD0_FSID               BIT(FATTR4_FSID)
+#define FATTR4_WORD0_UNIQUE_HANDLES     BIT(FATTR4_UNIQUE_HANDLES)
+#define FATTR4_WORD0_LEASE_TIME         BIT(FATTR4_LEASE_TIME)
+#define FATTR4_WORD0_RDATTR_ERROR       BIT(FATTR4_RDATTR_ERROR)
 /* Mandatory in NFSv4.1 */
-#define FATTR4_WORD2_SUPPATTR_EXCLCREAT (1UL << 11)
+#define FATTR4_WORD2_SUPPATTR_EXCLCREAT BIT(FATTR4_SUPPATTR_EXCLCREAT - 64)
 
 /* Recommended Attributes */
-#define FATTR4_WORD0_ACL                (1UL << 12)
-#define FATTR4_WORD0_ACLSUPPORT         (1UL << 13)
-#define FATTR4_WORD0_ARCHIVE            (1UL << 14)
-#define FATTR4_WORD0_CANSETTIME         (1UL << 15)
-#define FATTR4_WORD0_CASE_INSENSITIVE   (1UL << 16)
-#define FATTR4_WORD0_CASE_PRESERVING    (1UL << 17)
-#define FATTR4_WORD0_CHOWN_RESTRICTED   (1UL << 18)
-#define FATTR4_WORD0_FILEHANDLE         (1UL << 19)
-#define FATTR4_WORD0_FILEID             (1UL << 20)
-#define FATTR4_WORD0_FILES_AVAIL        (1UL << 21)
-#define FATTR4_WORD0_FILES_FREE         (1UL << 22)
-#define FATTR4_WORD0_FILES_TOTAL        (1UL << 23)
-#define FATTR4_WORD0_FS_LOCATIONS       (1UL << 24)
-#define FATTR4_WORD0_HIDDEN             (1UL << 25)
-#define FATTR4_WORD0_HOMOGENEOUS        (1UL << 26)
-#define FATTR4_WORD0_MAXFILESIZE        (1UL << 27)
-#define FATTR4_WORD0_MAXLINK            (1UL << 28)
-#define FATTR4_WORD0_MAXNAME            (1UL << 29)
-#define FATTR4_WORD0_MAXREAD            (1UL << 30)
-#define FATTR4_WORD0_MAXWRITE           (1UL << 31)
-#define FATTR4_WORD1_MIMETYPE           (1UL << 0)
-#define FATTR4_WORD1_MODE               (1UL << 1)
-#define FATTR4_WORD1_NO_TRUNC           (1UL << 2)
-#define FATTR4_WORD1_NUMLINKS           (1UL << 3)
-#define FATTR4_WORD1_OWNER              (1UL << 4)
-#define FATTR4_WORD1_OWNER_GROUP        (1UL << 5)
-#define FATTR4_WORD1_QUOTA_HARD         (1UL << 6)
-#define FATTR4_WORD1_QUOTA_SOFT         (1UL << 7)
-#define FATTR4_WORD1_QUOTA_USED         (1UL << 8)
-#define FATTR4_WORD1_RAWDEV             (1UL << 9)
-#define FATTR4_WORD1_SPACE_AVAIL        (1UL << 10)
-#define FATTR4_WORD1_SPACE_FREE         (1UL << 11)
-#define FATTR4_WORD1_SPACE_TOTAL        (1UL << 12)
-#define FATTR4_WORD1_SPACE_USED         (1UL << 13)
-#define FATTR4_WORD1_SYSTEM             (1UL << 14)
-#define FATTR4_WORD1_TIME_ACCESS        (1UL << 15)
-#define FATTR4_WORD1_TIME_ACCESS_SET    (1UL << 16)
-#define FATTR4_WORD1_TIME_BACKUP        (1UL << 17)
-#define FATTR4_WORD1_TIME_CREATE        (1UL << 18)
-#define FATTR4_WORD1_TIME_DELTA         (1UL << 19)
-#define FATTR4_WORD1_TIME_METADATA      (1UL << 20)
-#define FATTR4_WORD1_TIME_MODIFY        (1UL << 21)
-#define FATTR4_WORD1_TIME_MODIFY_SET    (1UL << 22)
-#define FATTR4_WORD1_MOUNTED_ON_FILEID  (1UL << 23)
-#define FATTR4_WORD1_DACL               (1UL << 26)
-#define FATTR4_WORD1_SACL               (1UL << 27)
-#define FATTR4_WORD1_FS_LAYOUT_TYPES    (1UL << 30)
-#define FATTR4_WORD2_LAYOUT_TYPES       (1UL << 0)
-#define FATTR4_WORD2_LAYOUT_BLKSIZE     (1UL << 1)
-#define FATTR4_WORD2_MDSTHRESHOLD       (1UL << 4)
-#define FATTR4_WORD2_CLONE_BLKSIZE	(1UL << 13)
-#define FATTR4_WORD2_CHANGE_ATTR_TYPE	(1UL << 15)
-#define FATTR4_WORD2_SECURITY_LABEL     (1UL << 16)
-#define FATTR4_WORD2_MODE_UMASK		(1UL << 17)
-#define FATTR4_WORD2_XATTR_SUPPORT	(1UL << 18)
+#define FATTR4_WORD0_ACL                BIT(FATTR4_ACL)
+#define FATTR4_WORD0_ACLSUPPORT         BIT(FATTR4_ACLSUPPORT)
+#define FATTR4_WORD0_ARCHIVE            BIT(FATTR4_ARCHIVE)
+#define FATTR4_WORD0_CANSETTIME         BIT(FATTR4_CANSETTIME)
+#define FATTR4_WORD0_CASE_INSENSITIVE   BIT(FATTR4_CASE_INSENSITIVE)
+#define FATTR4_WORD0_CASE_PRESERVING    BIT(FATTR4_CASE_PRESERVING)
+#define FATTR4_WORD0_CHOWN_RESTRICTED   BIT(FATTR4_CHOWN_RESTRICTED)
+#define FATTR4_WORD0_FILEHANDLE         BIT(FATTR4_FILEHANDLE)
+#define FATTR4_WORD0_FILEID             BIT(FATTR4_FILEID)
+#define FATTR4_WORD0_FILES_AVAIL        BIT(FATTR4_FILES_AVAIL)
+#define FATTR4_WORD0_FILES_FREE         BIT(FATTR4_FILES_FREE)
+#define FATTR4_WORD0_FILES_TOTAL        BIT(FATTR4_FILES_TOTAL)
+#define FATTR4_WORD0_FS_LOCATIONS       BIT(FATTR4_FS_LOCATIONS)
+#define FATTR4_WORD0_HIDDEN             BIT(FATTR4_HIDDEN)
+#define FATTR4_WORD0_HOMOGENEOUS        BIT(FATTR4_HOMOGENEOUS)
+#define FATTR4_WORD0_MAXFILESIZE        BIT(FATTR4_MAXFILESIZE)
+#define FATTR4_WORD0_MAXLINK            BIT(FATTR4_MAXLINK)
+#define FATTR4_WORD0_MAXNAME            BIT(FATTR4_MAXNAME)
+#define FATTR4_WORD0_MAXREAD            BIT(FATTR4_MAXREAD)
+#define FATTR4_WORD0_MAXWRITE           BIT(FATTR4_MAXWRITE)
+
+#define FATTR4_WORD1_MIMETYPE           BIT(FATTR4_MIMETYPE - 32)
+#define FATTR4_WORD1_MODE               BIT(FATTR4_MODE	- 32)
+#define FATTR4_WORD1_NO_TRUNC           BIT(FATTR4_NO_TRUNC - 32)
+#define FATTR4_WORD1_NUMLINKS           BIT(FATTR4_NUMLINKS - 32)
+#define FATTR4_WORD1_OWNER              BIT(FATTR4_OWNER - 32)
+#define FATTR4_WORD1_OWNER_GROUP        BIT(FATTR4_OWNER_GROUP - 32)
+#define FATTR4_WORD1_QUOTA_HARD         BIT(FATTR4_QUOTA_AVAIL_HARD - 32)
+#define FATTR4_WORD1_QUOTA_SOFT         BIT(FATTR4_QUOTA_AVAIL_SOFT - 32)
+#define FATTR4_WORD1_QUOTA_USED         BIT(FATTR4_QUOTA_USED - 32)
+#define FATTR4_WORD1_RAWDEV             BIT(FATTR4_RAWDEV - 32)
+#define FATTR4_WORD1_SPACE_AVAIL        BIT(FATTR4_SPACE_AVAIL - 32)
+#define FATTR4_WORD1_SPACE_FREE         BIT(FATTR4_SPACE_FREE - 32)
+#define FATTR4_WORD1_SPACE_TOTAL        BIT(FATTR4_SPACE_TOTAL - 32)
+#define FATTR4_WORD1_SPACE_USED         BIT(FATTR4_SPACE_USED - 32)
+#define FATTR4_WORD1_SYSTEM             BIT(FATTR4_SYSTEM - 32)
+#define FATTR4_WORD1_TIME_ACCESS        BIT(FATTR4_TIME_ACCESS - 32)
+#define FATTR4_WORD1_TIME_ACCESS_SET    BIT(FATTR4_TIME_ACCESS_SET - 32)
+#define FATTR4_WORD1_TIME_BACKUP        BIT(FATTR4_TIME_BACKUP - 32)
+#define FATTR4_WORD1_TIME_CREATE        BIT(FATTR4_TIME_CREATE - 32)
+#define FATTR4_WORD1_TIME_DELTA         BIT(FATTR4_TIME_DELTA - 32)
+#define FATTR4_WORD1_TIME_METADATA      BIT(FATTR4_TIME_METADATA - 32)
+#define FATTR4_WORD1_TIME_MODIFY        BIT(FATTR4_TIME_MODIFY - 32)
+#define FATTR4_WORD1_TIME_MODIFY_SET    BIT(FATTR4_TIME_MODIFY_SET - 32)
+#define FATTR4_WORD1_MOUNTED_ON_FILEID  BIT(FATTR4_MOUNTED_ON_FILEID - 32)
+#define FATTR4_WORD1_DACL               BIT(FATTR4_DACL	- 32)
+#define FATTR4_WORD1_SACL               BIT(FATTR4_SACL	- 32)
+#define FATTR4_WORD1_FS_LAYOUT_TYPES    BIT(FATTR4_FS_LAYOUT_TYPES - 32)
+
+#define FATTR4_WORD2_LAYOUT_TYPES       BIT(FATTR4_LAYOUT_TYPES - 64)
+#define FATTR4_WORD2_LAYOUT_BLKSIZE     BIT(FATTR4_LAYOUT_BLKSIZE - 64)
+#define FATTR4_WORD2_MDSTHRESHOLD       BIT(FATTR4_MDSTHRESHOLD	- 64)
+#define FATTR4_WORD2_CLONE_BLKSIZE	BIT(FATTR4_CLONE_BLKSIZE - 64)
+#define FATTR4_WORD2_CHANGE_ATTR_TYPE	BIT(FATTR4_CHANGE_ATTR_TYPE - 64)
+#define FATTR4_WORD2_SECURITY_LABEL     BIT(FATTR4_SEC_LABEL - 64)
+#define FATTR4_WORD2_MODE_UMASK		BIT(FATTR4_MODE_UMASK - 64)
+#define FATTR4_WORD2_XATTR_SUPPORT	BIT(FATTR4_XATTR_SUPPORT - 64)
 
 /* MDS threshold bitmap bits */
 #define THRESHOLD_RD                    (1UL << 0)



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 51/52] NFSD: Use a bitmask loop to encode FATTR4 results
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (49 preceding siblings ...)
  2023-09-18 14:02 ` [PATCH v1 50/52] NFSD: Copy FATTR4 bit number definitions from RFCs Chuck Lever
@ 2023-09-18 14:02 ` Chuck Lever
  2023-09-18 14:02 ` [PATCH v1 52/52] NFSD: Rename nfsd4_encode_fattr() Chuck Lever
  2023-09-22 19:20 ` [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Jeff Layton
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:02 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

The fattr4 encoder is now structured like the COMPOUND op encoder:
one function for each individual attribute, called by bit number.
Benefits include:

- The individual attributes are now guaranteed to be encoded in
  bitmask order into the send buffer

- There can be no unwanted side effects between attribute encoders

- The code now clearly documents which attributes are /not/
  implemented on this server

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |  429 ++++++++++++++++++-----------------------------------
 1 file changed, 142 insertions(+), 287 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 97654a2b876f..d7f690a3ea86 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -2902,6 +2902,15 @@ struct nfsd4_fattr_args {
 	bool			ignore_crossmnt;
 };
 
+typedef __be32(*nfsd4_enc_attr)(struct xdr_stream *xdr,
+				const struct nfsd4_fattr_args *args);
+
+static __be32 nfsd4_encode_fattr4__noop(struct xdr_stream *xdr,
+					const struct nfsd4_fattr_args *args)
+{
+	return nfs_ok;
+}
+
 static __be32 nfsd4_encode_fattr4__true(struct xdr_stream *xdr,
 					const struct nfsd4_fattr_args *args)
 {
@@ -3354,6 +3363,108 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr,
 	return nfsd4_encode_bool(xdr, err == 0);
 }
 
+static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
+	[FATTR4_SUPPORTED_ATTRS]	= nfsd4_encode_fattr4_supported_attrs,
+	[FATTR4_TYPE]			= nfsd4_encode_fattr4_type,
+	[FATTR4_FH_EXPIRE_TYPE]		= nfsd4_encode_fattr4_fh_expire_type,
+	[FATTR4_CHANGE]			= nfsd4_encode_fattr4_change,
+	[FATTR4_SIZE]			= nfsd4_encode_fattr4_size,
+	[FATTR4_LINK_SUPPORT]		= nfsd4_encode_fattr4__true,
+	[FATTR4_SYMLINK_SUPPORT]	= nfsd4_encode_fattr4__true,
+	[FATTR4_NAMED_ATTR]		= nfsd4_encode_fattr4__false,
+	[FATTR4_FSID]			= nfsd4_encode_fattr4_fsid,
+	[FATTR4_UNIQUE_HANDLES]		= nfsd4_encode_fattr4__true,
+	[FATTR4_LEASE_TIME]		= nfsd4_encode_fattr4_lease_time,
+	[FATTR4_RDATTR_ERROR]		= nfsd4_encode_fattr4_rdattr_error,
+	[FATTR4_ACL]			= nfsd4_encode_fattr4_acl,
+	[FATTR4_ACLSUPPORT]		= nfsd4_encode_fattr4_aclsupport,
+	[FATTR4_ARCHIVE]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_CANSETTIME]		= nfsd4_encode_fattr4__true,
+	[FATTR4_CASE_INSENSITIVE]	= nfsd4_encode_fattr4__false,
+	[FATTR4_CASE_PRESERVING]	= nfsd4_encode_fattr4__true,
+	[FATTR4_CHOWN_RESTRICTED]	= nfsd4_encode_fattr4__true,
+	[FATTR4_FILEHANDLE]		= nfsd4_encode_fattr4_filehandle,
+	[FATTR4_FILEID]			= nfsd4_encode_fattr4_fileid,
+	[FATTR4_FILES_AVAIL]		= nfsd4_encode_fattr4_files_avail,
+	[FATTR4_FILES_FREE]		= nfsd4_encode_fattr4_files_free,
+	[FATTR4_FILES_TOTAL]		= nfsd4_encode_fattr4_files_total,
+	[FATTR4_FS_LOCATIONS]		= nfsd4_encode_fattr4_fs_locations,
+	[FATTR4_HIDDEN]			= nfsd4_encode_fattr4__noop,
+	[FATTR4_HOMOGENEOUS]		= nfsd4_encode_fattr4__true,
+	[FATTR4_MAXFILESIZE]		= nfsd4_encode_fattr4_maxfilesize,
+	[FATTR4_MAXLINK]		= nfsd4_encode_fattr4_maxlink,
+	[FATTR4_MAXNAME]		= nfsd4_encode_fattr4_maxname,
+	[FATTR4_MAXREAD]		= nfsd4_encode_fattr4_maxread,
+	[FATTR4_MAXWRITE]		= nfsd4_encode_fattr4_maxwrite,
+	[FATTR4_MIMETYPE]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_MODE]			= nfsd4_encode_fattr4_mode,
+	[FATTR4_NO_TRUNC]		= nfsd4_encode_fattr4__true,
+	[FATTR4_NUMLINKS]		= nfsd4_encode_fattr4_numlinks,
+	[FATTR4_OWNER]			= nfsd4_encode_fattr4_owner,
+	[FATTR4_OWNER_GROUP]		= nfsd4_encode_fattr4_owner_group,
+	[FATTR4_QUOTA_AVAIL_HARD]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_QUOTA_AVAIL_SOFT]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_QUOTA_USED]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_RAWDEV]			= nfsd4_encode_fattr4_rawdev,
+	[FATTR4_SPACE_AVAIL]		= nfsd4_encode_fattr4_space_avail,
+	[FATTR4_SPACE_FREE]		= nfsd4_encode_fattr4_space_free,
+	[FATTR4_SPACE_TOTAL]		= nfsd4_encode_fattr4_space_total,
+	[FATTR4_SPACE_USED]		= nfsd4_encode_fattr4_space_used,
+	[FATTR4_SYSTEM]			= nfsd4_encode_fattr4__noop,
+	[FATTR4_TIME_ACCESS]		= nfsd4_encode_fattr4_time_access,
+	[FATTR4_TIME_ACCESS_SET]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_TIME_BACKUP]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_TIME_CREATE]		= nfsd4_encode_fattr4_time_create,
+	[FATTR4_TIME_DELTA]		= nfsd4_encode_fattr4_time_delta,
+	[FATTR4_TIME_METADATA]		= nfsd4_encode_fattr4_time_metadata,
+	[FATTR4_TIME_MODIFY]		= nfsd4_encode_fattr4_time_modify,
+	[FATTR4_TIME_MODIFY_SET]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_MOUNTED_ON_FILEID]	= nfsd4_encode_fattr4_mounted_on_fileid,
+	[FATTR4_DIR_NOTIF_DELAY]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_DIRENT_NOTIF_DELAY]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_DACL]			= nfsd4_encode_fattr4__noop,
+	[FATTR4_SACL]			= nfsd4_encode_fattr4__noop,
+	[FATTR4_CHANGE_POLICY]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_FS_STATUS]		= nfsd4_encode_fattr4__noop,
+
+#ifdef CONFIG_NFSD_PNFS
+	[FATTR4_FS_LAYOUT_TYPES]	= nfsd4_encode_fattr4_fs_layout_types,
+	[FATTR4_LAYOUT_HINT]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_LAYOUT_TYPES]		= nfsd4_encode_fattr4_layout_types,
+	[FATTR4_LAYOUT_BLKSIZE]		= nfsd4_encode_fattr4_layout_blksize,
+	[FATTR4_LAYOUT_ALIGNMENT]	= nfsd4_encode_fattr4__noop,
+#else
+	[FATTR4_FS_LAYOUT_TYPES]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_LAYOUT_HINT]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_LAYOUT_TYPES]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_LAYOUT_BLKSIZE]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_LAYOUT_ALIGNMENT]	= nfsd4_encode_fattr4__noop,
+#endif
+
+	[FATTR4_FS_LOCATIONS_INFO]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_MDSTHRESHOLD]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_RETENTION_GET]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_RETENTION_SET]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_RETENTEVT_GET]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_RETENTEVT_SET]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_RETENTION_HOLD]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_MODE_SET_MASKED]	= nfsd4_encode_fattr4__noop,
+	[FATTR4_SUPPATTR_EXCLCREAT]	= nfsd4_encode_fattr4_suppattr_exclcreat,
+	[FATTR4_FS_CHARSET_CAP]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_CLONE_BLKSIZE]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_SPACE_FREED]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_CHANGE_ATTR_TYPE]	= nfsd4_encode_fattr4__noop,
+
+#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
+	[FATTR4_SEC_LABEL]		= nfsd4_encode_fattr4_sec_label,
+#else
+	[FATTR4_SEC_LABEL]		= nfsd4_encode_fattr4__noop,
+#endif
+
+	[FATTR4_MODE_UMASK]		= nfsd4_encode_fattr4__noop,
+	[FATTR4_XATTR_SUPPORT]		= nfsd4_encode_fattr4_xattr_support,
+};
+
 /*
  * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  * ourselves.
@@ -3361,13 +3472,10 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr,
 static __be32
 nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		struct svc_export *exp,
-		struct dentry *dentry, u32 *bmval,
+		struct dentry *dentry, const u32 *bmval,
 		struct svc_rqst *rqstp, int ignore_crossmnt)
 {
 	struct nfsd4_fattr_args args;
-	u32 bmval0 = bmval[0];
-	u32 bmval1 = bmval[1];
-	u32 bmval2 = bmval[2];
 	struct svc_fh *tempfh = NULL;
 	int starting_len = xdr->buf->len;
 	__be32 *attrlen_p, status;
@@ -3379,23 +3487,32 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		.mnt	= exp->ex_path.mnt,
 		.dentry	= dentry,
 	};
+	unsigned long bit, *mask;
+	u32 attrmask[3];
 
-	BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
-	BUG_ON(!nfsd_attrs_supported(minorversion, bmval));
+	WARN_ON_ONCE(bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1);
+	WARN_ON_ONCE(!nfsd_attrs_supported(minorversion, bmval));
 
 	args.rqstp = rqstp;
 	args.exp = exp;
 	args.dentry = dentry;
 	args.ignore_crossmnt = (ignore_crossmnt != 0);
 
+	/*
+	 * Make a local copy of the attribute bitmap that can be modified.
+	 */
+	attrmask[0] = bmval[0];
+	attrmask[1] = bmval[1];
+	attrmask[2] = bmval[2];
+
 	args.rdattr_err = 0;
 	if (exp->ex_fslocs.migrated) {
-		status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2,
-						&args.rdattr_err);
+		status = fattr_handle_absent_fs(&attrmask[0], &attrmask[1],
+						&attrmask[2], &args.rdattr_err);
 		if (status)
 			goto out;
 	}
-	if (bmval0 & (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE)) {
+	if (attrmask[0] & (FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE)) {
 		status = nfsd4_deleg_getattr_conflict(rqstp, d_inode(dentry));
 		if (status)
 			goto out;
@@ -3409,16 +3526,17 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 
 	if (!(args.stat.result_mask & STATX_BTIME))
 		/* underlying FS does not offer btime so we can't share it */
-		bmval1 &= ~FATTR4_WORD1_TIME_CREATE;
-	if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
+		attrmask[1] &= ~FATTR4_WORD1_TIME_CREATE;
+	if ((attrmask[0] & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
 			FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) ||
-	    (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
+	    (attrmask[1] & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
 		       FATTR4_WORD1_SPACE_TOTAL))) {
 		err = vfs_statfs(&path, &args.statfs);
 		if (err)
 			goto out_nfserr;
 	}
-	if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
+	if ((attrmask[0] & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) &&
+	    !fhp) {
 		tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
 		status = nfserr_jukebox;
 		if (!tempfh)
@@ -3432,10 +3550,10 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 		args.fhp = fhp;
 
 	args.acl = NULL;
-	if (bmval0 & FATTR4_WORD0_ACL) {
+	if (attrmask[0] & FATTR4_WORD0_ACL) {
 		err = nfsd4_get_nfs4_acl(rqstp, dentry, &args.acl);
 		if (err == -EOPNOTSUPP)
-			bmval0 &= ~FATTR4_WORD0_ACL;
+			attrmask[0] &= ~FATTR4_WORD0_ACL;
 		else if (err == -EINVAL) {
 			status = nfserr_attrnotsupp;
 			goto out;
@@ -3447,24 +3565,25 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
 	args.context = NULL;
-	if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) ||
-	     bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
+	if ((attrmask[2] & FATTR4_WORD2_SECURITY_LABEL) ||
+	     attrmask[0] & FATTR4_WORD0_SUPPORTED_ATTRS) {
 		if (exp->ex_flags & NFSEXP_SECURITY_LABEL)
 			err = security_inode_getsecctx(d_inode(dentry),
 						&args.context, &args.contextlen);
 		else
 			err = -EOPNOTSUPP;
 		args.contextsupport = (err == 0);
-		if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
+		if (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL) {
 			if (err == -EOPNOTSUPP)
-				bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL;
+				attrmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
 			else if (err)
 				goto out_nfserr;
 		}
 	}
 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
 
-	status = nfsd4_encode_bitmap4(xdr, bmval0, bmval1, bmval2);
+	status = nfsd4_encode_bitmap4(xdr, attrmask[0],
+				      attrmask[1], attrmask[2]);
 	if (status)
 		goto out;
 
@@ -3472,276 +3591,12 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	attrlen_p = xdr_reserve_space(xdr, XDR_UNIT);
 	if (!attrlen_p)
 		goto out_resource;
-
-	if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
-		status = nfsd4_encode_fattr4_supported_attrs(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_TYPE) {
-		status = nfsd4_encode_fattr4_type(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
-		status = nfsd4_encode_fattr4_fh_expire_type(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_CHANGE) {
-		status = nfsd4_encode_fattr4_change(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_SIZE) {
-		status = nfsd4_encode_fattr4_size(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
-		status = nfsd4_encode_fattr4__true(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
-		status = nfsd4_encode_fattr4__true(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
-		status = nfsd4_encode_fattr4__false(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FSID) {
-		status = nfsd4_encode_fattr4_fsid(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
-		status = nfsd4_encode_fattr4__false(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
-		status = nfsd4_encode_fattr4_lease_time(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
-		status = nfsd4_encode_fattr4_rdattr_error(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_ACL) {
-		status = nfsd4_encode_fattr4_acl(xdr, &args);
-		if (status)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
-		status = nfsd4_encode_fattr4_aclsupport(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_CANSETTIME) {
-		status = nfsd4_encode_fattr4__true(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
-		status = nfsd4_encode_fattr4__false(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
-		status = nfsd4_encode_fattr4__true(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
-		status = nfsd4_encode_fattr4__true(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
-		status = nfsd4_encode_fattr4_filehandle(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FILEID) {
-		status = nfsd4_encode_fattr4_fileid(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
-		status = nfsd4_encode_fattr4_files_avail(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FILES_FREE) {
-		status = nfsd4_encode_fattr4_files_free(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
-		status = nfsd4_encode_fattr4_files_total(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
-		status = nfsd4_encode_fattr4_fs_locations(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
-		status = nfsd4_encode_fattr4__true(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
-		status = nfsd4_encode_fattr4_maxfilesize(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_MAXLINK) {
-		status = nfsd4_encode_fattr4_maxlink(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_MAXNAME) {
-		status = nfsd4_encode_fattr4_maxname(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_MAXREAD) {
-		status = nfsd4_encode_fattr4_maxread(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval0 & FATTR4_WORD0_MAXWRITE) {
-		status = nfsd4_encode_fattr4_maxwrite(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_MODE) {
-		status = nfsd4_encode_fattr4_mode(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
-		status = nfsd4_encode_fattr4__true(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_NUMLINKS) {
-		status = nfsd4_encode_fattr4_numlinks(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_OWNER) {
-		status = nfsd4_encode_fattr4_owner(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
-		status = nfsd4_encode_fattr4_owner_group(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_RAWDEV) {
-		status = nfsd4_encode_fattr4_rawdev(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
-		status = nfsd4_encode_fattr4_space_avail(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
-		status = nfsd4_encode_fattr4_space_free(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
-		status = nfsd4_encode_fattr4_space_total(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_SPACE_USED) {
-		status = nfsd4_encode_fattr4_space_used(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
-		status = nfsd4_encode_fattr4_time_access(xdr, &args);
-		if (status)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_TIME_CREATE) {
-		status = nfsd4_encode_fattr4_time_create(xdr, &args);
-		if (status)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
-		status = nfsd4_encode_fattr4_time_delta(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
-		status = nfsd4_encode_fattr4_time_metadata(xdr, &args);
-		if (status)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
-		status = nfsd4_encode_fattr4_time_modify(xdr, &args);
-		if (status)
-			goto out;
-	}
-	if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
-		status = nfsd4_encode_fattr4_mounted_on_fileid(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-#ifdef CONFIG_NFSD_PNFS
-	if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) {
-		status = nfsd4_encode_fattr4_fs_layout_types(xdr, &args);
-		if (status)
-			goto out;
-	}
-
-	if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) {
-		status = nfsd4_encode_fattr4_layout_types(xdr, &args);
-		if (status)
-			goto out;
-	}
-
-	if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) {
-		status = nfsd4_encode_fattr4_layout_blksize(xdr, &args);
+	mask = (unsigned long *)attrmask;
+	for_each_set_bit(bit, mask, ARRAY_SIZE(nfsd4_enc_fattr4_encode_ops)) {
+		status = nfsd4_enc_fattr4_encode_ops[bit](xdr, &args);
 		if (status != nfs_ok)
 			goto out;
 	}
-#endif /* CONFIG_NFSD_PNFS */
-	if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
-		status = nfsd4_encode_fattr4_suppattr_exclcreat(xdr, &args);
-		if (status)
-			goto out;
-	}
-
-#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
-	if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
-		status = nfsd4_encode_fattr4_sec_label(xdr, &args);
-		if (status)
-			goto out;
-	}
-#endif
-
-	if (bmval2 & FATTR4_WORD2_XATTR_SUPPORT) {
-		status = nfsd4_encode_fattr4_xattr_support(xdr, &args);
-		if (status != nfs_ok)
-			goto out;
-	}
-
 	*attrlen_p = cpu_to_be32(xdr->buf->len - attrlen_offset - XDR_UNIT);
 	status = nfs_ok;
 



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* [PATCH v1 52/52] NFSD: Rename nfsd4_encode_fattr()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (50 preceding siblings ...)
  2023-09-18 14:02 ` [PATCH v1 51/52] NFSD: Use a bitmask loop to encode FATTR4 results Chuck Lever
@ 2023-09-18 14:02 ` Chuck Lever
  2023-09-22 19:20 ` [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Jeff Layton
  52 siblings, 0 replies; 54+ messages in thread
From: Chuck Lever @ 2023-09-18 14:02 UTC (permalink / raw)
  To: linux-nfs; +Cc: Chuck Lever

From: Chuck Lever <chuck.lever@oracle.com>

For better alignment with the specification, NFSD's encoder function
name should match the name of the XDR data type.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index d7f690a3ea86..e38af124169b 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3470,10 +3470,10 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
  * ourselves.
  */
 static __be32
-nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
-		struct svc_export *exp,
-		struct dentry *dentry, const u32 *bmval,
-		struct svc_rqst *rqstp, int ignore_crossmnt)
+nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
+		    struct svc_fh *fhp, struct svc_export *exp,
+		    struct dentry *dentry, const u32 *bmval,
+		    int ignore_crossmnt)
 {
 	struct nfsd4_fattr_args args;
 	struct svc_fh *tempfh = NULL;
@@ -3582,11 +3582,13 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
 	}
 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
 
+	/* attrmask */
 	status = nfsd4_encode_bitmap4(xdr, attrmask[0],
 				      attrmask[1], attrmask[2]);
 	if (status)
 		goto out;
 
+	/* attr_vals */
 	attrlen_offset = xdr->buf->len;
 	attrlen_p = xdr_reserve_space(xdr, XDR_UNIT);
 	if (!attrlen_p)
@@ -3646,8 +3648,8 @@ __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,
 	__be32 ret;
 
 	svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2);
-	ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp,
-							ignore_crossmnt);
+	ret = nfsd4_encode_fattr4(rqstp, &xdr, fhp, exp, dentry, bmval,
+				  ignore_crossmnt);
 	*p = xdr.p;
 	return ret;
 }
@@ -3706,8 +3708,8 @@ nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd,
 
 	}
 out_encode:
-	nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval,
-					cd->rd_rqstp, ignore_crossmnt);
+	nfserr = nfsd4_encode_fattr4(cd->rd_rqstp, xdr, NULL, exp, dentry,
+				     cd->rd_bmval, ignore_crossmnt);
 out_put:
 	dput(dentry);
 	exp_put(exp);
@@ -3951,8 +3953,9 @@ nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr,
 	struct svc_fh *fhp = getattr->ga_fhp;
 	struct xdr_stream *xdr = resp->xdr;
 
-	return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry,
-				    getattr->ga_bmval, resp->rqstp, 0);
+	/* obj_attributes */
+	return nfsd4_encode_fattr4(resp->rqstp, xdr, fhp, fhp->fh_export,
+				   fhp->fh_dentry, getattr->ga_bmval, 0);
 }
 
 static __be32



^ permalink raw reply related	[flat|nested] 54+ messages in thread

* Re: [PATCH v1 00/52] Modernize nfsd4_encode_fattr()
  2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
                   ` (51 preceding siblings ...)
  2023-09-18 14:02 ` [PATCH v1 52/52] NFSD: Rename nfsd4_encode_fattr() Chuck Lever
@ 2023-09-22 19:20 ` Jeff Layton
  52 siblings, 0 replies; 54+ messages in thread
From: Jeff Layton @ 2023-09-22 19:20 UTC (permalink / raw)
  To: Chuck Lever, linux-nfs; +Cc: Chuck Lever

On Mon, 2023-09-18 at 09:56 -0400, Chuck Lever wrote:
> This series restructures the server's fattr4 encoder. It is largely
> a maintenance improvement (ie, only 2nd-order benefits). There are
> no new features or performance benefits, and I hope there will be no
> changes in behavior.
> 
> The goals:
> * Better alignment with spec
> * Easier to read and audit
> * Less brittle
> * Some code de-duplication
> 
> This series applies to v6.6-rc2. Minor adjustment will be needed to
> apply it to nfsd-next. I apologize for the number of patches, but
> each of them (with only a couple of exceptions) is small and
> mechanical, and therefore easily digested.
> 
> A branch containing these patches is available in this repo:
> 
>   https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git
> 
> See the "nfsd4-encoder-overhaul" branch.
> 
> ---
> 
> Chuck Lever (52):
>       NFSD: Add simple u32, u64, and bool encoders
>       NFSD: Rename nfsd4_encode_bitmap()
>       NFSD: Clean up nfsd4_encode_setattr()
>       NFSD: Add struct nfsd4_fattr_args
>       NFSD: Add nfsd4_encode_fattr4__true()
>       NFSD: Add nfsd4_encode_fattr4__false()
>       NFSD: Add nfsd4_encode_fattr4_supported_attrs()
>       NFSD: Add nfsd4_encode_fattr4_type()
>       NFSD: Add nfsd4_encode_fattr4_fh_expire_type()
>       NFSD: Add nfsd4_encode_fattr4_change()
>       NFSD: Add nfsd4_encode_fattr4_size()
>       NFSD: Add nfsd4_encode_fattr4_fsid()
>       NFSD: Add nfsd4_encode_fattr4_lease_time()
>       NFSD: Add nfsd4_encode_fattr4_rdattr_error()
>       NFSD: Add nfsd4_encode_fattr4_aclsupport()
>       NFSD: Add nfsd4_encode_nfsace4()
>       NFSD: Add nfsd4_encode_fattr4_acl()
>       NFSD: Add nfsd4_encode_fattr4_filehandle()
>       NFSD: Add nfsd4_encode_fattr4_fileid()
>       NFSD: Add nfsd4_encode_fattr4_files_avail()
>       NFSD: Add nfsd4_encode_fattr4_files_free()
>       NFSD: Add nfsd4_encode_fattr4_files_total()
>       NFSD: Add nfsd4_encode_fattr4_fs_locations()
>       NFSD: Add nfsd4_encode_fattr4_maxfilesize()
>       NFSD: Add nfsd4_encode_fattr4_maxlink()
>       NFSD: Add nfsd4_encode_fattr4_maxname()
>       NFSD: Add nfsd4_encode_fattr4_maxread()
>       NFSD: Add nfsd4_encode_fattr4_maxwrite()
>       NFSD: Add nfsd4_encode_fattr4_mode()
>       NFSD: Add nfsd4_encode_fattr4_numlinks()
>       NFSD: Add nfsd4_encode_fattr4_owner()
>       NFSD: Add nfsd4_encode_fattr4_owner_group()
>       NFSD: Add nfsd4_encode_fattr4_rawdev()
>       NFSD: Add nfsd4_encode_fattr4_space_avail()
>       NFSD: Add nfsd4_encode_fattr4_space_free()
>       NFSD: Add nfsd4_encode_fattr4_space_total()
>       NFSD: Add nfsd4_encode_fattr4_space_used()
>       NFSD: Add nfsd4_encode_fattr4_time_access()
>       NFSD: Add nfsd4_encode_fattr4_time_create()
>       NFSD: Add nfsd4_encode_fattr4_time_delta()
>       NFSD: Add nfsd4_encode_fattr4_time_metadata()
>       NFSD: Add nfsd4_encode_fattr4_time_modify()
>       NFSD: Add nfsd4_encode_fattr4_mounted_on_fileid()
>       NFSD: Add nfsd4_encode_fattr4_fs_layout_types()
>       NFSD: Add nfsd4_encode_fattr4_layout_types()
>       NFSD: Add nfsd4_encode_fattr4_layout_blksize()
>       NFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat()
>       NFSD: Add nfsd4_encode_fattr4_sec_label()
>       NFSD: Add nfsd4_encode_fattr4_xattr_support()
>       NFSD: Copy FATTR4 bit number definitions from RFCs
>       NFSD: Use a bitmask loop to encode FATTR4 results
>       NFSD: Rename nfsd4_encode_fattr()
> 
> 
>  fs/nfsd/nfs4xdr.c        | 1419 +++++++++++++++++++++-----------------
>  fs/nfsd/nfsfh.c          |    2 +-
>  fs/nfsd/nfsfh.h          |    3 +-
>  fs/nfsd/xdr4.h           |  119 ++++
>  include/linux/iversion.h |    2 +-
>  include/linux/nfs4.h     |  260 +++++--
>  6 files changed, 1085 insertions(+), 720 deletions(-)
> 
> --
> Chuck Lever
> 

Large set, but the change is fairly mechanical overall, and the result
is much more readable.

Reviewed-by: Jeff Layton <jlayton@kernel.org>

^ permalink raw reply	[flat|nested] 54+ messages in thread

end of thread, other threads:[~2023-09-22 19:20 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-18 13:56 [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Chuck Lever
2023-09-18 13:56 ` [PATCH v1 01/52] NFSD: Add simple u32, u64, and bool encoders Chuck Lever
2023-09-18 13:57 ` [PATCH v1 02/52] NFSD: Rename nfsd4_encode_bitmap() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 03/52] NFSD: Clean up nfsd4_encode_setattr() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 04/52] NFSD: Add struct nfsd4_fattr_args Chuck Lever
2023-09-18 13:57 ` [PATCH v1 05/52] NFSD: Add nfsd4_encode_fattr4__true() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 06/52] NFSD: Add nfsd4_encode_fattr4__false() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 07/52] NFSD: Add nfsd4_encode_fattr4_supported_attrs() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 08/52] NFSD: Add nfsd4_encode_fattr4_type() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 09/52] NFSD: Add nfsd4_encode_fattr4_fh_expire_type() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 10/52] NFSD: Add nfsd4_encode_fattr4_change() Chuck Lever
2023-09-18 13:57 ` [PATCH v1 11/52] NFSD: Add nfsd4_encode_fattr4_size() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 12/52] NFSD: Add nfsd4_encode_fattr4_fsid() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 13/52] NFSD: Add nfsd4_encode_fattr4_lease_time() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 14/52] NFSD: Add nfsd4_encode_fattr4_rdattr_error() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 15/52] NFSD: Add nfsd4_encode_fattr4_aclsupport() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 16/52] NFSD: Add nfsd4_encode_nfsace4() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 17/52] NFSD: Add nfsd4_encode_fattr4_acl() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 18/52] NFSD: Add nfsd4_encode_fattr4_filehandle() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 19/52] NFSD: Add nfsd4_encode_fattr4_fileid() Chuck Lever
2023-09-18 13:58 ` [PATCH v1 20/52] NFSD: Add nfsd4_encode_fattr4_files_avail() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 21/52] NFSD: Add nfsd4_encode_fattr4_files_free() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 22/52] NFSD: Add nfsd4_encode_fattr4_files_total() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 23/52] NFSD: Add nfsd4_encode_fattr4_fs_locations() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 24/52] NFSD: Add nfsd4_encode_fattr4_maxfilesize() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 25/52] NFSD: Add nfsd4_encode_fattr4_maxlink() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 26/52] NFSD: Add nfsd4_encode_fattr4_maxname() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 27/52] NFSD: Add nfsd4_encode_fattr4_maxread() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 28/52] NFSD: Add nfsd4_encode_fattr4_maxwrite() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 29/52] NFSD: Add nfsd4_encode_fattr4_mode() Chuck Lever
2023-09-18 13:59 ` [PATCH v1 30/52] NFSD: Add nfsd4_encode_fattr4_numlinks() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 31/52] NFSD: Add nfsd4_encode_fattr4_owner() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 32/52] NFSD: Add nfsd4_encode_fattr4_owner_group() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 33/52] NFSD: Add nfsd4_encode_fattr4_rawdev() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 34/52] NFSD: Add nfsd4_encode_fattr4_space_avail() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 35/52] NFSD: Add nfsd4_encode_fattr4_space_free() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 36/52] NFSD: Add nfsd4_encode_fattr4_space_total() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 37/52] NFSD: Add nfsd4_encode_fattr4_space_used() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 38/52] NFSD: Add nfsd4_encode_fattr4_time_access() Chuck Lever
2023-09-18 14:00 ` [PATCH v1 39/52] NFSD: Add nfsd4_encode_fattr4_time_create() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 40/52] NFSD: Add nfsd4_encode_fattr4_time_delta() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 41/52] NFSD: Add nfsd4_encode_fattr4_time_metadata() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 42/52] NFSD: Add nfsd4_encode_fattr4_time_modify() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 43/52] NFSD: Add nfsd4_encode_fattr4_mounted_on_fileid() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 44/52] NFSD: Add nfsd4_encode_fattr4_fs_layout_types() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 45/52] NFSD: Add nfsd4_encode_fattr4_layout_types() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 46/52] NFSD: Add nfsd4_encode_fattr4_layout_blksize() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 47/52] NFSD: Add nfsd4_encode_fattr4_suppattr_exclcreat() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 48/52] NFSD: Add nfsd4_encode_fattr4_sec_label() Chuck Lever
2023-09-18 14:01 ` [PATCH v1 49/52] NFSD: Add nfsd4_encode_fattr4_xattr_support() Chuck Lever
2023-09-18 14:02 ` [PATCH v1 50/52] NFSD: Copy FATTR4 bit number definitions from RFCs Chuck Lever
2023-09-18 14:02 ` [PATCH v1 51/52] NFSD: Use a bitmask loop to encode FATTR4 results Chuck Lever
2023-09-18 14:02 ` [PATCH v1 52/52] NFSD: Rename nfsd4_encode_fattr() Chuck Lever
2023-09-22 19:20 ` [PATCH v1 00/52] Modernize nfsd4_encode_fattr() Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox