[Devel] [PATCH RH9 10/12] ms/Revert "ext4: simplify kobject usage"

Kirill Tkhai ktkhai at virtuozzo.com
Thu Oct 7 13:20:48 MSK 2021


From: Konstantin Khorenko <khorenko at virtuozzo.com>

This reverts ms commit bc1420ae56266fa2c5a8e452d55f744ca98fe42f.

* we want ext4 to send udev events
* kobject_uevent_env() kobject->kset is defined
  => let's ext4 defines kobject->kset

https://jira.sw.ru/browse/PSBM-127422

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 fs/ext4/sysfs.c |   43 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index 2314f7446592..7af925442a61 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -489,6 +489,13 @@ static void ext4_sb_release(struct kobject *kobj)
 	complete(&sbi->s_kobj_unregister);
 }
 
+static void ext4_kset_release(struct kobject *kobj)
+{
+	struct kset *kset = container_of(kobj, struct kset, kobj);
+
+	kfree(kset);
+}
+
 static const struct sysfs_ops ext4_attr_ops = {
 	.show	= ext4_attr_show,
 	.store	= ext4_attr_store,
@@ -511,7 +518,12 @@ void ext4_notify_error_sysfs(struct ext4_sb_info *sbi)
 	sysfs_notify(&sbi->s_kobj, NULL, "errors_count");
 }
 
-static struct kobject *ext4_root;
+static struct kobj_type ext4_ktype = {
+	.sysfs_ops	= &ext4_attr_ops,
+	.release	= ext4_kset_release,
+};
+
+static struct kset *ext4_kset;
 
 static struct kobject *ext4_feat;
 
@@ -520,8 +532,9 @@ int ext4_register_sysfs(struct super_block *sb)
 	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	int err;
 
+	sbi->s_kobj.kset = ext4_kset;
 	init_completion(&sbi->s_kobj_unregister);
-	err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, ext4_root,
+	err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL,
 				   "%s", sb->s_id);
 	if (err) {
 		kobject_put(&sbi->s_kobj);
@@ -562,18 +575,26 @@ int __init ext4_init_sysfs(void)
 {
 	int ret;
 
-	ext4_root = kobject_create_and_add("ext4", fs_kobj);
-	if (!ext4_root)
+	ext4_kset = kzalloc(sizeof(*ext4_kset), GFP_KERNEL);
+	if (!ext4_kset)
 		return -ENOMEM;
 
+	kobject_set_name(&ext4_kset->kobj, "ext4");
+	ext4_kset->kobj.parent = fs_kobj;
+	ext4_kset->kobj.ktype = &ext4_ktype;
+	ret = kset_register(ext4_kset);
+	if (ret)
+		goto kset_err;
+
 	ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
 	if (!ext4_feat) {
 		ret = -ENOMEM;
-		goto root_err;
+		goto kset_err;
 	}
 
+	ext4_feat->kset = ext4_kset;
 	ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
-				   ext4_root, "features");
+				   NULL, "features");
 	if (ret)
 		goto feat_err;
 
@@ -583,9 +604,9 @@ int __init ext4_init_sysfs(void)
 feat_err:
 	kobject_put(ext4_feat);
 	ext4_feat = NULL;
-root_err:
-	kobject_put(ext4_root);
-	ext4_root = NULL;
+kset_err:
+	kset_unregister(ext4_kset);
+	ext4_kset = NULL;
 	return ret;
 }
 
@@ -593,8 +614,8 @@ void ext4_exit_sysfs(void)
 {
 	kobject_put(ext4_feat);
 	ext4_feat = NULL;
-	kobject_put(ext4_root);
-	ext4_root = NULL;
+	kset_unregister(ext4_kset);
+	ext4_kset = NULL;
 	remove_proc_entry(proc_dirname, NULL);
 	ext4_proc_root = NULL;
 }




More information about the Devel mailing list