linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added
@ 2015-02-08 23:56 Anand Jain
  2015-02-08 23:56 ` [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data Anand Jain
                   ` (24 more replies)
  0 siblings, 25 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

This patch set will provide a framework and help to create attributes
from the structure btrfs_fs_devices which are available even before
fs_info is created. So by moving the parent kobject super_kobj from
fs_info to btrfs_fs_devices, it will help to create attributes
from the btrfs_fs_devices as well.
    
Just to note, this does not change any of the existing btrfs sysfs
external kobject names and its attributes and not even the life
cycle of them. Changes are internal only. And to ensure the same,
this path has been tested with various device operations and,
checking and comparing the sysfs kobjects and attributes with
sysfs kobject and attributes with out this patch, and they remain
same. These test cases are added to the progs as test-btrfs-devmgt.sh,
its patch is below as well.

v1->v2:
  . adds fresh set of patches from 12 to 24 to support seed fsids
  on btrfs sysfs layout and the related frame work changes
  . the patches 1 to 12 has no changes from the previous submit

Anand Jain (24):
  Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the
    kobject data
  Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion()
    twice
  Btrfs: sysfs: fix, undo sysfs device links
  Btrfs: sysfs: fix, kobject pointer clean up needed after kobject
    release
  Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy
  Btrfs: sysfs: reorder the kobject creations
  Btrfs: sysfs: rename __btrfs_sysfs_remove_one to
    btrfs_sysfs_remove_fsid
  Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create
    sysfs fsid
  Btrfs: sysfs: let default_attrs be separate from the kset
  Btrfs: sysfs: separate device kobject and its attribute creation
  Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to
    btrfs_fs_devices
  Btrfs: sysfs: add pointer to access fs_info from fs_devices
  Btrfs: introduce btrfs_get_fs_uuids
  Btrfs: sysfs: provide framework to remove all fsid kobject
  Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of
    fs_info
  Btrfs: sysfs btrfs_kobj_rm_device() pass fs_devices instead of fs_info
  Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static
  Btrfs: sysfs: make btrfs_sysfs_add_device() non static
  Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it non static
  Btrfs: sysfs: separate kobject and attribute creation
  Btrfs: sysfs: add support to add parent for fsid
  Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue
  Btrfs: sysfs: support seed devices in the sysfs layout
  Btrfs: sysfs: add check if super kobject is already initialized

 fs/btrfs/ctree.h       |   3 -
 fs/btrfs/dev-replace.c |   4 +-
 fs/btrfs/disk-io.c     |  19 +++++-
 fs/btrfs/sysfs.c       | 180 ++++++++++++++++++++++++++++++++++++++-----------
 fs/btrfs/sysfs.h       |  12 ++--
 fs/btrfs/volumes.c     |  46 +++++++++++--
 fs/btrfs/volumes.h     |   7 ++
 7 files changed, 214 insertions(+), 57 deletions(-)

-- 
2.0.0.153.g79dcccc


^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 02/24] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice Anand Jain
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

The following test case fails indicating that, thread tried to init an initialized object.

kernel: [232104.016513] kobject (ffff880006c1c980): tried to init an initialized object, something is seriously wrong.

btrfs_sysfs_remove_one() self test code:

open_tree()
{
 ::
        ret = btrfs_sysfs_add_one(fs_info);
	if (ret) {
              pr_err("BTRFS: failed to init sysfs interface: %d\n", ret);
                goto fail_block_groups;
        }
+       btrfs_sysfs_remove_one(fs_info);
+       ret = btrfs_sysfs_add_one(fs_info);
+       if (ret) {
+               pr_err("BTRFS: failed to init sysfs interface: %d\n", ret);
+               goto fail_block_groups;
+       }

cleaning up the unregistered kobject fixes this.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 92db3f6..68dcd17 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -439,6 +439,8 @@ static struct attribute *btrfs_attrs[] = {
 static void btrfs_release_super_kobj(struct kobject *kobj)
 {
 	struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+
+	memset(&fs_info->super_kobj, 0, sizeof(struct kobject));
 	complete(&fs_info->kobj_unregister);
 }
 
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 02/24] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
  2015-02-08 23:56 ` [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 03/24] Btrfs: sysfs: fix, undo sysfs device links Anand Jain
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

kobject_unregister is to handle the release of the kobject,
its completion init is being called in btrfs_sysfs_add_one(),
so we don't have to do the same in the open_ctree() again.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/disk-io.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8c63419..0cd6550 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2238,7 +2238,6 @@ int open_ctree(struct super_block *sb,
 	mutex_init(&fs_info->delalloc_root_mutex);
 	seqlock_init(&fs_info->profiles_lock);
 
-	init_completion(&fs_info->kobj_unregister);
 	INIT_LIST_HEAD(&fs_info->dirty_cowonly_roots);
 	INIT_LIST_HEAD(&fs_info->space_info);
 	INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 03/24] Btrfs: sysfs: fix, undo sysfs device links
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
  2015-02-08 23:56 ` [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data Anand Jain
  2015-02-08 23:56 ` [PATCH 02/24] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 04/24] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release Anand Jain
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

Theoritically need to remove the device links attributes, but since its entire device
kobject was removed, so there wasn't any issue of about it. Just do it nicely.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 68dcd17..adfac3e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -522,6 +522,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 		kobject_del(fs_info->space_info_kobj);
 		kobject_put(fs_info->space_info_kobj);
 	}
+	btrfs_kobj_rm_device(fs_info, NULL);
 	kobject_del(fs_info->device_dir_kobj);
 	kobject_put(fs_info->device_dir_kobj);
 	addrm_unknown_feature_attrs(fs_info, false);
@@ -604,6 +605,8 @@ static void init_feature_attrs(void)
 	}
 }
 
+/* when one_device is NULL, it removes all device links */
+
 int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 		struct btrfs_device *one_device)
 {
@@ -621,6 +624,20 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 						disk_kobj->name);
 	}
 
+	if (one_device)
+		return 0;
+
+	list_for_each_entry(one_device,
+			&fs_info->fs_devices->devices, dev_list) {
+		if (!one_device->bdev)
+			continue;
+		disk = one_device->bdev->bd_part;
+		disk_kobj = &part_to_dev(disk)->kobj;
+
+		sysfs_remove_link(fs_info->device_dir_kobj,
+						disk_kobj->name);
+	}
+
 	return 0;
 }
 
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 04/24] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (2 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 03/24] Btrfs: sysfs: fix, undo sysfs device links Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 05/24] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy Anand Jain
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

The sysfs clean up self test like in the below code fails, since
fs_info->device_dir_kobject still points to its stale kobject.
Reseting this pointer will help to fix this.

open_ctree()
{

ret = btrfs_sysfs_add_one(fs_info);
::
+       btrfs_sysfs_remove_one(fs_info);
+       ret = btrfs_sysfs_add_one(fs_info);
+       if (ret) {
+               pr_err("BTRFS: failed to init sysfs interface: %d\n", ret);
+               goto fail_block_groups;
+       }

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index adfac3e..15fead2 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -525,6 +525,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 	btrfs_kobj_rm_device(fs_info, NULL);
 	kobject_del(fs_info->device_dir_kobj);
 	kobject_put(fs_info->device_dir_kobj);
+	fs_info->device_dir_kobj = NULL;
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group);
 	__btrfs_sysfs_remove_one(fs_info);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 05/24] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (3 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 04/24] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 06/24] Btrfs: sysfs: reorder the kobject creations Anand Jain
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

Since the failure code in the btrfs_sysfs_add_one() can
call btrfs_sysfs_remove_one() even before device_dir_kobj
has been created we need to check if its null.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 15fead2..506f7e4 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -522,10 +522,12 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 		kobject_del(fs_info->space_info_kobj);
 		kobject_put(fs_info->space_info_kobj);
 	}
-	btrfs_kobj_rm_device(fs_info, NULL);
-	kobject_del(fs_info->device_dir_kobj);
-	kobject_put(fs_info->device_dir_kobj);
-	fs_info->device_dir_kobj = NULL;
+	if (fs_info->device_dir_kobj) {
+		btrfs_kobj_rm_device(fs_info, NULL);
+		kobject_del(fs_info->device_dir_kobj);
+		kobject_put(fs_info->device_dir_kobj);
+		fs_info->device_dir_kobj = NULL;
+	}
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group);
 	__btrfs_sysfs_remove_one(fs_info);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 06/24] Btrfs: sysfs: reorder the kobject creations
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (4 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 05/24] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 07/24] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid Anand Jain
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

As of now the order in which the kobjects are created
at btrfs_sysfs_add_one() is..
 fsid
 features
 unknown features (dynamic features)
 devices.

Since we would move fsid and device kobject to fs_devices
from fs_info structure, this patch will reorder in which
the kobjects are created as below.
 fsid
 devices
 features
 unknown features (dynamic features)

And hence the btrfs_sysfs_remove_one() will follow the same
in reverse order. and the device kobject destroy now can
be moved into the function __btrfs_sysfs_remove_one()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 506f7e4..c3e7f06 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -510,6 +510,13 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
 
 static void __btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 {
+	if (fs_info->device_dir_kobj) {
+		btrfs_kobj_rm_device(fs_info, NULL);
+		kobject_del(fs_info->device_dir_kobj);
+		kobject_put(fs_info->device_dir_kobj);
+		fs_info->device_dir_kobj = NULL;
+	}
+
 	kobject_del(&fs_info->super_kobj);
 	kobject_put(&fs_info->super_kobj);
 	wait_for_completion(&fs_info->kobj_unregister);
@@ -522,12 +529,6 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 		kobject_del(fs_info->space_info_kobj);
 		kobject_put(fs_info->space_info_kobj);
 	}
-	if (fs_info->device_dir_kobj) {
-		btrfs_kobj_rm_device(fs_info, NULL);
-		kobject_del(fs_info->device_dir_kobj);
-		kobject_put(fs_info->device_dir_kobj);
-		fs_info->device_dir_kobj = NULL;
-	}
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group);
 	__btrfs_sysfs_remove_one(fs_info);
@@ -700,6 +701,12 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 	if (error)
 		return error;
 
+	error = btrfs_kobj_add_device(fs_info, NULL);
+	if (error) {
+		__btrfs_sysfs_remove_one(fs_info);
+		return error;
+	}
+
 	error = sysfs_create_group(&fs_info->super_kobj,
 				   &btrfs_feature_attr_group);
 	if (error) {
@@ -711,10 +718,6 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 	if (error)
 		goto failure;
 
-	error = btrfs_kobj_add_device(fs_info, NULL);
-	if (error)
-		goto failure;
-
 	fs_info->space_info_kobj = kobject_create_and_add("allocation",
 						  &fs_info->super_kobj);
 	if (!fs_info->space_info_kobj) {
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 07/24] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (5 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 06/24] Btrfs: sysfs: reorder the kobject creations Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 08/24] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid Anand Jain
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index c3e7f06..c923e8b 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -508,7 +508,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
 	return 0;
 }
 
-static void __btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
+static void btrfs_sysfs_remove_fsid(struct btrfs_fs_info *fs_info)
 {
 	if (fs_info->device_dir_kobj) {
 		btrfs_kobj_rm_device(fs_info, NULL);
@@ -531,7 +531,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 	}
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group);
-	__btrfs_sysfs_remove_one(fs_info);
+	btrfs_sysfs_remove_fsid(fs_info);
 }
 
 const char * const btrfs_feature_set_names[3] = {
@@ -703,14 +703,14 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 
 	error = btrfs_kobj_add_device(fs_info, NULL);
 	if (error) {
-		__btrfs_sysfs_remove_one(fs_info);
+		btrfs_sysfs_remove_fsid(fs_info);
 		return error;
 	}
 
 	error = sysfs_create_group(&fs_info->super_kobj,
 				   &btrfs_feature_attr_group);
 	if (error) {
-		__btrfs_sysfs_remove_one(fs_info);
+		btrfs_sysfs_remove_fsid(fs_info);
 		return error;
 	}
 
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 08/24] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (6 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 07/24] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 09/24] Btrfs: sysfs: let default_attrs be separate from the kset Anand Jain
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

We need it in a seperate function so that it can be called from the
device discovery thread as well.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index c923e8b..f42d8fd 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -690,7 +690,12 @@ static struct dentry *btrfs_debugfs_root_dentry;
 /* Debugging tunables and exported data */
 u64 btrfs_debugfs_test;
 
-int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
+/*
+ * Can be called by the device discovery thread.
+ * And parent can be specified for seed device
+ */
+int btrfs_sysfs_add_fsid(struct btrfs_fs_info *fs_info,
+				struct kobject *parent)
 {
 	int error;
 
@@ -698,6 +703,14 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 	fs_info->super_kobj.kset = btrfs_kset;
 	error = kobject_init_and_add(&fs_info->super_kobj, &btrfs_ktype, NULL,
 				     "%pU", fs_info->fsid);
+	return error;
+}
+
+int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
+{
+	int error;
+
+	error = btrfs_sysfs_add_fsid(fs_info, NULL);
 	if (error)
 		return error;
 
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 09/24] Btrfs: sysfs: let default_attrs be separate from the kset
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (7 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 08/24] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 10/24] Btrfs: sysfs: separate device kobject and its attribute creation Anand Jain
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

As of now btrfs_attrs are provided using the default_attrs through
the kset. Separate them and create the default_attrs using the
sysfs_create_files instead. By doing this we will have the
flexibility that device discovery thread could create fsid
kobject.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index f42d8fd..5208a49 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -428,7 +428,7 @@ static ssize_t btrfs_clone_alignment_show(struct kobject *kobj,
 
 BTRFS_ATTR(clone_alignment, btrfs_clone_alignment_show);
 
-static struct attribute *btrfs_attrs[] = {
+static const struct attribute *btrfs_attrs[] = {
 	BTRFS_ATTR_PTR(label),
 	BTRFS_ATTR_PTR(nodesize),
 	BTRFS_ATTR_PTR(sectorsize),
@@ -447,7 +447,6 @@ static void btrfs_release_super_kobj(struct kobject *kobj)
 static struct kobj_type btrfs_ktype = {
 	.sysfs_ops	= &kobj_sysfs_ops,
 	.release	= btrfs_release_super_kobj,
-	.default_attrs	= btrfs_attrs,
 };
 
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
@@ -531,6 +530,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 	}
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group);
+	sysfs_remove_files(&fs_info->super_kobj, btrfs_attrs);
 	btrfs_sysfs_remove_fsid(fs_info);
 }
 
@@ -720,13 +720,17 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 		return error;
 	}
 
-	error = sysfs_create_group(&fs_info->super_kobj,
-				   &btrfs_feature_attr_group);
+	error = sysfs_create_files(&fs_info->super_kobj, btrfs_attrs);
 	if (error) {
 		btrfs_sysfs_remove_fsid(fs_info);
 		return error;
 	}
 
+	error = sysfs_create_group(&fs_info->super_kobj,
+				   &btrfs_feature_attr_group);
+	if (error)
+		goto failure;
+
 	error = addrm_unknown_feature_attrs(fs_info, true);
 	if (error)
 		goto failure;
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 10/24] Btrfs: sysfs: separate device kobject and its attribute creation
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (8 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 09/24] Btrfs: sysfs: let default_attrs be separate from the kset Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 11/24] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices Anand Jain
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

Separate device kobject and its attribute creation so that device
kobject can be created from the device discovery thread.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 5208a49..2cb4c69 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -645,13 +645,8 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 	return 0;
 }
 
-int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
-		struct btrfs_device *one_device)
+int btrfs_sysfs_add_device(struct btrfs_fs_info *fs_info)
 {
-	int error = 0;
-	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
-	struct btrfs_device *dev;
-
 	if (!fs_info->device_dir_kobj)
 		fs_info->device_dir_kobj = kobject_create_and_add("devices",
 						&fs_info->super_kobj);
@@ -659,6 +654,20 @@ int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
 	if (!fs_info->device_dir_kobj)
 		return -ENOMEM;
 
+	return 0;
+}
+
+int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
+		struct btrfs_device *one_device)
+{
+	int error = 0;
+	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
+	struct btrfs_device *dev;
+
+	error = btrfs_sysfs_add_device(fs_info);
+	if (error)
+		return error;
+
 	list_for_each_entry(dev, &fs_devices->devices, dev_list) {
 		struct hd_struct *disk;
 		struct kobject *disk_kobj;
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 11/24] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (9 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 10/24] Btrfs: sysfs: separate device kobject and its attribute creation Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 12/24] Btrfs: sysfs: add pointer to access fs_info from fs_devices Anand Jain
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

This patch will provide a framework and help to create attributes
from the structure btrfs_fs_devices which are available even before
fs_info is created. So by moving the parent kobject super_kobj from
fs_info to btrfs_fs_devices, it will help to create attributes
from the btrfs_fs_devices as well.

Patches on top of this patch now will be able to create the
sys/fs/btrfs/fsid kobject and attributes from btrfs_fs_devices
when devices are scanned and registered to the kernel.

Just to note, this does not change any of the existing btrfs sysfs
external kobject names and its attributes and not even the life
cycle of them. Changes are internal only. And to ensure the same,
this path has been tested with various device operations and,
checking and comparing the sysfs kobjects and attributes with
sysfs kobject and attributes with out this patch, and they remain
same.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/ctree.h   |  3 --
 fs/btrfs/sysfs.c   | 88 ++++++++++++++++++++++++++++++------------------------
 fs/btrfs/volumes.c |  3 +-
 fs/btrfs/volumes.h |  5 ++++
 4 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 7e60741..9493b91 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1580,10 +1580,7 @@ struct btrfs_fs_info {
 	struct task_struct *cleaner_kthread;
 	int thread_pool_size;
 
-	struct kobject super_kobj;
 	struct kobject *space_info_kobj;
-	struct kobject *device_dir_kobj;
-	struct completion kobj_unregister;
 	int do_barriers;
 	int closing;
 	int log_root_recovering;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 2cb4c69..ac15fbb 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -33,6 +33,7 @@
 #include "volumes.h"
 
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj);
+static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj);
 
 static u64 get_features(struct btrfs_fs_info *fs_info,
 			enum btrfs_feature_set set)
@@ -438,10 +439,10 @@ static const struct attribute *btrfs_attrs[] = {
 
 static void btrfs_release_super_kobj(struct kobject *kobj)
 {
-	struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+	struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj);
 
-	memset(&fs_info->super_kobj, 0, sizeof(struct kobject));
-	complete(&fs_info->kobj_unregister);
+	memset(&fs_devs->super_kobj, 0, sizeof(struct kobject));
+	complete(&fs_devs->kobj_unregister);
 }
 
 static struct kobj_type btrfs_ktype = {
@@ -449,11 +450,18 @@ static struct kobj_type btrfs_ktype = {
 	.release	= btrfs_release_super_kobj,
 };
 
+static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj)
+{
+	if (kobj->ktype != &btrfs_ktype)
+		return NULL;
+	return container_of(kobj, struct btrfs_fs_devices, super_kobj);
+}
+
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
 {
 	if (kobj->ktype != &btrfs_ktype)
 		return NULL;
-	return container_of(kobj, struct btrfs_fs_info, super_kobj);
+	return to_fs_devs(kobj)->fs_info;
 }
 
 #define NUM_FEATURE_BITS 64
@@ -494,12 +502,12 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
 			attrs[0] = &fa->kobj_attr.attr;
 			if (add) {
 				int ret;
-				ret = sysfs_merge_group(&fs_info->super_kobj,
+				ret = sysfs_merge_group(&fs_info->fs_devices->super_kobj,
 							&agroup);
 				if (ret)
 					return ret;
 			} else
-				sysfs_unmerge_group(&fs_info->super_kobj,
+				sysfs_unmerge_group(&fs_info->fs_devices->super_kobj,
 						    &agroup);
 		}
 
@@ -507,18 +515,17 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
 	return 0;
 }
 
-static void btrfs_sysfs_remove_fsid(struct btrfs_fs_info *fs_info)
+static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 {
-	if (fs_info->device_dir_kobj) {
-		btrfs_kobj_rm_device(fs_info, NULL);
-		kobject_del(fs_info->device_dir_kobj);
-		kobject_put(fs_info->device_dir_kobj);
-		fs_info->device_dir_kobj = NULL;
+	if (fs_devs->device_dir_kobj) {
+		kobject_del(fs_devs->device_dir_kobj);
+		kobject_put(fs_devs->device_dir_kobj);
+		fs_devs->device_dir_kobj = NULL;
 	}
 
-	kobject_del(&fs_info->super_kobj);
-	kobject_put(&fs_info->super_kobj);
-	wait_for_completion(&fs_info->kobj_unregister);
+	kobject_del(&fs_devs->super_kobj);
+	kobject_put(&fs_devs->super_kobj);
+	wait_for_completion(&fs_devs->kobj_unregister);
 }
 
 void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
@@ -529,9 +536,10 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 		kobject_put(fs_info->space_info_kobj);
 	}
 	addrm_unknown_feature_attrs(fs_info, false);
-	sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group);
-	sysfs_remove_files(&fs_info->super_kobj, btrfs_attrs);
-	btrfs_sysfs_remove_fsid(fs_info);
+	sysfs_remove_group(&fs_info->fs_devices->super_kobj, &btrfs_feature_attr_group);
+	sysfs_remove_files(&fs_info->fs_devices->super_kobj, btrfs_attrs);
+	btrfs_kobj_rm_device(fs_info, NULL);
+	btrfs_sysfs_remove_fsid(fs_info->fs_devices);
 }
 
 const char * const btrfs_feature_set_names[3] = {
@@ -617,14 +625,14 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 	struct hd_struct *disk;
 	struct kobject *disk_kobj;
 
-	if (!fs_info->device_dir_kobj)
+	if (!fs_info->fs_devices->device_dir_kobj)
 		return -EINVAL;
 
 	if (one_device && one_device->bdev) {
 		disk = one_device->bdev->bd_part;
 		disk_kobj = &part_to_dev(disk)->kobj;
 
-		sysfs_remove_link(fs_info->device_dir_kobj,
+		sysfs_remove_link(fs_info->fs_devices->device_dir_kobj,
 						disk_kobj->name);
 	}
 
@@ -638,20 +646,20 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 		disk = one_device->bdev->bd_part;
 		disk_kobj = &part_to_dev(disk)->kobj;
 
-		sysfs_remove_link(fs_info->device_dir_kobj,
+		sysfs_remove_link(fs_info->fs_devices->device_dir_kobj,
 						disk_kobj->name);
 	}
 
 	return 0;
 }
 
-int btrfs_sysfs_add_device(struct btrfs_fs_info *fs_info)
+int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs)
 {
-	if (!fs_info->device_dir_kobj)
-		fs_info->device_dir_kobj = kobject_create_and_add("devices",
-						&fs_info->super_kobj);
+	if (!fs_devs->device_dir_kobj)
+		fs_devs->device_dir_kobj = kobject_create_and_add("devices",
+						&fs_devs->super_kobj);
 
-	if (!fs_info->device_dir_kobj)
+	if (!fs_devs->device_dir_kobj)
 		return -ENOMEM;
 
 	return 0;
@@ -664,7 +672,7 @@ int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
 	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
 	struct btrfs_device *dev;
 
-	error = btrfs_sysfs_add_device(fs_info);
+	error = btrfs_sysfs_add_device(fs_devices);
 	if (error)
 		return error;
 
@@ -681,7 +689,7 @@ int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
 		disk = dev->bdev->bd_part;
 		disk_kobj = &part_to_dev(disk)->kobj;
 
-		error = sysfs_create_link(fs_info->device_dir_kobj,
+		error = sysfs_create_link(fs_devices->device_dir_kobj,
 					  disk_kobj, disk_kobj->name);
 		if (error)
 			break;
@@ -703,39 +711,41 @@ u64 btrfs_debugfs_test;
  * Can be called by the device discovery thread.
  * And parent can be specified for seed device
  */
-int btrfs_sysfs_add_fsid(struct btrfs_fs_info *fs_info,
+static int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 				struct kobject *parent)
 {
 	int error;
 
-	init_completion(&fs_info->kobj_unregister);
-	fs_info->super_kobj.kset = btrfs_kset;
-	error = kobject_init_and_add(&fs_info->super_kobj, &btrfs_ktype, NULL,
-				     "%pU", fs_info->fsid);
+	init_completion(&fs_devs->kobj_unregister);
+	fs_devs->super_kobj.kset = btrfs_kset;
+	error = kobject_init_and_add(&fs_devs->super_kobj, &btrfs_ktype, NULL,
+				     "%pU", fs_devs->fsid);
 	return error;
 }
 
 int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 {
 	int error;
+	struct btrfs_fs_devices *fs_devs = fs_info->fs_devices;
+	struct kobject *super_kobj = &fs_devs->super_kobj;
 
-	error = btrfs_sysfs_add_fsid(fs_info, NULL);
+	error = btrfs_sysfs_add_fsid(fs_devs, NULL);
 	if (error)
 		return error;
 
 	error = btrfs_kobj_add_device(fs_info, NULL);
 	if (error) {
-		btrfs_sysfs_remove_fsid(fs_info);
+		btrfs_sysfs_remove_fsid(fs_devs);
 		return error;
 	}
 
-	error = sysfs_create_files(&fs_info->super_kobj, btrfs_attrs);
+	error = sysfs_create_files(super_kobj, btrfs_attrs);
 	if (error) {
-		btrfs_sysfs_remove_fsid(fs_info);
+		btrfs_sysfs_remove_fsid(fs_devs);
 		return error;
 	}
 
-	error = sysfs_create_group(&fs_info->super_kobj,
+	error = sysfs_create_group(super_kobj,
 				   &btrfs_feature_attr_group);
 	if (error)
 		goto failure;
@@ -745,7 +755,7 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 		goto failure;
 
 	fs_info->space_info_kobj = kobject_create_and_add("allocation",
-						  &fs_info->super_kobj);
+						  super_kobj);
 	if (!fs_info->space_info_kobj) {
 		error = -ENOMEM;
 		goto failure;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 0144790..218a14a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2243,7 +2243,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 		 */
 		snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU",
 						root->fs_info->fsid);
-		if (kobject_rename(&root->fs_info->super_kobj, fsid_buf))
+		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
+								fsid_buf))
 			goto error_trans;
 	}
 
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index d6fe73c..c2e5bd0 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -253,6 +253,11 @@ struct btrfs_fs_devices {
 	 * nonrot flag set
 	 */
 	int rotating;
+
+	/* sysfs kobjects */
+	struct kobject super_kobj;
+	struct kobject *device_dir_kobj;
+	struct completion kobj_unregister;
 };
 
 #define BTRFS_BIO_INLINE_CSUM_SIZE	64
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 12/24] Btrfs: sysfs: add pointer to access fs_info from fs_devices
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (10 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 11/24] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 13/24] Btrfs: introduce btrfs_get_fs_uuids Anand Jain
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

From: Anand Jain <Anand.Jain@oracle.com>

adds fs_info pointer with struct btrfs_fs_devices.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c   | 4 ++++
 fs/btrfs/volumes.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index ac15fbb..4b5bac6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -530,6 +530,8 @@ static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 
 void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 {
+	fs_info->fs_devices->fs_info = NULL;
+
 	if (fs_info->space_info_kobj) {
 		sysfs_remove_files(fs_info->space_info_kobj, allocation_attrs);
 		kobject_del(fs_info->space_info_kobj);
@@ -729,6 +731,8 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 	struct btrfs_fs_devices *fs_devs = fs_info->fs_devices;
 	struct kobject *super_kobj = &fs_devs->super_kobj;
 
+	fs_devs->fs_info = fs_info;
+
 	error = btrfs_sysfs_add_fsid(fs_devs, NULL);
 	if (error)
 		return error;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index c2e5bd0..53fd278 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -254,6 +254,7 @@ struct btrfs_fs_devices {
 	 */
 	int rotating;
 
+	struct btrfs_fs_info *fs_info;
 	/* sysfs kobjects */
 	struct kobject super_kobj;
 	struct kobject *device_dir_kobj;
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 13/24] Btrfs: introduce btrfs_get_fs_uuids
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (11 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 12/24] Btrfs: sysfs: add pointer to access fs_info from fs_devices Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 14/24] Btrfs: sysfs: provide framework to remove all fsid kobject Anand Jain
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 4 ++++
 fs/btrfs/volumes.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 218a14a..c1b1038 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -52,6 +52,10 @@ static void btrfs_dev_stat_print_on_load(struct btrfs_device *device);
 
 DEFINE_MUTEX(uuid_mutex);
 static LIST_HEAD(fs_uuids);
+struct list_head *btrfs_get_fs_uuids(void)
+{
+	return &fs_uuids;
+}
 
 static struct btrfs_fs_devices *__alloc_fs_devices(void)
 {
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 53fd278..4e99f06 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -540,5 +540,6 @@ static inline void unlock_chunks(struct btrfs_root *root)
 	mutex_unlock(&root->fs_info->chunk_mutex);
 }
 
+struct list_head *btrfs_get_fs_uuids(void);
 
 #endif
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 14/24] Btrfs: sysfs: provide framework to remove all fsid kobject
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (12 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 13/24] Btrfs: introduce btrfs_get_fs_uuids Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 15/24] Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of fs_info Anand Jain
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 4b5bac6..83d7535 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -515,7 +515,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
 	return 0;
 }
 
-static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
+static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 {
 	if (fs_devs->device_dir_kobj) {
 		kobject_del(fs_devs->device_dir_kobj);
@@ -528,6 +528,21 @@ static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 	wait_for_completion(&fs_devs->kobj_unregister);
 }
 
+/* when fs_devs is NULL it will remove all fsid kobject */
+static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
+{
+	struct list_head *fs_uuids = btrfs_get_fs_uuids();
+
+	if (fs_devs) {
+		__btrfs_sysfs_remove_fsid(fs_devs);
+		return;
+	}
+
+	list_for_each_entry(fs_devs, fs_uuids, list) {
+		__btrfs_sysfs_remove_fsid(fs_devs);
+	}
+}
+
 void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 {
 	fs_info->fs_devices->fs_info = NULL;
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 15/24] Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of fs_info
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (13 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 14/24] Btrfs: sysfs: provide framework to remove all fsid kobject Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 16/24] Btrfs: sysfs btrfs_kobj_rm_device() " Anand Jain
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

btrfs_kobj_add_device() does not need fs_info any more.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/dev-replace.c | 2 +-
 fs/btrfs/sysfs.c       | 7 +++----
 fs/btrfs/sysfs.h       | 2 +-
 fs/btrfs/volumes.c     | 2 +-
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index ca6a3a3..2acc0aa 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -593,7 +593,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 
 	/* replace the sysfs entry */
 	btrfs_kobj_rm_device(fs_info, src_device);
-	btrfs_kobj_add_device(fs_info, tgt_device);
+	btrfs_kobj_add_device(fs_info->fs_devices, tgt_device);
 	btrfs_rm_dev_replace_free_srcdev(fs_info, src_device);
 
 	/* write back the superblocks */
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 83d7535..15e4d54 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -682,11 +682,10 @@ int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs)
 	return 0;
 }
 
-int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
-		struct btrfs_device *one_device)
+int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
+				struct btrfs_device *one_device)
 {
 	int error = 0;
-	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
 	struct btrfs_device *dev;
 
 	error = btrfs_sysfs_add_device(fs_devices);
@@ -752,7 +751,7 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 	if (error)
 		return error;
 
-	error = btrfs_kobj_add_device(fs_info, NULL);
+	error = btrfs_kobj_add_device(fs_devs, NULL);
 	if (error) {
 		btrfs_sysfs_remove_fsid(fs_devs);
 		return error;
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index f7dd298..eeb86a8 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -70,7 +70,7 @@ char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
 extern const char * const btrfs_feature_set_names[3];
 extern struct kobj_type space_info_ktype;
 extern struct kobj_type btrfs_raid_ktype;
-int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
+int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
 int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
                 struct btrfs_device *one_device);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c1b1038..e567d54 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2206,7 +2206,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 				    tmp + 1);
 
 	/* add sysfs device entry */
-	btrfs_kobj_add_device(root->fs_info, device);
+	btrfs_kobj_add_device(root->fs_info->fs_devices, device);
 
 	/*
 	 * we've got more storage, clear any full flags on the space
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 16/24] Btrfs: sysfs btrfs_kobj_rm_device() pass fs_devices instead of fs_info
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (14 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 15/24] Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of fs_info Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 17/24] Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static Anand Jain
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

since btrfs_kobj_rm_device() does nothing with fs_info

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/dev-replace.c |  2 +-
 fs/btrfs/sysfs.c       | 12 ++++++------
 fs/btrfs/sysfs.h       |  2 +-
 fs/btrfs/volumes.c     |  4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 2acc0aa..124b60f 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -592,7 +592,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 	mutex_unlock(&uuid_mutex);
 
 	/* replace the sysfs entry */
-	btrfs_kobj_rm_device(fs_info, src_device);
+	btrfs_kobj_rm_device(fs_info->fs_devices, src_device);
 	btrfs_kobj_add_device(fs_info->fs_devices, tgt_device);
 	btrfs_rm_dev_replace_free_srcdev(fs_info, src_device);
 
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 15e4d54..4c86e62 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -555,7 +555,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->fs_devices->super_kobj, &btrfs_feature_attr_group);
 	sysfs_remove_files(&fs_info->fs_devices->super_kobj, btrfs_attrs);
-	btrfs_kobj_rm_device(fs_info, NULL);
+	btrfs_kobj_rm_device(fs_info->fs_devices, NULL);
 	btrfs_sysfs_remove_fsid(fs_info->fs_devices);
 }
 
@@ -636,20 +636,20 @@ static void init_feature_attrs(void)
 
 /* when one_device is NULL, it removes all device links */
 
-int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
+int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device)
 {
 	struct hd_struct *disk;
 	struct kobject *disk_kobj;
 
-	if (!fs_info->fs_devices->device_dir_kobj)
+	if (!fs_devices->device_dir_kobj)
 		return -EINVAL;
 
 	if (one_device && one_device->bdev) {
 		disk = one_device->bdev->bd_part;
 		disk_kobj = &part_to_dev(disk)->kobj;
 
-		sysfs_remove_link(fs_info->fs_devices->device_dir_kobj,
+		sysfs_remove_link(fs_devices->device_dir_kobj,
 						disk_kobj->name);
 	}
 
@@ -657,13 +657,13 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 		return 0;
 
 	list_for_each_entry(one_device,
-			&fs_info->fs_devices->devices, dev_list) {
+			&fs_devices->devices, dev_list) {
 		if (!one_device->bdev)
 			continue;
 		disk = one_device->bdev->bd_part;
 		disk_kobj = &part_to_dev(disk)->kobj;
 
-		sysfs_remove_link(fs_info->fs_devices->device_dir_kobj,
+		sysfs_remove_link(fs_devices->device_dir_kobj,
 						disk_kobj->name);
 	}
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index eeb86a8..3938ac1 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -72,6 +72,6 @@ extern struct kobj_type space_info_ktype;
 extern struct kobj_type btrfs_raid_ktype;
 int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
-int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
+int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
                 struct btrfs_device *one_device);
 #endif /* _BTRFS_SYSFS_H_ */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e567d54..51873ec 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1701,7 +1701,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 	if (device->bdev) {
 		device->fs_devices->open_devices--;
 		/* remove sysfs entry */
-		btrfs_kobj_rm_device(root->fs_info, device);
+		btrfs_kobj_rm_device(root->fs_info->fs_devices, device);
 	}
 
 	call_rcu(&device->rcu, free_device);
@@ -2285,7 +2285,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 error_trans:
 	btrfs_end_transaction(trans, root);
 	rcu_string_free(device->name);
-	btrfs_kobj_rm_device(root->fs_info, device);
+	btrfs_kobj_rm_device(root->fs_info->fs_devices, device);
 	kfree(device);
 error:
 	blkdev_put(bdev, FMODE_EXCL);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 17/24] Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (15 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 16/24] Btrfs: sysfs btrfs_kobj_rm_device() " Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 18/24] Btrfs: sysfs: make btrfs_sysfs_add_device() " Anand Jain
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 2 +-
 fs/btrfs/sysfs.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 4c86e62..2dbb064 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -727,7 +727,7 @@ u64 btrfs_debugfs_test;
  * Can be called by the device discovery thread.
  * And parent can be specified for seed device
  */
-static int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
+int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 				struct kobject *parent)
 {
 	int error;
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 3938ac1..aaff124 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -74,4 +74,6 @@ int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
 int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
                 struct btrfs_device *one_device);
+int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
+				struct kobject *parent);
 #endif /* _BTRFS_SYSFS_H_ */
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 18/24] Btrfs: sysfs: make btrfs_sysfs_add_device() non static
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (16 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 17/24] Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 19/24] Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it " Anand Jain
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index aaff124..ac06b5c 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -76,4 +76,5 @@ int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
                 struct btrfs_device *one_device);
 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 				struct kobject *parent);
+int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
 #endif /* _BTRFS_SYSFS_H_ */
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 19/24] Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it non static
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (17 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 18/24] Btrfs: sysfs: make btrfs_sysfs_add_device() " Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 20/24] Btrfs: sysfs: separate kobject and attribute creation Anand Jain
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 2 +-
 fs/btrfs/sysfs.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 2dbb064..ff9e5f6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -529,7 +529,7 @@ static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 }
 
 /* when fs_devs is NULL it will remove all fsid kobject */
-static void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
+void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 {
 	struct list_head *fs_uuids = btrfs_get_fs_uuids();
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index ac06b5c..2b31f6f 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -77,4 +77,5 @@ int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 				struct kobject *parent);
 int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
+void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
 #endif /* _BTRFS_SYSFS_H_ */
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 20/24] Btrfs: sysfs: separate kobject and attribute creation
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (18 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 19/24] Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it " Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-08 23:56 ` [PATCH 21/24] Btrfs: sysfs: add support to add parent for fsid Anand Jain
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/disk-io.c | 18 +++++++++++++++++-
 fs/btrfs/sysfs.c   | 15 ++-------------
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 0cd6550..4b7f3b8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2785,10 +2785,22 @@ retry_root_backup:
 
 	btrfs_close_extra_devices(fs_info, fs_devices, 1);
 
+	ret = btrfs_sysfs_add_fsid(fs_devices, NULL);
+	if (ret) {
+		pr_err("BTRFS: failed to init sysfs fsid interface: %d\n", ret);
+		goto fail_block_groups;
+	}
+
+	ret = btrfs_sysfs_add_device(fs_devices);
+	if (ret) {
+		pr_err("BTRFS: failed to init sysfs device interface: %d\n", ret);
+		goto fail_fsdev_sysfs;
+	}
+
 	ret = btrfs_sysfs_add_one(fs_info);
 	if (ret) {
 		pr_err("BTRFS: failed to init sysfs interface: %d\n", ret);
-		goto fail_block_groups;
+		goto fail_fsdev_sysfs;
 	}
 
 	ret = btrfs_init_space_info(fs_info);
@@ -3002,6 +3014,9 @@ fail_cleaner:
 fail_sysfs:
 	btrfs_sysfs_remove_one(fs_info);
 
+fail_fsdev_sysfs:
+	btrfs_sysfs_remove_fsid(fs_info->fs_devices);
+
 fail_block_groups:
 	btrfs_put_block_group_cache(fs_info);
 	btrfs_free_block_groups(fs_info);
@@ -3679,6 +3694,7 @@ void close_ctree(struct btrfs_root *root)
 	}
 
 	btrfs_sysfs_remove_one(fs_info);
+	btrfs_sysfs_remove_fsid(fs_info->fs_devices);
 
 	btrfs_free_fs_roots(fs_info);
 
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index ff9e5f6..d0caa32 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -556,7 +556,6 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 	sysfs_remove_group(&fs_info->fs_devices->super_kobj, &btrfs_feature_attr_group);
 	sysfs_remove_files(&fs_info->fs_devices->super_kobj, btrfs_attrs);
 	btrfs_kobj_rm_device(fs_info->fs_devices, NULL);
-	btrfs_sysfs_remove_fsid(fs_info->fs_devices);
 }
 
 const char * const btrfs_feature_set_names[3] = {
@@ -688,10 +687,6 @@ int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
 	int error = 0;
 	struct btrfs_device *dev;
 
-	error = btrfs_sysfs_add_device(fs_devices);
-	if (error)
-		return error;
-
 	list_for_each_entry(dev, &fs_devices->devices, dev_list) {
 		struct hd_struct *disk;
 		struct kobject *disk_kobj;
@@ -747,19 +742,13 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 
 	fs_devs->fs_info = fs_info;
 
-	error = btrfs_sysfs_add_fsid(fs_devs, NULL);
-	if (error)
-		return error;
-
 	error = btrfs_kobj_add_device(fs_devs, NULL);
-	if (error) {
-		btrfs_sysfs_remove_fsid(fs_devs);
+	if (error)
 		return error;
-	}
 
 	error = sysfs_create_files(super_kobj, btrfs_attrs);
 	if (error) {
-		btrfs_sysfs_remove_fsid(fs_devs);
+		btrfs_kobj_rm_device(fs_devs, NULL);
 		return error;
 	}
 
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 21/24] Btrfs: sysfs: add support to add parent for fsid
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (19 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 20/24] Btrfs: sysfs: separate kobject and attribute creation Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-11 18:41   ` David Sterba
  2015-02-08 23:56 ` [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue Anand Jain
                   ` (3 subsequent siblings)
  24 siblings, 1 reply; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

To support seed sysfs layout and represent seed fsid under
the sprout we need the facility to create fsid under the
specified parent.
---
 fs/btrfs/sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index d0caa32..d89bf4d 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -729,8 +729,8 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
 
 	init_completion(&fs_devs->kobj_unregister);
 	fs_devs->super_kobj.kset = btrfs_kset;
-	error = kobject_init_and_add(&fs_devs->super_kobj, &btrfs_ktype, NULL,
-				     "%pU", fs_devs->fsid);
+	error = kobject_init_and_add(&fs_devs->super_kobj,
+				&btrfs_ktype, parent, "%pU", fs_devs->fsid);
 	return error;
 }
 
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (20 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 21/24] Btrfs: sysfs: add support to add parent for fsid Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-11 18:40   ` David Sterba
  2015-02-08 23:56 ` [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout Anand Jain
                   ` (2 subsequent siblings)
  24 siblings, 1 reply; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 51873ec..1490723 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2249,7 +2249,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 						root->fs_info->fsid);
 		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
 								fsid_buf))
-			goto error_trans;
+			printk(KERN_WARNING\
+			"BTRFS: sysfs: failed to create fsid for sprout\n");
 	}
 
 	root->fs_info->num_tolerated_disk_barrier_failures =
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (21 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-11 18:52   ` David Sterba
  2015-02-08 23:56 ` [PATCH 24/24] Btrfs: sysfs: add check if super kobject is already initialized Anand Jain
  2015-02-11 19:01 ` [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added David Sterba
  24 siblings, 1 reply; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

This adds an enhancement to show the seed fsid and devices.

The way sprouting handles fs_devices:
      clone seed fs_devices and add to the fs_uuids
      mem copy seed fs_devices and assign to fs_devices->seed (move dev_list)
      evacuate seed fs_devices contents to hold sprout fs devices contents

  So to be inline with this fs_devices changes during seeding,
  represent seed fsid under the sprout fsid, this is achieved
  by using the kobject_move()

eg: showing two levels of seeding.

find /sys/fs/btrfs/ -type d -name devices -exec ls {} \; -print

sde
/sys/fs/btrfs/8c2772d4-6951-43c3-89b6-3ab3c70a13f8/f7ef2904-ce89-4421-bfb0-49fd999e9a0b/devices
sdd
/sys/fs/btrfs/8c2772d4-6951-43c3-89b6-3ab3c70a13f8/f7ef2904-ce89-4421-bfb0-49fd999e9a0b/53ac3265-0c34-4afd-9453-cc0d1a07be64/devices
sdf
/sys/fs/btrfs/8c2772d4-6951-43c3-89b6-3ab3c70a13f8/devices

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/dev-replace.c |  4 +--
 fs/btrfs/disk-io.c     |  4 +--
 fs/btrfs/sysfs.c       | 66 +++++++++++++++++++++++++++++++++++---------------
 fs/btrfs/sysfs.h       |  8 +++---
 fs/btrfs/volumes.c     | 40 +++++++++++++++++++++++++-----
 5 files changed, 89 insertions(+), 33 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 124b60f..e72b986 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -592,8 +592,8 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 	mutex_unlock(&uuid_mutex);
 
 	/* replace the sysfs entry */
-	btrfs_kobj_rm_device(fs_info->fs_devices, src_device);
-	btrfs_kobj_add_device(fs_info->fs_devices, tgt_device);
+	btrfs_kobj_rm_device(fs_info->fs_devices, src_device, 0);
+	btrfs_kobj_add_device(fs_info->fs_devices, tgt_device, 0);
 	btrfs_rm_dev_replace_free_srcdev(fs_info, src_device);
 
 	/* write back the superblocks */
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 4b7f3b8..77372af 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2785,13 +2785,13 @@ retry_root_backup:
 
 	btrfs_close_extra_devices(fs_info, fs_devices, 1);
 
-	ret = btrfs_sysfs_add_fsid(fs_devices, NULL);
+	ret = btrfs_sysfs_add_fsid(fs_devices, NULL, 1);
 	if (ret) {
 		pr_err("BTRFS: failed to init sysfs fsid interface: %d\n", ret);
 		goto fail_block_groups;
 	}
 
-	ret = btrfs_sysfs_add_device(fs_devices);
+	ret = btrfs_sysfs_add_device(fs_devices, 1);
 	if (ret) {
 		pr_err("BTRFS: failed to init sysfs device interface: %d\n", ret);
 		goto fail_fsdev_sysfs;
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index d89bf4d..f8358d2 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -517,15 +517,20 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
 
 static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs)
 {
+	if (fs_devs->seed)
+		__btrfs_sysfs_remove_fsid(fs_devs->seed);
+
 	if (fs_devs->device_dir_kobj) {
 		kobject_del(fs_devs->device_dir_kobj);
 		kobject_put(fs_devs->device_dir_kobj);
 		fs_devs->device_dir_kobj = NULL;
 	}
 
-	kobject_del(&fs_devs->super_kobj);
-	kobject_put(&fs_devs->super_kobj);
-	wait_for_completion(&fs_devs->kobj_unregister);
+	if (fs_devs->super_kobj.state_initialized) {
+		kobject_del(&fs_devs->super_kobj);
+		kobject_put(&fs_devs->super_kobj);
+		wait_for_completion(&fs_devs->kobj_unregister);
+	}
 }
 
 /* when fs_devs is NULL it will remove all fsid kobject */
@@ -555,7 +560,7 @@ void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->fs_devices->super_kobj, &btrfs_feature_attr_group);
 	sysfs_remove_files(&fs_info->fs_devices->super_kobj, btrfs_attrs);
-	btrfs_kobj_rm_device(fs_info->fs_devices, NULL);
+	btrfs_kobj_rm_device(fs_info->fs_devices, NULL, 1);
 }
 
 const char * const btrfs_feature_set_names[3] = {
@@ -636,7 +641,7 @@ static void init_feature_attrs(void)
 /* when one_device is NULL, it removes all device links */
 
 int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
-		struct btrfs_device *one_device)
+		struct btrfs_device *one_device, int follow_seed)
 {
 	struct hd_struct *disk;
 	struct kobject *disk_kobj;
@@ -666,27 +671,39 @@ int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
 						disk_kobj->name);
 	}
 
+	if (follow_seed && fs_devices->seed)
+		btrfs_kobj_rm_device(fs_devices->seed, NULL, follow_seed);
+
 	return 0;
 }
 
-int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs)
+int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs, int follow_seed)
 {
-	if (!fs_devs->device_dir_kobj)
-		fs_devs->device_dir_kobj = kobject_create_and_add("devices",
-						&fs_devs->super_kobj);
 
-	if (!fs_devs->device_dir_kobj)
-		return -ENOMEM;
+	while (fs_devs) {
+		if (!fs_devs->device_dir_kobj)
+			fs_devs->device_dir_kobj = kobject_create_and_add(
+					"devices", &fs_devs->super_kobj);
+
+		if (!fs_devs->device_dir_kobj)
+			return -ENOMEM;
+
+		if (!follow_seed)
+			return 0;
+
+		fs_devs = fs_devs->seed;
+	}
 
 	return 0;
 }
 
 int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
-				struct btrfs_device *one_device)
+			struct btrfs_device *one_device, int follow_seed)
 {
 	int error = 0;
 	struct btrfs_device *dev;
 
+again:
 	list_for_each_entry(dev, &fs_devices->devices, dev_list) {
 		struct hd_struct *disk;
 		struct kobject *disk_kobj;
@@ -706,6 +723,11 @@ int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
 			break;
 	}
 
+	if (follow_seed && fs_devices->seed) {
+		fs_devices = fs_devices->seed;
+		goto again;
+	}
+
 	return error;
 }
 
@@ -723,14 +745,20 @@ u64 btrfs_debugfs_test;
  * And parent can be specified for seed device
  */
 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
-				struct kobject *parent)
+				struct kobject *parent, int follow_seed)
 {
-	int error;
+	int error = 0;
 
-	init_completion(&fs_devs->kobj_unregister);
-	fs_devs->super_kobj.kset = btrfs_kset;
-	error = kobject_init_and_add(&fs_devs->super_kobj,
+	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,
 				&btrfs_ktype, parent, "%pU", fs_devs->fsid);
+		if (!follow_seed)
+			return error;
+		parent = &fs_devs->super_kobj;
+		fs_devs = fs_devs->seed;
+	}
 	return error;
 }
 
@@ -742,13 +770,13 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 
 	fs_devs->fs_info = fs_info;
 
-	error = btrfs_kobj_add_device(fs_devs, NULL);
+	error = btrfs_kobj_add_device(fs_devs, NULL, 1);
 	if (error)
 		return error;
 
 	error = sysfs_create_files(super_kobj, btrfs_attrs);
 	if (error) {
-		btrfs_kobj_rm_device(fs_devs, NULL);
+		btrfs_kobj_rm_device(fs_devs, NULL, 0);
 		return error;
 	}
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 2b31f6f..59e7dba 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -71,11 +71,11 @@ extern const char * const btrfs_feature_set_names[3];
 extern struct kobj_type space_info_ktype;
 extern struct kobj_type btrfs_raid_ktype;
 int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices,
-		struct btrfs_device *one_device);
+		struct btrfs_device *one_device, int follow_seed);
 int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices,
-                struct btrfs_device *one_device);
+                struct btrfs_device *one_device, int follow_seed);
 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
-				struct kobject *parent);
-int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
+				struct kobject *parent, int follow_seed);
+int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs, int follow_seed);
 void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
 #endif /* _BTRFS_SYSFS_H_ */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1490723..9e87143 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -27,6 +27,7 @@
 #include <linux/kthread.h>
 #include <linux/raid/pq.h>
 #include <linux/semaphore.h>
+#include <linux/kobject.h>
 #include <asm/div64.h>
 #include "ctree.h"
 #include "extent_map.h"
@@ -1701,7 +1702,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 	if (device->bdev) {
 		device->fs_devices->open_devices--;
 		/* remove sysfs entry */
-		btrfs_kobj_rm_device(root->fs_info->fs_devices, device);
+		btrfs_kobj_rm_device(root->fs_info->fs_devices, device, 0);
 	}
 
 	call_rcu(&device->rcu, free_device);
@@ -1979,11 +1980,15 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
 
 	memcpy(seed_devices, fs_devices, sizeof(*seed_devices));
 	seed_devices->opened = 1;
+	seed_devices->device_dir_kobj = NULL;
+	memset(&seed_devices->super_kobj, 0, sizeof(struct kobject));
+	memset(&seed_devices->kobj_unregister, 0, sizeof(struct completion));
 	INIT_LIST_HEAD(&seed_devices->devices);
 	INIT_LIST_HEAD(&seed_devices->alloc_list);
 	mutex_init(&seed_devices->device_list_mutex);
 
 	mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
+	btrfs_kobj_rm_device(fs_devices, NULL, 0);
 	list_splice_init_rcu(&fs_devices->devices, &seed_devices->devices,
 			      synchronize_rcu);
 	list_for_each_entry(device, &seed_devices->devices, dev_list)
@@ -2206,7 +2211,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 				    tmp + 1);
 
 	/* add sysfs device entry */
-	btrfs_kobj_add_device(root->fs_info->fs_devices, device);
+	btrfs_kobj_add_device(root->fs_info->fs_devices, device, 0);
 
 	/*
 	 * we've got more storage, clear any full flags on the space
@@ -2235,6 +2240,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 
 	if (seeding_dev) {
 		char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
+		struct btrfs_fs_devices *fs_devs = root->fs_info->fs_devices;
 
 		ret = btrfs_finish_sprout(trans, root);
 		if (ret) {
@@ -2242,15 +2248,37 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 			goto error_trans;
 		}
 
-		/* Sprouting would change fsid of the mounted root,
+		/*
+		 * Sprouting would change fsid of the mounted root,
 		 * so rename the fsid on the sysfs
 		 */
 		snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU",
 						root->fs_info->fsid);
-		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
-								fsid_buf))
+		if (!kobject_rename(&fs_devs->super_kobj, fsid_buf)) {
+			struct btrfs_fs_devices *seed_devs;
+
+			seed_devs = fs_devs->seed;
+
+			/* Create the seed fsid inside the sprout fsid */
+
+			btrfs_sysfs_add_fsid(seed_devs, &fs_devs->super_kobj, 0);
+			btrfs_sysfs_add_device(seed_devs, 0);
+			btrfs_kobj_add_device(seed_devs, NULL, 0);
+
+			/*
+			 * If this is a nested seed, that is if there is seed's
+			 * seed device then move that inside its seed device.
+			 */
+			if (seed_devs->seed) {
+				if (kobject_move(&seed_devs->seed->super_kobj,
+							&seed_devs->super_kobj))
+					printk(KERN_WARNING\
+						"Btrfs: sysfs: kobject move failed\n");
+			}
+		} else {
 			printk(KERN_WARNING\
 			"BTRFS: sysfs: failed to create fsid for sprout\n");
+		}
 	}
 
 	root->fs_info->num_tolerated_disk_barrier_failures =
@@ -2286,7 +2314,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 error_trans:
 	btrfs_end_transaction(trans, root);
 	rcu_string_free(device->name);
-	btrfs_kobj_rm_device(root->fs_info->fs_devices, device);
+	btrfs_kobj_rm_device(root->fs_info->fs_devices, device, 0);
 	kfree(device);
 error:
 	blkdev_put(bdev, FMODE_EXCL);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH 24/24] Btrfs: sysfs: add check if super kobject is already initialized
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (22 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout Anand Jain
@ 2015-02-08 23:56 ` Anand Jain
  2015-02-11 18:41   ` David Sterba
  2015-02-11 19:01 ` [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added David Sterba
  24 siblings, 1 reply; 39+ messages in thread
From: Anand Jain @ 2015-02-08 23:56 UTC (permalink / raw)
  To: linux-btrfs; +Cc: clm, dsterba

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

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index f8358d2..5c555da 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 = -EINVAL;
+		}
 		if (!follow_seed)
 			return error;
 		parent = &fs_devs->super_kobj;
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* Re: [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue
  2015-02-08 23:56 ` [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue Anand Jain
@ 2015-02-11 18:40   ` David Sterba
  2015-02-12  3:22     ` Anand Jain
  0 siblings, 1 reply; 39+ messages in thread
From: David Sterba @ 2015-02-11 18:40 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

On Mon, Feb 09, 2015 at 07:56:23AM +0800, Anand Jain wrote:
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/volumes.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 51873ec..1490723 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2249,7 +2249,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
>  						root->fs_info->fsid);
>  		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
>  								fsid_buf))
> -			goto error_trans;
> +			printk(KERN_WARNING\
> +			"BTRFS: sysfs: failed to create fsid for sprout\n");

You can safely use btrfs_warn here.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 24/24] Btrfs: sysfs: add check if super kobject is already initialized
  2015-02-08 23:56 ` [PATCH 24/24] Btrfs: sysfs: add check if super kobject is already initialized Anand Jain
@ 2015-02-11 18:41   ` David Sterba
  0 siblings, 0 replies; 39+ messages in thread
From: David Sterba @ 2015-02-11 18:41 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

Missing signed-off-by

On Mon, Feb 09, 2015 at 07:56:25AM +0800, Anand Jain wrote:
> ---
>  fs/btrfs/sysfs.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index f8358d2..5c555da 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 = -EINVAL;
> +		}
>  		if (!follow_seed)
>  			return error;
>  		parent = &fs_devs->super_kobj;
> -- 
> 2.0.0.153.g79dcccc
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 21/24] Btrfs: sysfs: add support to add parent for fsid
  2015-02-08 23:56 ` [PATCH 21/24] Btrfs: sysfs: add support to add parent for fsid Anand Jain
@ 2015-02-11 18:41   ` David Sterba
  0 siblings, 0 replies; 39+ messages in thread
From: David Sterba @ 2015-02-11 18:41 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

On Mon, Feb 09, 2015 at 07:56:22AM +0800, Anand Jain wrote:
> To support seed sysfs layout and represent seed fsid under
> the sprout we need the facility to create fsid under the
> specified parent.

Missing signed-off-by

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout
  2015-02-08 23:56 ` [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout Anand Jain
@ 2015-02-11 18:52   ` David Sterba
  2015-02-12  6:25     ` Anand Jain
  0 siblings, 1 reply; 39+ messages in thread
From: David Sterba @ 2015-02-11 18:52 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

On Mon, Feb 09, 2015 at 07:56:24AM +0800, Anand Jain wrote:
> This adds an enhancement to show the seed fsid and devices.
> 
> The way sprouting handles fs_devices:
>       clone seed fs_devices and add to the fs_uuids
>       mem copy seed fs_devices and assign to fs_devices->seed (move dev_list)
>       evacuate seed fs_devices contents to hold sprout fs devices contents
> 
>   So to be inline with this fs_devices changes during seeding,
>   represent seed fsid under the sprout fsid, this is achieved
>   by using the kobject_move()
> 
> eg: showing two levels of seeding.

That's new to me, how does nested seeding work?

> find /sys/fs/btrfs/ -type d -name devices -exec ls {} \; -print
> 
> sde
> /sys/fs/btrfs/8c2772d4-6951-43c3-89b6-3ab3c70a13f8/f7ef2904-ce89-4421-bfb0-49fd999e9a0b/devices
> sdd
> /sys/fs/btrfs/8c2772d4-6951-43c3-89b6-3ab3c70a13f8/f7ef2904-ce89-4421-bfb0-49fd999e9a0b/53ac3265-0c34-4afd-9453-cc0d1a07be64/devices

The plain uuid is IMHO not the best naming convention, although it's
acceptable in the global list in /sys/fs/btrfs/* I'd rather avoid it if
it's mixed with other files.

Would it be enough to print all relevant seeding information into a
single file? If the "UUID" directoreis do not contain anything else,
that would be IMHO best.

Do the seeding fsids exist on their own in /sys/sf/btrfs? I haven't
tested the patchset so I'd probably find that out myself.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added
  2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
                   ` (23 preceding siblings ...)
  2015-02-08 23:56 ` [PATCH 24/24] Btrfs: sysfs: add check if super kobject is already initialized Anand Jain
@ 2015-02-11 19:01 ` David Sterba
  2015-02-12  7:23   ` Anand Jain
  24 siblings, 1 reply; 39+ messages in thread
From: David Sterba @ 2015-02-11 19:01 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, clm, dsterba

On Mon, Feb 09, 2015 at 07:56:01AM +0800, Anand Jain wrote:
> This patch set will provide a framework and help to create attributes
> from the structure btrfs_fs_devices which are available even before
> fs_info is created. So by moving the parent kobject super_kobj from
> fs_info to btrfs_fs_devices, it will help to create attributes
> from the btrfs_fs_devices as well.
>     
> Just to note, this does not change any of the existing btrfs sysfs
> external kobject names and its attributes and not even the life
> cycle of them. Changes are internal only. And to ensure the same,
> this path has been tested with various device operations and,
> checking and comparing the sysfs kobjects and attributes with
> sysfs kobject and attributes with out this patch, and they remain
> same. These test cases are added to the progs as test-btrfs-devmgt.sh,
> its patch is below as well.

I went through the patchset, looks ok to me in general. The only concern
is about the new seeding representation, but the other changes seem ok
(but I did not do in-depth review).

I like the patch separation, that really helps to understand the changes
although there are 20+ patches in total.

We can merge patches 1-22, patch 23 should be folded into 24 as it fixes
a bug introduced there.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue
  2015-02-11 18:40   ` David Sterba
@ 2015-02-12  3:22     ` Anand Jain
  2015-02-13 16:15       ` David Sterba
  0 siblings, 1 reply; 39+ messages in thread
From: Anand Jain @ 2015-02-12  3:22 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm



On 02/12/2015 02:40 AM, David Sterba wrote:
> On Mon, Feb 09, 2015 at 07:56:23AM +0800, Anand Jain wrote:
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   fs/btrfs/volumes.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index 51873ec..1490723 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -2249,7 +2249,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
>>   						root->fs_info->fsid);
>>   		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
>>   								fsid_buf))
>> -			goto error_trans;
>> +			printk(KERN_WARNING\
>> +			"BTRFS: sysfs: failed to create fsid for sprout\n");
>
> You can safely use btrfs_warn here.
>

right. I tried to know what to use before, but wasn't sure. would you be 
able to accept it as it is ? OR I can send a new patch to correct this. 
Just that changing this commit would fail further commits like
   Btrfs: sysfs: support seed devices in the sysfs layout.

Thanks, Anand


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout
  2015-02-11 18:52   ` David Sterba
@ 2015-02-12  6:25     ` Anand Jain
  2015-02-13 17:33       ` David Sterba
  2015-02-13 17:51       ` David Sterba
  0 siblings, 2 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-12  6:25 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm; +Cc: Gui Hecheng


Thanks for commenting. more below.


On 02/12/2015 02:52 AM, David Sterba wrote:
> On Mon, Feb 09, 2015 at 07:56:24AM +0800, Anand Jain wrote:
>> This adds an enhancement to show the seed fsid and devices.
>>
>> The way sprouting handles fs_devices:
>>        clone seed fs_devices and add to the fs_uuids
>>        mem copy seed fs_devices and assign to fs_devices->seed (move dev_list)
>>        evacuate seed fs_devices contents to hold sprout fs devices contents
>>
>>    So to be inline with this fs_devices changes during seeding,
>>    represent seed fsid under the sprout fsid, this is achieved
>>    by using the kobject_move()
>>
>> eg: showing two levels of seeding.
>
> That's new to me, how does nested seeding work?

  I called below operation as nested seeding:
     mark a sprout as seed, mount it, add a new sprout to it.
     eg:
      mkfs.btrfs /dev/sdz
      btrfstune -S 1 /dev/sdz
      mount /dev/sdz /btrfs
      btrfs dev add /dev/sdy /btrfs
      umount /btrfs
      btrfstune -S 1 /dev/sdy
      mount /dev/sdy /btrfs
      btrfs dev add /dev/sdx /btrfs


(Its bit complicated during seeding, as fs_devices and device move 
around. /proc/fs/btrfs/devlist helped to understand. its in the ML)

{
Since we are on this topic: btrfs-progs shouldn't have had this patch:
    git log -p 2513077
-------------------------
commit 2513077f2f830b4bc83d528bfb6979eb461918bd
Author: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Date:   Mon Oct 6 18:16:46 2014 +0800

     btrfs-progs: fix device missing of btrfs fi show with seed devices
-------------------------

it doesn't work with nested seed as I commented
   http://marc.info/?l=linux-btrfs&m=141102300324251&w=2
-------------------------
   btrfs fi show -d
warning devid 1 not found already
warning devid 2 not found already
Check tree block failed, want=29425664, have=0
read block failed check_tree_block
Couldn't setup csum tree
Check tree block failed, want=29360128, have=0
read block failed check_tree_block
-------------------------

I haven't see next version of this patch from Gui. (Gui ?, copied)
}


>> find /sys/fs/btrfs/ -type d -name devices -exec ls {} \; -print
>>
>> sde
>> /sys/fs/btrfs/8c2772d4-6951-43c3-89b6-3ab3c70a13f8/f7ef2904-ce89-4421-bfb0-49fd999e9a0b/devices
>> sdd
>> /sys/fs/btrfs/8c2772d4-6951-43c3-89b6-3ab3c70a13f8/f7ef2904-ce89-4421-bfb0-49fd999e9a0b/53ac3265-0c34-4afd-9453-cc0d1a07be64/devices
>
> The plain uuid is IMHO not the best naming convention, although it's
> acceptable in the global list in /sys/fs/btrfs/* I'd rather avoid it if
> it's mixed with other files.

just to clarify, the above aren't uuid, they are fsid rather, sorry I 
didn't mention.
   sde
   /sys/fs/btrfs/sprout-fsid/seed-fsid/devices
   sdd
   /sys/fs/btrfs/sprout-fsid/seed-fsid/2nd-level-seed-fsid/devices

In any case, as in previous RFC patch
   [PATCH RFC] btrfs: add sysfs layout to show volume info
uuid will be there, the reasons are first,
btrfs kernel the device uniqueness is determined by fsid-uuid-devid 
combination (which means if _any one_ of these is different its going to 
create a new struct btrfs_device), so its easy to be inline with that. 
name abstraction links on top of it can be created as well.
next,
we originally have device name link under /sys/fs/btrfs/fsid/device. 
Since it made first, I doubt if we could alter that to a kobject dir 
instead of link?. Some script might be using it. So I am planning to put 
uuid under /sys/fs/btrfs/fsid/device to contain info about the device. 
as shown in the RFC patch above.

> Would it be enough to print all relevant seeding information into a
> single file? If the "UUID" directoreis do not contain anything else,
> that would be IMHO best.

Hmm nope it will contain more info.

> Do the seeding fsids exist on their own in /sys/sf/btrfs? I haven't
> tested the patchset so I'd probably find that out myself.

Thanks, Anand


> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added
  2015-02-11 19:01 ` [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added David Sterba
@ 2015-02-12  7:23   ` Anand Jain
  0 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-12  7:23 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm


Thanks for commenting. V3 is out. more below.

On 02/12/2015 03:01 AM, David Sterba wrote:
> On Mon, Feb 09, 2015 at 07:56:01AM +0800, Anand Jain wrote:
>> This patch set will provide a framework and help to create attributes
>> from the structure btrfs_fs_devices which are available even before
>> fs_info is created. So by moving the parent kobject super_kobj from
>> fs_info to btrfs_fs_devices, it will help to create attributes
>> from the btrfs_fs_devices as well.
>>
>> Just to note, this does not change any of the existing btrfs sysfs
>> external kobject names and its attributes and not even the life
>> cycle of them. Changes are internal only. And to ensure the same,
>> this path has been tested with various device operations and,
>> checking and comparing the sysfs kobjects and attributes with
>> sysfs kobject and attributes with out this patch, and they remain
>> same. These test cases are added to the progs as test-btrfs-devmgt.sh,
>> its patch is below as well.
>
> I went through the patchset, looks ok to me in general. The only concern
> is about the new seeding representation, but the other changes seem ok
> (but I did not do in-depth review).
>
> I like the patch separation, that really helps to understand the changes
> although there are 20+ patches in total.
>
> We can merge patches 1-22, patch 23 should be folded into 24 as it fixes
> a bug introduced there.

Actually there isn't bug, 24 it provides framework for the upcoming RFC 
patch which is under test. Since I wanted this upcoming RFC patch to be 
sleek, so I pushed 24 with the framework patch set.


Thanks, Anand

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue
  2015-02-12  3:22     ` Anand Jain
@ 2015-02-13 16:15       ` David Sterba
  2015-03-09 17:10         ` Anand Jain
  0 siblings, 1 reply; 39+ messages in thread
From: David Sterba @ 2015-02-13 16:15 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, linux-btrfs, clm

On Thu, Feb 12, 2015 at 11:22:38AM +0800, Anand Jain wrote:
> 
> 
> On 02/12/2015 02:40 AM, David Sterba wrote:
> > On Mon, Feb 09, 2015 at 07:56:23AM +0800, Anand Jain wrote:
> >> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> >> ---
> >>   fs/btrfs/volumes.c | 3 ++-
> >>   1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> >> index 51873ec..1490723 100644
> >> --- a/fs/btrfs/volumes.c
> >> +++ b/fs/btrfs/volumes.c
> >> @@ -2249,7 +2249,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
> >>   						root->fs_info->fsid);
> >>   		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
> >>   								fsid_buf))
> >> -			goto error_trans;
> >> +			printk(KERN_WARNING\
> >> +			"BTRFS: sysfs: failed to create fsid for sprout\n");
> >
> > You can safely use btrfs_warn here.
> >
> 
> right. I tried to know what to use before, but wasn't sure.

There's already btrfs_error used in the function. The only context where
the message macros are not usable is during mount when fs_info is not
available.

> would you be 
> able to accept it as it is ? OR I can send a new patch to correct this. 
> Just that changing this commit would fail further commits like
>    Btrfs: sysfs: support seed devices in the sysfs layout.

But this patch also needs to apply the same sort of change, please
resend. Thanks.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout
  2015-02-12  6:25     ` Anand Jain
@ 2015-02-13 17:33       ` David Sterba
  2015-03-09 17:11         ` Anand Jain
  2015-02-13 17:51       ` David Sterba
  1 sibling, 1 reply; 39+ messages in thread
From: David Sterba @ 2015-02-13 17:33 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, linux-btrfs, clm, Gui Hecheng

On Thu, Feb 12, 2015 at 02:25:32PM +0800, Anand Jain wrote:
> On 02/12/2015 02:52 AM, David Sterba wrote:
> > On Mon, Feb 09, 2015 at 07:56:24AM +0800, Anand Jain wrote:
> >> This adds an enhancement to show the seed fsid and devices.
> >>
> >> The way sprouting handles fs_devices:
> >>        clone seed fs_devices and add to the fs_uuids
> >>        mem copy seed fs_devices and assign to fs_devices->seed (move dev_list)
> >>        evacuate seed fs_devices contents to hold sprout fs devices contents
> >>
> >>    So to be inline with this fs_devices changes during seeding,
> >>    represent seed fsid under the sprout fsid, this is achieved
> >>    by using the kobject_move()
> >>
> >> eg: showing two levels of seeding.
> >
> > That's new to me, how does nested seeding work?
> 
>   I called below operation as nested seeding:
>      mark a sprout as seed, mount it, add a new sprout to it.
>      eg:
>       mkfs.btrfs /dev/sdz
>       btrfstune -S 1 /dev/sdz
>       mount /dev/sdz /btrfs
>       btrfs dev add /dev/sdy /btrfs
>       umount /btrfs
>       btrfstune -S 1 /dev/sdy
>       mount /dev/sdy /btrfs
>       btrfs dev add /dev/sdx /btrfs

While I'm not sure if seeding was originally expected to work on a
multi-device filesystem, it makes sense to me. But what I don't
understand here is the concept of 'nesting'.

Let's say we have device A, B and C, and a * denotes a seeding device.
Then we can start with a populated filesystem on device A.

Then mark it seeding, A*, all fine.

Add device B to A*, all writes are captured by B, fine.

Now, we make B seeding.

Mounting the filesystem from A* should not IMO see any device B* as all
changes were stored there, namely the superblock of A* is kept intact.

Mouting from B* should see both A* and B*. Here it may resemble some
nesting or chaining, if that's what you mean.

(Adding a device C to A*, B* would mean that just all writes are captured
by C, ie.  no difference compared to the respective situation for A*, B,
so I can stop the example here.)

I'm thinking about a representation of the possible relations between
the devices. Seems that the seeding hierarchy for one filesystem is
always linear, so it's ok to represent it by the filesystem UUID chain.

/sys/fs/btrfs/UUID1/UUID2/UUID3

What I still find unsatisfying is lack of any explicit naming attached
to the UUIDs. As we can use lots of types of UUID, saying that "if it
looks like an uuid if the main filesystem directory in sysfs, then it's
the seeding filesystem" is not the best we can come up with.

I don't have a final idea, but at least

/sys/fs/btrfs/UUID1/seeding/UUID2/seeding/UUID3

would look more friendly to the user and also more accssible to
scripting. We coud possibly add other files/dirs to the inserted
directory.


A sidenote: the nesting forms a tree structure so it's possible to do a
snapshotting on the filesystem level, very similar to what the LVM
snapshots do, but here we have to provide a new device manually to
capture the new writes and make sure that all the devices do not
disappear.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout
  2015-02-12  6:25     ` Anand Jain
  2015-02-13 17:33       ` David Sterba
@ 2015-02-13 17:51       ` David Sterba
  2015-02-18  3:04         ` Anand Jain
  1 sibling, 1 reply; 39+ messages in thread
From: David Sterba @ 2015-02-13 17:51 UTC (permalink / raw)
  To: Anand Jain; +Cc: dsterba, linux-btrfs, clm, Gui Hecheng

On Thu, Feb 12, 2015 at 02:25:32PM +0800, Anand Jain wrote:
> Since we are on this topic: btrfs-progs shouldn't have had this patch:
>     git log -p 2513077
> -------------------------
> commit 2513077f2f830b4bc83d528bfb6979eb461918bd
> Author: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> Date:   Mon Oct 6 18:16:46 2014 +0800
> 
>      btrfs-progs: fix device missing of btrfs fi show with seed devices
> -------------------------
> 
> it doesn't work with nested seed as I commented
>    http://marc.info/?l=linux-btrfs&m=141102300324251&w=2
> -------------------------
>    btrfs fi show -d
> warning devid 1 not found already
> warning devid 2 not found already
> Check tree block failed, want=29425664, have=0
> read block failed check_tree_block
> Couldn't setup csum tree
> Check tree block failed, want=29360128, have=0
> read block failed check_tree_block
> -------------------------
> 
> I haven't see next version of this patch from Gui. (Gui ?, copied)

The fixed version was "[PATCH v2 3/3] btrfs-progs: fix device missing of
btrfs fi show with seed devices"

http://article.gmane.org/gmane.comp.file-systems.btrfs/39186/

and that's what I have merged.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout
  2015-02-13 17:51       ` David Sterba
@ 2015-02-18  3:04         ` Anand Jain
  0 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-02-18  3:04 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm


[guihc.fnst@cn.fujitsu.com
  bounced removing the email id from the cc-list].

Dave,

here is the patch list for Oct.
   https://patchwork.kernel.org/project/linux-btrfs/list/?page=7
v2 isn't there. I am confused.

Anyway if btrfs-progs integration-20150213
contained V2. I am on it now. And I still see the problem.

----------------------
btrfs fi show <-- on a nested seed fs
warning devid 1 not found already  <---
warning devid 2 not found already  <---
bytenr mismatch, want=4194304, have=0 <----
Label: none  uuid: fce49239-b392-4e4d-b775-57dca7f2426b
	Total devices 1 FS bytes used 28.00KiB
	devid    1 size 967.86MiB used 12.00MiB path /dev/sdb

Label: none  uuid: bccc7c86-82ff-4f2c-805a-4d384642f5e6
	Total devices 2 FS bytes used 92.00KiB
	devid    1 size 967.86MiB used 8.00MiB path /dev/sdb
	devid    2 size 967.87MiB used 144.00MiB path /dev/sdc

Label: none  uuid: 6ea26ac0-b4e9-4a56-9079-67d25a57ac27
	Total devices 3 FS bytes used 156.00KiB
	devid    3 size 1.52GiB used 224.00MiB path /dev/sdd
	*** Some devices missing

btrfs-progs v3.19-rc2-68-gd4bf1cc
--------------------------

Can you pls revert this patch for now ?


Thanks, Anand



On 02/14/2015 01:51 AM, David Sterba wrote:
> On Thu, Feb 12, 2015 at 02:25:32PM +0800, Anand Jain wrote:
>> Since we are on this topic: btrfs-progs shouldn't have had this patch:
>>      git log -p 2513077
>> -------------------------
>> commit 2513077f2f830b4bc83d528bfb6979eb461918bd
>> Author: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
>> Date:   Mon Oct 6 18:16:46 2014 +0800
>>
>>       btrfs-progs: fix device missing of btrfs fi show with seed devices
>> -------------------------
>>
>> it doesn't work with nested seed as I commented
>>     http://marc.info/?l=linux-btrfs&m=141102300324251&w=2
>> -------------------------
>>     btrfs fi show -d
>> warning devid 1 not found already
>> warning devid 2 not found already
>> Check tree block failed, want=29425664, have=0
>> read block failed check_tree_block
>> Couldn't setup csum tree
>> Check tree block failed, want=29360128, have=0
>> read block failed check_tree_block
>> -------------------------
>>
>> I haven't see next version of this patch from Gui. (Gui ?, copied)
>
> The fixed version was "[PATCH v2 3/3] btrfs-progs: fix device missing of
> btrfs fi show with seed devices"
>
> http://article.gmane.org/gmane.comp.file-systems.btrfs/39186/
>
> and that's what I have merged.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue
  2015-02-13 16:15       ` David Sterba
@ 2015-03-09 17:10         ` Anand Jain
  0 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-03-09 17:10 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm



On 02/13/2015 11:15 AM, David Sterba wrote:
> On Thu, Feb 12, 2015 at 11:22:38AM +0800, Anand Jain wrote:
>>
>>
>> On 02/12/2015 02:40 AM, David Sterba wrote:
>>> On Mon, Feb 09, 2015 at 07:56:23AM +0800, Anand Jain wrote:
>>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>>> ---
>>>>    fs/btrfs/volumes.c | 3 ++-
>>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>>>> index 51873ec..1490723 100644
>>>> --- a/fs/btrfs/volumes.c
>>>> +++ b/fs/btrfs/volumes.c
>>>> @@ -2249,7 +2249,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
>>>>    						root->fs_info->fsid);
>>>>    		if (kobject_rename(&root->fs_info->fs_devices->super_kobj,
>>>>    								fsid_buf))
>>>> -			goto error_trans;
>>>> +			printk(KERN_WARNING\
>>>> +			"BTRFS: sysfs: failed to create fsid for sprout\n");
>>>
>>> You can safely use btrfs_warn here.
>>>
>>
>> right. I tried to know what to use before, but wasn't sure.
>
> There's already btrfs_error used in the function. The only context where
> the message macros are not usable is during mount when fs_info is not
> available.
>
>> would you be
>> able to accept it as it is ? OR I can send a new patch to correct this.
>> Just that changing this commit would fail further commits like
>>     Btrfs: sysfs: support seed devices in the sysfs layout.
>
> But this patch also needs to apply the same sort of change, please
> resend. Thanks.

I got this in my local ws. Will be sending it out.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout
  2015-02-13 17:33       ` David Sterba
@ 2015-03-09 17:11         ` Anand Jain
  0 siblings, 0 replies; 39+ messages in thread
From: Anand Jain @ 2015-03-09 17:11 UTC (permalink / raw)
  To: dsterba, linux-btrfs, clm, Gui Hecheng



Hi Dave,

  Sorry for the delay I was caught up some issues... (hope I didn't miss 
any of the email).


On 02/13/2015 12:33 PM, David Sterba wrote:
> On Thu, Feb 12, 2015 at 02:25:32PM +0800, Anand Jain wrote:
>> On 02/12/2015 02:52 AM, David Sterba wrote:
>>> On Mon, Feb 09, 2015 at 07:56:24AM +0800, Anand Jain wrote:
>>>> This adds an enhancement to show the seed fsid and devices.
>>>>
>>>> The way sprouting handles fs_devices:
>>>>         clone seed fs_devices and add to the fs_uuids
>>>>         mem copy seed fs_devices and assign to fs_devices->seed (move dev_list)
>>>>         evacuate seed fs_devices contents to hold sprout fs devices contents
>>>>
>>>>     So to be inline with this fs_devices changes during seeding,
>>>>     represent seed fsid under the sprout fsid, this is achieved
>>>>     by using the kobject_move()
>>>>
>>>> eg: showing two levels of seeding.
>>>
>>> That's new to me, how does nested seeding work?
>>
>>    I called below operation as nested seeding:
>>       mark a sprout as seed, mount it, add a new sprout to it.
>>       eg:
>>        mkfs.btrfs /dev/sdz
>>        btrfstune -S 1 /dev/sdz
>>        mount /dev/sdz /btrfs
>>        btrfs dev add /dev/sdy /btrfs
>>        umount /btrfs
>>        btrfstune -S 1 /dev/sdy
>>        mount /dev/sdy /btrfs
>>        btrfs dev add /dev/sdx /btrfs
>
> While I'm not sure if seeding was originally expected to work on a
> multi-device filesystem, it makes sense to me. But what I don't
> understand here is the concept of 'nesting'.
>
> Let's say we have device A, B and C, and a * denotes a seeding device.
> Then we can start with a populated filesystem on device A.
>
> Then mark it seeding, A*, all fine.
>
> Add device B to A*, all writes are captured by B, fine.

yes. in this context B is called sprout (of A).

> Now, we make B seeding.
>
> Mounting the filesystem from A* should not IMO see any device B* as all
> changes were stored there, namely the superblock of A* is kept intact.

> Mouting from B* should see both A* and B*. Here it may resemble some
> nesting or chaining, if that's what you mean.

> (Adding a device C to A*, B* would mean that just all writes are captured
> by C, ie.  no difference compared to the respective situation for A*, B,
> so I can stop the example here.)

yes. you got that right.

In the same context there is this bug:
   search email for the sub: "replace seed/sprout hangs (regression ?)"

> I'm thinking about a representation of the possible relations between
> the devices. Seems that the seeding hierarchy for one filesystem is
> always linear, so it's ok to represent it by the filesystem UUID chain.

> /sys/fs/btrfs/UUID1/UUID2/UUID3

This been(being) done. I will send out the patch RFC for your kind 
integration.

> What I still find unsatisfying is lack of any explicit naming attached
> to the UUIDs. As we can use lots of types of UUID, saying that "if it
> looks like an uuid if the main filesystem directory in sysfs, then it's
> the seeding filesystem" is not the best we can come up with.
>
> I don't have a final idea, but at least
>
> /sys/fs/btrfs/UUID1/seeding/UUID2/seeding/UUID3
>
> would look more friendly to the user and also more accssible to
> scripting. We coud possibly add other files/dirs to the inserted
> directory.

in the above 'seeding' kobject dir is redundant, since there won't be a 
fsid under a fsid unless its a seed. And there would be a 'seeding' 
attribute to tell is its seeding.

>
> A sidenote: the nesting forms a tree structure so it's possible to do a
> snapshotting on the filesystem level, very similar to what the LVM
> snapshots do, but here we have to provide a new device manually to
> capture the new writes and make sure that all the devices do not
> disappear.



Thanks, Anand

^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2015-03-09 17:11 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-08 23:56 [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
2015-02-08 23:56 ` [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data Anand Jain
2015-02-08 23:56 ` [PATCH 02/24] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice Anand Jain
2015-02-08 23:56 ` [PATCH 03/24] Btrfs: sysfs: fix, undo sysfs device links Anand Jain
2015-02-08 23:56 ` [PATCH 04/24] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release Anand Jain
2015-02-08 23:56 ` [PATCH 05/24] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy Anand Jain
2015-02-08 23:56 ` [PATCH 06/24] Btrfs: sysfs: reorder the kobject creations Anand Jain
2015-02-08 23:56 ` [PATCH 07/24] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid Anand Jain
2015-02-08 23:56 ` [PATCH 08/24] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid Anand Jain
2015-02-08 23:56 ` [PATCH 09/24] Btrfs: sysfs: let default_attrs be separate from the kset Anand Jain
2015-02-08 23:56 ` [PATCH 10/24] Btrfs: sysfs: separate device kobject and its attribute creation Anand Jain
2015-02-08 23:56 ` [PATCH 11/24] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices Anand Jain
2015-02-08 23:56 ` [PATCH 12/24] Btrfs: sysfs: add pointer to access fs_info from fs_devices Anand Jain
2015-02-08 23:56 ` [PATCH 13/24] Btrfs: introduce btrfs_get_fs_uuids Anand Jain
2015-02-08 23:56 ` [PATCH 14/24] Btrfs: sysfs: provide framework to remove all fsid kobject Anand Jain
2015-02-08 23:56 ` [PATCH 15/24] Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of fs_info Anand Jain
2015-02-08 23:56 ` [PATCH 16/24] Btrfs: sysfs btrfs_kobj_rm_device() " Anand Jain
2015-02-08 23:56 ` [PATCH 17/24] Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static Anand Jain
2015-02-08 23:56 ` [PATCH 18/24] Btrfs: sysfs: make btrfs_sysfs_add_device() " Anand Jain
2015-02-08 23:56 ` [PATCH 19/24] Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it " Anand Jain
2015-02-08 23:56 ` [PATCH 20/24] Btrfs: sysfs: separate kobject and attribute creation Anand Jain
2015-02-08 23:56 ` [PATCH 21/24] Btrfs: sysfs: add support to add parent for fsid Anand Jain
2015-02-11 18:41   ` David Sterba
2015-02-08 23:56 ` [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue Anand Jain
2015-02-11 18:40   ` David Sterba
2015-02-12  3:22     ` Anand Jain
2015-02-13 16:15       ` David Sterba
2015-03-09 17:10         ` Anand Jain
2015-02-08 23:56 ` [PATCH 23/24] Btrfs: sysfs: support seed devices in the sysfs layout Anand Jain
2015-02-11 18:52   ` David Sterba
2015-02-12  6:25     ` Anand Jain
2015-02-13 17:33       ` David Sterba
2015-03-09 17:11         ` Anand Jain
2015-02-13 17:51       ` David Sterba
2015-02-18  3:04         ` Anand Jain
2015-02-08 23:56 ` [PATCH 24/24] Btrfs: sysfs: add check if super kobject is already initialized Anand Jain
2015-02-11 18:41   ` David Sterba
2015-02-11 19:01 ` [PATCH 00/24 V2] provide frame work so that sysfs attributs from the fs_devices can be added David Sterba
2015-02-12  7:23   ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).