diff mbox

[24/24,V3] Btrfs: sysfs: add check if super kobject is already initialized

Message ID 1423696868-8971-25-git-send-email-anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Anand Jain Feb. 11, 2015, 11:21 p.m. UTC
This patch will be useful when we have to change the context in which we create
and destroy sysfs fsid and device kobjects. But this is a good change to have it,
as it just does the right thing in general.


Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2->v3: add missing signed-off, update commit
v1->v2: when kobject is already created return EEXIST, not sent to ML

 fs/btrfs/sysfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index f8358d2..6ebbe6c 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -750,10 +750,14 @@  int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 	int error = 0;
 
 	while (fs_devs) {
-		init_completion(&fs_devs->kobj_unregister);
-		fs_devs->super_kobj.kset = btrfs_kset;
-		error = kobject_init_and_add(&fs_devs->super_kobj,
+		if (!fs_devs->super_kobj.state_initialized) {
+			init_completion(&fs_devs->kobj_unregister);
+			fs_devs->super_kobj.kset = btrfs_kset;
+			error = kobject_init_and_add(&fs_devs->super_kobj,
 				&btrfs_ktype, parent, "%pU", fs_devs->fsid);
+		} else {
+			error = -EEXIST;
+		}
 		if (!follow_seed)
 			return error;
 		parent = &fs_devs->super_kobj;