Skip to content

Commit c441f12

Browse files
olgakorn1Trond Myklebust
authored andcommitted
sunrpc: Create a client/ subdirectory in the sunrpc sysfs
For network namespace separation. Signed-off-by: Anna Schumaker <[email protected]> Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 7467874 commit c441f12

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

net/sunrpc/sysfs.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,62 @@
22
/*
33
* Copyright (c) 2020 Anna Schumaker <[email protected]>
44
*/
5+
#include <linux/sunrpc/clnt.h>
56
#include <linux/kobject.h>
67

78
static struct kset *rpc_sunrpc_kset;
9+
static struct kobject *rpc_sunrpc_client_kobj;
10+
11+
static void rpc_sysfs_object_release(struct kobject *kobj)
12+
{
13+
kfree(kobj);
14+
}
15+
16+
static const struct kobj_ns_type_operations *
17+
rpc_sysfs_object_child_ns_type(struct kobject *kobj)
18+
{
19+
return &net_ns_type_operations;
20+
}
21+
22+
static struct kobj_type rpc_sysfs_object_type = {
23+
.release = rpc_sysfs_object_release,
24+
.sysfs_ops = &kobj_sysfs_ops,
25+
.child_ns_type = rpc_sysfs_object_child_ns_type,
26+
};
27+
28+
static struct kobject *rpc_sysfs_object_alloc(const char *name,
29+
struct kset *kset,
30+
struct kobject *parent)
31+
{
32+
struct kobject *kobj;
33+
34+
kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
35+
if (kobj) {
36+
kobj->kset = kset;
37+
if (kobject_init_and_add(kobj, &rpc_sysfs_object_type,
38+
parent, "%s", name) == 0)
39+
return kobj;
40+
kobject_put(kobj);
41+
}
42+
return NULL;
43+
}
844

945
int rpc_sysfs_init(void)
1046
{
1147
rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj);
1248
if (!rpc_sunrpc_kset)
1349
return -ENOMEM;
50+
rpc_sunrpc_client_kobj = rpc_sysfs_object_alloc("client", rpc_sunrpc_kset, NULL);
51+
if (!rpc_sunrpc_client_kobj) {
52+
kset_unregister(rpc_sunrpc_kset);
53+
rpc_sunrpc_client_kobj = NULL;
54+
return -ENOMEM;
55+
}
1456
return 0;
1557
}
1658

1759
void rpc_sysfs_exit(void)
1860
{
61+
kobject_put(rpc_sunrpc_client_kobj);
1962
kset_unregister(rpc_sunrpc_kset);
2063
}

0 commit comments

Comments
 (0)