17
17
#include "netns.h"
18
18
#include "sysfs.h"
19
19
20
- struct kobject * nfs_net_kobj ;
21
20
static struct kset * nfs_kset ;
22
21
23
- static void nfs_netns_object_release (struct kobject * kobj )
24
- {
25
- kfree (kobj );
26
- }
27
-
28
22
static void nfs_kset_release (struct kobject * kobj )
29
23
{
30
24
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(
40
34
static struct kobj_type nfs_kset_type = {
41
35
.release = nfs_kset_release ,
42
36
.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 ,
48
37
.child_ns_type = nfs_netns_object_child_ns_type ,
49
38
};
50
39
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
-
67
40
int nfs_sysfs_init (void )
68
41
{
69
42
int ret ;
@@ -88,18 +61,11 @@ int nfs_sysfs_init(void)
88
61
return ret ;
89
62
}
90
63
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
- }
97
64
return 0 ;
98
65
}
99
66
100
67
void nfs_sysfs_exit (void )
101
68
{
102
- kobject_put (nfs_net_kobj );
103
69
kset_unregister (nfs_kset );
104
70
}
105
71
@@ -157,7 +123,6 @@ static void nfs_netns_client_release(struct kobject *kobj)
157
123
kobject );
158
124
159
125
kfree (rcu_dereference_raw (c -> identifier ));
160
- kfree (c );
161
126
}
162
127
163
128
static const void * nfs_netns_client_namespace (const struct kobject * kobj )
@@ -181,6 +146,25 @@ static struct kobj_type nfs_netns_client_type = {
181
146
.namespace = nfs_netns_client_namespace ,
182
147
};
183
148
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
+
184
168
static struct nfs_netns_client * nfs_netns_client_alloc (struct kobject * parent ,
185
169
struct net * net )
186
170
{
@@ -190,9 +174,18 @@ static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent,
190
174
if (p ) {
191
175
p -> net = net ;
192
176
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
+
193
185
if (kobject_init_and_add (& p -> kobject , & nfs_netns_client_type ,
194
- parent , "nfs_client" ) == 0 )
186
+ & p -> nfs_net_kobj , "nfs_client" ) == 0 )
195
187
return p ;
188
+
196
189
kobject_put (& p -> kobject );
197
190
}
198
191
return NULL ;
@@ -202,7 +195,7 @@ void nfs_netns_sysfs_setup(struct nfs_net *netns, struct net *net)
202
195
{
203
196
struct nfs_netns_client * clp ;
204
197
205
- clp = nfs_netns_client_alloc (nfs_net_kobj , net );
198
+ clp = nfs_netns_client_alloc (& nfs_kset -> kobj , net );
206
199
if (clp ) {
207
200
netns -> nfs_client = clp ;
208
201
kobject_uevent (& clp -> kobject , KOBJ_ADD );
@@ -217,6 +210,8 @@ void nfs_netns_sysfs_destroy(struct nfs_net *netns)
217
210
kobject_uevent (& clp -> kobject , KOBJ_REMOVE );
218
211
kobject_del (& clp -> kobject );
219
212
kobject_put (& clp -> kobject );
213
+ kobject_del (& clp -> nfs_net_kobj );
214
+ kobject_put (& clp -> nfs_net_kobj );
220
215
netns -> nfs_client = NULL ;
221
216
}
222
217
}
0 commit comments