summaryrefslogtreecommitdiff
path: root/fs/nfs/sysfs.c
diff options
context:
space:
mode:
authorBenjamin Coddington <bcodding@redhat.com>2023-06-15 14:07:24 -0400
committerTrond Myklebust <trond.myklebust@hammerspace.com>2023-06-19 14:59:07 -0400
commit943aef2dbcf75f81c4574903131bd9559cee4fd1 (patch)
tree5427b6c571e1b7d4fed5295531e6c49ef1467784 /fs/nfs/sysfs.c
parentd5082ace6c8ddefd19b8f7b7164580d972fdb103 (diff)
NFS: Open-code the nfs_kset kset_create_and_add()
In preparation to make objects below /sys/fs/nfs namespace aware, we need to define our own kobj_type for the nfs kset so that we can add the .child_ns_type member in a following patch. No functional change here, only the unrolling of kset_create_and_add(). Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Diffstat (limited to 'fs/nfs/sysfs.c')
-rw-r--r--fs/nfs/sysfs.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index 8f89aeca6272..9adb8ac08d9a 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -25,12 +25,23 @@ static void nfs_netns_object_release(struct kobject *kobj)
kfree(kobj);
}
+static void nfs_kset_release(struct kobject *kobj)
+{
+ struct kset *kset = container_of(kobj, struct kset, kobj);
+ kfree(kset);
+}
+
static const struct kobj_ns_type_operations *nfs_netns_object_child_ns_type(
const struct kobject *kobj)
{
return &net_ns_type_operations;
}
+static struct kobj_type nfs_kset_type = {
+ .release = nfs_kset_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+};
+
static struct kobj_type nfs_netns_object_type = {
.release = nfs_netns_object_release,
.sysfs_ops = &kobj_sysfs_ops,
@@ -55,13 +66,32 @@ static struct kobject *nfs_netns_object_alloc(const char *name,
int nfs_sysfs_init(void)
{
- nfs_kset = kset_create_and_add("nfs", NULL, fs_kobj);
+ int ret;
+
+ nfs_kset = kzalloc(sizeof(*nfs_kset), GFP_KERNEL);
if (!nfs_kset)
return -ENOMEM;
+
+ ret = kobject_set_name(&nfs_kset->kobj, "nfs");
+ if (ret) {
+ kfree(nfs_kset);
+ return ret;
+ }
+
+ nfs_kset->kobj.parent = fs_kobj;
+ nfs_kset->kobj.ktype = &nfs_kset_type;
+ nfs_kset->kobj.kset = NULL;
+
+ ret = kset_register(nfs_kset);
+ if (ret) {
+ kfree(nfs_kset);
+ return ret;
+ }
+
nfs_net_kobj = nfs_netns_object_alloc("net", nfs_kset, NULL);
if (!nfs_net_kobj) {
kset_unregister(nfs_kset);
- nfs_kset = NULL;
+ kfree(nfs_kset);
return -ENOMEM;
}
return 0;