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

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Benjamin Coddington and committed by
Trond Myklebust
e96f9268 943aef2d

+33 -37
+32 -37
fs/nfs/sysfs.c
··· 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 - 23 - static void nfs_netns_object_release(struct kobject *kobj) 24 - { 25 - kfree(kobj); 26 - } 27 21 28 22 static void nfs_kset_release(struct kobject *kobj) 29 23 { ··· 34 40 static struct kobj_type nfs_kset_type = { 35 41 .release = nfs_kset_release, 36 42 .sysfs_ops = &kobj_sysfs_ops, 37 - }; 38 - 39 - static struct kobj_type nfs_netns_object_type = { 40 - .release = nfs_netns_object_release, 41 - .sysfs_ops = &kobj_sysfs_ops, 42 43 .child_ns_type = nfs_netns_object_child_ns_type, 43 44 }; 44 - 45 - static struct kobject *nfs_netns_object_alloc(const char *name, 46 - struct kset *kset, struct kobject *parent) 47 - { 48 - struct kobject *kobj; 49 - 50 - kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); 51 - if (kobj) { 52 - kobj->kset = kset; 53 - if (kobject_init_and_add(kobj, &nfs_netns_object_type, 54 - parent, "%s", name) == 0) 55 - return kobj; 56 - kobject_put(kobj); 57 - } 58 - return NULL; 59 - } 60 45 61 46 int nfs_sysfs_init(void) 62 47 { ··· 61 88 return ret; 62 89 } 63 90 64 - nfs_net_kobj = nfs_netns_object_alloc("net", nfs_kset, NULL); 65 - if (!nfs_net_kobj) { 66 - kset_unregister(nfs_kset); 67 - kfree(nfs_kset); 68 - return -ENOMEM; 69 - } 70 91 return 0; 71 92 } 72 93 73 94 void nfs_sysfs_exit(void) 74 95 { 75 - kobject_put(nfs_net_kobj); 76 96 kset_unregister(nfs_kset); 77 97 } 78 98 ··· 123 157 kobject); 124 158 125 159 kfree(rcu_dereference_raw(c->identifier)); 126 - kfree(c); 127 160 } 128 161 129 162 static const void *nfs_netns_client_namespace(const struct kobject *kobj) ··· 146 181 .namespace = nfs_netns_client_namespace, 147 182 }; 148 183 184 + static void nfs_netns_object_release(struct kobject *kobj) 185 + { 186 + struct nfs_netns_client *c = container_of(kobj, 187 + struct nfs_netns_client, 188 + nfs_net_kobj); 189 + kfree(c); 190 + } 191 + 192 + static const void *nfs_netns_namespace(const struct kobject *kobj) 193 + { 194 + return container_of(kobj, struct nfs_netns_client, nfs_net_kobj)->net; 195 + } 196 + 197 + static struct kobj_type nfs_netns_object_type = { 198 + .release = nfs_netns_object_release, 199 + .sysfs_ops = &kobj_sysfs_ops, 200 + .namespace = nfs_netns_namespace, 201 + }; 202 + 149 203 static struct nfs_netns_client *nfs_netns_client_alloc(struct kobject *parent, 150 204 struct net *net) 151 205 { ··· 174 190 if (p) { 175 191 p->net = net; 176 192 p->kobject.kset = nfs_kset; 193 + p->nfs_net_kobj.kset = nfs_kset; 194 + 195 + if (kobject_init_and_add(&p->nfs_net_kobj, &nfs_netns_object_type, 196 + parent, "net") != 0) { 197 + kobject_put(&p->nfs_net_kobj); 198 + return NULL; 199 + } 200 + 177 201 if (kobject_init_and_add(&p->kobject, &nfs_netns_client_type, 178 - parent, "nfs_client") == 0) 202 + &p->nfs_net_kobj, "nfs_client") == 0) 179 203 return p; 204 + 180 205 kobject_put(&p->kobject); 181 206 } 182 207 return NULL; ··· 195 202 { 196 203 struct nfs_netns_client *clp; 197 204 198 - clp = nfs_netns_client_alloc(nfs_net_kobj, net); 205 + clp = nfs_netns_client_alloc(&nfs_kset->kobj, net); 199 206 if (clp) { 200 207 netns->nfs_client = clp; 201 208 kobject_uevent(&clp->kobject, KOBJ_ADD); ··· 210 217 kobject_uevent(&clp->kobject, KOBJ_REMOVE); 211 218 kobject_del(&clp->kobject); 212 219 kobject_put(&clp->kobject); 220 + kobject_del(&clp->nfs_net_kobj); 221 + kobject_put(&clp->nfs_net_kobj); 213 222 netns->nfs_client = NULL; 214 223 } 215 224 }
+1
fs/nfs/sysfs.h
··· 10 10 11 11 struct nfs_netns_client { 12 12 struct kobject kobject; 13 + struct kobject nfs_net_kobj; 13 14 struct net *net; 14 15 const char __rcu *identifier; 15 16 };