Skip to contentSkip to conversation

nfs/nfsd: add support for localio

PATCH Superseded Mike Snitzer 3 participants 54 messages Aug 19, 2024 – Aug 22, 2024

Subsystems (5)

v12 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v12 cover nfs/nfsd: add support for localio

These latest changes are available in my git tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Significant progress was made on the entire series, I implemented all 3 changes NeilBrown suggested here:
https://marc.info/?l=linux-nfs&m=172004547710968&w=2

And Neil kindly provided review of a preliminary v12 that I then used to refine this final v12 further. Neil found the series much cleaner and approachable.

This v12 also switches the NFS client's localio code over to driving IO in terms of nfsd's nfsd_file (rather than a simple file pointer). I checked with Jeff Layton and he likes the switch to using nfsd_file (Jeff did suggest I make sure to keep struct nfsd_file completely opaque to the client). Proper use of nfsd_file provides a solid performance improvement (as detailed in the last patch's commit header) thanks especially to the nfsd filecache's GC feature (which localio now makes use of).

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).
- Verified all of Hammerspace's various sanity tests pass (this includes numerous pNFS and flexfiles tests).

Please review, I'm hopeful I've addressed any outstanding issues and that these changes worthy of being merged for v6.12. If you see something, say something ;)

Changes since v11:
- The required localio specific changes in fs/nfsd/ are much simpler (thanks to the prelim patches that update common code to support the the localio case, fs/nfsd/localio.c in particular is now very lean)
- Improved the localio protocol to address NeilBrown's issue #1. Replaced GETUUID with UUID_IS_LOCAL RPC, which inverts protocol such that client generates a nonce (shortlived single-use UUID) and proceeds to verify the server sees it in nfs_common.
- this eliminated the need to add 'struct nfsd_uuid' to nfsd_net
- Finished the RFC series NeilBrown started to introduce nfsd_file_acquire_local(), enables the use of a "fake" svc_rqst to be eliminated: https://marc.info/?l=linux-nfs&m=171980269529965&w=2
(uses auth_domain as suggested, addresses NeilBrown's issue #2)
- rpcauth_map_clnt_to_svc_cred_local now uses userns of client and from_{kuid,kgid}_munged (hopefully addresses NeilBrown's issue #3)
- Updated nfs_local_call_write() to override_creds() with the cred used by the client to open the localio file.
- To avoid localio hitting writeback deadlock (same as is done for existing loopback NFSD support in nfsd_vfs_write() function): set PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO in nfs_local_call_write() and restore current->flags before return.
- Factored nfs_stat_to_errno and nfs4_stat_to_errno out to nfs_common to eliminate localio code creating yet another copy of them. (eliminates existing duplication between fs/nfs/nfs[23]xdr.c)
- Simplified Kconfig so that NFS_LOCALIO depends on NFS_FS and NFSD_LOCALIO depends on NFSD.
- Only support localio if UNIX Authentication (AUTH_UNIX) is used.
- Improved workqueue patch to not use wait_for_completion().
- Dropped 2 prelim fs/nfs/ patches that weren't actually needed.
- Updated localio.rst to reflect the various changes listed above, also added a new "FAQ" section from Trond (which was informed by an in-person discussion about localio that Trond had with Christoph).
- Fixed "nfsd: add nfsd_file_acquire_local()" commit to work with NFSv3 (had been testing with NFSv4.2 and the fact that NFSv3 regressed due to 'nfs_ver' not being properly initialized for non-LOCALIO callers was missed.
- Fixed issue Neil reported where "When using localio, if I open, read, don't close, then try to stop the server and umount the exported filesystem I get EBUSY for the umount."
- fix by removing refcount on localio file (no longer cache open localio file in the client).
- Fixed nfsd tracepoints that were impacted by the possibility they'd be passed a NULL rqstp when using localio.
- Rebased on cel/nfsd-next (based on v6.11-rc4) to layer upon Neil's various changes that were originally motivated by LOCALIO, reduces footprint of this patchset.
- Exported nfsd_file interfaces needed to switch the nfs client's localio code over to using it.
- Switched the the nfs client's localio code over to using nfsd_file.

Thanks,
Mike

Mike Snitzer (13):
nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
nfs_common: factor out nfs4_errtbl and nfs4_stat_to_errno
nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h
nfsd: fix nfsfh tracepoints to properly handle NULL rqstp
SUNRPC: remove call_allocate() BUG_ONs
nfs_common: add NFS LOCALIO auxiliary protocol enablement
nfsd: implement server support for NFS_LOCALIO_PROGRAM
nfs: implement client support for NFS_LOCALIO_PROGRAM
nfs: add Documentation/filesystems/nfs/localio.rst
nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local
nfs_common: expose localio's required nfsd symbols to nfs client
nfs: push localio nfsd_file_put call out to client
nfs: switch client to use nfsd_file for localio

NeilBrown (3):
nfsd: factor out __fh_verify to allow NULL rqstp to be passed
nfsd: add nfsd_file_acquire_local()
SUNRPC: replace program list with program array

Trond Myklebust (4):
nfs: enable localio for non-pNFS IO
pnfs/flexfiles: enable localio support
nfs/localio: use dedicated workqueues for filesystem read and write
nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

Weston Andros Adamson (4):
SUNRPC: add rpcauth_map_clnt_to_svc_cred_local
nfsd: add localio support
nfs: pass struct file to nfs_init_pgio and nfs_init_commit
nfs: add localio support

 Documentation/filesystems/nfs/localio.rst | 255 +++++++
 fs/Kconfig                                |   3 +
 fs/nfs/Kconfig                            |  15 +
 fs/nfs/Makefile                           |   1 +
 fs/nfs/client.c                           |  15 +-
 fs/nfs/filelayout/filelayout.c            |   6 +-
 fs/nfs/flexfilelayout/flexfilelayout.c    | 142 +++-
 fs/nfs/flexfilelayout/flexfilelayout.h    |   2 +
 fs/nfs/flexfilelayout/flexfilelayoutdev.c |   6 +
 fs/nfs/inode.c                            |  57 +-
 fs/nfs/internal.h                         |  61 +-
 fs/nfs/localio.c                          | 784 ++++++++++++++++++++++
 fs/nfs/nfs2xdr.c                          |  70 +-
 fs/nfs/nfs3xdr.c                          | 108 +--
 fs/nfs/nfs4xdr.c                          |  84 +--
 fs/nfs/nfstrace.h                         |  61 ++
 fs/nfs/pagelist.c                         |  16 +-
 fs/nfs/pnfs_nfs.c                         |   2 +-
 fs/nfs/write.c                            |  12 +-
 fs/nfs_common/Makefile                    |   5 +
 fs/nfs_common/common.c                    | 134 ++++
 fs/nfs_common/nfslocalio.c                | 194 ++++++
 fs/nfsd/Kconfig                           |  15 +
 fs/nfsd/Makefile                          |   1 +
 fs/nfsd/export.c                          |   8 +-
 fs/nfsd/filecache.c                       |  90 ++-
 fs/nfsd/filecache.h                       |   5 +
 fs/nfsd/localio.c                         | 183 +++++
 fs/nfsd/netns.h                           |   8 +-
 fs/nfsd/nfsctl.c                          |   2 +-
 fs/nfsd/nfsd.h                            |   6 +-
 fs/nfsd/nfsfh.c                           | 114 ++--
 fs/nfsd/nfsfh.h                           |   5 +
 fs/nfsd/nfssvc.c                          | 100 ++-
 fs/nfsd/trace.h                           |  39 +-
 fs/nfsd/vfs.h                             |  10 +
 include/linux/nfs.h                       |   9 +
 include/linux/nfs_common.h                |  17 +
 include/linux/nfs_fs_sb.h                 |  10 +
 include/linux/nfs_xdr.h                   |  20 +-
 include/linux/nfslocalio.h                |  56 ++
 include/linux/sunrpc/auth.h               |   4 +
 include/linux/sunrpc/svc.h                |   7 +-
 net/sunrpc/auth.c                         |  22 +
 net/sunrpc/clnt.c                         |   6 -
 net/sunrpc/svc.c                          |  68 +-
 net/sunrpc/svc_xprt.c                     |   2 +-
 net/sunrpc/svcauth_unix.c                 |   3 +-
 48 files changed, 2428 insertions(+), 415 deletions(-)
 create mode 100644 Documentation/filesystems/nfs/localio.rst
 create mode 100644 fs/nfs/localio.c
 create mode 100644 fs/nfs_common/common.c
 create mode 100644 fs/nfs_common/nfslocalio.c
 create mode 100644 fs/nfsd/localio.c
 create mode 100644 include/linux/nfs_common.h
 create mode 100644 include/linux/nfslocalio.h
Signature · 1 line
2.44.0
#1 lore raw

PATCH v12 1/24 nfs_common: factor out nfs_errtbl and nfs_stat_to_errno

Common nfs_stat_to_errno() is used by both fs/nfs/nfs2xdr.c and fs/nfs/nfs3xdr.c

Will also be used by fs/nfsd/localio.c

---
 fs/nfs/Kconfig             |   1 +
 fs/nfs/nfs2xdr.c           |  70 +-----------------------
 fs/nfs/nfs3xdr.c           | 108 +++++++------------------------------
 fs/nfs/nfs4xdr.c           |   4 +-
 fs/nfs_common/Makefile     |   2 +
 fs/nfs_common/common.c     |  67 +++++++++++++++++++++++
 fs/nfsd/Kconfig            |   1 +
 include/linux/nfs_common.h |  16 ++++++
 8 files changed, 109 insertions(+), 160 deletions(-)
 create mode 100644 fs/nfs_common/common.c
 create mode 100644 include/linux/nfs_common.h
fs/nfs/Kconfig +1 -0
index 57249f040dfc..0eb20012792f 100644
@@ -4,6 +4,7 @@ config NFS_FS
 	depends on INET && FILE_LOCKING && MULTIUSER
 	select LOCKD
 	select SUNRPC
+	select NFS_COMMON
 	select NFS_ACL_SUPPORT if NFS_V3_ACL
 	help
 	  Choose Y here if you want to access files residing on other
fs/nfs/nfs2xdr.c +1 -69

93 lines not on this page · raw message

fs/nfs/nfs3xdr.c +20 -88

237 lines not on this page · raw message

fs/nfs/nfs4xdr.c +1 -3
index 7704a4509676..b4091af1a60d 100644
@@ -52,6 +52,7 @@
 #include <linux/nfs.h>
 #include <linux/nfs4.h>
 #include <linux/nfs_fs.h>
+#include <linux/nfs_common.h>
 
 #include "nfs4_fs.h"
 #include "nfs4trace.h"
@@ -63,9 +64,6 @@
 
 #define NFSDBG_FACILITY		NFSDBG_XDR
 
-/* Mapping from NFS error code to "errno" error code. */
-#define errno_NFSERR_IO		EIO
-
 struct compound_hdr;
 static int nfs4_stat_to_errno(int);
 static void encode_layoutget(struct xdr_stream *xdr,
fs/nfs_common/Makefile +2 -0
index 119c75ab9fd0..e58b01bb8dda 100644
@@ -8,3 +8,5 @@ nfs_acl-objs := nfsacl.o
 
 obj-$(CONFIG_GRACE_PERIOD) += grace.o
 obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o
+
+obj-$(CONFIG_NFS_COMMON) += common.o
fs/nfs_common/common.c new file +67 -0

67 lines not on this page · raw message

fs/nfsd/Kconfig +1 -0
index ec2ab6429e00..c0bd1509ccd4 100644
@@ -7,6 +7,7 @@ config NFSD
 	select LOCKD
 	select SUNRPC
 	select EXPORTFS
+	select NFS_COMMON
 	select NFS_ACL_SUPPORT if NFSD_V2_ACL
 	select NFS_ACL_SUPPORT if NFSD_V3_ACL
 	depends on MULTIUSER
include/linux/nfs_common.h new file +16 -0
new file mode 100644
index 000000000000..3395c4a4d372
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * This file contains constants and methods used by both NFS client and server.
+ */
+#ifndef _LINUX_NFS_COMMON_H
+#define _LINUX_NFS_COMMON_H
+
+#include <linux/errno.h>
+#include <uapi/linux/nfs.h>
+
+/* Mapping from NFS error code to "errno" error code. */
+#define errno_NFSERR_IO EIO
+
+int nfs_stat_to_errno(enum nfs_stat status);
+
+#endif /* _LINUX_NFS_COMMON_H */
Signature · 1 line
2.44.0
#2 lore raw

PATCH v12 2/24 nfs_common: factor out nfs4_errtbl and nfs4_stat_to_errno

In reply to Mike Snitzer

Common nfs4_stat_to_errno() is used by fs/nfs/nfs4xdr.c and will be used by fs/nfs/localio.c

---
 fs/nfs/nfs4xdr.c           | 67 --------------------------------------
 fs/nfs_common/common.c     | 67 ++++++++++++++++++++++++++++++++++++++
 include/linux/nfs_common.h |  1 +
 3 files changed, 68 insertions(+), 67 deletions(-)
fs/nfs/nfs4xdr.c +0 -67
index b4091af1a60d..971305bdaecb 100644
@@ -65,7 +65,6 @@
 #define NFSDBG_FACILITY		NFSDBG_XDR
 
 struct compound_hdr;
-static int nfs4_stat_to_errno(int);
 static void encode_layoutget(struct xdr_stream *xdr,
 			     const struct nfs4_layoutget_args *args,
 			     struct compound_hdr *hdr);
@@ -7619,72 +7618,6 @@ int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
 	return 0;
 }
 
-/*
- * We need to translate between nfs status return values and
- * the local errno values which may not be the same.
- */
-static struct {
-	int stat;
-	int errno;
-} nfs_errtbl[] = {
-	{ NFS4_OK,		0		},
-	{ NFS4ERR_PERM,		-EPERM		},
-	{ NFS4ERR_NOENT,	-ENOENT		},
-	{ NFS4ERR_IO,		-errno_NFSERR_IO},
-	{ NFS4ERR_NXIO,		-ENXIO		},
-	{ NFS4ERR_ACCESS,	-EACCES		},
-	{ NFS4ERR_EXIST,	-EEXIST		},
-	{ NFS4ERR_XDEV,		-EXDEV		},
-	{ NFS4ERR_NOTDIR,	-ENOTDIR	},
-	{ NFS4ERR_ISDIR,	-EISDIR		},
-	{ NFS4ERR_INVAL,	-EINVAL		},
-	{ NFS4ERR_FBIG,		-EFBIG		},
-	{ NFS4ERR_NOSPC,	-ENOSPC		},
-	{ NFS4ERR_ROFS,		-EROFS		},
-	{ NFS4ERR_MLINK,	-EMLINK		},
-	{ NFS4ERR_NAMETOOLONG,	-ENAMETOOLONG	},
-	{ NFS4ERR_NOTEMPTY,	-ENOTEMPTY	},
-	{ NFS4ERR_DQUOT,	-EDQUOT		},
-	{ NFS4ERR_STALE,	-ESTALE		},
-	{ NFS4ERR_BADHANDLE,	-EBADHANDLE	},
-	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
-	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
-	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
-	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
-	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
-	{ NFS4ERR_LOCKED,	-EAGAIN		},
-	{ NFS4ERR_SYMLINK,	-ELOOP		},
-	{ NFS4ERR_OP_ILLEGAL,	-EOPNOTSUPP	},
-	{ NFS4ERR_DEADLOCK,	-EDEADLK	},
-	{ NFS4ERR_NOXATTR,	-ENODATA	},
-	{ NFS4ERR_XATTR2BIG,	-E2BIG		},
-	{ -1,			-EIO		}
-};
-
-/*
- * Convert an NFS error code to a local one.
- * This one is used jointly by NFSv2 and NFSv3.
- */
-static int
-nfs4_stat_to_errno(int stat)
-{
-	int i;
-	for (i = 0; nfs_errtbl[i].stat != -1; i++) {
-		if (nfs_errtbl[i].stat == stat)
-			return nfs_errtbl[i].errno;
-	}
-	if (stat <= 10000 || stat > 10100) {
-		/* The server is looney tunes. */
-		return -EREMOTEIO;
-	}
-	/* If we cannot translate the error, the recovery routines should
-	 * handle it.
-	 * Note: remaining NFSv4 error codes have values > 10000, so should
-	 * not conflict with native Linux error codes.
-	 */
-	return -stat;
-}
-
 #ifdef CONFIG_NFS_V4_2
 #include "nfs42xdr.c"
 #endif /* CONFIG_NFS_V4_2 */
fs/nfs_common/common.c +67 -0

76 lines not on this page · raw message

include/linux/nfs_common.h +1 -0
index 3395c4a4d372..5fc02df88252 100644
@@ -12,5 +12,6 @@
 #define errno_NFSERR_IO EIO
 
 int nfs_stat_to_errno(enum nfs_stat status);
+int nfs4_stat_to_errno(int stat);
 
 #endif /* _LINUX_NFS_COMMON_H */
Signature · 1 line
2.44.0
#3 lore raw

PATCH v12 3/24 nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h

In reply to Mike Snitzer

Eliminates duplicate functions in various files to allow for additional callers.

---
 fs/nfs/flexfilelayout/flexfilelayout.c |  6 ------
 fs/nfs/nfs4xdr.c                       | 13 -------------
 include/linux/nfs_xdr.h                | 20 +++++++++++++++++++-
 3 files changed, 19 insertions(+), 20 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +0 -6
index 39ba9f4208aa..d4d551ffea7b 100644
@@ -2086,12 +2086,6 @@ static int ff_layout_encode_ioerr(struct xdr_stream *xdr,
 	return ff_layout_encode_ds_ioerr(xdr, &ff_args->errors);
 }
 
-static void
-encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
-{
-	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
-}
-
 static void
 ff_layout_encode_ff_iostat_head(struct xdr_stream *xdr,
 			    const nfs4_stateid *stateid,
fs/nfs/nfs4xdr.c +0 -13
index 971305bdaecb..6bf2d44e5d4e 100644
@@ -972,11 +972,6 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
 	return p;
 }
 
-static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
-{
-	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
-}
-
 static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
 {
 	WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
@@ -4406,14 +4401,6 @@ static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
 	return 0;
 }
 
-static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
-{
-	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
-	if (unlikely(ret < 0))
-		return -EIO;
-	return 0;
-}
-
 static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
 {
 	return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
include/linux/nfs_xdr.h +19 -1
index 45623af3e7b8..5e93fbfb785a 100644
@@ -1853,6 +1853,24 @@ struct nfs_rpc_ops {
 	void	(*disable_swap)(struct inode *inode);
 };
 
+/*
+ * Helper functions used by NFS client and/or server
+ */
+static inline void encode_opaque_fixed(struct xdr_stream *xdr,
+				       const void *buf, size_t len)
+{
+	WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
+}
+
+static inline int decode_opaque_fixed(struct xdr_stream *xdr,
+				      void *buf, size_t len)
+{
+	ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
+	if (unlikely(ret < 0))
+		return -EIO;
+	return 0;
+}
+
 /*
  * Function vectors etc. for the NFS client
  */
@@ -1866,4 +1884,4 @@ extern const struct rpc_version nfs_version4;
 extern const struct rpc_version nfsacl_version3;
 extern const struct rpc_program nfsacl_program;
 
-#endif
+#endif /* _LINUX_NFS_XDR_H */
Signature · 1 line
2.44.0
#4 lore raw

PATCH v12 4/24 nfsd: factor out __fh_verify to allow NULL rqstp to be passed

In reply to Mike Snitzer

From: NeilBrown <[email protected]>

__fh_verify() offers an interface like fh_verify() but doesn't require a struct svc_rqst *, instead it also takes the specific parts as explicit required arguments. So it is safe to call __fh_verify() with a NULL rqstp, but the net, cred, and client args must not be NULL.

__fh_verify() does not use SVC_NET(), nor does the functions it calls.

Rather then depending on rqstp->rq_vers to determine nfs version, pass it in explicitly. This removes another dependency on rqstp and ensures the correct version is checked. The rqstp can be for an NLM request and while some code tests that, other code does not.

Rather than using rqstp->rq_client pass the client and gssclient explicitly to __fh_verify and then to nfsd_set_fh_dentry().

The final places where __fh_verify unconditionally dereferences rqstp involve checking if the connection is suitably secure. They look at rqstp->rq_xprt which is not meaningful in the target use case of "localio" NFS in which the client talks directly to the local server. So have these always succeed when rqstp is NULL.

Lastly, 4 associated tracepoints are only used if rqstp is not NULL (this is stop-gap that will be properly fixed in the next commit).

---
 fs/nfsd/export.c |   8 ++-
 fs/nfsd/nfsfh.c  | 124 ++++++++++++++++++++++++++++-------------------
 2 files changed, 82 insertions(+), 50 deletions(-)
fs/nfsd/export.c +7 -1
index 7bb4f2075ac5..fe36f441d1d9 100644
@@ -1077,7 +1077,13 @@ static struct svc_export *exp_find(struct cache_detail *cd,
 __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
 {
 	struct exp_flavor_info *f, *end = exp->ex_flavors + exp->ex_nflavors;
-	struct svc_xprt *xprt = rqstp->rq_xprt;
+	struct svc_xprt *xprt;
+
+	if (!rqstp)
+		/* Always allow LOCALIO */
+		return 0;
+
+	xprt = rqstp->rq_xprt;
 
 	if (exp->ex_xprtsec_modes & NFSEXP_XPRTSEC_NONE) {
 		if (!test_bit(XPT_TLS_SESSION, &xprt->xpt_flags))
fs/nfsd/nfsfh.c +75 -49

218 lines not on this page · raw message

Signature · 1 line
2.44.0
#5 lore raw

PATCH v12 5/24 nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

In reply to Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL. Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++--------
 fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------
 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +4 -8
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net,
 
 	error = nfserr_stale;
 	if (IS_ERR(exp)) {
-		if (rqstp)
-			trace_nfsd_set_fh_dentry_badexport(rqstp, fhp, PTR_ERR(exp));
+		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp, PTR_ERR(exp));
 
 		if (PTR_ERR(exp) == -ENOENT)
 			return error;
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net,
 						data_left, fileid_type, 0,
 						nfsd_acceptable, exp);
 		if (IS_ERR_OR_NULL(dentry)) {
-			if (rqstp)
-				trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,
+			trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,
 					dentry ?  PTR_ERR(dentry) : -ESTALE);
 			switch (PTR_ERR(dentry)) {
 			case -ENOMEM:
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
 	dentry = fhp->fh_dentry;
 	exp = fhp->fh_export;
 
-	if (rqstp)
-		trace_nfsd_fh_verify(rqstp, fhp, type, access);
+	trace_nfsd_fh_verify(net, rqstp, fhp, type, access);
 
 	/*
 	 * We still have to do all these permission checks, even when
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
 	/* Finally, check access permissions. */
 	error = nfsd_permission(cred, exp, dentry, access);
 out:
-	if (rqstp)
-		trace_nfsd_fh_verify_err(rqstp, fhp, type, access, error);
+	trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access, error);
 	if (error == nfserr_stale)
 		nfsd_stats_fh_stale_inc(nn, exp);
 	return error;
fs/nfsd/trace.h +21 -15
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,
 
 TRACE_EVENT(nfsd_fh_verify,
 	TP_PROTO(
+		const struct net *net,
 		const struct svc_rqst *rqstp,
 		const struct svc_fh *fhp,
 		umode_t type,
 		int access
 	),
-	TP_ARGS(rqstp, fhp, type, access),
+	TP_ARGS(net, rqstp, fhp, type, access),
 	TP_STRUCT__entry(
 		__field(unsigned int, netns_ino)
 		__sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
 		__field(unsigned long, access)
 	),
 	TP_fast_assign(
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt->xpt_local,
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt->xpt_remote,
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt->xpt_local,
+					  rqstp->rq_xprt->xpt_locallen);
+			__assign_sockaddr(client, &rqstp->rq_xprt->xpt_remote,
+					  rqstp->rq_xprt->xpt_remotelen);
+		}
+		__entry->xid = rqstp ? be32_to_cpu(rqstp->rq_xid) : 0;
 		__entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle);
 		__entry->inode = d_inode(fhp->fh_dentry);
 		__entry->type = type;
@@ -232,13 +235,14 @@ TRACE_EVENT(nfsd_fh_verify,
 
 TRACE_EVENT_CONDITION(nfsd_fh_verify_err,
 	TP_PROTO(
+		const struct net *net,
 		const struct svc_rqst *rqstp,
 		const struct svc_fh *fhp,
 		umode_t type,
 		int access,
 		__be32 error
 	),
-	TP_ARGS(rqstp, fhp, type, access, error),
+	TP_ARGS(net, rqstp, fhp, type, access, error),
 	TP_CONDITION(error),
 	TP_STRUCT__entry(
 		__field(unsigned int, netns_ino)
@@ -252,12 +256,14 @@ TRACE_EVENT_CONDITION(nfsd_fh_verify_err,
 		__field(int, error)
 	),
 	TP_fast_assign(
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt->xpt_local,
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt->xpt_remote,
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt->xpt_local,
+					  rqstp->rq_xprt->xpt_locallen);
+			__assign_sockaddr(client, &rqstp->rq_xprt->xpt_remote,
+					  rqstp->rq_xprt->xpt_remotelen);
+		}
+		__entry->xid = rqstp ? be32_to_cpu(rqstp->rq_xid) : 0;
 		__entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle);
 		if (fhp->fh_dentry)
 			__entry->inode = d_inode(fhp->fh_dentry);
@@ -286,7 +292,7 @@ DECLARE_EVENT_CLASS(nfsd_fh_err_class,
 		__field(int, status)
 	),
 	TP_fast_assign(
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->xid = rqstp ? be32_to_cpu(rqstp->rq_xid) : 0;
 		__entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle);
 		__entry->status = status;
 	),
Signature · 1 line
2.44.0
#13 lore raw

PATCH v12 6/24 nfsd: add nfsd_file_acquire_local()

In reply to Mike Snitzer

From: NeilBrown <[email protected]>

nfsd_file_acquire_local() can be used to look up a file by filehandle without having a struct svc_rqst. This can be used by NFS LOCALIO to allow the NFS client to bypass the NFS protocol to directly access a file provided by the NFS server which is running in the same kernel.

In nfsd_file_do_acquire() care is taken to always use fh_verify() if rqstp is not NULL (as is the case for non-LOCALIO callers). Otherwise the non-LOCALIO callers will not supply the correct and required arguments to __fh_verify (e.g. nfs_vers is 0, gssclient isn't passed).

---
 fs/nfsd/filecache.c | 62 ++++++++++++++++++++++++++++++++++++++++-----
 fs/nfsd/filecache.h |  4 +++
 fs/nfsd/nfsfh.c     |  2 +-
 fs/nfsd/nfsfh.h     |  5 ++++
 4 files changed, 65 insertions(+), 8 deletions(-)
fs/nfsd/filecache.c +55 -7
index 9e9d246f993c..2cc838bbeb89 100644
@@ -982,12 +982,14 @@ nfsd_file_is_cached(struct inode *inode)
 }
 
 static __be32
-nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
+nfsd_file_do_acquire(struct svc_rqst *rqstp, struct net *net,
+		     struct svc_cred *cred, int nfs_vers,
+		     struct auth_domain *client,
+		     struct svc_fh *fhp,
 		     unsigned int may_flags, struct file *file,
 		     struct nfsd_file **pnf, bool want_gc)
 {
 	unsigned char need = may_flags & NFSD_FILE_MAY_MASK;
-	struct net *net = SVC_NET(rqstp);
 	struct nfsd_file *new, *nf;
 	bool stale_retry = true;
 	bool open_retry = true;
@@ -996,8 +998,13 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	int ret;
 
 retry:
-	status = fh_verify(rqstp, fhp, S_IFREG,
-				may_flags|NFSD_MAY_OWNER_OVERRIDE);
+	if (rqstp) {
+		status = fh_verify(rqstp, fhp, S_IFREG,
+				   may_flags|NFSD_MAY_OWNER_OVERRIDE);
+	} else {
+		status = __fh_verify(NULL, net, cred, nfs_vers, client, NULL, fhp,
+				     S_IFREG, may_flags|NFSD_MAY_OWNER_OVERRIDE);
+	}
 	if (status != nfs_ok)
 		return status;
 	inode = d_inode(fhp->fh_dentry);
@@ -1143,7 +1150,8 @@ __be32
 nfsd_file_acquire_gc(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		     unsigned int may_flags, struct nfsd_file **pnf)
 {
-	return nfsd_file_do_acquire(rqstp, fhp, may_flags, NULL, pnf, true);
+	return nfsd_file_do_acquire(rqstp, SVC_NET(rqstp), NULL, 0, NULL,
+				    fhp, may_flags, NULL, pnf, true);
 }
 
 /**
@@ -1167,7 +1175,46 @@ __be32
 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		  unsigned int may_flags, struct nfsd_file **pnf)
 {
-	return nfsd_file_do_acquire(rqstp, fhp, may_flags, NULL, pnf, false);
+	return nfsd_file_do_acquire(rqstp, SVC_NET(rqstp), NULL, 0, NULL,
+				    fhp, may_flags, NULL, pnf, false);
+}
+
+/**
+ * nfsd_file_acquire_local - Get a struct nfsd_file with an open file for localio
+ * @net: The network namespace in which to perform a lookup
+ * @cred: the user credential with which to validate access
+ * @nfs_vers: NFS version number to assume for request
+ * @client: the auth_domain for LOCALIO lookup
+ * @fhp: the NFS filehandle of the file to be opened
+ * @may_flags: NFSD_MAY_ settings for the file
+ * @pnf: OUT: new or found "struct nfsd_file" object
+ *
+ * This file lookup interface provide access to a file given the
+ * filehandle and credential.  No connection-based authorisation
+ * is performed and in that way it is quite different to other
+ * file access mediated by nfsd.  It allows a kernel module such as the NFS
+ * client to reach across network and filesystem namespaces to access
+ * a file.  The security implications of this should be carefully
+ * considered before use.
+ *
+ * The nfsd_file_object returned by this API is reference-counted
+ * but not garbage-collected. The object is unhashed after the
+ * final nfsd_file_put().
+ *
+ * Return values:
+ *   %nfs_ok - @pnf points to an nfsd_file with its reference
+ *   count boosted.
+ *
+ * On error, an nfsstat value in network byte order is returned.
+ */
+__be32
+nfsd_file_acquire_local(struct net *net, struct svc_cred *cred,
+			int nfs_vers, struct auth_domain *client,
+			struct svc_fh *fhp,
+			unsigned int may_flags, struct nfsd_file **pnf)
+{
+	return nfsd_file_do_acquire(NULL, net, cred, nfs_vers, client,
+				    fhp, may_flags, NULL, pnf, false);
 }
 
 /**
@@ -1193,7 +1240,8 @@ nfsd_file_acquire_opened(struct svc_rqst *rqstp, struct svc_fh *fhp,
 			 unsigned int may_flags, struct file *file,
 			 struct nfsd_file **pnf)
 {
-	return nfsd_file_do_acquire(rqstp, fhp, may_flags, file, pnf, false);
+	return nfsd_file_do_acquire(rqstp, SVC_NET(rqstp), NULL, 0, NULL,
+				    fhp, may_flags, file, pnf, false);
 }
 
 /*
fs/nfsd/filecache.h +4 -0
index 3fbec24eea6c..6dab41f8541e 100644
@@ -66,5 +66,9 @@ __be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
 __be32 nfsd_file_acquire_opened(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		  unsigned int may_flags, struct file *file,
 		  struct nfsd_file **nfp);
+__be32 nfsd_file_acquire_local(struct net *net, struct svc_cred *cred,
+			       int nfs_vers, struct auth_domain *client,
+			       struct svc_fh *fhp,
+			       unsigned int may_flags, struct nfsd_file **pnf);
 int nfsd_file_cache_stats_show(struct seq_file *m, void *v);
 #endif /* _FS_NFSD_FILECACHE_H */
fs/nfsd/nfsfh.c +1 -1
index bae727e65214..6253505c4555 100644
@@ -298,7 +298,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net,
 	return error;
 }
 
-static __be32
+__be32
 __fh_verify(struct svc_rqst *rqstp,
 	    struct net *net, struct svc_cred *cred,
 	    int nfs_vers, struct auth_domain *client,
fs/nfsd/nfsfh.h +5 -0
index 8d46e203d139..1429bee0ac1c 100644
@@ -217,6 +217,11 @@ extern char * SVCFH_fmt(struct svc_fh *fhp);
  * Function prototypes
  */
 __be32	fh_verify(struct svc_rqst *, struct svc_fh *, umode_t, int);
+__be32	__fh_verify(struct svc_rqst *rqstp,
+		    struct net *net, struct svc_cred *cred,
+		    int nfs_vers, struct auth_domain *client,
+		    struct auth_domain *gssclient,
+		    struct svc_fh *fhp, umode_t type, int access);
 __be32	fh_compose(struct svc_fh *, struct svc_export *, struct dentry *, struct svc_fh *);
 __be32	fh_update(struct svc_fh *);
 void	fh_put(struct svc_fh *);
Signature · 1 line
2.44.0
#14 lore raw

PATCH v12 7/24 SUNRPC: remove call_allocate() BUG_ONs

In reply to Mike Snitzer

Remove BUG_ON if p_arglen=0 to allow RPC with void arg. Remove BUG_ON if p_replen=0 to allow RPC with void return.

The former was needed for the first revision of the LOCALIO protocol which had an RPC that took a void arg:

    /* raw RFC 9562 UUID */
    typedef u8 uuid_t<UUID_SIZE>;

    program NFS_LOCALIO_PROGRAM {
        version LOCALIO_V1 {
            void
                NULL(void) = 0;

            uuid_t
                GETUUID(void) = 1;
        } = 1;
    } = 400122;

The latter is needed for the final revision of the LOCALIO protocol which has a UUID_IS_LOCAL RPC which returns a void:

    /* raw RFC 9562 UUID */
    typedef u8 uuid_t<UUID_SIZE>;

    program NFS_LOCALIO_PROGRAM {
        version LOCALIO_V1 {
            void
                NULL(void) = 0;

            void
                UUID_IS_LOCAL(uuid_t) = 1;
        } = 1;
    } = 400122;

There is really no value in triggering a BUG_ON in response to either of these previously unsupported conditions.

NeilBrown would like the entire 'if (proc->p_proc != 0)' branch removed (not just the one BUG_ON that must be removed for LOCALIO's immediate needs of returning void).

---
 net/sunrpc/clnt.c | 6 ------
 1 file changed, 6 deletions(-)
net/sunrpc/clnt.c +0 -6
index 09f29a95f2bc..00fe6df11ab7 100644
@@ -1893,12 +1893,6 @@ call_allocate(struct rpc_task *task)
 	if (req->rq_buffer)
 		return;
 
-	if (proc->p_proc != 0) {
-		BUG_ON(proc->p_arglen == 0);
-		if (proc->p_decode != NULL)
-			BUG_ON(proc->p_replen == 0);
-	}
-
 	/*
 	 * Calculate the size (in quads) of the RPC call
 	 * and reply headers, and convert both values
Signature · 1 line
2.44.0
#15 lore raw

PATCH v12 8/24 SUNRPC: add rpcauth_map_clnt_to_svc_cred_local

In reply to Mike Snitzer

From: Weston Andros Adamson <[email protected]>

Add new funtion rpcauth_map_clnt_to_svc_cred_local which maps a generic cred to a svc_cred suitable for use in nfsd.

This is needed by the localio code to map nfs client creds to nfs server credentials.

Following from net/sunrpc/auth_unix.c:unx_marshal() it is clear that ->fsuid and ->fsgid must be used (rather than ->uid and ->gid). In addition, these uid and gid must be translated with from_kuid_munged() so local client uses correct uid and gid when acting as local server.

---
 include/linux/sunrpc/auth.h |  4 ++++
 net/sunrpc/auth.c           | 22 ++++++++++++++++++++++
 2 files changed, 26 insertions(+)
include/linux/sunrpc/auth.h +4 -0
index 61e58327b1aa..4cfb68f511db 100644
@@ -11,6 +11,7 @@
 #define _LINUX_SUNRPC_AUTH_H
 
 #include <linux/sunrpc/sched.h>
+#include <linux/sunrpc/svcauth.h>
 #include <linux/sunrpc/msg_prot.h>
 #include <linux/sunrpc/xdr.h>
 
@@ -184,6 +185,9 @@ int			rpcauth_uptodatecred(struct rpc_task *);
 int			rpcauth_init_credcache(struct rpc_auth *);
 void			rpcauth_destroy_credcache(struct rpc_auth *);
 void			rpcauth_clear_credcache(struct rpc_cred_cache *);
+void			rpcauth_map_clnt_to_svc_cred_local(struct rpc_clnt *clnt,
+							   const struct cred *,
+							   struct svc_cred *);
 char *			rpcauth_stringify_acceptor(struct rpc_cred *);
 
 static inline
net/sunrpc/auth.c +22 -0
index 04534ea537c8..3b6d91b36589 100644
@@ -17,6 +17,7 @@
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/gss_api.h>
 #include <linux/spinlock.h>
+#include <linux/user_namespace.h>
 
 #include <trace/events/sunrpc.h>
 
@@ -308,6 +309,27 @@ rpcauth_init_credcache(struct rpc_auth *auth)
 }
 EXPORT_SYMBOL_GPL(rpcauth_init_credcache);
 
+void
+rpcauth_map_clnt_to_svc_cred_local(struct rpc_clnt *clnt,
+				   const struct cred *cred,
+				   struct svc_cred *svc)
+{
+	struct user_namespace *userns = clnt->cl_cred ?
+		clnt->cl_cred->user_ns : &init_user_ns;
+
+	memset(svc, 0, sizeof(struct svc_cred));
+
+	svc->cr_uid = KUIDT_INIT(from_kuid_munged(userns, cred->fsuid));
+	svc->cr_gid = KGIDT_INIT(from_kgid_munged(userns, cred->fsgid));
+	svc->cr_flavor = clnt->cl_auth->au_flavor;
+	if (cred->group_info)
+		svc->cr_group_info = get_group_info(cred->group_info);
+	/* These aren't relevant for local (network is bypassed) */
+	svc->cr_principal = NULL;
+	svc->cr_gss_mech = NULL;
+}
+EXPORT_SYMBOL_GPL(rpcauth_map_clnt_to_svc_cred_local);
+
 char *
 rpcauth_stringify_acceptor(struct rpc_cred *cred)
 {
Signature · 1 line
2.44.0
#16 lore raw

PATCH v12 9/24 nfs_common: add NFS LOCALIO auxiliary protocol enablement

In reply to Mike Snitzer

fs/nfs_common/nfslocalio.c provides interfaces that enable an NFS client to generate a nonce (single-use UUID) and associated short-lived nfs_uuid_t struct, register it with nfs_common for subsequent lookup and verification by the NFS server and if matched the NFS server populates members in the nfs_uuid_t struct.

nfs_common's nfs_uuids list is the basis for localio enablement, as such it has members that point to nfsd memory for direct use by the client (e.g. 'net' is the server's network namespace, through it the client can access nn->nfsd_serv with proper rcu read access).

This commit adds all the nfs_client members required to implement the entire localio feature (which depends on the LOCALIO protocol).

---
 fs/nfs/client.c            |  9 ++++
 fs/nfs_common/Makefile     |  3 ++
 fs/nfs_common/nfslocalio.c | 97 ++++++++++++++++++++++++++++++++++++++
 include/linux/nfs_fs_sb.h  | 10 ++++
 include/linux/nfslocalio.h | 37 +++++++++++++++
 5 files changed, 156 insertions(+)
 create mode 100644 fs/nfs_common/nfslocalio.c
 create mode 100644 include/linux/nfslocalio.h
fs/nfs/client.c +9 -0
index 8286edd6062d..1b65a5d7af49 100644
@@ -178,6 +178,15 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
 	clp->cl_max_connect = cl_init->max_connect ? cl_init->max_connect : 1;
 	clp->cl_net = get_net(cl_init->net);
 
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	seqlock_init(&clp->cl_boot_lock);
+	ktime_get_real_ts64(&clp->cl_nfssvc_boot);
+	clp->cl_rpcclient_localio = ERR_PTR(-EINVAL);
+	clp->nfsd_open_local_fh = NULL;
+	clp->cl_nfssvc_net = NULL;
+	clp->cl_nfssvc_dom = NULL;
+#endif /* CONFIG_NFS_LOCALIO */
+
 	clp->cl_principal = "*";
 	clp->cl_xprtsec = cl_init->xprtsec;
 	return clp;
fs/nfs_common/Makefile +3 -0
index e58b01bb8dda..a5e54809701e 100644
@@ -6,6 +6,9 @@
 obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o
 nfs_acl-objs := nfsacl.o
 
+obj-$(CONFIG_NFS_COMMON_LOCALIO_SUPPORT) += nfs_localio.o
+nfs_localio-objs := nfslocalio.o
+
 obj-$(CONFIG_GRACE_PERIOD) += grace.o
 obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o
 
fs/nfs_common/nfslocalio.c new file +97 -0

97 lines not on this page · raw message

include/linux/nfs_fs_sb.h +10 -0
index 1df86ab98c77..3849cc2832f0 100644
@@ -8,6 +8,7 @@
 #include <linux/wait.h>
 #include <linux/nfs_xdr.h>
 #include <linux/sunrpc/xprt.h>
+#include <linux/nfslocalio.h>
 
 #include <linux/atomic.h>
 #include <linux/refcount.h>
@@ -125,6 +126,15 @@ struct nfs_client {
 	struct net		*cl_net;
 	struct list_head	pending_cb_stateids;
 	struct rcu_head		rcu;
+
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	struct timespec64	cl_nfssvc_boot;
+	seqlock_t		cl_boot_lock;
+	struct rpc_clnt *	cl_rpcclient_localio;
+	struct net *	        cl_nfssvc_net;
+	struct auth_domain *	cl_nfssvc_dom;
+	nfs_to_nfsd_open_t	nfsd_open_local_fh;
+#endif /* CONFIG_NFS_LOCALIO */
 };
 
 /*
include/linux/nfslocalio.h new file +37 -0
new file mode 100644
index 000000000000..109cb8534e3f
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Mike Snitzer <[email protected]>
+ */
+#ifndef __LINUX_NFSLOCALIO_H
+#define __LINUX_NFSLOCALIO_H
+
+#include <linux/list.h>
+#include <linux/uuid.h>
+#include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/svcauth.h>
+#include <linux/nfs.h>
+#include <net/net_namespace.h>
+
+/*
+ * Useful to allow a client to negotiate if localio
+ * possible with its server.
+ */
+typedef struct {
+	uuid_t uuid;
+	struct list_head list;
+	struct net *net; /* nfsd's network namespace */
+	struct auth_domain *dom; /* auth_domain for localio */
+} nfs_uuid_t;
+
+void nfs_uuid_begin(nfs_uuid_t *);
+void nfs_uuid_end(nfs_uuid_t *);
+bool nfs_uuid_is_local(const uuid_t *, struct net *, struct auth_domain *);
+
+typedef int (*nfs_to_nfsd_open_t)(struct net *, struct auth_domain *, struct rpc_clnt *,
+				const struct cred *, const struct nfs_fh *,
+				const fmode_t, struct file **);
+
+nfs_to_nfsd_open_t get_nfsd_open_local_fh(void);
+void put_nfsd_open_local_fh(void);
+
+#endif  /* __LINUX_NFSLOCALIO_H */
Signature · 1 line
2.44.0
#19 lore raw

PATCH v12 10/24 nfsd: add localio support

In reply to Mike Snitzer

From: Weston Andros Adamson <[email protected]>

Add server support for bypassing NFS for localhost reads, writes, and commits. This is only useful when both the client and server are running on the same host.

If nfsd_open_local_fh() fails then the NFS client will both retry and fallback to normal network-based read, write and commit operations if localio is no longer supported.

Care is taken to ensure the same NFS security mechanisms are used (authentication, etc) regardless of whether localio or regular NFS access is used. The auth_domain established as part of the traditional NFS client access to the NFS server is also used for localio. Store auth_domain for localio in nfsd_uuid_t and transfer it to the client if it is local to the server.

Relative to containers, localio gives the client access to the network namespace the server has. This is required to allow the client to access the server's per-namespace nfsd_net struct.

CONFIG_NFSD_LOCALIO controls the server enablement for localio. A later commit will add CONFIG_NFS_LOCALIO to allow the client enablement.

This commit also introduces the use of a percpu_ref to interlock nfsd_destroy_serv and nfsd_open_local_fh, and warrants a more detailed explanation:

Introduce nfsd_serv_try_get and nfsd_serv_put and update the nfsd code to prevent nfsd_destroy_serv from destroying nn->nfsd_serv until any client initiated localio calls to nfsd (that are _not_ in the context of nfsd) are complete.

nfsd_open_local_fh is updated to nfsd_serv_try_get before opening its file handle and then drop the reference using nfsd_serv_put at the end of nfsd_open_local_fh.

This "interlock" working relies heavily on nfsd_open_local_fh()'s maybe_get_net() safely dealing with the possibility that the struct net (and nfsd_net by association) may have been destroyed by nfsd_destroy_serv() via nfsd_shutdown_net().

Verified to fix an easy to hit crash that would occur if an nfsd instance running in a container, with a localio client mounted, is shutdown. Upon restart of the container and associated nfsd the client would go on to crash due to NULL pointer dereference that occuured due to the nfs client's localio attempting to nfsd_open_local_fh(), using nn->nfsd_serv, without having a proper reference on nn->nfsd_serv.

---
 fs/Kconfig          |   3 ++
 fs/nfsd/Kconfig     |  14 ++++++
 fs/nfsd/Makefile    |   1 +
 fs/nfsd/filecache.c |   2 +-
 fs/nfsd/localio.c   | 111 ++++++++++++++++++++++++++++++++++++++++++++
 fs/nfsd/netns.h     |   8 +++-
 fs/nfsd/nfssvc.c    |  39 ++++++++++++++++
 fs/nfsd/trace.h     |   3 +-
 fs/nfsd/vfs.h       |  10 ++++
 9 files changed, 188 insertions(+), 3 deletions(-)
 create mode 100644 fs/nfsd/localio.c
fs/Kconfig +3 -0
index a46b0cbc4d8f..1b8a5edbddff 100644
@@ -377,6 +377,9 @@ config NFS_ACL_SUPPORT
 	tristate
 	select FS_POSIX_ACL
 
+config NFS_COMMON_LOCALIO_SUPPORT
+	bool
+
 config NFS_COMMON
 	bool
 	depends on NFSD || NFS_FS || LOCKD
fs/nfsd/Kconfig +14 -0
index c0bd1509ccd4..1fca57c79c60 100644
@@ -90,6 +90,20 @@ config NFSD_V4
 
 	  If unsure, say N.
 
+config NFSD_LOCALIO
+	bool "NFS server support for the LOCALIO auxiliary protocol"
+	depends on NFSD
+	select NFS_COMMON_LOCALIO_SUPPORT
+	help
+	  Some NFS servers support an auxiliary NFS LOCALIO protocol
+	  that is not an official part of the NFS protocol.
+
+	  This option enables support for the LOCALIO protocol in the
+	  kernel's NFS server.  Enable this to bypass using the NFS
+	  protocol when issuing reads, writes and commits to the server.
+
+	  If unsure, say N.
+
 config NFSD_PNFS
 	bool
 
fs/nfsd/Makefile +1 -0
index b8736a82e57c..78b421778a79 100644
@@ -23,3 +23,4 @@ nfsd-$(CONFIG_NFSD_PNFS) += nfs4layouts.o
 nfsd-$(CONFIG_NFSD_BLOCKLAYOUT) += blocklayout.o blocklayoutxdr.o
 nfsd-$(CONFIG_NFSD_SCSILAYOUT) += blocklayout.o blocklayoutxdr.o
 nfsd-$(CONFIG_NFSD_FLEXFILELAYOUT) += flexfilelayout.o flexfilelayoutxdr.o
+nfsd-$(CONFIG_NFSD_LOCALIO) += localio.o
fs/nfsd/filecache.c +1 -1
index 2cc838bbeb89..56be99a3667a 100644
@@ -52,7 +52,7 @@
 #define NFSD_FILE_CACHE_UP		     (0)
 
 /* We only care about NFSD_MAY_READ/WRITE for this cache */
-#define NFSD_FILE_MAY_MASK	(NFSD_MAY_READ|NFSD_MAY_WRITE)
+#define NFSD_FILE_MAY_MASK	(NFSD_MAY_READ|NFSD_MAY_WRITE|NFSD_MAY_LOCALIO)
 
 static DEFINE_PER_CPU(unsigned long, nfsd_file_cache_hits);
 static DEFINE_PER_CPU(unsigned long, nfsd_file_acquisitions);
fs/nfsd/localio.c new file +111 -0

111 lines not on this page · raw message

fs/nfsd/netns.h +7 -1
index 238fc4e56e53..e2d953f21dde 100644
@@ -13,6 +13,7 @@
 #include <linux/filelock.h>
 #include <linux/nfs4.h>
 #include <linux/percpu_counter.h>
+#include <linux/percpu-refcount.h>
 #include <linux/siphash.h>
 #include <linux/sunrpc/stats.h>
 
@@ -139,7 +140,9 @@ struct nfsd_net {
 
 	struct svc_info nfsd_info;
 #define nfsd_serv nfsd_info.serv
-
+	struct percpu_ref nfsd_serv_ref;
+	struct completion nfsd_serv_confirm_done;
+	struct completion nfsd_serv_free_done;
 
 	/*
 	 * clientid and stateid data for construction of net unique COPY
@@ -221,6 +224,9 @@ struct nfsd_net {
 extern bool nfsd_support_version(int vers);
 extern unsigned int nfsd_net_id;
 
+bool nfsd_serv_try_get(struct nfsd_net *nn);
+void nfsd_serv_put(struct nfsd_net *nn);
+
 void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn);
 void nfsd_reset_write_verifier(struct nfsd_net *nn);
 #endif /* __NFSD_NETNS_H__ */
fs/nfsd/nfssvc.c +39 -0
index defc430f912f..e43d440f9f0a 100644
@@ -193,6 +193,30 @@ int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change
 	return 0;
 }
 
+bool nfsd_serv_try_get(struct nfsd_net *nn)
+{
+	return percpu_ref_tryget_live(&nn->nfsd_serv_ref);
+}
+
+void nfsd_serv_put(struct nfsd_net *nn)
+{
+	percpu_ref_put(&nn->nfsd_serv_ref);
+}
+
+static void nfsd_serv_done(struct percpu_ref *ref)
+{
+	struct nfsd_net *nn = container_of(ref, struct nfsd_net, nfsd_serv_ref);
+
+	complete(&nn->nfsd_serv_confirm_done);
+}
+
+static void nfsd_serv_free(struct percpu_ref *ref)
+{
+	struct nfsd_net *nn = container_of(ref, struct nfsd_net, nfsd_serv_ref);
+
+	complete(&nn->nfsd_serv_free_done);
+}
+
 /*
  * Maximum number of nfsd processes
  */
@@ -392,6 +416,7 @@ static void nfsd_shutdown_net(struct net *net)
 		lockd_down(net);
 		nn->lockd_up = false;
 	}
+	percpu_ref_exit(&nn->nfsd_serv_ref);
 	nn->nfsd_net_up = false;
 	nfsd_shutdown_generic();
 }
@@ -471,6 +496,13 @@ void nfsd_destroy_serv(struct net *net)
 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 	struct svc_serv *serv = nn->nfsd_serv;
 
+	lockdep_assert_held(&nfsd_mutex);
+
+	percpu_ref_kill_and_confirm(&nn->nfsd_serv_ref, nfsd_serv_done);
+	wait_for_completion(&nn->nfsd_serv_confirm_done);
+	wait_for_completion(&nn->nfsd_serv_free_done);
+	/* percpu_ref_exit is called in nfsd_shutdown_net */
+
 	spin_lock(&nfsd_notifier_lock);
 	nn->nfsd_serv = NULL;
 	spin_unlock(&nfsd_notifier_lock);
@@ -595,6 +627,13 @@ int nfsd_create_serv(struct net *net)
 	if (nn->nfsd_serv)
 		return 0;
 
+	error = percpu_ref_init(&nn->nfsd_serv_ref, nfsd_serv_free,
+				0, GFP_KERNEL);
+	if (error)
+		return error;
+	init_completion(&nn->nfsd_serv_free_done);
+	init_completion(&nn->nfsd_serv_confirm_done);
+
 	if (nfsd_max_blksize == 0)
 		nfsd_max_blksize = nfsd_get_default_max_blksize();
 	nfsd_reset_versions(nn);
fs/nfsd/trace.h +2 -1
index d49b3c1e3ba9..20e170f19b0b 100644
@@ -86,7 +86,8 @@ DEFINE_NFSD_XDR_ERR_EVENT(cant_encode);
 		{ NFSD_MAY_NOT_BREAK_LEASE,	"NOT_BREAK_LEASE" },	\
 		{ NFSD_MAY_BYPASS_GSS,		"BYPASS_GSS" },		\
 		{ NFSD_MAY_READ_IF_EXEC,	"READ_IF_EXEC" },	\
-		{ NFSD_MAY_64BIT_COOKIE,	"64BIT_COOKIE" })
+		{ NFSD_MAY_64BIT_COOKIE,	"64BIT_COOKIE" },	\
+		{ NFSD_MAY_LOCALIO,		"LOCALIO" })
 
 TRACE_EVENT(nfsd_compound,
 	TP_PROTO(
fs/nfsd/vfs.h +10 -0
index 01947561d375..9720951c49a0 100644
@@ -33,6 +33,8 @@
 
 #define NFSD_MAY_64BIT_COOKIE		0x1000 /* 64 bit readdir cookies for >= NFSv3 */
 
+#define NFSD_MAY_LOCALIO		0x2000 /* for tracing, reflects when localio used */
+
 #define NFSD_MAY_CREATE		(NFSD_MAY_EXEC|NFSD_MAY_WRITE)
 #define NFSD_MAY_REMOVE		(NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
 
@@ -158,6 +160,14 @@ __be32		nfsd_permission(struct svc_cred *cred, struct svc_export *exp,
 
 void		nfsd_filp_close(struct file *fp);
 
+int		nfsd_open_local_fh(struct net *net,
+				   struct auth_domain *dom,
+				   struct rpc_clnt *rpc_clnt,
+				   const struct cred *cred,
+				   const struct nfs_fh *nfs_fh,
+				   const fmode_t fmode,
+				   struct file **pfilp);
+
 static inline int fh_want_write(struct svc_fh *fh)
 {
 	int ret;
Signature · 1 line
2.44.0
#20 lore raw

PATCH v12 11/24 nfsd: implement server support for NFS_LOCALIO_PROGRAM

In reply to Mike Snitzer

The LOCALIO auxiliary RPC protocol consists of a single "UUID_IS_LOCAL" RPC method that allows the Linux NFS client to verify the local Linux NFS server can see the nonce (single-use UUID) the client generated and made available in nfs_common. This protocol isn't part of an IETF standard, nor does it need to be considering it is Linux-to-Linux auxiliary RPC protocol that amounts to an implementation detail.

The UUID_IS_LOCAL method encodes the client generated uuid_t in terms of the fixed UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR methods are used instead of the less efficient variable sized methods.

The RPC program number for the NFS_LOCALIO_PROGRAM is 400122 (as assigned by IANA, see https://www.iana.org/assignments/rpc-program-numbers/ ):
Linux Kernel Organization 400122 nfslocalio

[neilb: factored out and simplified single localio protocol]
---
 fs/nfsd/localio.c   | 75 +++++++++++++++++++++++++++++++++++++++++++++
 fs/nfsd/nfsd.h      |  4 +++
 fs/nfsd/nfssvc.c    | 28 ++++++++++++++++-
 include/linux/nfs.h |  7 +++++
 4 files changed, 113 insertions(+), 1 deletion(-)
fs/nfsd/localio.c +75 -0
index ed528524b368..9cdea1d1c28a 100644
@@ -13,12 +13,15 @@
 #include <linux/nfs.h>
 #include <linux/nfs_common.h>
 #include <linux/nfslocalio.h>
+#include <linux/nfs_fs.h>
+#include <linux/nfs_xdr.h>
 #include <linux/string.h>
 
 #include "nfsd.h"
 #include "vfs.h"
 #include "netns.h"
 #include "filecache.h"
+#include "cache.h"
 
 /**
  * nfsd_open_local_fh - lookup a local filehandle @nfs_fh and map to @file
@@ -109,3 +112,75 @@ EXPORT_SYMBOL_GPL(nfsd_open_local_fh);
 
 /* Compile time type checking, not used by anything */
 static nfs_to_nfsd_open_t __maybe_unused nfsd_open_local_fh_typecheck = nfsd_open_local_fh;
+
+/*
+ * UUID_IS_LOCAL XDR functions
+ */
+
+static __be32 localio_proc_null(struct svc_rqst *rqstp)
+{
+	return rpc_success;
+}
+
+struct localio_uuidarg {
+	uuid_t			uuid;
+};
+
+static __be32 localio_proc_uuid_is_local(struct svc_rqst *rqstp)
+{
+	struct localio_uuidarg *argp = rqstp->rq_argp;
+
+	(void) nfs_uuid_is_local(&argp->uuid, SVC_NET(rqstp),
+				 rqstp->rq_client);
+
+	return rpc_success;
+}
+
+static bool localio_decode_uuidarg(struct svc_rqst *rqstp,
+				   struct xdr_stream *xdr)
+{
+	struct localio_uuidarg *argp = rqstp->rq_argp;
+	u8 uuid[UUID_SIZE];
+
+	if (decode_opaque_fixed(xdr, uuid, UUID_SIZE))
+		return false;
+	import_uuid(&argp->uuid, uuid);
+
+	return true;
+}
+
+static const struct svc_procedure localio_procedures1[] = {
+	[LOCALIOPROC_NULL] = {
+		.pc_func = localio_proc_null,
+		.pc_decode = nfssvc_decode_voidarg,
+		.pc_encode = nfssvc_encode_voidres,
+		.pc_argsize = sizeof(struct nfsd_voidargs),
+		.pc_ressize = sizeof(struct nfsd_voidres),
+		.pc_cachetype = RC_NOCACHE,
+		.pc_xdrressize = 0,
+		.pc_name = "NULL",
+	},
+	[LOCALIOPROC_UUID_IS_LOCAL] = {
+		.pc_func = localio_proc_uuid_is_local,
+		.pc_decode = localio_decode_uuidarg,
+		.pc_encode = nfssvc_encode_voidres,
+		.pc_argsize = sizeof(struct localio_uuidarg),
+		.pc_argzero = sizeof(struct localio_uuidarg),
+		.pc_ressize = sizeof(struct nfsd_voidres),
+		.pc_cachetype = RC_NOCACHE,
+		.pc_name = "UUID_IS_LOCAL",
+	},
+};
+
+#define LOCALIO_NR_PROCEDURES ARRAY_SIZE(localio_procedures1)
+static DEFINE_PER_CPU_ALIGNED(unsigned long,
+			      localio_count[LOCALIO_NR_PROCEDURES]);
+const struct svc_version localio_version1 = {
+	.vs_vers	= 1,
+	.vs_nproc	= LOCALIO_NR_PROCEDURES,
+	.vs_proc	= localio_procedures1,
+	.vs_dispatch	= nfsd_dispatch,
+	.vs_count	= localio_count,
+	.vs_xdrsize	= XDR_QUADLEN(UUID_SIZE),
+	.vs_hidden	= true,
+};
fs/nfsd/nfsd.h +4 -0
index 4ccbf014a2c7..f87a359d968f 100644
@@ -146,6 +146,10 @@ extern const struct svc_version nfsd_acl_version3;
 #endif
 #endif
 
+#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
+extern const struct svc_version localio_version1;
+#endif
+
 struct nfsd_net;
 
 enum vers_op {NFSD_SET, NFSD_CLEAR, NFSD_TEST, NFSD_AVAIL };
fs/nfsd/nfssvc.c +27 -1
index e43d440f9f0a..1bec3a53e35f 100644
@@ -80,6 +80,25 @@ DEFINE_SPINLOCK(nfsd_drc_lock);
 unsigned long	nfsd_drc_max_mem;
 unsigned long	nfsd_drc_mem_used;
 
+#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
+static const struct svc_version *localio_versions[] = {
+	[1] = &localio_version1,
+};
+
+#define NFSD_LOCALIO_NRVERS		ARRAY_SIZE(localio_versions)
+
+static struct svc_program	nfsd_localio_program = {
+	.pg_prog		= NFS_LOCALIO_PROGRAM,
+	.pg_nvers		= NFSD_LOCALIO_NRVERS,
+	.pg_vers		= localio_versions,
+	.pg_name		= "nfslocalio",
+	.pg_class		= "nfsd",
+	.pg_authenticate	= &svc_set_client,
+	.pg_init_request	= svc_generic_init_request,
+	.pg_rpcbind_set		= svc_generic_rpcbind_set,
+};
+#endif /* CONFIG_NFSD_LOCALIO */
+
 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
 static const struct svc_version *nfsd_acl_version[] = {
 # if defined(CONFIG_NFSD_V2_ACL)
@@ -94,6 +113,9 @@ static const struct svc_version *nfsd_acl_version[] = {
 #define NFSD_ACL_NRVERS		ARRAY_SIZE(nfsd_acl_version)
 
 static struct svc_program	nfsd_acl_program = {
+#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
+	.pg_next		= &nfsd_localio_program,
+#endif /* CONFIG_NFSD_LOCALIO */
 	.pg_prog		= NFS_ACL_PROGRAM,
 	.pg_nvers		= NFSD_ACL_NRVERS,
 	.pg_vers		= nfsd_acl_version,
@@ -119,6 +141,10 @@ static const struct svc_version *nfsd_version[NFSD_MAXVERS+1] = {
 struct svc_program		nfsd_program = {
 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
 	.pg_next		= &nfsd_acl_program,
+#else
+#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
+	.pg_next		= &nfsd_localio_program,
+#endif /* CONFIG_NFSD_LOCALIO */
 #endif
 	.pg_prog		= NFS_PROGRAM,		/* program number */
 	.pg_nvers		= NFSD_MAXVERS+1,	/* nr of entries in nfsd_version */
@@ -944,7 +970,7 @@ nfsd(void *vrqstp)
 }
 
 /**
- * nfsd_dispatch - Process an NFS or NFSACL Request
+ * nfsd_dispatch - Process an NFS or NFSACL or LOCALIO Request
  * @rqstp: incoming request
  *
  * This RPC dispatcher integrates the NFS server's duplicate reply cache.
include/linux/nfs.h +7 -0
index ceb70a926b95..5ff1a5b3b00c 100644
@@ -13,6 +13,13 @@
 #include <linux/crc32.h>
 #include <uapi/linux/nfs.h>
 
+/* The localio program is entirely private to Linux and is
+ * NOT part of the uapi.
+ */
+#define NFS_LOCALIO_PROGRAM		400122
+#define LOCALIOPROC_NULL		0
+#define LOCALIOPROC_UUID_IS_LOCAL	1
+
 /*
  * This is the kernel NFS client file handle representation
  */
Signature · 1 line
2.44.0
#21 lore raw

PATCH v12 12/24 SUNRPC: replace program list with program array

In reply to Mike Snitzer

From: NeilBrown <[email protected]>

A service created with svc_create_pooled() can be given a linked list of programs and all of these will be served.

Using a linked list makes it cumbersome when there are several programs that can be optionally selected with CONFIG settings.

After this patch is applied, API consumers must use only svc_create_pooled() when creating an RPC service that listens for more than one RPC program.

---
 fs/nfsd/nfsctl.c           |  2 +-
 fs/nfsd/nfsd.h             |  2 +-
 fs/nfsd/nfssvc.c           | 67 +++++++++++++++++--------------------
 include/linux/sunrpc/svc.h |  7 ++--
 net/sunrpc/svc.c           | 68 ++++++++++++++++++++++----------------
 net/sunrpc/svc_xprt.c      |  2 +-
 net/sunrpc/svcauth_unix.c  |  3 +-
 7 files changed, 79 insertions(+), 72 deletions(-)
fs/nfsd/nfsctl.c +1 -1
index 1c9e5b4bcb0a..64c1b4d649bc 100644
@@ -2246,7 +2246,7 @@ static __net_init int nfsd_net_init(struct net *net)
 	if (retval)
 		goto out_repcache_error;
 	memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
-	nn->nfsd_svcstats.program = &nfsd_program;
+	nn->nfsd_svcstats.program = &nfsd_programs[0];
 	for (i = 0; i < sizeof(nn->nfsd_versions); i++)
 		nn->nfsd_versions[i] = nfsd_support_version(i);
 	for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
fs/nfsd/nfsd.h +1 -1
index f87a359d968f..232a873dc53a 100644
@@ -85,7 +85,7 @@ struct nfsd_genl_rqstp {
 	u32			rq_opnum[NFSD_MAX_OPS_PER_COMPOUND];
 };
 
-extern struct svc_program	nfsd_program;
+extern struct svc_program	nfsd_programs[];
 extern const struct svc_version	nfsd_version2, nfsd_version3, nfsd_version4;
 extern struct mutex		nfsd_mutex;
 extern spinlock_t		nfsd_drc_lock;
fs/nfsd/nfssvc.c +31 -36

106 lines not on this page · raw message

include/linux/sunrpc/svc.h +4 -3
index 437672bcaa22..c7ad2fb2a155 100644
@@ -67,9 +67,10 @@ enum {
  * We currently do not support more than one RPC program per daemon.
  */
 struct svc_serv {
-	struct svc_program *	sv_program;	/* RPC program */
+	struct svc_program *	sv_programs;	/* RPC programs */
 	struct svc_stat *	sv_stats;	/* RPC statistics */
 	spinlock_t		sv_lock;
+	unsigned int		sv_nprogs;	/* Number of sv_programs */
 	unsigned int		sv_nrthreads;	/* # of server threads */
 	unsigned int		sv_maxconn;	/* max connections allowed or
 						 * '0' causing max to be based
@@ -357,10 +358,9 @@ struct svc_process_info {
 };
 
 /*
- * List of RPC programs on the same transport endpoint
+ * RPC program - an array of these can use the same transport endpoint
  */
 struct svc_program {
-	struct svc_program *	pg_next;	/* other programs (same xprt) */
 	u32			pg_prog;	/* program number */
 	unsigned int		pg_lovers;	/* lowest version */
 	unsigned int		pg_hivers;	/* highest version */
@@ -438,6 +438,7 @@ bool		   svc_rqst_replace_page(struct svc_rqst *rqstp,
 void		   svc_rqst_release_pages(struct svc_rqst *rqstp);
 void		   svc_exit_thread(struct svc_rqst *);
 struct svc_serv *  svc_create_pooled(struct svc_program *prog,
+				     unsigned int nprog,
 				     struct svc_stat *stats,
 				     unsigned int bufsize,
 				     int (*threadfn)(void *data));
net/sunrpc/svc.c +39 -29

166 lines not on this page · raw message

net/sunrpc/svc_xprt.c +1 -1
index 53ebc719ff5a..43c57124de52 100644
@@ -268,7 +268,7 @@ static int _svc_xprt_create(struct svc_serv *serv, const char *xprt_name,
 		spin_unlock(&svc_xprt_class_lock);
 		newxprt = xcl->xcl_ops->xpo_create(serv, net, sap, len, flags);
 		if (IS_ERR(newxprt)) {
-			trace_svc_xprt_create_err(serv->sv_program->pg_name,
+			trace_svc_xprt_create_err(serv->sv_programs->pg_name,
 						  xcl->xcl_name, sap, len,
 						  newxprt);
 			module_put(xcl->xcl_owner);
net/sunrpc/svcauth_unix.c +2 -1
index 04b45588ae6f..8ca98b146ec8 100644
@@ -697,7 +697,8 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
 	rqstp->rq_auth_stat = rpc_autherr_badcred;
 	ipm = ip_map_cached_get(xprt);
 	if (ipm == NULL)
-		ipm = __ip_map_lookup(sn->ip_map_cache, rqstp->rq_server->sv_program->pg_class,
+		ipm = __ip_map_lookup(sn->ip_map_cache,
+				      rqstp->rq_server->sv_programs->pg_class,
 				    &sin6->sin6_addr);
 
 	if (ipm == NULL)
Signature · 1 line
2.44.0
#25 lore raw

PATCH v12 13/24 nfs: pass struct file to nfs_init_pgio and nfs_init_commit

In reply to Mike Snitzer

From: Weston Andros Adamson <[email protected]>

The localio file will be passed, in future commits, by callers that enable localio support (for both regular NFS and pNFS IO).

---
 fs/nfs/filelayout/filelayout.c         | 6 +++---
 fs/nfs/flexfilelayout/flexfilelayout.c | 6 +++---
 fs/nfs/internal.h                      | 6 ++++--
 fs/nfs/pagelist.c                      | 6 ++++--
 fs/nfs/pnfs_nfs.c                      | 2 +-
 fs/nfs/write.c                         | 5 +++--
 6 files changed, 18 insertions(+), 13 deletions(-)
fs/nfs/filelayout/filelayout.c +3 -3
index b6e9aeaf4ce2..d39a1f58e18d 100644
@@ -488,7 +488,7 @@ filelayout_read_pagelist(struct nfs_pgio_header *hdr)
 	/* Perform an asynchronous read to ds */
 	nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
 			  NFS_PROTO(hdr->inode), &filelayout_read_call_ops,
-			  0, RPC_TASK_SOFTCONN);
+			  0, RPC_TASK_SOFTCONN, NULL);
 	return PNFS_ATTEMPTED;
 }
 
@@ -530,7 +530,7 @@ filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
 	/* Perform an asynchronous write */
 	nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
 			  NFS_PROTO(hdr->inode), &filelayout_write_call_ops,
-			  sync, RPC_TASK_SOFTCONN);
+			  sync, RPC_TASK_SOFTCONN, NULL);
 	return PNFS_ATTEMPTED;
 }
 
@@ -1011,7 +1011,7 @@ static int filelayout_initiate_commit(struct nfs_commit_data *data, int how)
 		data->args.fh = fh;
 	return nfs_initiate_commit(ds_clnt, data, NFS_PROTO(data->inode),
 				   &filelayout_commit_call_ops, how,
-				   RPC_TASK_SOFTCONN);
+				   RPC_TASK_SOFTCONN, NULL);
 out_err:
 	pnfs_generic_prepare_to_resend_writes(data);
 	pnfs_generic_commit_release(data);
fs/nfs/flexfilelayout/flexfilelayout.c +3 -3
index d4d551ffea7b..01ee52551a63 100644
@@ -1806,7 +1806,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
 	nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
 			  vers == 3 ? &ff_layout_read_call_ops_v3 :
 				      &ff_layout_read_call_ops_v4,
-			  0, RPC_TASK_SOFTCONN);
+			  0, RPC_TASK_SOFTCONN, NULL);
 	put_cred(ds_cred);
 	return PNFS_ATTEMPTED;
 
@@ -1874,7 +1874,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
 	nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
 			  vers == 3 ? &ff_layout_write_call_ops_v3 :
 				      &ff_layout_write_call_ops_v4,
-			  sync, RPC_TASK_SOFTCONN);
+			  sync, RPC_TASK_SOFTCONN, NULL);
 	put_cred(ds_cred);
 	return PNFS_ATTEMPTED;
 
@@ -1949,7 +1949,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
 	ret = nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops,
 				   vers == 3 ? &ff_layout_commit_call_ops_v3 :
 					       &ff_layout_commit_call_ops_v4,
-				   how, RPC_TASK_SOFTCONN);
+				   how, RPC_TASK_SOFTCONN, NULL);
 	put_cred(ds_cred);
 	return ret;
 out_err:
fs/nfs/internal.h +4 -2
index 5902a9beca1f..9fc6c1a41ee4 100644
@@ -308,7 +308,8 @@ void nfs_pgio_header_free(struct nfs_pgio_header *);
 int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
 int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
-		      const struct rpc_call_ops *call_ops, int how, int flags);
+		      const struct rpc_call_ops *call_ops, int how, int flags,
+		      struct file *localio);
 void nfs_free_request(struct nfs_page *req);
 struct nfs_pgio_mirror *
 nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
@@ -528,7 +529,8 @@ extern int nfs_initiate_commit(struct rpc_clnt *clnt,
 			       struct nfs_commit_data *data,
 			       const struct nfs_rpc_ops *nfs_ops,
 			       const struct rpc_call_ops *call_ops,
-			       int how, int flags);
+			       int how, int flags,
+			       struct file *localio);
 extern void nfs_init_commit(struct nfs_commit_data *data,
 			    struct list_head *head,
 			    struct pnfs_layout_segment *lseg,
fs/nfs/pagelist.c +4 -2
index 04124f226665..532cfaf79813 100644
@@ -731,7 +731,8 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata)
 
 int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
-		      const struct rpc_call_ops *call_ops, int how, int flags)
+		      const struct rpc_call_ops *call_ops, int how, int flags,
+		      struct file *localio)
 {
 	struct rpc_task *task;
 	struct rpc_message msg = {
@@ -961,7 +962,8 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)
 					NFS_PROTO(hdr->inode),
 					desc->pg_rpc_callops,
 					desc->pg_ioflags,
-					RPC_TASK_CRED_NOREF | task_flags);
+					RPC_TASK_CRED_NOREF | task_flags,
+					NULL);
 	}
 	return ret;
 }
fs/nfs/pnfs_nfs.c +1 -1
index a74ee69a2fa6..dbef837e871a 100644
@@ -490,7 +490,7 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
 			nfs_initiate_commit(NFS_CLIENT(inode), data,
 					    NFS_PROTO(data->inode),
 					    data->mds_ops, how,
-					    RPC_TASK_CRED_NOREF);
+					    RPC_TASK_CRED_NOREF, NULL);
 		} else {
 			nfs_init_commit(data, NULL, data->lseg, cinfo);
 			initiate_commit(data, how);
fs/nfs/write.c +3 -2
index d074d0ceb4f0..ad9e98e46a0d 100644
@@ -1663,7 +1663,8 @@ EXPORT_SYMBOL_GPL(nfs_commitdata_release);
 int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,
 			const struct nfs_rpc_ops *nfs_ops,
 			const struct rpc_call_ops *call_ops,
-			int how, int flags)
+			int how, int flags,
+			struct file *localio)
 {
 	struct rpc_task *task;
 	int priority = flush_task_priority(how);
@@ -1809,7 +1810,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
 		task_flags = RPC_TASK_MOVEABLE;
 	return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),
 				   data->mds_ops, how,
-				   RPC_TASK_CRED_NOREF | task_flags);
+				   RPC_TASK_CRED_NOREF | task_flags, NULL);
 }
 
 /*
Signature · 1 line
2.44.0
#26 lore raw

PATCH v12 14/24 nfs: add localio support

In reply to Mike Snitzer

From: Weston Andros Adamson <[email protected]>

Add client support for bypassing NFS for localhost reads, writes, and commits. This is only useful when the client and the server are running on the same host.

nfs_local_probe() is stubbed out, later commits will enable client and server handshake via a Linux-only LOCALIO auxiliary RPC protocol.

This has dynamic binding with the nfsd module (via nfs_localio module which is part of nfs_common). Localio will only work if nfsd is already loaded.

The "localio_enabled" nfs kernel module parameter can be used to disable and enable the ability to use localio support.

CONFIG_NFS_LOCALIO controls the client enablement.

---
 fs/nfs/Kconfig            |  14 +
 fs/nfs/Makefile           |   1 +
 fs/nfs/client.c           |   3 +
 fs/nfs/internal.h         |  51 ++++
 fs/nfs/localio.c          | 613 ++++++++++++++++++++++++++++++++++++++
 fs/nfs/nfstrace.h         |  61 ++++
 fs/nfs/pagelist.c         |   4 +
 fs/nfs/write.c            |   3 +
 include/linux/nfs.h       |   2 +
 include/linux/nfs_fs_sb.h |   1 +
 10 files changed, 753 insertions(+)
 create mode 100644 fs/nfs/localio.c
fs/nfs/Kconfig +14 -0
index 0eb20012792f..d52a1df28f69 100644
@@ -87,6 +87,20 @@ config NFS_V4
 
 	  If unsure, say Y.
 
+config NFS_LOCALIO
+	bool "NFS client support for the LOCALIO auxiliary protocol"
+	depends on NFS_FS
+	select NFS_COMMON_LOCALIO_SUPPORT
+	help
+	  Some NFS servers support an auxiliary NFS LOCALIO protocol
+	  that is not an official part of the NFS protocol.
+
+	  This option enables support for the LOCALIO protocol in the
+	  kernel's NFS client.  Enable this to bypass using the NFS
+	  protocol when issuing reads, writes and commits to the server.
+
+	  If unsure, say N.
+
 config NFS_SWAP
 	bool "Provide swap over NFS support"
 	default n
fs/nfs/Makefile +1 -0
index 5f6db37f461e..9fb2f2cac87e 100644
@@ -13,6 +13,7 @@ nfs-y 			:= client.o dir.o file.o getroot.o inode.o super.o \
 nfs-$(CONFIG_ROOT_NFS)	+= nfsroot.o
 nfs-$(CONFIG_SYSCTL)	+= sysctl.o
 nfs-$(CONFIG_NFS_FSCACHE) += fscache.o
+nfs-$(CONFIG_NFS_LOCALIO) += localio.o
 
 obj-$(CONFIG_NFS_V2) += nfsv2.o
 nfsv2-y := nfs2super.o proc.o nfs2xdr.o
fs/nfs/client.c +3 -0
index 1b65a5d7af49..bf327ddbdd25 100644
@@ -242,6 +242,8 @@ static void pnfs_init_server(struct nfs_server *server)
  */
 void nfs_free_client(struct nfs_client *clp)
 {
+	nfs_local_disable(clp);
+
 	/* -EIO all pending I/O */
 	if (!IS_ERR(clp->cl_rpcclient))
 		rpc_shutdown_client(clp->cl_rpcclient);
@@ -433,6 +435,7 @@ struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)
 			list_add_tail(&new->cl_share_link,
 					&nn->nfs_client_list);
 			spin_unlock(&nn->nfs_client_lock);
+			nfs_local_probe(new);
 			return rpc_ops->init_client(new, cl_init);
 		}
 
fs/nfs/internal.h +51 -0

57 lines not on this page · raw message

fs/nfs/localio.c new file +613 -0

613 lines not on this page · raw message

fs/nfs/nfstrace.h +61 -0

67 lines not on this page · raw message

fs/nfs/pagelist.c +4 -0
index 532cfaf79813..c4160edd377e 100644
@@ -762,6 +762,10 @@ int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
 		hdr->args.count,
 		(unsigned long long)hdr->args.offset);
 
+	if (localio)
+		return nfs_local_doio(NFS_SERVER(hdr->inode)->nfs_client,
+				      localio, hdr, call_ops);
+
 	task = rpc_run_task(&task_setup_data);
 	if (IS_ERR(task))
 		return PTR_ERR(task);
fs/nfs/write.c +3 -0
index ad9e98e46a0d..8bc807a3e041 100644
@@ -1693,6 +1693,9 @@ int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,
 
 	dprintk("NFS: initiated commit call\n");
 
+	if (localio)
+		return nfs_local_commit(localio, data, call_ops, how);
+
 	task = rpc_run_task(&task_setup_data);
 	if (IS_ERR(task))
 		return PTR_ERR(task);
include/linux/nfs.h +2 -0
index 5ff1a5b3b00c..89ef8c5e98db 100644
@@ -8,6 +8,8 @@
 #ifndef _LINUX_NFS_H
 #define _LINUX_NFS_H
 
+#include <linux/cred.h>
+#include <linux/sunrpc/auth.h>
 #include <linux/sunrpc/msg_prot.h>
 #include <linux/string.h>
 #include <linux/crc32.h>
include/linux/nfs_fs_sb.h +1 -0
index 3849cc2832f0..5edc57657985 100644
@@ -50,6 +50,7 @@ struct nfs_client {
 #define NFS_CS_DS		7		/* - Server is a DS */
 #define NFS_CS_REUSEPORT	8		/* - reuse src port on reconnect */
 #define NFS_CS_PNFS		9		/* - Server used for pnfs */
+#define NFS_CS_LOCAL_IO		10		/* - client is local */
 	struct sockaddr_storage	cl_addr;	/* server identifier */
 	size_t			cl_addrlen;
 	char *			cl_hostname;	/* hostname of server */
Signature · 1 line
2.44.0
#27 lore raw

PATCH v12 15/24 nfs: enable localio for non-pNFS IO

In reply to Mike Snitzer

From: Trond Myklebust <[email protected]>

Try a local open of the file being written to, and if it succeeds, then use localio to issue IO.

---
 fs/nfs/pagelist.c | 8 +++++++-
 fs/nfs/write.c    | 6 +++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
fs/nfs/pagelist.c +7 -1
index c4160edd377e..1bd0224f7ee8 100644
@@ -958,6 +958,12 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)
 	nfs_pgheader_init(desc, hdr, nfs_pgio_header_free);
 	ret = nfs_generic_pgio(desc, hdr);
 	if (ret == 0) {
+		struct nfs_client *clp = NFS_SERVER(hdr->inode)->nfs_client;
+
+		struct file *filp = nfs_local_file_open(clp, hdr->cred,
+							hdr->args.fh,
+							hdr->args.context);
+
 		if (NFS_SERVER(hdr->inode)->nfs_client->cl_minorversion)
 			task_flags = RPC_TASK_MOVEABLE;
 		ret = nfs_initiate_pgio(NFS_CLIENT(hdr->inode),
@@ -967,7 +973,7 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)
 					desc->pg_rpc_callops,
 					desc->pg_ioflags,
 					RPC_TASK_CRED_NOREF | task_flags,
-					NULL);
+					filp);
 	}
 	return ret;
 }
fs/nfs/write.c +5 -1
index 8bc807a3e041..6436db54b2fc 100644
@@ -1795,6 +1795,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
 		struct nfs_commit_info *cinfo)
 {
 	struct nfs_commit_data	*data;
+	struct file *filp;
 	unsigned short task_flags = 0;
 
 	/* another commit raced with us */
@@ -1811,9 +1812,12 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
 	nfs_init_commit(data, head, NULL, cinfo);
 	if (NFS_SERVER(inode)->nfs_client->cl_minorversion)
 		task_flags = RPC_TASK_MOVEABLE;
+
+	filp = nfs_local_file_open(NFS_SERVER(inode)->nfs_client, data->cred,
+				   data->args.fh, data->context);
 	return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),
 				   data->mds_ops, how,
-				   RPC_TASK_CRED_NOREF | task_flags, NULL);
+				   RPC_TASK_CRED_NOREF | task_flags, filp);
 }
 
 /*
Signature · 1 line
2.44.0
#28 lore raw

PATCH v12 16/24 pnfs/flexfiles: enable localio support

In reply to Mike Snitzer

From: Trond Myklebust <[email protected]>

If the DS is local to this client use localio to write the data.

---
 fs/nfs/flexfilelayout/flexfilelayout.c    | 109 ++++++++++++++++++++--
 fs/nfs/flexfilelayout/flexfilelayout.h    |   2 +
 fs/nfs/flexfilelayout/flexfilelayoutdev.c |   6 ++
 3 files changed, 110 insertions(+), 7 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +102 -7
index 01ee52551a63..206b4b524e43 100644
@@ -11,6 +11,7 @@
 #include <linux/nfs_mount.h>
 #include <linux/nfs_page.h>
 #include <linux/module.h>
+#include <linux/file.h>
 #include <linux/sched/mm.h>
 
 #include <linux/sunrpc/metrics.h>
@@ -162,6 +163,52 @@ decode_name(struct xdr_stream *xdr, u32 *id)
 	return 0;
 }
 
+static struct file *
+ff_local_open_fh(struct pnfs_layout_segment *lseg,
+		 u32 ds_idx,
+		 struct nfs_client *clp,
+		 const struct cred *cred,
+		 struct nfs_fh *fh,
+		 fmode_t mode)
+{
+	struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
+	struct file *filp, *new, __rcu **pfile;
+
+	if (!nfs_server_is_local(clp))
+		return NULL;
+	if (mode & FMODE_WRITE) {
+		/*
+		 * Always request read and write access since this corresponds
+		 * to a rw layout.
+		 */
+		mode |= FMODE_READ;
+		pfile = &mirror->rw_file;
+	} else
+		pfile = &mirror->ro_file;
+
+	new = NULL;
+	rcu_read_lock();
+	filp = rcu_dereference(*pfile);
+	if (!filp) {
+		rcu_read_unlock();
+		new = nfs_local_open_fh(clp, cred, fh, mode);
+		if (IS_ERR(new))
+			return NULL;
+		rcu_read_lock();
+		/* try to swap in the pointer */
+		filp = cmpxchg(pfile, NULL, new);
+		if (!filp) {
+			filp = new;
+			new = NULL;
+		}
+	}
+	filp = get_file_rcu(&filp);
+	rcu_read_unlock();
+	if (new)
+		fput(new);
+	return filp;
+}
+
 static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror *m1,
 		const struct nfs4_ff_layout_mirror *m2)
 {
@@ -237,8 +284,15 @@ static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
 
 static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
 {
+	struct file *filp;
 	const struct cred	*cred;
 
+	filp = rcu_access_pointer(mirror->ro_file);
+	if (filp)
+		fput(filp);
+	filp = rcu_access_pointer(mirror->rw_file);
+	if (filp)
+		fput(filp);
 	ff_layout_remove_mirror(mirror);
 	kfree(mirror->fh_versions);
 	cred = rcu_access_pointer(mirror->ro_cred);
@@ -414,6 +468,7 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
 		struct nfs4_ff_layout_mirror *mirror;
 		struct cred *kcred;
 		const struct cred __rcu *cred;
+		const struct cred __rcu *old;
 		kuid_t uid;
 		kgid_t gid;
 		u32 ds_count, fh_count, id;
@@ -513,13 +568,26 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
 
 		mirror = ff_layout_add_mirror(lh, fls->mirror_array[i]);
 		if (mirror != fls->mirror_array[i]) {
+			struct file *filp;
+
 			/* swap cred ptrs so free_mirror will clean up old */
 			if (lgr->range.iomode == IOMODE_READ) {
-				cred = xchg(&mirror->ro_cred, cred);
-				rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
+				old = xchg(&mirror->ro_cred, cred);
+				rcu_assign_pointer(fls->mirror_array[i]->ro_cred, old);
+				/* drop file if creds changed */
+				if (old != cred) {
+					filp = rcu_dereference_protected(xchg(&mirror->ro_file, NULL), 1);
+					if (filp)
+						fput(filp);
+				}
 			} else {
-				cred = xchg(&mirror->rw_cred, cred);
-				rcu_assign_pointer(fls->mirror_array[i]->rw_cred, cred);
+				old = xchg(&mirror->rw_cred, cred);
+				rcu_assign_pointer(fls->mirror_array[i]->rw_cred, old);
+				if (old != cred) {
+					filp = rcu_dereference_protected(xchg(&mirror->rw_file, NULL), 1);
+					if (filp)
+						fput(filp);
+				}
 			}
 			ff_layout_free_mirror(fls->mirror_array[i]);
 			fls->mirror_array[i] = mirror;
@@ -1756,6 +1824,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
 	struct pnfs_layout_segment *lseg = hdr->lseg;
 	struct nfs4_pnfs_ds *ds;
 	struct rpc_clnt *ds_clnt;
+	struct file *filp;
 	struct nfs4_ff_layout_mirror *mirror;
 	const struct cred *ds_cred;
 	loff_t offset = hdr->args.offset;
@@ -1802,11 +1871,19 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
 	hdr->args.offset = offset;
 	hdr->mds_offset = offset;
 
+	/* Start IO accounting for local read */
+	filp = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
+				FMODE_READ);
+	if (filp) {
+		hdr->task.tk_start = ktime_get();
+		ff_layout_read_record_layoutstats_start(&hdr->task, hdr);
+	}
+
 	/* Perform an asynchronous read to ds */
 	nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
 			  vers == 3 ? &ff_layout_read_call_ops_v3 :
 				      &ff_layout_read_call_ops_v4,
-			  0, RPC_TASK_SOFTCONN, NULL);
+			  0, RPC_TASK_SOFTCONN, filp);
 	put_cred(ds_cred);
 	return PNFS_ATTEMPTED;
 
@@ -1826,6 +1903,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
 	struct pnfs_layout_segment *lseg = hdr->lseg;
 	struct nfs4_pnfs_ds *ds;
 	struct rpc_clnt *ds_clnt;
+	struct file *filp;
 	struct nfs4_ff_layout_mirror *mirror;
 	const struct cred *ds_cred;
 	loff_t offset = hdr->args.offset;
@@ -1870,11 +1948,19 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
 	 */
 	hdr->args.offset = offset;
 
+	/* Start IO accounting for local write */
+	filp = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
+				FMODE_READ|FMODE_WRITE);
+	if (filp) {
+		hdr->task.tk_start = ktime_get();
+		ff_layout_write_record_layoutstats_start(&hdr->task, hdr);
+	}
+
 	/* Perform an asynchronous write */
 	nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
 			  vers == 3 ? &ff_layout_write_call_ops_v3 :
 				      &ff_layout_write_call_ops_v4,
-			  sync, RPC_TASK_SOFTCONN, NULL);
+			  sync, RPC_TASK_SOFTCONN, filp);
 	put_cred(ds_cred);
 	return PNFS_ATTEMPTED;
 
@@ -1908,6 +1994,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
 	struct pnfs_layout_segment *lseg = data->lseg;
 	struct nfs4_pnfs_ds *ds;
 	struct rpc_clnt *ds_clnt;
+	struct file *filp;
 	struct nfs4_ff_layout_mirror *mirror;
 	const struct cred *ds_cred;
 	u32 idx;
@@ -1946,10 +2033,18 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
 	if (fh)
 		data->args.fh = fh;
 
+	/* Start IO accounting for local commit */
+	filp = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
+				FMODE_READ|FMODE_WRITE);
+	if (filp) {
+		data->task.tk_start = ktime_get();
+		ff_layout_commit_record_layoutstats_start(&data->task, data);
+	}
+
 	ret = nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops,
 				   vers == 3 ? &ff_layout_commit_call_ops_v3 :
 					       &ff_layout_commit_call_ops_v4,
-				   how, RPC_TASK_SOFTCONN, NULL);
+				   how, RPC_TASK_SOFTCONN, filp);
 	put_cred(ds_cred);
 	return ret;
 out_err:
fs/nfs/flexfilelayout/flexfilelayout.h +2 -0
index f84b3fb0dddd..8e042df5a2c9 100644
@@ -82,7 +82,9 @@ struct nfs4_ff_layout_mirror {
 	struct nfs_fh			*fh_versions;
 	nfs4_stateid			stateid;
 	const struct cred __rcu		*ro_cred;
+	struct file __rcu		*ro_file;
 	const struct cred __rcu		*rw_cred;
+	struct file __rcu		*rw_file;
 	refcount_t			ref;
 	spinlock_t			lock;
 	unsigned long			flags;
fs/nfs/flexfilelayout/flexfilelayoutdev.c +6 -0
index e028f5a0ef5f..e58bedfb1dcc 100644
@@ -395,6 +395,12 @@ nfs4_ff_layout_prepare_ds(struct pnfs_layout_segment *lseg,
 
 	/* connect success, check rsize/wsize limit */
 	if (!status) {
+		/*
+		 * ds_clp is put in destroy_ds().
+		 * keep ds_clp even if DS is local, so that if local IO cannot
+		 * proceed somehow, we can fall back to NFS whenever we want.
+		 */
+		nfs_local_probe(ds->ds_clp);
 		max_payload =
 			nfs_block_size(rpc_max_payload(ds->ds_clp->cl_rpcclient),
 				       NULL);
Signature · 1 line
2.44.0
#29 lore raw

PATCH v12 17/24 nfs/localio: use dedicated workqueues for filesystem read and write

In reply to Mike Snitzer

From: Trond Myklebust <[email protected]>

For localio access, don't call filesystem read() and write() routines directly. This solves two problems:

1) localio writes need to use a normal (non-memreclaim) unbound workqueue. This avoids imposing new requirements on how underlying filesystems process frontend IO, which would cause a large amount of work to update all filesystems. Without this change, when XFS starts getting low on space, XFS flushes work on a non-memreclaim work queue, which causes a priority inversion problem:

00573 workqueue: WQ_MEM_RECLAIM writeback:wb_workfn is flushing !WQ_MEM_RECLAIM xfs-sync/vdc:xfs_flush_inodes_worker 00573 WARNING: CPU: 6 PID: 8525 at kernel/workqueue.c:3706 check_flush_dependency+0x2a4/0x328 00573 Modules linked in:
00573 CPU: 6 PID: 8525 Comm: kworker/u71:5 Not tainted 6.10.0-rc3-ktest-00032-g2b0a133403ab #18502 00573 Hardware name: linux,dummy-virt (DT)
00573 Workqueue: writeback wb_workfn (flush-0:33)
00573 pstate: 400010c5 (nZcv daIF -PAN -UAO -TCO -DIT +SSBS BTYPE=--)
00573 pc : check_flush_dependency+0x2a4/0x328
00573 lr : check_flush_dependency+0x2a4/0x328
00573 sp : ffff0000c5f06bb0
00573 x29: ffff0000c5f06bb0 x28: ffff0000c998a908 x27: 1fffe00019331521
00573 x26: ffff0000d0620900 x25: ffff0000c5f06ca0 x24: ffff8000828848c0
00573 x23: 1fffe00018be0d8e x22: ffff0000c1210000 x21: ffff0000c75fde00
00573 x20: ffff800080bfd258 x19: ffff0000cad63400 x18: ffff0000cd3a4810
00573 x17: 0000000000000000 x16: 0000000000000000 x15: ffff800080508d98
00573 x14: 0000000000000000 x13: 204d49414c434552 x12: 1fffe0001b6eeab2
00573 x11: ffff60001b6eeab2 x10: dfff800000000000 x9 : ffff60001b6eeab3
00573 x8 : 0000000000000001 x7 : 00009fffe491154e x6 : ffff0000db775593
00573 x5 : ffff0000db775590 x4 : ffff0000db775590 x3 : 0000000000000000
00573 x2 : 0000000000000027 x1 : ffff600018be0d62 x0 : dfff800000000000
00573 Call trace:

00573  check_flush_dependency+0x2a4/0x328
00573  __flush_work+0x184/0x5c8
00573  flush_work+0x18/0x28
00573  xfs_flush_inodes+0x68/0x88
00573  xfs_file_buffered_write+0x128/0x6f0
00573  xfs_file_write_iter+0x358/0x448
00573  nfs_local_doio+0x854/0x1568
00573  nfs_initiate_pgio+0x214/0x418
00573  nfs_generic_pg_pgios+0x304/0x480
00573  nfs_pageio_doio+0xe8/0x240
00573  nfs_pageio_complete+0x160/0x480
00573  nfs_writepages+0x300/0x4f0
00573  do_writepages+0x12c/0x4a0
00573  __writeback_single_inode+0xd4/0xa68
00573  writeback_sb_inodes+0x470/0xcb0
00573  __writeback_inodes_wb+0xb0/0x1d0
00573  wb_writeback+0x594/0x808
00573  wb_workfn+0x5e8/0x9e0
00573  process_scheduled_works+0x53c/0xd90
00573  worker_thread+0x370/0x8c8
00573  kthread+0x258/0x2e8
00573  ret_from_fork+0x10/0x20

2) Some filesystem writeback routines can end up taking up a lot of stack space (particularly XFS). Instead of risking running over due to the extra overhead from the NFS stack, we should just call these routines from a workqueue job. Since we need to do this to address 1) above we're able to avoid possibly blowing the stack "for free".

Use of dedicated workqueues improves performance over using the system_unbound_wq.

Also, the creds used to open the file are used to override_creds() in both nfs_local_call_read() and nfs_local_call_write() -- otherwise the workqueue could have elevated capabilities (which the caller may not).

Lastly, care is taken to set PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO in nfs_do_local_write() to avoid writeback deadlocks.

The PF_LOCAL_THROTTLE flag prevents deadlocks in balance_dirty_pages() by causing writes to only be throttled against other writes to the same bdi (it keeps the throttling local). Normally all writes to bdi(s) are throttled equally (after throughput factors are allowed for).

The PF_MEMALLOC_NOIO flag prevents the lower filesystem IO from causing memory reclaim to re-enter filesystems or IO devices and so prevents deadlocks from occuring where IO that cleans pages is waiting on IO to complete.

---
 fs/nfs/inode.c    | 57 ++++++++++++++++++++++------------
 fs/nfs/internal.h |  1 +
 fs/nfs/localio.c  | 79 +++++++++++++++++++++++++++++++++--------------
 3 files changed, 95 insertions(+), 42 deletions(-)
fs/nfs/inode.c +38 -19
index b4914a11c3c2..542c7d97b235 100644
@@ -2461,35 +2461,54 @@ static void nfs_destroy_inodecache(void)
 	kmem_cache_destroy(nfs_inode_cachep);
 }
 
+struct workqueue_struct *nfslocaliod_workqueue;
 struct workqueue_struct *nfsiod_workqueue;
 EXPORT_SYMBOL_GPL(nfsiod_workqueue);
 
 /*
- * start up the nfsiod workqueue
- */
-static int nfsiod_start(void)
-{
-	struct workqueue_struct *wq;
-	dprintk("RPC:       creating workqueue nfsiod\n");
-	wq = alloc_workqueue("nfsiod", WQ_MEM_RECLAIM | WQ_UNBOUND, 0);
-	if (wq == NULL)
-		return -ENOMEM;
-	nfsiod_workqueue = wq;
-	return 0;
-}
-
-/*
- * Destroy the nfsiod workqueue
+ * Destroy the nfsiod workqueues
  */
 static void nfsiod_stop(void)
 {
 	struct workqueue_struct *wq;
 
 	wq = nfsiod_workqueue;
-	if (wq == NULL)
-		return;
-	nfsiod_workqueue = NULL;
-	destroy_workqueue(wq);
+	if (wq != NULL) {
+		nfsiod_workqueue = NULL;
+		destroy_workqueue(wq);
+	}
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	wq = nfslocaliod_workqueue;
+	if (wq != NULL) {
+		nfslocaliod_workqueue = NULL;
+		destroy_workqueue(wq);
+	}
+#endif /* CONFIG_NFS_LOCALIO */
+}
+
+/*
+ * Start the nfsiod workqueues
+ */
+static int nfsiod_start(void)
+{
+	dprintk("RPC:       creating workqueue nfsiod\n");
+	nfsiod_workqueue = alloc_workqueue("nfsiod", WQ_MEM_RECLAIM | WQ_UNBOUND, 0);
+	if (nfsiod_workqueue == NULL)
+		return -ENOMEM;
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	/*
+	 * localio writes need to use a normal (non-memreclaim) workqueue.
+	 * When we start getting low on space, XFS goes and calls flush_work() on
+	 * a non-memreclaim work queue, which causes a priority inversion problem.
+	 */
+	dprintk("RPC:       creating workqueue nfslocaliod\n");
+	nfslocaliod_workqueue = alloc_workqueue("nfslocaliod", WQ_UNBOUND, 0);
+	if (unlikely(nfslocaliod_workqueue == NULL)) {
+		nfsiod_stop();
+		return -ENOMEM;
+	}
+#endif /* CONFIG_NFS_LOCALIO */
+	return 0;
 }
 
 unsigned int nfs_net_id;
fs/nfs/internal.h +1 -0
index acb9d8bb4076..23f0d180fd19 100644
@@ -439,6 +439,7 @@ int nfs_check_flags(int);
 
 /* inode.c */
 extern struct workqueue_struct *nfsiod_workqueue;
+extern struct workqueue_struct *nfslocaliod_workqueue;
 extern struct inode *nfs_alloc_inode(struct super_block *sb);
 extern void nfs_free_inode(struct inode *);
 extern int nfs_write_inode(struct inode *, struct writeback_control *);
fs/nfs/localio.c +56 -23

121 lines not on this page · raw message

Signature · 1 line
2.44.0
#30 lore raw

PATCH v12 18/24 nfs: implement client support for NFS_LOCALIO_PROGRAM

In reply to Mike Snitzer

The LOCALIO auxiliary RPC protocol consists of a single "UUID_IS_LOCAL" RPC method that allows the Linux NFS client to verify the local Linux NFS server can see the nonce (single-use UUID) the client generated and made available in nfs_common for subsequent lookup and verification by the NFS server. If matched, the NFS server populates members in the nfs_uuid_t struct. The NFS client then transfers these nfs_uuid_t struct member pointers to the nfs_client struct and cleans up the nfs_uuid_t struct. See: fs/nfs/localio.c:nfs_local_probe()

This protocol isn't part of an IETF standard, nor does it need to be considering it is Linux-to-Linux auxiliary RPC protocol that amounts to an implementation detail.

Localio is only supported when UNIX-style authentication (AUTH_UNIX, aka AUTH_SYS) is used (enforced by fs/nfs/localio.c:nfs_local_probe()).

The UUID_IS_LOCAL method encodes the client generated uuid_t in terms of the fixed UUID_SIZE (16 bytes). The fixed size opaque encode and decode XDR methods are used instead of the less efficient variable sized methods.

Having a nonce (single-use uuid) is better than using the same uuid for the life of the server, and sending it proactively by client rather than reactively by the server is also safer.

[NeilBrown factored out and simplified a single localio protocol and proposed making the uuid short-lived]

---
 fs/nfs/client.c  |   6 +-
 fs/nfs/localio.c | 148 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 147 insertions(+), 7 deletions(-)
fs/nfs/client.c +4 -2
index bf327ddbdd25..23fe1611cc9f 100644
@@ -435,8 +435,10 @@ struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init)
 			list_add_tail(&new->cl_share_link,
 					&nn->nfs_client_list);
 			spin_unlock(&nn->nfs_client_lock);
-			nfs_local_probe(new);
-			return rpc_ops->init_client(new, cl_init);
+			new = rpc_ops->init_client(new, cl_init);
+			if (!IS_ERR(new))
+				 nfs_local_probe(new);
+			return new;
 		}
 
 		spin_unlock(&nn->nfs_client_lock);
fs/nfs/localio.c +143 -5

185 lines not on this page · raw message

Signature · 1 line
2.44.0
#31 lore raw

PATCH v12 19/24 nfs: add Documentation/filesystems/nfs/localio.rst

In reply to Mike Snitzer

This document gives an overview of the LOCALIO auxiliary RPC protocol added to the Linux NFS client and server to allow them to reliably handshake to determine if they are on the same host.

Once an NFS client and server handshake as "local", the client will bypass the network RPC protocol for read, write and commit operations. Due to this XDR and RPC bypass, these operations will operate faster.

---
 Documentation/filesystems/nfs/localio.rst | 178 ++++++++++++++++++++++
 include/linux/nfslocalio.h                |   2 +
 2 files changed, 180 insertions(+)
 create mode 100644 Documentation/filesystems/nfs/localio.rst
Documentation/filesystems/nfs/localio.rst new file +178 -0
new file mode 100644
index 000000000000..d8bdab88f1db
@@ -0,0 +1,178 @@
+===========
+NFS LOCALIO
+===========
+
+Overview
+========
+
+The LOCALIO auxiliary RPC protocol allows the Linux NFS client and
+server to reliably handshake to determine if they are on the same host.
+
+Once an NFS client and server handshake as "local", the client will
+bypass the network RPC protocol for read, write and commit operations.
+Due to this XDR and RPC bypass, these operations will operate faster.
+
+The LOCALIO auxiliary protocol's implementation, which uses the same
+connection as NFS traffic, follows the pattern established by the NFS
+ACL protocol extension.
+
+The LOCALIO auxiliary protocol is needed to allow robust discovery of
+clients local to their servers. In a private implementation that
+preceded use of this LOCALIO protocol, a fragile sockaddr network
+address based match against all local network interfaces was attempted.
+But unlike the LOCALIO protocol, the sockaddr-based matching didn't
+handle use of iptables or containers.
+
+The robust handshake between local client and server is just the
+beginning, the ultimate use case this locality makes possible is the
+client is able to open files and issue reads, writes and commits
+directly to the server without having to go over the network. The
+requirement is to perform these loopback NFS operations as efficiently
+as possible, this is particularly useful for container use cases
+(e.g. kubernetes) where it is possible to run an IO job local to the
+server.
+
+The performance advantage realized from LOCALIO's ability to bypass
+using XDR and RPC for reads, writes and commits can be extreme, e.g.:
+fio for 20 secs with 24 libaio threads, 128k directio reads, qd of 8,
+- With LOCALIO:
+  read: IOPS=311k, BW=38.0GiB/s (40.8GB/s)(760GiB/20001msec)
+- Without LOCALIO:
+  read: IOPS=12.0k, BW=1495MiB/s (1568MB/s)(29.2GiB/20015msec)
+
+RPC
+===
+
+The LOCALIO auxiliary RPC protocol consists of a single "UUID_IS_LOCAL"
+RPC method that allows the Linux NFS client to verify the local Linux
+NFS server can see the nonce (single-use UUID) the client generated and
+made available in nfs_common. This protocol isn't part of an IETF
+standard, nor does it need to be considering it is Linux-to-Linux
+auxiliary RPC protocol that amounts to an implementation detail.
+
+The UUID_IS_LOCAL method encodes the client generated uuid_t in terms of
+the fixed UUID_SIZE (16 bytes). The fixed size opaque encode and decode
+XDR methods are used instead of the less efficient variable sized
+methods.
+
+The RPC program number for the NFS_LOCALIO_PROGRAM is 400122 (as assigned
+by IANA, see https://www.iana.org/assignments/rpc-program-numbers/ ):
+Linux Kernel Organization       400122  nfslocalio
+
+The LOCALIO protocol spec in rpcgen syntax is:
+
+/* raw RFC 9562 UUID */
+#define UUID_SIZE 16
+typedef u8 uuid_t<UUID_SIZE>;
+
+program NFS_LOCALIO_PROGRAM {
+    version LOCALIO_V1 {
+        void
+            NULL(void) = 0;
+
+        void
+            UUID_IS_LOCAL(uuid_t) = 1;
+    } = 1;
+} = 400122;
+
+LOCALIO uses the same transport connection as NFS traffic. As such,
+LOCALIO is not registered with rpcbind.
+
+NFS Common and Client/Server Handshake
+======================================
+
+fs/nfs_common/nfslocalio.c provides interfaces that enable an NFS client
+to generate a nonce (single-use UUID) and associated short-lived
+nfs_uuid_t struct, register it with nfs_common for subsequent lookup and
+verification by the NFS server and if matched the NFS server populates
+members in the nfs_uuid_t struct. The nfs client then transfers these
+nfs_uuid_t struct member pointers to the nfs_client struct and cleans up
+the nfs_uuid_t struct.  See: fs/nfs/localio.c:nfs_local_probe()
+
+nfs_common's nfs_uuids list is the basis for LOCALIO enablement, as such
+it has members that point to nfsd memory for direct use by the client
+(e.g. 'net' is the server's network namespace, through it the client can
+access nn->nfsd_serv with proper rcu read access). It is this client
+and server synchronization that enables advanced usage and lifetime of
+objects to span from the host kernel's nfsd to per-container knfsd
+instances that are connected to nfs client's running on the same local
+host.
+
+NFS Client issues IO instead of Server
+======================================
+
+Because LOCALIO is focused on protocol bypass to achieve improved IO
+performance alternatives to traditional NFS wire protocol (SUNRPC with
+XDR) to access the backing filesystem must be provided.
+
+See fs/nfs/localio.c:nfs_local_open_fh() and
+fs/nfsd/localio.c:nfsd_open_local_fh() for the interface that makes
+focused use of select nfs server objects to allow a client local to a
+server to open a file pointer without needing to go over the network.
+
+The client's fs/nfs/localio.c:nfs_local_open_fh() will call into the
+server's fs/nfsd/localio.c:nfsd_open_local_fh() and carefully access
+both the nfsd network namespace and the associated nn->nfsd_serv in
+terms of RCU. If nfsd_open_local_fh() finds that client no longer sees
+valid nfsd objects (be it struct net or nn->nfsd_serv) it returns ENXIO
+to nfs_local_open_fh() and the client will try to reestablish the
+LOCALIO resources needed by calling nfs_local_probe() again. This
+recovery is needed if/when an nfsd instance running in a container were
+to reboot while a LOCALIO client is connected to it.
+
+Once the client has an open file pointer it will issue reads, writes and
+commits directly to the underlying local filesystem (normally done by
+the nfs server). As such, for these operations, the NFS client is
+issuing IO to the underlying local filesystem that it is sharing with
+the NFS server. See: fs/nfs/localio.c:nfs_local_doio() and
+fs/nfs/localio.c:nfs_local_commit().
+
+Security
+========
+
+Localio is only supported when UNIX-style authentication (AUTH_UNIX, aka
+AUTH_SYS) is used.
+
+Care is taken to ensure the same NFS security mechanisms are used
+(authentication, etc) regardless of whether LOCALIO or regular NFS
+access is used. The auth_domain established as part of the traditional
+NFS client access to the NFS server is also used for LOCALIO.
+
+Relative to containers, LOCALIO gives the client access to the network
+namespace the server has. This is required to allow the client to access
+the server's per-namespace nfsd_net struct. With traditional NFS, the
+client is afforded this same level of access (albeit in terms of the NFS
+protocol via SUNRPC). No other namespaces (user, mount, etc) have been
+altered or purposely extended from the server to the client.
+
+Testing
+=======
+
+The LOCALIO auxiliary protocol and associated NFS LOCALIO read, write
+and commit access have proven stable against various test scenarios:
+
+- Client and server both on the same host.
+
+- All permutations of client and server support enablement for both
+  local and remote client and server.
+
+- Testing against NFS storage products that don't support the LOCALIO
+  protocol was also performed.
+
+- Client on host, server within a container (for both v3 and v4.2).
+  The container testing was in terms of podman managed containers and
+  includes successful container stop/restart scenario.
+
+- Formalizing these test scenarios in terms of existing test
+  infrastructure is on-going. Initial regular coverage is provided in
+  terms of ktest running xfstests against a LOCALIO-enabled NFS loopback
+  mount configuration, and includes lockdep and KASAN coverage, see:
+  https://evilpiepirate.org/~testdashboard/ci?user=snitzer&branch=snitm-nfs-next
+  https://github.com/koverstreet/ktest
+
+- Various kdevops testing (in terms of "Chuck's BuildBot") has been
+  performed to regularly verify the LOCALIO changes haven't caused any
+  regressions to non-LOCALIO NFS use cases.
+
+- All of Hammerspace's various sanity tests pass with LOCALIO enabled
+  (this includes numerous pNFS and flexfiles tests).
include/linux/nfslocalio.h +2 -0
index 109cb8534e3f..c6edcb7c0dcd 100644
@@ -15,6 +15,8 @@
 /*
  * Useful to allow a client to negotiate if localio
  * possible with its server.
+ *
+ * See Documentation/filesystems/nfs/localio.rst for more detail.
  */
 typedef struct {
 	uuid_t uuid;
Signature · 1 line
2.44.0
#32 lore raw

PATCH v12 20/24 nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local

In reply to Mike Snitzer

Offers performance improvements if/when a file is reopened before launderette cleans it from the filecache's LRU.

---
 fs/nfsd/filecache.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/nfsd/filecache.c +5 -4
index 56be99a3667a..447faa194166 100644
@@ -1197,9 +1197,10 @@ nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
  * a file.  The security implications of this should be carefully
  * considered before use.
  *
- * The nfsd_file_object returned by this API is reference-counted
- * but not garbage-collected. The object is unhashed after the
- * final nfsd_file_put().
+ * The nfsd_file object returned by this API is reference-counted
+ * and garbage-collected. The object is retained for a few
+ * seconds after the final nfsd_file_put() in case the caller
+ * wants to re-use it.
  *
  * Return values:
  *   %nfs_ok - @pnf points to an nfsd_file with its reference
@@ -1214,7 +1215,7 @@ nfsd_file_acquire_local(struct net *net, struct svc_cred *cred,
 			unsigned int may_flags, struct nfsd_file **pnf)
 {
 	return nfsd_file_do_acquire(NULL, net, cred, nfs_vers, client,
-				    fhp, may_flags, NULL, pnf, false);
+				    fhp, may_flags, NULL, pnf, true);
 }
 
 /**
Signature · 1 line
2.44.0
#34 lore raw

PATCH v12 21/24 nfs_common: expose localio's required nfsd symbols to nfs client

In reply to Mike Snitzer

From: Mike Snitzer <[email protected]>

Switch the caching of nfsd_open_local_fh symbol from being within each nfs_client struct to being globally maintained within nfs_common (accessible via the global 'nfs_to' nfs_to_nfsd_t struct).

Introduce nfsd_file_file() wrapper that provides access to nfsd_file's backing file. Keeps nfsd_file structure opaque to NFS client (as suggested by Jeff Layton).

The addition of nfsd_file_get, nfsd_file_put and nfsd_file_file symbols prepares for switching the NFS client to using nfsd_file for localio.

Despite the use of indirect function calls, caching these nfsd symbols for use by the client offers a ~10% performance win (compared to always doing get+call+put) for high IOPS workloads.

---
 fs/nfs/client.c            |   1 -
 fs/nfs/localio.c           |  17 +++---
 fs/nfs_common/nfslocalio.c | 117 +++++++++++++++++++++++++++++++++----
 fs/nfsd/filecache.c        |  25 ++++++++
 fs/nfsd/filecache.h        |   1 +
 fs/nfsd/localio.c          |   2 +-
 include/linux/nfs_fs_sb.h  |   1 -
 include/linux/nfslocalio.h |  27 +++++++--
 8 files changed, 163 insertions(+), 28 deletions(-)
fs/nfs/client.c +0 -1
index 23fe1611cc9f..fe60a82f06d8 100644
@@ -182,7 +182,6 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
 	seqlock_init(&clp->cl_boot_lock);
 	ktime_get_real_ts64(&clp->cl_nfssvc_boot);
 	clp->cl_rpcclient_localio = ERR_PTR(-EINVAL);
-	clp->nfsd_open_local_fh = NULL;
 	clp->cl_nfssvc_net = NULL;
 	clp->cl_nfssvc_dom = NULL;
 #endif /* CONFIG_NFS_LOCALIO */
fs/nfs/localio.c +7 -10
index f5ecbd9fefb6..38303427e0b3 100644
@@ -121,7 +121,7 @@ const struct rpc_program nfslocalio_program = {
  */
 static void nfs_local_enable(struct nfs_client *clp, nfs_uuid_t *nfs_uuid)
 {
-	if (READ_ONCE(clp->nfsd_open_local_fh)) {
+	if (!IS_ERR(clp->cl_rpcclient_localio)) {
 		set_bit(NFS_CS_LOCAL_IO, &clp->cl_flags);
 		clp->cl_nfssvc_net = nfs_uuid->net;
 		clp->cl_nfssvc_dom = nfs_uuid->dom;
@@ -136,8 +136,7 @@ void nfs_local_disable(struct nfs_client *clp)
 {
 	if (test_and_clear_bit(NFS_CS_LOCAL_IO, &clp->cl_flags)) {
 		trace_nfs_local_disable(clp);
-		put_nfsd_open_local_fh();
-		clp->nfsd_open_local_fh = NULL;
+		put_nfs_to_nfsd_symbols();
 		if (!IS_ERR(clp->cl_rpcclient_localio)) {
 			rpc_shutdown_client(clp->cl_rpcclient_localio);
 			clp->cl_rpcclient_localio = ERR_PTR(-EINVAL);
@@ -162,16 +161,14 @@ static void nfs_init_localioclient(struct nfs_client *clp)
 	if (IS_ERR(clp->cl_rpcclient_localio))
 		goto out;
 	/* No errors! Assume that localio is supported */
-	clp->nfsd_open_local_fh = get_nfsd_open_local_fh();
-	if (!clp->nfsd_open_local_fh) {
+	if (!get_nfs_to_nfsd_symbols()) {
 		rpc_shutdown_client(clp->cl_rpcclient_localio);
 		clp->cl_rpcclient_localio = ERR_PTR(-EINVAL);
 	}
 out:
-	dprintk_rcu("%s: server (%s) %s NFS LOCALIO, nfsd_open_local_fh is %s.\n",
+	dprintk_rcu("%s: server (%s) %s NFS LOCALIO.\n",
 		__func__, rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR),
-		(IS_ERR(clp->cl_rpcclient_localio) ? "does not support" : "supports"),
-		(clp->nfsd_open_local_fh ? "set" : "not set"));
+		(IS_ERR(clp->cl_rpcclient_localio) ? "does not support" : "supports"));
 }
 
 static bool nfs_server_uuid_is_local(struct nfs_client *clp, nfs_uuid_t *nfs_uuid)
@@ -245,8 +242,8 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
 	if (mode & ~(FMODE_READ | FMODE_WRITE))
 		return ERR_PTR(-EINVAL);
 
-	status = clp->nfsd_open_local_fh(clp->cl_nfssvc_net, clp->cl_nfssvc_dom,
-					 clp->cl_rpcclient, cred, fh, mode, &filp);
+	status = nfs_to.nfsd_open_local_fh(clp->cl_nfssvc_net, clp->cl_nfssvc_dom,
+					   clp->cl_rpcclient, cred, fh, mode, &filp);
 	if (status < 0) {
 		trace_nfs_local_open_fh(fh, mode, status);
 		switch (status) {
fs/nfs_common/nfslocalio.c +107 -10

134 lines not on this page · raw message

fs/nfsd/filecache.c +25 -0
index 447faa194166..d7c6122231f4 100644
@@ -39,6 +39,7 @@
 #include <linux/fsnotify.h>
 #include <linux/seq_file.h>
 #include <linux/rhashtable.h>
+#include <linux/nfslocalio.h>
 
 #include "vfs.h"
 #include "nfsd.h"
@@ -345,6 +346,10 @@ nfsd_file_get(struct nfsd_file *nf)
 		return nf;
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(nfsd_file_get);
+
+/* Compile time type checking, not used by anything */
+static nfs_to_nfsd_file_get_t __maybe_unused nfsd_file_get_typecheck = nfsd_file_get;
 
 /**
  * nfsd_file_put - put the reference to a nfsd_file
@@ -389,6 +394,26 @@ nfsd_file_put(struct nfsd_file *nf)
 	if (refcount_dec_and_test(&nf->nf_ref))
 		nfsd_file_free(nf);
 }
+EXPORT_SYMBOL_GPL(nfsd_file_put);
+
+/* Compile time type checking, not used by anything */
+static nfs_to_nfsd_file_put_t __maybe_unused nfsd_file_put_typecheck = nfsd_file_put;
+
+/**
+ * nfsd_file_file - get the backing file of an nfsd_file
+ * @nf: nfsd_file of which to access the backing file.
+ *
+ * Return backing file for @nf.
+ */
+struct file *
+nfsd_file_file(struct nfsd_file *nf)
+{
+	return nf->nf_file;
+}
+EXPORT_SYMBOL_GPL(nfsd_file_file);
+
+/* Compile time type checking, not used by anything */
+static nfs_to_nfsd_file_file_t __maybe_unused nfsd_file_file_typecheck = nfsd_file_file;
 
 static void
 nfsd_file_dispose_list(struct list_head *dispose)
fs/nfsd/filecache.h +1 -0
index 6dab41f8541e..ab8a4423edd9 100644
@@ -56,6 +56,7 @@ int nfsd_file_cache_start_net(struct net *net);
 void nfsd_file_cache_shutdown_net(struct net *net);
 void nfsd_file_put(struct nfsd_file *nf);
 struct nfsd_file *nfsd_file_get(struct nfsd_file *nf);
+struct file *nfsd_file_file(struct nfsd_file *nf);
 void nfsd_file_close_inode_sync(struct inode *inode);
 void nfsd_file_net_dispose(struct nfsd_net *nn);
 bool nfsd_file_is_cached(struct inode *inode);
fs/nfsd/localio.c +1 -1
index 9cdea1d1c28a..008b935a3a6c 100644
@@ -111,7 +111,7 @@ int nfsd_open_local_fh(struct net *cl_nfssvc_net,
 EXPORT_SYMBOL_GPL(nfsd_open_local_fh);
 
 /* Compile time type checking, not used by anything */
-static nfs_to_nfsd_open_t __maybe_unused nfsd_open_local_fh_typecheck = nfsd_open_local_fh;
+static nfs_to_nfsd_open_local_fh_t __maybe_unused nfsd_open_local_fh_typecheck = nfsd_open_local_fh;
 
 /*
  * UUID_IS_LOCAL XDR functions
include/linux/nfs_fs_sb.h +0 -1
index 5edc57657985..10453c6f8ca8 100644
@@ -134,7 +134,6 @@ struct nfs_client {
 	struct rpc_clnt *	cl_rpcclient_localio;
 	struct net *	        cl_nfssvc_net;
 	struct auth_domain *	cl_nfssvc_dom;
-	nfs_to_nfsd_open_t	nfsd_open_local_fh;
 #endif /* CONFIG_NFS_LOCALIO */
 };
 
include/linux/nfslocalio.h +22 -5
index c6edcb7c0dcd..6302d36f9112 100644
@@ -7,6 +7,7 @@
 
 #include <linux/list.h>
 #include <linux/uuid.h>
+#include <linux/refcount.h>
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/svcauth.h>
 #include <linux/nfs.h>
@@ -29,11 +30,27 @@ void nfs_uuid_begin(nfs_uuid_t *);
 void nfs_uuid_end(nfs_uuid_t *);
 bool nfs_uuid_is_local(const uuid_t *, struct net *, struct auth_domain *);
 
-typedef int (*nfs_to_nfsd_open_t)(struct net *, struct auth_domain *, struct rpc_clnt *,
-				const struct cred *, const struct nfs_fh *,
-				const fmode_t, struct file **);
+struct nfsd_file;
 
-nfs_to_nfsd_open_t get_nfsd_open_local_fh(void);
-void put_nfsd_open_local_fh(void);
+typedef int (*nfs_to_nfsd_open_local_fh_t)(struct net *, struct auth_domain *,
+				struct rpc_clnt *, const struct cred *,
+				const struct nfs_fh *, const fmode_t,
+				struct file **);
+typedef struct nfsd_file * (*nfs_to_nfsd_file_get_t)(struct nfsd_file *);
+typedef void (*nfs_to_nfsd_file_put_t)(struct nfsd_file *);
+typedef struct file * (*nfs_to_nfsd_file_file_t)(struct nfsd_file *);
+
+typedef struct {
+	refcount_t			ref;
+	nfs_to_nfsd_open_local_fh_t	nfsd_open_local_fh;
+	nfs_to_nfsd_file_get_t		nfsd_file_get;
+	nfs_to_nfsd_file_put_t		nfsd_file_put;
+	nfs_to_nfsd_file_file_t		nfsd_file_file;
+} nfs_to_nfsd_t;
+
+extern nfs_to_nfsd_t nfs_to;
+
+bool get_nfs_to_nfsd_symbols(void);
+void put_nfs_to_nfsd_symbols(void);
 
 #endif  /* __LINUX_NFSLOCALIO_H */
Signature · 1 line
2.44.0
#35 lore raw

PATCH v12 22/24 nfs: push localio nfsd_file_put call out to client

In reply to Mike Snitzer

Change nfsd_open_local_fh() to return an nfsd_file, instead of file, and move associated reference counting to the nfs client's nfs_local_open_fh().

This is the first step in allowing proper use of nfsd_file for localio (such that the benefits of nfsd's filecache can be realized).

---
 fs/nfs/localio.c           |  7 +++++--
 fs/nfs_common/nfslocalio.c |  2 +-
 fs/nfsd/localio.c          | 11 ++++-------
 fs/nfsd/vfs.h              |  2 +-
 include/linux/nfslocalio.h |  2 +-
 5 files changed, 12 insertions(+), 12 deletions(-)
fs/nfs/localio.c +5 -2
index 38303427e0b3..7d63d7e34643 100644
@@ -237,13 +237,14 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
 		  struct nfs_fh *fh, const fmode_t mode)
 {
 	struct file *filp;
+	struct nfsd_file *nf;
 	int status;
 
 	if (mode & ~(FMODE_READ | FMODE_WRITE))
 		return ERR_PTR(-EINVAL);
 
 	status = nfs_to.nfsd_open_local_fh(clp->cl_nfssvc_net, clp->cl_nfssvc_dom,
-					   clp->cl_rpcclient, cred, fh, mode, &filp);
+					   clp->cl_rpcclient, cred, fh, mode, &nf);
 	if (status < 0) {
 		trace_nfs_local_open_fh(fh, mode, status);
 		switch (status) {
@@ -255,8 +256,10 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
 		case -ETIMEDOUT:
 			status = -EAGAIN;
 		}
-		filp = ERR_PTR(status);
+		return ERR_PTR(status);
 	}
+	filp = get_file(nfs_to.nfsd_file_file(nf));
+	nfs_to.nfsd_file_put(nf);
 	return filp;
 }
 EXPORT_SYMBOL_GPL(nfs_local_open_fh);
fs/nfs_common/nfslocalio.c +1 -1
index 087649911b52..f59167e596d3 100644
@@ -98,7 +98,7 @@ static void put_##NFSD_SYMBOL(void)			\
 /* The nfs localio code needs to call into nfsd to map filehandle -> struct nfsd_file */
 extern int nfsd_open_local_fh(struct net *, struct auth_domain *, struct rpc_clnt *,
 			      const struct cred *, const struct nfs_fh *,
-			      const fmode_t, struct file **);
+			      const fmode_t, struct nfsd_file **);
 DEFINE_NFS_TO_NFSD_SYMBOL(nfsd_open_local_fh);
 
 /* The nfs localio code needs to call into nfsd to acquire the nfsd_file */
fs/nfsd/localio.c +4 -7
index 008b935a3a6c..2ceab49f3cb6 100644
@@ -32,13 +32,13 @@
  * @cred: cred that the client established
  * @nfs_fh: filehandle to lookup
  * @fmode: fmode_t to use for open
- * @pfilp: returned file pointer that maps to @nfs_fh
+ * @pnf: returned nfsd_file pointer that maps to @nfs_fh
  *
  * This function maps a local fh to a path on a local filesystem.
  * This is useful when the nfs client has the local server mounted - it can
  * avoid all the NFS overhead with reads, writes and commits.
  *
- * On successful return, caller is responsible for calling path_put. Also
+ * On successful return, caller is responsible for calling nfsd_file_put. Also
  * note that this is called from nfs.ko via find_symbol() to avoid an explicit
  * dependency on knfsd. So, there is no forward declaration in a header file
  * for it that is shared with the client.
@@ -49,7 +49,7 @@ int nfsd_open_local_fh(struct net *cl_nfssvc_net,
 			 const struct cred *cred,
 			 const struct nfs_fh *nfs_fh,
 			 const fmode_t fmode,
-			 struct file **pfilp)
+			 struct nfsd_file **pnf)
 {
 	int mayflags = NFSD_MAY_LOCALIO;
 	int status = 0;
@@ -57,7 +57,6 @@ int nfsd_open_local_fh(struct net *cl_nfssvc_net,
 	const struct cred *save_cred;
 	struct svc_cred rq_cred;
 	struct svc_fh fh;
-	struct nfsd_file *nf;
 	__be32 beres;
 
 	if (nfs_fh->size > NFS4_FHSIZE)
@@ -91,13 +90,11 @@ int nfsd_open_local_fh(struct net *cl_nfssvc_net,
 	rpcauth_map_clnt_to_svc_cred_local(rpc_clnt, cred, &rq_cred);
 
 	beres = nfsd_file_acquire_local(cl_nfssvc_net, &rq_cred, rpc_clnt->cl_vers,
-					cl_nfssvc_dom, &fh, mayflags, &nf);
+					cl_nfssvc_dom, &fh, mayflags, pnf);
 	if (beres) {
 		status = nfs_stat_to_errno(be32_to_cpu(beres));
 		goto out_fh_put;
 	}
-	*pfilp = get_file(nf->nf_file);
-	nfsd_file_put(nf);
 out_fh_put:
 	fh_put(&fh);
 	if (rq_cred.cr_group_info)
fs/nfsd/vfs.h +1 -1
index 9720951c49a0..ec8a8aae540b 100644
@@ -166,7 +166,7 @@ int		nfsd_open_local_fh(struct net *net,
 				   const struct cred *cred,
 				   const struct nfs_fh *nfs_fh,
 				   const fmode_t fmode,
-				   struct file **pfilp);
+				   struct nfsd_file **pnf);
 
 static inline int fh_want_write(struct svc_fh *fh)
 {
include/linux/nfslocalio.h +1 -1
index 6302d36f9112..7e09ff621d93 100644
@@ -35,7 +35,7 @@ struct nfsd_file;
 typedef int (*nfs_to_nfsd_open_local_fh_t)(struct net *, struct auth_domain *,
 				struct rpc_clnt *, const struct cred *,
 				const struct nfs_fh *, const fmode_t,
-				struct file **);
+				struct nfsd_file **);
 typedef struct nfsd_file * (*nfs_to_nfsd_file_get_t)(struct nfsd_file *);
 typedef void (*nfs_to_nfsd_file_put_t)(struct nfsd_file *);
 typedef struct file * (*nfs_to_nfsd_file_file_t)(struct nfsd_file *);
Signature · 1 line
2.44.0
#37 lore raw

PATCH v12 23/24 nfs: switch client to use nfsd_file for localio

In reply to Mike Snitzer

The most interesting changes in this commit are those dealing with the shift to make proper use of nfsd_file so that its lifetime (before nfsd_file_put is called) is extended until after commit, read and write operations.

So rather than immediately call nfsd_file_put() in nfs_local_open_fh(), nfsd_file_put() isn't called until nfs_local_pgio_release() for read/write and not until nfs_local_release_commit_data() for commit.

Aside from that, the bulk of the changes are just various mechanical changes to switch localio code from passing a file pointer to passing an nfsd_file pointer. But the flexfilelayout.c changes also dealt with the unfortunate business of back-filling conditional compilation for the non-LOCALIO case because otherwise the 'nfs_to' symbol would be unavailable (only localio code is dependent on 'nfs_to').

With an fio test that issues 128K directio reads with 24 threads to the same file, for 20 secs, there are noticably fewer nfsd_file allocations and a slight performance improvement:

Before this commit:

read: IOPS=260k, BW=31.7GiB/s (34.0GB/s)(634GiB/20001msec)

  # cat /proc/fs/nfsd/filecache
  total inodes:  0
  hash buckets:  256
  lru entries:   0
  cache hits:    4628466
  acquisitions:  5191234
  allocations:   827632
  releases:      827632
  evictions:     0
  mean age (ms): 0

After this commit:

read: IOPS=311k, BW=38.0GiB/s (40.8GB/s)(760GiB/20001msec)

  # cat /proc/fs/nfsd/filecache
  total inodes:  0
  hash buckets:  256
  lru entries:   0
  cache hits:    6224711
  acquisitions:  6224712
  allocations:   1
  releases:      1
  evictions:     1
  mean age (ms): 23786
  mean age (ms): 23198

It should be noted that while making proper use of nfsd_file and nfsd's filecache offers a clear performance win, it still comes up short compared to simply caching the open file in the client:

read: IOPS=375k, BW=45.7GiB/s (49.1GB/s)(915GiB/20002msec)

  # cat /proc/fs/nfsd/filecache
  total inodes:  0
  hash buckets:  256
  lru entries:   0
  cache hits:    11
  acquisitions:  24
  allocations:   14
  releases:      14
  evictions:     0
  mean age (ms): 0

But caching the open file in the client has object lifetime problems and is avoided because otherwise the client would disallow proper refcounting and release of each nfsd export's backing filesystem.

---
 fs/nfs/flexfilelayout/flexfilelayout.c | 123 ++++++++++++++++---------
 fs/nfs/flexfilelayout/flexfilelayout.h |   4 +-
 fs/nfs/internal.h                      |  31 ++++---
 fs/nfs/localio.c                       |  74 +++++++--------
 fs/nfs/pagelist.c                      |  10 +-
 fs/nfs/write.c                         |  10 +-
 6 files changed, 144 insertions(+), 108 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +78 -45
index 206b4b524e43..d91b640f6c05 100644
@@ -163,7 +163,17 @@ decode_name(struct xdr_stream *xdr, u32 *id)
 	return 0;
 }
 
-static struct file *
+/*
+ * A dummy definition to make RCU (and non-LOCALIO compilation) happy.
+ * struct nfsd_file should never be dereferenced in this file.
+ */
+struct nfsd_file {
+       int undefined__;
+};
+
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+
+static struct nfsd_file *
 ff_local_open_fh(struct pnfs_layout_segment *lseg,
 		 u32 ds_idx,
 		 struct nfs_client *clp,
@@ -172,7 +182,7 @@ ff_local_open_fh(struct pnfs_layout_segment *lseg,
 		 fmode_t mode)
 {
 	struct nfs4_ff_layout_mirror *mirror = FF_LAYOUT_COMP(lseg, ds_idx);
-	struct file *filp, *new, __rcu **pfile;
+	struct nfsd_file *nf, *new, __rcu **pnf;
 
 	if (!nfs_server_is_local(clp))
 		return NULL;
@@ -182,33 +192,43 @@ ff_local_open_fh(struct pnfs_layout_segment *lseg,
 		 * to a rw layout.
 		 */
 		mode |= FMODE_READ;
-		pfile = &mirror->rw_file;
+		pnf = &mirror->rw_file;
 	} else
-		pfile = &mirror->ro_file;
+		pnf = &mirror->ro_file;
 
 	new = NULL;
 	rcu_read_lock();
-	filp = rcu_dereference(*pfile);
-	if (!filp) {
+	nf = rcu_dereference(*pnf);
+	if (!nf) {
 		rcu_read_unlock();
 		new = nfs_local_open_fh(clp, cred, fh, mode);
 		if (IS_ERR(new))
 			return NULL;
 		rcu_read_lock();
 		/* try to swap in the pointer */
-		filp = cmpxchg(pfile, NULL, new);
-		if (!filp) {
-			filp = new;
+		nf = cmpxchg(pnf, NULL, new);
+		if (!nf) {
+			nf = new;
 			new = NULL;
 		}
 	}
-	filp = get_file_rcu(&filp);
+	nf = nfs_to.nfsd_file_get(nf);
 	rcu_read_unlock();
 	if (new)
-		fput(new);
-	return filp;
+		nfs_to.nfsd_file_put(new);
+	return nf;
 }
 
+#else
+static struct nfsd_file *
+ff_local_open_fh(struct pnfs_layout_segment *lseg, u32 ds_idx,
+		 struct nfs_client *clp, const struct cred *cred,
+		 struct nfs_fh *fh, fmode_t mode)
+{
+	return NULL;
+}
+#endif /* IS_ENABLED(CONFIG_NFS_LOCALIO) */
+
 static bool ff_mirror_match_fh(const struct nfs4_ff_layout_mirror *m1,
 		const struct nfs4_ff_layout_mirror *m2)
 {
@@ -284,15 +304,17 @@ static struct nfs4_ff_layout_mirror *ff_layout_alloc_mirror(gfp_t gfp_flags)
 
 static void ff_layout_free_mirror(struct nfs4_ff_layout_mirror *mirror)
 {
-	struct file *filp;
-	const struct cred	*cred;
+	struct nfsd_file * __maybe_unused nf;
+	const struct cred *cred;
 
-	filp = rcu_access_pointer(mirror->ro_file);
-	if (filp)
-		fput(filp);
-	filp = rcu_access_pointer(mirror->rw_file);
-	if (filp)
-		fput(filp);
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	nf = rcu_access_pointer(mirror->ro_file);
+	if (nf)
+		nfs_to.nfsd_file_put(nf);
+	nf = rcu_access_pointer(mirror->rw_file);
+	if (nf)
+		nfs_to.nfsd_file_put(nf);
+#endif
 	ff_layout_remove_mirror(mirror);
 	kfree(mirror->fh_versions);
 	cred = rcu_access_pointer(mirror->ro_cred);
@@ -468,7 +490,6 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
 		struct nfs4_ff_layout_mirror *mirror;
 		struct cred *kcred;
 		const struct cred __rcu *cred;
-		const struct cred __rcu *old;
 		kuid_t uid;
 		kgid_t gid;
 		u32 ds_count, fh_count, id;
@@ -568,27 +589,39 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
 
 		mirror = ff_layout_add_mirror(lh, fls->mirror_array[i]);
 		if (mirror != fls->mirror_array[i]) {
-			struct file *filp;
-
 			/* swap cred ptrs so free_mirror will clean up old */
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
 			if (lgr->range.iomode == IOMODE_READ) {
-				old = xchg(&mirror->ro_cred, cred);
+				const struct cred __rcu *old =
+					xchg(&mirror->ro_cred, cred);
 				rcu_assign_pointer(fls->mirror_array[i]->ro_cred, old);
 				/* drop file if creds changed */
 				if (old != cred) {
-					filp = rcu_dereference_protected(xchg(&mirror->ro_file, NULL), 1);
-					if (filp)
-						fput(filp);
+					struct nfsd_file *nf =
+						rcu_dereference_protected(xchg(&mirror->ro_file, NULL), 1);
+					if (nf)
+						nfs_to.nfsd_file_put(nf);
 				}
 			} else {
-				old = xchg(&mirror->rw_cred, cred);
+				const struct cred __rcu *old =
+					xchg(&mirror->rw_cred, cred);
 				rcu_assign_pointer(fls->mirror_array[i]->rw_cred, old);
 				if (old != cred) {
-					filp = rcu_dereference_protected(xchg(&mirror->rw_file, NULL), 1);
-					if (filp)
-						fput(filp);
+					struct nfsd_file *nf =
+						rcu_dereference_protected(xchg(&mirror->rw_file, NULL), 1);
+					if (nf)
+						nfs_to.nfsd_file_put(nf);
 				}
 			}
+#else
+			if (lgr->range.iomode == IOMODE_READ) {
+				cred = xchg(&mirror->ro_cred, cred);
+				rcu_assign_pointer(fls->mirror_array[i]->ro_cred, cred);
+			} else {
+				cred = xchg(&mirror->rw_cred, cred);
+				rcu_assign_pointer(fls->mirror_array[i]->rw_cred, cred);
+			}
+#endif /* IS_ENABLED(CONFIG_NFS_LOCALIO) */
 			ff_layout_free_mirror(fls->mirror_array[i]);
 			fls->mirror_array[i] = mirror;
 		}
@@ -1824,7 +1857,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
 	struct pnfs_layout_segment *lseg = hdr->lseg;
 	struct nfs4_pnfs_ds *ds;
 	struct rpc_clnt *ds_clnt;
-	struct file *filp;
+	struct nfsd_file *nf;
 	struct nfs4_ff_layout_mirror *mirror;
 	const struct cred *ds_cred;
 	loff_t offset = hdr->args.offset;
@@ -1872,9 +1905,9 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
 	hdr->mds_offset = offset;
 
 	/* Start IO accounting for local read */
-	filp = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
-				FMODE_READ);
-	if (filp) {
+	nf = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
+			      FMODE_READ);
+	if (nf) {
 		hdr->task.tk_start = ktime_get();
 		ff_layout_read_record_layoutstats_start(&hdr->task, hdr);
 	}
@@ -1883,7 +1916,7 @@ ff_layout_read_pagelist(struct nfs_pgio_header *hdr)
 	nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
 			  vers == 3 ? &ff_layout_read_call_ops_v3 :
 				      &ff_layout_read_call_ops_v4,
-			  0, RPC_TASK_SOFTCONN, filp);
+			  0, RPC_TASK_SOFTCONN, nf);
 	put_cred(ds_cred);
 	return PNFS_ATTEMPTED;
 
@@ -1903,7 +1936,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
 	struct pnfs_layout_segment *lseg = hdr->lseg;
 	struct nfs4_pnfs_ds *ds;
 	struct rpc_clnt *ds_clnt;
-	struct file *filp;
+	struct nfsd_file *nf;
 	struct nfs4_ff_layout_mirror *mirror;
 	const struct cred *ds_cred;
 	loff_t offset = hdr->args.offset;
@@ -1949,9 +1982,9 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
 	hdr->args.offset = offset;
 
 	/* Start IO accounting for local write */
-	filp = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
+	nf = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
 				FMODE_READ|FMODE_WRITE);
-	if (filp) {
+	if (nf) {
 		hdr->task.tk_start = ktime_get();
 		ff_layout_write_record_layoutstats_start(&hdr->task, hdr);
 	}
@@ -1960,7 +1993,7 @@ ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
 	nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops,
 			  vers == 3 ? &ff_layout_write_call_ops_v3 :
 				      &ff_layout_write_call_ops_v4,
-			  sync, RPC_TASK_SOFTCONN, filp);
+			  sync, RPC_TASK_SOFTCONN, nf);
 	put_cred(ds_cred);
 	return PNFS_ATTEMPTED;
 
@@ -1994,7 +2027,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
 	struct pnfs_layout_segment *lseg = data->lseg;
 	struct nfs4_pnfs_ds *ds;
 	struct rpc_clnt *ds_clnt;
-	struct file *filp;
+	struct nfsd_file *nf;
 	struct nfs4_ff_layout_mirror *mirror;
 	const struct cred *ds_cred;
 	u32 idx;
@@ -2034,9 +2067,9 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
 		data->args.fh = fh;
 
 	/* Start IO accounting for local commit */
-	filp = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
-				FMODE_READ|FMODE_WRITE);
-	if (filp) {
+	nf = ff_local_open_fh(lseg, idx, ds->ds_clp, ds_cred, fh,
+			      FMODE_READ|FMODE_WRITE);
+	if (nf) {
 		data->task.tk_start = ktime_get();
 		ff_layout_commit_record_layoutstats_start(&data->task, data);
 	}
@@ -2044,7 +2077,7 @@ static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how)
 	ret = nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops,
 				   vers == 3 ? &ff_layout_commit_call_ops_v3 :
 					       &ff_layout_commit_call_ops_v4,
-				   how, RPC_TASK_SOFTCONN, filp);
+				   how, RPC_TASK_SOFTCONN, nf);
 	put_cred(ds_cred);
 	return ret;
 out_err:
fs/nfs/flexfilelayout/flexfilelayout.h +2 -2
index 8e042df5a2c9..562e7e27a8b5 100644
@@ -82,9 +82,9 @@ struct nfs4_ff_layout_mirror {
 	struct nfs_fh			*fh_versions;
 	nfs4_stateid			stateid;
 	const struct cred __rcu		*ro_cred;
-	struct file __rcu		*ro_file;
+	struct nfsd_file __rcu		*ro_file;
 	const struct cred __rcu		*rw_cred;
-	struct file __rcu		*rw_file;
+	struct nfsd_file __rcu		*rw_file;
 	refcount_t			ref;
 	spinlock_t			lock;
 	unsigned long			flags;
fs/nfs/internal.h +17 -14
index 23f0d180fd19..a7677a16e929 100644
@@ -309,7 +309,7 @@ int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
 int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
 		      const struct rpc_call_ops *call_ops, int how, int flags,
-		      struct file *localio);
+		      struct nfsd_file *localio);
 void nfs_free_request(struct nfs_page *req);
 struct nfs_pgio_mirror *
 nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
@@ -455,43 +455,46 @@ extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
 /* localio.c */
 extern void nfs_local_disable(struct nfs_client *);
 extern void nfs_local_probe(struct nfs_client *);
-extern struct file *nfs_local_open_fh(struct nfs_client *, const struct cred *,
-				      struct nfs_fh *, const fmode_t);
-extern struct file *nfs_local_file_open(struct nfs_client *clp,
-					const struct cred *cred,
-					struct nfs_fh *fh,
-					struct nfs_open_context *ctx);
-extern int nfs_local_doio(struct nfs_client *, struct file *,
+extern struct nfsd_file *nfs_local_open_fh(struct nfs_client *,
+					   const struct cred *,
+					   struct nfs_fh *,
+					   const fmode_t);
+extern struct nfsd_file *nfs_local_file_open(struct nfs_client *clp,
+					     const struct cred *cred,
+					     struct nfs_fh *fh,
+					     struct nfs_open_context *ctx);
+extern int nfs_local_doio(struct nfs_client *, struct nfsd_file *,
 			  struct nfs_pgio_header *,
 			  const struct rpc_call_ops *);
-extern int nfs_local_commit(struct file *, struct nfs_commit_data *,
+extern int nfs_local_commit(struct nfsd_file *, struct nfs_commit_data *,
 			    const struct rpc_call_ops *, int);
 extern bool nfs_server_is_local(const struct nfs_client *clp);
 
 #else
 static inline void nfs_local_disable(struct nfs_client *clp) {}
 static inline void nfs_local_probe(struct nfs_client *clp) {}
-static inline struct file *nfs_local_open_fh(struct nfs_client *clp,
+static inline struct nfsd_file *nfs_local_open_fh(struct nfs_client *clp,
 					const struct cred *cred,
 					struct nfs_fh *fh,
 					const fmode_t mode)
 {
 	return ERR_PTR(-EINVAL);
 }
-static inline struct file *nfs_local_file_open(struct nfs_client *clp,
+static inline struct nfsd_file *nfs_local_file_open(struct nfs_client *clp,
 					const struct cred *cred,
 					struct nfs_fh *fh,
 					struct nfs_open_context *ctx)
 {
 	return NULL;
 }
-static inline int nfs_local_doio(struct nfs_client *clp, struct file *filep,
+static inline int nfs_local_doio(struct nfs_client *clp, struct nfsd_file *nf,
 				struct nfs_pgio_header *hdr,
 				const struct rpc_call_ops *call_ops)
 {
 	return -EINVAL;
 }
-static inline int nfs_local_commit(struct file *filep, struct nfs_commit_data *data,
+static inline int nfs_local_commit(struct nfsd_file *nf,
+				struct nfs_commit_data *data,
 				const struct rpc_call_ops *call_ops, int how)
 {
 	return -EINVAL;
@@ -582,7 +585,7 @@ extern int nfs_initiate_commit(struct rpc_clnt *clnt,
 			       const struct nfs_rpc_ops *nfs_ops,
 			       const struct rpc_call_ops *call_ops,
 			       int how, int flags,
-			       struct file *localio);
+			       struct nfsd_file *localio);
 extern void nfs_init_commit(struct nfs_commit_data *data,
 			    struct list_head *head,
 			    struct pnfs_layout_segment *lseg,
fs/nfs/localio.c +37 -37

232 lines not on this page · raw message

fs/nfs/pagelist.c +5 -5
index 1bd0224f7ee8..6f836b66ef79 100644
@@ -732,7 +732,7 @@ static void nfs_pgio_prepare(struct rpc_task *task, void *calldata)
 int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
 		      const struct rpc_call_ops *call_ops, int how, int flags,
-		      struct file *localio)
+		      struct nfsd_file *localio)
 {
 	struct rpc_task *task;
 	struct rpc_message msg = {
@@ -960,9 +960,9 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)
 	if (ret == 0) {
 		struct nfs_client *clp = NFS_SERVER(hdr->inode)->nfs_client;
 
-		struct file *filp = nfs_local_file_open(clp, hdr->cred,
-							hdr->args.fh,
-							hdr->args.context);
+		struct nfsd_file *nf = nfs_local_file_open(clp, hdr->cred,
+							   hdr->args.fh,
+							   hdr->args.context);
 
 		if (NFS_SERVER(hdr->inode)->nfs_client->cl_minorversion)
 			task_flags = RPC_TASK_MOVEABLE;
@@ -973,7 +973,7 @@ static int nfs_generic_pg_pgios(struct nfs_pageio_descriptor *desc)
 					desc->pg_rpc_callops,
 					desc->pg_ioflags,
 					RPC_TASK_CRED_NOREF | task_flags,
-					filp);
+					nf);
 	}
 	return ret;
 }
fs/nfs/write.c +5 -5
index 6436db54b2fc..89a49a08bc90 100644
@@ -1664,7 +1664,7 @@ int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,
 			const struct nfs_rpc_ops *nfs_ops,
 			const struct rpc_call_ops *call_ops,
 			int how, int flags,
-			struct file *localio)
+			struct nfsd_file *localio)
 {
 	struct rpc_task *task;
 	int priority = flush_task_priority(how);
@@ -1795,7 +1795,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
 		struct nfs_commit_info *cinfo)
 {
 	struct nfs_commit_data	*data;
-	struct file *filp;
+	struct nfsd_file *nf;
 	unsigned short task_flags = 0;
 
 	/* another commit raced with us */
@@ -1813,11 +1813,11 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
 	if (NFS_SERVER(inode)->nfs_client->cl_minorversion)
 		task_flags = RPC_TASK_MOVEABLE;
 
-	filp = nfs_local_file_open(NFS_SERVER(inode)->nfs_client, data->cred,
-				   data->args.fh, data->context);
+	nf = nfs_local_file_open(NFS_SERVER(inode)->nfs_client, data->cred,
+				 data->args.fh, data->context);
 	return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),
 				   data->mds_ops, how,
-				   RPC_TASK_CRED_NOREF | task_flags, filp);
+				   RPC_TASK_CRED_NOREF | task_flags, nf);
 }
 
 /*
Signature · 1 line
2.44.0
#38 lore raw

PATCH v12 24/24 nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

In reply to Mike Snitzer

From: Trond Myklebust <[email protected]>

Add a FAQ section to give answers to questions that have been raised during review of the localio feature.

---
 Documentation/filesystems/nfs/localio.rst | 77 +++++++++++++++++++++++
 1 file changed, 77 insertions(+)
Documentation/filesystems/nfs/localio.rst +77 -0
index d8bdab88f1db..acd8f3e5d87a 100644
@@ -40,6 +40,83 @@ fio for 20 secs with 24 libaio threads, 128k directio reads, qd of 8,
 - Without LOCALIO:
   read: IOPS=12.0k, BW=1495MiB/s (1568MB/s)(29.2GiB/20015msec)
 
+FAQ
+===
+
+1. What are the use cases for LOCALIO?
+
+   a. Workloads where the NFS client and server are on the same host
+      realize improved IO performance. In particular, it is common when
+      running containerised workloads for jobs to find themselves
+      running on the same host as the knfsd server being used for
+      storage.
+
+2. What are the requirements for LOCALIO?
+
+   a. Bypass use of the network RPC protocol as much as possible. This
+      includes bypassing XDR and RPC for open, read, write and commit
+      operations.
+   b. Allow client and server to autonomously discover if they are
+      running local to each other without making any assumptions about
+      the local network topology.
+   c. Support the use of containers by being compatible with relevant
+      namespaces (e.g. network, user, mount).
+   d. Support all versions of NFS. NFSv3 is of particular importance
+      because it has wide enterprise usage and pNFS flexfiles makes use
+      of it for the data path.
+
+3. Why doesn’t LOCALIO just compare IP addresses or hostnames when
+   deciding if the NFS client and server are co-located on the same
+   host?
+
+   Since one of the main use cases is containerised workloads, we cannot
+   assume that IP addresses will be shared between the client and
+   server. This sets up a requirement for a handshake protocol that
+   needs to go over the same connection as the NFS traffic in order to
+   identify that the client and the server really are running on the
+   same host. The handshake uses a secret that is sent over the wire,
+   and can be verified by both parties by comparing with a value stored
+   in shared kernel memory if they are truly co-located.
+
+4. Does LOCALIO improve pNFS flexfiles?
+
+   Yes, LOCALIO complements pNFS flexfiles by allowing it to take
+   advantage of NFS client and server locality.  Policy that initiates
+   client IO as closely to the server where the data is stored naturally
+   benefits from the data path optimization LOCALIO provides.
+
+5. Why not develop a new pNFS layout to enable LOCALIO?
+
+   A new pNFS layout could be developed, but doing so would put the
+   onus on the server to somehow discover that the client is co-located
+   when deciding to hand out the layout.
+   There is value in a simpler approach (as provided by LOCALIO) that
+   allows the NFS client to negotiate and leverage locality without
+   requiring more elaborate modeling and discovery of such locality in a
+   more centralized manner.
+
+6. Why is having the client perform a server-side file OPEN, without
+   using RPC, beneficial?  Is the benefit pNFS specific?
+
+   Avoiding the use of XDR and RPC for file opens is beneficial to
+   performance regardless of whether pNFS is used. However adding a
+   requirement to go over the wire to do an open and/or close ends up
+   negating any benefit of avoiding the wire for doing the I/O itself
+   when we’re dealing with small files. There is no benefit to replacing
+   the READ or WRITE with a new open and/or close operation that still
+   needs to go over the wire.
+
+7. Why is LOCALIO only supported with UNIX Authentication (AUTH_UNIX)?
+
+   Strong authentication is usually tied to the connection itself. It
+   works by establishing a context that is cached by the server, and
+   that acts as the key for discovering the authorisation token, which
+   can then be passed to rpc.mountd to complete the authentication
+   process. On the other hand, in the case of AUTH_UNIX, the credential
+   that was passed over the wire is used directly as the key in the
+   upcall to rpc.mountd. This simplifies the authentication process, and
+   so makes AUTH_UNIX easier to support.
+
 RPC
 ===
 
Signature · 1 line
2.44.0
#43 lore raw
In reply to Mike Snitzer
Quoted 9 lines · Mike Snitzer

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).

LOCALIO is enabled, but the tests I run (except for pynfs, which uses a synthetic client) all target a remote NFS server .

There wasn't a convenient way to hack the workflows to run the NFS server locally. So, these tests act as a regression test with LOCALIO enabled and a remote NFS server -- ie, the traditional NFS deployment scenario. I thought this would be OK because Kent's rig is already handling LOCALIO-specific testing.

When I re-enable the ltp NFS suite, that does use a local NFS server. That suite hasn't ever been reliable for me, so I don't use it for now.

--
Chuck Lever

#44 lore raw
Quoted 10 lines · Chuck Lever III
Quoted 9 lines · Mike Snitzer

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).

Quoted 8 lines

LOCALIO is enabled, but the tests I run (except for pynfs, which uses a synthetic client) all target a remote NFS server .

There wasn't a convenient way to hack the workflows to run the NFS server locally. So, these tests act as a regression test with LOCALIO enabled and a remote NFS server -- ie, the traditional NFS deployment scenario. I thought this would be OK because Kent's rig is already handling LOCALIO-specific testing.

Makes sense, thanks for clarifying.

Quoted 3 lines

When I re-enable the ltp NFS suite, that does use a local NFS server. That suite hasn't ever been reliable for me, so I don't use it for now.

OK.

maintainer
#6 lore raw

Re: [PATCH v12 05/24] nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

In reply to Mike Snitzer
Quoted 107 lines · Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL.  Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++-------- fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------

 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +0 -0
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,


  error = nfserr_stale;
  if (IS_ERR(exp)) {

fs/nfsd/nfsfh.c +0 -2
-		if (rqstp)
-			trace_nfsd_set_fh_dentry_badexport(rqstp,

fhp, PTR_ERR(exp));

fs/nfsd/nfsfh.c +1 -0
+		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp,

PTR_ERR(exp));

  if (PTR_ERR(exp) == -ENOENT)
  return error;

fs/nfsd/nfsfh.c +0 -2
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
  						data_left,
 fileid_type, 0,
  						nfsd_acceptable,
 exp);
  		if (IS_ERR_OR_NULL(dentry)) {
-			if (rqstp)
-

trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,

fs/nfsd/nfsfh.c +1 -0
+			trace_nfsd_set_fh_dentry_badhandle(rqstp,

fhp,
  dentry ?  PTR_ERR(dentry) :
-ESTALE);
  switch (PTR_ERR(dentry)) {
  case -ENOMEM:

fs/nfsd/nfsfh.c +0 -0
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	dentry = fhp->fh_dentry;
  	exp = fhp->fh_export;

fs/nfsd/nfsfh.c +1 -2
-	if (rqstp)
-		trace_nfsd_fh_verify(rqstp, fhp, type, access);
+	trace_nfsd_fh_verify(net, rqstp, fhp, type, access);


  /*
  * We still have to do all these permission checks, even when

fs/nfsd/nfsfh.c +0 -0
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	/* Finally, check access permissions. */
  	error = nfsd_permission(cred, exp, dentry, access);

 out:

fs/nfsd/nfsfh.c +0 -2
-	if (rqstp)
-		trace_nfsd_fh_verify_err(rqstp, fhp, type, access,

error);

fs/nfsd/nfsfh.c +1 -0
+	trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access,

error);
  if (error == nfserr_stale)
  nfsd_stats_fh_stale_inc(nn, exp);
  return error;

fs/nfsd/trace.h +0 -0
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,


 TRACE_EVENT(nfsd_fh_verify,
  TP_PROTO(

fs/nfsd/trace.h +1 -0
+		const struct net *net,

  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access
  ),

fs/nfsd/trace.h +1 -1
-	TP_ARGS(rqstp, fhp, type, access),
+	TP_ARGS(net, rqstp, fhp, type, access),

  TP_STRUCT__entry(
  __field(unsigned int, netns_ino) __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)

fs/nfsd/trace.h +0 -0
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
  		__field(unsigned long, access)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +0 -2
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +0 -2
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +3 -2
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

fs/nfsd/trace.h +1 -0
+			__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_remotelen);

fs/nfsd/trace.h

Quoted 1 line
fs/nfsd/trace.h +1 -0
+		}

Does this need an else branch to set these values to something when rqstp is NULL, or are we guaranteed that they are already zeroed out when they aren't assigned?

Quoted 59 lines
fs/nfsd/trace.h +1 -0
+		__entry->xid = rqstp ? be32_to_cpu(rqstp->rq_xid) :

0;
  __entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle); __entry->inode = d_inode(fhp->fh_dentry); __entry->type = type;

fs/nfsd/trace.h +0 -0
@@ -232,13 +235,14 @@ TRACE_EVENT(nfsd_fh_verify,


 TRACE_EVENT_CONDITION(nfsd_fh_verify_err,
  TP_PROTO(

fs/nfsd/trace.h +1 -0
+		const struct net *net,

  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access,
  __be32 error
  ),

fs/nfsd/trace.h +1 -1
-	TP_ARGS(rqstp, fhp, type, access, error),
+	TP_ARGS(net, rqstp, fhp, type, access, error),

  TP_CONDITION(error),
  TP_STRUCT__entry(
  __field(unsigned int, netns_ino)

fs/nfsd/trace.h +0 -0
@@ -252,12 +256,14 @@ TRACE_EVENT_CONDITION(nfsd_fh_verify_err,
  		__field(int, error)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +0 -2
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +0 -2
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +3 -2
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

fs/nfsd/trace.h +1 -0
+			__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_remotelen);

fs/nfsd/trace.h +2 -0
+		}
+		__entry->xid = rqstp ? be32_to_cpu(rqstp->rq_xid) :

0;
  __entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle); if (fhp->fh_dentry)
  __entry->inode = d_inode(fhp->fh_dentry);

fs/nfsd/trace.h +0 -0
@@ -286,7 +292,7 @@ DECLARE_EVENT_CLASS(nfsd_fh_err_class,
  		__field(int, status)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +1 -1
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->xid = rqstp ? be32_to_cpu(rqstp->rq_xid) :

0;
  __entry->fh_hash = knfsd_fh_hash(&fhp->fh_handle); __entry->status = status;
  ),

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

Re: [PATCH v12 09/24] nfs_common: add NFS LOCALIO auxiliary protocol enablement

In reply to Mike Snitzer
Quoted 177 lines · Mike Snitzer

fs/nfs_common/nfslocalio.c provides interfaces that enable an NFS client to generate a nonce (single-use UUID) and associated short-lived nfs_uuid_t struct, register it with nfs_common for subsequent lookup and verification by the NFS server and if matched the NFS server populates members in the nfs_uuid_t struct.

nfs_common's nfs_uuids list is the basis for localio enablement, as such it has members that point to nfsd memory for direct use by the client (e.g. 'net' is the server's network namespace, through it the client can access nn->nfsd_serv with proper rcu read access).

This commit adds all the nfs_client members required to implement the entire localio feature (which depends on the LOCALIO protocol).

---
 fs/nfs/client.c            |  9 ++++
 fs/nfs_common/Makefile     |  3 ++ fs/nfs_common/nfslocalio.c | 97 ++++++++++++++++++++++++++++++++++++++ include/linux/nfs_fs_sb.h  | 10 ++++ include/linux/nfslocalio.h | 37 +++++++++++++++

 5 files changed, 156 insertions(+)

 create mode 100644 fs/nfs_common/nfslocalio.c
 create mode 100644 include/linux/nfslocalio.h

fs/nfs/client.c +0 -0
index 8286edd6062d..1b65a5d7af49 100644
@@ -178,6 +178,15 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
  	clp->cl_max_connect = cl_init->max_connect ? cl_init->max_connect : 1;
  	clp->cl_net = get_net(cl_init->net);

fs/nfs/client.c +9 -0
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	seqlock_init(&clp->cl_boot_lock);
+	ktime_get_real_ts64(&clp->cl_nfssvc_boot);
+	clp->cl_rpcclient_localio = ERR_PTR(-EINVAL);
+	clp->nfsd_open_local_fh = NULL;
+	clp->cl_nfssvc_net = NULL;
+	clp->cl_nfssvc_dom = NULL;
+#endif /* CONFIG_NFS_LOCALIO */
+

  clp->cl_principal = "*";
  clp->cl_xprtsec = cl_init->xprtsec;
  return clp;

fs/nfs_common/Makefile +0 -0
index e58b01bb8dda..a5e54809701e 100644
@@ -6,6 +6,9 @@

 obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o
 nfs_acl-objs := nfsacl.o

fs/nfs_common/Makefile +3 -0
+obj-$(CONFIG_NFS_COMMON_LOCALIO_SUPPORT) += nfs_localio.o
+nfs_localio-objs := nfslocalio.o
+

 obj-$(CONFIG_GRACE_PERIOD) += grace.o
 obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o

fs/nfs_common/nfslocalio.c new file +97 -0
new file mode 100644
index 000000000000..a20ff7607707
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 Mike Snitzer <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/rculist.h>
+#include <linux/nfslocalio.h>
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("NFS localio protocol bypass support");
+
+DEFINE_MUTEX(nfs_uuid_mutex);
+
+/*
+ * Global list of nfs_uuid_t instances, add/remove
+ * is protected by nfs_uuid_mutex.
+ * Reads are protected by RCU read lock (see below).
+ */
+LIST_HEAD(nfs_uuids);
+
+void nfs_uuid_begin(nfs_uuid_t *nfs_uuid)
+{
+	nfs_uuid->net = NULL;
+	nfs_uuid->dom = NULL;
+	uuid_gen(&nfs_uuid->uuid);
+
+	mutex_lock(&nfs_uuid_mutex);
+	list_add_tail_rcu(&nfs_uuid->list, &nfs_uuids);
+	mutex_unlock(&nfs_uuid_mutex);
+}
+EXPORT_SYMBOL_GPL(nfs_uuid_begin);
+
+void nfs_uuid_end(nfs_uuid_t *nfs_uuid)
+{
+	mutex_lock(&nfs_uuid_mutex);
+	list_del_rcu(&nfs_uuid->list);
+	mutex_unlock(&nfs_uuid_mutex);
+}
+EXPORT_SYMBOL_GPL(nfs_uuid_end);
+
+/* Must be called with RCU read lock held. */
+static nfs_uuid_t * nfs_uuid_lookup(const uuid_t *uuid)
+{
+	nfs_uuid_t *nfs_uuid;
+
+	list_for_each_entry_rcu(nfs_uuid, &nfs_uuids, list)
+		if (uuid_equal(&nfs_uuid->uuid, uuid))
+			return nfs_uuid;
+
+	return NULL;
+}
+
+bool nfs_uuid_is_local(const uuid_t *uuid, struct net *net, struct auth_domain *dom)
+{
+	bool is_local = false;
+	nfs_uuid_t *nfs_uuid;
+
+	rcu_read_lock();
+	nfs_uuid = nfs_uuid_lookup(uuid);
+	if (nfs_uuid) {
+		is_local = true;
+		nfs_uuid->net = net;
+		kref_get(&dom->ref);
+		nfs_uuid->dom = dom;
+	}
+	rcu_read_unlock();
+
+	return is_local;
+}
+EXPORT_SYMBOL_GPL(nfs_uuid_is_local);
+
+/*
+ * The nfs localio code needs to call into nfsd to do the filehandle -> struct path
+ * mapping, but cannot be statically linked, because that will make the nfs module
+ * depend on the nfsd module.
+ *
+ * Instead, do dynamic linking to the nfsd module (via nfs_common module). The
+ * nfs_common module will only hold a reference on nfsd when localio is in use.
+ * This allows some sanity checking, like giving up on localio if nfsd isn't loaded.
+ */
+
+extern int nfsd_open_local_fh(struct net *, struct auth_domain *, struct rpc_clnt *,
+			const struct cred *, const struct nfs_fh *,
+			const fmode_t, struct file **);
+
+nfs_to_nfsd_open_t get_nfsd_open_local_fh(void)
+{
+	return symbol_request(nfsd_open_local_fh);
+}
+EXPORT_SYMBOL_GPL(get_nfsd_open_local_fh);
+
+void put_nfsd_open_local_fh(void)
+{
+	symbol_put(nfsd_open_local_fh);
+}
+EXPORT_SYMBOL_GPL(put_nfsd_open_local_fh);
include/linux/nfs_fs_sb.h +1 -0
index 1df86ab98c77..3849cc2832f0 100644
@@ -8,6 +8,7 @@
  #include <linux/wait.h>
  #include <linux/nfs_xdr.h>
  #include <linux/sunrpc/xprt.h>
+#include <linux/nfslocalio.h>


 #include <linux/atomic.h>
 #include <linux/refcount.h>

include/linux/nfs_fs_sb.h +0 -0
@@ -125,6 +126,15 @@ struct nfs_client {
  	struct net		*cl_net;
  	struct list_head	pending_cb_stateids;

include/linux/nfs_fs_sb.h struct nfs_client { · line 137

Quoted 10 lines
include/linux/nfs_fs_sb.h +9 -0
  	struct rcu_head		rcu;
+
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	struct timespec64	cl_nfssvc_boot;
+	seqlock_t		cl_boot_lock;
+	struct rpc_clnt *	cl_rpcclient_localio;
+	struct net *	        cl_nfssvc_net;
+	struct auth_domain *	cl_nfssvc_dom;
+	nfs_to_nfsd_open_t	nfsd_open_local_fh;
+#endif /* CONFIG_NFS_LOCALIO */

nit: a lot of these fields aren't used until later patches (e.g. cl_boot_lock). It would be better if those were added in the patches where they actually get used.

Quoted 46 lines
include/linux/nfs_fs_sb.h +0 -0
  };


 /*

include/linux/nfslocalio.h new file +37 -0
new file mode 100644
index 000000000000..109cb8534e3f
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Mike Snitzer <[email protected]>
+ */
+#ifndef __LINUX_NFSLOCALIO_H
+#define __LINUX_NFSLOCALIO_H
+
+#include <linux/list.h>
+#include <linux/uuid.h>
+#include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/svcauth.h>
+#include <linux/nfs.h>
+#include <net/net_namespace.h>
+
+/*
+ * Useful to allow a client to negotiate if localio
+ * possible with its server.
+ */
+typedef struct {
+	uuid_t uuid;
+	struct list_head list;
+	struct net *net; /* nfsd's network namespace */
+	struct auth_domain *dom; /* auth_domain for localio */
+} nfs_uuid_t;
+
+void nfs_uuid_begin(nfs_uuid_t *);
+void nfs_uuid_end(nfs_uuid_t *);
+bool nfs_uuid_is_local(const uuid_t *, struct net *, struct auth_domain *);
+
+typedef int (*nfs_to_nfsd_open_t)(struct net *, struct auth_domain *, struct rpc_clnt *,
+				const struct cred *, const struct nfs_fh *,
+				const fmode_t, struct file **);
+
+nfs_to_nfsd_open_t get_nfsd_open_local_fh(void);
+void put_nfsd_open_local_fh(void);
+
+#endif  /* __LINUX_NFSLOCALIO_H */
Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#22 lore raw

Re: [PATCH v12 12/24] SUNRPC: replace program list with program array

In reply to Mike Snitzer
Quoted 91 lines · Mike Snitzer

From: NeilBrown <[email protected]>

A service created with svc_create_pooled() can be given a linked list of programs and all of these will be served.

Using a linked list makes it cumbersome when there are several programs that can be optionally selected with CONFIG settings.

After this patch is applied, API consumers must use only svc_create_pooled() when creating an RPC service that listens for more than one RPC program.

---
 fs/nfsd/nfsctl.c           |  2 +-
 fs/nfsd/nfsd.h             |  2 +-
 fs/nfsd/nfssvc.c           | 67 +++++++++++++++++-------------------- include/linux/sunrpc/svc.h |  7 ++--
 net/sunrpc/svc.c           | 68 ++++++++++++++++++++++---------------- net/sunrpc/svc_xprt.c      |  2 +- net/sunrpc/svcauth_unix.c  |  3 +-

 7 files changed, 79 insertions(+), 72 deletions(-)
fs/nfsd/nfsctl.c +1 -1
index 1c9e5b4bcb0a..64c1b4d649bc 100644
@@ -2246,7 +2246,7 @@ static __net_init int nfsd_net_init(struct net *net)
  	if (retval)
  		goto out_repcache_error;
  	memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
-	nn->nfsd_svcstats.program = &nfsd_program;
+	nn->nfsd_svcstats.program = &nfsd_programs[0];
  	for (i = 0; i < sizeof(nn->nfsd_versions); i++)
  		nn->nfsd_versions[i] = nfsd_support_version(i);
  	for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
fs/nfsd/nfsd.h +0 -0
index f87a359d968f..232a873dc53a 100644
@@ -85,7 +85,7 @@ struct nfsd_genl_rqstp {
  	u32			rq_opnum[NFSD_MAX_OPS_PER_COMPOUND];
  };

fs/nfsd/nfsd.h +1 -1
-extern struct svc_program	nfsd_program;
+extern struct svc_program	nfsd_programs[];

 extern const struct svc_version nfsd_version2, nfsd_version3, nfsd_version4;
 extern struct mutex nfsd_mutex;
 extern spinlock_t nfsd_drc_lock;

fs/nfsd/nfssvc.c +0 -0
index 1bec3a53e35f..5f8680ab1013 100644
@@ -35,7 +35,6 @@
  #define NFSDDBG_FACILITY	NFSDDBG_SVC


 atomic_t nfsd_th_cnt = ATOMIC_INIT(0);
-extern struct svc_program nfsd_program;
 static int nfsd(void *vrqstp);
 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
 static int nfsd_acl_rpcbind_set(struct net *,

fs/nfsd/nfssvc.c +0 -0
@@ -87,16 +86,6 @@ static const struct svc_version *localio_versions[] = {


 #define NFSD_LOCALIO_NRVERS ARRAY_SIZE(localio_versions)

fs/nfsd/nfssvc.c +0 -10
-static struct svc_program	nfsd_localio_program = {
-	.pg_prog		= NFS_LOCALIO_PROGRAM,
-	.pg_nvers		= NFSD_LOCALIO_NRVERS,
-	.pg_vers		= localio_versions,
-	.pg_name		= "nfslocalio",
-	.pg_class		= "nfsd",
-	.pg_authenticate	= &svc_set_client,
-	.pg_init_request	= svc_generic_init_request,
-	.pg_rpcbind_set		= svc_generic_rpcbind_set,
-};

 #endif /* CONFIG_NFSD_LOCALIO */

 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)

fs/nfsd/nfssvc.c +0 -0
@@ -109,23 +98,9 @@ static const struct svc_version *nfsd_acl_version[] = {
  # endif
  };

fs/nfsd/nfssvc.c +1 -1
-#define NFSD_ACL_MINVERS            2
+#define NFSD_ACL_MINVERS	2

 #define NFSD_ACL_NRVERS ARRAY_SIZE(nfsd_acl_version)

fs/nfsd/nfssvc.c +0 -4
-static struct svc_program	nfsd_acl_program = {
-#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
-	.pg_next		= &nfsd_localio_program,
-#endif /* CONFIG_NFSD_LOCALIO */

fs/nfsd/nfssvc.c static const struct svc_version *nfsd_acl_version[] = { · line 128

Quoted 10 lines
fs/nfsd/nfssvc.c +0 -10
-	.pg_prog		= NFS_ACL_PROGRAM,
-	.pg_nvers		= NFSD_ACL_NRVERS,
-	.pg_vers		= nfsd_acl_version,
-	.pg_name		= "nfsacl",
-	.pg_class		= "nfsd",
-	.pg_authenticate	= &svc_set_client,
-	.pg_init_request	= nfsd_acl_init_request,
-	.pg_rpcbind_set		= nfsd_acl_rpcbind_set,
-};
-

You just added this code in patch 11.

I think it'd be clearer to reverse the order of patches 11 and 12. That way you don't have this interim version of the localio program that lives on the linked list.

Quoted 309 lines

 #endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */
 static const struct svc_version *nfsd_version[NFSD_MAXVERS+1] = {

fs/nfsd/nfssvc.c +0 -0
@@ -138,22 +113,41 @@ static const struct svc_version *nfsd_version[NFSD_MAXVERS+1] = {
  #endif
  };

fs/nfsd/nfssvc.c +2 -8
-struct svc_program		nfsd_program = {
-#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
-	.pg_next		= &nfsd_acl_program,
-#else
-#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
-	.pg_next		= &nfsd_localio_program,
-#endif /* CONFIG_NFSD_LOCALIO */
-#endif
+struct svc_program		nfsd_programs[] = {
+	{

  .pg_prog = NFS_PROGRAM, /* program number */
  .pg_nvers = NFSD_MAXVERS+1, /* nr of entries in nfsd_version */
  .pg_vers = nfsd_version, /* version table */
  .pg_name = "nfsd", /* program name */
  .pg_class = "nfsd", /* authentication class */

fs/nfsd/nfssvc.c +1 -1
-	.pg_authenticate	= &svc_set_client,	/* export authentication */
+	.pg_authenticate	= svc_set_client,	/* export authentication */

  .pg_init_request = nfsd_init_request,
  .pg_rpcbind_set = nfsd_rpcbind_set,

fs/nfsd/nfssvc.c +25 -0
+	},
+#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
+	{
+	.pg_prog		= NFS_ACL_PROGRAM,
+	.pg_nvers		= NFSD_ACL_NRVERS,
+	.pg_vers		= nfsd_acl_version,
+	.pg_name		= "nfsacl",
+	.pg_class		= "nfsd",
+	.pg_authenticate	= svc_set_client,
+	.pg_init_request	= nfsd_acl_init_request,
+	.pg_rpcbind_set		= nfsd_acl_rpcbind_set,
+	},
+#endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */
+#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
+	{
+	.pg_prog		= NFS_LOCALIO_PROGRAM,
+	.pg_nvers		= NFSD_LOCALIO_NRVERS,
+	.pg_vers		= localio_versions,
+	.pg_name		= "nfslocalio",
+	.pg_class		= "nfsd",
+	.pg_authenticate	= svc_set_client,
+	.pg_init_request	= svc_generic_init_request,
+	.pg_rpcbind_set		= svc_generic_rpcbind_set,
+	}
+#endif /* IS_ENABLED(CONFIG_NFSD_LOCALIO) */

 };

 bool nfsd_support_version(int vers)

fs/nfsd/nfssvc.c +2 -1
@@ -663,7 +657,8 @@ int nfsd_create_serv(struct net *net)
  	if (nfsd_max_blksize == 0)
  		nfsd_max_blksize = nfsd_get_default_max_blksize();
  	nfsd_reset_versions(nn);
-	serv = svc_create_pooled(&nfsd_program, &nn->nfsd_svcstats,
+	serv = svc_create_pooled(nfsd_programs, ARRAY_SIZE(nfsd_programs),
+				 &nn->nfsd_svcstats,
  				 nfsd_max_blksize, nfsd);
  	if (serv == NULL)
  		return -ENOMEM;
include/linux/sunrpc/svc.h +1 -1
index 437672bcaa22..c7ad2fb2a155 100644
@@ -67,9 +67,10 @@ enum {
   * We currently do not support more than one RPC program per daemon.
   */
  struct svc_serv {
-	struct svc_program *	sv_program;	/* RPC program */
+	struct svc_program *	sv_programs;	/* RPC programs */

  struct svc_stat * sv_stats; /* RPC statistics */
  spinlock_t sv_lock;

include/linux/sunrpc/svc.h +1 -0
+	unsigned int		sv_nprogs;	/* Number of sv_programs */

  unsigned int sv_nrthreads; /* # of server threads */
  unsigned int sv_maxconn; /* max connections allowed or
  * '0' causing max to be based

include/linux/sunrpc/svc.h +0 -0
@@ -357,10 +358,9 @@ struct svc_process_info {
  };


 /*
- * List of RPC programs on the same transport endpoint
+ * RPC program - an array of these can use the same transport endpoint */
 struct svc_program {

include/linux/sunrpc/svc.h +0 -1
-	struct svc_program *	pg_next;	/* other programs (same xprt) */

  u32 pg_prog; /* program number */
  unsigned int pg_lovers; /* lowest version */
  unsigned int pg_hivers; /* highest version */

include/linux/sunrpc/svc.h +1 -0
@@ -438,6 +438,7 @@ bool		   svc_rqst_replace_page(struct svc_rqst *rqstp,
  void		   svc_rqst_release_pages(struct svc_rqst *rqstp);
  void		   svc_exit_thread(struct svc_rqst *);
  struct svc_serv *  svc_create_pooled(struct svc_program *prog,
+				     unsigned int nprog,
  				     struct svc_stat *stats,
  				     unsigned int bufsize,
  				     int (*threadfn)(void *data));
net/sunrpc/svc.c +0 -0
index ff6f3e35b36d..b33386d249c2 100644
@@ -440,10 +440,11 @@ EXPORT_SYMBOL_GPL(svc_rpcb_cleanup);


 static int svc_uses_rpcbind(struct svc_serv *serv) {

net/sunrpc/svc.c +4 -2
-	struct svc_program	*progp;
-	unsigned int		i;
+	unsigned int		p, i;
+
+	for (p = 0; p < serv->sv_nprogs; p++) {
+		struct svc_program *progp = &serv->sv_programs[p];

net/sunrpc/svc.c +0 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next) {

  for (i = 0; i < progp->pg_nvers; i++) { if (progp->pg_vers[i] == NULL) continue;

net/sunrpc/svc.c +0 -0
@@ -480,7 +481,7 @@ __svc_init_bc(struct svc_serv *serv)
   * Create an RPC service
   */

 static struct svc_serv *

net/sunrpc/svc.c +1 -1
-__svc_create(struct svc_program *prog, struct svc_stat *stats,
+__svc_create(struct svc_program *prog, int nprogs, struct svc_stat *stats,

       unsigned int bufsize, int npools, int (*threadfn)(void *data)) {
  struct svc_serv *serv;

net/sunrpc/svc.c +14 -12
@@ -491,7 +492,8 @@ __svc_create(struct svc_program *prog, struct svc_stat *stats,
  	if (!(serv = kzalloc(sizeof(*serv), GFP_KERNEL)))
  		return NULL;
  	serv->sv_name      = prog->pg_name;
-	serv->sv_program   = prog;
+	serv->sv_programs  = prog;
+	serv->sv_nprogs    = nprogs;
  	serv->sv_stats     = stats;
  	if (bufsize > RPCSVC_MAXPAYLOAD)
  		bufsize = RPCSVC_MAXPAYLOAD;
@@ -499,17 +501,18 @@ __svc_create(struct svc_program *prog, struct svc_stat *stats,
  	serv->sv_max_mesg  = roundup(serv->sv_max_payload + PAGE_SIZE, PAGE_SIZE);
  	serv->sv_threadfn = threadfn;
  	xdrsize = 0;
-	while (prog) {
-		prog->pg_lovers = prog->pg_nvers-1;
-		for (vers=0; vers<prog->pg_nvers ; vers++)
-			if (prog->pg_vers[vers]) {
-				prog->pg_hivers = vers;
-				if (prog->pg_lovers > vers)
-					prog->pg_lovers = vers;
-				if (prog->pg_vers[vers]->vs_xdrsize > xdrsize)
-					xdrsize = prog->pg_vers[vers]->vs_xdrsize;
+	for (i = 0; i < nprogs; i++) {
+		struct svc_program *progp = &prog[i];
+
+		progp->pg_lovers = progp->pg_nvers-1;
+		for (vers = 0; vers < progp->pg_nvers ; vers++)
+			if (progp->pg_vers[vers]) {
+				progp->pg_hivers = vers;
+				if (progp->pg_lovers > vers)
+					progp->pg_lovers = vers;
+				if (progp->pg_vers[vers]->vs_xdrsize > xdrsize)
+					xdrsize = progp->pg_vers[vers]->vs_xdrsize;
  			}
-		prog = prog->pg_next;
  	}
  	serv->sv_xdrsize   = xdrsize;
  	INIT_LIST_HEAD(&serv->sv_tempsocks);
@@ -558,13 +561,14 @@ __svc_create(struct svc_program *prog, struct svc_stat *stats,
  struct svc_serv *svc_create(struct svc_program *prog, unsigned int bufsize,
  			    int (*threadfn)(void *data))
  {
-	return __svc_create(prog, NULL, bufsize, 1, threadfn);
+	return __svc_create(prog, 1, NULL, bufsize, 1, threadfn);
  }
  EXPORT_SYMBOL_GPL(svc_create);


 /**
  * svc_create_pooled - Create an RPC service with pooled threads
- * @prog: the RPC program the new service will handle
+ * @prog:  Array of RPC programs the new service will handle
+ * @nprogs: Number of programs in the array
  * @stats: the stats struct if desired
  * @bufsize: maximum message size for @prog
  * @threadfn: a function to service RPC requests for @prog

net/sunrpc/svc.c +1 -0
@@ -572,6 +576,7 @@ EXPORT_SYMBOL_GPL(svc_create);
   * Returns an instantiated struct svc_serv object or NULL.
   */
  struct svc_serv *svc_create_pooled(struct svc_program *prog,
+				   unsigned int nprogs,
  				   struct svc_stat *stats,
  				   unsigned int bufsize,
  				   int (*threadfn)(void *data))
@@ -579,7 +584,7 @@ struct svc_serv *svc_create_pooled(struct svc_program *prog,
  	struct svc_serv *serv;
  	unsigned int npools = svc_pool_map_get();

net/sunrpc/svc.c +1 -1
-	serv = __svc_create(prog, stats, bufsize, npools, threadfn);
+	serv = __svc_create(prog, nprogs, stats, bufsize, npools, threadfn);

  if (!serv)
  goto out_err;
  serv->sv_is_pooled = true;

net/sunrpc/svc.c +0 -0
@@ -602,16 +607,16 @@ svc_destroy(struct svc_serv **servp)


  *servp = NULL;

net/sunrpc/svc.c +1 -1
-	dprintk("svc: svc_destroy(%s)\n", serv->sv_program->pg_name);
+	dprintk("svc: svc_destroy(%s)\n", serv->sv_programs->pg_name);

  timer_shutdown_sync(&serv->sv_temptimer);

  /*
  * Remaining transports at this point are not expected. */ WARN_ONCE(!list_empty(&serv->sv_permsocks),

net/sunrpc/svc.c +1 -1
-		  "SVC: permsocks remain for %s\n", serv->sv_program->pg_name);
+		  "SVC: permsocks remain for %s\n", serv->sv_programs->pg_name);

  WARN_ONCE(!list_empty(&serv->sv_tempsocks),

net/sunrpc/svc.c +1 -1
-		  "SVC: tempsocks remain for %s\n", serv->sv_program->pg_name);
+		  "SVC: tempsocks remain for %s\n", serv->sv_programs->pg_name);


  cache_clean_deferred(serv);

net/sunrpc/svc.c +1 -2
@@ -1149,15 +1154,16 @@ int svc_register(const struct svc_serv *serv, struct net *net,
  		 const int family, const unsigned short proto,
  		 const unsigned short port)
  {
-	struct svc_program	*progp;
-	unsigned int		i;
+	unsigned int		p, i;
  	int			error = 0;


  WARN_ON_ONCE(proto == 0 && port == 0);
  if (proto == 0 && port == 0)
  return -EINVAL;

net/sunrpc/svc.c +3 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next) {
+	for (p = 0; p < serv->sv_nprogs; p++) {
+		struct svc_program *progp = &serv->sv_programs[p];
+

  for (i = 0; i < progp->pg_nvers; i++) {

  error = progp->pg_rpcbind_set(net, progp, i,

net/sunrpc/svc.c +1 -2
@@ -1209,13 +1215,14 @@ static void __svc_unregister(struct net *net, const u32 program, const u32 versi
  static void svc_unregister(const struct svc_serv *serv, struct net *net)
  {
  	struct sighand_struct *sighand;
-	struct svc_program *progp;
  	unsigned long flags;
-	unsigned int i;
+	unsigned int p, i;


  clear_thread_flag(TIF_SIGPENDING);

net/sunrpc/svc.c +3 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next) {
+	for (p = 0; p < serv->sv_nprogs; p++) {
+		struct svc_program *progp = &serv->sv_programs[p];
+

  for (i = 0; i < progp->pg_nvers; i++) { if (progp->pg_vers[i] == NULL) continue;

net/sunrpc/svc.c +1 -1
@@ -1321,7 +1328,7 @@ svc_process_common(struct svc_rqst *rqstp)
  	struct svc_process_info process;
  	enum svc_auth_status	auth_res;
  	unsigned int		aoffset;
-	int			rc;
+	int			pr, rc;
  	__be32			*p;


  /* Will be turned off only when NFSv4 Sessions are used */

net/sunrpc/svc.c +0 -0
@@ -1345,9 +1352,12 @@ svc_process_common(struct svc_rqst *rqstp)
  	rqstp->rq_vers = be32_to_cpup(p++);
  	rqstp->rq_proc = be32_to_cpup(p);

net/sunrpc/svc.c +3 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next)
+	for (pr = 0; pr < serv->sv_nprogs; pr++) {
+		progp = &serv->sv_programs[pr];
+

  if (rqstp->rq_prog == progp->pg_prog) break;

net/sunrpc/svc.c +1 -0
+	}


  /*
  * Decode auth data, and add verifier to reply buffer.

net/sunrpc/svc_xprt.c +1 -1
index 53ebc719ff5a..43c57124de52 100644
@@ -268,7 +268,7 @@ static int _svc_xprt_create(struct svc_serv *serv, const char *xprt_name,
  		spin_unlock(&svc_xprt_class_lock);
  		newxprt = xcl->xcl_ops->xpo_create(serv, net, sap, len, flags);
  		if (IS_ERR(newxprt)) {
-			trace_svc_xprt_create_err(serv->sv_program->pg_name,
+			trace_svc_xprt_create_err(serv->sv_programs->pg_name,
  						  xcl->xcl_name, sap, len,
  						  newxprt);
  			module_put(xcl->xcl_owner);
net/sunrpc/svcauth_unix.c +2 -1
index 04b45588ae6f..8ca98b146ec8 100644
@@ -697,7 +697,8 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
  	rqstp->rq_auth_stat = rpc_autherr_badcred;
  	ipm = ip_map_cached_get(xprt);
  	if (ipm == NULL)
-		ipm = __ip_map_lookup(sn->ip_map_cache, rqstp->rq_server->sv_program->pg_class,
+		ipm = __ip_map_lookup(sn->ip_map_cache,
+				      rqstp->rq_server->sv_programs->pg_class,
  				    &sin6->sin6_addr);


  if (ipm == NULL)

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

Re: [PATCH v12 20/24] nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local

In reply to Mike Snitzer
Quoted 34 lines · Mike Snitzer

Offers performance improvements if/when a file is reopened before launderette cleans it from the filecache's LRU.

---
 fs/nfsd/filecache.c | 9 +++++----

 1 file changed, 5 insertions(+), 4 deletions(-)
fs/nfsd/filecache.c +5 -4
index 56be99a3667a..447faa194166 100644
@@ -1197,9 +1197,10 @@ nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
   * a file.  The security implications of this should be carefully
   * considered before use.
   *
- * The nfsd_file_object returned by this API is reference-counted
- * but not garbage-collected. The object is unhashed after the
- * final nfsd_file_put().
+ * The nfsd_file object returned by this API is reference-counted
+ * and garbage-collected. The object is retained for a few
+ * seconds after the final nfsd_file_put() in case the caller
+ * wants to re-use it.
   *
   * Return values:
   *   %nfs_ok - @pnf points to an nfsd_file with its reference
@@ -1214,7 +1215,7 @@ nfsd_file_acquire_local(struct net *net, struct svc_cred *cred,
  			unsigned int may_flags, struct nfsd_file **pnf)
  {
  	return nfsd_file_do_acquire(NULL, net, cred, nfs_vers, client,
-				    fhp, may_flags, NULL, pnf, false);
+				    fhp, may_flags, NULL, pnf, true);
  }
Quoted 2 lines


 /**

I'd just squash this into patch #6.

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

Re: [PATCH v12 09/24] nfs_common: add NFS LOCALIO auxiliary protocol enablement

In reply to Mike Snitzer
Quoted 141 lines · Mike Snitzer

fs/nfs_common/nfslocalio.c provides interfaces that enable an NFS client to generate a nonce (single-use UUID) and associated short-lived nfs_uuid_t struct, register it with nfs_common for subsequent lookup and verification by the NFS server and if matched the NFS server populates members in the nfs_uuid_t struct.

nfs_common's nfs_uuids list is the basis for localio enablement, as such it has members that point to nfsd memory for direct use by the client (e.g. 'net' is the server's network namespace, through it the client can access nn->nfsd_serv with proper rcu read access).

This commit adds all the nfs_client members required to implement the entire localio feature (which depends on the LOCALIO protocol).

---
 fs/nfs/client.c            |  9 ++++
 fs/nfs_common/Makefile     |  3 ++ fs/nfs_common/nfslocalio.c | 97 ++++++++++++++++++++++++++++++++++++++ include/linux/nfs_fs_sb.h  | 10 ++++ include/linux/nfslocalio.h | 37 +++++++++++++++

 5 files changed, 156 insertions(+)

 create mode 100644 fs/nfs_common/nfslocalio.c
 create mode 100644 include/linux/nfslocalio.h

fs/nfs/client.c +0 -0
index 8286edd6062d..1b65a5d7af49 100644
@@ -178,6 +178,15 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
  	clp->cl_max_connect = cl_init->max_connect ? cl_init->max_connect : 1;
  	clp->cl_net = get_net(cl_init->net);

fs/nfs/client.c +9 -0
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	seqlock_init(&clp->cl_boot_lock);
+	ktime_get_real_ts64(&clp->cl_nfssvc_boot);
+	clp->cl_rpcclient_localio = ERR_PTR(-EINVAL);
+	clp->nfsd_open_local_fh = NULL;
+	clp->cl_nfssvc_net = NULL;
+	clp->cl_nfssvc_dom = NULL;
+#endif /* CONFIG_NFS_LOCALIO */
+

  clp->cl_principal = "*";
  clp->cl_xprtsec = cl_init->xprtsec;
  return clp;

fs/nfs_common/Makefile +0 -0
index e58b01bb8dda..a5e54809701e 100644
@@ -6,6 +6,9 @@

 obj-$(CONFIG_NFS_ACL_SUPPORT) += nfs_acl.o
 nfs_acl-objs := nfsacl.o

fs/nfs_common/Makefile +3 -0
+obj-$(CONFIG_NFS_COMMON_LOCALIO_SUPPORT) += nfs_localio.o
+nfs_localio-objs := nfslocalio.o
+

 obj-$(CONFIG_GRACE_PERIOD) += grace.o
 obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o

fs/nfs_common/nfslocalio.c new file +76 -0
new file mode 100644
index 000000000000..a20ff7607707
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 Mike Snitzer <[email protected]>
+ */
+
+#include <linux/module.h>
+#include <linux/rculist.h>
+#include <linux/nfslocalio.h>
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("NFS localio protocol bypass support");
+
+DEFINE_MUTEX(nfs_uuid_mutex);
+
+/*
+ * Global list of nfs_uuid_t instances, add/remove
+ * is protected by nfs_uuid_mutex.
+ * Reads are protected by RCU read lock (see below).
+ */
+LIST_HEAD(nfs_uuids);
+
+void nfs_uuid_begin(nfs_uuid_t *nfs_uuid)
+{
+	nfs_uuid->net = NULL;
+	nfs_uuid->dom = NULL;
+	uuid_gen(&nfs_uuid->uuid);
+
+	mutex_lock(&nfs_uuid_mutex);
+	list_add_tail_rcu(&nfs_uuid->list, &nfs_uuids);
+	mutex_unlock(&nfs_uuid_mutex);
+}
+EXPORT_SYMBOL_GPL(nfs_uuid_begin);
+
+void nfs_uuid_end(nfs_uuid_t *nfs_uuid)
+{
+	mutex_lock(&nfs_uuid_mutex);
+	list_del_rcu(&nfs_uuid->list);
+	mutex_unlock(&nfs_uuid_mutex);
+}
+EXPORT_SYMBOL_GPL(nfs_uuid_end);
+
+/* Must be called with RCU read lock held. */
+static nfs_uuid_t * nfs_uuid_lookup(const uuid_t *uuid)
+{
+	nfs_uuid_t *nfs_uuid;
+
+	list_for_each_entry_rcu(nfs_uuid, &nfs_uuids, list)
+		if (uuid_equal(&nfs_uuid->uuid, uuid))
+			return nfs_uuid;
+
+	return NULL;
+}
+
+bool nfs_uuid_is_local(const uuid_t *uuid, struct net *net, struct auth_domain *dom)
+{
+	bool is_local = false;
+	nfs_uuid_t *nfs_uuid;
+
+	rcu_read_lock();
+	nfs_uuid = nfs_uuid_lookup(uuid);
+	if (nfs_uuid) {
+		is_local = true;
+		nfs_uuid->net = net;
+		kref_get(&dom->ref);
+		nfs_uuid->dom = dom;
+	}
+	rcu_read_unlock();
+
+	return is_local;
+}
+EXPORT_SYMBOL_GPL(nfs_uuid_is_local);
+
+/*
+ * The nfs localio code needs to call into nfsd to do the filehandle -> struct path
+ * mapping, but cannot be statically linked, because that will make the nfs module
+ * depend on the nfsd module.

fs/nfs_common/nfslocalio.c line 86

Quoted 10 lines
fs/nfs_common/nfslocalio.c new file +10 -0
+ *
+ * Instead, do dynamic linking to the nfsd module (via nfs_common module). The
+ * nfs_common module will only hold a reference on nfsd when localio is in use.
+ * This allows some sanity checking, like giving up on localio if nfsd isn't loaded.
+ */
+
+extern int nfsd_open_local_fh(struct net *, struct auth_domain *, struct rpc_clnt *,
+			const struct cred *, const struct nfs_fh *,
+			const fmode_t, struct file **);
+

BTW: this adds the above prototype, but the function itself isn't added until patch #10.

Quoted 82 lines
fs/nfs_common/nfslocalio.c new file +11 -0
+nfs_to_nfsd_open_t get_nfsd_open_local_fh(void)
+{
+	return symbol_request(nfsd_open_local_fh);
+}
+EXPORT_SYMBOL_GPL(get_nfsd_open_local_fh);
+
+void put_nfsd_open_local_fh(void)
+{
+	symbol_put(nfsd_open_local_fh);
+}
+EXPORT_SYMBOL_GPL(put_nfsd_open_local_fh);
include/linux/nfs_fs_sb.h +1 -0
index 1df86ab98c77..3849cc2832f0 100644
@@ -8,6 +8,7 @@
  #include <linux/wait.h>
  #include <linux/nfs_xdr.h>
  #include <linux/sunrpc/xprt.h>
+#include <linux/nfslocalio.h>


 #include <linux/atomic.h>
 #include <linux/refcount.h>

include/linux/nfs_fs_sb.h +9 -0
@@ -125,6 +126,15 @@ struct nfs_client {
  	struct net		*cl_net;
  	struct list_head	pending_cb_stateids;
  	struct rcu_head		rcu;
+
+#if IS_ENABLED(CONFIG_NFS_LOCALIO)
+	struct timespec64	cl_nfssvc_boot;
+	seqlock_t		cl_boot_lock;
+	struct rpc_clnt *	cl_rpcclient_localio;
+	struct net *	        cl_nfssvc_net;
+	struct auth_domain *	cl_nfssvc_dom;
+	nfs_to_nfsd_open_t	nfsd_open_local_fh;
+#endif /* CONFIG_NFS_LOCALIO */
  };


 /*

include/linux/nfslocalio.h new file +37 -0
new file mode 100644
index 000000000000..109cb8534e3f
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2024 Mike Snitzer <[email protected]>
+ */
+#ifndef __LINUX_NFSLOCALIO_H
+#define __LINUX_NFSLOCALIO_H
+
+#include <linux/list.h>
+#include <linux/uuid.h>
+#include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/svcauth.h>
+#include <linux/nfs.h>
+#include <net/net_namespace.h>
+
+/*
+ * Useful to allow a client to negotiate if localio
+ * possible with its server.
+ */
+typedef struct {
+	uuid_t uuid;
+	struct list_head list;
+	struct net *net; /* nfsd's network namespace */
+	struct auth_domain *dom; /* auth_domain for localio */
+} nfs_uuid_t;
+
+void nfs_uuid_begin(nfs_uuid_t *);
+void nfs_uuid_end(nfs_uuid_t *);
+bool nfs_uuid_is_local(const uuid_t *, struct net *, struct auth_domain *);
+
+typedef int (*nfs_to_nfsd_open_t)(struct net *, struct auth_domain *, struct rpc_clnt *,
+				const struct cred *, const struct nfs_fh *,
+				const fmode_t, struct file **);
+
+nfs_to_nfsd_open_t get_nfsd_open_local_fh(void);
+void put_nfsd_open_local_fh(void);
+
+#endif  /* __LINUX_NFSLOCALIO_H */
Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#36 lore raw

Re: [PATCH v12 22/24] nfs: push localio nfsd_file_put call out to client

In reply to Mike Snitzer
Quoted 82 lines · Mike Snitzer

Change nfsd_open_local_fh() to return an nfsd_file, instead of file, and move associated reference counting to the nfs client's nfs_local_open_fh().

This is the first step in allowing proper use of nfsd_file for localio (such that the benefits of nfsd's filecache can be realized).

---
 fs/nfs/localio.c           |  7 +++++--
 fs/nfs_common/nfslocalio.c |  2 +-
 fs/nfsd/localio.c          | 11 ++++-------
 fs/nfsd/vfs.h              |  2 +-
 include/linux/nfslocalio.h |  2 +-

 5 files changed, 12 insertions(+), 12 deletions(-)
fs/nfs/localio.c +1 -0
index 38303427e0b3..7d63d7e34643 100644
@@ -237,13 +237,14 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
  		  struct nfs_fh *fh, const fmode_t mode)
  {
  	struct file *filp;
+	struct nfsd_file *nf;
  	int status;


  if (mode & ~(FMODE_READ | FMODE_WRITE))
  return ERR_PTR(-EINVAL);

  status = nfs_to.nfsd_open_local_fh(clp->cl_nfssvc_net, clp->cl_nfssvc_dom,

fs/nfs/localio.c +1 -1
-					   clp->cl_rpcclient, cred, fh, mode, &filp);
+					   clp->cl_rpcclient, cred, fh, mode, &nf);

  if (status < 0) { trace_nfs_local_open_fh(fh, mode, status); switch (status) {

fs/nfs/localio.c +0 -0
@@ -255,8 +256,10 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,

  case -ETIMEDOUT:
  status = -EAGAIN;
  }

fs/nfs/localio.c +1 -1
-		filp = ERR_PTR(status);
+		return ERR_PTR(status);

  }

fs/nfs/localio.c +2 -0
+	filp = get_file(nfs_to.nfsd_file_file(nf));
+	nfs_to.nfsd_file_put(nf);

  return filp;
 }
 EXPORT_SYMBOL_GPL(nfs_local_open_fh);

fs/nfs_common/nfslocalio.c +1 -1
index 087649911b52..f59167e596d3 100644
@@ -98,7 +98,7 @@ static void put_##NFSD_SYMBOL(void)			\
  /* The nfs localio code needs to call into nfsd to map filehandle -> struct nfsd_file */
  extern int nfsd_open_local_fh(struct net *, struct auth_domain *, struct rpc_clnt *,
  			      const struct cred *, const struct nfs_fh *,
-			      const fmode_t, struct file **);
+			      const fmode_t, struct nfsd_file **);
  DEFINE_NFS_TO_NFSD_SYMBOL(nfsd_open_local_fh);


 /* The nfs localio code needs to call into nfsd to acquire the nfsd_file */

fs/nfsd/localio.c +2 -2
index 008b935a3a6c..2ceab49f3cb6 100644
@@ -32,13 +32,13 @@
   * @cred: cred that the client established
   * @nfs_fh: filehandle to lookup
   * @fmode: fmode_t to use for open
- * @pfilp: returned file pointer that maps to @nfs_fh
+ * @pnf: returned nfsd_file pointer that maps to @nfs_fh
   *
   * This function maps a local fh to a path on a local filesystem.
   * This is useful when the nfs client has the local server mounted - it can
   * avoid all the NFS overhead with reads, writes and commits.
   *
- * On successful return, caller is responsible for calling path_put. Also
+ * On successful return, caller is responsible for calling nfsd_file_put. Also
   * note that this is called from nfs.ko via find_symbol() to avoid an explicit
   * dependency on knfsd. So, there is no forward declaration in a header file
   * for it that is shared with the client.

fs/nfsd/localio.c int nfsd_open_local_fh(struct net *cl_nfssvc_net, · line 52

Quoted 5 lines
fs/nfsd/localio.c +1 -1
@@ -49,7 +49,7 @@ int nfsd_open_local_fh(struct net *cl_nfssvc_net,
  			 const struct cred *cred,
  			 const struct nfs_fh *nfs_fh,
  			 const fmode_t fmode,
-			 struct file **pfilp)
+			 struct nfsd_file **pnf)

I think I'd prefer to see this change made earlier in the series, when nfsd_open_local_fh is first introduced (patch #10), and then just adapt the later patches to deal with the change.

Quoted 21 lines
fs/nfsd/localio.c +0 -1
  {
  	int mayflags = NFSD_MAY_LOCALIO;
  	int status = 0;
@@ -57,7 +57,6 @@ int nfsd_open_local_fh(struct net *cl_nfssvc_net,
  	const struct cred *save_cred;
  	struct svc_cred rq_cred;
  	struct svc_fh fh;
-	struct nfsd_file *nf;
  	__be32 beres;


  if (nfs_fh->size > NFS4_FHSIZE)

fs/nfsd/localio.c +0 -0
@@ -91,13 +90,11 @@ int nfsd_open_local_fh(struct net *cl_nfssvc_net,
  	rpcauth_map_clnt_to_svc_cred_local(rpc_clnt, cred, &rq_cred);


  beres = nfsd_file_acquire_local(cl_nfssvc_net, &rq_cred, rpc_clnt->cl_vers,

fs/nfsd/localio.c +1 -1
-					cl_nfssvc_dom, &fh, mayflags, &nf);
+					cl_nfssvc_dom, &fh, mayflags, pnf);

  if (beres) {
  status = nfs_stat_to_errno(be32_to_cpu(beres)); goto out_fh_put;
  }

fs/nfsd/localio.c int nfsd_open_local_fh(struct net *cl_nfssvc_net, · line 100

Quoted 2 lines
fs/nfsd/localio.c +0 -2
-	*pfilp = get_file(nf->nf_file);
-	nfsd_file_put(nf);

I do like eliminating the unnecessary refcount shuffle here. Much simpler.

Quoted 29 lines

 out_fh_put:
  fh_put(&fh);
  if (rq_cred.cr_group_info)

fs/nfsd/vfs.h +1 -1
index 9720951c49a0..ec8a8aae540b 100644
@@ -166,7 +166,7 @@ int		nfsd_open_local_fh(struct net *net,
  				   const struct cred *cred,
  				   const struct nfs_fh *nfs_fh,
  				   const fmode_t fmode,
-				   struct file **pfilp);
+				   struct nfsd_file **pnf);


 static inline int fh_want_write(struct svc_fh *fh) {

include/linux/nfslocalio.h +1 -1
index 6302d36f9112..7e09ff621d93 100644
@@ -35,7 +35,7 @@ struct nfsd_file;
  typedef int (*nfs_to_nfsd_open_local_fh_t)(struct net *, struct auth_domain *,
  				struct rpc_clnt *, const struct cred *,
  				const struct nfs_fh *, const fmode_t,
-				struct file **);
+				struct nfsd_file **);
  typedef struct nfsd_file * (*nfs_to_nfsd_file_get_t)(struct nfsd_file *);
  typedef void (*nfs_to_nfsd_file_put_t)(struct nfsd_file *);
  typedef struct file * (*nfs_to_nfsd_file_file_t)(struct nfsd_file *);
Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#39 lore raw

Re: [PATCH v12 24/24] nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

In reply to Mike Snitzer
Quoted 97 lines · Mike Snitzer

From: Trond Myklebust <[email protected]>

Add a FAQ section to give answers to questions that have been raised during review of the localio feature.

---
 Documentation/filesystems/nfs/localio.rst | 77 +++++++++++++++++++++++

 1 file changed, 77 insertions(+)
Documentation/filesystems/nfs/localio.rst +0 -0
index d8bdab88f1db..acd8f3e5d87a 100644
@@ -40,6 +40,83 @@ fio for 20 secs with 24 libaio threads, 128k directio reads, qd of 8,

 - Without LOCALIO:
   read: IOPS=12.0k, BW=1495MiB/s (1568MB/s)(29.2GiB/20015msec)

Documentation/filesystems/nfs/localio.rst +77 -0
+FAQ
+===
+
+1. What are the use cases for LOCALIO?
+
+   a. Workloads where the NFS client and server are on the same host
+      realize improved IO performance. In particular, it is common when
+      running containerised workloads for jobs to find themselves
+      running on the same host as the knfsd server being used for
+      storage.
+
+2. What are the requirements for LOCALIO?
+
+   a. Bypass use of the network RPC protocol as much as possible. This
+      includes bypassing XDR and RPC for open, read, write and commit
+      operations.
+   b. Allow client and server to autonomously discover if they are
+      running local to each other without making any assumptions about
+      the local network topology.
+   c. Support the use of containers by being compatible with relevant
+      namespaces (e.g. network, user, mount).
+   d. Support all versions of NFS. NFSv3 is of particular importance
+      because it has wide enterprise usage and pNFS flexfiles makes use
+      of it for the data path.
+
+3. Why doesn’t LOCALIO just compare IP addresses or hostnames when
+   deciding if the NFS client and server are co-located on the same
+   host?
+
+   Since one of the main use cases is containerised workloads, we cannot
+   assume that IP addresses will be shared between the client and
+   server. This sets up a requirement for a handshake protocol that
+   needs to go over the same connection as the NFS traffic in order to
+   identify that the client and the server really are running on the
+   same host. The handshake uses a secret that is sent over the wire,
+   and can be verified by both parties by comparing with a value stored
+   in shared kernel memory if they are truly co-located.
+
+4. Does LOCALIO improve pNFS flexfiles?
+
+   Yes, LOCALIO complements pNFS flexfiles by allowing it to take
+   advantage of NFS client and server locality.  Policy that initiates
+   client IO as closely to the server where the data is stored naturally
+   benefits from the data path optimization LOCALIO provides.
+
+5. Why not develop a new pNFS layout to enable LOCALIO?
+
+   A new pNFS layout could be developed, but doing so would put the
+   onus on the server to somehow discover that the client is co-located
+   when deciding to hand out the layout.
+   There is value in a simpler approach (as provided by LOCALIO) that
+   allows the NFS client to negotiate and leverage locality without
+   requiring more elaborate modeling and discovery of such locality in a
+   more centralized manner.
+
+6. Why is having the client perform a server-side file OPEN, without
+   using RPC, beneficial?  Is the benefit pNFS specific?
+
+   Avoiding the use of XDR and RPC for file opens is beneficial to
+   performance regardless of whether pNFS is used. However adding a
+   requirement to go over the wire to do an open and/or close ends up
+   negating any benefit of avoiding the wire for doing the I/O itself
+   when we’re dealing with small files. There is no benefit to replacing
+   the READ or WRITE with a new open and/or close operation that still
+   needs to go over the wire.
+
+7. Why is LOCALIO only supported with UNIX Authentication (AUTH_UNIX)?
+
+   Strong authentication is usually tied to the connection itself. It
+   works by establishing a context that is cached by the server, and
+   that acts as the key for discovering the authorisation token, which
+   can then be passed to rpc.mountd to complete the authentication
+   process. On the other hand, in the case of AUTH_UNIX, the credential
+   that was passed over the wire is used directly as the key in the
+   upcall to rpc.mountd. This simplifies the authentication process, and
+   so makes AUTH_UNIX easier to support.
+
Quoted 3 lines

 RPC
 ===

I'd just squash this into patch #19.

Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#45 lore raw
In reply to Mike Snitzer
Quoted 165 lines · Mike Snitzer

These latest changes are available in my git tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Significant progress was made on the entire series, I implemented all 3 changes NeilBrown suggested here:
https://marc.info/?l=linux-nfs&m=172004547710968&w=2

And Neil kindly provided review of a preliminary v12 that I then used to refine this final v12 further.  Neil found the series much cleaner and approachable.

This v12 also switches the NFS client's localio code over to driving IO in terms of nfsd's nfsd_file (rather than a simple file pointer). I checked with Jeff Layton and he likes the switch to using nfsd_file (Jeff did suggest I make sure to keep struct nfsd_file completely opaque to the client).  Proper use of nfsd_file provides a solid performance improvement (as detailed in the last patch's commit header) thanks especially to the nfsd filecache's GC feature (which localio now makes use of).

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).
- Verified all of Hammerspace's various sanity tests pass (this includes numerous pNFS and flexfiles tests).

Please review, I'm hopeful I've addressed any outstanding issues and that these changes worthy of being merged for v6.12.  If you see something, say something ;)

Changes since v11:
- The required localio specific changes in fs/nfsd/ are much simpler (thanks to the prelim patches that update common code to support the the localio case, fs/nfsd/localio.c in particular is now very lean)
- Improved the localio protocol to address NeilBrown's issue #1. Replaced GETUUID with UUID_IS_LOCAL RPC, which inverts protocol such that client generates a nonce (shortlived single-use UUID) and proceeds to verify the server sees it in nfs_common.
  - this eliminated the need to add 'struct nfsd_uuid' to nfsd_net
- Finished the RFC series NeilBrown started to introduce nfsd_file_acquire_local(), enables the use of a "fake" svc_rqst to be eliminated: https://marc.info/?l=linux-nfs&m=171980269529965&w=2
  (uses auth_domain as suggested, addresses NeilBrown's issue #2)
- rpcauth_map_clnt_to_svc_cred_local now uses userns of client and from_{kuid,kgid}_munged (hopefully addresses NeilBrown's issue #3)
- Updated nfs_local_call_write() to override_creds() with the cred used by the client to open the localio file.
- To avoid localio hitting writeback deadlock (same as is done for existing loopback NFSD support in nfsd_vfs_write() function): set PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO in nfs_local_call_write() and restore current->flags before return.
- Factored nfs_stat_to_errno and nfs4_stat_to_errno out to nfs_common to eliminate localio code creating yet another copy of them. (eliminates existing duplication between fs/nfs/nfs[23]xdr.c)
- Simplified Kconfig so that NFS_LOCALIO depends on NFS_FS and NFSD_LOCALIO depends on NFSD.
- Only support localio if UNIX Authentication (AUTH_UNIX) is used.
- Improved workqueue patch to not use wait_for_completion().
- Dropped 2 prelim fs/nfs/ patches that weren't actually needed.
- Updated localio.rst to reflect the various changes listed above, also added a new "FAQ" section from Trond (which was informed by an in-person discussion about localio that Trond had with Christoph).
- Fixed "nfsd: add nfsd_file_acquire_local()" commit to work with NFSv3 (had been testing with NFSv4.2 and the fact that NFSv3 regressed due to 'nfs_ver' not being properly initialized for non-LOCALIO callers was missed.
- Fixed issue Neil reported where "When using localio, if I open, read, don't close, then try to stop the server and umount the exported filesystem I get EBUSY for the umount."
  - fix by removing refcount on localio file (no longer cache open localio file in the client).
- Fixed nfsd tracepoints that were impacted by the possibility they'd be passed a NULL rqstp when using localio.
- Rebased on cel/nfsd-next (based on v6.11-rc4) to layer upon Neil's various changes that were originally motivated by LOCALIO, reduces footprint of this patchset.
- Exported nfsd_file interfaces needed to switch the nfs client's localio code over to using it.
- Switched the the nfs client's localio code over to using nfsd_file.

Thanks,
Mike

Mike Snitzer (13):
  nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
  nfs_common: factor out nfs4_errtbl and nfs4_stat_to_errno
  nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h
  nfsd: fix nfsfh tracepoints to properly handle NULL rqstp
  SUNRPC: remove call_allocate() BUG_ONs
  nfs_common: add NFS LOCALIO auxiliary protocol enablement
  nfsd: implement server support for NFS_LOCALIO_PROGRAM
  nfs: implement client support for NFS_LOCALIO_PROGRAM
  nfs: add Documentation/filesystems/nfs/localio.rst
  nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local
  nfs_common: expose localio's required nfsd symbols to nfs client
  nfs: push localio nfsd_file_put call out to client
  nfs: switch client to use nfsd_file for localio

NeilBrown (3):
  nfsd: factor out __fh_verify to allow NULL rqstp to be passed
  nfsd: add nfsd_file_acquire_local()
  SUNRPC: replace program list with program array

Trond Myklebust (4):
  nfs: enable localio for non-pNFS IO
  pnfs/flexfiles: enable localio support
  nfs/localio: use dedicated workqueues for filesystem read and write
  nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

Weston Andros Adamson (4):
  SUNRPC: add rpcauth_map_clnt_to_svc_cred_local
  nfsd: add localio support
  nfs: pass struct file to nfs_init_pgio and nfs_init_commit
  nfs: add localio support

 Documentation/filesystems/nfs/localio.rst | 255 +++++++ fs/Kconfig                                |   3 + fs/nfs/Kconfig                            |  15 + fs/nfs/Makefile                           |   1 + fs/nfs/client.c                           |  15 +- fs/nfs/filelayout/filelayout.c            |   6 +- fs/nfs/flexfilelayout/flexfilelayout.c    | 142 +++- fs/nfs/flexfilelayout/flexfilelayout.h    |   2 + fs/nfs/flexfilelayout/flexfilelayoutdev.c |   6 + fs/nfs/inode.c                            |  57 +- fs/nfs/internal.h                         |  61 +-

 fs/nfs/localio.c                          | 784 ++++++++++++++++++++++
 fs/nfs/nfs2xdr.c                          |  70 +-
 fs/nfs/nfs3xdr.c                          | 108 +--
 fs/nfs/nfs4xdr.c                          |  84 +--
 fs/nfs/nfstrace.h                         |  61 ++
 fs/nfs/pagelist.c                         |  16 +-
 fs/nfs/pnfs_nfs.c                         |   2 +-

 fs/nfs/write.c                            |  12 +- fs/nfs_common/Makefile                    |   5 + fs/nfs_common/common.c                    | 134 ++++ fs/nfs_common/nfslocalio.c                | 194 ++++++ fs/nfsd/Kconfig                           |  15 + fs/nfsd/Makefile                          |   1 + fs/nfsd/export.c                          |   8 +- fs/nfsd/filecache.c                       |  90 ++- fs/nfsd/filecache.h                       |   5 + fs/nfsd/localio.c                         | 183 +++++ fs/nfsd/netns.h                           |   8 +- fs/nfsd/nfsctl.c                          |   2 +- fs/nfsd/nfsd.h                            |   6 +- fs/nfsd/nfsfh.c                           | 114 ++-- fs/nfsd/nfsfh.h                           |   5 + fs/nfsd/nfssvc.c                          | 100 ++- fs/nfsd/trace.h                           |  39 +- fs/nfsd/vfs.h                             |  10 + include/linux/nfs.h                       |   9 + include/linux/nfs_common.h                |  17 + include/linux/nfs_fs_sb.h                 |  10 + include/linux/nfs_xdr.h                   |  20 +- include/linux/nfslocalio.h                |  56 ++ include/linux/sunrpc/auth.h               |   4 + include/linux/sunrpc/svc.h                |   7 +- net/sunrpc/auth.c                         |  22 + net/sunrpc/clnt.c                         |   6 - net/sunrpc/svc.c                          |  68 +- net/sunrpc/svc_xprt.c                     |   2 +- net/sunrpc/svcauth_unix.c                 |   3 +-

Quoted 9 lines
 48 files changed, 2428 insertions(+), 415 deletions(-)

 create mode 100644 Documentation/filesystems/nfs/localio.rst create mode 100644 fs/nfs/localio.c
 create mode 100644 fs/nfs_common/common.c
 create mode 100644 fs/nfs_common/nfslocalio.c create mode 100644 fs/nfsd/localio.c
 create mode 100644 include/linux/nfs_common.h create mode 100644 include/linux/nfslocalio.h

This looks much improved. I didn't see anything that stood out at me as being problematic code-wise with the design or final product, aside from a couple of minor things.

But...this patchset is hard to review. My main gripe is that there is a lot of "churn" -- places where you add code, just to rework it in a new way in a later patch.

For instance, the nfsd_file conversion should be integrated into the new infrastructure much earlier instead of having a patch that later does that conversion. Those kinds extraneous changes make this much harder to review than it would be if this were done in a way that avoided that churn.

Signature · 1 line
Jeff Layton <[email protected]>
#52 lore raw
In reply to Mike Snitzer
Quoted 165 lines · Mike Snitzer

These latest changes are available in my git tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Significant progress was made on the entire series, I implemented all 3 changes NeilBrown suggested here:
https://marc.info/?l=linux-nfs&m=172004547710968&w=2

And Neil kindly provided review of a preliminary v12 that I then used to refine this final v12 further. Neil found the series much cleaner and approachable.

This v12 also switches the NFS client's localio code over to driving IO in terms of nfsd's nfsd_file (rather than a simple file pointer). I checked with Jeff Layton and he likes the switch to using nfsd_file (Jeff did suggest I make sure to keep struct nfsd_file completely opaque to the client). Proper use of nfsd_file provides a solid performance improvement (as detailed in the last patch's commit header) thanks especially to the nfsd filecache's GC feature (which localio now makes use of).

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).
- Verified all of Hammerspace's various sanity tests pass (this includes numerous pNFS and flexfiles tests).

Please review, I'm hopeful I've addressed any outstanding issues and that these changes worthy of being merged for v6.12. If you see something, say something ;)

Changes since v11:
- The required localio specific changes in fs/nfsd/ are much simpler (thanks to the prelim patches that update common code to support the the localio case, fs/nfsd/localio.c in particular is now very lean)
- Improved the localio protocol to address NeilBrown's issue #1. Replaced GETUUID with UUID_IS_LOCAL RPC, which inverts protocol such that client generates a nonce (shortlived single-use UUID) and proceeds to verify the server sees it in nfs_common.
- this eliminated the need to add 'struct nfsd_uuid' to nfsd_net
- Finished the RFC series NeilBrown started to introduce nfsd_file_acquire_local(), enables the use of a "fake" svc_rqst to be eliminated: https://marc.info/?l=linux-nfs&m=171980269529965&w=2
(uses auth_domain as suggested, addresses NeilBrown's issue #2)
- rpcauth_map_clnt_to_svc_cred_local now uses userns of client and from_{kuid,kgid}_munged (hopefully addresses NeilBrown's issue #3)
- Updated nfs_local_call_write() to override_creds() with the cred used by the client to open the localio file.
- To avoid localio hitting writeback deadlock (same as is done for existing loopback NFSD support in nfsd_vfs_write() function): set PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO in nfs_local_call_write() and restore current->flags before return.
- Factored nfs_stat_to_errno and nfs4_stat_to_errno out to nfs_common to eliminate localio code creating yet another copy of them. (eliminates existing duplication between fs/nfs/nfs[23]xdr.c)
- Simplified Kconfig so that NFS_LOCALIO depends on NFS_FS and NFSD_LOCALIO depends on NFSD.
- Only support localio if UNIX Authentication (AUTH_UNIX) is used.
- Improved workqueue patch to not use wait_for_completion().
- Dropped 2 prelim fs/nfs/ patches that weren't actually needed.
- Updated localio.rst to reflect the various changes listed above, also added a new "FAQ" section from Trond (which was informed by an in-person discussion about localio that Trond had with Christoph).
- Fixed "nfsd: add nfsd_file_acquire_local()" commit to work with NFSv3 (had been testing with NFSv4.2 and the fact that NFSv3 regressed due to 'nfs_ver' not being properly initialized for non-LOCALIO callers was missed.
- Fixed issue Neil reported where "When using localio, if I open, read, don't close, then try to stop the server and umount the exported filesystem I get EBUSY for the umount."
- fix by removing refcount on localio file (no longer cache open localio file in the client).
- Fixed nfsd tracepoints that were impacted by the possibility they'd be passed a NULL rqstp when using localio.
- Rebased on cel/nfsd-next (based on v6.11-rc4) to layer upon Neil's various changes that were originally motivated by LOCALIO, reduces footprint of this patchset.
- Exported nfsd_file interfaces needed to switch the nfs client's localio code over to using it.
- Switched the the nfs client's localio code over to using nfsd_file.

Thanks,
Mike

Mike Snitzer (13):
nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
nfs_common: factor out nfs4_errtbl and nfs4_stat_to_errno
nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h
nfsd: fix nfsfh tracepoints to properly handle NULL rqstp
SUNRPC: remove call_allocate() BUG_ONs
nfs_common: add NFS LOCALIO auxiliary protocol enablement
nfsd: implement server support for NFS_LOCALIO_PROGRAM
nfs: implement client support for NFS_LOCALIO_PROGRAM
nfs: add Documentation/filesystems/nfs/localio.rst
nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local
nfs_common: expose localio's required nfsd symbols to nfs client
nfs: push localio nfsd_file_put call out to client
nfs: switch client to use nfsd_file for localio

NeilBrown (3):
nfsd: factor out __fh_verify to allow NULL rqstp to be passed
nfsd: add nfsd_file_acquire_local()
SUNRPC: replace program list with program array

Trond Myklebust (4):
nfs: enable localio for non-pNFS IO
pnfs/flexfiles: enable localio support
nfs/localio: use dedicated workqueues for filesystem read and write
nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

Weston Andros Adamson (4):
SUNRPC: add rpcauth_map_clnt_to_svc_cred_local
nfsd: add localio support
nfs: pass struct file to nfs_init_pgio and nfs_init_commit
nfs: add localio support

 Documentation/filesystems/nfs/localio.rst | 255 +++++++
 fs/Kconfig                                |   3 +
 fs/nfs/Kconfig                            |  15 +
 fs/nfs/Makefile                           |   1 +
 fs/nfs/client.c                           |  15 +-
 fs/nfs/filelayout/filelayout.c            |   6 +-
 fs/nfs/flexfilelayout/flexfilelayout.c    | 142 +++-
 fs/nfs/flexfilelayout/flexfilelayout.h    |   2 +
 fs/nfs/flexfilelayout/flexfilelayoutdev.c |   6 +
 fs/nfs/inode.c                            |  57 +-
 fs/nfs/internal.h                         |  61 +-
 fs/nfs/localio.c                          | 784 ++++++++++++++++++++++
 fs/nfs/nfs2xdr.c                          |  70 +-
 fs/nfs/nfs3xdr.c                          | 108 +--
 fs/nfs/nfs4xdr.c                          |  84 +--
 fs/nfs/nfstrace.h                         |  61 ++
 fs/nfs/pagelist.c                         |  16 +-
 fs/nfs/pnfs_nfs.c                         |   2 +-
 fs/nfs/write.c                            |  12 +-
 fs/nfs_common/Makefile                    |   5 +
 fs/nfs_common/common.c                    | 134 ++++
 fs/nfs_common/nfslocalio.c                | 194 ++++++
 fs/nfsd/Kconfig                           |  15 +
 fs/nfsd/Makefile                          |   1 +
 fs/nfsd/export.c                          |   8 +-
 fs/nfsd/filecache.c                       |  90 ++-
 fs/nfsd/filecache.h                       |   5 +
 fs/nfsd/localio.c                         | 183 +++++
 fs/nfsd/netns.h                           |   8 +-
 fs/nfsd/nfsctl.c                          |   2 +-
 fs/nfsd/nfsd.h                            |   6 +-
 fs/nfsd/nfsfh.c                           | 114 ++--
 fs/nfsd/nfsfh.h                           |   5 +
 fs/nfsd/nfssvc.c                          | 100 ++-
 fs/nfsd/trace.h                           |  39 +-
 fs/nfsd/vfs.h                             |  10 +
 include/linux/nfs.h                       |   9 +
 include/linux/nfs_common.h                |  17 +
 include/linux/nfs_fs_sb.h                 |  10 +
 include/linux/nfs_xdr.h                   |  20 +-
 include/linux/nfslocalio.h                |  56 ++
 include/linux/sunrpc/auth.h               |   4 +
 include/linux/sunrpc/svc.h                |   7 +-
 net/sunrpc/auth.c                         |  22 +
 net/sunrpc/clnt.c                         |   6 -
 net/sunrpc/svc.c                          |  68 +-
 net/sunrpc/svc_xprt.c                     |   2 +-
 net/sunrpc/svcauth_unix.c                 |   3 +-
Quoted 13 lines
 48 files changed, 2428 insertions(+), 415 deletions(-)
 create mode 100644 Documentation/filesystems/nfs/localio.rst
 create mode 100644 fs/nfs/localio.c
 create mode 100644 fs/nfs_common/common.c
 create mode 100644 fs/nfs_common/nfslocalio.c
 create mode 100644 fs/nfsd/localio.c
 create mode 100644 include/linux/nfs_common.h
 create mode 100644 include/linux/nfslocalio.h
Signature · 1 line
2.44.0

Hi Mike-

I've started familiarizing myself with v12. I'm happy to see that the fake svc_rqst code is gone, and I thank you, Neil, and Trond for your effort replacing that code.

I think I understand why we have to use an ephemeral garbage- collected nfsd_file rather than having the client hold one open while it has an open file descriptor for that file.

Next I want to start auditing the client's open path for security issues. I will hold any specific comments until I've done that.

It's great that Jeff has reviewed these already! I concur that a little patch re-organization will be helpful.

Signature · 1 line
Chuck Lever
#46 lore raw
In reply to Jeff Layton
Quoted 184 lines · Jeff Layton
Quoted 165 lines · Mike Snitzer

These latest changes are available in my git tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Significant progress was made on the entire series, I implemented all 3 changes NeilBrown suggested here:
https://marc.info/?l=linux-nfs&m=172004547710968&w=2

And Neil kindly provided review of a preliminary v12 that I then used to refine this final v12 further.  Neil found the series much cleaner and approachable.

This v12 also switches the NFS client's localio code over to driving IO in terms of nfsd's nfsd_file (rather than a simple file pointer). I checked with Jeff Layton and he likes the switch to using nfsd_file (Jeff did suggest I make sure to keep struct nfsd_file completely opaque to the client).  Proper use of nfsd_file provides a solid performance improvement (as detailed in the last patch's commit header) thanks especially to the nfsd filecache's GC feature (which localio now makes use of).

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).
- Verified all of Hammerspace's various sanity tests pass (this includes numerous pNFS and flexfiles tests).

Please review, I'm hopeful I've addressed any outstanding issues and that these changes worthy of being merged for v6.12.  If you see something, say something ;)

Changes since v11:
- The required localio specific changes in fs/nfsd/ are much simpler (thanks to the prelim patches that update common code to support the the localio case, fs/nfsd/localio.c in particular is now very lean)
- Improved the localio protocol to address NeilBrown's issue #1. Replaced GETUUID with UUID_IS_LOCAL RPC, which inverts protocol such that client generates a nonce (shortlived single-use UUID) and proceeds to verify the server sees it in nfs_common.
  - this eliminated the need to add 'struct nfsd_uuid' to nfsd_net
- Finished the RFC series NeilBrown started to introduce nfsd_file_acquire_local(), enables the use of a "fake" svc_rqst to be eliminated: https://marc.info/?l=linux-nfs&m=171980269529965&w=2
  (uses auth_domain as suggested, addresses NeilBrown's issue #2)
- rpcauth_map_clnt_to_svc_cred_local now uses userns of client and from_{kuid,kgid}_munged (hopefully addresses NeilBrown's issue #3)
- Updated nfs_local_call_write() to override_creds() with the cred used by the client to open the localio file.
- To avoid localio hitting writeback deadlock (same as is done for existing loopback NFSD support in nfsd_vfs_write() function): set PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO in nfs_local_call_write() and restore current->flags before return.
- Factored nfs_stat_to_errno and nfs4_stat_to_errno out to nfs_common to eliminate localio code creating yet another copy of them. (eliminates existing duplication between fs/nfs/nfs[23]xdr.c)
- Simplified Kconfig so that NFS_LOCALIO depends on NFS_FS and NFSD_LOCALIO depends on NFSD.
- Only support localio if UNIX Authentication (AUTH_UNIX) is used.
- Improved workqueue patch to not use wait_for_completion().
- Dropped 2 prelim fs/nfs/ patches that weren't actually needed.
- Updated localio.rst to reflect the various changes listed above, also added a new "FAQ" section from Trond (which was informed by an in-person discussion about localio that Trond had with Christoph).
- Fixed "nfsd: add nfsd_file_acquire_local()" commit to work with NFSv3 (had been testing with NFSv4.2 and the fact that NFSv3 regressed due to 'nfs_ver' not being properly initialized for non-LOCALIO callers was missed.
- Fixed issue Neil reported where "When using localio, if I open, read, don't close, then try to stop the server and umount the exported filesystem I get EBUSY for the umount."
  - fix by removing refcount on localio file (no longer cache open localio file in the client).
- Fixed nfsd tracepoints that were impacted by the possibility they'd be passed a NULL rqstp when using localio.
- Rebased on cel/nfsd-next (based on v6.11-rc4) to layer upon Neil's various changes that were originally motivated by LOCALIO, reduces footprint of this patchset.
- Exported nfsd_file interfaces needed to switch the nfs client's localio code over to using it.
- Switched the the nfs client's localio code over to using nfsd_file.

Thanks,
Mike

Mike Snitzer (13):
  nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
  nfs_common: factor out nfs4_errtbl and nfs4_stat_to_errno
  nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h
  nfsd: fix nfsfh tracepoints to properly handle NULL rqstp
  SUNRPC: remove call_allocate() BUG_ONs
  nfs_common: add NFS LOCALIO auxiliary protocol enablement
  nfsd: implement server support for NFS_LOCALIO_PROGRAM
  nfs: implement client support for NFS_LOCALIO_PROGRAM
  nfs: add Documentation/filesystems/nfs/localio.rst
  nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local
  nfs_common: expose localio's required nfsd symbols to nfs client
  nfs: push localio nfsd_file_put call out to client
  nfs: switch client to use nfsd_file for localio

NeilBrown (3):
  nfsd: factor out __fh_verify to allow NULL rqstp to be passed
  nfsd: add nfsd_file_acquire_local()
  SUNRPC: replace program list with program array

Trond Myklebust (4):
  nfs: enable localio for non-pNFS IO
  pnfs/flexfiles: enable localio support
  nfs/localio: use dedicated workqueues for filesystem read and write
  nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

Weston Andros Adamson (4):
  SUNRPC: add rpcauth_map_clnt_to_svc_cred_local
  nfsd: add localio support
  nfs: pass struct file to nfs_init_pgio and nfs_init_commit
  nfs: add localio support

 Documentation/filesystems/nfs/localio.rst | 255 +++++++ fs/Kconfig                                |   3 + fs/nfs/Kconfig                            |  15 + fs/nfs/Makefile                           |   1 + fs/nfs/client.c                           |  15 +- fs/nfs/filelayout/filelayout.c            |   6 +- fs/nfs/flexfilelayout/flexfilelayout.c    | 142 +++- fs/nfs/flexfilelayout/flexfilelayout.h    |   2 + fs/nfs/flexfilelayout/flexfilelayoutdev.c |   6 + fs/nfs/inode.c                            |  57 +- fs/nfs/internal.h                         |  61 +-

 fs/nfs/localio.c                          | 784 ++++++++++++++++++++++
 fs/nfs/nfs2xdr.c                          |  70 +-
 fs/nfs/nfs3xdr.c                          | 108 +--
 fs/nfs/nfs4xdr.c                          |  84 +--
 fs/nfs/nfstrace.h                         |  61 ++
 fs/nfs/pagelist.c                         |  16 +-
 fs/nfs/pnfs_nfs.c                         |   2 +-

 fs/nfs/write.c                            |  12 +- fs/nfs_common/Makefile                    |   5 + fs/nfs_common/common.c                    | 134 ++++ fs/nfs_common/nfslocalio.c                | 194 ++++++ fs/nfsd/Kconfig                           |  15 + fs/nfsd/Makefile                          |   1 + fs/nfsd/export.c                          |   8 +- fs/nfsd/filecache.c                       |  90 ++- fs/nfsd/filecache.h                       |   5 + fs/nfsd/localio.c                         | 183 +++++ fs/nfsd/netns.h                           |   8 +- fs/nfsd/nfsctl.c                          |   2 +- fs/nfsd/nfsd.h                            |   6 +- fs/nfsd/nfsfh.c                           | 114 ++-- fs/nfsd/nfsfh.h                           |   5 + fs/nfsd/nfssvc.c                          | 100 ++- fs/nfsd/trace.h                           |  39 +- fs/nfsd/vfs.h                             |  10 + include/linux/nfs.h                       |   9 + include/linux/nfs_common.h                |  17 + include/linux/nfs_fs_sb.h                 |  10 + include/linux/nfs_xdr.h                   |  20 +- include/linux/nfslocalio.h                |  56 ++ include/linux/sunrpc/auth.h               |   4 + include/linux/sunrpc/svc.h                |   7 +- net/sunrpc/auth.c                         |  22 + net/sunrpc/clnt.c                         |   6 - net/sunrpc/svc.c                          |  68 +- net/sunrpc/svc_xprt.c                     |   2 +- net/sunrpc/svcauth_unix.c                 |   3 +-

Quoted 9 lines
 48 files changed, 2428 insertions(+), 415 deletions(-)

 create mode 100644 Documentation/filesystems/nfs/localio.rst create mode 100644 fs/nfs/localio.c
 create mode 100644 fs/nfs_common/common.c
 create mode 100644 fs/nfs_common/nfslocalio.c create mode 100644 fs/nfsd/localio.c
 create mode 100644 include/linux/nfs_common.h create mode 100644 include/linux/nfslocalio.h

This looks much improved. I didn't see anything that stood out at me as being problematic code-wise with the design or final product, aside from a couple of minor things.

But...this patchset is hard to review. My main gripe is that there is a lot of "churn" -- places where you add code, just to rework it in a new way in a later patch.

Quoted 5 lines

For instance, the nfsd_file conversion should be integrated into the new infrastructure much earlier instead of having a patch that later does that conversion. Those kinds extraneous changes make this much harder to review than it would be if this were done in a way that avoided that churn.

I thought about folding the nfsd_file changes in from the beginning but stopped short of doing so because the churn you speak of really only smacks you in the face when reviewing the fs/nfs/flexfilelayout/flexfilelayout.c changes (which happen to be featured prominently at the top of patch 23).

Otherwise, there really is very little change/churn from the nfsd_file switchover. And the general statement that the series hard to review over needless churn seems strong. Only place is with nfsd_file.

Anyway, I can rebase to fold the nfsd_file changes in (so that its done that way from the start) if you and others want it done that way. Please just have one last think about it and let me know.

Thanks,
Mike

#53 lore raw
In reply to Chuck Lever
Quoted 186 lines · Chuck Lever
Quoted 165 lines · Mike Snitzer

These latest changes are available in my git tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Significant progress was made on the entire series, I implemented all 3 changes NeilBrown suggested here:
https://marc.info/?l=linux-nfs&m=172004547710968&w=2

And Neil kindly provided review of a preliminary v12 that I then used to refine this final v12 further. Neil found the series much cleaner and approachable.

This v12 also switches the NFS client's localio code over to driving IO in terms of nfsd's nfsd_file (rather than a simple file pointer). I checked with Jeff Layton and he likes the switch to using nfsd_file (Jeff did suggest I make sure to keep struct nfsd_file completely opaque to the client). Proper use of nfsd_file provides a solid performance improvement (as detailed in the last patch's commit header) thanks especially to the nfsd filecache's GC feature (which localio now makes use of).

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).
- Verified all of Hammerspace's various sanity tests pass (this includes numerous pNFS and flexfiles tests).

Please review, I'm hopeful I've addressed any outstanding issues and that these changes worthy of being merged for v6.12. If you see something, say something ;)

Changes since v11:
- The required localio specific changes in fs/nfsd/ are much simpler (thanks to the prelim patches that update common code to support the the localio case, fs/nfsd/localio.c in particular is now very lean)
- Improved the localio protocol to address NeilBrown's issue #1. Replaced GETUUID with UUID_IS_LOCAL RPC, which inverts protocol such that client generates a nonce (shortlived single-use UUID) and proceeds to verify the server sees it in nfs_common.
- this eliminated the need to add 'struct nfsd_uuid' to nfsd_net
- Finished the RFC series NeilBrown started to introduce nfsd_file_acquire_local(), enables the use of a "fake" svc_rqst to be eliminated: https://marc.info/?l=linux-nfs&m=171980269529965&w=2
(uses auth_domain as suggested, addresses NeilBrown's issue #2)
- rpcauth_map_clnt_to_svc_cred_local now uses userns of client and from_{kuid,kgid}_munged (hopefully addresses NeilBrown's issue #3)
- Updated nfs_local_call_write() to override_creds() with the cred used by the client to open the localio file.
- To avoid localio hitting writeback deadlock (same as is done for existing loopback NFSD support in nfsd_vfs_write() function): set PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO in nfs_local_call_write() and restore current->flags before return.
- Factored nfs_stat_to_errno and nfs4_stat_to_errno out to nfs_common to eliminate localio code creating yet another copy of them. (eliminates existing duplication between fs/nfs/nfs[23]xdr.c)
- Simplified Kconfig so that NFS_LOCALIO depends on NFS_FS and NFSD_LOCALIO depends on NFSD.
- Only support localio if UNIX Authentication (AUTH_UNIX) is used.
- Improved workqueue patch to not use wait_for_completion().
- Dropped 2 prelim fs/nfs/ patches that weren't actually needed.
- Updated localio.rst to reflect the various changes listed above, also added a new "FAQ" section from Trond (which was informed by an in-person discussion about localio that Trond had with Christoph).
- Fixed "nfsd: add nfsd_file_acquire_local()" commit to work with NFSv3 (had been testing with NFSv4.2 and the fact that NFSv3 regressed due to 'nfs_ver' not being properly initialized for non-LOCALIO callers was missed.
- Fixed issue Neil reported where "When using localio, if I open, read, don't close, then try to stop the server and umount the exported filesystem I get EBUSY for the umount."
- fix by removing refcount on localio file (no longer cache open localio file in the client).
- Fixed nfsd tracepoints that were impacted by the possibility they'd be passed a NULL rqstp when using localio.
- Rebased on cel/nfsd-next (based on v6.11-rc4) to layer upon Neil's various changes that were originally motivated by LOCALIO, reduces footprint of this patchset.
- Exported nfsd_file interfaces needed to switch the nfs client's localio code over to using it.
- Switched the the nfs client's localio code over to using nfsd_file.

Thanks,
Mike

Mike Snitzer (13):
nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
nfs_common: factor out nfs4_errtbl and nfs4_stat_to_errno
nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h
nfsd: fix nfsfh tracepoints to properly handle NULL rqstp
SUNRPC: remove call_allocate() BUG_ONs
nfs_common: add NFS LOCALIO auxiliary protocol enablement
nfsd: implement server support for NFS_LOCALIO_PROGRAM
nfs: implement client support for NFS_LOCALIO_PROGRAM
nfs: add Documentation/filesystems/nfs/localio.rst
nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local
nfs_common: expose localio's required nfsd symbols to nfs client
nfs: push localio nfsd_file_put call out to client
nfs: switch client to use nfsd_file for localio

NeilBrown (3):
nfsd: factor out __fh_verify to allow NULL rqstp to be passed
nfsd: add nfsd_file_acquire_local()
SUNRPC: replace program list with program array

Trond Myklebust (4):
nfs: enable localio for non-pNFS IO
pnfs/flexfiles: enable localio support
nfs/localio: use dedicated workqueues for filesystem read and write
nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

Weston Andros Adamson (4):
SUNRPC: add rpcauth_map_clnt_to_svc_cred_local
nfsd: add localio support
nfs: pass struct file to nfs_init_pgio and nfs_init_commit
nfs: add localio support

 Documentation/filesystems/nfs/localio.rst | 255 +++++++
 fs/Kconfig                                |   3 +
 fs/nfs/Kconfig                            |  15 +
 fs/nfs/Makefile                           |   1 +
 fs/nfs/client.c                           |  15 +-
 fs/nfs/filelayout/filelayout.c            |   6 +-
 fs/nfs/flexfilelayout/flexfilelayout.c    | 142 +++-
 fs/nfs/flexfilelayout/flexfilelayout.h    |   2 +
 fs/nfs/flexfilelayout/flexfilelayoutdev.c |   6 +
 fs/nfs/inode.c                            |  57 +-
 fs/nfs/internal.h                         |  61 +-
 fs/nfs/localio.c                          | 784 ++++++++++++++++++++++
 fs/nfs/nfs2xdr.c                          |  70 +-
 fs/nfs/nfs3xdr.c                          | 108 +--
 fs/nfs/nfs4xdr.c                          |  84 +--
 fs/nfs/nfstrace.h                         |  61 ++
 fs/nfs/pagelist.c                         |  16 +-
 fs/nfs/pnfs_nfs.c                         |   2 +-
 fs/nfs/write.c                            |  12 +-
 fs/nfs_common/Makefile                    |   5 +
 fs/nfs_common/common.c                    | 134 ++++
 fs/nfs_common/nfslocalio.c                | 194 ++++++
 fs/nfsd/Kconfig                           |  15 +
 fs/nfsd/Makefile                          |   1 +
 fs/nfsd/export.c                          |   8 +-
 fs/nfsd/filecache.c                       |  90 ++-
 fs/nfsd/filecache.h                       |   5 +
 fs/nfsd/localio.c                         | 183 +++++
 fs/nfsd/netns.h                           |   8 +-
 fs/nfsd/nfsctl.c                          |   2 +-
 fs/nfsd/nfsd.h                            |   6 +-
 fs/nfsd/nfsfh.c                           | 114 ++--
 fs/nfsd/nfsfh.h                           |   5 +
 fs/nfsd/nfssvc.c                          | 100 ++-
 fs/nfsd/trace.h                           |  39 +-
 fs/nfsd/vfs.h                             |  10 +
 include/linux/nfs.h                       |   9 +
 include/linux/nfs_common.h                |  17 +
 include/linux/nfs_fs_sb.h                 |  10 +
 include/linux/nfs_xdr.h                   |  20 +-
 include/linux/nfslocalio.h                |  56 ++
 include/linux/sunrpc/auth.h               |   4 +
 include/linux/sunrpc/svc.h                |   7 +-
 net/sunrpc/auth.c                         |  22 +
 net/sunrpc/clnt.c                         |   6 -
 net/sunrpc/svc.c                          |  68 +-
 net/sunrpc/svc_xprt.c                     |   2 +-
 net/sunrpc/svcauth_unix.c                 |   3 +-
Quoted 13 lines
 48 files changed, 2428 insertions(+), 415 deletions(-)
 create mode 100644 Documentation/filesystems/nfs/localio.rst
 create mode 100644 fs/nfs/localio.c
 create mode 100644 fs/nfs_common/common.c
 create mode 100644 fs/nfs_common/nfslocalio.c
 create mode 100644 fs/nfsd/localio.c
 create mode 100644 include/linux/nfs_common.h
 create mode 100644 include/linux/nfslocalio.h
Signature · 1 line
2.44.0

Hi Mike-

I've started familiarizing myself with v12. I'm happy to see that the fake svc_rqst code is gone, and I thank you, Neil, and Trond for your effort replacing that code.

Quoted 6 lines

I think I understand why we have to use an ephemeral garbage- collected nfsd_file rather than having the client hold one open while it has an open file descriptor for that file.

Next I want to start auditing the client's open path for security issues. I will hold any specific comments until I've done that.

Sounds good, thanks.

Quoted 2 lines

It's great that Jeff has reviewed these already! I concur that a little patch re-organization will be helpful.

Sure, I just replied to Jeff. I can do the work to rebase the use of nfsd_file so that the series has it from the start if you agree it best that way. Please advise if you've noticed anything else that stands out for me to handle at the same time.

Thanks,
Mike

#40 lore raw

Re: [PATCH v12 24/24] nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

In reply to Jeff Layton
Quoted 95 lines · Jeff Layton
Quoted 94 lines · Mike Snitzer

From: Trond Myklebust <[email protected]>

Add a FAQ section to give answers to questions that have been raised during review of the localio feature.

---
 Documentation/filesystems/nfs/localio.rst | 77 +++++++++++++++++++++++

 1 file changed, 77 insertions(+)
Documentation/filesystems/nfs/localio.rst +0 -0
index d8bdab88f1db..acd8f3e5d87a 100644
@@ -40,6 +40,83 @@ fio for 20 secs with 24 libaio threads, 128k directio reads, qd of 8,

 - Without LOCALIO:
   read: IOPS=12.0k, BW=1495MiB/s (1568MB/s)(29.2GiB/20015msec)

Documentation/filesystems/nfs/localio.rst +74 -0
+FAQ
+===
+
+1. What are the use cases for LOCALIO?
+
+   a. Workloads where the NFS client and server are on the same host
+      realize improved IO performance. In particular, it is common when
+      running containerised workloads for jobs to find themselves
+      running on the same host as the knfsd server being used for
+      storage.
+
+2. What are the requirements for LOCALIO?
+
+   a. Bypass use of the network RPC protocol as much as possible. This
+      includes bypassing XDR and RPC for open, read, write and commit
+      operations.
+   b. Allow client and server to autonomously discover if they are
+      running local to each other without making any assumptions about
+      the local network topology.
+   c. Support the use of containers by being compatible with relevant
+      namespaces (e.g. network, user, mount).
+   d. Support all versions of NFS. NFSv3 is of particular importance
+      because it has wide enterprise usage and pNFS flexfiles makes use
+      of it for the data path.
+
+3. Why doesn´t LOCALIO just compare IP addresses or hostnames when
+   deciding if the NFS client and server are co-located on the same
+   host?
+
+   Since one of the main use cases is containerised workloads, we cannot
+   assume that IP addresses will be shared between the client and
+   server. This sets up a requirement for a handshake protocol that
+   needs to go over the same connection as the NFS traffic in order to
+   identify that the client and the server really are running on the
+   same host. The handshake uses a secret that is sent over the wire,
+   and can be verified by both parties by comparing with a value stored
+   in shared kernel memory if they are truly co-located.
+
+4. Does LOCALIO improve pNFS flexfiles?
+
+   Yes, LOCALIO complements pNFS flexfiles by allowing it to take
+   advantage of NFS client and server locality.  Policy that initiates
+   client IO as closely to the server where the data is stored naturally
+   benefits from the data path optimization LOCALIO provides.
+
+5. Why not develop a new pNFS layout to enable LOCALIO?
+
+   A new pNFS layout could be developed, but doing so would put the
+   onus on the server to somehow discover that the client is co-located
+   when deciding to hand out the layout.
+   There is value in a simpler approach (as provided by LOCALIO) that
+   allows the NFS client to negotiate and leverage locality without
+   requiring more elaborate modeling and discovery of such locality in a
+   more centralized manner.
+
+6. Why is having the client perform a server-side file OPEN, without
+   using RPC, beneficial?  Is the benefit pNFS specific?
+
+   Avoiding the use of XDR and RPC for file opens is beneficial to
+   performance regardless of whether pNFS is used. However adding a
+   requirement to go over the wire to do an open and/or close ends up
+   negating any benefit of avoiding the wire for doing the I/O itself
+   when we´re dealing with small files. There is no benefit to replacing
+   the READ or WRITE with a new open and/or close operation that still
+   needs to go over the wire.
+
+7. Why is LOCALIO only supported with UNIX Authentication (AUTH_UNIX)?
+
+   Strong authentication is usually tied to the connection itself. It
+   works by establishing a context that is cached by the server, and
+   that acts as the key for discovering the authorisation token, which
+   can then be passed to rpc.mountd to complete the authentication
+   process. On the other hand, in the case of AUTH_UNIX, the credential
+   that was passed over the wire is used directly as the key in the
Quoted 8 lines
Quoted 6 lines

+   upcall to rpc.mountd. This simplifies the authentication process, and +   so makes AUTH_UNIX easier to support.
+
 RPC
 ===

I'd just squash this into patch #19.

That'd use the fact Trond is the author.

Does linux have a shortage on commit ids I'm unaware of? ;)

#41 lore raw

Re: [PATCH v12 24/24] nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

Quoted 105 lines · Mike Snitzer
Quoted 95 lines · Jeff Layton
Quoted 94 lines · Mike Snitzer

From: Trond Myklebust <[email protected]>

Add a FAQ section to give answers to questions that have been raised during review of the localio feature.

---
 Documentation/filesystems/nfs/localio.rst | 77 +++++++++++++++++++++++

 1 file changed, 77 insertions(+)
Documentation/filesystems/nfs/localio.rst +0 -0
index d8bdab88f1db..acd8f3e5d87a 100644
@@ -40,6 +40,83 @@ fio for 20 secs with 24 libaio threads, 128k directio reads, qd of 8,

 - Without LOCALIO:
   read: IOPS=12.0k, BW=1495MiB/s (1568MB/s)(29.2GiB/20015msec)

Documentation/filesystems/nfs/localio.rst +74 -0
+FAQ
+===
+
+1. What are the use cases for LOCALIO?
+
+   a. Workloads where the NFS client and server are on the same host
+      realize improved IO performance. In particular, it is common when
+      running containerised workloads for jobs to find themselves
+      running on the same host as the knfsd server being used for
+      storage.
+
+2. What are the requirements for LOCALIO?
+
+   a. Bypass use of the network RPC protocol as much as possible. This
+      includes bypassing XDR and RPC for open, read, write and commit
+      operations.
+   b. Allow client and server to autonomously discover if they are
+      running local to each other without making any assumptions about
+      the local network topology.
+   c. Support the use of containers by being compatible with relevant
+      namespaces (e.g. network, user, mount).
+   d. Support all versions of NFS. NFSv3 is of particular importance
+      because it has wide enterprise usage and pNFS flexfiles makes use
+      of it for the data path.
+
+3. Why doesn´t LOCALIO just compare IP addresses or hostnames when
+   deciding if the NFS client and server are co-located on the same
+   host?
+
+   Since one of the main use cases is containerised workloads, we cannot
+   assume that IP addresses will be shared between the client and
+   server. This sets up a requirement for a handshake protocol that
+   needs to go over the same connection as the NFS traffic in order to
+   identify that the client and the server really are running on the
+   same host. The handshake uses a secret that is sent over the wire,
+   and can be verified by both parties by comparing with a value stored
+   in shared kernel memory if they are truly co-located.
+
+4. Does LOCALIO improve pNFS flexfiles?
+
+   Yes, LOCALIO complements pNFS flexfiles by allowing it to take
+   advantage of NFS client and server locality.  Policy that initiates
+   client IO as closely to the server where the data is stored naturally
+   benefits from the data path optimization LOCALIO provides.
+
+5. Why not develop a new pNFS layout to enable LOCALIO?
+
+   A new pNFS layout could be developed, but doing so would put the
+   onus on the server to somehow discover that the client is co-located
+   when deciding to hand out the layout.
+   There is value in a simpler approach (as provided by LOCALIO) that
+   allows the NFS client to negotiate and leverage locality without
+   requiring more elaborate modeling and discovery of such locality in a
+   more centralized manner.
+
+6. Why is having the client perform a server-side file OPEN, without
+   using RPC, beneficial?  Is the benefit pNFS specific?
+
+   Avoiding the use of XDR and RPC for file opens is beneficial to
+   performance regardless of whether pNFS is used. However adding a
+   requirement to go over the wire to do an open and/or close ends up
+   negating any benefit of avoiding the wire for doing the I/O itself
+   when we´re dealing with small files. There is no benefit to replacing
+   the READ or WRITE with a new open and/or close operation that still
+   needs to go over the wire.
+
+7. Why is LOCALIO only supported with UNIX Authentication (AUTH_UNIX)?
+
+   Strong authentication is usually tied to the connection itself. It
+   works by establishing a context that is cached by the server, and
+   that acts as the key for discovering the authorisation token, which
+   can then be passed to rpc.mountd to complete the authentication
+   process. On the other hand, in the case of AUTH_UNIX, the credential
+   that was passed over the wire is used directly as the key in the
Quoted 8 lines
Quoted 6 lines

+   upcall to rpc.mountd. This simplifies the authentication process, and +   so makes AUTH_UNIX easier to support.
+
 RPC
 ===

I'd just squash this into patch #19.

Quoted 1 line

That'd use the fact Trond is the author.

s/use/lose/

Quoted 3 lines

Does linux have a shortage on commit ids I'm unaware of? ;)

Anyway, I'd prefer the FAQ be left split out as a separate commit given the author is different.

#23 lore raw

Re: [PATCH v12 12/24] SUNRPC: replace program list with program array

In reply to Jeff Layton
Quoted 105 lines · Jeff Layton
Quoted 91 lines · Mike Snitzer

From: NeilBrown <[email protected]>

A service created with svc_create_pooled() can be given a linked list of programs and all of these will be served.

Using a linked list makes it cumbersome when there are several programs that can be optionally selected with CONFIG settings.

After this patch is applied, API consumers must use only svc_create_pooled() when creating an RPC service that listens for more than one RPC program.

---
 fs/nfsd/nfsctl.c           |  2 +-
 fs/nfsd/nfsd.h             |  2 +-
 fs/nfsd/nfssvc.c           | 67 +++++++++++++++++-------------------- include/linux/sunrpc/svc.h |  7 ++--
 net/sunrpc/svc.c           | 68 ++++++++++++++++++++++---------------- net/sunrpc/svc_xprt.c      |  2 +- net/sunrpc/svcauth_unix.c  |  3 +-

 7 files changed, 79 insertions(+), 72 deletions(-)
fs/nfsd/nfsctl.c +1 -1
index 1c9e5b4bcb0a..64c1b4d649bc 100644
@@ -2246,7 +2246,7 @@ static __net_init int nfsd_net_init(struct net *net)
  	if (retval)
  		goto out_repcache_error;
  	memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
-	nn->nfsd_svcstats.program = &nfsd_program;
+	nn->nfsd_svcstats.program = &nfsd_programs[0];
  	for (i = 0; i < sizeof(nn->nfsd_versions); i++)
  		nn->nfsd_versions[i] = nfsd_support_version(i);
  	for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
fs/nfsd/nfsd.h +0 -0
index f87a359d968f..232a873dc53a 100644
@@ -85,7 +85,7 @@ struct nfsd_genl_rqstp {
  	u32			rq_opnum[NFSD_MAX_OPS_PER_COMPOUND];
  };

fs/nfsd/nfsd.h +1 -1
-extern struct svc_program	nfsd_program;
+extern struct svc_program	nfsd_programs[];

 extern const struct svc_version nfsd_version2, nfsd_version3, nfsd_version4;
 extern struct mutex nfsd_mutex;
 extern spinlock_t nfsd_drc_lock;

fs/nfsd/nfssvc.c +0 -0
index 1bec3a53e35f..5f8680ab1013 100644
@@ -35,7 +35,6 @@
  #define NFSDDBG_FACILITY	NFSDDBG_SVC


 atomic_t nfsd_th_cnt = ATOMIC_INIT(0);
-extern struct svc_program nfsd_program;
 static int nfsd(void *vrqstp);
 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
 static int nfsd_acl_rpcbind_set(struct net *,

fs/nfsd/nfssvc.c +0 -0
@@ -87,16 +86,6 @@ static const struct svc_version *localio_versions[] = {


 #define NFSD_LOCALIO_NRVERS ARRAY_SIZE(localio_versions)

fs/nfsd/nfssvc.c +0 -10
-static struct svc_program	nfsd_localio_program = {
-	.pg_prog		= NFS_LOCALIO_PROGRAM,
-	.pg_nvers		= NFSD_LOCALIO_NRVERS,
-	.pg_vers		= localio_versions,
-	.pg_name		= "nfslocalio",
-	.pg_class		= "nfsd",
-	.pg_authenticate	= &svc_set_client,
-	.pg_init_request	= svc_generic_init_request,
-	.pg_rpcbind_set		= svc_generic_rpcbind_set,
-};

 #endif /* CONFIG_NFSD_LOCALIO */

 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)

fs/nfsd/nfssvc.c +0 -0
@@ -109,23 +98,9 @@ static const struct svc_version *nfsd_acl_version[] = {
  # endif
  };

fs/nfsd/nfssvc.c +1 -1
-#define NFSD_ACL_MINVERS            2
+#define NFSD_ACL_MINVERS	2

 #define NFSD_ACL_NRVERS ARRAY_SIZE(nfsd_acl_version)

fs/nfsd/nfssvc.c +0 -4
-static struct svc_program	nfsd_acl_program = {
-#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
-	.pg_next		= &nfsd_localio_program,
-#endif /* CONFIG_NFSD_LOCALIO */

fs/nfsd/nfssvc.c static const struct svc_version *nfsd_acl_version[] = { · line 128

Quoted 10 lines
fs/nfsd/nfssvc.c +0 -10
-	.pg_prog		= NFS_ACL_PROGRAM,
-	.pg_nvers		= NFSD_ACL_NRVERS,
-	.pg_vers		= nfsd_acl_version,
-	.pg_name		= "nfsacl",
-	.pg_class		= "nfsd",
-	.pg_authenticate	= &svc_set_client,
-	.pg_init_request	= nfsd_acl_init_request,
-	.pg_rpcbind_set		= nfsd_acl_rpcbind_set,
-};
-

You just added this code in patch 11.

Quoted 3 lines

I think it'd be clearer to reverse the order of patches 11 and 12. That way you don't have this interim version of the localio program that lives on the linked list.

You may recall that these changes developed over time. This patch from Neil came after because he saw a way to make things better. Inverting/inserting patches earlier to reduce "churn" loses the development history. (It also introduces possibility to cause some regression or break bisect-ability.)

It'd be one thing if I wrote every patch in this series, but I built on others' work and then others upon that. Preserving development history and attribution is something I've always tried to do. Otherwise changes get attributed to the wrong person.

SO in this instance, I'd prefer to keep Neil's contribution as-is and avoid switching patch 12 and 11.

Thanks,
Mike

Quoted 314 lines
Quoted 310 lines

 #endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */
 static const struct svc_version *nfsd_version[NFSD_MAXVERS+1] = {

fs/nfsd/nfssvc.c +0 -0
@@ -138,22 +113,41 @@ static const struct svc_version *nfsd_version[NFSD_MAXVERS+1] = {
  #endif
  };

fs/nfsd/nfssvc.c +2 -8
-struct svc_program		nfsd_program = {
-#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
-	.pg_next		= &nfsd_acl_program,
-#else
-#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
-	.pg_next		= &nfsd_localio_program,
-#endif /* CONFIG_NFSD_LOCALIO */
-#endif
+struct svc_program		nfsd_programs[] = {
+	{

  .pg_prog = NFS_PROGRAM, /* program number */
  .pg_nvers = NFSD_MAXVERS+1, /* nr of entries in nfsd_version */
  .pg_vers = nfsd_version, /* version table */
  .pg_name = "nfsd", /* program name */
  .pg_class = "nfsd", /* authentication class */

fs/nfsd/nfssvc.c +1 -1
-	.pg_authenticate	= &svc_set_client,	/* export authentication */
+	.pg_authenticate	= svc_set_client,	/* export authentication */

  .pg_init_request = nfsd_init_request,
  .pg_rpcbind_set = nfsd_rpcbind_set,

fs/nfsd/nfssvc.c +25 -0
+	},
+#if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
+	{
+	.pg_prog		= NFS_ACL_PROGRAM,
+	.pg_nvers		= NFSD_ACL_NRVERS,
+	.pg_vers		= nfsd_acl_version,
+	.pg_name		= "nfsacl",
+	.pg_class		= "nfsd",
+	.pg_authenticate	= svc_set_client,
+	.pg_init_request	= nfsd_acl_init_request,
+	.pg_rpcbind_set		= nfsd_acl_rpcbind_set,
+	},
+#endif /* defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL) */
+#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
+	{
+	.pg_prog		= NFS_LOCALIO_PROGRAM,
+	.pg_nvers		= NFSD_LOCALIO_NRVERS,
+	.pg_vers		= localio_versions,
+	.pg_name		= "nfslocalio",
+	.pg_class		= "nfsd",
+	.pg_authenticate	= svc_set_client,
+	.pg_init_request	= svc_generic_init_request,
+	.pg_rpcbind_set		= svc_generic_rpcbind_set,
+	}
+#endif /* IS_ENABLED(CONFIG_NFSD_LOCALIO) */

 };

 bool nfsd_support_version(int vers)

fs/nfsd/nfssvc.c +2 -1
@@ -663,7 +657,8 @@ int nfsd_create_serv(struct net *net)
  	if (nfsd_max_blksize == 0)
  		nfsd_max_blksize = nfsd_get_default_max_blksize();
  	nfsd_reset_versions(nn);
-	serv = svc_create_pooled(&nfsd_program, &nn->nfsd_svcstats,
+	serv = svc_create_pooled(nfsd_programs, ARRAY_SIZE(nfsd_programs),
+				 &nn->nfsd_svcstats,
  				 nfsd_max_blksize, nfsd);
  	if (serv == NULL)
  		return -ENOMEM;
include/linux/sunrpc/svc.h +1 -1
index 437672bcaa22..c7ad2fb2a155 100644
@@ -67,9 +67,10 @@ enum {
   * We currently do not support more than one RPC program per daemon.
   */
  struct svc_serv {
-	struct svc_program *	sv_program;	/* RPC program */
+	struct svc_program *	sv_programs;	/* RPC programs */

  struct svc_stat * sv_stats; /* RPC statistics */
  spinlock_t sv_lock;

include/linux/sunrpc/svc.h +1 -0
+	unsigned int		sv_nprogs;	/* Number of sv_programs */

  unsigned int sv_nrthreads; /* # of server threads */
  unsigned int sv_maxconn; /* max connections allowed or
  * '0' causing max to be based

include/linux/sunrpc/svc.h +0 -0
@@ -357,10 +358,9 @@ struct svc_process_info {
  };


 /*
- * List of RPC programs on the same transport endpoint
+ * RPC program - an array of these can use the same transport endpoint */
 struct svc_program {

include/linux/sunrpc/svc.h +0 -1
-	struct svc_program *	pg_next;	/* other programs (same xprt) */

  u32 pg_prog; /* program number */
  unsigned int pg_lovers; /* lowest version */
  unsigned int pg_hivers; /* highest version */

include/linux/sunrpc/svc.h +1 -0
@@ -438,6 +438,7 @@ bool		   svc_rqst_replace_page(struct svc_rqst *rqstp,
  void		   svc_rqst_release_pages(struct svc_rqst *rqstp);
  void		   svc_exit_thread(struct svc_rqst *);
  struct svc_serv *  svc_create_pooled(struct svc_program *prog,
+				     unsigned int nprog,
  				     struct svc_stat *stats,
  				     unsigned int bufsize,
  				     int (*threadfn)(void *data));
net/sunrpc/svc.c +0 -0
index ff6f3e35b36d..b33386d249c2 100644
@@ -440,10 +440,11 @@ EXPORT_SYMBOL_GPL(svc_rpcb_cleanup);


 static int svc_uses_rpcbind(struct svc_serv *serv) {

net/sunrpc/svc.c +4 -2
-	struct svc_program	*progp;
-	unsigned int		i;
+	unsigned int		p, i;
+
+	for (p = 0; p < serv->sv_nprogs; p++) {
+		struct svc_program *progp = &serv->sv_programs[p];

net/sunrpc/svc.c +0 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next) {

  for (i = 0; i < progp->pg_nvers; i++) { if (progp->pg_vers[i] == NULL) continue;

net/sunrpc/svc.c +0 -0
@@ -480,7 +481,7 @@ __svc_init_bc(struct svc_serv *serv)
   * Create an RPC service
   */

 static struct svc_serv *

net/sunrpc/svc.c +1 -1
-__svc_create(struct svc_program *prog, struct svc_stat *stats,
+__svc_create(struct svc_program *prog, int nprogs, struct svc_stat *stats,

       unsigned int bufsize, int npools, int (*threadfn)(void *data)) {
  struct svc_serv *serv;

net/sunrpc/svc.c +14 -12
@@ -491,7 +492,8 @@ __svc_create(struct svc_program *prog, struct svc_stat *stats,
  	if (!(serv = kzalloc(sizeof(*serv), GFP_KERNEL)))
  		return NULL;
  	serv->sv_name      = prog->pg_name;
-	serv->sv_program   = prog;
+	serv->sv_programs  = prog;
+	serv->sv_nprogs    = nprogs;
  	serv->sv_stats     = stats;
  	if (bufsize > RPCSVC_MAXPAYLOAD)
  		bufsize = RPCSVC_MAXPAYLOAD;
@@ -499,17 +501,18 @@ __svc_create(struct svc_program *prog, struct svc_stat *stats,
  	serv->sv_max_mesg  = roundup(serv->sv_max_payload + PAGE_SIZE, PAGE_SIZE);
  	serv->sv_threadfn = threadfn;
  	xdrsize = 0;
-	while (prog) {
-		prog->pg_lovers = prog->pg_nvers-1;
-		for (vers=0; vers<prog->pg_nvers ; vers++)
-			if (prog->pg_vers[vers]) {
-				prog->pg_hivers = vers;
-				if (prog->pg_lovers > vers)
-					prog->pg_lovers = vers;
-				if (prog->pg_vers[vers]->vs_xdrsize > xdrsize)
-					xdrsize = prog->pg_vers[vers]->vs_xdrsize;
+	for (i = 0; i < nprogs; i++) {
+		struct svc_program *progp = &prog[i];
+
+		progp->pg_lovers = progp->pg_nvers-1;
+		for (vers = 0; vers < progp->pg_nvers ; vers++)
+			if (progp->pg_vers[vers]) {
+				progp->pg_hivers = vers;
+				if (progp->pg_lovers > vers)
+					progp->pg_lovers = vers;
+				if (progp->pg_vers[vers]->vs_xdrsize > xdrsize)
+					xdrsize = progp->pg_vers[vers]->vs_xdrsize;
  			}
-		prog = prog->pg_next;
  	}
  	serv->sv_xdrsize   = xdrsize;
  	INIT_LIST_HEAD(&serv->sv_tempsocks);
@@ -558,13 +561,14 @@ __svc_create(struct svc_program *prog, struct svc_stat *stats,
  struct svc_serv *svc_create(struct svc_program *prog, unsigned int bufsize,
  			    int (*threadfn)(void *data))
  {
-	return __svc_create(prog, NULL, bufsize, 1, threadfn);
+	return __svc_create(prog, 1, NULL, bufsize, 1, threadfn);
  }
  EXPORT_SYMBOL_GPL(svc_create);


 /**
  * svc_create_pooled - Create an RPC service with pooled threads
- * @prog: the RPC program the new service will handle
+ * @prog:  Array of RPC programs the new service will handle
+ * @nprogs: Number of programs in the array
  * @stats: the stats struct if desired
  * @bufsize: maximum message size for @prog
  * @threadfn: a function to service RPC requests for @prog

net/sunrpc/svc.c +1 -0
@@ -572,6 +576,7 @@ EXPORT_SYMBOL_GPL(svc_create);
   * Returns an instantiated struct svc_serv object or NULL.
   */
  struct svc_serv *svc_create_pooled(struct svc_program *prog,
+				   unsigned int nprogs,
  				   struct svc_stat *stats,
  				   unsigned int bufsize,
  				   int (*threadfn)(void *data))
@@ -579,7 +584,7 @@ struct svc_serv *svc_create_pooled(struct svc_program *prog,
  	struct svc_serv *serv;
  	unsigned int npools = svc_pool_map_get();

net/sunrpc/svc.c +1 -1
-	serv = __svc_create(prog, stats, bufsize, npools, threadfn);
+	serv = __svc_create(prog, nprogs, stats, bufsize, npools, threadfn);

  if (!serv)
  goto out_err;
  serv->sv_is_pooled = true;

net/sunrpc/svc.c +0 -0
@@ -602,16 +607,16 @@ svc_destroy(struct svc_serv **servp)


  *servp = NULL;

net/sunrpc/svc.c +1 -1
-	dprintk("svc: svc_destroy(%s)\n", serv->sv_program->pg_name);
+	dprintk("svc: svc_destroy(%s)\n", serv->sv_programs->pg_name);

  timer_shutdown_sync(&serv->sv_temptimer);

  /*
  * Remaining transports at this point are not expected. */ WARN_ONCE(!list_empty(&serv->sv_permsocks),

net/sunrpc/svc.c +1 -1
-		  "SVC: permsocks remain for %s\n", serv->sv_program->pg_name);
+		  "SVC: permsocks remain for %s\n", serv->sv_programs->pg_name);

  WARN_ONCE(!list_empty(&serv->sv_tempsocks),

net/sunrpc/svc.c +1 -1
-		  "SVC: tempsocks remain for %s\n", serv->sv_program->pg_name);
+		  "SVC: tempsocks remain for %s\n", serv->sv_programs->pg_name);


  cache_clean_deferred(serv);

net/sunrpc/svc.c +1 -2
@@ -1149,15 +1154,16 @@ int svc_register(const struct svc_serv *serv, struct net *net,
  		 const int family, const unsigned short proto,
  		 const unsigned short port)
  {
-	struct svc_program	*progp;
-	unsigned int		i;
+	unsigned int		p, i;
  	int			error = 0;


  WARN_ON_ONCE(proto == 0 && port == 0);
  if (proto == 0 && port == 0)
  return -EINVAL;

net/sunrpc/svc.c +3 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next) {
+	for (p = 0; p < serv->sv_nprogs; p++) {
+		struct svc_program *progp = &serv->sv_programs[p];
+

  for (i = 0; i < progp->pg_nvers; i++) {

  error = progp->pg_rpcbind_set(net, progp, i,

net/sunrpc/svc.c +1 -2
@@ -1209,13 +1215,14 @@ static void __svc_unregister(struct net *net, const u32 program, const u32 versi
  static void svc_unregister(const struct svc_serv *serv, struct net *net)
  {
  	struct sighand_struct *sighand;
-	struct svc_program *progp;
  	unsigned long flags;
-	unsigned int i;
+	unsigned int p, i;


  clear_thread_flag(TIF_SIGPENDING);

net/sunrpc/svc.c +3 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next) {
+	for (p = 0; p < serv->sv_nprogs; p++) {
+		struct svc_program *progp = &serv->sv_programs[p];
+

  for (i = 0; i < progp->pg_nvers; i++) { if (progp->pg_vers[i] == NULL) continue;

net/sunrpc/svc.c +1 -1
@@ -1321,7 +1328,7 @@ svc_process_common(struct svc_rqst *rqstp)
  	struct svc_process_info process;
  	enum svc_auth_status	auth_res;
  	unsigned int		aoffset;
-	int			rc;
+	int			pr, rc;
  	__be32			*p;


  /* Will be turned off only when NFSv4 Sessions are used */

net/sunrpc/svc.c +0 -0
@@ -1345,9 +1352,12 @@ svc_process_common(struct svc_rqst *rqstp)
  	rqstp->rq_vers = be32_to_cpup(p++);
  	rqstp->rq_proc = be32_to_cpup(p);

net/sunrpc/svc.c +3 -1
-	for (progp = serv->sv_program; progp; progp = progp->pg_next)
+	for (pr = 0; pr < serv->sv_nprogs; pr++) {
+		progp = &serv->sv_programs[pr];
+

  if (rqstp->rq_prog == progp->pg_prog) break;

net/sunrpc/svc.c +1 -0
+	}


  /*
  * Decode auth data, and add verifier to reply buffer.

net/sunrpc/svc_xprt.c +1 -1
index 53ebc719ff5a..43c57124de52 100644
@@ -268,7 +268,7 @@ static int _svc_xprt_create(struct svc_serv *serv, const char *xprt_name,
  		spin_unlock(&svc_xprt_class_lock);
  		newxprt = xcl->xcl_ops->xpo_create(serv, net, sap, len, flags);
  		if (IS_ERR(newxprt)) {
-			trace_svc_xprt_create_err(serv->sv_program->pg_name,
+			trace_svc_xprt_create_err(serv->sv_programs->pg_name,
  						  xcl->xcl_name, sap, len,
  						  newxprt);
  			module_put(xcl->xcl_owner);
net/sunrpc/svcauth_unix.c +2 -1
index 04b45588ae6f..8ca98b146ec8 100644
@@ -697,7 +697,8 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
  	rqstp->rq_auth_stat = rpc_autherr_badcred;
  	ipm = ip_map_cached_get(xprt);
  	if (ipm == NULL)
-		ipm = __ip_map_lookup(sn->ip_map_cache, rqstp->rq_server->sv_program->pg_class,
+		ipm = __ip_map_lookup(sn->ip_map_cache,
+				      rqstp->rq_server->sv_programs->pg_class,
  				    &sin6->sin6_addr);


  if (ipm == NULL)

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

Re: [PATCH v12 05/24] nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

In reply to Jeff Layton
Quoted 105 lines · Jeff Layton
Quoted 104 lines · Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL.  Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++-------- fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------

 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +0 -0
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,


  error = nfserr_stale;
  if (IS_ERR(exp)) {

fs/nfsd/nfsfh.c +0 -2
-		if (rqstp)
-			trace_nfsd_set_fh_dentry_badexport(rqstp,

fhp, PTR_ERR(exp));

fs/nfsd/nfsfh.c +1 -0
+		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp,

PTR_ERR(exp));

  if (PTR_ERR(exp) == -ENOENT)
  return error;

fs/nfsd/nfsfh.c +0 -2
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
  						data_left,
 fileid_type, 0,
  						nfsd_acceptable,
 exp);
  		if (IS_ERR_OR_NULL(dentry)) {
-			if (rqstp)
-

trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,

fs/nfsd/nfsfh.c +1 -0
+			trace_nfsd_set_fh_dentry_badhandle(rqstp,

fhp,
  dentry ?  PTR_ERR(dentry) :
-ESTALE);
  switch (PTR_ERR(dentry)) {
  case -ENOMEM:

fs/nfsd/nfsfh.c +0 -0
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	dentry = fhp->fh_dentry;
  	exp = fhp->fh_export;

fs/nfsd/nfsfh.c +1 -2
-	if (rqstp)
-		trace_nfsd_fh_verify(rqstp, fhp, type, access);
+	trace_nfsd_fh_verify(net, rqstp, fhp, type, access);


  /*
  * We still have to do all these permission checks, even when

fs/nfsd/nfsfh.c +0 -0
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	/* Finally, check access permissions. */
  	error = nfsd_permission(cred, exp, dentry, access);

 out:

fs/nfsd/nfsfh.c +0 -2
-	if (rqstp)
-		trace_nfsd_fh_verify_err(rqstp, fhp, type, access,

error);

fs/nfsd/nfsfh.c +1 -0
+	trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access,

error);
  if (error == nfserr_stale)
  nfsd_stats_fh_stale_inc(nn, exp);
  return error;

fs/nfsd/trace.h +0 -0
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,


 TRACE_EVENT(nfsd_fh_verify,
  TP_PROTO(

fs/nfsd/trace.h +1 -0
+		const struct net *net,

  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access
  ),

fs/nfsd/trace.h +1 -1
-	TP_ARGS(rqstp, fhp, type, access),
+	TP_ARGS(net, rqstp, fhp, type, access),

  TP_STRUCT__entry(
  __field(unsigned int, netns_ino) __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)

fs/nfsd/trace.h +0 -0
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
  		__field(unsigned long, access)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +0 -2
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +0 -2
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +3 -2
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

fs/nfsd/trace.h +1 -0
+			__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 8 lines

fs/nfsd/trace.h

Quoted 4 lines
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_remotelen);

fs/nfsd/trace.h +1 -0
+		}

Does this need an else branch to set these values to something when rqstp is NULL, or are we guaranteed that they are already zeroed out when they aren't assigned?

I'm not sure. It isn't immediately clear what is actually using these.

But I did just notice an inconsistency, these entry members are defined:

                __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
                __sockaddr(client, rqstp->rq_xprt->xpt_remotelen)

Yet they go on to use rqstp->rq_xprt->xpt_locallen and rqstp->rq_xprt->xpt_remotelen respectively.

Chuck, would welcome your feedback on how to properly fix these tracepoints to handle rqstp being NULL. And the inconsistency I just noted is something extra.

Thanks,
Mike

#24 lore raw

Re: [PATCH v12 12/24] SUNRPC: replace program list with program array

In reply to Mike Snitzer
Quoted 116 lines · Mike Snitzer
Quoted 105 lines · Jeff Layton
Quoted 91 lines · Mike Snitzer

From: NeilBrown <[email protected]>

A service created with svc_create_pooled() can be given a linked list of programs and all of these will be served.

Using a linked list makes it cumbersome when there are several programs that can be optionally selected with CONFIG settings.

After this patch is applied, API consumers must use only svc_create_pooled() when creating an RPC service that listens for more than one RPC program.

---
 fs/nfsd/nfsctl.c           |  2 +-
 fs/nfsd/nfsd.h             |  2 +-
 fs/nfsd/nfssvc.c           | 67 +++++++++++++++++-------------------- include/linux/sunrpc/svc.h |  7 ++--
 net/sunrpc/svc.c           | 68 ++++++++++++++++++++++---------------- net/sunrpc/svc_xprt.c      |  2 +- net/sunrpc/svcauth_unix.c  |  3 +-

 7 files changed, 79 insertions(+), 72 deletions(-)
fs/nfsd/nfsctl.c +1 -1
index 1c9e5b4bcb0a..64c1b4d649bc 100644
@@ -2246,7 +2246,7 @@ static __net_init int nfsd_net_init(struct net *net)
  	if (retval)
  		goto out_repcache_error;
  	memset(&nn->nfsd_svcstats, 0, sizeof(nn->nfsd_svcstats));
-	nn->nfsd_svcstats.program = &nfsd_program;
+	nn->nfsd_svcstats.program = &nfsd_programs[0];
  	for (i = 0; i < sizeof(nn->nfsd_versions); i++)
  		nn->nfsd_versions[i] = nfsd_support_version(i);
  	for (i = 0; i < sizeof(nn->nfsd4_minorversions); i++)
fs/nfsd/nfsd.h +0 -0
index f87a359d968f..232a873dc53a 100644
@@ -85,7 +85,7 @@ struct nfsd_genl_rqstp {
  	u32			rq_opnum[NFSD_MAX_OPS_PER_COMPOUND];
  };

fs/nfsd/nfsd.h +1 -1
-extern struct svc_program	nfsd_program;
+extern struct svc_program	nfsd_programs[];

 extern const struct svc_version nfsd_version2, nfsd_version3, nfsd_version4;
 extern struct mutex nfsd_mutex;
 extern spinlock_t nfsd_drc_lock;

fs/nfsd/nfssvc.c +0 -0
index 1bec3a53e35f..5f8680ab1013 100644
@@ -35,7 +35,6 @@
  #define NFSDDBG_FACILITY	NFSDDBG_SVC


 atomic_t nfsd_th_cnt = ATOMIC_INIT(0);
-extern struct svc_program nfsd_program;
 static int nfsd(void *vrqstp);
 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
 static int nfsd_acl_rpcbind_set(struct net *,

fs/nfsd/nfssvc.c +0 -0
@@ -87,16 +86,6 @@ static const struct svc_version *localio_versions[] = {


 #define NFSD_LOCALIO_NRVERS ARRAY_SIZE(localio_versions)

fs/nfsd/nfssvc.c +0 -10
-static struct svc_program	nfsd_localio_program = {
-	.pg_prog		= NFS_LOCALIO_PROGRAM,
-	.pg_nvers		= NFSD_LOCALIO_NRVERS,
-	.pg_vers		= localio_versions,
-	.pg_name		= "nfslocalio",
-	.pg_class		= "nfsd",
-	.pg_authenticate	= &svc_set_client,
-	.pg_init_request	= svc_generic_init_request,
-	.pg_rpcbind_set		= svc_generic_rpcbind_set,
-};

 #endif /* CONFIG_NFSD_LOCALIO */

 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)

fs/nfsd/nfssvc.c +0 -0
@@ -109,23 +98,9 @@ static const struct svc_version *nfsd_acl_version[] = {
  # endif
  };

fs/nfsd/nfssvc.c +1 -1
-#define NFSD_ACL_MINVERS            2
+#define NFSD_ACL_MINVERS	2

 #define NFSD_ACL_NRVERS ARRAY_SIZE(nfsd_acl_version)

fs/nfsd/nfssvc.c +0 -4
-static struct svc_program	nfsd_acl_program = {
-#if IS_ENABLED(CONFIG_NFSD_LOCALIO)
-	.pg_next		= &nfsd_localio_program,
-#endif /* CONFIG_NFSD_LOCALIO */

fs/nfsd/nfssvc.c static const struct svc_version *nfsd_acl_version[] = { · line 128

Quoted 10 lines
fs/nfsd/nfssvc.c +0 -10
-	.pg_prog		= NFS_ACL_PROGRAM,
-	.pg_nvers		= NFSD_ACL_NRVERS,
-	.pg_vers		= nfsd_acl_version,
-	.pg_name		= "nfsacl",
-	.pg_class		= "nfsd",
-	.pg_authenticate	= &svc_set_client,
-	.pg_init_request	= nfsd_acl_init_request,
-	.pg_rpcbind_set		= nfsd_acl_rpcbind_set,
-};
-

You just added this code in patch 11.

Quoted 3 lines

I think it'd be clearer to reverse the order of patches 11 and 12. That way you don't have this interim version of the localio program that lives on the linked list.

You may recall that these changes developed over time. This patch from Neil came after because he saw a way to make things better. Inverting/inserting patches earlier to reduce "churn" loses the development history. (It also introduces possibility to cause some regression or break bisect-ability.)

Quoted 7 lines

It'd be one thing if I wrote every patch in this series, but I built on others' work and then others upon that. Preserving development history and attribution is something I've always tried to do. Otherwise changes get attributed to the wrong person.

SO in this instance, I'd prefer to keep Neil's contribution as-is and avoid switching patch 12 and 11.

Looked closer, Neil is a co-developer on the preceding patch (happened as side-effect of a different rebase some iterations ago). So I'm fine with switching patches 11 and 12 like you suggested. It does make things cleaner.

Thanks,
Mike

maintainer
#42 lore raw

Re: [PATCH v12 24/24] nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

In reply to Mike Snitzer
Quoted 108 lines · Mike Snitzer
Quoted 105 lines · Mike Snitzer
Quoted 95 lines · Jeff Layton
Quoted 94 lines · Mike Snitzer

From: Trond Myklebust <[email protected]>

Add a FAQ section to give answers to questions that have been raised during review of the localio feature.

---
 Documentation/filesystems/nfs/localio.rst | 77 +++++++++++++++++++++++

 1 file changed, 77 insertions(+)
Documentation/filesystems/nfs/localio.rst +0 -0
index d8bdab88f1db..acd8f3e5d87a 100644
@@ -40,6 +40,83 @@ fio for 20 secs with 24 libaio threads, 128k directio reads, qd of 8,

 - Without LOCALIO:
   read: IOPS=12.0k, BW=1495MiB/s (1568MB/s)(29.2GiB/20015msec)

Documentation/filesystems/nfs/localio.rst +74 -0
+FAQ
+===
+
+1. What are the use cases for LOCALIO?
+
+   a. Workloads where the NFS client and server are on the same host
+      realize improved IO performance. In particular, it is common when
+      running containerised workloads for jobs to find themselves
+      running on the same host as the knfsd server being used for
+      storage.
+
+2. What are the requirements for LOCALIO?
+
+   a. Bypass use of the network RPC protocol as much as possible. This
+      includes bypassing XDR and RPC for open, read, write and commit
+      operations.
+   b. Allow client and server to autonomously discover if they are
+      running local to each other without making any assumptions about
+      the local network topology.
+   c. Support the use of containers by being compatible with relevant
+      namespaces (e.g. network, user, mount).
+   d. Support all versions of NFS. NFSv3 is of particular importance
+      because it has wide enterprise usage and pNFS flexfiles makes use
+      of it for the data path.
+
+3. Why doesn´t LOCALIO just compare IP addresses or hostnames when
+   deciding if the NFS client and server are co-located on the same
+   host?
+
+   Since one of the main use cases is containerised workloads, we cannot
+   assume that IP addresses will be shared between the client and
+   server. This sets up a requirement for a handshake protocol that
+   needs to go over the same connection as the NFS traffic in order to
+   identify that the client and the server really are running on the
+   same host. The handshake uses a secret that is sent over the wire,
+   and can be verified by both parties by comparing with a value stored
+   in shared kernel memory if they are truly co-located.
+
+4. Does LOCALIO improve pNFS flexfiles?
+
+   Yes, LOCALIO complements pNFS flexfiles by allowing it to take
+   advantage of NFS client and server locality.  Policy that initiates
+   client IO as closely to the server where the data is stored naturally
+   benefits from the data path optimization LOCALIO provides.
+
+5. Why not develop a new pNFS layout to enable LOCALIO?
+
+   A new pNFS layout could be developed, but doing so would put the
+   onus on the server to somehow discover that the client is co-located
+   when deciding to hand out the layout.
+   There is value in a simpler approach (as provided by LOCALIO) that
+   allows the NFS client to negotiate and leverage locality without
+   requiring more elaborate modeling and discovery of such locality in a
+   more centralized manner.
+
+6. Why is having the client perform a server-side file OPEN, without
+   using RPC, beneficial?  Is the benefit pNFS specific?
+
+   Avoiding the use of XDR and RPC for file opens is beneficial to
+   performance regardless of whether pNFS is used. However adding a
+   requirement to go over the wire to do an open and/or close ends up
+   negating any benefit of avoiding the wire for doing the I/O itself
+   when we´re dealing with small files. There is no benefit to replacing
+   the READ or WRITE with a new open and/or close operation that still
+   needs to go over the wire.
+
+7. Why is LOCALIO only supported with UNIX Authentication (AUTH_UNIX)?
+
+   Strong authentication is usually tied to the connection itself. It
+   works by establishing a context that is cached by the server, and
+   that acts as the key for discovering the authorisation token, which
+   can then be passed to rpc.mountd to complete the authentication
+   process. On the other hand, in the case of AUTH_UNIX, the credential
+   that was passed over the wire is used directly as the key in the
Quoted 8 lines
Quoted 6 lines

+   upcall to rpc.mountd. This simplifies the authentication process, and +   so makes AUTH_UNIX easier to support.
+
 RPC
 ===

I'd just squash this into patch #19.

Quoted 1 line

That'd use the fact Trond is the author.

Quoted 8 lines

s/use/lose/

Quoted 3 lines

Does linux have a shortage on commit ids I'm unaware of? ;)

Anyway, I'd prefer the FAQ be left split out as a separate commit given the author is different.

No worries. I don't feel as strongly about this one.

Signature · 1 line
Jeff Layton <[email protected]>
#48 lore raw
In reply to Jeff Layton

Hey Jeff,

Quoted 4 lines · Jeff Layton

This looks much improved. I didn't see anything that stood out at me as being problematic code-wise with the design or final product, aside from a couple of minor things.

BTW, thanks for this feedback, much appreciated!

Quoted 9 lines

But...this patchset is hard to review. My main gripe is that there is a lot of "churn" -- places where you add code, just to rework it in a new way in a later patch.

For instance, the nfsd_file conversion should be integrated into the new infrastructure much earlier instead of having a patch that later does that conversion. Those kinds extraneous changes make this much harder to review than it would be if this were done in a way that avoided that churn.

I think I've addressed all your v12 review comments from earlier today. I've pushed the new series out to my git repo here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

No code changes, purely a bunch of rebasing to clean up like you suggested. Only outstanding thing is the nfsd tracepoints handling of NULL rqstp (would like to get Chuck's expert feedback on that point).

Please feel free to have a look at my branch while I wait for any other v12 feedback from Chuck and/or others before I send out v13. I'd like to avoid spamming the list like I did in the past ;)

Thanks,
Mike

maintainer
#47 lore raw
In reply to Mike Snitzer
Quoted 197 lines · Mike Snitzer
Quoted 184 lines · Jeff Layton
Quoted 165 lines · Mike Snitzer

These latest changes are available in my git tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Significant progress was made on the entire series, I implemented all 3 changes NeilBrown suggested here:
https://marc.info/?l=linux-nfs&m=172004547710968&w=2

And Neil kindly provided review of a preliminary v12 that I then used to refine this final v12 further.  Neil found the series much cleaner and approachable.

This v12 also switches the NFS client's localio code over to driving IO in terms of nfsd's nfsd_file (rather than a simple file pointer). I checked with Jeff Layton and he likes the switch to using nfsd_file (Jeff did suggest I make sure to keep struct nfsd_file completely opaque to the client).  Proper use of nfsd_file provides a solid performance improvement (as detailed in the last patch's commit header) thanks especially to the nfsd filecache's GC feature (which localio now makes use of).

Testing:
- Chuck's kdevops NFS testing has been operating against the nfs-localio-for-next branch for a while now (not sure if LOCALIO is enabled or if Chuck is just verifying the branch works with LOCALIO disabled).
- Verified all of Hammerspace's various sanity tests pass (this includes numerous pNFS and flexfiles tests).

Please review, I'm hopeful I've addressed any outstanding issues and that these changes worthy of being merged for v6.12.  If you see something, say something ;)

Changes since v11:
- The required localio specific changes in fs/nfsd/ are much simpler (thanks to the prelim patches that update common code to support the the localio case, fs/nfsd/localio.c in particular is now very lean)
- Improved the localio protocol to address NeilBrown's issue #1. Replaced GETUUID with UUID_IS_LOCAL RPC, which inverts protocol such that client generates a nonce (shortlived single-use UUID) and proceeds to verify the server sees it in nfs_common.
  - this eliminated the need to add 'struct nfsd_uuid' to nfsd_net
- Finished the RFC series NeilBrown started to introduce nfsd_file_acquire_local(), enables the use of a "fake" svc_rqst to be eliminated: https://marc.info/?l=linux-nfs&m=171980269529965&w=2
  (uses auth_domain as suggested, addresses NeilBrown's issue #2)
- rpcauth_map_clnt_to_svc_cred_local now uses userns of client and from_{kuid,kgid}_munged (hopefully addresses NeilBrown's issue #3)
- Updated nfs_local_call_write() to override_creds() with the cred used by the client to open the localio file.
- To avoid localio hitting writeback deadlock (same as is done for existing loopback NFSD support in nfsd_vfs_write() function): set PF_LOCAL_THROTTLE | PF_MEMALLOC_NOIO in nfs_local_call_write() and restore current->flags before return.
- Factored nfs_stat_to_errno and nfs4_stat_to_errno out to nfs_common to eliminate localio code creating yet another copy of them. (eliminates existing duplication between fs/nfs/nfs[23]xdr.c)
- Simplified Kconfig so that NFS_LOCALIO depends on NFS_FS and NFSD_LOCALIO depends on NFSD.
- Only support localio if UNIX Authentication (AUTH_UNIX) is used.
- Improved workqueue patch to not use wait_for_completion().
- Dropped 2 prelim fs/nfs/ patches that weren't actually needed.
- Updated localio.rst to reflect the various changes listed above, also added a new "FAQ" section from Trond (which was informed by an in-person discussion about localio that Trond had with Christoph).
- Fixed "nfsd: add nfsd_file_acquire_local()" commit to work with NFSv3 (had been testing with NFSv4.2 and the fact that NFSv3 regressed due to 'nfs_ver' not being properly initialized for non-LOCALIO callers was missed.
- Fixed issue Neil reported where "When using localio, if I open, read, don't close, then try to stop the server and umount the exported filesystem I get EBUSY for the umount."
  - fix by removing refcount on localio file (no longer cache open localio file in the client).
- Fixed nfsd tracepoints that were impacted by the possibility they'd be passed a NULL rqstp when using localio.
- Rebased on cel/nfsd-next (based on v6.11-rc4) to layer upon Neil's various changes that were originally motivated by LOCALIO, reduces footprint of this patchset.
- Exported nfsd_file interfaces needed to switch the nfs client's localio code over to using it.
- Switched the the nfs client's localio code over to using nfsd_file.

Thanks,
Mike

Mike Snitzer (13):
  nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
  nfs_common: factor out nfs4_errtbl and nfs4_stat_to_errno
  nfs: factor out {encode,decode}_opaque_fixed to nfs_xdr.h
  nfsd: fix nfsfh tracepoints to properly handle NULL rqstp
  SUNRPC: remove call_allocate() BUG_ONs
  nfs_common: add NFS LOCALIO auxiliary protocol enablement
  nfsd: implement server support for NFS_LOCALIO_PROGRAM
  nfs: implement client support for NFS_LOCALIO_PROGRAM
  nfs: add Documentation/filesystems/nfs/localio.rst
  nfsd: use GC for nfsd_file returned by nfsd_file_acquire_local
  nfs_common: expose localio's required nfsd symbols to nfs client
  nfs: push localio nfsd_file_put call out to client
  nfs: switch client to use nfsd_file for localio

NeilBrown (3):
  nfsd: factor out __fh_verify to allow NULL rqstp to be passed
  nfsd: add nfsd_file_acquire_local()
  SUNRPC: replace program list with program array

Trond Myklebust (4):
  nfs: enable localio for non-pNFS IO
  pnfs/flexfiles: enable localio support
  nfs/localio: use dedicated workqueues for filesystem read and write
  nfs: add FAQ section to Documentation/filesystems/nfs/localio.rst

Weston Andros Adamson (4):
  SUNRPC: add rpcauth_map_clnt_to_svc_cred_local
  nfsd: add localio support
  nfs: pass struct file to nfs_init_pgio and nfs_init_commit
  nfs: add localio support

 Documentation/filesystems/nfs/localio.rst | 255 +++++++ fs/Kconfig                                |   3 + fs/nfs/Kconfig                            |  15 + fs/nfs/Makefile                           |   1 + fs/nfs/client.c                           |  15 +- fs/nfs/filelayout/filelayout.c            |   6 +- fs/nfs/flexfilelayout/flexfilelayout.c    | 142 +++- fs/nfs/flexfilelayout/flexfilelayout.h    |   2 + fs/nfs/flexfilelayout/flexfilelayoutdev.c |   6 + fs/nfs/inode.c                            |  57 +- fs/nfs/internal.h                         |  61 +-

 fs/nfs/localio.c                          | 784 ++++++++++++++++++++++
 fs/nfs/nfs2xdr.c                          |  70 +-
 fs/nfs/nfs3xdr.c                          | 108 +--
 fs/nfs/nfs4xdr.c                          |  84 +--
 fs/nfs/nfstrace.h                         |  61 ++
 fs/nfs/pagelist.c                         |  16 +-
 fs/nfs/pnfs_nfs.c                         |   2 +-

 fs/nfs/write.c                            |  12 +- fs/nfs_common/Makefile                    |   5 + fs/nfs_common/common.c                    | 134 ++++ fs/nfs_common/nfslocalio.c                | 194 ++++++ fs/nfsd/Kconfig                           |  15 + fs/nfsd/Makefile                          |   1 + fs/nfsd/export.c                          |   8 +- fs/nfsd/filecache.c                       |  90 ++- fs/nfsd/filecache.h                       |   5 + fs/nfsd/localio.c                         | 183 +++++ fs/nfsd/netns.h                           |   8 +- fs/nfsd/nfsctl.c                          |   2 +- fs/nfsd/nfsd.h                            |   6 +- fs/nfsd/nfsfh.c                           | 114 ++-- fs/nfsd/nfsfh.h                           |   5 + fs/nfsd/nfssvc.c                          | 100 ++- fs/nfsd/trace.h                           |  39 +- fs/nfsd/vfs.h                             |  10 + include/linux/nfs.h                       |   9 + include/linux/nfs_common.h                |  17 + include/linux/nfs_fs_sb.h                 |  10 + include/linux/nfs_xdr.h                   |  20 +- include/linux/nfslocalio.h                |  56 ++ include/linux/sunrpc/auth.h               |   4 + include/linux/sunrpc/svc.h                |   7 +- net/sunrpc/auth.c                         |  22 + net/sunrpc/clnt.c                         |   6 - net/sunrpc/svc.c                          |  68 +- net/sunrpc/svc_xprt.c                     |   2 +- net/sunrpc/svcauth_unix.c                 |   3 +-

Quoted 9 lines
 48 files changed, 2428 insertions(+), 415 deletions(-)

 create mode 100644 Documentation/filesystems/nfs/localio.rst create mode 100644 fs/nfs/localio.c
 create mode 100644 fs/nfs_common/common.c
 create mode 100644 fs/nfs_common/nfslocalio.c create mode 100644 fs/nfsd/localio.c
 create mode 100644 include/linux/nfs_common.h create mode 100644 include/linux/nfslocalio.h

This looks much improved. I didn't see anything that stood out at me as being problematic code-wise with the design or final product, aside from a couple of minor things.

But...this patchset is hard to review. My main gripe is that there is a lot of "churn" -- places where you add code, just to rework it in a new way in a later patch.

Quoted 5 lines

For instance, the nfsd_file conversion should be integrated into the new infrastructure much earlier instead of having a patch that later does that conversion. Those kinds extraneous changes make this much harder to review than it would be if this were done in a way that avoided that churn.

I thought about folding the nfsd_file changes in from the beginning but stopped short of doing so because the churn you speak of really only smacks you in the face when reviewing the fs/nfs/flexfilelayout/flexfilelayout.c changes (which happen to be featured prominently at the top of patch 23).

Quoted 4 lines

Otherwise, there really is very little change/churn from the nfsd_file switchover.  And the general statement that the series hard to review over needless churn seems strong.  Only place is with nfsd_file.

That's the part I focused on initially. I only did some cursory looks at the client-side bits.

To give you an example: I was confused as to why you were passing back a struct file in nfsd_open_local_fh in patch #9, and it wasn't until I got into the later part of the series that I figured out that you changed that to a struct nfsd_file pointer later (which makes sense). I wouldn't have had to do that if the rework around nfsd_file had been done from the get-go.

Quoted 3 lines

Anyway, I can rebase to fold the nfsd_file changes in (so that its done that way from the start) if you and others want it done that way. Please just have one last think about it and let me know.

I think that would be best. The historical commits that show the interim stages of development just aren't terribly useful when we're merging brand new functionality like this.

Signature · 1 line
Jeff Layton <[email protected]>
maintainer
#49 lore raw
In reply to Mike Snitzer
Quoted 10 lines · Mike Snitzer

Hey Jeff,

Quoted 4 lines · Jeff Layton

This looks much improved. I didn't see anything that stood out at me as being problematic code-wise with the design or final product, aside from a couple of minor things.

BTW, thanks for this feedback, much appreciated!

You're very welcome. Thanks for doing this work!

Quoted 14 lines
Quoted 9 lines

But...this patchset is hard to review. My main gripe is that there is a lot of "churn" -- places where you add code, just to rework it in a new way in a later patch.

For instance, the nfsd_file conversion should be integrated into the new infrastructure much earlier instead of having a patch that later does that conversion. Those kinds extraneous changes make this much harder to review than it would be if this were done in a way that avoided that churn.

I think I've addressed all your v12 review comments from earlier today.  I've pushed the new series out to my git repo here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Quoted 8 lines

No code changes, purely a bunch of rebasing to clean up like you suggested.  Only outstanding thing is the nfsd tracepoints handling of NULL rqstp (would like to get Chuck's expert feedback on that point).

Please feel free to have a look at my branch while I wait for any other v12 feedback from Chuck and/or others before I send out v13. I'd like to avoid spamming the list like I did in the past ;)

That looks much cleaner than the last posting. Once you post the new version I'll give a more thorough review, but I don't see any major problems at first glance.

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

Re: [PATCH v12 05/24] nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

In reply to Mike Snitzer
Quoted 122 lines · Mike Snitzer
Quoted 105 lines · Jeff Layton
Quoted 104 lines · Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL.  Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++-------- fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------

 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +0 -0
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,


  error = nfserr_stale;
  if (IS_ERR(exp)) {

fs/nfsd/nfsfh.c +0 -2
-		if (rqstp)
-			trace_nfsd_set_fh_dentry_badexport(rqstp,

fhp, PTR_ERR(exp));

fs/nfsd/nfsfh.c +1 -0
+		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp,

PTR_ERR(exp));

  if (PTR_ERR(exp) == -ENOENT)
  return error;

fs/nfsd/nfsfh.c +0 -2
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
  						data_left,
 fileid_type, 0,
  						nfsd_acceptable,
 exp);
  		if (IS_ERR_OR_NULL(dentry)) {
-			if (rqstp)
-

trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,

fs/nfsd/nfsfh.c +1 -0
+			trace_nfsd_set_fh_dentry_badhandle(rqstp,

fhp,
  dentry ?  PTR_ERR(dentry) :
-ESTALE);
  switch (PTR_ERR(dentry)) {
  case -ENOMEM:

fs/nfsd/nfsfh.c +0 -0
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	dentry = fhp->fh_dentry;
  	exp = fhp->fh_export;

fs/nfsd/nfsfh.c +1 -2
-	if (rqstp)
-		trace_nfsd_fh_verify(rqstp, fhp, type, access);
+	trace_nfsd_fh_verify(net, rqstp, fhp, type, access);


  /*
  * We still have to do all these permission checks, even when

fs/nfsd/nfsfh.c +0 -0
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	/* Finally, check access permissions. */
  	error = nfsd_permission(cred, exp, dentry, access);

 out:

fs/nfsd/nfsfh.c +0 -2
-	if (rqstp)
-		trace_nfsd_fh_verify_err(rqstp, fhp, type, access,

error);

fs/nfsd/nfsfh.c +1 -0
+	trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access,

error);
  if (error == nfserr_stale)
  nfsd_stats_fh_stale_inc(nn, exp);
  return error;

fs/nfsd/trace.h +0 -0
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,


 TRACE_EVENT(nfsd_fh_verify,
  TP_PROTO(

fs/nfsd/trace.h +1 -0
+		const struct net *net,

  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access
  ),

fs/nfsd/trace.h +1 -1
-	TP_ARGS(rqstp, fhp, type, access),
+	TP_ARGS(net, rqstp, fhp, type, access),

  TP_STRUCT__entry(
  __field(unsigned int, netns_ino) __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)

fs/nfsd/trace.h +0 -0
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
  		__field(unsigned long, access)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +0 -2
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +0 -2
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +3 -2
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

fs/nfsd/trace.h +1 -0
+			__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 8 lines

fs/nfsd/trace.h

Quoted 4 lines
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_remotelen);

fs/nfsd/trace.h +1 -0
+		}

Does this need an else branch to set these values to something when rqstp is NULL, or are we guaranteed that they are already zeroed out when they aren't assigned?

I'm not sure. It isn't immediately clear what is actually using these.

But I did just notice an inconsistency, these entry members are defined:

                __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
                __sockaddr(client, rqstp->rq_xprt->xpt_remotelen)
Quoted 6 lines

Yet they go on to use rqstp->rq_xprt->xpt_locallen and rqstp->rq_xprt->xpt_remotelen respectively.

Chuck, would welcome your feedback on how to properly fix these tracepoints to handle rqstp being NULL. And the inconsistency I just noted is something extra.

First, a comment about patch ordering: I think you can preserve attribution but make these a little easier to digest if you reverse 4/ and 5/. Fix the problem before it becomes a problem, as it were.

As a general remark, I would prefer to retain the trace points and even the address information in the local I/O case: the client address is an important part of the decision to permit or deny access to the FH in question. The issue is how to make that happen...

The __sockaddr() macros I think will trigger an oops if rqstp == NULL. The second argument determines the size of a variable-length trace field IIRC. One way to avoid that is to use a fixed size field for the addresses (big enough to store an IPv6 address? or an abstract address? those can get pretty big)

I need to study 4/ more closely; perhaps it is doing too much in a single patch. (ie, the code ends up in a better place, but the details of the transition are obscured by being lumped together into one patch).

So, can you or Neil answer: what would appear as the client address for local I/O ?

Signature · 1 line
Chuck Lever
#50 lore raw
In reply to Mike Snitzer
Quoted 28 lines · Mike Snitzer

Hey Jeff,

Quoted 4 lines · Jeff Layton

This looks much improved. I didn't see anything that stood out at me as being problematic code-wise with the design or final product, aside from a couple of minor things.

BTW, thanks for this feedback, much appreciated!

Quoted 9 lines

But...this patchset is hard to review. My main gripe is that there is a lot of "churn" -- places where you add code, just to rework it in a new way in a later patch.

For instance, the nfsd_file conversion should be integrated into the new infrastructure much earlier instead of having a patch that later does that conversion. Those kinds extraneous changes make this much harder to review than it would be if this were done in a way that avoided that churn.

I think I've addressed all your v12 review comments from earlier today. I've pushed the new series out to my git repo here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Quoted 7 lines

No code changes, purely a bunch of rebasing to clean up like you suggested. Only outstanding thing is the nfsd tracepoints handling of NULL rqstp (would like to get Chuck's expert feedback on that point).

Please feel free to have a look at my branch while I wait for any other v12 feedback from Chuck and/or others before I send out v13. I'd like to avoid spamming the list like I did in the past ;)

Was looking for an appropriate place to reply with this question, but didn't see one. So here goes:

One of the issues Neil mentioned was dealing with the case where a server file system is unexported and perhaps unmounted while there is LOCALIO ongoing.

Can you describe what the client and application see in this case? Do you have test cases for this scenario? Obviously we don't want a crash or deadlock, but I would guess the client/app should behave just like remote NFSv3 -- there, the server returns ESTALE on a READ or WRITE, and read(2) or write(2) on the client returns EIO. Ie, behavior should be deterministic.

--
Chuck Lever

#51 lore raw
Quoted 36 lines · Chuck Lever III
Quoted 28 lines · Mike Snitzer

Hey Jeff,

Quoted 4 lines · Jeff Layton

This looks much improved. I didn't see anything that stood out at me as being problematic code-wise with the design or final product, aside from a couple of minor things.

BTW, thanks for this feedback, much appreciated!

Quoted 9 lines

But...this patchset is hard to review. My main gripe is that there is a lot of "churn" -- places where you add code, just to rework it in a new way in a later patch.

For instance, the nfsd_file conversion should be integrated into the new infrastructure much earlier instead of having a patch that later does that conversion. Those kinds extraneous changes make this much harder to review than it would be if this were done in a way that avoided that churn.

I think I've addressed all your v12 review comments from earlier today. I've pushed the new series out to my git repo here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=nfs-localio-for-next

Quoted 7 lines

No code changes, purely a bunch of rebasing to clean up like you suggested. Only outstanding thing is the nfsd tracepoints handling of NULL rqstp (would like to get Chuck's expert feedback on that point).

Please feel free to have a look at my branch while I wait for any other v12 feedback from Chuck and/or others before I send out v13. I'd like to avoid spamming the list like I did in the past ;)

Quoted 6 lines

Was looking for an appropriate place to reply with this question, but didn't see one. So here goes:

One of the issues Neil mentioned was dealing with the case where a server file system is unexported and perhaps unmounted while there is LOCALIO ongoing.

Yes, that was a problem with v11 and prior because the client was holding a reference on the nfsd_file's underlying file (nf->nf_file) for the duration of the open (within nfs_open_ctx). That client-side caching of the open file was done for performance reasons, but with client-side use of nfsd_file we can claw back ~50% of that performance by using the filecache's GC (patch 23 in this series details the comparative performance numbers I'm talking about).

So I removed that extra client-side reference entirely, and just rely on nfsd's filecache to hold the file open by nfsd_file_acquire_local() taking reference on nfsd_file (so server does the normal thing on shutdown where it walks the filecache's hlist during shutdown).

Quoted 2 lines

Can you describe what the client and application see in this case? Do you have test cases for this scenario?

No, I've been testing it manually:

Client is using localio for /mnt/test2:

# python3
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

f = open("/mnt/test2/testfile", encoding = "ISO-8859-1") s = f.read(8)

Server (happens to be running in container) is shutdown:

podman exec -ti nfs_12 /bin/bash [root@6baf567b559a /]# systemctl stop nfs-server.service [root@6baf567b559a /]# umount /export/cvol_12_0

(even easier to test without server in a container)

Quoted 4 lines

Obviously we don't want a crash or deadlock, but I would guess the client/app should behave just like remote NFSv3 -- there, the server returns ESTALE on a READ or WRITE, and read(2) or write(2) on the client returns EIO. Ie, behavior should be deterministic.

Yes, that is how it works: exactly like remote NFSv3.

#9 lore raw

Re: [PATCH v12 05/24] nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

In reply to Chuck Lever
Quoted 146 lines · Chuck Lever
Quoted 122 lines · Mike Snitzer
Quoted 105 lines · Jeff Layton
Quoted 104 lines · Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL.  Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++-------- fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------

 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +0 -0
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,


  error = nfserr_stale;
  if (IS_ERR(exp)) {

fs/nfsd/nfsfh.c +0 -2
-		if (rqstp)
-			trace_nfsd_set_fh_dentry_badexport(rqstp,

fhp, PTR_ERR(exp));

fs/nfsd/nfsfh.c +1 -0
+		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp,

PTR_ERR(exp));

  if (PTR_ERR(exp) == -ENOENT)
  return error;

fs/nfsd/nfsfh.c +0 -2
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
  						data_left,
 fileid_type, 0,
  						nfsd_acceptable,
 exp);
  		if (IS_ERR_OR_NULL(dentry)) {
-			if (rqstp)
-

trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,

fs/nfsd/nfsfh.c +1 -0
+			trace_nfsd_set_fh_dentry_badhandle(rqstp,

fhp,
  dentry ?  PTR_ERR(dentry) :
-ESTALE);
  switch (PTR_ERR(dentry)) {
  case -ENOMEM:

fs/nfsd/nfsfh.c +0 -0
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	dentry = fhp->fh_dentry;
  	exp = fhp->fh_export;

fs/nfsd/nfsfh.c +1 -2
-	if (rqstp)
-		trace_nfsd_fh_verify(rqstp, fhp, type, access);
+	trace_nfsd_fh_verify(net, rqstp, fhp, type, access);


  /*
  * We still have to do all these permission checks, even when

fs/nfsd/nfsfh.c +0 -0
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	/* Finally, check access permissions. */
  	error = nfsd_permission(cred, exp, dentry, access);

 out:

fs/nfsd/nfsfh.c +0 -2
-	if (rqstp)
-		trace_nfsd_fh_verify_err(rqstp, fhp, type, access,

error);

fs/nfsd/nfsfh.c +1 -0
+	trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access,

error);
  if (error == nfserr_stale)
  nfsd_stats_fh_stale_inc(nn, exp);
  return error;

fs/nfsd/trace.h +0 -0
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,


 TRACE_EVENT(nfsd_fh_verify,
  TP_PROTO(

fs/nfsd/trace.h +1 -0
+		const struct net *net,

  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access
  ),

fs/nfsd/trace.h +1 -1
-	TP_ARGS(rqstp, fhp, type, access),
+	TP_ARGS(net, rqstp, fhp, type, access),

  TP_STRUCT__entry(
  __field(unsigned int, netns_ino) __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)

fs/nfsd/trace.h +0 -0
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
  		__field(unsigned long, access)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +0 -2
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +0 -2
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +3 -2
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

fs/nfsd/trace.h +1 -0
+			__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 8 lines

fs/nfsd/trace.h

Quoted 4 lines
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_remotelen);

fs/nfsd/trace.h +1 -0
+		}

Does this need an else branch to set these values to something when rqstp is NULL, or are we guaranteed that they are already zeroed out when they aren't assigned?

I'm not sure. It isn't immediately clear what is actually using these.

But I did just notice an inconsistency, these entry members are defined:

                __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
                __sockaddr(client, rqstp->rq_xprt->xpt_remotelen)
Quoted 6 lines

Yet they go on to use rqstp->rq_xprt->xpt_locallen and rqstp->rq_xprt->xpt_remotelen respectively.

Chuck, would welcome your feedback on how to properly fix these tracepoints to handle rqstp being NULL. And the inconsistency I just noted is something extra.

First, a comment about patch ordering: I think you can preserve attribution but make these a little easier to digest if you reverse 4/ and 5/. Fix the problem before it becomes a problem, as it were.

As a general remark, I would prefer to retain the trace points and even the address information in the local I/O case: the client address is an important part of the decision to permit or deny access to the FH in question. The issue is how to make that happen...

The __sockaddr() macros I think will trigger an oops if rqstp == NULL. The second argument determines the size of a variable-length trace field IIRC. One way to avoid that is to use a fixed size field for the addresses (big enough to store an IPv6 address? or an abstract address? those can get pretty big)

Quoted 7 lines

I need to study 4/ more closely; perhaps it is doing too much in a single patch. (ie, the code ends up in a better place, but the details of the transition are obscured by being lumped together into one patch).

So, can you or Neil answer: what would appear as the client address for local I/O ?

Before when there was the "fake" svc_rqst it was initialized with:

       /* Note: we're connecting to ourself, so source addr == peer addr */
       rqstp->rq_addrlen = rpc_peeraddr(rpc_clnt,
                       (struct sockaddr *)&rqstp->rq_addr,
                       sizeof(rqstp->rq_addr));

Anyway, as the code is also now: the rpc_clnt passed to nfsd_open_local_fh() will reflect the same address as the server.

My thinking was that for localio there doesn't need to be any explicit listing of the address info in the tracepoints (but that'd be more convincing if we at least logged localio by looking for and logging NFSD_MAY_LOCALIO in mayflags passed to nfsd_file_acquire_local).

But I agree it'd be nice to have tracepoints log matching 127.0.0.1 or ::1, etc -- just don't think it strictly necessary.

Open to whatever you think best.

Mike

maintainer
#10 lore raw

Re: [PATCH v12 05/24] nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

Quoted 170 lines · Mike Snitzer
Quoted 146 lines · Chuck Lever
Quoted 122 lines · Mike Snitzer
Quoted 105 lines · Jeff Layton
Quoted 104 lines · Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL.  Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++-------- fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------

 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +0 -0
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,


  error = nfserr_stale;
  if (IS_ERR(exp)) {

fs/nfsd/nfsfh.c +0 -2
-		if (rqstp)
-			trace_nfsd_set_fh_dentry_badexport(rqstp,

fhp, PTR_ERR(exp));

fs/nfsd/nfsfh.c +1 -0
+		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp,

PTR_ERR(exp));

  if (PTR_ERR(exp) == -ENOENT)
  return error;

fs/nfsd/nfsfh.c +0 -2
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
  						data_left,
 fileid_type, 0,
  						nfsd_acceptable,
 exp);
  		if (IS_ERR_OR_NULL(dentry)) {
-			if (rqstp)
-

trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,

fs/nfsd/nfsfh.c +1 -0
+			trace_nfsd_set_fh_dentry_badhandle(rqstp,

fhp,
  dentry ?  PTR_ERR(dentry) :
-ESTALE);
  switch (PTR_ERR(dentry)) {
  case -ENOMEM:

fs/nfsd/nfsfh.c +0 -0
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	dentry = fhp->fh_dentry;
  	exp = fhp->fh_export;

fs/nfsd/nfsfh.c +1 -2
-	if (rqstp)
-		trace_nfsd_fh_verify(rqstp, fhp, type, access);
+	trace_nfsd_fh_verify(net, rqstp, fhp, type, access);


  /*
  * We still have to do all these permission checks, even when

fs/nfsd/nfsfh.c +0 -0
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	/* Finally, check access permissions. */
  	error = nfsd_permission(cred, exp, dentry, access);

 out:

fs/nfsd/nfsfh.c +0 -2
-	if (rqstp)
-		trace_nfsd_fh_verify_err(rqstp, fhp, type, access,

error);

fs/nfsd/nfsfh.c +1 -0
+	trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access,

error);
  if (error == nfserr_stale)
  nfsd_stats_fh_stale_inc(nn, exp);
  return error;

fs/nfsd/trace.h +0 -0
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,


 TRACE_EVENT(nfsd_fh_verify,
  TP_PROTO(

fs/nfsd/trace.h +1 -0
+		const struct net *net,

  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access
  ),

fs/nfsd/trace.h +1 -1
-	TP_ARGS(rqstp, fhp, type, access),
+	TP_ARGS(net, rqstp, fhp, type, access),

  TP_STRUCT__entry(
  __field(unsigned int, netns_ino) __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)

fs/nfsd/trace.h +0 -0
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
  		__field(unsigned long, access)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +0 -2
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +0 -2
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +3 -2
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

fs/nfsd/trace.h +1 -0
+			__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 8 lines

fs/nfsd/trace.h

Quoted 4 lines
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_remotelen);

fs/nfsd/trace.h +1 -0
+		}

Does this need an else branch to set these values to something when rqstp is NULL, or are we guaranteed that they are already zeroed out when they aren't assigned?

I'm not sure. It isn't immediately clear what is actually using these.

But I did just notice an inconsistency, these entry members are defined:

                __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
                __sockaddr(client, rqstp->rq_xprt->xpt_remotelen)
Quoted 6 lines

Yet they go on to use rqstp->rq_xprt->xpt_locallen and rqstp->rq_xprt->xpt_remotelen respectively.

Chuck, would welcome your feedback on how to properly fix these tracepoints to handle rqstp being NULL. And the inconsistency I just noted is something extra.

First, a comment about patch ordering: I think you can preserve attribution but make these a little easier to digest if you reverse 4/ and 5/. Fix the problem before it becomes a problem, as it were.

As a general remark, I would prefer to retain the trace points and even the address information in the local I/O case: the client address is an important part of the decision to permit or deny access to the FH in question. The issue is how to make that happen...

The __sockaddr() macros I think will trigger an oops if rqstp == NULL. The second argument determines the size of a variable-length trace field IIRC. One way to avoid that is to use a fixed size field for the addresses (big enough to store an IPv6 address? or an abstract address? those can get pretty big)

Quoted 7 lines

I need to study 4/ more closely; perhaps it is doing too much in a single patch. (ie, the code ends up in a better place, but the details of the transition are obscured by being lumped together into one patch).

So, can you or Neil answer: what would appear as the client address for local I/O ?

Before when there was the "fake" svc_rqst it was initialized with:

       /* Note: we're connecting to ourself, so source addr == peer addr */
       rqstp->rq_addrlen = rpc_peeraddr(rpc_clnt,
                       (struct sockaddr *)&rqstp->rq_addr,
                       sizeof(rqstp->rq_addr));

Anyway, as the code is also now: the rpc_clnt passed to nfsd_open_local_fh() will reflect the same address as the server.

My thinking was that for localio there doesn't need to be any explicit listing of the address info in the tracepoints (but that'd be more convincing if we at least logged localio by looking for and logging NFSD_MAY_LOCALIO in mayflags passed to nfsd_file_acquire_local).

Quoted 5 lines

But I agree it'd be nice to have tracepoints log matching 127.0.0.1 or ::1, etc -- just don't think it strictly necessary.

Open to whatever you think best.

The client is likely to be coming from a different container in many cases and so won't be coming in via the loopback interface. Presenting a loopback address in that case seems wrong.

What would be ideal IMO would be to still display the addresses from the rpc_clnt and just display a flag or something that shows that this is a localio request. Having to pass that as an additional arg to __fh_verify would be pretty ugly though (and may be a layering violation).

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

Re: [PATCH v12 05/24] nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

Quoted 174 lines · Jeff Layton
Quoted 173 lines · Mike Snitzer
Quoted 146 lines · Chuck Lever
Quoted 122 lines · Mike Snitzer
Quoted 105 lines · Jeff Layton
Quoted 104 lines · Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL.  Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++-------- fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------

 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +0 -0
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,


  error = nfserr_stale;
  if (IS_ERR(exp)) {

fs/nfsd/nfsfh.c +0 -2
-		if (rqstp)
-			trace_nfsd_set_fh_dentry_badexport(rqstp,

fhp, PTR_ERR(exp));

fs/nfsd/nfsfh.c +1 -0
+		trace_nfsd_set_fh_dentry_badexport(rqstp, fhp,

PTR_ERR(exp));

  if (PTR_ERR(exp) == -ENOENT)
  return error;

fs/nfsd/nfsfh.c +0 -2
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
  						data_left,
 fileid_type, 0,
  						nfsd_acceptable,
 exp);
  		if (IS_ERR_OR_NULL(dentry)) {
-			if (rqstp)
-

trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,

fs/nfsd/nfsfh.c +1 -0
+			trace_nfsd_set_fh_dentry_badhandle(rqstp,

fhp,
  dentry ?  PTR_ERR(dentry) :
-ESTALE);
  switch (PTR_ERR(dentry)) {
  case -ENOMEM:

fs/nfsd/nfsfh.c +0 -0
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	dentry = fhp->fh_dentry;
  	exp = fhp->fh_export;

fs/nfsd/nfsfh.c +1 -2
-	if (rqstp)
-		trace_nfsd_fh_verify(rqstp, fhp, type, access);
+	trace_nfsd_fh_verify(net, rqstp, fhp, type, access);


  /*
  * We still have to do all these permission checks, even when

fs/nfsd/nfsfh.c +0 -0
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
  	/* Finally, check access permissions. */
  	error = nfsd_permission(cred, exp, dentry, access);

 out:

fs/nfsd/nfsfh.c +0 -2
-	if (rqstp)
-		trace_nfsd_fh_verify_err(rqstp, fhp, type, access,

error);

fs/nfsd/nfsfh.c +1 -0
+	trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access,

error);
  if (error == nfserr_stale)
  nfsd_stats_fh_stale_inc(nn, exp);
  return error;

fs/nfsd/trace.h +0 -0
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,


 TRACE_EVENT(nfsd_fh_verify,
  TP_PROTO(

fs/nfsd/trace.h +1 -0
+		const struct net *net,

  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access
  ),

fs/nfsd/trace.h +1 -1
-	TP_ARGS(rqstp, fhp, type, access),
+	TP_ARGS(net, rqstp, fhp, type, access),

  TP_STRUCT__entry(
  __field(unsigned int, netns_ino) __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)

fs/nfsd/trace.h +0 -0
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
  		__field(unsigned long, access)
  	),

  TP_fast_assign(

fs/nfsd/trace.h +0 -2
-		__entry->netns_ino = SVC_NET(rqstp)->ns.inum;
-		__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +0 -2
-		       rqstp->rq_xprt->xpt_locallen);
-		__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +3 -2
-				  rqstp->rq_xprt->xpt_remotelen);
-		__entry->xid = be32_to_cpu(rqstp->rq_xid);
+		__entry->netns_ino = net->ns.inum;
+		if (rqstp) {
+			__assign_sockaddr(server, &rqstp->rq_xprt-
Quoted 1 line

xpt_local,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

fs/nfsd/trace.h +1 -0
+			__assign_sockaddr(client, &rqstp->rq_xprt-
Quoted 8 lines

fs/nfsd/trace.h

Quoted 4 lines
Quoted 1 line

xpt_remote,

fs/nfsd/trace.h +1 -0
+					  rqstp->rq_xprt-
Quoted 1 line

xpt_remotelen);

fs/nfsd/trace.h +1 -0
+		}

Does this need an else branch to set these values to something when rqstp is NULL, or are we guaranteed that they are already zeroed out when they aren't assigned?

I'm not sure. It isn't immediately clear what is actually using these.

But I did just notice an inconsistency, these entry members are defined:

                __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
                __sockaddr(client, rqstp->rq_xprt->xpt_remotelen)
Quoted 6 lines

Yet they go on to use rqstp->rq_xprt->xpt_locallen and rqstp->rq_xprt->xpt_remotelen respectively.

Chuck, would welcome your feedback on how to properly fix these tracepoints to handle rqstp being NULL. And the inconsistency I just noted is something extra.

First, a comment about patch ordering: I think you can preserve attribution but make these a little easier to digest if you reverse 4/ and 5/. Fix the problem before it becomes a problem, as it were.

As a general remark, I would prefer to retain the trace points and even the address information in the local I/O case: the client address is an important part of the decision to permit or deny access to the FH in question. The issue is how to make that happen...

The __sockaddr() macros I think will trigger an oops if rqstp == NULL. The second argument determines the size of a variable-length trace field IIRC. One way to avoid that is to use a fixed size field for the addresses (big enough to store an IPv6 address? or an abstract address? those can get pretty big)

Quoted 7 lines

I need to study 4/ more closely; perhaps it is doing too much in a single patch. (ie, the code ends up in a better place, but the details of the transition are obscured by being lumped together into one patch).

So, can you or Neil answer: what would appear as the client address for local I/O ?

Before when there was the "fake" svc_rqst it was initialized with:

       /* Note: we're connecting to ourself, so source addr == peer addr */
       rqstp->rq_addrlen = rpc_peeraddr(rpc_clnt,
                       (struct sockaddr *)&rqstp->rq_addr,
                       sizeof(rqstp->rq_addr));

Anyway, as the code is also now: the rpc_clnt passed to nfsd_open_local_fh() will reflect the same address as the server.

My thinking was that for localio there doesn't need to be any explicit listing of the address info in the tracepoints (but that'd be more convincing if we at least logged localio by looking for and logging NFSD_MAY_LOCALIO in mayflags passed to nfsd_file_acquire_local).

But I agree it'd be nice to have tracepoints log matching 127.0.0.1 or ::1, etc -- just don't think it strictly necessary.

Quoted 6 lines
Quoted 2 lines

Open to whatever you think best.

The client is likely to be coming from a different container in many cases and so won't be coming in via the loopback interface. Presenting a loopback address in that case seems wrong.

Right, wasn't suggesting to always display loopback interface, was saying ideal to display reality. There isn't anything special in the rpc_clnt address. The localio RPC client is connecting to the server using the same rpcclient as NFS (cloned from that used for NFS).

Quoted 5 lines

What would be ideal IMO would be to still display the addresses from the rpc_clnt and just display a flag or something that shows that this is a localio request. Having to pass that as an additional arg to __fh_verify would be pretty ugly though (and may be a layering violation).

I agree. But yeah, I don't have a sense for how to do this cleanly.

Pass rpc_clnt in and only use it for address if mayflags has NFSD_MAY_LOCALIO set _and_ rqstop is NULL?

#12 lore raw

Re: [PATCH v12 05/24] nfsd: fix nfsfh tracepoints to properly handle NULL rqstp

Quoted 163 lines · Mike Snitzer
Quoted 158 lines · Jeff Layton
Quoted 157 lines · Mike Snitzer
Quoted 146 lines · Chuck Lever
Quoted 122 lines · Mike Snitzer
Quoted 105 lines · Jeff Layton
Quoted 104 lines · Mike Snitzer

Fixes stop-gap used in previous commit where caller avoided using tracepoint if rqstp is NULL. Instead, have each tracepoint avoid dereferencing NULL rqstp.

---
 fs/nfsd/nfsfh.c | 12 ++++--------
 fs/nfsd/trace.h | 36 +++++++++++++++++++++---------------
 2 files changed, 25 insertions(+), 23 deletions(-)
fs/nfsd/nfsfh.c +1 -2
index 19e173187ab9..bae727e65214 100644
@@ -195,8 +195,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
 
  error = nfserr_stale;
  if (IS_ERR(exp)) {
- if (rqstp)
- trace_nfsd_set_fh_dentry_badexport(rqstp,
 fhp, PTR_ERR(exp));
+ trace_nfsd_set_fh_dentry_badexport(rqstp, fhp,
 PTR_ERR(exp));

if (PTR_ERR(exp) == -ENOENT)
return error;

fs/nfsd/nfsfh.c +0 -2
@@ -244,8 +243,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst
 *rqstp, struct net *net,
  data_left,
 fileid_type, 0,
  nfsd_acceptable,
 exp);
  if (IS_ERR_OR_NULL(dentry)) {
- if (rqstp)
-

trace_nfsd_set_fh_dentry_badhandle(rqstp, fhp,
+ trace_nfsd_set_fh_dentry_badhandle(rqstp,
fhp,
dentry ? PTR_ERR(dentry) :

fs/nfsd/nfsfh.c +1 -3
-ESTALE);
  switch (PTR_ERR(dentry)) {
  case -ENOMEM:
@@ -321,8 +319,7 @@ __fh_verify(struct svc_rqst *rqstp,
  dentry = fhp->fh_dentry;
  exp = fhp->fh_export;
 
- if (rqstp)
- trace_nfsd_fh_verify(rqstp, fhp, type, access);
+ trace_nfsd_fh_verify(net, rqstp, fhp, type, access);
 
  /*
   * We still have to do all these permission checks, even

when

fs/nfsd/nfsfh.c +1 -2
@@ -376,8 +373,7 @@ __fh_verify(struct svc_rqst *rqstp,
  /* Finally, check access permissions. */
  error = nfsd_permission(cred, exp, dentry, access);
 out:
- if (rqstp)
- trace_nfsd_fh_verify_err(rqstp, fhp, type, access,
 error);
+ trace_nfsd_fh_verify_err(net, rqstp, fhp, type, access,
 error);
  if (error == nfserr_stale)
  nfsd_stats_fh_stale_inc(nn, exp);
  return error;
fs/nfsd/trace.h +6 -7
index 77bbd23aa150..d49b3c1e3ba9 100644
@@ -195,12 +195,13 @@ TRACE_EVENT(nfsd_compound_encode_err,
 
 TRACE_EVENT(nfsd_fh_verify,
  TP_PROTO(
+ const struct net *net,
  const struct svc_rqst *rqstp,
  const struct svc_fh *fhp,
  umode_t type,
  int access
  ),
- TP_ARGS(rqstp, fhp, type, access),
+ TP_ARGS(net, rqstp, fhp, type, access),
  TP_STRUCT__entry(
  __field(unsigned int, netns_ino)
  __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
@@ -212,12 +213,14 @@ TRACE_EVENT(nfsd_fh_verify,
  __field(unsigned long, access)
  ),
  TP_fast_assign(
- __entry->netns_ino = SVC_NET(rqstp)->ns.inum;
- __assign_sockaddr(server, &rqstp->rq_xprt-
 > xpt_local,
-        rqstp->rq_xprt->xpt_locallen);
- __assign_sockaddr(client, &rqstp->rq_xprt-
 > xpt_remote,
-   rqstp->rq_xprt->xpt_remotelen);
- __entry->xid = be32_to_cpu(rqstp->rq_xid);
+ __entry->netns_ino = net->ns.inum;
+ if (rqstp) {
+ __assign_sockaddr(server, &rqstp->rq_xprt-
 > xpt_local,
+   rqstp->rq_xprt-
Quoted 1 line

xpt_locallen);

+ __assign_sockaddr(client, &rqstp->rq_xprt-

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

xpt_remote,

+ rqstp->rq_xprt-

Quoted 1 line

xpt_remotelen);

+ }

Does this need an else branch to set these values to something when rqstp is NULL, or are we guaranteed that they are already zeroed out when they aren't assigned?

I'm not sure. It isn't immediately clear what is actually using these.

But I did just notice an inconsistency, these entry members are defined:

               __sockaddr(server, rqstp->rq_xprt->xpt_remotelen)
               __sockaddr(client, rqstp->rq_xprt->xpt_remotelen)
Quoted 6 lines

Yet they go on to use rqstp->rq_xprt->xpt_locallen and rqstp->rq_xprt->xpt_remotelen respectively.

Chuck, would welcome your feedback on how to properly fix these tracepoints to handle rqstp being NULL. And the inconsistency I just noted is something extra.

First, a comment about patch ordering: I think you can preserve attribution but make these a little easier to digest if you reverse 4/ and 5/. Fix the problem before it becomes a problem, as it were.

As a general remark, I would prefer to retain the trace points and even the address information in the local I/O case: the client address is an important part of the decision to permit or deny access to the FH in question. The issue is how to make that happen...

The __sockaddr() macros I think will trigger an oops if rqstp == NULL. The second argument determines the size of a variable-length trace field IIRC. One way to avoid that is to use a fixed size field for the addresses (big enough to store an IPv6 address? or an abstract address? those can get pretty big)

Quoted 7 lines

I need to study 4/ more closely; perhaps it is doing too much in a single patch. (ie, the code ends up in a better place, but the details of the transition are obscured by being lumped together into one patch).

So, can you or Neil answer: what would appear as the client address for local I/O ?

Before when there was the "fake" svc_rqst it was initialized with:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
      /* Note: we're connecting to ourself, so source addr == peer addr */
      rqstp->rq_addrlen = rpc_peeraddr(rpc_clnt,
                      (struct sockaddr *)&rqstp->rq_addr,
                      sizeof(rqstp->rq_addr));

Anyway, as the code is also now: the rpc_clnt passed to nfsd_open_local_fh() will reflect the same address as the server.

I agree it should be the client's actual address that is recorded in nfsd_open_local_fh() and later reported by trace points or other instrumentation.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

My thinking was that for localio there doesn't need to be any explicit listing of the address info in the tracepoints (but that'd be more convincing if we at least logged localio by looking for and logging NFSD_MAY_LOCALIO in mayflags passed to nfsd_file_acquire_local).

But I agree it'd be nice to have tracepoints log matching 127.0.0.1 or ::1, etc -- just don't think it strictly necessary.

The usual usage scenario for the IP address in these particular trace points is to troubleshoot incorrect security policy settings (ie, export options based on client IP address).

I'm not exactly clear on how export options apply to LOCALIO open requests -- that's the main focus of the security-related review I plan to do.

(Similarity to remote NFSv3 behavior, as described in your other email reply, is indeed the preferred model, IMO).

Quoted 17 lines
Quoted 6 lines
Quoted 2 lines

Open to whatever you think best.

The client is likely to be coming from a different container in many cases and so won't be coming in via the loopback interface. Presenting a loopback address in that case seems wrong.

Right, wasn't suggesting to always display loopback interface, was saying ideal to display reality. There isn't anything special in the rpc_clnt address. The localio RPC client is connecting to the server using the same rpcclient as NFS (cloned from that used for NFS).

Quoted 5 lines

What would be ideal IMO would be to still display the addresses from the rpc_clnt and just display a flag or something that shows that this is a localio request. Having to pass that as an additional arg to __fh_verify would be pretty ugly though (and may be a layering violation).

NFSD_MAY_LOCALIO might be set only for LOCALIO opens. I don't think it is today, but that could be one way to indicate the difference in callers.

Quoted 4 lines

I agree. But yeah, I don't have a sense for how to do this cleanly.

Pass rpc_clnt in and only use it for address if mayflags has NFSD_MAY_LOCALIO set _and_ rqstop is NULL?

Will have a look, but I bet Neil might be the best person to propose an initial design.

--
Chuck Lever