* [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 02/24] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice Anand Jain
` (22 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 02/24] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
2015-02-11 23:20 ` [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 03/24] Btrfs: sysfs: fix, undo sysfs device links Anand Jain
` (21 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 03/24] Btrfs: sysfs: fix, undo sysfs device links
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
2015-02-11 23:20 ` [PATCH 01/24] Btrfs: sysfs: fix, btrfs_release_super_kobj() should to clean up the kobject data Anand Jain
2015-02-11 23:20 ` [PATCH 02/24] Btrfs: sysfs: fix, fs_info kobject_unregister has init_completion() twice Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 04/24] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release Anand Jain
` (20 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 04/24] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (2 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 03/24] Btrfs: sysfs: fix, undo sysfs device links Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 05/24] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy Anand Jain
` (19 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 05/24] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (3 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 04/24] Btrfs: sysfs: fix, kobject pointer clean up needed after kobject release Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 06/24] Btrfs: sysfs: reorder the kobject creations Anand Jain
` (18 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 06/24] Btrfs: sysfs: reorder the kobject creations
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (4 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 05/24] Btrfc: sysfs: fix, check if device_dir_kobj is init before destroy Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 07/24] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid Anand Jain
` (17 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 07/24] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (5 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 06/24] Btrfs: sysfs: reorder the kobject creations Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 08/24] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid Anand Jain
` (16 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 08/24] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (6 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 07/24] Btrfs: sysfs: rename __btrfs_sysfs_remove_one to btrfs_sysfs_remove_fsid Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 09/24] Btrfs: sysfs: let default_attrs be separate from the kset Anand Jain
` (15 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 09/24] Btrfs: sysfs: let default_attrs be separate from the kset
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (7 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 08/24] Btrfs: sysfs: introduce function btrfs_sysfs_add_fsid() to create sysfs fsid Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 10/24] Btrfs: sysfs: separate device kobject and its attribute creation Anand Jain
` (14 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 10/24] Btrfs: sysfs: separate device kobject and its attribute creation
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (8 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 09/24] Btrfs: sysfs: let default_attrs be separate from the kset Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 11/24] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices Anand Jain
` (13 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 11/24] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (9 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 10/24] Btrfs: sysfs: separate device kobject and its attribute creation Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 12/24] Btrfs: sysfs: add pointer to access fs_info from fs_devices Anand Jain
` (12 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 12/24] Btrfs: sysfs: add pointer to access fs_info from fs_devices
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (10 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 11/24] Btrfs: sysfs: move super_kobj and device_dir_kobj from fs_info to btrfs_fs_devices Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 13/24] Btrfs: introduce btrfs_get_fs_uuids Anand Jain
` (11 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 13/24] Btrfs: introduce btrfs_get_fs_uuids
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (11 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 12/24] Btrfs: sysfs: add pointer to access fs_info from fs_devices Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 14/24] Btrfs: sysfs: provide framework to remove all fsid kobject Anand Jain
` (10 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 14/24] Btrfs: sysfs: provide framework to remove all fsid kobject
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (12 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 13/24] Btrfs: introduce btrfs_get_fs_uuids Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:20 ` [PATCH 15/24] Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of fs_info Anand Jain
` (9 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 15/24] Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of fs_info
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (13 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 14/24] Btrfs: sysfs: provide framework to remove all fsid kobject Anand Jain
@ 2015-02-11 23:20 ` Anand Jain
2015-02-11 23:21 ` [PATCH 16/24] Btrfs: sysfs btrfs_kobj_rm_device() " Anand Jain
` (8 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:20 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] 30+ messages in thread* [PATCH 16/24] Btrfs: sysfs btrfs_kobj_rm_device() pass fs_devices instead of fs_info
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (14 preceding siblings ...)
2015-02-11 23:20 ` [PATCH 15/24] Btrfs: sysfs btrfs_kobj_add_device() pass fs_devices instead of fs_info Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 17/24] Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static Anand Jain
` (7 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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] 30+ messages in thread* [PATCH 17/24] Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (15 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 16/24] Btrfs: sysfs btrfs_kobj_rm_device() " Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 18/24] Btrfs: sysfs: make btrfs_sysfs_add_device() " Anand Jain
` (6 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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] 30+ messages in thread* [PATCH 18/24] Btrfs: sysfs: make btrfs_sysfs_add_device() non static
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (16 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 17/24] Btrfs: sysfs: make btrfs_sysfs_add_fsid() non static Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 19/24] Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it " Anand Jain
` (5 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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] 30+ messages in thread* [PATCH 19/24] Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it non static
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (17 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 18/24] Btrfs: sysfs: make btrfs_sysfs_add_device() " Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 20/24] Btrfs: sysfs: separate kobject and attribute creation Anand Jain
` (4 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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] 30+ messages in thread* [PATCH 20/24] Btrfs: sysfs: separate kobject and attribute creation
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (18 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 19/24] Btrfs: sysfs: btrfs_sysfs_remove_fsid() make it " Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 21/24 V3] Btrfs: sysfs: add support to add parent for fsid Anand Jain
` (3 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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] 30+ messages in thread* [PATCH 21/24 V3] Btrfs: sysfs: add support to add parent for fsid
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (19 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 20/24] Btrfs: sysfs: separate kobject and attribute creation Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue Anand Jain
` (2 subsequent siblings)
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2->v3: added missing signed-off
v1->v2: does not exist
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] 30+ messages in thread* [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (20 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 21/24 V3] Btrfs: sysfs: add support to add parent for fsid Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 23/24 V3] Btrfs: sysfs: support seed devices in the sysfs layout Anand Jain
2015-02-11 23:21 ` [PATCH 24/24 V3] Btrfs: sysfs: add check if super kobject is already initialized Anand Jain
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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] 30+ messages in thread* [PATCH 23/24 V3] Btrfs: sysfs: support seed devices in the sysfs layout
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (21 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 22/24] Btrfs: sysfs: don't fail seeding for the sake of sysfs kobject issue Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
2015-02-11 23:21 ` [PATCH 24/24 V3] Btrfs: sysfs: add check if super kobject is already initialized Anand Jain
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 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()
The end result will be,
/sys/fs/btrfs/sprout-fsid/level-1-seed-fsid/(if)level-2-seed-fsid
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>
---
v2->v3: commit updates, Thanks Dave.
v1->v2: does not exist
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] 30+ messages in thread* [PATCH 24/24 V3] Btrfs: sysfs: add check if super kobject is already initialized
2015-02-11 23:20 [PATCH 00/24 V3] provide frame work so that sysfs attributs from the fs_devices can be added Anand Jain
` (22 preceding siblings ...)
2015-02-11 23:21 ` [PATCH 23/24 V3] Btrfs: sysfs: support seed devices in the sysfs layout Anand Jain
@ 2015-02-11 23:21 ` Anand Jain
23 siblings, 0 replies; 30+ messages in thread
From: Anand Jain @ 2015-02-11 23:21 UTC (permalink / raw)
To: linux-btrfs; +Cc: clm, dsterba
This patch will be useful when we have to change the context in which we create
and destroy sysfs fsid and device kobjects. But this is a good change to have it,
as it just does the right thing in general.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2->v3: add missing signed-off, update commit
v1->v2: when kobject is already created return EEXIST, not sent to ML
fs/btrfs/sysfs.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index f8358d2..6ebbe6c 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -750,10 +750,14 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
int error = 0;
while (fs_devs) {
- init_completion(&fs_devs->kobj_unregister);
- fs_devs->super_kobj.kset = btrfs_kset;
- error = kobject_init_and_add(&fs_devs->super_kobj,
+ if (!fs_devs->super_kobj.state_initialized) {
+ init_completion(&fs_devs->kobj_unregister);
+ fs_devs->super_kobj.kset = btrfs_kset;
+ error = kobject_init_and_add(&fs_devs->super_kobj,
&btrfs_ktype, parent, "%pU", fs_devs->fsid);
+ } else {
+ error = -EEXIST;
+ }
if (!follow_seed)
return error;
parent = &fs_devs->super_kobj;
--
2.0.0.153.g79dcccc
^ permalink raw reply related [flat|nested] 30+ messages in thread