Skip to contentSkip to conversation

Fixes for the NFS automounter

PATCH In review Trond Myklebust 3 participants 9 messages Aug 4, 2025 – Aug 24, 2025

Subsystems (2)
lore
Share & tools
lore

Trond Myklebust

author maintainer
#0 lore raw

cover Fixes for the NFS automounter

From: Trond Myklebust <[email protected]>

This series addresses 2 sets of issues with the NFS automount functionality:

1. Capabilities are being inherited from the parent directory instead of assuming that the subdirectory may have different properties than the parent. This is particularly problematic when the parent is a referral.
2. We appear to be repeating some operations unnecessarily when traversing a submount point.

Trond Myklebust (2):
NFS: Fix the setting of capabilities when automounting a new
filesystem
NFSv4: Remove duplicate lookups, capability probes and fsinfo calls

 fs/nfs/client.c      | 44 +++++++++++++++++++++-
 fs/nfs/internal.h    |  2 +-
 fs/nfs/nfs4_fs.h     |  5 ++-
 fs/nfs/nfs4client.c  | 20 +---------
 fs/nfs/nfs4getroot.c | 14 +++----
 fs/nfs/nfs4proc.c    | 89 ++++++++++++++++++++------------------------
 6 files changed, 93 insertions(+), 81 deletions(-)
Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH 1/2 NFS: Fix the setting of capabilities when automounting a new filesystem

From: Trond Myklebust <[email protected]>

Capabilities cannot be inherited when we cross into a new filesystem. They need to be reset to the minimal defaults, and then probed for again.

Fixes 54ceac451598 ("NFS: Share NFS superblocks per-protocol per-server per-FSID")
---
 fs/nfs/client.c     | 44 ++++++++++++++++++++++++++++++++++++++++++--
 fs/nfs/internal.h   |  2 +-
 fs/nfs/nfs4client.c | 20 +-------------------
 fs/nfs/nfs4proc.c   |  2 +-
 4 files changed, 45 insertions(+), 23 deletions(-)
fs/nfs/client.c +42 -2
index e13eb429b8b5..8fb4a950dd55 100644
@@ -682,6 +682,44 @@ struct nfs_client *nfs_init_client(struct nfs_client *clp,
 }
 EXPORT_SYMBOL_GPL(nfs_init_client);
 
+static void nfs4_server_set_init_caps(struct nfs_server *server)
+{
+#if IS_ENABLED(CONFIG_NFS_V4)
+	/* Set the basic capabilities */
+	server->caps = server->nfs_client->cl_mvops->init_caps;
+	if (server->flags & NFS_MOUNT_NORDIRPLUS)
+		server->caps &= ~NFS_CAP_READDIRPLUS;
+	if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA)
+		server->caps &= ~NFS_CAP_READ_PLUS;
+
+	/*
+	 * Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower
+	 * authentication.
+	 */
+	if (nfs4_disable_idmapping &&
+	    server->client->cl_auth->au_flavor == RPC_AUTH_UNIX)
+		server->caps |= NFS_CAP_UIDGID_NOMAP;
+#endif
+}
+
+void nfs_server_set_init_caps(struct nfs_server *server)
+{
+	switch (server->nfs_client->rpc_ops->version) {
+	case 2:
+		server->caps = NFS_CAP_HARDLINKS | NFS_CAP_SYMLINKS;
+		break;
+	case 3:
+		server->caps = NFS_CAP_HARDLINKS | NFS_CAP_SYMLINKS;
+		if (!(server->flags & NFS_MOUNT_NORDIRPLUS))
+			server->caps |= NFS_CAP_READDIRPLUS;
+		break;
+	default:
+		nfs4_server_set_init_caps(server);
+		break;
+	}
+}
+EXPORT_SYMBOL_GPL(nfs_server_set_init_caps);
+
 /*
  * Create a version 2 or 3 client
  */
@@ -726,7 +764,6 @@ static int nfs_init_server(struct nfs_server *server,
 	/* Initialise the client representation from the mount data */
 	server->flags = ctx->flags;
 	server->options = ctx->options;
-	server->caps |= NFS_CAP_HARDLINKS | NFS_CAP_SYMLINKS;
 
 	switch (clp->rpc_ops->version) {
 	case 2:
@@ -762,6 +799,8 @@ static int nfs_init_server(struct nfs_server *server,
 	if (error < 0)
 		goto error;
 
+	nfs_server_set_init_caps(server);
+
 	/* Preserve the values of mount_server-related mount options */
 	if (ctx->mount_server.addrlen) {
 		memcpy(&server->mountd_address, &ctx->mount_server.address,
@@ -934,7 +973,6 @@ void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_server *sour
 	target->acregmax = source->acregmax;
 	target->acdirmin = source->acdirmin;
 	target->acdirmax = source->acdirmax;
-	target->caps = source->caps;
 	target->options = source->options;
 	target->auth_info = source->auth_info;
 	target->port = source->port;
@@ -1169,6 +1207,8 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
 	if (error < 0)
 		goto out_free_server;
 
+	nfs_server_set_init_caps(server);
+
 	/* probe the filesystem info for this server filesystem */
 	error = nfs_probe_server(server, fh);
 	if (error < 0)
fs/nfs/internal.h +1 -1
index 0143e0794d32..1a18d8d9be25 100644
@@ -231,7 +231,7 @@ extern struct nfs_client *
 nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
 				struct nfs4_sessionid *, u32);
 extern struct nfs_server *nfs_create_server(struct fs_context *);
-extern void nfs4_server_set_init_caps(struct nfs_server *);
+extern void nfs_server_set_init_caps(struct nfs_server *);
 extern struct nfs_server *nfs4_create_server(struct fs_context *);
 extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
 extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
fs/nfs/nfs4client.c +1 -19
index 2ea98f1f116f..6fddf43d729c 100644
@@ -1074,24 +1074,6 @@ static void nfs4_session_limit_xasize(struct nfs_server *server)
 #endif
 }
 
-void nfs4_server_set_init_caps(struct nfs_server *server)
-{
-	/* Set the basic capabilities */
-	server->caps |= server->nfs_client->cl_mvops->init_caps;
-	if (server->flags & NFS_MOUNT_NORDIRPLUS)
-			server->caps &= ~NFS_CAP_READDIRPLUS;
-	if (server->nfs_client->cl_proto == XPRT_TRANSPORT_RDMA)
-		server->caps &= ~NFS_CAP_READ_PLUS;
-
-	/*
-	 * Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower
-	 * authentication.
-	 */
-	if (nfs4_disable_idmapping &&
-			server->client->cl_auth->au_flavor == RPC_AUTH_UNIX)
-		server->caps |= NFS_CAP_UIDGID_NOMAP;
-}
-
 static int nfs4_server_common_setup(struct nfs_server *server,
 		struct nfs_fh *mntfh, bool auth_probe)
 {
@@ -1110,7 +1092,7 @@ static int nfs4_server_common_setup(struct nfs_server *server,
 	if (error < 0)
 		return error;
 
-	nfs4_server_set_init_caps(server);
+	nfs_server_set_init_caps(server);
 
 	/* Probe the root fh to retrieve its FSID and filehandle */
 	error = nfs4_get_rootfh(server, mntfh, auth_probe);
fs/nfs/nfs4proc.c +1 -1
index d7dc669d84c5..c7c7ec22f21d 100644
@@ -4092,7 +4092,7 @@ int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
 	};
 	int err;
 
-	nfs4_server_set_init_caps(server);
+	nfs_server_set_init_caps(server);
 	do {
 		err = nfs4_handle_exception(server,
 				_nfs4_server_capabilities(server, fhandle),
Signature · 1 line
2.50.1
author maintainer
#3 lore raw

PATCH 2/2 NFSv4: Remove duplicate lookups, capability probes and fsinfo calls

In reply to Trond Myklebust

From: Trond Myklebust <[email protected]>

When crossing into a new filesystem, the NFSv4 client will look up the new directory, and then call nfs4_server_capabilities() as well as nfs4_do_fsinfo() at least twice.

This patch removes the duplicate calls, and reduces the initial lookup to retrieve just a minimal set of attributes.

---
 fs/nfs/nfs4_fs.h     |  5 ++-
 fs/nfs/nfs4getroot.c | 14 +++----
 fs/nfs/nfs4proc.c    | 87 ++++++++++++++++++++------------------------
 3 files changed, 48 insertions(+), 58 deletions(-)
fs/nfs/nfs4_fs.h +3 -2
index d3ca91f60fc1..c34c89af9c7d 100644
@@ -63,7 +63,7 @@ struct nfs4_minor_version_ops {
 	bool	(*match_stateid)(const nfs4_stateid *,
 			const nfs4_stateid *);
 	int	(*find_root_sec)(struct nfs_server *, struct nfs_fh *,
-			struct nfs_fsinfo *);
+				 struct nfs_fattr *);
 	void	(*free_lock_state)(struct nfs_server *,
 			struct nfs4_lock_state *);
 	int	(*test_and_free_expired)(struct nfs_server *,
@@ -296,7 +296,8 @@ extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
 extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *);
-extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
+extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *,
+				struct nfs_fattr *, bool);
 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
 extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
 extern int nfs4_destroy_clientid(struct nfs_client *clp);
fs/nfs/nfs4getroot.c +6 -8
index 1a69479a3a59..e67ea345de69 100644
@@ -12,30 +12,28 @@
 
 int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe)
 {
-	struct nfs_fsinfo fsinfo;
+	struct nfs_fattr *fattr = nfs_alloc_fattr();
 	int ret = -ENOMEM;
 
-	fsinfo.fattr = nfs_alloc_fattr();
-	if (fsinfo.fattr == NULL)
+	if (fattr == NULL)
 		goto out;
 
 	/* Start by getting the root filehandle from the server */
-	ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo, auth_probe);
+	ret = nfs4_proc_get_rootfh(server, mntfh, fattr, auth_probe);
 	if (ret < 0) {
 		dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
 		goto out;
 	}
 
-	if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
-			|| !S_ISDIR(fsinfo.fattr->mode)) {
+	if (!(fattr->valid & NFS_ATTR_FATTR_TYPE) || !S_ISDIR(fattr->mode)) {
 		printk(KERN_ERR "nfs4_get_rootfh:"
 		       " getroot encountered non-directory\n");
 		ret = -ENOTDIR;
 		goto out;
 	}
 
-	memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
+	memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
 out:
-	nfs_free_fattr(fsinfo.fattr);
+	nfs_free_fattr(fattr);
 	return ret;
 }
fs/nfs/nfs4proc.c +39 -48

210 lines not on this page · raw message

Signature · 1 line
2.50.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] NFS: Fix the setting of capabilities when automounting a new filesystem

In reply to Trond Myklebust
Quoted 9 lines · Trond Myklebust

From: Trond Myklebust <[email protected]>

Capabilities cannot be inherited when we cross into a new filesystem. They need to be reset to the minimal defaults, and then probed for again.

Fixes 54ceac451598 ("NFS: Share NFS superblocks per-protocol per-server per-FSID")

Ben

Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] NFSv4: Remove duplicate lookups, capability probes and fsinfo calls

In reply to Trond Myklebust
Quoted 85 lines · Trond Myklebust

From: Trond Myklebust <[email protected]>

When crossing into a new filesystem, the NFSv4 client will look up the new directory, and then call nfs4_server_capabilities() as well as nfs4_do_fsinfo() at least twice.

This patch removes the duplicate calls, and reduces the initial lookup to retrieve just a minimal set of attributes.

---
 fs/nfs/nfs4_fs.h     |  5 ++-
 fs/nfs/nfs4getroot.c | 14 +++----
 fs/nfs/nfs4proc.c    | 87 ++++++++++++++++++++------------------------
 3 files changed, 48 insertions(+), 58 deletions(-)
fs/nfs/nfs4_fs.h +3 -2
index d3ca91f60fc1..c34c89af9c7d 100644
@@ -63,7 +63,7 @@ struct nfs4_minor_version_ops {
 	bool	(*match_stateid)(const nfs4_stateid *,
 			const nfs4_stateid *);
 	int	(*find_root_sec)(struct nfs_server *, struct nfs_fh *,
-			struct nfs_fsinfo *);
+				 struct nfs_fattr *);
 	void	(*free_lock_state)(struct nfs_server *,
 			struct nfs4_lock_state *);
 	int	(*test_and_free_expired)(struct nfs_server *,
@@ -296,7 +296,8 @@ extern int nfs4_call_sync(struct rpc_clnt *, struct nfs_server *,
 extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *);
-extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
+extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *,
+				struct nfs_fattr *, bool);
 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
 extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
 extern int nfs4_destroy_clientid(struct nfs_client *clp);
fs/nfs/nfs4getroot.c +6 -8
index 1a69479a3a59..e67ea345de69 100644
@@ -12,30 +12,28 @@
 
 int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe)
 {
-	struct nfs_fsinfo fsinfo;
+	struct nfs_fattr *fattr = nfs_alloc_fattr();
 	int ret = -ENOMEM;
 
-	fsinfo.fattr = nfs_alloc_fattr();
-	if (fsinfo.fattr == NULL)
+	if (fattr == NULL)
 		goto out;
 
 	/* Start by getting the root filehandle from the server */
-	ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo, auth_probe);
+	ret = nfs4_proc_get_rootfh(server, mntfh, fattr, auth_probe);
 	if (ret < 0) {
 		dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
 		goto out;
 	}
 
-	if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
-			|| !S_ISDIR(fsinfo.fattr->mode)) {
+	if (!(fattr->valid & NFS_ATTR_FATTR_TYPE) || !S_ISDIR(fattr->mode)) {
 		printk(KERN_ERR "nfs4_get_rootfh:"
 		       " getroot encountered non-directory\n");
 		ret = -ENOTDIR;
 		goto out;
 	}
 
-	memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
+	memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
 out:
-	nfs_free_fattr(fsinfo.fattr);
+	nfs_free_fattr(fattr);
 	return ret;
 }
fs/nfs/nfs4proc.c +0 -0
index c7c7ec22f21d..7d2b67e06cc3 100644

fs/nfs/nfs4proc.c static int nfs4_discover_trunking(struct nfs_server *server, · line 4247

Quoted 10 lines
fs/nfs/nfs4proc.c +4 -2
@@ -4240,15 +4240,18 @@ static int nfs4_discover_trunking(struct nfs_server *server,
 }
 
 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
-		struct nfs_fsinfo *info)
+			     struct nfs_fattr *fattr)
 {
-	u32 bitmask[3];
+	u32 bitmask[3] = {
+		[0] = FATTR4_WORD0_TYPE | FATTR4_WORD0_CHANGE |
+		      FATTR4_WORD0_SIZE | FATTR4_WORD0_FSID,

Just a thought when noticing this change --

Don't we want at least FATTR4_WORD0_FILEID and
FATTR4_WORD1_MOUNTED_ON_FILEID as well here?

Ben

author maintainer
#5 lore raw

Re: [PATCH 2/2] NFSv4: Remove duplicate lookups, capability probes and fsinfo calls

Quoted 121 lines · Benjamin Coddington
Quoted 112 lines · Trond Myklebust

From: Trond Myklebust <[email protected]>

When crossing into a new filesystem, the NFSv4 client will look up the
new directory, and then call nfs4_server_capabilities() as well as nfs4_do_fsinfo() at least twice.

This patch removes the duplicate calls, and reduces the initial lookup
to retrieve just a minimal set of attributes.

---
 fs/nfs/nfs4_fs.h     |  5 ++-
 fs/nfs/nfs4getroot.c | 14 +++----
 fs/nfs/nfs4proc.c    | 87 ++++++++++++++++++++--------------------
----

 3 files changed, 48 insertions(+), 58 deletions(-)
fs/nfs/nfs4_fs.h +0 -0
index d3ca91f60fc1..c34c89af9c7d 100644
@@ -63,7 +63,7 @@ struct nfs4_minor_version_ops {
  	bool	(*match_stateid)(const nfs4_stateid *,
  			const nfs4_stateid *);

  int (*find_root_sec)(struct nfs_server *, struct
nfs_fh *,

fs/nfs/nfs4_fs.h +1 -1
-			struct nfs_fsinfo *);
+				 struct nfs_fattr *);

  void (*free_lock_state)(struct nfs_server *,
  struct nfs4_lock_state *);
  int (*test_and_free_expired)(struct nfs_server *,

fs/nfs/nfs4_fs.h +0 -0
@@ -296,7 +296,8 @@ extern int nfs4_call_sync(struct rpc_clnt *,
 struct nfs_server *,

 extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *); -extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
+extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *,

fs/nfs/nfs4_fs.h +1 -0
+				struct nfs_fattr *, bool);

 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
 extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
 extern int nfs4_destroy_clientid(struct nfs_client *clp);

fs/nfs/nfs4getroot.c +0 -0
index 1a69479a3a59..e67ea345de69 100644
@@ -12,30 +12,28 @@
 

 int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe)
 {

fs/nfs/nfs4getroot.c +1 -1
-	struct nfs_fsinfo fsinfo;
+	struct nfs_fattr *fattr = nfs_alloc_fattr();

  int ret = -ENOMEM;

fs/nfs/nfs4getroot.c +1 -2
-	fsinfo.fattr = nfs_alloc_fattr();
-	if (fsinfo.fattr == NULL)
+	if (fattr == NULL)

  goto out;

  /* Start by getting the root filehandle from the server */

fs/nfs/nfs4getroot.c +0 -1
-	ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo,

auth_probe);

fs/nfs/nfs4getroot.c +1 -0
+	ret = nfs4_proc_get_rootfh(server, mntfh, fattr,

auth_probe);
  if (ret < 0) {
  dprintk("nfs4_get_rootfh: getroot error = %d\n", - ret);
  goto out;
  }

fs/nfs/nfs4getroot.c +1 -2
-	if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
-			|| !S_ISDIR(fsinfo.fattr->mode)) {
+	if (!(fattr->valid & NFS_ATTR_FATTR_TYPE) ||

!S_ISDIR(fattr->mode)) {
  printk(KERN_ERR "nfs4_get_rootfh:"
         " getroot encountered non-directory\n"); ret = -ENOTDIR;
  goto out;
  }

fs/nfs/nfs4getroot.c +0 -1
-	memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server-
Quoted 1 line

fsid));

fs/nfs/nfs4getroot.c +1 -0
+	memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));

 out:

fs/nfs/nfs4getroot.c +1 -1
-	nfs_free_fattr(fsinfo.fattr);
+	nfs_free_fattr(fattr);

  return ret;
 }

fs/nfs/nfs4proc.c +0 -0
index c7c7ec22f21d..7d2b67e06cc3 100644
@@ -4240,15 +4240,18 @@ static int nfs4_discover_trunking(struct
 nfs_server *server,
  }
 

 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,

fs/nfs/nfs4proc.c +1 -1
-		struct nfs_fsinfo *info)
+			     struct nfs_fattr *fattr)

 {

fs/nfs/nfs4proc.c static int nfs4_discover_trunking(struct nfs_server *server, · line 4247

Quoted 4 lines
fs/nfs/nfs4proc.c +3 -1
-	u32 bitmask[3];
+	u32 bitmask[3] = {
+		[0] = FATTR4_WORD0_TYPE | FATTR4_WORD0_CHANGE |
+		      FATTR4_WORD0_SIZE | FATTR4_WORD0_FSID,

Just a thought when noticing this change --

Quoted 2 lines

Don't we want at least FATTR4_WORD0_FILEID and
FATTR4_WORD1_MOUNTED_ON_FILEID as well here?

Only FATTR4_WORD0_TYPE and FATTR4_WORD0_FSID are used by the caller, so we don't actually need FATTR4_WORD0_CHANGE or FATTR4_WORD0_SIZE either. I put them in so that the test for the auth flavour would have more chances of catching a problem.

Note that neither FATTR4_WORD0_FILEID or FATTR4_WORD1_MOUNTED_ON_FILEID are mandatory attributes, so I also chose to avoid them + all the timestamps for that reason.

Quoted 5 lines

Ben

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected], [email protected]
#6 lore raw

Re: [PATCH 2/2] NFSv4: Remove duplicate lookups, capability probes and fsinfo calls

Quoted 84 lines · Trond Myklebust
Quoted 83 lines · Benjamin Coddington
Quoted 81 lines · Trond Myklebust

From: Trond Myklebust <[email protected]>

When crossing into a new filesystem, the NFSv4 client will look up the
new directory, and then call nfs4_server_capabilities() as well as nfs4_do_fsinfo() at least twice.

This patch removes the duplicate calls, and reduces the initial lookup
to retrieve just a minimal set of attributes.

---
 fs/nfs/nfs4_fs.h     |  5 ++-
 fs/nfs/nfs4getroot.c | 14 +++----
 fs/nfs/nfs4proc.c    | 87 ++++++++++++++++++++--------------------
----

 3 files changed, 48 insertions(+), 58 deletions(-)
fs/nfs/nfs4_fs.h +0 -0
index d3ca91f60fc1..c34c89af9c7d 100644
@@ -63,7 +63,7 @@ struct nfs4_minor_version_ops {
  	bool	(*match_stateid)(const nfs4_stateid *,
  			const nfs4_stateid *);

  int (*find_root_sec)(struct nfs_server *, struct
nfs_fh *,

fs/nfs/nfs4_fs.h +1 -1
-			struct nfs_fsinfo *);
+				 struct nfs_fattr *);

  void (*free_lock_state)(struct nfs_server *,
  struct nfs4_lock_state *);
  int (*test_and_free_expired)(struct nfs_server *,

fs/nfs/nfs4_fs.h +0 -0
@@ -296,7 +296,8 @@ extern int nfs4_call_sync(struct rpc_clnt *,
 struct nfs_server *,

 extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *); -extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
+extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *,

fs/nfs/nfs4_fs.h +1 -0
+				struct nfs_fattr *, bool);

 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
 extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
 extern int nfs4_destroy_clientid(struct nfs_client *clp);

fs/nfs/nfs4getroot.c +0 -0
index 1a69479a3a59..e67ea345de69 100644
@@ -12,30 +12,28 @@
 

 int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe)
 {

fs/nfs/nfs4getroot.c +1 -1
-	struct nfs_fsinfo fsinfo;
+	struct nfs_fattr *fattr = nfs_alloc_fattr();

  int ret = -ENOMEM;

fs/nfs/nfs4getroot.c +1 -2
-	fsinfo.fattr = nfs_alloc_fattr();
-	if (fsinfo.fattr == NULL)
+	if (fattr == NULL)

  goto out;

  /* Start by getting the root filehandle from the server */

fs/nfs/nfs4getroot.c +0 -1
-	ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo,

auth_probe);

fs/nfs/nfs4getroot.c +1 -0
+	ret = nfs4_proc_get_rootfh(server, mntfh, fattr,

auth_probe);
  if (ret < 0) {
  dprintk("nfs4_get_rootfh: getroot error = %d\n", - ret);
  goto out;
  }

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
fs/nfs/nfs4getroot.c +1 -2
-	if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
-			|| !S_ISDIR(fsinfo.fattr->mode)) {
+	if (!(fattr->valid & NFS_ATTR_FATTR_TYPE) ||

!S_ISDIR(fattr->mode)) {
  printk(KERN_ERR "nfs4_get_rootfh:"
         " getroot encountered non-directory\n"); ret = -ENOTDIR;
  goto out;
  }

.. now I think we won't have fattr->mode here, more below:

Quoted 29 lines
Quoted 29 lines
Quoted 22 lines
fs/nfs/nfs4getroot.c +0 -1
-	memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server-
Quoted 1 line

fsid));

fs/nfs/nfs4getroot.c +1 -0
+	memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));

 out:

fs/nfs/nfs4getroot.c +1 -1
-	nfs_free_fattr(fsinfo.fattr);
+	nfs_free_fattr(fattr);

  return ret;
 }

fs/nfs/nfs4proc.c +0 -0
index c7c7ec22f21d..7d2b67e06cc3 100644
@@ -4240,15 +4240,18 @@ static int nfs4_discover_trunking(struct
 nfs_server *server,
  }
 

 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,

fs/nfs/nfs4proc.c +1 -1
-		struct nfs_fsinfo *info)
+			     struct nfs_fattr *fattr)

 {

fs/nfs/nfs4proc.c static int nfs4_discover_trunking(struct nfs_server *server, · line 4247

Quoted 4 lines
fs/nfs/nfs4proc.c +3 -1
-	u32 bitmask[3];
+	u32 bitmask[3] = {
+		[0] = FATTR4_WORD0_TYPE | FATTR4_WORD0_CHANGE |
+		      FATTR4_WORD0_SIZE | FATTR4_WORD0_FSID,

Just a thought when noticing this change --

Quoted 8 lines
Quoted 2 lines

Don't we want at least FATTR4_WORD0_FILEID and
FATTR4_WORD1_MOUNTED_ON_FILEID as well here?

Only FATTR4_WORD0_TYPE and FATTR4_WORD0_FSID are used by the caller, so we don't actually need FATTR4_WORD0_CHANGE or FATTR4_WORD0_SIZE either. I put them in so that the test for the auth flavour would have more chances of catching a problem.

Ah, I see now... we're going to call ->fsinfo() again (as you stated in the description).

But I don't see how _CHANGE or _SIZE are used.. and as I was hunting around there's that check in nfs4_get_rootfh() (above) for S_ISDIR(fattr->mode), but this dropped the fsinfo call out of nfs4_proc_get_rootfh(), so I think fattr->mode will never be set.

Quoted 3 lines

Note that neither FATTR4_WORD0_FILEID or FATTR4_WORD1_MOUNTED_ON_FILEID are mandatory attributes, so I also chose to avoid them + all the timestamps for that reason.

Gotcha, making sense. This is tricky for me to review, maybe I should just test it.. :)

Ben

#7 lore raw

Re: [PATCH 2/2] NFSv4: Remove duplicate lookups, capability probes and fsinfo calls

Quoted 136 lines · Benjamin Coddington
Quoted 84 lines · Trond Myklebust
Quoted 83 lines · Benjamin Coddington
Quoted 81 lines · Trond Myklebust

From: Trond Myklebust <[email protected]>

When crossing into a new filesystem, the NFSv4 client will look up the
new directory, and then call nfs4_server_capabilities() as well as nfs4_do_fsinfo() at least twice.

This patch removes the duplicate calls, and reduces the initial lookup
to retrieve just a minimal set of attributes.

---
 fs/nfs/nfs4_fs.h     |  5 ++-
 fs/nfs/nfs4getroot.c | 14 +++----
 fs/nfs/nfs4proc.c    | 87 ++++++++++++++++++++--------------------
----

 3 files changed, 48 insertions(+), 58 deletions(-)
fs/nfs/nfs4_fs.h +0 -0
index d3ca91f60fc1..c34c89af9c7d 100644
@@ -63,7 +63,7 @@ struct nfs4_minor_version_ops {
  	bool	(*match_stateid)(const nfs4_stateid *,
  			const nfs4_stateid *);

  int (*find_root_sec)(struct nfs_server *, struct
nfs_fh *,

fs/nfs/nfs4_fs.h +1 -1
-			struct nfs_fsinfo *);
+				 struct nfs_fattr *);

  void (*free_lock_state)(struct nfs_server *,
  struct nfs4_lock_state *);
  int (*test_and_free_expired)(struct nfs_server *,

fs/nfs/nfs4_fs.h +0 -0
@@ -296,7 +296,8 @@ extern int nfs4_call_sync(struct rpc_clnt *,
 struct nfs_server *,

 extern void nfs4_init_sequence(struct nfs4_sequence_args *, struct nfs4_sequence_res *, int, int);
 extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, const struct cred *, struct nfs4_setclientid_res *);
 extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, const struct cred *); -extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *, bool);
+extern int nfs4_proc_get_rootfh(struct nfs_server *, struct nfs_fh *,

fs/nfs/nfs4_fs.h +1 -0
+				struct nfs_fattr *, bool);

 extern int nfs4_proc_bind_conn_to_session(struct nfs_client *, const struct cred *cred);
 extern int nfs4_proc_exchange_id(struct nfs_client *clp, const struct cred *cred);
 extern int nfs4_destroy_clientid(struct nfs_client *clp);

fs/nfs/nfs4getroot.c +0 -0
index 1a69479a3a59..e67ea345de69 100644
@@ -12,30 +12,28 @@
 

 int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool auth_probe)
 {

fs/nfs/nfs4getroot.c +1 -1
-	struct nfs_fsinfo fsinfo;
+	struct nfs_fattr *fattr = nfs_alloc_fattr();

  int ret = -ENOMEM;

fs/nfs/nfs4getroot.c +1 -2
-	fsinfo.fattr = nfs_alloc_fattr();
-	if (fsinfo.fattr == NULL)
+	if (fattr == NULL)

  goto out;

  /* Start by getting the root filehandle from the server */

fs/nfs/nfs4getroot.c +0 -1
-	ret = nfs4_proc_get_rootfh(server, mntfh, &fsinfo,

auth_probe);

fs/nfs/nfs4getroot.c +1 -0
+	ret = nfs4_proc_get_rootfh(server, mntfh, fattr,

auth_probe);
  if (ret < 0) {
  dprintk("nfs4_get_rootfh: getroot error = %d\n", - ret);
  goto out;
  }

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
fs/nfs/nfs4getroot.c +1 -2
-	if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_TYPE)
-			|| !S_ISDIR(fsinfo.fattr->mode)) {
+	if (!(fattr->valid & NFS_ATTR_FATTR_TYPE) ||

!S_ISDIR(fattr->mode)) {
  printk(KERN_ERR "nfs4_get_rootfh:"
         " getroot encountered non-directory\n"); ret = -ENOTDIR;
  goto out;
  }

.. now I think we won't have fattr->mode here, more below:

Quoted 29 lines
Quoted 29 lines
Quoted 22 lines
fs/nfs/nfs4getroot.c +0 -1
-	memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server-
Quoted 1 line

fsid));

fs/nfs/nfs4getroot.c +1 -0
+	memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));

 out:

fs/nfs/nfs4getroot.c +1 -1
-	nfs_free_fattr(fsinfo.fattr);
+	nfs_free_fattr(fattr);

  return ret;
 }

fs/nfs/nfs4proc.c +0 -0
index c7c7ec22f21d..7d2b67e06cc3 100644
@@ -4240,15 +4240,18 @@ static int nfs4_discover_trunking(struct
 nfs_server *server,
  }
 

 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,

fs/nfs/nfs4proc.c +1 -1
-		struct nfs_fsinfo *info)
+			     struct nfs_fattr *fattr)

 {

fs/nfs/nfs4proc.c static int nfs4_discover_trunking(struct nfs_server *server, · line 4247

Quoted 4 lines
fs/nfs/nfs4proc.c +3 -1
-	u32 bitmask[3];
+	u32 bitmask[3] = {
+		[0] = FATTR4_WORD0_TYPE | FATTR4_WORD0_CHANGE |
+		      FATTR4_WORD0_SIZE | FATTR4_WORD0_FSID,

Just a thought when noticing this change --

Quoted 8 lines
Quoted 2 lines

Don't we want at least FATTR4_WORD0_FILEID and
FATTR4_WORD1_MOUNTED_ON_FILEID as well here?

Only FATTR4_WORD0_TYPE and FATTR4_WORD0_FSID are used by the caller, so we don't actually need FATTR4_WORD0_CHANGE or FATTR4_WORD0_SIZE either. I put them in so that the test for the auth flavour would have more chances of catching a problem.

Quoted 7 lines

Ah, I see now... we're going to call ->fsinfo() again (as you stated in the description).

But I don't see how _CHANGE or _SIZE are used.. and as I was hunting around there's that check in nfs4_get_rootfh() (above) for S_ISDIR(fattr->mode), but this dropped the fsinfo call out of nfs4_proc_get_rootfh(), so I think fattr->mode will never be set.

I ran this through some basic testing, and I see now that _TYPE gets into fattr->mode when we decode, which of course makes sense.

So, FWIW - this makes sense and looks good to me now.

Ben

#8 lore raw
In reply to Trond Myklebust

Hello,

I think this patch (https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=b01f21cacde9f2878492cf318fee61bf4ccad323) might have broken the getxattr system call over NFS.

On v6.16.1, I was able to call getxattr on files in an NFS 4.2 mount, but with this patch, running the same command I get:

    $ cd /path/to/nfs4.2/mount
    $ getfattr -n user.hash.sha512 'S01E01 - Kassa.mkv'
    S01E01 - Kassa.mkv: user.hash.sha512: Operation not supported

Without this patch, it just returns the xattr with no problem.

Am I missing a mount option? Or, is it possible this commit introduced a bug?

I ran a git bisect between v6.16.1 and v6.16.2 and it pointed to this patch's backport to the stable tree.

Thanks,
--Scott