Skip to contentSkip to conversation

NFS & SUNRPC Sysfs Improvements

PATCH Superseded Anna Schumaker 5 participants 12 messages Jan 8, 2025 – Jan 20, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Anna Schumaker

author maintainer
#0 lore raw

cover NFS & SUNRPC Sysfs Improvements

From: Anna Schumaker <[email protected]>

These are a few improvements that have been in the back of my mind for a while, and I finally had the chance to work on. The first patch adds a (read-only) file to check the server's implementation id. The remaining two patches are sunrpc side to display the xprtsec in use for each transport and to add a new transport to the xprt switch.

Thoughts?
Anna

Anna Schumaker (3):
NFS: Add implid to sysfs
sunrpc: Add a sysfs attr for xprtsec
sunrpc: Add a sysfs file for adding a new xprt

 fs/nfs/sysfs.c                       | 79 ++++++++++++++++++++++++++
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 83 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++
 4 files changed, 184 insertions(+)
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH 1/3 NFS: Add implid to sysfs

From: Anna Schumaker <[email protected]>

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.

---
 fs/nfs/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
fs/nfs/sysfs.c +79 -0
index 7b59a40d40c0..6b82c92c45bf 100644
@@ -272,6 +272,32 @@ 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;
+	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;
+	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 +335,33 @@ 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)
+{
+	struct nfs_client *clp = server->nfs_client;
+	int ret;
+
+	if (clp->cl_implid && strlen(clp->cl_implid->domain) > 0) {
+		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 +378,32 @@ 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);
+
+/*	if (server->nfs_client->cl_serverowner) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverowner.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);
+	}
+
+	if (server->nfs_client->cl_serverscope) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverscope.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);
+	}
+
+	if (server->nfs_client->cl_implid) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid.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);
+	}*/
 }
 EXPORT_SYMBOL_GPL(nfs_sysfs_add_server);
 
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH 1/3] NFS: Add implid to sysfs

Quoted 5 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

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.

I agree that admins will want to know (and they might not yet know they want to know), good idea!

A couple comments..

Quoted 43 lines
---
 fs/nfs/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
fs/nfs/sysfs.c +26 -0
index 7b59a40d40c0..6b82c92c45bf 100644
@@ -272,6 +272,32 @@ 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;
+	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;
+	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,

fs/nfs/sysfs.c static struct kobj_type nfs_sb_ktype = { · line 344

Quoted 10 lines
fs/nfs/sysfs.c +7 -0
@@ -309,6 +335,33 @@ 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)
+{
+	struct nfs_client *clp = server->nfs_client;
+	int ret;
+
+	if (clp->cl_implid && strlen(clp->cl_implid->domain) > 0) {

Can we create the files and leave them empty if the strings are not set? Having an empty file might be a nice prompt for an implementation to start sending values. I also have a slight preference for a less dynamic sysfs.

Quoted 24 lines
fs/nfs/sysfs.c +20 -0
+		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;

fs/nfs/sysfs.c void nfs_sysfs_add_server(struct nfs_server *server) · line 382

Quoted 5 lines
fs/nfs/sysfs.c +2 -0
@@ -325,6 +378,32 @@ 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);

I think you didn't mean to send the hunk below. :)

Ben

Quoted 29 lines
fs/nfs/sysfs.c +24 -0
+
+/*	if (server->nfs_client->cl_serverowner) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverowner.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);
+	}
+
+	if (server->nfs_client->cl_serverscope) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverscope.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);
+	}
+
+	if (server->nfs_client->cl_implid) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid.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);
+	}*/
 }
 EXPORT_SYMBOL_GPL(nfs_sysfs_add_server);
 
Signature · 1 line
2.47.1
#3 lore raw

Re: [PATCH 1/3] NFS: Add implid to sysfs

Hi Ben,

Quoted 59 lines · Benjamin Coddington
Quoted 5 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

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.

I agree that admins will want to know (and they might not yet know they want to know), good idea!

A couple comments..

Quoted 46 lines
---
 fs/nfs/sysfs.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
fs/nfs/sysfs.c +26 -0
index 7b59a40d40c0..6b82c92c45bf 100644
@@ -272,6 +272,32 @@ 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;
+	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;
+	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 +335,33 @@ static struct kobj_type nfs_sb_ktype = {
 	.child_ns_type = nfs_netns_object_child_ns_type,
 };
 
Quoted 11 lines

fs/nfs/sysfs.c static struct kobj_type nfs_sb_ktype = { · line 344

Quoted 7 lines
fs/nfs/sysfs.c +7 -0
+#if IS_ENABLED(CONFIG_NFS_V4_1)
+static void nfs_sysfs_add_nfsv41_server(struct nfs_server *server)
+{
+	struct nfs_client *clp = server->nfs_client;
+	int ret;
+
+	if (clp->cl_implid && strlen(clp->cl_implid->domain) > 0) {

Can we create the files and leave them empty if the strings are not set? Having an empty file might be a nice prompt for an implementation to start sending values. I also have a slight preference for a less dynamic sysfs.

Sure! I've made that change in my branch.

Quoted 24 lines
Quoted 24 lines
fs/nfs/sysfs.c +20 -0
+		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;
Quoted 8 lines

fs/nfs/sysfs.c void nfs_sysfs_add_server(struct nfs_server *server) · line 382

Quoted 6 lines
fs/nfs/sysfs.c +2 -0
@@ -325,6 +378,32 @@ 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);

I think you didn't mean to send the hunk below. :)

Hah! No, I did not. I've removed it for v2.

Thanks for looking at this!

Anna

Quoted 33 lines

Ben

Quoted 29 lines
fs/nfs/sysfs.c +24 -0
+
+/*	if (server->nfs_client->cl_serverowner) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverowner.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);
+	}
+
+	if (server->nfs_client->cl_serverscope) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_serverscope.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);
+	}
+
+	if (server->nfs_client->cl_implid) {
+		ret = sysfs_create_file_ns(&server->kobj, &nfs_sysfs_attr_implid.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);
+	}*/
 }
 EXPORT_SYMBOL_GPL(nfs_sysfs_add_server);
 
Signature · 1 line
2.47.1
author maintainer
#4 lore raw

PATCH 2/3 sunrpc: Add a sysfs attr for xprtsec

In reply to Anna Schumaker

From: Anna Schumaker <[email protected]>

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

---
 net/sunrpc/sysfs.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
net/sunrpc/sysfs.c +29 -0
index 5c8ecdaaa985..dc3b7cd70000 100644
@@ -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,
Signature · 1 line
2.47.1
author maintainer
#5 lore raw

PATCH 3/3 sunrpc: Add a sysfs file for adding a new xprt

In reply to Anna Schumaker

From: Anna Schumaker <[email protected]>

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

---
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 54 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++++++
 3 files changed, 76 insertions(+)
include/linux/sunrpc/xprtmultipath.h +1 -0
index c0514c684b2c..c827c6ef0bc5 100644
@@ -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);
net/sunrpc/sysfs.c +54 -0

68 lines not on this page · raw message

net/sunrpc/xprtmultipath.c +21 -0
index 720d3ba742ec..a07b81ce93c3 100644
@@ -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)
Signature · 1 line
2.47.1
#6 lore raw

Re: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt

Quoted 4 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

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

I like this too! I'd prefer it was ./add_xprt instead of ./xprt_switch_add_xprt, since the directory already gives the context that you're operating on the xprt_switch.

After happily adding a bunch of xprts, I did have to look up the source to re-learn how to remove them which wasn't obvious from the sysfs structure. You have to write "offline", then "remove" to the xprt_state file. This made me wish there was just a ./xprt-N-tcp/del_xprt that would do both of those..

.. and in stark contrast to my previous preference on less dynamic sysfs, I think that the ./del_xprt shouldn't appear for the "main" xprt (since you can't remove/delete them).

.. all just thoughts, these look good!

Quoted 128 lines
---
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 54 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++++++
 3 files changed, 76 insertions(+)
include/linux/sunrpc/xprtmultipath.h +1 -0
index c0514c684b2c..c827c6ef0bc5 100644
@@ -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);
net/sunrpc/sysfs.c +54 -0
index dc3b7cd70000..ce7dae140770 100644
@@ -250,6 +250,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)
@@ -451,8 +500,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(xprt_switch_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);
net/sunrpc/xprtmultipath.c +21 -0
index 720d3ba742ec..a07b81ce93c3 100644
@@ -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)
Signature · 1 line
2.47.1
#7 lore raw

Re: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt

Quoted 10 lines · Benjamin Coddington
Quoted 4 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

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

I like this too! I'd prefer it was ./add_xprt instead of ./xprt_switch_add_xprt, since the directory already gives the context that you're operating on the xprt_switch.

I'd prefer that too, actually. I don't know what I was thinking going with the longer name, and I've made that change for v2.

Quoted 6 lines

After happily adding a bunch of xprts, I did have to look up the source to re-learn how to remove them which wasn't obvious from the sysfs structure. You have to write "offline", then "remove" to the xprt_state file. This made me wish there was just a ./xprt-N-tcp/del_xprt that would do both of those..

rpcctl xprt remove will already do both of those in one step, if that helps. But I can look at adding in 'del_xprt' if you still think it would help.

Quoted 6 lines

.. and in stark contrast to my previous preference on less dynamic sysfs, I think that the ./del_xprt shouldn't appear for the "main" xprt (since you can't remove/delete them).

.. all just thoughts, these look good!

Thanks!
Anna

Quoted 130 lines
Quoted 129 lines
---
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 54 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++++++
 3 files changed, 76 insertions(+)
include/linux/sunrpc/xprtmultipath.h +1 -0
index c0514c684b2c..c827c6ef0bc5 100644
@@ -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);
net/sunrpc/sysfs.c +54 -0
index dc3b7cd70000..ce7dae140770 100644
@@ -250,6 +250,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)
@@ -451,8 +500,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(xprt_switch_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);
net/sunrpc/xprtmultipath.c +21 -0
index 720d3ba742ec..a07b81ce93c3 100644
@@ -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)
Signature · 1 line
2.47.1
#8 lore raw

Re: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt

In reply to Anna Schumaker
Quoted 63 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

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

---
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 54 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++++++
 3 files changed, 76 insertions(+)
include/linux/sunrpc/xprtmultipath.h +1 -0
index c0514c684b2c..c827c6ef0bc5 100644
@@ -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);
net/sunrpc/sysfs.c +30 -0
index dc3b7cd70000..ce7dae140770 100644
@@ -250,6 +250,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;

net/sunrpc/sysfs.c static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj, · line 292

Quoted 10 lines
net/sunrpc/sysfs.c +10 -0
+       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);

Before adding a new transport don't we need to check that we are not at or over the limit of how many connections we currently have (not over nconnect limit and/or over the session trunking limit)?

Quoted 62 lines
net/sunrpc/sysfs.c +14 -0
+       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)
@@ -451,8 +500,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(xprt_switch_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);
net/sunrpc/xprtmultipath.c +21 -1
index 720d3ba742ec..a07b81ce93c3 100644
@@ -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.47.1

#9 lore raw

Re: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt

Hi Olga,

Quoted 70 lines · Olga Kornievskaia
Quoted 69 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

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

---
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 54 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++++++
 3 files changed, 76 insertions(+)
include/linux/sunrpc/xprtmultipath.h +1 -0
index c0514c684b2c..c827c6ef0bc5 100644
@@ -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);
net/sunrpc/sysfs.c +36 -0
index dc3b7cd70000..ce7dae140770 100644
@@ -250,6 +250,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);
Quoted 8 lines

net/sunrpc/sysfs.c static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj, · line 292

Quoted 4 lines
net/sunrpc/sysfs.c +4 -0
+               goto out_put_xprt;
+       }
+
+       rpc_xprt_switch_add_xprt(xprt_switch, new);

Before adding a new transport don't we need to check that we are not at or over the limit of how many connections we currently have (not over nconnect limit and/or over the session trunking limit)?

That's a good thought, but I'm not really seeing how to do that from inside the sunrpc code. Those are configuration values for the NFS client, and don't get passed down to sunrpc, so sunrpc has no knownledge of them. If you think that'll be a problem, I can look into adding those checks for the next posting.

Anna

Quoted 63 lines
Quoted 63 lines
net/sunrpc/sysfs.c +14 -0
+       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)
@@ -451,8 +500,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(xprt_switch_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);
net/sunrpc/xprtmultipath.c +21 -1
index 720d3ba742ec..a07b81ce93c3 100644
@@ -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.47.1

#10 lore raw

Re: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt

Quoted 83 lines · Anna Schumaker

Hi Olga,

Quoted 70 lines · Olga Kornievskaia
Quoted 69 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

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

---
 include/linux/sunrpc/xprtmultipath.h |  1 +
 net/sunrpc/sysfs.c                   | 54 ++++++++++++++++++++++++++++
 net/sunrpc/xprtmultipath.c           | 21 +++++++++++
 3 files changed, 76 insertions(+)
include/linux/sunrpc/xprtmultipath.h +1 -0
index c0514c684b2c..c827c6ef0bc5 100644
@@ -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);
net/sunrpc/sysfs.c +36 -0
index dc3b7cd70000..ce7dae140770 100644
@@ -250,6 +250,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);
Quoted 8 lines

net/sunrpc/sysfs.c static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj, · line 292

Quoted 4 lines
net/sunrpc/sysfs.c +4 -0
+               goto out_put_xprt;
+       }
+
+       rpc_xprt_switch_add_xprt(xprt_switch, new);

Before adding a new transport don't we need to check that we are not at or over the limit of how many connections we currently have (not over nconnect limit and/or over the session trunking limit)?

Quoted 1 line

That's a good thought, but I'm not really seeing how to do that from inside the sunrpc code. Those are configuration values for the NFS client, and don't get passed down to sunrpc, so sunrpc has no knownledge of them. If you think that'll be a problem, I can look into adding those checks for the next posting.

Seems incorrect to allow going over a limit we enforce at the nfs layer? So I think it is a problem.

The other thing that sticks out. Given that this is version agnostic what happens for v3/v4 and the bc_xprt?

Quoted 67 lines

Anna

Quoted 63 lines
Quoted 63 lines
net/sunrpc/sysfs.c +14 -0
+       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)
@@ -451,8 +500,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(xprt_switch_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);
net/sunrpc/xprtmultipath.c +21 -1
index 720d3ba742ec..a07b81ce93c3 100644
@@ -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.47.1

#11 lore raw

Re: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt

In reply to Anna Schumaker

Hi Anna,

kernel test robot noticed the following build warnings:

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Anna-Schumaker/NFS-Add-implid-to-sysfs/20250109-053732
base:   git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next
patch link:    https://lore.kernel.org/r/20250108213632.260498-4-anna%40kernel.org
patch subject: [PATCH 3/3] sunrpc: Add a sysfs file for adding a new xprt
config: x86_64-randconfig-r073-20250119 (https://download.01.org/0day-ci/archive/20250120/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

New smatch warnings:
net/sunrpc/sysfs.c:288 rpc_sysfs_xprt_switch_add_xprt_store() warn: passing zero to 'PTR_ERR'

vim +/PTR_ERR +288 net/sunrpc/sysfs.c

2b155d9a088aee Anna Schumaker 2025-01-08  260  static ssize_t rpc_sysfs_xprt_switch_add_xprt_store(struct kobject *kobj,
2b155d9a088aee Anna Schumaker 2025-01-08  261  						    struct kobj_attribute *attr,
2b155d9a088aee Anna Schumaker 2025-01-08  262  						    const char *buf, size_t count)
2b155d9a088aee Anna Schumaker 2025-01-08  263  {
2b155d9a088aee Anna Schumaker 2025-01-08  264  	struct rpc_xprt_switch *xprt_switch =
2b155d9a088aee Anna Schumaker 2025-01-08  265  		rpc_sysfs_xprt_switch_kobj_get_xprt(kobj);
2b155d9a088aee Anna Schumaker 2025-01-08  266  	struct xprt_create xprt_create_args;
2b155d9a088aee Anna Schumaker 2025-01-08  267  	struct rpc_xprt *xprt, *new;
2b155d9a088aee Anna Schumaker 2025-01-08  268  
2b155d9a088aee Anna Schumaker 2025-01-08  269  	if (!xprt_switch)
2b155d9a088aee Anna Schumaker 2025-01-08  270  		return 0;
2b155d9a088aee Anna Schumaker 2025-01-08  271  
2b155d9a088aee Anna Schumaker 2025-01-08  272  	xprt = rpc_xprt_switch_get_main_xprt(xprt_switch);
2b155d9a088aee Anna Schumaker 2025-01-08  273  	if (!xprt)
2b155d9a088aee Anna Schumaker 2025-01-08  274  		goto out;
2b155d9a088aee Anna Schumaker 2025-01-08  275  
2b155d9a088aee Anna Schumaker 2025-01-08  276  	xprt_create_args.ident = xprt->xprt_class->ident;
2b155d9a088aee Anna Schumaker 2025-01-08  277  	xprt_create_args.net = xprt->xprt_net;
2b155d9a088aee Anna Schumaker 2025-01-08  278  	xprt_create_args.dstaddr = (struct sockaddr *)&xprt->addr;
2b155d9a088aee Anna Schumaker 2025-01-08  279  	xprt_create_args.addrlen = xprt->addrlen;
2b155d9a088aee Anna Schumaker 2025-01-08  280  	xprt_create_args.servername = xprt->servername;
2b155d9a088aee Anna Schumaker 2025-01-08  281  	xprt_create_args.bc_xprt = xprt->bc_xprt;
2b155d9a088aee Anna Schumaker 2025-01-08  282  	xprt_create_args.xprtsec = xprt->xprtsec;
2b155d9a088aee Anna Schumaker 2025-01-08  283  	xprt_create_args.connect_timeout = xprt->connect_timeout;
2b155d9a088aee Anna Schumaker 2025-01-08  284  	xprt_create_args.reconnect_timeout = xprt->max_reconnect_timeout;
2b155d9a088aee Anna Schumaker 2025-01-08  285  
2b155d9a088aee Anna Schumaker 2025-01-08  286  	new = xprt_create_transport(&xprt_create_args);
2b155d9a088aee Anna Schumaker 2025-01-08  287  	if (IS_ERR_OR_NULL(new)) {

This should just be if (IS_ERR(new)) {, otherwise we end up with a nonsense debate about whether impossible NULL returns should be handled as a error or a success.

2b155d9a088aee Anna Schumaker 2025-01-08 @288  		count = PTR_ERR(new);
2b155d9a088aee Anna Schumaker 2025-01-08  289  		goto out_put_xprt;
2b155d9a088aee Anna Schumaker 2025-01-08  290  	}
2b155d9a088aee Anna Schumaker 2025-01-08  291  
2b155d9a088aee Anna Schumaker 2025-01-08  292  	rpc_xprt_switch_add_xprt(xprt_switch, new);
2b155d9a088aee Anna Schumaker 2025-01-08  293  	xprt_put(new);
2b155d9a088aee Anna Schumaker 2025-01-08  294  
2b155d9a088aee Anna Schumaker 2025-01-08  295  out_put_xprt:
2b155d9a088aee Anna Schumaker 2025-01-08  296  	xprt_put(xprt);
2b155d9a088aee Anna Schumaker 2025-01-08  297  out:
2b155d9a088aee Anna Schumaker 2025-01-08  298  	xprt_switch_put(xprt_switch);
2b155d9a088aee Anna Schumaker 2025-01-08  299  	return count;
2b155d9a088aee Anna Schumaker 2025-01-08  300  }
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki