Skip to content

Commit e96f926

Browse files
bcodding-rhTrond Myklebust
authored andcommitted
NFS: Make all of /sys/fs/nfs network-namespace unique
Expand the NFS network-namespaced sysfs from /sys/fs/nfs/net down one level into /sys/fs/nfs by moving the "net" kobject onto struct nfs_netns_client and setting it up during network namespace init. This prepares the way for superblock kobjects within /sys/fs/nfs that will only be visible to matching network namespaces. Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 943aef2 commit e96f926

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

fs/nfs/sysfs.c

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717
#include "netns.h"
1818
#include "sysfs.h"
1919

20-
struct kobject *nfs_net_kobj;
2120
static struct kset *nfs_kset;
2221

23-
static void nfs_netns_object_release(struct kobject *kobj)
24-
{
25-
kfree(kobj);
26-
}
27-
2822
static void nfs_kset_release(struct kobject *kobj)
2923
{
3024
struct kset *kset = container_of(kobj, struct kset, kobj);
@@ -40,30 +34,9 @@ static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
4034
static struct kobj_type nfs_kset_type = {
4135
.release = nfs_kset_release,
4236
.sysfs_ops = &kobj_sysfs_ops,
43-
};
44-
45-
static struct kobj_type nfs_netns_object_type = {
46-
.release = nfs_netns_object_release,
47-
.sysfs_ops = &kobj_sysfs_ops,
4837
.child_ns_type = nfs_netns_object_child_ns_type,
4938
};
5039

51-
static struct kobject *nfs_netns_object_alloc(const char *name,
52-
struct kset *kset, struct kobject *parent)
53-
{
54-
struct kobject *kobj;
55-
56-
kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
57-
if (kobj) {
58-
kobj->kset = kset;
59-
if (kobject_init_and_add(kobj, &nfs_netns_object_type,
60-
parent, "%s", name) == 0)
61-
return kobj;
62-
kobject_put(kobj);
63-
}
64-
return NULL;
65-
}
66-
6740
int nfs_sysfs_init(void)
6841
{
6942
int ret;
@@ -88,18 +61,11 @@ int nfs_sysfs_init(void)
8861
return ret;
8962
}
9063

91-
nfs_net_kobj = nfs_netns_object_alloc("net", nfs_kset, NULL);
92-
if (!nfs_net_kobj) {
93-
kset_unregister(nfs_kset);
94-
kfree(nfs_kset);
95-
return -ENOMEM;
96-
}
9764
return 0;
9865
}
9966

10067
void nfs_sysfs_exit(void)
10168
{
102-
kobject_put(nfs_net_kobj);
10369
kset_unregister(nfs_kset);
10470
}
10571

@@ -157,7 +123,6 @@ static void nfs_netns_client_release(struct kobject *kobj)
157123
kobject);
158124

159125
kfree(rcu_dereference_raw(c->identifier));
160-
kfree(c);
161126
}
162127

163128
static const void *nfs_netns_client_namespace(const struct kobject *kobj)
@@ -181,6 +146,25 @@ static struct kobj_type nfs_netns_client_type = {
181146
.namespace = nfs_netns_client_namespace,
182147
};
183148

149+
static void nfs_netns_object_release(struct kobject *kobj)
150+
{
151+
struct nfs_netns_client *c = container_of(kobj,
152+
struct nfs_netns_client,
153+
nfs_net_kobj);
154+
kfree(c);
155+
}
156+
157+
static const void *nfs_netns_namespace(const struct kobject *kobj)
158+
{
159+
return container_of(kobj, struct nfs_netns_client, nfs_net_kobj)->net;
160+
}
161+
162+
static struct kobj_type nfs_netns_object_type = {
163+
.release = nfs_netns_object_release,
164+
.sysfs_ops = &kobj_sysfs_ops,
165+
.namespace = nfs_netns_namespace,
166+
};
167+
184168
static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent,
185169
struct net *net)
186170
{
@@ -190,9 +174,18 @@ static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent,
190174
if (p) {
191175
p->net = net;
192176
p->kobject.kset = nfs_kset;
177+
p->nfs_net_kobj.kset = nfs_kset;
178+
179+
if (kobject_init_and_add(&p->nfs_net_kobj, &nfs_netns_object_type,
180+
parent, "net") != 0) {
181+
kobject_put(&p->nfs_net_kobj);
182+
return NULL;
183+
}
184+
193185
if (kobject_init_and_add(&p->kobject, &nfs_netns_client_type,
194-
parent, "nfs_client") == 0)
186+
&p->nfs_net_kobj, "nfs_client") == 0)
195187
return p;
188+
196189
kobject_put(&p->kobject);
197190
}
198191
return NULL;
@@ -202,7 +195,7 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
202195
{
203196
struct nfs_netns_client *clp;
204197

205-
clp = nfs_netns_client_alloc(nfs_net_kobj, net);
198+
clp = nfs_netns_client_alloc(&nfs_kset->kobj, net);
206199
if (clp) {
207200
netns->nfs_client = clp;
208201
kobject_uevent(&clp->kobject, KOBJ_ADD);
@@ -217,6 +210,8 @@ void nfs_netns_sysfs_destroy(struct nfs_net *netns)
217210
kobject_uevent(&clp->kobject, KOBJ_REMOVE);
218211
kobject_del(&clp->kobject);
219212
kobject_put(&clp->kobject);
213+
kobject_del(&clp->nfs_net_kobj);
214+
kobject_put(&clp->nfs_net_kobj);
220215
netns->nfs_client = NULL;
221216
}
222217
}

fs/nfs/sysfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
struct nfs_netns_client {
1212
struct kobject kobject;
13+
struct kobject nfs_net_kobj;
1314
struct net *net;
1415
const char __rcu *identifier;
1516
};

0 commit comments

Comments
 (0)