Skip to content

Commit c5a382e

Browse files
olgakorn1Trond Myklebust
authored andcommitted
sunrpc: Create per-rpc_clnt sysfs kobjects
These will eventually have files placed under them for sysfs operations. Signed-off-by: Anna Schumaker <[email protected]> Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent c441f12 commit c5a382e

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

include/linux/sunrpc/clnt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/sunrpc/xprtmultipath.h>
3030

3131
struct rpc_inode;
32+
struct rpc_sysfs_client;
3233

3334
/*
3435
* The high-level client handle
@@ -71,6 +72,7 @@ struct rpc_clnt {
7172
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
7273
struct dentry *cl_debugfs; /* debugfs directory */
7374
#endif
75+
struct rpc_sysfs_client *cl_sysfs; /* sysfs directory */
7476
/* cl_work is only needed after cl_xpi is no longer used,
7577
* and that are of similar size
7678
*/

net/sunrpc/clnt.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <trace/events/sunrpc.h>
4242

4343
#include "sunrpc.h"
44+
#include "sysfs.h"
4445
#include "netns.h"
4546

4647
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
@@ -300,6 +301,7 @@ static int rpc_client_register(struct rpc_clnt *clnt,
300301
int err;
301302

302303
rpc_clnt_debugfs_register(clnt);
304+
rpc_sysfs_client_setup(clnt, net);
303305

304306
pipefs_sb = rpc_get_sb_net(net);
305307
if (pipefs_sb) {
@@ -327,6 +329,7 @@ static int rpc_client_register(struct rpc_clnt *clnt,
327329
out:
328330
if (pipefs_sb)
329331
rpc_put_sb_net(net);
332+
rpc_sysfs_client_destroy(clnt);
330333
rpc_clnt_debugfs_unregister(clnt);
331334
return err;
332335
}
@@ -733,6 +736,7 @@ int rpc_switch_client_transport(struct rpc_clnt *clnt,
733736

734737
rpc_unregister_client(clnt);
735738
__rpc_clnt_remove_pipedir(clnt);
739+
rpc_sysfs_client_destroy(clnt);
736740
rpc_clnt_debugfs_unregister(clnt);
737741

738742
/*
@@ -879,6 +883,7 @@ static void rpc_free_client_work(struct work_struct *work)
879883
* so they cannot be called in rpciod, so they are handled separately
880884
* here.
881885
*/
886+
rpc_sysfs_client_destroy(clnt);
882887
rpc_clnt_debugfs_unregister(clnt);
883888
rpc_free_clid(clnt);
884889
rpc_clnt_remove_pipedir(clnt);

net/sunrpc/sysfs.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
#include <linux/sunrpc/clnt.h>
66
#include <linux/kobject.h>
7+
#include "sysfs.h"
78

89
static struct kset *rpc_sunrpc_kset;
910
static struct kobject *rpc_sunrpc_client_kobj;
@@ -56,8 +57,68 @@ int rpc_sysfs_init(void)
5657
return 0;
5758
}
5859

60+
static void rpc_sysfs_client_release(struct kobject *kobj)
61+
{
62+
struct rpc_sysfs_client *c;
63+
64+
c = container_of(kobj, struct rpc_sysfs_client, kobject);
65+
kfree(c);
66+
}
67+
68+
static const void *rpc_sysfs_client_namespace(struct kobject *kobj)
69+
{
70+
return container_of(kobj, struct rpc_sysfs_client, kobject)->net;
71+
}
72+
73+
static struct kobj_type rpc_sysfs_client_type = {
74+
.release = rpc_sysfs_client_release,
75+
.sysfs_ops = &kobj_sysfs_ops,
76+
.namespace = rpc_sysfs_client_namespace,
77+
};
78+
5979
void rpc_sysfs_exit(void)
6080
{
6181
kobject_put(rpc_sunrpc_client_kobj);
6282
kset_unregister(rpc_sunrpc_kset);
6383
}
84+
85+
static struct rpc_sysfs_client *rpc_sysfs_client_alloc(struct kobject *parent,
86+
struct net *net,
87+
int clid)
88+
{
89+
struct rpc_sysfs_client *p;
90+
91+
p = kzalloc(sizeof(*p), GFP_KERNEL);
92+
if (p) {
93+
p->net = net;
94+
p->kobject.kset = rpc_sunrpc_kset;
95+
if (kobject_init_and_add(&p->kobject, &rpc_sysfs_client_type,
96+
parent, "clnt-%d", clid) == 0)
97+
return p;
98+
kobject_put(&p->kobject);
99+
}
100+
return NULL;
101+
}
102+
103+
void rpc_sysfs_client_setup(struct rpc_clnt *clnt, struct net *net)
104+
{
105+
struct rpc_sysfs_client *rpc_client;
106+
107+
rpc_client = rpc_sysfs_client_alloc(rpc_sunrpc_client_kobj, net, clnt->cl_clid);
108+
if (rpc_client) {
109+
clnt->cl_sysfs = rpc_client;
110+
kobject_uevent(&rpc_client->kobject, KOBJ_ADD);
111+
}
112+
}
113+
114+
void rpc_sysfs_client_destroy(struct rpc_clnt *clnt)
115+
{
116+
struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs;
117+
118+
if (rpc_client) {
119+
kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE);
120+
kobject_del(&rpc_client->kobject);
121+
kobject_put(&rpc_client->kobject);
122+
clnt->cl_sysfs = NULL;
123+
}
124+
}

net/sunrpc/sysfs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
#ifndef __SUNRPC_SYSFS_H
66
#define __SUNRPC_SYSFS_H
77

8+
struct rpc_sysfs_client {
9+
struct kobject kobject;
10+
struct net *net;
11+
};
12+
813
int rpc_sysfs_init(void);
914
void rpc_sysfs_exit(void);
1015

16+
void rpc_sysfs_client_setup(struct rpc_clnt *clnt, struct net *net);
17+
void rpc_sysfs_client_destroy(struct rpc_clnt *clnt);
18+
1119
#endif

0 commit comments

Comments
 (0)