public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements
@ 2025-01-27 21:50 Anna Schumaker
  2025-01-27 21:50 ` [PATCH v2 1/5] NFS: Add implid to sysfs Anna Schumaker
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Anna Schumaker @ 2025-01-27 21:50 UTC (permalink / raw)
  To: linux-nfs, trond.myklebust; +Cc: anna

From: Anna Schumaker <anna.schumaker@oracle.com>

These are a handful of improvements that have been in the back of my
mind for a while. The first patch adds a (read-only) file to the NFS
client's sysfs collection to check the server's implementation id. The
remaining patches are on the sunrpc side.

I did look into the 'nconnect' and 'max_connect' NFS client mount
options and how they interact with adding a new xprt in patch 4. My
reading is that 'nconnect' is just the initial number of connections
made by the NFS client during mounting. That shouldn't disallow adding a
new connection. The 'max_connect' parameter refers to the maximum number
of unique IP addresses in an xprt switch. The new connection I generate
is a clone of the main xprt, not a new address, so this doesn't come
into play either. So I'm convinced adding a new xprt is okay to do here.

Thoughts?
Anna

Changes for v2:
- Added a file for rpc_clnt information
- Added a file for on-step xprt deletion

Anna Schumaker (5):
  NFS: Add implid to sysfs
  sunrpc: Add a sysfs attr for xprtsec
  sunrpc: Add a sysfs files for rpc_clnt information
  sunrpc: Add a sysfs file for adding a new xprt
  sunrpc: Add a sysfs file for one-step xprt deletion

 fs/nfs/sysfs.c                       |  60 ++++++++
 include/linux/sunrpc/xprtmultipath.h |   1 +
 net/sunrpc/sysfs.c                   | 202 +++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           |  21 +++
 4 files changed, 284 insertions(+)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/5] NFS: Add implid to sysfs
  2025-01-27 21:50 [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Anna Schumaker
@ 2025-01-27 21:50 ` Anna Schumaker
  2025-01-27 21:50 ` [PATCH v2 2/5] sunrpc: Add a sysfs attr for xprtsec Anna Schumaker
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Anna Schumaker @ 2025-01-27 21:50 UTC (permalink / raw)
  To: linux-nfs, trond.myklebust; +Cc: anna

From: Anna Schumaker <anna.schumaker@oracle.com>

The Linux NFS server added support for returning this information during
an EXCHANGE_ID in Linux v6.13. This is something and admin might want to
query, so let's add it to sysfs.

Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
---
v2: * Removed accidentally included (but commented out) code block
    * Unconditionally display the files (with empty contents) for NFS v4.1,
      even if the server does not set these values.
---
 fs/nfs/sysfs.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index 7b59a40d40c0..b30401b2c939 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -272,6 +272,38 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr,
 
 static struct kobj_attribute nfs_sysfs_attr_shutdown = __ATTR_RW(shutdown);
 
+#if IS_ENABLED(CONFIG_NFS_V4_1)
+static ssize_t
+implid_domain_show(struct kobject *kobj, struct kobj_attribute *attr,
+				char *buf)
+{
+	struct nfs_server *server = container_of(kobj, struct nfs_server, kobj);
+	struct nfs41_impl_id *impl_id = server->nfs_client->cl_implid;
+
+	if (!impl_id || strlen(impl_id->domain) == 0)
+		return 0; //sysfs_emit(buf, "");
+	return sysfs_emit(buf, "%s\n", impl_id->domain);
+}
+
+static struct kobj_attribute nfs_sysfs_attr_implid_domain = __ATTR_RO(implid_domain);
+
+
+static ssize_t
+implid_name_show(struct kobject *kobj, struct kobj_attribute *attr,
+				char *buf)
+{
+	struct nfs_server *server = container_of(kobj, struct nfs_server, kobj);
+	struct nfs41_impl_id *impl_id = server->nfs_client->cl_implid;
+
+	if (!impl_id || strlen(impl_id->name) == 0)
+		return 0; //sysfs_emit(buf, "");
+	return sysfs_emit(buf, "%s\n", impl_id->name);
+}
+
+static struct kobj_attribute nfs_sysfs_attr_implid_name = __ATTR_RO(implid_name);
+
+#endif /* IS_ENABLED(CONFIG_NFS_V4_1) */
+
 #define RPC_CLIENT_NAME_SIZE 64
 
 void nfs_sysfs_link_rpc_client(struct nfs_server *server,
@@ -309,6 +341,32 @@ static struct kobj_type nfs_sb_ktype = {
 	.child_ns_type = nfs_netns_object_child_ns_type,
 };
 
+#if IS_ENABLED(CONFIG_NFS_V4_1)
+static void nfs_sysfs_add_nfsv41_server(struct nfs_server *server)
+{
+	int ret;
+
+	if (!server->nfs_client->cl_implid)
+		return;
+
+	ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid_domain.attr,
+					   nfs_netns_server_namespace(&server->kobj));
+	if (ret < 0)
+		pr_warn("NFS: sysfs_create_file_ns for server-%d failed (%d)\n",
+			server->s_sysfs_id, ret);
+
+	ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid_name.attr,
+				   nfs_netns_server_namespace(&server->kobj));
+	if (ret < 0)
+		pr_warn("NFS: sysfs_create_file_ns for server-%d failed (%d)\n",
+			server->s_sysfs_id, ret);
+}
+#else /* CONFIG_NFS_V4_1 */
+static inline void nfs_sysfs_add_nfsv41_server(struct nfs_server *server)
+{
+}
+#endif /* CONFIG_NFS_V4_1 */
+
 void nfs_sysfs_add_server(struct nfs_server *server)
 {
 	int ret;
@@ -325,6 +383,8 @@ void nfs_sysfs_add_server(struct nfs_server *server)
 	if (ret < 0)
 		pr_warn("NFS: sysfs_create_file_ns for server-%d failed (%d)\n",
 			server->s_sysfs_id, ret);
+
+	nfs_sysfs_add_nfsv41_server(server);
 }
 EXPORT_SYMBOL_GPL(nfs_sysfs_add_server);
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/5] sunrpc: Add a sysfs attr for xprtsec
  2025-01-27 21:50 [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Anna Schumaker
  2025-01-27 21:50 ` [PATCH v2 1/5] NFS: Add implid to sysfs Anna Schumaker
@ 2025-01-27 21:50 ` Anna Schumaker
  2025-01-27 21:50 ` [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information Anna Schumaker
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Anna Schumaker @ 2025-01-27 21:50 UTC (permalink / raw)
  To: linux-nfs, trond.myklebust; +Cc: anna

From: Anna Schumaker <anna.schumaker@oracle.com>

This allows the admin to check the TLS configuration for each xprt.

Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
---
 net/sunrpc/sysfs.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index 5c8ecdaaa985..dc3b7cd70000 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -129,6 +129,31 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj,
 	return ret;
 }
 
+static const char *xprtsec_strings[] = {
+	[RPC_XPRTSEC_NONE] = "none",
+	[RPC_XPRTSEC_TLS_ANON] = "tls-anon",
+	[RPC_XPRTSEC_TLS_X509] = "tls-x509",
+};
+
+static ssize_t rpc_sysfs_xprt_xprtsec_show(struct kobject *kobj,
+					   struct kobj_attribute *attr,
+					   char *buf)
+{
+	struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
+	ssize_t ret;
+
+	if (!xprt) {
+		ret = sprintf(buf, "<closed>\n");
+		goto out;
+	}
+
+	ret = sprintf(buf, "%s\n", xprtsec_strings[xprt->xprtsec.policy]);
+	xprt_put(xprt);
+out:
+	return ret;
+
+}
+
 static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj,
 					struct kobj_attribute *attr, char *buf)
 {
@@ -404,6 +429,9 @@ static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr,
 static struct kobj_attribute rpc_sysfs_xprt_srcaddr = __ATTR(srcaddr,
 	0644, rpc_sysfs_xprt_srcaddr_show, NULL);
 
+static struct kobj_attribute rpc_sysfs_xprt_xprtsec = __ATTR(xprtsec,
+	0644, rpc_sysfs_xprt_xprtsec_show, NULL);
+
 static struct kobj_attribute rpc_sysfs_xprt_info = __ATTR(xprt_info,
 	0444, rpc_sysfs_xprt_info_show, NULL);
 
@@ -413,6 +441,7 @@ static struct kobj_attribute rpc_sysfs_xprt_change_state = __ATTR(xprt_state,
 static struct attribute *rpc_sysfs_xprt_attrs[] = {
 	&rpc_sysfs_xprt_dstaddr.attr,
 	&rpc_sysfs_xprt_srcaddr.attr,
+	&rpc_sysfs_xprt_xprtsec.attr,
 	&rpc_sysfs_xprt_info.attr,
 	&rpc_sysfs_xprt_change_state.attr,
 	NULL,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information
  2025-01-27 21:50 [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Anna Schumaker
  2025-01-27 21:50 ` [PATCH v2 1/5] NFS: Add implid to sysfs Anna Schumaker
  2025-01-27 21:50 ` [PATCH v2 2/5] sunrpc: Add a sysfs attr for xprtsec Anna Schumaker
@ 2025-01-27 21:50 ` Anna Schumaker
  2025-02-03 13:42   ` Benjamin Coddington
  2025-01-27 21:50 ` [PATCH v2 4/5] sunrpc: Add a sysfs file for adding a new xprt Anna Schumaker
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Anna Schumaker @ 2025-01-27 21:50 UTC (permalink / raw)
  To: linux-nfs, trond.myklebust; +Cc: anna

From: Anna Schumaker <anna.schumaker@oracle.com>

These files display useful information about the RPC client, such as the
rpc version number, program name, and maximum number of connections
allowed.

Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
---
 net/sunrpc/sysfs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index dc3b7cd70000..0d382ab24f1f 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -59,6 +59,16 @@ static struct kobject *rpc_sysfs_object_alloc(const char *name,
 	return NULL;
 }
 
+static inline struct rpc_clnt *
+rpc_sysfs_client_kobj_get_clnt(struct kobject *kobj)
+{
+	struct rpc_sysfs_client *c = container_of(kobj,
+		struct rpc_sysfs_client, kobject);
+	struct rpc_clnt *ret = c->clnt;
+
+	return refcount_inc_not_zero(&ret->cl_count) ? ret : NULL;
+}
+
 static inline struct rpc_xprt *
 rpc_sysfs_xprt_kobj_get_xprt(struct kobject *kobj)
 {
@@ -86,6 +96,51 @@ rpc_sysfs_xprt_switch_kobj_get_xprt(struct kobject *kobj)
 	return xprt_switch_get(x->xprt_switch);
 }
 
+static ssize_t rpc_sysfs_clnt_version_show(struct kobject *kobj,
+					   struct kobj_attribute *attr,
+					   char *buf)
+{
+	struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj);
+	ssize_t ret;
+
+	if (!clnt)
+		return sprintf(buf, "<closed>\n");
+
+	ret = sprintf(buf, "%u", clnt->cl_vers);
+	refcount_dec(&clnt->cl_count);
+	return ret;
+}
+
+static ssize_t rpc_sysfs_clnt_program_show(struct kobject *kobj,
+					   struct kobj_attribute *attr,
+					   char *buf)
+{
+	struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj);
+	ssize_t ret;
+
+	if (!clnt)
+		return sprintf(buf, "<closed>\n");
+
+	ret = sprintf(buf, "%s", clnt->cl_program->name);
+	refcount_dec(&clnt->cl_count);
+	return ret;
+}
+
+static ssize_t rpc_sysfs_clnt_max_connect_show(struct kobject *kobj,
+					       struct kobj_attribute *attr,
+					       char *buf)
+{
+	struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj);
+	ssize_t ret;
+
+	if (!clnt)
+		return sprintf(buf, "<closed>\n");
+
+	ret = sprintf(buf, "%u\n", clnt->cl_max_connect);
+	refcount_dec(&clnt->cl_count);
+	return ret;
+}
+
 static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj,
 					   struct kobj_attribute *attr,
 					   char *buf)
@@ -423,6 +478,23 @@ static const void *rpc_sysfs_xprt_namespace(const struct kobject *kobj)
 			    kobject)->xprt->xprt_net;
 }
 
+static struct kobj_attribute rpc_sysfs_clnt_version = __ATTR(rpc_version,
+	0444, rpc_sysfs_clnt_version_show, NULL);
+
+static struct kobj_attribute rpc_sysfs_clnt_program = __ATTR(program,
+	0444, rpc_sysfs_clnt_program_show, NULL);
+
+static struct kobj_attribute rpc_sysfs_clnt_max_connect = __ATTR(max_connect,
+	0644, rpc_sysfs_clnt_max_connect_show, NULL);
+
+static struct attribute *rpc_sysfs_rpc_clnt_attrs[] = {
+	&rpc_sysfs_clnt_version.attr,
+	&rpc_sysfs_clnt_program.attr,
+	&rpc_sysfs_clnt_max_connect.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(rpc_sysfs_rpc_clnt);
+
 static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr,
 	0644, rpc_sysfs_xprt_dstaddr_show, rpc_sysfs_xprt_dstaddr_store);
 
@@ -459,6 +531,7 @@ ATTRIBUTE_GROUPS(rpc_sysfs_xprt_switch);
 
 static const struct kobj_type rpc_sysfs_client_type = {
 	.release = rpc_sysfs_client_release,
+	.default_groups = rpc_sysfs_rpc_clnt_groups,
 	.sysfs_ops = &kobj_sysfs_ops,
 	.namespace = rpc_sysfs_client_namespace,
 };
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/5] sunrpc: Add a sysfs file for adding a new xprt
  2025-01-27 21:50 [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Anna Schumaker
                   ` (2 preceding siblings ...)
  2025-01-27 21:50 ` [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information Anna Schumaker
@ 2025-01-27 21:50 ` Anna Schumaker
  2025-01-27 21:50 ` [PATCH v2 5/5] sunrpc: Add a sysfs file for one-step xprt deletion Anna Schumaker
  2025-02-03 13:43 ` [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Benjamin Coddington
  5 siblings, 0 replies; 8+ messages in thread
From: Anna Schumaker @ 2025-01-27 21:50 UTC (permalink / raw)
  To: linux-nfs, trond.myklebust; +Cc: anna

From: Anna Schumaker <anna.schumaker@oracle.com>

Writing to this file will clone the 'main' xprt of an xprt_switch and
add it to be used as an additional connection.

Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
--
v2: Rename the new file to add_xprt
---
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 54 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++++++
 3 files changed, 76 insertions(+)

diff --git a/include/linux/sunrpc/xprtmultipath.h b/include/linux/sunrpc/xprtmultipath.h
index c0514c684b2c..c827c6ef0bc5 100644
--- a/include/linux/sunrpc/xprtmultipath.h
+++ b/include/linux/sunrpc/xprtmultipath.h
@@ -56,6 +56,7 @@ extern void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps,
 		struct rpc_xprt *xprt);
 extern void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
 		struct rpc_xprt *xprt, bool offline);
+extern struct rpc_xprt *rpc_xprt_switch_get_main_xprt(struct rpc_xprt_switch *xps);
 
 extern void xprt_iter_init(struct rpc_xprt_iter *xpi,
 		struct rpc_xprt_switch *xps);
diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index 0d382ab24f1f..a9d155a2b0ea 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -305,6 +305,55 @@ static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj,
 	return ret;
 }
 
+static ssize_t rpc_sysfs_xprt_switch_add_xprt_show(struct kobject *kobj,
+						   struct kobj_attribute *attr,
+						   char *buf)
+{
+	return sprintf(buf, "# add one xprt to this xprt_switch\n");
+}
+
+static ssize_t rpc_sysfs_xprt_switch_add_xprt_store(struct kobject *kobj,
+						    struct kobj_attribute *attr,
+						    const char *buf, size_t count)
+{
+	struct rpc_xprt_switch *xprt_switch =
+		rpc_sysfs_xprt_switch_kobj_get_xprt(kobj);
+	struct xprt_create xprt_create_args;
+	struct rpc_xprt *xprt, *new;
+
+	if (!xprt_switch)
+		return 0;
+
+	xprt = rpc_xprt_switch_get_main_xprt(xprt_switch);
+	if (!xprt)
+		goto out;
+
+	xprt_create_args.ident = xprt->xprt_class->ident;
+	xprt_create_args.net = xprt->xprt_net;
+	xprt_create_args.dstaddr = (struct sockaddr *)&xprt->addr;
+	xprt_create_args.addrlen = xprt->addrlen;
+	xprt_create_args.servername = xprt->servername;
+	xprt_create_args.bc_xprt = xprt->bc_xprt;
+	xprt_create_args.xprtsec = xprt->xprtsec;
+	xprt_create_args.connect_timeout = xprt->connect_timeout;
+	xprt_create_args.reconnect_timeout = xprt->max_reconnect_timeout;
+
+	new = xprt_create_transport(&xprt_create_args);
+	if (IS_ERR_OR_NULL(new)) {
+		count = PTR_ERR(new);
+		goto out_put_xprt;
+	}
+
+	rpc_xprt_switch_add_xprt(xprt_switch, new);
+	xprt_put(new);
+
+out_put_xprt:
+	xprt_put(xprt);
+out:
+	xprt_switch_put(xprt_switch);
+	return count;
+}
+
 static ssize_t rpc_sysfs_xprt_dstaddr_store(struct kobject *kobj,
 					    struct kobj_attribute *attr,
 					    const char *buf, size_t count)
@@ -523,8 +572,13 @@ ATTRIBUTE_GROUPS(rpc_sysfs_xprt);
 static struct kobj_attribute rpc_sysfs_xprt_switch_info =
 	__ATTR(xprt_switch_info, 0444, rpc_sysfs_xprt_switch_info_show, NULL);
 
+static struct kobj_attribute rpc_sysfs_xprt_switch_add_xprt =
+	__ATTR(add_xprt, 0644, rpc_sysfs_xprt_switch_add_xprt_show,
+		rpc_sysfs_xprt_switch_add_xprt_store);
+
 static struct attribute *rpc_sysfs_xprt_switch_attrs[] = {
 	&rpc_sysfs_xprt_switch_info.attr,
+	&rpc_sysfs_xprt_switch_add_xprt.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(rpc_sysfs_xprt_switch);
diff --git a/net/sunrpc/xprtmultipath.c b/net/sunrpc/xprtmultipath.c
index 720d3ba742ec..a07b81ce93c3 100644
--- a/net/sunrpc/xprtmultipath.c
+++ b/net/sunrpc/xprtmultipath.c
@@ -92,6 +92,27 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
 	xprt_put(xprt);
 }
 
+/**
+ * rpc_xprt_switch_get_main_xprt - Get the 'main' xprt for an xprt switch.
+ * @xps: pointer to struct rpc_xprt_switch.
+ */
+struct rpc_xprt *rpc_xprt_switch_get_main_xprt(struct rpc_xprt_switch *xps)
+{
+	struct rpc_xprt_iter xpi;
+	struct rpc_xprt *xprt;
+
+	xprt_iter_init_listall(&xpi, xps);
+
+	xprt = xprt_iter_get_xprt(&xpi);
+	while (xprt && !xprt->main) {
+		xprt_put(xprt);
+		xprt = xprt_iter_get_next(&xpi);
+	}
+
+	xprt_iter_destroy(&xpi);
+	return xprt;
+}
+
 static DEFINE_IDA(rpc_xprtswitch_ids);
 
 void xprt_multipath_cleanup_ids(void)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/5] sunrpc: Add a sysfs file for one-step xprt deletion
  2025-01-27 21:50 [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Anna Schumaker
                   ` (3 preceding siblings ...)
  2025-01-27 21:50 ` [PATCH v2 4/5] sunrpc: Add a sysfs file for adding a new xprt Anna Schumaker
@ 2025-01-27 21:50 ` Anna Schumaker
  2025-02-03 13:43 ` [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Benjamin Coddington
  5 siblings, 0 replies; 8+ messages in thread
From: Anna Schumaker @ 2025-01-27 21:50 UTC (permalink / raw)
  To: linux-nfs, trond.myklebust; +Cc: anna

From: Anna Schumaker <anna.schumaker@oracle.com>

Previously, the admin would need to set the xprt state to "offline"
before attempting to remove. This patch adds a new sysfs attr that does
both these steps in a single call.

Suggested-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
---
 net/sunrpc/sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index a9d155a2b0ea..1e1cb2b3c51a 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -286,6 +286,14 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj,
 	return ret;
 }
 
+static ssize_t rpc_sysfs_xprt_del_xprt_show(struct kobject *kobj,
+					    struct kobj_attribute *attr,
+					    char *buf)
+{
+	return sprintf(buf, "# delete this xprt\n");
+}
+
+
 static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj,
 					       struct kobj_attribute *attr,
 					       char *buf)
@@ -464,6 +472,40 @@ static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
 	return count;
 }
 
+static ssize_t rpc_sysfs_xprt_del_xprt(struct kobject *kobj,
+				       struct kobj_attribute *attr,
+				       const char *buf, size_t count)
+{
+	struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
+	struct rpc_xprt_switch *xps = rpc_sysfs_xprt_kobj_get_xprt_switch(kobj);
+
+	if (!xprt || !xps) {
+		count = 0;
+		goto out;
+	}
+
+	if (xprt->main) {
+		count = -EINVAL;
+		goto release_tasks;
+	}
+
+	if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) {
+		count = -EINTR;
+		goto out_put;
+	}
+
+	xprt_set_offline_locked(xprt, xps);
+	xprt_delete_locked(xprt, xps);
+
+release_tasks:
+	xprt_release_write(xprt, NULL);
+out_put:
+	xprt_put(xprt);
+	xprt_switch_put(xps);
+out:
+	return count;
+}
+
 int rpc_sysfs_init(void)
 {
 	rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj);
@@ -559,12 +601,16 @@ static struct kobj_attribute rpc_sysfs_xprt_info = __ATTR(xprt_info,
 static struct kobj_attribute rpc_sysfs_xprt_change_state = __ATTR(xprt_state,
 	0644, rpc_sysfs_xprt_state_show, rpc_sysfs_xprt_state_change);
 
+static struct kobj_attribute rpc_sysfs_xprt_del = __ATTR(del_xprt,
+	0644, rpc_sysfs_xprt_del_xprt_show, rpc_sysfs_xprt_del_xprt);
+
 static struct attribute *rpc_sysfs_xprt_attrs[] = {
 	&rpc_sysfs_xprt_dstaddr.attr,
 	&rpc_sysfs_xprt_srcaddr.attr,
 	&rpc_sysfs_xprt_xprtsec.attr,
 	&rpc_sysfs_xprt_info.attr,
 	&rpc_sysfs_xprt_change_state.attr,
+	&rpc_sysfs_xprt_del.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(rpc_sysfs_xprt);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information
  2025-01-27 21:50 ` [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information Anna Schumaker
@ 2025-02-03 13:42   ` Benjamin Coddington
  0 siblings, 0 replies; 8+ messages in thread
From: Benjamin Coddington @ 2025-02-03 13:42 UTC (permalink / raw)
  To: Anna Schumaker; +Cc: linux-nfs, trond.myklebust

On 27 Jan 2025, at 16:50, Anna Schumaker wrote:

> From: Anna Schumaker <anna.schumaker@oracle.com>
>
> These files display useful information about the RPC client, such as the
> rpc version number, program name, and maximum number of connections
> allowed.
>
> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
> ---
>  net/sunrpc/sysfs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 73 insertions(+)
>
> diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
> index dc3b7cd70000..0d382ab24f1f 100644
> --- a/net/sunrpc/sysfs.c
> +++ b/net/sunrpc/sysfs.c
> @@ -59,6 +59,16 @@ static struct kobject *rpc_sysfs_object_alloc(const char *name,
>  	return NULL;
>  }
>
> +static inline struct rpc_clnt *
> +rpc_sysfs_client_kobj_get_clnt(struct kobject *kobj)
> +{
> +	struct rpc_sysfs_client *c = container_of(kobj,
> +		struct rpc_sysfs_client, kobject);
> +	struct rpc_clnt *ret = c->clnt;
> +
> +	return refcount_inc_not_zero(&ret->cl_count) ? ret : NULL;
> +}
> +
>  static inline struct rpc_xprt *
>  rpc_sysfs_xprt_kobj_get_xprt(struct kobject *kobj)
>  {
> @@ -86,6 +96,51 @@ rpc_sysfs_xprt_switch_kobj_get_xprt(struct kobject *kobj)
>  	return xprt_switch_get(x->xprt_switch);
>  }
>
> +static ssize_t rpc_sysfs_clnt_version_show(struct kobject *kobj,
> +					   struct kobj_attribute *attr,
> +					   char *buf)
> +{
> +	struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj);
> +	ssize_t ret;
> +
> +	if (!clnt)
> +		return sprintf(buf, "<closed>\n");
> +
> +	ret = sprintf(buf, "%u", clnt->cl_vers);
> +	refcount_dec(&clnt->cl_count);
> +	return ret;
> +}
> +
> +static ssize_t rpc_sysfs_clnt_program_show(struct kobject *kobj,
> +					   struct kobj_attribute *attr,
> +					   char *buf)
> +{
> +	struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj);
> +	ssize_t ret;
> +
> +	if (!clnt)
> +		return sprintf(buf, "<closed>\n");
> +
> +	ret = sprintf(buf, "%s", clnt->cl_program->name);
> +	refcount_dec(&clnt->cl_count);
> +	return ret;
> +}
> +
> +static ssize_t rpc_sysfs_clnt_max_connect_show(struct kobject *kobj,
> +					       struct kobj_attribute *attr,
> +					       char *buf)
> +{
> +	struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj);
> +	ssize_t ret;
> +
> +	if (!clnt)
> +		return sprintf(buf, "<closed>\n");
> +
> +	ret = sprintf(buf, "%u\n", clnt->cl_max_connect);
> +	refcount_dec(&clnt->cl_count);
> +	return ret;
> +}
> +
>  static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj,
>  					   struct kobj_attribute *attr,
>  					   char *buf)
> @@ -423,6 +478,23 @@ static const void *rpc_sysfs_xprt_namespace(const struct kobject *kobj)
>  			    kobject)->xprt->xprt_net;
>  }
>
> +static struct kobj_attribute rpc_sysfs_clnt_version = __ATTR(rpc_version,
> +	0444, rpc_sysfs_clnt_version_show, NULL);
> +
> +static struct kobj_attribute rpc_sysfs_clnt_program = __ATTR(program,
> +	0444, rpc_sysfs_clnt_program_show, NULL);
> +
> +static struct kobj_attribute rpc_sysfs_clnt_max_connect = __ATTR(max_connect,
> +	0644, rpc_sysfs_clnt_max_connect_show, NULL);

Wants 0444 here.

Ben


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements
  2025-01-27 21:50 [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Anna Schumaker
                   ` (4 preceding siblings ...)
  2025-01-27 21:50 ` [PATCH v2 5/5] sunrpc: Add a sysfs file for one-step xprt deletion Anna Schumaker
@ 2025-02-03 13:43 ` Benjamin Coddington
  5 siblings, 0 replies; 8+ messages in thread
From: Benjamin Coddington @ 2025-02-03 13:43 UTC (permalink / raw)
  To: Anna Schumaker; +Cc: linux-nfs, trond.myklebust

On 27 Jan 2025, at 16:50, Anna Schumaker wrote:

> From: Anna Schumaker <anna.schumaker@oracle.com>
>
> These are a handful of improvements that have been in the back of my
> mind for a while. The first patch adds a (read-only) file to the NFS
> client's sysfs collection to check the server's implementation id. The
> remaining patches are on the sunrpc side.
>
> I did look into the 'nconnect' and 'max_connect' NFS client mount
> options and how they interact with adding a new xprt in patch 4. My
> reading is that 'nconnect' is just the initial number of connections
> made by the NFS client during mounting. That shouldn't disallow adding a
> new connection. The 'max_connect' parameter refers to the maximum number
> of unique IP addresses in an xprt switch. The new connection I generate
> is a clone of the main xprt, not a new address, so this doesn't come
> into play either. So I'm convinced adding a new xprt is okay to do here.
>
> Thoughts?
> Anna

Looks great, one minor comment on 3/5.

For series:
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>

Ben


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-02-03 13:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-27 21:50 [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Anna Schumaker
2025-01-27 21:50 ` [PATCH v2 1/5] NFS: Add implid to sysfs Anna Schumaker
2025-01-27 21:50 ` [PATCH v2 2/5] sunrpc: Add a sysfs attr for xprtsec Anna Schumaker
2025-01-27 21:50 ` [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information Anna Schumaker
2025-02-03 13:42   ` Benjamin Coddington
2025-01-27 21:50 ` [PATCH v2 4/5] sunrpc: Add a sysfs file for adding a new xprt Anna Schumaker
2025-01-27 21:50 ` [PATCH v2 5/5] sunrpc: Add a sysfs file for one-step xprt deletion Anna Schumaker
2025-02-03 13:43 ` [PATCH v2 0/5] NFS & SUNRPC: Sysfs Improvements Benjamin Coddington

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox