diff mbox series

[2/3] nfsd: add support for FATTR4_OPEN_ARGUMENTS

Message ID 20240816-delstid-v1-2-c221c3dc14cd@kernel.org (mailing list archive)
State New
Headers show
Series nfsd: implement OPEN_XOR_DELEGATION part of delstid draft | expand

Commit Message

Jeff Layton Aug. 16, 2024, 12:42 p.m. UTC
Add support for FATTR4_OPEN_ARGUMENTS. This a new mechanism for the
client to discover what OPEN features the server supports.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 fs/nfsd/delstid_xdr.c |  2 +-
 fs/nfsd/delstid_xdr.h |  3 +++
 fs/nfsd/nfs4xdr.c     | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfsd/nfsd.h        |  3 ++-
 4 files changed, 59 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/nfsd/delstid_xdr.c b/fs/nfsd/delstid_xdr.c
index 63494d14f5d2..b63f338da357 100644
--- a/fs/nfsd/delstid_xdr.c
+++ b/fs/nfsd/delstid_xdr.c
@@ -435,7 +435,7 @@  xdrgen_encode_open_args_createmode4(struct xdr_stream *xdr, enum open_args_creat
 	return xdr_stream_encode_u32(xdr, value) == XDR_UNIT;
 }
 
-static bool __maybe_unused
+bool
 xdrgen_encode_fattr4_open_arguments(struct xdr_stream *xdr, const fattr4_open_arguments *value)
 {
 	return xdrgen_encode_open_arguments4(xdr, value);
diff --git a/fs/nfsd/delstid_xdr.h b/fs/nfsd/delstid_xdr.h
index 3ca8d0cc8569..2a91a353ab93 100644
--- a/fs/nfsd/delstid_xdr.h
+++ b/fs/nfsd/delstid_xdr.h
@@ -99,4 +99,7 @@  typedef nfstime4 fattr4_time_deleg_modify;
 
 #define OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS (0x100000)
 
+/* delstid.c */
+bool xdrgen_encode_fattr4_open_arguments(struct xdr_stream *xdr,
+					 const fattr4_open_arguments *value);
 #endif /* _DELSTID_H */
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index b3d2000c8a08..dbaadb0ad980 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -3400,6 +3400,58 @@  static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr,
 	return nfsd4_encode_bool(xdr, err == 0);
 }
 
+#define NFSD_OA_SHARE_ACCESS	(BIT(OPEN_ARGS_SHARE_ACCESS_READ)	| \
+				 BIT(OPEN_ARGS_SHARE_ACCESS_WRITE)	| \
+				 BIT(OPEN_ARGS_SHARE_ACCESS_BOTH))
+
+#define NFSD_OA_SHARE_DENY	(BIT(OPEN_ARGS_SHARE_DENY_NONE)		| \
+				 BIT(OPEN_ARGS_SHARE_DENY_READ)		| \
+				 BIT(OPEN_ARGS_SHARE_DENY_WRITE)	| \
+				 BIT(OPEN_ARGS_SHARE_DENY_BOTH))
+
+#define NFSD_OA_SHARE_ACCESS_WANT	(BIT(OPEN_ARGS_SHARE_ACCESS_WANT_ANY_DELEG)		| \
+					 BIT(OPEN_ARGS_SHARE_ACCESS_WANT_NO_DELEG)		| \
+					 BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL))
+
+#define NFSD_OA_OPEN_CLAIM	(BIT(OPEN_ARGS_OPEN_CLAIM_NULL)		| \
+				 BIT(OPEN_ARGS_OPEN_CLAIM_PREVIOUS)	| \
+				 BIT(OPEN_ARGS_OPEN_CLAIM_DELEGATE_CUR)	| \
+				 BIT(OPEN_ARGS_OPEN_CLAIM_DELEGATE_PREV)| \
+				 BIT(OPEN_ARGS_OPEN_CLAIM_FH)		| \
+				 BIT(OPEN_ARGS_OPEN_CLAIM_DELEG_CUR_FH)	| \
+				 BIT(OPEN_ARGS_OPEN_CLAIM_DELEG_PREV_FH))
+
+#define NFSD_OA_CREATE_MODE	(BIT(OPEN_ARGS_CREATEMODE_UNCHECKED4)	| \
+				 BIT(OPEN_ARGS_CREATE_MODE_GUARDED)	| \
+				 BIT(OPEN_ARGS_CREATEMODE_EXCLUSIVE4)	| \
+				 BIT(OPEN_ARGS_CREATE_MODE_EXCLUSIVE4_1))
+
+static __be32 nfsd4_encode_fattr4_open_arguments(struct xdr_stream *xdr,
+						 const struct nfsd4_fattr_args *args)
+{
+	uint32_t oa_share_access = NFSD_OA_SHARE_ACCESS;
+	uint32_t oa_share_deny = NFSD_OA_SHARE_DENY;
+	uint32_t oa_share_access_want = NFSD_OA_SHARE_ACCESS_WANT;
+	uint32_t oa_open_claim = NFSD_OA_OPEN_CLAIM;
+	uint32_t oa_create_mode = NFSD_OA_CREATE_MODE;
+	struct open_arguments4 oa;
+
+	oa.oa_share_access.count = 1;
+	oa.oa_share_access.element = &oa_share_access;
+	oa.oa_share_deny.count = 1;
+	oa.oa_share_deny.element = &oa_share_deny;
+	oa.oa_share_access_want.count = 1;
+	oa.oa_share_access_want.element = &oa_share_access_want;
+	oa.oa_open_claim.count = 1;
+	oa.oa_open_claim.element = &oa_open_claim;
+	oa.oa_create_mode.count = 1;
+	oa.oa_create_mode.element = &oa_create_mode;
+
+	if (!xdrgen_encode_fattr4_open_arguments(xdr, &oa))
+		return nfserr_resource;
+	return nfs_ok;
+}
+
 static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
 	[FATTR4_SUPPORTED_ATTRS]	= nfsd4_encode_fattr4_supported_attrs,
 	[FATTR4_TYPE]			= nfsd4_encode_fattr4_type,
@@ -3500,6 +3552,7 @@  static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
 
 	[FATTR4_MODE_UMASK]		= nfsd4_encode_fattr4__noop,
 	[FATTR4_XATTR_SUPPORT]		= nfsd4_encode_fattr4_xattr_support,
+	[FATTR4_OPEN_ARGUMENTS]		= nfsd4_encode_fattr4_open_arguments,
 };
 
 /*
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 4ccbf014a2c7..c98fb104ba7d 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -454,7 +454,8 @@  enum {
 	(NFSD4_1_SUPPORTED_ATTRS_WORD2 | \
 	FATTR4_WORD2_MODE_UMASK | \
 	NFSD4_2_SECURITY_ATTRS | \
-	FATTR4_WORD2_XATTR_SUPPORT)
+	FATTR4_WORD2_XATTR_SUPPORT | \
+	FATTR4_WORD2_OPEN_ARGUMENTS)
 
 extern const u32 nfsd_suppattrs[3][3];