NFS & SUNRPC: Sysfs Improvements
Subsystems (3)
Anna Schumaker
maintainerv2 cover NFS & SUNRPC: Sysfs Improvements
From: Anna Schumaker <[email protected]>
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(+)
Signature · 1 line
2.48.1
Anna Schumaker
maintainerPATCH v2 1/5 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.
---
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(+)
fs/nfs/sysfs.c +60 -0
@@ -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);
Signature · 1 line
2.48.1
Anna Schumaker
maintainerPATCH v2 2/5 sunrpc: Add a sysfs attr for xprtsec
In reply to Anna SchumakerFrom: 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
@@ -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.48.1
Anna Schumaker
maintainerPATCH v2 3/5 sunrpc: Add a sysfs files for rpc_clnt information
In reply to Anna SchumakerFrom: Anna Schumaker <[email protected]>
These files display useful information about the RPC client, such as the rpc version number, program name, and maximum number of connections allowed.
--- net/sunrpc/sysfs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
net/sunrpc/sysfs.c +73 -0
@@ -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, };
Signature · 1 line
2.48.1
Anna Schumaker
maintainerPATCH v2 4/5 sunrpc: Add a sysfs file for adding a new xprt
In reply to Anna SchumakerFrom: 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.
--
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(+)
include/linux/sunrpc/xprtmultipath.h +1 -0
@@ -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
@@ -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.48.1
Anna Schumaker
maintainerPATCH v2 5/5 sunrpc: Add a sysfs file for one-step xprt deletion
In reply to Anna SchumakerFrom: Anna Schumaker <[email protected]>
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.
--- net/sunrpc/sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
net/sunrpc/sysfs.c +46 -0
@@ -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);
Signature · 1 line
2.48.1
Re: [PATCH v2 3/5] sunrpc: Add a sysfs files for rpc_clnt information
In reply to Anna SchumakerQuoted 86 lines · Anna Schumaker
From: Anna Schumaker <[email protected]>
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 <[email protected]>--- net/sunrpc/sysfs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)net/sunrpc/sysfs.c +55
-0@@ -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;
net/sunrpc/sysfs.c static const void *rpc_sysfs_xprt_namespace(const struct kobject *kobj) · line 488
Quoted 10 lines
net/sunrpc/sysfs.c +8
-0} +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
Quoted 16 lines · Anna Schumaker
From: Anna Schumaker <[email protected]>
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.
Quoted 2 lines
Thoughts?
Anna
Looks great, one minor comment on 3/5.
For series:
Ben