Skip to contentSkip to conversation

nfsd: implement the "delstid" draft

PATCH Superseded Jeff Layton 3 participants 11 messages Aug 26, 2024 – Aug 30, 2024

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

v2 cover nfsd: implement the "delstid" draft

This adds support for most of the "delstid" draft:

https://datatracker.ietf.org/doc/draft-ietf-nfsv4-delstid/06/

This includes a number of new features around the OPEN call:

- support for FATTR4_OPEN_ARGUMENTS: A new way for clients to discover what OPEN features the server supports at mount time.

- support for OPEN_XOR_DELEGATION: The server can send only a delegation stateid in response to an OPEN (avoiding the useless open stateid in that case).

- support for delegated timestamps: when the client holds a write delegation, it can send an updated atime and mtime in the CB_GETATTR response

FATTR4_OFFLINE is not implemented, since we don't have a way to designate that under Linux. [1]

This patchset depends on a number of patchsets still in flight:
- the multigrain timestamp series [2] (in Christian's vfs.mgtime branch)
- the nfsd CB_GETATTR fixes [3][4] (in Chuck's nfsd-fixes branch)
- Chuck's xdrgen patches [5] (in Chuck's lkxdrgen branch)

If you want to test this functionality, you'll also need client-side patches that went into v6.11-rc5 [6][7].

I should make special mention of patch #2, which starts integrating the xdrgenerated header. That will affect both the client and server, so I want to make sure everyone (Trond and Anna, in particular) is on board with this scheme before we merge it.

For now, that patch just moves the header from where it was in Chuck's tree, but it'd probably be better to add a new "make xdrgen" target for that, long term.

[1]: We could add a STATX_ATTR_OFFLINE flag for this, but the userland
use-cases are not 100% clear to me.
[2]: https://lore.kernel.org/linux-fsdevel/[email protected]/
[3]: https://lore.kernel.org/linux-nfs/Zsoe%[email protected]/T/#t
[4]: https://lore.kernel.org/linux-nfs/[email protected]/T/#t
[5]: https://lore.kernel.org/linux-nfs/[email protected]/T/#me0207d0b18c19ddbf1cf698acff7e591bb4b100c
[6]: https://lore.kernel.org/linux-nfs/[email protected]/
[7]: https://lore.kernel.org/linux-nfs/[email protected]/

---
Changes in v2:
- rebase onto Chuck's lkxdrgen branch, and reworked how autogenerated code is included
- declare nfsd_open_arguments as a global, so it doesn't have to be
set up on the stack each time
- delegated timestamp support has been added
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Jeff Layton (7):
nfsd: add pragma public to delegated timestamp types
nfs_common: make nfs4.h include generated nfs4_1.h
nfsd: add support for FATTR4_OPEN_ARGUMENTS
nfsd: implement OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION
fs: add an ATTR_CTIME_DLG flag
nfsd: drop the ncf_cb_bmap field
nfsd: add support for delegated timestamps

 {fs/nfsd => Documentation/sunrpc/xdr}/nfs4_1.x     |   2 +
 fs/attr.c                                          |  10 +-
 fs/nfsd/Makefile                                   |   2 +-
 fs/nfsd/nfs4callback.c                             |  43 +++++++-
 fs/nfsd/nfs4state.c                                | 115 +++++++++++++++++++--
 fs/nfsd/nfs4xdr.c                                  |  53 +++++++++-
 fs/nfsd/nfs4xdr_gen.c                              |  12 +--
 fs/nfsd/nfsd.h                                     |   6 +-
 fs/nfsd/state.h                                    |   4 +-
 fs/nfsd/xdr4cb.h                                   |  10 +-
 include/linux/fs.h                                 |   1 +
 include/linux/nfs4.h                               |   7 +-
 include/linux/nfs_xdr.h                            |   5 -
 .../linux/sunrpc/xdrgen/nfs4_1.h                   |  14 ++-
 include/uapi/linux/nfs4.h                          |   7 +-
 15 files changed, 244 insertions(+), 47 deletions(-)

---
base-commit: 55f9aa30de14b6ec52940adeb4790c15247fed40
change-id: 20240815-delstid-93290691ad11

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/7 nfsd: add pragma public to delegated timestamp types

In a later patch we're going to need the ability to decode the delegated timestamp fields. Make the decoders available for the delgated timestamp types, and regenerate the source and header files.

---
 fs/nfsd/nfs4_1.x      |  2 ++
 fs/nfsd/nfs4xdr_gen.c | 10 +++++-----
 fs/nfsd/nfs4xdr_gen.h |  8 +++++++-
 3 files changed, 14 insertions(+), 6 deletions(-)
fs/nfsd/nfs4_1.x +2 -0
index d2fde450de5e..fc37d1ecba0f 100644
@@ -150,6 +150,8 @@ const OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010;
  */
 typedef nfstime4        fattr4_time_deleg_access;
 typedef nfstime4        fattr4_time_deleg_modify;
+pragma public 		fattr4_time_deleg_access;
+pragma public		fattr4_time_deleg_modify;
 
 
 %/*
fs/nfsd/nfs4xdr_gen.c +5 -5
index c22372144a57..0816cfa530e0 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 // Generated by xdrgen. Manual edits will be lost.
-// XDR specification modification time: Fri Aug 23 17:28:09 2024
+// XDR specification modification time: Fri Aug 23 18:57:46 2024
 
 #include "nfs4xdr_gen.h"
 
@@ -120,13 +120,13 @@ xdrgen_decode_fattr4_open_arguments(struct xdr_stream *xdr, fattr4_open_argument
 	return xdrgen_decode_open_arguments4(xdr, ptr);
 };
 
-static bool __maybe_unused
+bool
 xdrgen_decode_fattr4_time_deleg_access(struct xdr_stream *xdr, fattr4_time_deleg_access *ptr)
 {
 	return xdrgen_decode_nfstime4(xdr, ptr);
 };
 
-static bool __maybe_unused
+bool
 xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg_modify *ptr)
 {
 	return xdrgen_decode_nfstime4(xdr, ptr);
@@ -223,13 +223,13 @@ xdrgen_encode_fattr4_open_arguments(struct xdr_stream *xdr, const fattr4_open_ar
 	return xdrgen_encode_open_arguments4(xdr, value);
 };
 
-static bool __maybe_unused
+bool
 xdrgen_encode_fattr4_time_deleg_access(struct xdr_stream *xdr, const fattr4_time_deleg_access *value)
 {
 	return xdrgen_encode_nfstime4(xdr, value);
 };
 
-static bool __maybe_unused
+bool
 xdrgen_encode_fattr4_time_deleg_modify(struct xdr_stream *xdr, const fattr4_time_deleg_modify *value)
 {
 	return xdrgen_encode_nfstime4(xdr, value);
fs/nfsd/nfs4xdr_gen.h +7 -1
index 48da108a2427..e79935f973ff 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /* Generated by xdrgen. Manual edits will be lost. */
-/* XDR specification modification time: Fri Aug 23 17:28:09 2024 */
+/* XDR specification modification time: Fri Aug 23 18:57:46 2024 */
 
 #ifndef _LINUX_NFS4_XDRGEN_H
 #define _LINUX_NFS4_XDRGEN_H
@@ -88,8 +88,14 @@ enum { OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION = 0x200000 };
 enum { OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010 };
 
 typedef struct nfstime4 fattr4_time_deleg_access;
+bool xdrgen_decode_fattr4_time_deleg_access(struct xdr_stream *xdr, fattr4_time_deleg_access *ptr);
+bool xdrgen_encode_fattr4_time_deleg_access(struct xdr_stream *xdr, const fattr4_time_deleg_access *value);
+
 
 typedef struct nfstime4 fattr4_time_deleg_modify;
+bool xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg_modify *ptr);
+bool xdrgen_encode_fattr4_time_deleg_modify(struct xdr_stream *xdr, const fattr4_time_deleg_modify *value);
+
 
 enum { FATTR4_TIME_DELEG_ACCESS = 84 };
 
Signature · 1 line
2.46.0
author maintainer
#2 lore raw

PATCH v2 2/7 nfs_common: make nfs4.h include generated nfs4_1.h

In reply to Jeff Layton

Long term, we'd like to move to autogenerating a lot of our XDR code. Both the client and server include include/linux/nfs4.h. That file is hand-rolled and some of the symbols in it conflict with the autogenerated symbols from the spec.

Move nfs4_1.x to Documentation/sunrpc/xdr. Create a new include/linux/sunrpc/xdrgen directory in which we can keep autogenerated header files. Move the new, generated nfs4xdr_gen.h file to nfs4_1.h in that directory. Have include/linux/nfs4.h include the newly renamed file and then remove conflicting definitions from it and nfs_xdr.h.

For now, the .x file from which we're generating the header is fairly small and just covers the delstid draft, but we can expand that in the future and just remove conflicting definitions as we go.

---
 {fs/nfsd => Documentation/sunrpc/xdr}/nfs4_1.x                | 0
 fs/nfsd/nfs4xdr_gen.c                                         | 2 +-
 include/linux/nfs4.h                                          | 7 +------
 include/linux/nfs_xdr.h                                       | 5 -----
 fs/nfsd/nfs4xdr_gen.h => include/linux/sunrpc/xdrgen/nfs4_1.h | 6 +++---
 5 files changed, 5 insertions(+), 15 deletions(-)
Documentation/sunrpc/xdr/nfs4_1.x renamed from fs/nfsd/nfs4_1.x +0 -0
similarity index 100%
rename from fs/nfsd/nfs4_1.x
rename to Documentation/sunrpc/xdr/nfs4_1.x
fs/nfsd/nfs4xdr_gen.c +1 -1
index 0816cfa530e0..3e55dd1e6530 100644
@@ -2,7 +2,7 @@
 // Generated by xdrgen. Manual edits will be lost.
 // XDR specification modification time: Fri Aug 23 18:57:46 2024
 
-#include "nfs4xdr_gen.h"
+#include <linux/sunrpc/xdrgen/nfs4.h>
 
 static bool __maybe_unused
 xdrgen_decode_int64_t(struct xdr_stream *xdr, int64_t *ptr)
include/linux/nfs4.h +1 -6
index 8d7430d9f218..b90719244775 100644
@@ -17,6 +17,7 @@
 #include <linux/uidgid.h>
 #include <uapi/linux/nfs4.h>
 #include <linux/sunrpc/msg_prot.h>
+#include <linux/sunrpc/xdrgen/nfs4_1.h>
 
 enum nfs4_acl_whotype {
 	NFS4_ACL_WHO_NAMED = 0,
@@ -512,12 +513,6 @@ enum {
 	FATTR4_XATTR_SUPPORT		= 82,
 };
 
-enum {
-	FATTR4_TIME_DELEG_ACCESS	= 84,
-	FATTR4_TIME_DELEG_MODIFY	= 85,
-	FATTR4_OPEN_ARGUMENTS		= 86,
-};
-
 /*
  * The following internal definitions enable processing the above
  * attribute bits within 32-bit word boundaries.
include/linux/nfs_xdr.h +0 -5
index 45623af3e7b8..d3fe47baf110 100644
@@ -1315,11 +1315,6 @@ struct nfs4_fsid_present_res {
 
 #endif /* CONFIG_NFS_V4 */
 
-struct nfstime4 {
-	u64	seconds;
-	u32	nseconds;
-};
-
 #ifdef CONFIG_NFS_V4_1
 
 struct pnfs_commit_bucket {
include/linux/sunrpc/xdrgen/nfs4_1.h renamed from fs/nfsd/nfs4xdr_gen.h +3 -3
similarity index 96%
rename from fs/nfsd/nfs4xdr_gen.h
rename to include/linux/sunrpc/xdrgen/nfs4_1.h
index e79935f973ff..0272c2ee8739 100644
@@ -2,8 +2,8 @@
 /* Generated by xdrgen. Manual edits will be lost. */
 /* XDR specification modification time: Fri Aug 23 18:57:46 2024 */
 
-#ifndef _LINUX_NFS4_XDRGEN_H
-#define _LINUX_NFS4_XDRGEN_H
+#ifndef _LINUX_XDRGEN_NFS4_H
+#define _LINUX_XDRGEN_NFS4_H
 
 #include <linux/types.h>
 #include <linux/sunrpc/svc.h>
@@ -103,4 +103,4 @@ enum { FATTR4_TIME_DELEG_MODIFY = 85 };
 
 enum { OPEN4_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS = 0x100000 };
 
-#endif /* _LINUX_NFS4_XDRGEN_H */
+#endif /* _LINUX_XDRGEN_NFS4_H */
Signature · 1 line
2.46.0
author maintainer
#3 lore raw

PATCH v2 3/7 nfsd: add support for FATTR4_OPEN_ARGUMENTS

In reply to Jeff Layton

Add support for FATTR4_OPEN_ARGUMENTS. This a new mechanism for the client to discover what OPEN features the server supports.

---
 fs/nfsd/Makefile  |  2 +-
 fs/nfsd/nfs4xdr.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfsd/nfsd.h    |  3 ++-
 3 files changed, 52 insertions(+), 2 deletions(-)
fs/nfsd/Makefile +1 -1
index b8736a82e57c..d6ab3ae7d0a0 100644
@@ -18,7 +18,7 @@ nfsd-$(CONFIG_NFSD_V2) += nfsproc.o nfsxdr.o
 nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o
 nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o
 nfsd-$(CONFIG_NFSD_V4)	+= nfs4proc.o nfs4xdr.o nfs4state.o nfs4idmap.o \
-			   nfs4acl.o nfs4callback.o nfs4recover.o
+			   nfs4acl.o nfs4callback.o nfs4recover.o nfs4xdr_gen.o
 nfsd-$(CONFIG_NFSD_PNFS) += nfs4layouts.o
 nfsd-$(CONFIG_NFSD_BLOCKLAYOUT) += blocklayout.o blocklayoutxdr.o
 nfsd-$(CONFIG_NFSD_SCSILAYOUT) += blocklayout.o blocklayoutxdr.o
fs/nfsd/nfs4xdr.c +49 -0

61 lines not on this page · raw message

fs/nfsd/nfsd.h +2 -1
index 4ccbf014a2c7..c98fb104ba7d 100644
@@ -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];
 
Signature · 1 line
2.46.0
author maintainer
#5 lore raw

PATCH v2 4/7 nfsd: implement OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION

In reply to Jeff Layton

Allow clients to request getting a delegation xor an open stateid if a delegation isn't available. This allows the client to avoid sending a final CLOSE for the (useless) open stateid, when it is granted a delegation.

This is done by moving the increment of the open stateid and unlocking of the st_mutex until after we acquire a delegation. If we get a delegation, we zero out the op_stateid field and set the NO_OPEN_STATEID flag. If the open stateid was brand new, then unhash it too in this case since it won't be needed.

If we can't get a delegation or the new flag wasn't requested, then just increment and copy the open stateid as usual.

---
 fs/nfsd/nfs4state.c       | 28 ++++++++++++++++++++++++----
 fs/nfsd/nfs4xdr.c         |  5 +++--
 include/uapi/linux/nfs4.h |  7 +++++--
 3 files changed, 32 insertions(+), 8 deletions(-)
fs/nfsd/nfs4state.c +24 -4
index 9fe67c412f9b..b544320246bf 100644
@@ -6029,6 +6029,17 @@ static void nfsd4_deleg_xgrade_none_ext(struct nfsd4_open *open,
 	 */
 }
 
+/* Are we only returning a delegation stateid? */
+static bool open_xor_delegation(struct nfsd4_open *open)
+{
+	if (!(open->op_deleg_want & OPEN4_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION))
+		return false;
+	if (open->op_delegate_type != NFS4_OPEN_DELEGATE_READ &&
+	    open->op_delegate_type != NFS4_OPEN_DELEGATE_WRITE)
+		return false;
+	return true;
+}
+
 /**
  * nfsd4_process_open2 - finish open processing
  * @rqstp: the RPC transaction being executed
@@ -6051,6 +6062,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
 	struct nfs4_delegation *dp = NULL;
 	__be32 status;
 	bool new_stp = false;
+	bool deleg_only = false;
 
 	/*
 	 * Lookup file; if found, lookup stateid and check open request,
@@ -6105,9 +6117,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
 			open->op_odstate = NULL;
 	}
 
-	nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid);
-	mutex_unlock(&stp->st_mutex);
-
 	if (nfsd4_has_session(&resp->cstate)) {
 		if (open->op_deleg_want & NFS4_SHARE_WANT_NO_DELEG) {
 			open->op_delegate_type = NFS4_OPEN_DELEGATE_NONE_EXT;
@@ -6121,7 +6130,18 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
 	* OPEN succeeds even if we fail.
 	*/
 	nfs4_open_delegation(open, stp, &resp->cstate.current_fh);
+	deleg_only = open_xor_delegation(open);
 nodeleg:
+	if (deleg_only) {
+		memcpy(&open->op_stateid, &zero_stateid, sizeof(open->op_stateid));
+		open->op_rflags |= OPEN4_RESULT_NO_OPEN_STATEID;
+		if (new_stp)
+			release_open_stateid(stp);
+	} else {
+		nfs4_inc_and_copy_stateid(&open->op_stateid, &stp->st_stid);
+	}
+	mutex_unlock(&stp->st_mutex);
+
 	status = nfs_ok;
 	trace_nfsd_open(&stp->st_stid.sc_stateid);
 out:
@@ -6137,7 +6157,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
 	/*
 	* To finish the open response, we just need to set the rflags.
 	*/
-	open->op_rflags = NFS4_OPEN_RESULT_LOCKTYPE_POSIX;
+	open->op_rflags |= NFS4_OPEN_RESULT_LOCKTYPE_POSIX;
 	if (nfsd4_has_session(&resp->cstate))
 		open->op_rflags |= NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK;
 	else if (!(open->op_openowner->oo_flags & NFS4_OO_CONFIRMED))
fs/nfsd/nfs4xdr.c +3 -2
index 1c8219ea8af7..8266f910d847 100644
@@ -1066,7 +1066,7 @@ static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *sh
 		return nfs_ok;
 	if (!argp->minorversion)
 		return nfserr_bad_xdr;
-	switch (w & NFS4_SHARE_WANT_MASK) {
+	switch (w & NFS4_SHARE_WANT_TYPE_MASK) {
 	case NFS4_SHARE_WANT_NO_PREFERENCE:
 	case NFS4_SHARE_WANT_READ_DELEG:
 	case NFS4_SHARE_WANT_WRITE_DELEG:
@@ -3410,7 +3410,8 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr,
 
 #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))
+					 BIT(OPEN_ARGS_SHARE_ACCESS_WANT_CANCEL)		| \
+					 BIT(OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION))
 
 #define NFSD_OA_OPEN_CLAIM	(BIT(OPEN_ARGS_OPEN_CLAIM_NULL)		| \
 				 BIT(OPEN_ARGS_OPEN_CLAIM_PREVIOUS)	| \
include/uapi/linux/nfs4.h +5 -2
index caf4db2fcbb9..4273e0249fcb 100644
@@ -58,7 +58,7 @@
 #define NFS4_SHARE_DENY_BOTH	0x0003
 
 /* nfs41 */
-#define NFS4_SHARE_WANT_MASK		0xFF00
+#define NFS4_SHARE_WANT_TYPE_MASK	0xFF00
 #define NFS4_SHARE_WANT_NO_PREFERENCE	0x0000
 #define NFS4_SHARE_WANT_READ_DELEG	0x0100
 #define NFS4_SHARE_WANT_WRITE_DELEG	0x0200
@@ -66,13 +66,16 @@
 #define NFS4_SHARE_WANT_NO_DELEG	0x0400
 #define NFS4_SHARE_WANT_CANCEL		0x0500
 
-#define NFS4_SHARE_WHEN_MASK		0xF0000
+#define NFS4_SHARE_WHEN_MASK				0xF0000
 #define NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL	0x10000
 #define NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED		0x20000
 
+#define NFS4_SHARE_WANT_MOD_MASK			0xF00000
 #define NFS4_SHARE_WANT_DELEG_TIMESTAMPS		0x100000
 #define NFS4_SHARE_WANT_OPEN_XOR_DELEGATION		0x200000
 
+#define NFS4_SHARE_WANT_MASK	(NFS4_SHARE_WANT_TYPE_MASK | NFS4_SHARE_WANT_MOD_MASK)
+
 #define NFS4_CDFC4_FORE	0x1
 #define NFS4_CDFC4_BACK 0x2
 #define NFS4_CDFC4_BOTH 0x3
Signature · 1 line
2.46.0
author maintainer
#6 lore raw

PATCH v2 5/7 fs: add an ATTR_CTIME_DLG flag

In reply to Jeff Layton

When updating the ctime on an inode for a setattr with a multigrain filesystem, we usually want to take the latest time we can get for the ctime. The exception to this rule is when there is a nfsd write delegation and the server is proxying timestamps from the client.

When nfsd gets a CB_GETATTR response, we want to update the timestamp value in the inode to the values that the client is tracking. The client doesn't send a ctime value (since that's always determined by the exported filesystem), but it does send a mtime value. In the case where it does, then we may also need to update the ctime to a value commensurate with that.

Add a ATTR_CTIME_DELEG flag, which tells the underlying setattr machinery to respect that value and not to set it to the current time.

---
 fs/attr.c          | 10 +++++++++-
 include/linux/fs.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)
fs/attr.c +9 -1
index 7144b207e715..0eb7b228b94d 100644
@@ -295,7 +295,15 @@ static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr)
 		return;
 	}
 
-	now = inode_set_ctime_current(inode);
+	/*
+	 * In the case of an update for a write delegation, we must respect
+	 * the value in ia_ctime and not use the current time.
+	 */
+	if (ia_valid & ATTR_CTIME_DLG)
+		inode_set_ctime_to_ts(inode, attr->ia_ctime);
+	else
+		now = inode_set_ctime_current(inode);
+
 	if (ia_valid & ATTR_ATIME_SET)
 		inode_set_atime_to_ts(inode, attr->ia_atime);
 	else if (ia_valid & ATTR_ATIME)
include/linux/fs.h +1 -0
index 7c1da3c687bd..43a802b2cb0d 100644
@@ -211,6 +211,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 #define ATTR_TIMES_SET	(1 << 16)
 #define ATTR_TOUCH	(1 << 17)
 #define ATTR_DELEG	(1 << 18) /* Delegated attrs (don't break) */
+#define ATTR_CTIME_DLG	(1 << 19) /* Delegation in effect */
 
 /*
  * Whiteout is represented by a char device.  The following constants define the
Signature · 1 line
2.46.0
author maintainer
#9 lore raw

PATCH v2 6/7 nfsd: drop the ncf_cb_bmap field

In reply to Jeff Layton

This is always the same value, and in a later patch we're going to need to set bits in WORD2. We can simplify this code and save a little space in the delegation too. Just hardcode the bitmap in the callback encode function.

---
 fs/nfsd/nfs4callback.c | 5 ++++-
 fs/nfsd/nfs4state.c    | 1 -
 fs/nfsd/state.h        | 1 -
 3 files changed, 4 insertions(+), 3 deletions(-)
fs/nfsd/nfs4callback.c +4 -1
index d756f443fc44..988232086589 100644
@@ -364,10 +364,13 @@ encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr,
 	struct nfs4_delegation *dp =
 		container_of(fattr, struct nfs4_delegation, dl_cb_fattr);
 	struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle;
+	u32 bmap[1];
+
+	bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE;
 
 	encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR);
 	encode_nfs_fh4(xdr, fh);
-	encode_bitmap4(xdr, fattr->ncf_cb_bmap, ARRAY_SIZE(fattr->ncf_cb_bmap));
+	encode_bitmap4(xdr, bmap, ARRAY_SIZE(bmap));
 	hdr->nops++;
 }
 
fs/nfsd/nfs4state.c +0 -1
index b544320246bf..f353aeb4cc0a 100644
@@ -1182,7 +1182,6 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_file *fp,
 	nfsd4_init_cb(&dp->dl_cb_fattr.ncf_getattr, dp->dl_stid.sc_client,
 			&nfsd4_cb_getattr_ops, NFSPROC4_CLNT_CB_GETATTR);
 	dp->dl_cb_fattr.ncf_file_modified = false;
-	dp->dl_cb_fattr.ncf_cb_bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE;
 	get_nfs4_file(fp);
 	dp->dl_stid.sc_file = fp;
 	return dp;
fs/nfsd/state.h +0 -1
index ec4559ecd193..65691457d9ba 100644
@@ -137,7 +137,6 @@ struct nfs4_cpntf_state {
 struct nfs4_cb_fattr {
 	struct nfsd4_callback ncf_getattr;
 	u32 ncf_cb_status;
-	u32 ncf_cb_bmap[1];
 
 	/* from CB_GETATTR reply */
 	u64 ncf_cb_change;
Signature · 1 line
2.46.0
author maintainer
#10 lore raw

PATCH v2 7/7 nfsd: add support for delegated timestamps

In reply to Jeff Layton

Add support for the delegated timestamps on write delegations. This allows the server to proxy timestamps from the delegation holder to other clients that are doing GETATTRs vs. the same inode.

Add a new flag to nfs4_delegation for indicating that the client can provide timestamps in the CB_GETATTR response. Set that when the client sets the appropriate flag in the open request.

Add timespec64 fields to nfs4_cb_fattr and decode the timestamps into those. Vet those timestamps according to the delstid spec and update the inode attrs if necessary.

For multigrain timestamps, ensure that we accept the client's version of the ctime instead of updating to the latest clock as we normally would. That should be fine since the client holds a delegation, and nothing else will be making changes.

---
 fs/nfsd/nfs4callback.c | 42 +++++++++++++++++++++---
 fs/nfsd/nfs4state.c    | 86 ++++++++++++++++++++++++++++++++++++++++++++++----
 fs/nfsd/nfs4xdr.c      |  1 +
 fs/nfsd/nfsd.h         |  3 +-
 fs/nfsd/state.h        |  3 ++
 fs/nfsd/xdr4cb.h       | 10 ++++--
 6 files changed, 130 insertions(+), 15 deletions(-)
fs/nfsd/nfs4callback.c +37 -5
index 988232086589..d5004790f2b1 100644
@@ -93,12 +93,35 @@ static int decode_cb_fattr4(struct xdr_stream *xdr, uint32_t *bitmap,
 {
 	fattr->ncf_cb_change = 0;
 	fattr->ncf_cb_fsize = 0;
+	fattr->ncf_cb_atime.tv_sec = 0;
+	fattr->ncf_cb_atime.tv_nsec = 0;
+	fattr->ncf_cb_mtime.tv_sec = 0;
+	fattr->ncf_cb_mtime.tv_nsec = 0;
+
 	if (bitmap[0] & FATTR4_WORD0_CHANGE)
 		if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_change) < 0)
 			return -NFSERR_BAD_XDR;
 	if (bitmap[0] & FATTR4_WORD0_SIZE)
 		if (xdr_stream_decode_u64(xdr, &fattr->ncf_cb_fsize) < 0)
 			return -NFSERR_BAD_XDR;
+	if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_ACCESS) {
+		fattr4_time_deleg_access access;
+
+		if (!xdrgen_decode_fattr4_time_deleg_access(xdr, &access))
+			return -NFSERR_BAD_XDR;
+		fattr->ncf_cb_atime.tv_sec = access.seconds;
+		fattr->ncf_cb_atime.tv_nsec = access.nseconds;
+
+	}
+	if (bitmap[2] & FATTR4_WORD2_TIME_DELEG_MODIFY) {
+		fattr4_time_deleg_modify modify;
+
+		if (!xdrgen_decode_fattr4_time_deleg_modify(xdr, &modify))
+			return -NFSERR_BAD_XDR;
+		fattr->ncf_cb_mtime.tv_sec = modify.seconds;
+		fattr->ncf_cb_mtime.tv_nsec = modify.nseconds;
+
+	}
 	return 0;
 }
 
@@ -364,13 +387,18 @@ encode_cb_getattr4args(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr,
 	struct nfs4_delegation *dp =
 		container_of(fattr, struct nfs4_delegation, dl_cb_fattr);
 	struct knfsd_fh *fh = &dp->dl_stid.sc_file->fi_fhandle;
-	u32 bmap[1];
+	u32 bmap[3];
+	u32 bmap_size = 1;
 
 	bmap[0] = FATTR4_WORD0_CHANGE | FATTR4_WORD0_SIZE;
-
+	if (dp->dl_deleg_ts) {
+		bmap[1] = 0;
+		bmap[2] = FATTR4_WORD2_TIME_DELEG_ACCESS | FATTR4_WORD2_TIME_DELEG_MODIFY;
+		bmap_size = 3;
+	}
 	encode_nfs_cb_opnum4(xdr, OP_CB_GETATTR);
 	encode_nfs_fh4(xdr, fh);
-	encode_bitmap4(xdr, bmap, ARRAY_SIZE(bmap));
+	encode_bitmap4(xdr, bmap, bmap_size);
 	hdr->nops++;
 }
 
@@ -595,7 +623,7 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp,
 	struct nfs4_cb_compound_hdr hdr;
 	int status;
 	u32 bitmap[3] = {0};
-	u32 attrlen;
+	u32 attrlen, maxlen;
 	struct nfs4_cb_fattr *ncf =
 		container_of(cb, struct nfs4_cb_fattr, ncf_getattr);
 
@@ -614,7 +642,11 @@ static int nfs4_xdr_dec_cb_getattr(struct rpc_rqst *rqstp,
 		return -NFSERR_BAD_XDR;
 	if (xdr_stream_decode_u32(xdr, &attrlen) < 0)
 		return -NFSERR_BAD_XDR;
-	if (attrlen > (sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize)))
+	maxlen = sizeof(ncf->ncf_cb_change) + sizeof(ncf->ncf_cb_fsize);
+	if (bitmap[2] != 0)
+		maxlen += (sizeof(ncf->ncf_cb_mtime.tv_sec) +
+			   sizeof(ncf->ncf_cb_mtime.tv_nsec)) * 2;
+	if (attrlen > maxlen)
 		return -NFSERR_BAD_XDR;
 	status = decode_cb_fattr4(xdr, bitmap, ncf);
 	return status;
fs/nfsd/nfs4state.c +80 -6

110 lines not on this page · raw message

fs/nfsd/nfs4xdr.c +1 -0
index 8266f910d847..c79f7402bc30 100644
@@ -3411,6 +3411,7 @@ static __be32 nfsd4_encode_fattr4_xattr_support(struct xdr_stream *xdr,
 #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)		| \
+					 BIT(OPEN_ARGS_SHARE_ACCESS_WANT_DELEG_TIMESTAMPS)	| \
 					 BIT(OPEN_ARGS_SHARE_ACCESS_WANT_OPEN_XOR_DELEGATION))
 
 #define NFSD_OA_OPEN_CLAIM	(BIT(OPEN_ARGS_OPEN_CLAIM_NULL)		| \
fs/nfsd/nfsd.h +2 -1
index c98fb104ba7d..2d89b82e5453 100644
@@ -421,7 +421,8 @@ enum {
  | FATTR4_WORD1_TIME_DELTA      | FATTR4_WORD1_TIME_METADATA   | FATTR4_WORD1_TIME_CREATE      \
  | FATTR4_WORD1_TIME_MODIFY     | FATTR4_WORD1_TIME_MODIFY_SET | FATTR4_WORD1_MOUNTED_ON_FILEID)
 
-#define NFSD4_SUPPORTED_ATTRS_WORD2 0
+#define NFSD4_SUPPORTED_ATTRS_WORD2 (FATTR4_WORD2_TIME_DELEG_MODIFY | \
+				     FATTR4_WORD2_TIME_DELEG_ACCESS)
 
 /* 4.1 */
 #ifdef CONFIG_NFSD_PNFS
fs/nfsd/state.h +3 -0
index 65691457d9ba..b2ffb7d36721 100644
@@ -141,6 +141,8 @@ struct nfs4_cb_fattr {
 	/* from CB_GETATTR reply */
 	u64 ncf_cb_change;
 	u64 ncf_cb_fsize;
+	struct timespec64 ncf_cb_mtime;
+	struct timespec64 ncf_cb_atime;
 
 	unsigned long ncf_cb_flags;
 	bool ncf_file_modified;
@@ -184,6 +186,7 @@ struct nfs4_delegation {
 	int			dl_retries;
 	struct nfsd4_callback	dl_recall;
 	bool			dl_recalled;
+	bool			dl_deleg_ts;
 
 	/* for CB_GETATTR */
 	struct nfs4_cb_fattr    dl_cb_fattr;
fs/nfsd/xdr4cb.h +7 -3
index e8b00309c449..f1a315cd31b7 100644
@@ -59,16 +59,20 @@
  * 1: CB_GETATTR opcode (32-bit)
  * N: file_handle
  * 1: number of entry in attribute array (32-bit)
- * 1: entry 0 in attribute array (32-bit)
+ * 3: entry 0-2 in attribute array (32-bit * 3)
  */
 #define NFS4_enc_cb_getattr_sz		(cb_compound_enc_hdr_sz +       \
 					cb_sequence_enc_sz +            \
-					1 + enc_nfs4_fh_sz + 1 + 1)
+					1 + enc_nfs4_fh_sz + 1 + 3)
 /*
  * 4: fattr_bitmap_maxsz
  * 1: attribute array len
  * 2: change attr (64-bit)
  * 2: size (64-bit)
+ * 2: atime.seconds (64-bit)
+ * 1: atime.nanoseconds (32-bit)
+ * 2: mtime.seconds (64-bit)
+ * 1: mtime.nanoseconds (32-bit)
  */
 #define NFS4_dec_cb_getattr_sz		(cb_compound_dec_hdr_sz  +      \
-			cb_sequence_dec_sz + 4 + 1 + 2 + 2 + op_dec_sz)
+			cb_sequence_dec_sz + 4 + 1 + 2 + 2 + 2 + 1 + 2 + 1 + op_dec_sz)
Signature · 1 line
2.46.0
#7 lore raw

Re: [PATCH v2 5/7] fs: add an ATTR_CTIME_DLG flag

In reply to Jeff Layton
Quoted 5 lines · Jeff Layton

When updating the ctime on an inode for a setattr with a multigrain filesystem, we usually want to take the latest time we can get for the ctime. The exception to this rule is when there is a nfsd write delegation and the server is proxying timestamps from the client.

Quoted 8 lines

When nfsd gets a CB_GETATTR response, we want to update the timestamp value in the inode to the values that the client is tracking. The client doesn't send a ctime value (since that's always determined by the exported filesystem), but it does send a mtime value. In the case where it does, then we may also need to update the ctime to a value commensurate with that.

Add a ATTR_CTIME_DELEG flag, which tells the underlying setattr

Fwiw: disconnect between commit message and actually used ATTR_CTIME_DLG.

Quoted 4 lines

machinery to respect that value and not to set it to the current time.

---

Are you set on sending us on a mission to free up ATTR_* bits after freeing up FMODE_* bits? ;)

If there's going to be more ATTR_*DELEG* flags that modify the behavior when delegation is in effect then we could consider adding another unsigned int ia_deleg field to struct iattr so that you can check:

if (ia_valid & ATTR_CTIME) {
	if (unlikely(iattr->ia_deleg & ATTR_CTIME))
		// do some special stuff
	else
		// do the regular stuff
}

or some such variant.

Quoted 30 lines
 fs/attr.c          | 10 +++++++++-
 include/linux/fs.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)
fs/attr.c +9 -1
index 7144b207e715..0eb7b228b94d 100644
@@ -295,7 +295,15 @@ static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr)
 		return;
 	}
 
-	now = inode_set_ctime_current(inode);
+	/*
+	 * In the case of an update for a write delegation, we must respect
+	 * the value in ia_ctime and not use the current time.
+	 */
+	if (ia_valid & ATTR_CTIME_DLG)
+		inode_set_ctime_to_ts(inode, attr->ia_ctime);
+	else
+		now = inode_set_ctime_current(inode);
+
 	if (ia_valid & ATTR_ATIME_SET)
 		inode_set_atime_to_ts(inode, attr->ia_atime);
 	else if (ia_valid & ATTR_ATIME)
include/linux/fs.h +0 -0
index 7c1da3c687bd..43a802b2cb0d 100644

include/linux/fs.h typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, · line 214

Quoted 4 lines
include/linux/fs.h +1 -0
@@ -211,6 +211,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 #define ATTR_TIMES_SET	(1 << 16)
 #define ATTR_TOUCH	(1 << 17)
 #define ATTR_DELEG	(1 << 18) /* Delegated attrs (don't break) */
+#define ATTR_CTIME_DLG	(1 << 19) /* Delegation in effect */

What's the interaction between ATTR_DELEG and ATTR_CTIME_DLG? I think that's potentially confusing.

author maintainer
#8 lore raw

Re: [PATCH v2 5/7] fs: add an ATTR_CTIME_DLG flag

Quoted 13 lines · Christian Brauner
Quoted 12 lines · Jeff Layton

When updating the ctime on an inode for a setattr with a multigrain filesystem, we usually want to take the latest time we can get for the ctime. The exception to this rule is when there is a nfsd write delegation and the server is proxying timestamps from the client.

When nfsd gets a CB_GETATTR response, we want to update the timestamp value in the inode to the values that the client is tracking. The client doesn't send a ctime value (since that's always determined by the exported filesystem), but it does send a mtime value. In the case where it does, then we may also need to update the ctime to a value commensurate with that.

Quoted 4 lines
Quoted 1 line

Add a ATTR_CTIME_DELEG flag, which tells the underlying setattr

Fwiw: disconnect between commit message and actually used ATTR_CTIME_DLG.

Thanks, will fix.

Quoted 8 lines
Quoted 4 lines

machinery to respect that value and not to set it to the current time.

---

Are you set on sending us on a mission to free up ATTR_* bits after freeing up FMODE_* bits? ;)

Those aren't usually allocated from the heap, so I wouldn't bother, but I get the jest.

Quoted 4 lines

If there's going to be more ATTR_*DELEG* flags that modify the behavior when delegation is in effect then we could consider adding another unsigned int ia_deleg field to struct iattr so that you can check:

Quoted 9 lines
if (ia_valid & ATTR_CTIME) {
	if (unlikely(iattr->ia_deleg & ATTR_CTIME))
		// do some special stuff
	else
		// do the regular stuff
}

or some such variant.

I don't forsee other flags being needed, but you never know. For now I wouldn't bother.

Quoted 29 lines
Quoted 29 lines
 fs/attr.c          | 10 +++++++++-
 include/linux/fs.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)
fs/attr.c +9 -1
index 7144b207e715..0eb7b228b94d 100644
@@ -295,7 +295,15 @@ static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr)
 		return;
 	}
 
-	now = inode_set_ctime_current(inode);
+	/*
+	 * In the case of an update for a write delegation, we must respect
+	 * the value in ia_ctime and not use the current time.
+	 */
+	if (ia_valid & ATTR_CTIME_DLG)
+		inode_set_ctime_to_ts(inode, attr->ia_ctime);
+	else
+		now = inode_set_ctime_current(inode);
+
 	if (ia_valid & ATTR_ATIME_SET)
 		inode_set_atime_to_ts(inode, attr->ia_atime);
 	else if (ia_valid & ATTR_ATIME)
include/linux/fs.h +0 -0
index 7c1da3c687bd..43a802b2cb0d 100644
Quoted 9 lines

include/linux/fs.h typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, · line 214

Quoted 5 lines
include/linux/fs.h +1 -0
@@ -211,6 +211,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 #define ATTR_TIMES_SET	(1 << 16)
 #define ATTR_TOUCH	(1 << 17)
 #define ATTR_DELEG	(1 << 18) /* Delegated attrs (don't break) */
+#define ATTR_CTIME_DLG	(1 << 19) /* Delegation in effect */

What's the interaction between ATTR_DELEG and ATTR_CTIME_DLG? I think that's potentially confusing.

Now that you mention it, I suppose we could just key off of ATTR_DELEG instead of declaring a new flag. That should be simpler to reason out for everyone. I'll respin this along those lines instead.

Thanks for the review!

Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw

Re: [PATCH v2 3/7] nfsd: add support for FATTR4_OPEN_ARGUMENTS

In reply to Jeff Layton
kernel test robot noticed the following build errors:

Hi Jeff,

kernel test robot noticed the following build errors:

[auto build test ERROR on 55f9aa30de14b6ec52940adeb4790c15247fed40]

url:    https://github.com/intel-lab-lkp/linux/commits/Jeff-Layton/nfsd-add-pragma-public-to-delegated-timestamp-types/20240826-205313
base:   55f9aa30de14b6ec52940adeb4790c15247fed40
patch link:    https://lore.kernel.org/r/20240826-delstid-v2-3-e8ab5c0e39cc%40kernel.org
patch subject: [PATCH v2 3/7] nfsd: add support for FATTR4_OPEN_ARGUMENTS
config: alpha-allyesconfig (https://download.01.org/0day-ci/archive/20240830/[email protected]/config)
compiler: alpha-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240830/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> fs/nfsd/nfs4xdr_gen.c:5:10: fatal error: linux/sunrpc/xdrgen/nfs4.h: No such file or directory

5 | #include <linux/sunrpc/xdrgen/nfs4.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

vim +5 fs/nfsd/nfs4xdr_gen.c

a5d1a86a2b739f3 Chuck Lever 2024-08-19 4
f96781780f53e55 Jeff Layton 2024-08-26 @5 #include <linux/sunrpc/xdrgen/nfs4.h> a5d1a86a2b739f3 Chuck Lever 2024-08-19 6

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki