Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sunrpc: Add a sysfs files for rpc_clnt information

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

Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
Link: https://lore.kernel.org/r/20250207204225.594002-4-anna@kernel.org
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by

Anna Schumaker and committed by
Trond Myklebust
88efd79c 41cb320b

+73
+73
net/sunrpc/sysfs.c
··· 59 59 return NULL; 60 60 } 61 61 62 + static inline struct rpc_clnt * 63 + rpc_sysfs_client_kobj_get_clnt(struct kobject *kobj) 64 + { 65 + struct rpc_sysfs_client *c = container_of(kobj, 66 + struct rpc_sysfs_client, kobject); 67 + struct rpc_clnt *ret = c->clnt; 68 + 69 + return refcount_inc_not_zero(&ret->cl_count) ? ret : NULL; 70 + } 71 + 62 72 static inline struct rpc_xprt * 63 73 rpc_sysfs_xprt_kobj_get_xprt(struct kobject *kobj) 64 74 { ··· 94 84 struct rpc_sysfs_xprt_switch, kobject); 95 85 96 86 return xprt_switch_get(x->xprt_switch); 87 + } 88 + 89 + static ssize_t rpc_sysfs_clnt_version_show(struct kobject *kobj, 90 + struct kobj_attribute *attr, 91 + char *buf) 92 + { 93 + struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj); 94 + ssize_t ret; 95 + 96 + if (!clnt) 97 + return sprintf(buf, "<closed>\n"); 98 + 99 + ret = sprintf(buf, "%u", clnt->cl_vers); 100 + refcount_dec(&clnt->cl_count); 101 + return ret; 102 + } 103 + 104 + static ssize_t rpc_sysfs_clnt_program_show(struct kobject *kobj, 105 + struct kobj_attribute *attr, 106 + char *buf) 107 + { 108 + struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj); 109 + ssize_t ret; 110 + 111 + if (!clnt) 112 + return sprintf(buf, "<closed>\n"); 113 + 114 + ret = sprintf(buf, "%s", clnt->cl_program->name); 115 + refcount_dec(&clnt->cl_count); 116 + return ret; 117 + } 118 + 119 + static ssize_t rpc_sysfs_clnt_max_connect_show(struct kobject *kobj, 120 + struct kobj_attribute *attr, 121 + char *buf) 122 + { 123 + struct rpc_clnt *clnt = rpc_sysfs_client_kobj_get_clnt(kobj); 124 + ssize_t ret; 125 + 126 + if (!clnt) 127 + return sprintf(buf, "<closed>\n"); 128 + 129 + ret = sprintf(buf, "%u\n", clnt->cl_max_connect); 130 + refcount_dec(&clnt->cl_count); 131 + return ret; 97 132 } 98 133 99 134 static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj, ··· 478 423 kobject)->xprt->xprt_net; 479 424 } 480 425 426 + static struct kobj_attribute rpc_sysfs_clnt_version = __ATTR(rpc_version, 427 + 0444, rpc_sysfs_clnt_version_show, NULL); 428 + 429 + static struct kobj_attribute rpc_sysfs_clnt_program = __ATTR(program, 430 + 0444, rpc_sysfs_clnt_program_show, NULL); 431 + 432 + static struct kobj_attribute rpc_sysfs_clnt_max_connect = __ATTR(max_connect, 433 + 0444, rpc_sysfs_clnt_max_connect_show, NULL); 434 + 435 + static struct attribute *rpc_sysfs_rpc_clnt_attrs[] = { 436 + &rpc_sysfs_clnt_version.attr, 437 + &rpc_sysfs_clnt_program.attr, 438 + &rpc_sysfs_clnt_max_connect.attr, 439 + NULL, 440 + }; 441 + ATTRIBUTE_GROUPS(rpc_sysfs_rpc_clnt); 442 + 481 443 static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr, 482 444 0644, rpc_sysfs_xprt_dstaddr_show, rpc_sysfs_xprt_dstaddr_store); 483 445 ··· 531 459 532 460 static const struct kobj_type rpc_sysfs_client_type = { 533 461 .release = rpc_sysfs_client_release, 462 + .default_groups = rpc_sysfs_rpc_clnt_groups, 534 463 .sysfs_ops = &kobj_sysfs_ops, 535 464 .namespace = rpc_sysfs_client_namespace, 536 465 };