Skip to contentSkip to conversation

NFS: Re-probe server capabilities on remount

PATCH New [email protected] 1 participant 6 messages Oct 14, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover NFS: Re-probe server capabilities on remount

From: Anna Schumaker <[email protected]>

These patches hook into the nfs_reconfigure() function to reset and reprobe a server's capabilities when remounted. This could be useful if a server is upgraded to support a new NFS v4.2 feature or if it has other changes that can only be detected at mount-time.

Thoughts?
Anna

Anna Schumaker (5):
NFS: Create an nfs4_server_set_init_caps() function
NFS: Move nfs_probe_destination() into the generic client
NFS: Replace calls to nfs_probe_fsinfo() with nfs_probe_server()
NFS: Call nfs_probe_server() during a fscontext-reconfigure event
NFS: Unexport nfs_probe_fsinfo()

 fs/nfs/client.c     | 37 ++++++++++++++++++--------
 fs/nfs/internal.h   |  3 ++-
 fs/nfs/nfs4client.c | 65 ++++++++++++++-------------------------------
 fs/nfs/nfs4proc.c   |  2 ++
 fs/nfs/super.c      |  7 ++++-
 5 files changed, 56 insertions(+), 58 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/5 NFS: Create an nfs4_server_set_init_caps() function

From: Anna Schumaker <[email protected]>

And call it before doing an FSINFO probe to reset to the baseline capabilities before probing.

---
 fs/nfs/internal.h   |  1 +
 fs/nfs/nfs4client.c | 41 +++++++++++++++++++++++------------------
 fs/nfs/nfs4proc.c   |  2 ++
 3 files changed, 26 insertions(+), 18 deletions(-)
fs/nfs/internal.h +1 -0
index 7483f196c6ef..690271adb294 100644
@@ -209,6 +209,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 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 +23 -18

61 lines not on this page · raw message

fs/nfs/nfs4proc.c +2 -0
index fc0be32b19fc..77bbdced702f 100644
@@ -3923,6 +3923,8 @@ int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
 		.interruptible = true,
 	};
 	int err;
+
+	nfs4_server_set_init_caps(server);
 	do {
 		err = nfs4_handle_exception(server,
 				_nfs4_server_capabilities(server, fhandle),
Signature · 1 line
2.33.0
#2 lore raw

PATCH 2/5 NFS: Move nfs_probe_destination() into the generic client

In reply to [email protected]

From: Anna Schumaker <[email protected]>

And rename it to nfs_probe_server(). I also change it to take the nfs_fh as an argument so callers can choose what filehandle to probe.

---
 fs/nfs/client.c     | 24 ++++++++++++++++++++++++
 fs/nfs/internal.h   |  1 +
 fs/nfs/nfs4client.c | 26 +-------------------------
 3 files changed, 26 insertions(+), 25 deletions(-)
fs/nfs/client.c +24 -0
index 6956079b7741..b7b79a348c2b 100644
@@ -864,6 +864,30 @@ int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs
 }
 EXPORT_SYMBOL_GPL(nfs_probe_fsinfo);
 
+/*
+ * Grab the destination's particulars, including lease expiry time.
+ *
+ * Returns zero if probe succeeded and retrieved FSID matches the FSID
+ * we have cached.
+ */
+int nfs_probe_server(struct nfs_server *server, struct nfs_fh *mntfh)
+{
+	struct nfs_fattr *fattr;
+	int error;
+
+	fattr = nfs_alloc_fattr();
+	if (fattr == NULL)
+		return -ENOMEM;
+
+	/* Sanity: the probe won't work if the destination server
+	 * does not recognize the migrated FH. */
+	error = nfs_probe_fsinfo(server, mntfh, fattr);
+
+	nfs_free_fattr(fattr);
+	return error;
+}
+EXPORT_SYMBOL_GPL(nfs_probe_server);
+
 /*
  * Copy useful information when duplicating a server record
  */
fs/nfs/internal.h +1 -0
index 690271adb294..508cb64c2661 100644
@@ -194,6 +194,7 @@ extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
 int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
 struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
 int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
+int nfs_probe_server(struct nfs_server *, struct nfs_fh *);
 void nfs_server_insert_lists(struct nfs_server *);
 void nfs_server_remove_lists(struct nfs_server *);
 void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
fs/nfs/nfs4client.c +1 -25
index 3fb0ca92377c..85978ecb727e 100644
@@ -1293,30 +1293,6 @@ struct nfs_server *nfs4_create_referral_server(struct fs_context *fc)
 	return ERR_PTR(error);
 }
 
-/*
- * Grab the destination's particulars, including lease expiry time.
- *
- * Returns zero if probe succeeded and retrieved FSID matches the FSID
- * we have cached.
- */
-static int nfs_probe_destination(struct nfs_server *server)
-{
-	struct inode *inode = d_inode(server->super->s_root);
-	struct nfs_fattr *fattr;
-	int error;
-
-	fattr = nfs_alloc_fattr();
-	if (fattr == NULL)
-		return -ENOMEM;
-
-	/* Sanity: the probe won't work if the destination server
-	 * does not recognize the migrated FH. */
-	error = nfs_probe_fsinfo(server, NFS_FH(inode), fattr);
-
-	nfs_free_fattr(fattr);
-	return error;
-}
-
 /**
  * nfs4_update_server - Move an nfs_server to a different nfs_client
  *
@@ -1377,5 +1353,5 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname,
 		server->nfs_client->cl_hostname = kstrdup(hostname, GFP_KERNEL);
 	nfs_server_insert_lists(server);
 
-	return nfs_probe_destination(server);
+	return nfs_probe_server(server, NFS_FH(d_inode(server->super->s_root)));
 }
Signature · 1 line
2.33.0
#3 lore raw

PATCH 3/5 NFS: Replace calls to nfs_probe_fsinfo() with nfs_probe_server()

In reply to [email protected]

From: Anna Schumaker <[email protected]>

Clean up. There are a few places where we want to probe the server, but don't actually care about the fsinfo result. Change these to use nfs_probe_server(), which handles the fattr allocation for us.

---
 fs/nfs/client.c     | 10 +---------
 fs/nfs/nfs4client.c |  8 +-------
 2 files changed, 2 insertions(+), 16 deletions(-)
fs/nfs/client.c +1 -9
index b7b79a348c2b..7f30a6c1a0b0 100644
@@ -1082,7 +1082,6 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
 				    rpc_authflavor_t flavor)
 {
 	struct nfs_server *server;
-	struct nfs_fattr *fattr_fsinfo;
 	int error;
 
 	server = nfs_alloc_server();
@@ -1091,11 +1090,6 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
 
 	server->cred = get_cred(source->cred);
 
-	error = -ENOMEM;
-	fattr_fsinfo = nfs_alloc_fattr();
-	if (fattr_fsinfo == NULL)
-		goto out_free_server;
-
 	/* Copy data from the source */
 	server->nfs_client = source->nfs_client;
 	server->destroy = source->destroy;
@@ -1111,7 +1105,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
 		goto out_free_server;
 
 	/* probe the filesystem info for this server filesystem */
-	error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
+	error = nfs_probe_server(server, fh);
 	if (error < 0)
 		goto out_free_server;
 
@@ -1125,11 +1119,9 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
 	nfs_server_insert_lists(server);
 	server->mount_time = jiffies;
 
-	nfs_free_fattr(fattr_fsinfo);
 	return server;
 
 out_free_server:
-	nfs_free_fattr(fattr_fsinfo);
 	nfs_free_server(server);
 	return ERR_PTR(error);
 }
fs/nfs/nfs4client.c +1 -7
index 85978ecb727e..d8b5a250ca05 100644
@@ -1080,17 +1080,12 @@ void nfs4_server_set_init_caps(struct nfs_server *server)
 static int nfs4_server_common_setup(struct nfs_server *server,
 		struct nfs_fh *mntfh, bool auth_probe)
 {
-	struct nfs_fattr *fattr;
 	int error;
 
 	/* data servers support only a subset of NFSv4.1 */
 	if (is_ds_only_client(server->nfs_client))
 		return -EPROTONOSUPPORT;
 
-	fattr = nfs_alloc_fattr();
-	if (fattr == NULL)
-		return -ENOMEM;
-
 	/* We must ensure the session is initialised first */
 	error = nfs4_init_session(server->nfs_client);
 	if (error < 0)
@@ -1108,7 +1103,7 @@ static int nfs4_server_common_setup(struct nfs_server *server,
 			(unsigned long long) server->fsid.minor);
 	nfs_display_fhandle(mntfh, "Pseudo-fs root FH");
 
-	error = nfs_probe_fsinfo(server, mntfh, fattr);
+	error = nfs_probe_server(server, mntfh);
 	if (error < 0)
 		goto out;
 
@@ -1122,7 +1117,6 @@ static int nfs4_server_common_setup(struct nfs_server *server,
 	server->mount_time = jiffies;
 	server->destroy = nfs4_destroy_server;
 out:
-	nfs_free_fattr(fattr);
 	return error;
 }
 
Signature · 1 line
2.33.0
#4 lore raw

PATCH 4/5 NFS: Call nfs_probe_server() during a fscontext-reconfigure event

In reply to [email protected]

From: Anna Schumaker <[email protected]>

This lets us update the server's attributes when the user does a "mount -o remount" on the filesystem.

---
 fs/nfs/super.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/nfs/super.c +6 -1
index e65c83494c05..3aced401735c 100644
@@ -1004,6 +1004,7 @@ int nfs_reconfigure(struct fs_context *fc)
 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
 	struct super_block *sb = fc->root->d_sb;
 	struct nfs_server *nfss = sb->s_fs_info;
+	int ret;
 
 	sync_filesystem(sb);
 
@@ -1028,7 +1029,11 @@ int nfs_reconfigure(struct fs_context *fc)
 	}
 
 	/* compare new mount options with old ones */
-	return nfs_compare_remount_data(nfss, ctx);
+	ret = nfs_compare_remount_data(nfss, ctx);
+	if (ret)
+		return ret;
+
+	return nfs_probe_server(nfss, NFS_FH(d_inode(fc->root)));
 }
 EXPORT_SYMBOL_GPL(nfs_reconfigure);
 
Signature · 1 line
2.33.0
#5 lore raw

PATCH 5/5 NFS: Unexport nfs_probe_fsinfo()

In reply to [email protected]

From: Anna Schumaker <[email protected]>

All the callers are now in client.c so we can remove the EXPORT_SYMBOL_GPL() and make it static.

---
 fs/nfs/client.c   | 3 +--
 fs/nfs/internal.h | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)
fs/nfs/client.c +1 -2
index 7f30a6c1a0b0..1e4dc1ab9312 100644
@@ -828,7 +828,7 @@ static void nfs_server_set_fsinfo(struct nfs_server *server,
 /*
  * Probe filesystem information, including the FSID on v2/v3
  */
-int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
+static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs_fattr *fattr)
 {
 	struct nfs_fsinfo fsinfo;
 	struct nfs_client *clp = server->nfs_client;
@@ -862,7 +862,6 @@ int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, struct nfs
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(nfs_probe_fsinfo);
 
 /*
  * Grab the destination's particulars, including lease expiry time.
fs/nfs/internal.h +0 -1
index 508cb64c2661..12f6acb483bb 100644
@@ -193,7 +193,6 @@ extern void nfs_clients_exit(struct net *net);
 extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
 int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
 struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
-int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
 int nfs_probe_server(struct nfs_server *, struct nfs_fh *);
 void nfs_server_insert_lists(struct nfs_server *);
 void nfs_server_remove_lists(struct nfs_server *);
Signature · 1 line
2.33.0