summaryrefslogtreecommitdiff
path: root/fs/nfsd
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2023-09-29 09:59:24 -0400
committerChuck Lever <chuck.lever@oracle.com>2023-10-16 12:44:32 -0400
commit802e191353e496f7ad5b00954b4643a1b8d726b5 (patch)
tree55124cc87d86a0132f7a4c7542d44f05cd43fcd1 /fs/nfsd
parent6dd43c6d5112ffde72fdef782e0970cd27041e79 (diff)
NFSD: Add nfsd4_encode_open_delegation4()
To better align our implementation with the XDR specification, refactor the part of nfsd4_encode_open() that encodes delegation metadata. As part of that refactor, remove an unnecessary BUG() call site and a comment that appears to be stale. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r--fs/nfsd/nfs4xdr.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 4a1d428066ce..cacd06949796 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -4175,12 +4175,42 @@ nfsd4_encode_open_none_delegation4(struct xdr_stream *xdr,
}
static __be32
+nfsd4_encode_open_delegation4(struct xdr_stream *xdr, struct nfsd4_open *open)
+{
+ __be32 status;
+
+ /* delegation_type */
+ if (xdr_stream_encode_u32(xdr, open->op_delegate_type) != XDR_UNIT)
+ return nfserr_resource;
+ switch (open->op_delegate_type) {
+ case NFS4_OPEN_DELEGATE_NONE:
+ status = nfs_ok;
+ break;
+ case NFS4_OPEN_DELEGATE_READ:
+ /* read */
+ status = nfsd4_encode_open_read_delegation4(xdr, open);
+ break;
+ case NFS4_OPEN_DELEGATE_WRITE:
+ /* write */
+ status = nfsd4_encode_open_write_delegation4(xdr, open);
+ break;
+ case NFS4_OPEN_DELEGATE_NONE_EXT:
+ /* od_whynone */
+ status = nfsd4_encode_open_none_delegation4(xdr, open);
+ break;
+ default:
+ status = nfserr_serverfault;
+ }
+
+ return status;
+}
+
+static __be32
nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr,
union nfsd4_op_u *u)
{
struct nfsd4_open *open = &u->open;
struct xdr_stream *xdr = resp->xdr;
- __be32 *p;
nfserr = nfsd4_encode_stateid4(xdr, &open->op_stateid);
if (nfserr)
@@ -4196,28 +4226,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr,
if (nfserr)
return nfserr;
- p = xdr_reserve_space(xdr, 4);
- if (!p)
- return nfserr_resource;
-
- *p++ = cpu_to_be32(open->op_delegate_type);
- switch (open->op_delegate_type) {
- case NFS4_OPEN_DELEGATE_NONE:
- break;
- case NFS4_OPEN_DELEGATE_READ:
- /* read */
- return nfsd4_encode_open_read_delegation4(xdr, open);
- case NFS4_OPEN_DELEGATE_WRITE:
- /* write */
- return nfsd4_encode_open_write_delegation4(xdr, open);
- case NFS4_OPEN_DELEGATE_NONE_EXT:
- /* od_whynone */
- return nfsd4_encode_open_none_delegation4(xdr, open);
- default:
- BUG();
- }
- /* XXX save filehandle here */
- return 0;
+ /* delegation */
+ return nfsd4_encode_open_delegation4(xdr, open);
}
static __be32