linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6 v2] update sysfs per btrfs device operations
@ 2014-06-03  3:35 Anand Jain
  2014-06-03  3:35 ` [PATCH 1/6 v2] btrfs: rename add_device_membership to btrfs_kobj_add_device Anand Jain
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Anand Jain @ 2014-06-03  3:35 UTC (permalink / raw)
  To: linux-btrfs; +Cc: jeffm, dsterba, clm

This patch set fixes the bugs which Jeff patch is fixing,
which is to update sysfs when device is added and removed.

Further, this patch set also address the following.
  - Update sysfs path when device is replaced
  - Update sysfs path when sprout is created

Also mainly this patch makes the code more modular
which will support the enhancement like in the RFC
patch 6/6 below

Thanks.

Anand Jain (6):
  btrfs: rename add_device_membership to btrfs_kobj_add_device
  btrfs: dev delete should remove sysfs entry
  btrfs: dev add should add its sysfs entry
  btrfs: dev replace should replace the sysfs entry
  btrfs: create sprout should rename fsid on the sysfs as well
  btrfs: revamp /sys/fs/btrfs/<fsid>/devices

 fs/btrfs/dev-replace.c     |   5 +++
 fs/btrfs/sysfs.c           | 103 +++++++++++++++++++++++++++++++++++++++++----
 fs/btrfs/sysfs.h           |   4 ++
 fs/btrfs/volumes.c         |  18 ++++++++
 fs/btrfs/volumes.h         |   2 +
 include/uapi/linux/btrfs.h |   1 +
 6 files changed, 125 insertions(+), 8 deletions(-)

-- 
1.8.5.3


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

* [PATCH 1/6 v2] btrfs: rename add_device_membership to btrfs_kobj_add_device
  2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
@ 2014-06-03  3:35 ` Anand Jain
  2014-06-03 13:23   ` David Sterba
  2014-06-03  3:36 ` [PATCH 2/6 v2] btrfs: dev delete should remove sysfs entry Anand Jain
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Anand Jain @ 2014-06-03  3:35 UTC (permalink / raw)
  To: linux-btrfs; +Cc: jeffm, dsterba, clm

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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: this is a new patch in the patch-set sent before,
    as per the review comments. Thanks David.

 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 522d023..41b0672 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -572,7 +572,7 @@ static void init_feature_attrs(void)
 	}
 }
 
-static int add_device_membership(struct btrfs_fs_info *fs_info)
+static int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info)
 {
 	int error = 0;
 	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
@@ -633,7 +633,7 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 	if (error)
 		goto failure;
 
-	error = add_device_membership(fs_info);
+	error = btrfs_kobj_add_device(fs_info);
 	if (error)
 		goto failure;
 
-- 
1.8.5.3


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

* [PATCH 2/6 v2] btrfs: dev delete should remove sysfs entry
  2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
  2014-06-03  3:35 ` [PATCH 1/6 v2] btrfs: rename add_device_membership to btrfs_kobj_add_device Anand Jain
@ 2014-06-03  3:36 ` Anand Jain
  2014-06-03 13:23   ` David Sterba
  2014-06-03  3:36 ` [PATCH 3/6 v2] btrfs: dev add should add its " Anand Jain
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Anand Jain @ 2014-06-03  3:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: jeffm, dsterba, clm

when we delete the device from the mounted btrfs,
we would need its corresponding sysfs enty to
be removed as well.

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
---
 v2: the function name change applied here

 fs/btrfs/sysfs.c   | 20 ++++++++++++++++++++
 fs/btrfs/sysfs.h   |  2 ++
 fs/btrfs/volumes.c |  4 ++++
 3 files changed, 26 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 41b0672..4100771 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -572,6 +572,26 @@ static void init_feature_attrs(void)
 	}
 }
 
+int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
+		struct btrfs_device *one_device)
+{
+	struct hd_struct *disk;
+	struct kobject *disk_kobj;
+
+	if (!fs_info->device_dir_kobj)
+		return -EINVAL;
+
+	if (one_device) {
+		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;
+}
+
 static int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info)
 {
 	int error = 0;
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 9ab5763..529554e 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -66,4 +66,6 @@ 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_rm_device(struct btrfs_fs_info *fs_info,
+                struct btrfs_device *one_device);
 #endif /* _BTRFS_SYSFS_H_ */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d4633d4..5f434d7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -40,6 +40,7 @@
 #include "rcu-string.h"
 #include "math.h"
 #include "dev-replace.h"
+#include "sysfs.h"
 
 static int init_first_rw_device(struct btrfs_trans_handle *trans,
 				struct btrfs_root *root,
@@ -1675,6 +1676,9 @@ 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);
+
 	call_rcu(&device->rcu, free_device);
 
 	num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1;
-- 
1.8.5.3


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

* [PATCH 3/6 v2] btrfs: dev add should add its sysfs entry
  2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
  2014-06-03  3:35 ` [PATCH 1/6 v2] btrfs: rename add_device_membership to btrfs_kobj_add_device Anand Jain
  2014-06-03  3:36 ` [PATCH 2/6 v2] btrfs: dev delete should remove sysfs entry Anand Jain
@ 2014-06-03  3:36 ` Anand Jain
  2014-06-03 13:23   ` David Sterba
  2014-06-03  3:36 ` [PATCH 4/6 v2] btrfs: dev replace should replace the " Anand Jain
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Anand Jain @ 2014-06-03  3:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: jeffm, dsterba, clm

we would need the device links to be created,
when device is added.

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
---
 v2: the function name change applied here

 fs/btrfs/sysfs.c   | 12 +++++++++---
 fs/btrfs/sysfs.h   |  2 ++
 fs/btrfs/volumes.c |  5 +++++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 4100771..9733cfc 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -592,14 +592,17 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 	return 0;
 }
 
-static int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info)
+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;
 
-	fs_info->device_dir_kobj = kobject_create_and_add("devices",
+	if (!fs_info->device_dir_kobj)
+		fs_info->device_dir_kobj = kobject_create_and_add("devices",
 						&fs_info->super_kobj);
+
 	if (!fs_info->device_dir_kobj)
 		return -ENOMEM;
 
@@ -610,6 +613,9 @@ static int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info)
 		if (!dev->bdev)
 			continue;
 
+		if (one_device && one_device != dev)
+			continue;
+
 		disk = dev->bdev->bd_part;
 		disk_kobj = &part_to_dev(disk)->kobj;
 
@@ -653,7 +659,7 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
 	if (error)
 		goto failure;
 
-	error = btrfs_kobj_add_device(fs_info);
+	error = btrfs_kobj_add_device(fs_info, NULL);
 	if (error)
 		goto failure;
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 529554e..ac46df3 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -66,6 +66,8 @@ 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,
+		struct btrfs_device *one_device);
 int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
                 struct btrfs_device *one_device);
 #endif /* _BTRFS_SYSFS_H_ */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 5f434d7..4a66e6b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2101,6 +2101,10 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 	total_bytes = btrfs_super_num_devices(root->fs_info->super_copy);
 	btrfs_set_super_num_devices(root->fs_info->super_copy,
 				    total_bytes + 1);
+
+	/* add sysfs device entry */
+	btrfs_kobj_add_device(root->fs_info, device);
+
 	mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 
 	if (seeding_dev) {
@@ -2161,6 +2165,7 @@ error_trans:
 	unlock_chunks(root);
 	btrfs_end_transaction(trans, root);
 	rcu_string_free(device->name);
+	btrfs_kobj_rm_device(root->fs_info, device);
 	kfree(device);
 error:
 	blkdev_put(bdev, FMODE_EXCL);
-- 
1.8.5.3


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

* [PATCH 4/6 v2] btrfs: dev replace should replace the sysfs entry
  2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
                   ` (2 preceding siblings ...)
  2014-06-03  3:36 ` [PATCH 3/6 v2] btrfs: dev add should add its " Anand Jain
@ 2014-06-03  3:36 ` Anand Jain
  2014-06-03 13:39   ` David Sterba
  2014-06-03  3:36 ` [PATCH 5/6 v2] btrfs: create sprout should rename fsid on the sysfs as well Anand Jain
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Anand Jain @ 2014-06-03  3:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: jeffm, dsterba, clm

when we replace the device its corresponding sysfs
entry has to be replaced as well

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 v2: the function name change applied here

 fs/btrfs/dev-replace.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 9f22905..1219982 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -36,6 +36,7 @@
 #include "check-integrity.h"
 #include "rcu-string.h"
 #include "dev-replace.h"
+#include "sysfs.h"
 
 static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 				       int scrub_ret);
@@ -562,6 +563,10 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 		fs_info->fs_devices->latest_bdev = tgt_device->bdev;
 	list_add(&tgt_device->dev_alloc_list, &fs_info->fs_devices->alloc_list);
 
+	/* replace the sysfs entry */
+	btrfs_kobj_rm_device(fs_info, src_device);
+	btrfs_kobj_add_device(fs_info, tgt_device);
+
 	btrfs_rm_dev_replace_blocked(fs_info);
 
 	btrfs_rm_dev_replace_srcdev(fs_info, src_device);
-- 
1.8.5.3


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

* [PATCH 5/6 v2] btrfs: create sprout should rename fsid on the sysfs as well
  2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
                   ` (3 preceding siblings ...)
  2014-06-03  3:36 ` [PATCH 4/6 v2] btrfs: dev replace should replace the " Anand Jain
@ 2014-06-03  3:36 ` Anand Jain
  2014-06-03 13:41   ` David Sterba
  2014-06-03  3:36 ` [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs/<fsid>/devices Anand Jain
  2014-06-20  9:53 ` [PATCH 0/6 v2] update sysfs per btrfs device operations David Sterba
  6 siblings, 1 reply; 17+ messages in thread
From: Anand Jain @ 2014-06-03  3:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: jeffm, dsterba, clm

Creating sprout will change the fsid of the mounted root.
do the same on the sysfs as well.

reproducer:
 mount /dev/sdb /btrfs (seed disk)
 btrfs dev add /dev/sdc /btrfs
 mount -o rw,remount /btrfs
 btrfs dev del /dev/sdb /btrfs
 mount /dev/sdb /btrfs

Error:
kobject_add_internal failed for fe350492-dc28-4051-a601-e017b17e6145 with -EEXIST, don't try to register things with the same name in the same directory.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 v2: function name change and defined BTRFS_UUID_UNPARSED_SIZE
     in btrfs.h include file

 fs/btrfs/volumes.c         | 9 +++++++++
 include/uapi/linux/btrfs.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 4a66e6b..d169bd8 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2108,6 +2108,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 	mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 
 	if (seeding_dev) {
+		char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
 		ret = init_first_rw_device(trans, root, device);
 		if (ret) {
 			btrfs_abort_transaction(trans, root, ret);
@@ -2118,6 +2119,14 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
 			btrfs_abort_transaction(trans, root, ret);
 			goto error_trans;
 		}
+
+		/* 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->super_kobj, fsid_buf))
+			goto error_trans;
 	} else {
 		ret = btrfs_add_device(trans, root, device);
 		if (ret) {
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index 839d574c..8ff61c2 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -38,6 +38,7 @@ struct btrfs_ioctl_vol_args {
 #define BTRFS_SUBVOL_QGROUP_INHERIT	(1ULL << 2)
 #define BTRFS_FSID_SIZE 16
 #define BTRFS_UUID_SIZE 16
+#define BTRFS_UUID_UNPARSED_SIZE	37
 
 #define BTRFS_QGROUP_INHERIT_SET_LIMITS	(1ULL << 0)
 
-- 
1.8.5.3


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

* [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs/<fsid>/devices
  2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
                   ` (4 preceding siblings ...)
  2014-06-03  3:36 ` [PATCH 5/6 v2] btrfs: create sprout should rename fsid on the sysfs as well Anand Jain
@ 2014-06-03  3:36 ` Anand Jain
  2014-06-03 14:08   ` David Sterba
  2014-06-20  9:53 ` [PATCH 0/6 v2] update sysfs per btrfs device operations David Sterba
  6 siblings, 1 reply; 17+ messages in thread
From: Anand Jain @ 2014-06-03  3:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: jeffm, dsterba, clm

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

As of now with out this patch the sysfs interface under dir
/sys/fs/btrfs/<fsid>/devices is just link to the block devs.

Moving forward we would need the above btrfs sysfs path to contain more
info about the btrfs devices. So this patch provides a framework for
the same.

And as of now a probe interface is added, which can be used to notify
btrfs for any change in the device status.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
  V2: On the 2nd thought I kept the device link, but under the device name.
      eg: /sys/fs/btrfs/<fsid>/devices/<sdx>/sdx-> link to blk device
          /sys/fs/btrfs/<fsid>/devices/<sdx>/probe
      and commit update accordingly

 fs/btrfs/sysfs.c   | 73 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 fs/btrfs/volumes.h |  2 ++
 2 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 9733cfc..92fb3bb 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -31,8 +31,11 @@
 #include "transaction.h"
 #include "sysfs.h"
 #include "volumes.h"
+#include "rcu-string.h"
 
 static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj);
+int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
+		struct btrfs_device *one_device);
 
 static u64 get_features(struct btrfs_fs_info *fs_info,
 			enum btrfs_feature_set set)
@@ -490,8 +493,13 @@ 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);
 	}
-	kobject_del(fs_info->device_dir_kobj);
-	kobject_put(fs_info->device_dir_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);
+	}
+
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->super_kobj, &btrfs_feature_attr_group);
 	__btrfs_sysfs_remove_one(fs_info);
@@ -577,21 +585,68 @@ int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
 {
 	struct hd_struct *disk;
 	struct kobject *disk_kobj;
+	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
+	struct btrfs_device *dev;
 
 	if (!fs_info->device_dir_kobj)
 		return -EINVAL;
 
 	if (one_device) {
+		if (!one_device->device_kobj.parent)
+			return -EINVAL;
+
 		disk = one_device->bdev->bd_part;
 		disk_kobj = &part_to_dev(disk)->kobj;
 
-		sysfs_remove_link(fs_info->device_dir_kobj,
+		sysfs_remove_link(&one_device->device_kobj,
 						disk_kobj->name);
+		kobject_del(&one_device->device_kobj);
+		kobject_put(&one_device->device_kobj);
+		return 0;
 	}
 
+	list_for_each_entry(dev, &fs_devices->devices, dev_list) {
+		if (!dev->device_kobj.parent)
+			continue;
+
+		disk = dev->bdev->bd_part;
+		disk_kobj = &part_to_dev(disk)->kobj;
+
+		sysfs_remove_link(&dev->device_kobj, disk_kobj->name);
+		kobject_del(&dev->device_kobj);
+		kobject_put(&dev->device_kobj);
+	}
 	return 0;
 }
 
+#define to_btrfs_device(_kobj) container_of(_kobj, struct btrfs_device, device_kobj)
+
+static ssize_t device_kobj_probe_store(struct kobject *dev_kobj,
+			struct kobj_attribute *a, const char *buf, size_t len)
+{
+	/* Fixme: Call appropriate device check status handler */
+
+        return len;
+}
+
+BTRFS_ATTR_RW(probe, 0200, NULL, device_kobj_probe_store);
+
+static struct attribute *device_kobj_attrs[] = {
+	BTRFS_ATTR_PTR(probe),
+	NULL,
+};
+
+static void device_kobj_release(struct kobject *dev_kobj)
+{
+	/* nothing to free as of now */
+}
+
+struct kobj_type device_ktype = {
+	.sysfs_ops	= &kobj_sysfs_ops,
+	.release	= device_kobj_release,
+	.default_attrs	= device_kobj_attrs,
+};
+
 int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
 		struct btrfs_device *one_device)
 {
@@ -610,19 +665,25 @@ int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
 		struct hd_struct *disk;
 		struct kobject *disk_kobj;
 
-		if (!dev->bdev)
+		if (!dev->bdev || dev->missing || dev->device_kobj.parent)
 			continue;
 
 		if (one_device && one_device != dev)
 			continue;
 
+		error = kobject_init_and_add(&dev->device_kobj, &device_ktype,
+				fs_info->device_dir_kobj, "%s",
+				strrchr(rcu_str_deref(dev->name), '/') + 1);
+		if (error)
+			break;
+
 		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(&dev->device_kobj,
 					  disk_kobj, disk_kobj->name);
 		if (error)
 			break;
+
 	}
 
 	return error;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 25f0505..d0c9c32 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -113,6 +113,8 @@ struct btrfs_device {
 	int dev_stats_valid;
 	int dev_stats_dirty; /* counters need to be written to disk */
 	atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
+
+	struct kobject device_kobj;
 };
 
 struct btrfs_fs_devices {
-- 
1.8.5.3


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

* Re: [PATCH 1/6 v2] btrfs: rename add_device_membership to btrfs_kobj_add_device
  2014-06-03  3:35 ` [PATCH 1/6 v2] btrfs: rename add_device_membership to btrfs_kobj_add_device Anand Jain
@ 2014-06-03 13:23   ` David Sterba
  0 siblings, 0 replies; 17+ messages in thread
From: David Sterba @ 2014-06-03 13:23 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, jeffm, dsterba, clm

On Tue, Jun 03, 2014 at 11:35:59AM +0800, Anand Jain wrote:
> From: Anand Jain <anand.jain@oracle.com>
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.cz>

Thanks.

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

* Re: [PATCH 2/6 v2] btrfs: dev delete should remove sysfs entry
  2014-06-03  3:36 ` [PATCH 2/6 v2] btrfs: dev delete should remove sysfs entry Anand Jain
@ 2014-06-03 13:23   ` David Sterba
  0 siblings, 0 replies; 17+ messages in thread
From: David Sterba @ 2014-06-03 13:23 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, jeffm, dsterba, clm

On Tue, Jun 03, 2014 at 11:36:00AM +0800, Anand Jain wrote:
> when we delete the device from the mounted btrfs,
> we would need its corresponding sysfs enty to
> be removed as well.
> 
> Signed-off-by: Anand Jain <Anand.Jain@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.cz>

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

* Re: [PATCH 3/6 v2] btrfs: dev add should add its sysfs entry
  2014-06-03  3:36 ` [PATCH 3/6 v2] btrfs: dev add should add its " Anand Jain
@ 2014-06-03 13:23   ` David Sterba
  0 siblings, 0 replies; 17+ messages in thread
From: David Sterba @ 2014-06-03 13:23 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, jeffm, dsterba, clm

On Tue, Jun 03, 2014 at 11:36:01AM +0800, Anand Jain wrote:
> we would need the device links to be created,
> when device is added.
> 
> Signed-off-by: Anand Jain <Anand.Jain@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.cz>

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

* Re: [PATCH 4/6 v2] btrfs: dev replace should replace the sysfs entry
  2014-06-03  3:36 ` [PATCH 4/6 v2] btrfs: dev replace should replace the " Anand Jain
@ 2014-06-03 13:39   ` David Sterba
  0 siblings, 0 replies; 17+ messages in thread
From: David Sterba @ 2014-06-03 13:39 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, jeffm, dsterba, clm

On Tue, Jun 03, 2014 at 11:36:02AM +0800, Anand Jain wrote:
> when we replace the device its corresponding sysfs
> entry has to be replaced as well
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.cz>

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

* Re: [PATCH 5/6 v2] btrfs: create sprout should rename fsid on the sysfs as well
  2014-06-03  3:36 ` [PATCH 5/6 v2] btrfs: create sprout should rename fsid on the sysfs as well Anand Jain
@ 2014-06-03 13:41   ` David Sterba
  0 siblings, 0 replies; 17+ messages in thread
From: David Sterba @ 2014-06-03 13:41 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, jeffm, dsterba, clm

On Tue, Jun 03, 2014 at 11:36:03AM +0800, Anand Jain wrote:
> Creating sprout will change the fsid of the mounted root.
> do the same on the sysfs as well.
> 
> reproducer:
>  mount /dev/sdb /btrfs (seed disk)
>  btrfs dev add /dev/sdc /btrfs
>  mount -o rw,remount /btrfs
>  btrfs dev del /dev/sdb /btrfs
>  mount /dev/sdb /btrfs
> 
> Error:
> kobject_add_internal failed for fe350492-dc28-4051-a601-e017b17e6145 with -EEXIST, don't try to register things with the same name in the same directory.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.cz>

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

* Re: [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs/<fsid>/devices
  2014-06-03  3:36 ` [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs/<fsid>/devices Anand Jain
@ 2014-06-03 14:08   ` David Sterba
  2014-06-04  4:03     ` Anand Jain
  0 siblings, 1 reply; 17+ messages in thread
From: David Sterba @ 2014-06-03 14:08 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, jeffm, dsterba, clm, hugo

On Tue, Jun 03, 2014 at 11:36:04AM +0800, Anand Jain wrote:
> From: Anand Jain <anand.jain@oracle.com>
> 
> As of now with out this patch the sysfs interface under dir
> /sys/fs/btrfs/<fsid>/devices is just link to the block devs.

At this point it's part of the sysfs ABI and should not be changed.

> Moving forward we would need the above btrfs sysfs path to contain more
> info about the btrfs devices. So this patch provides a framework for
> the same.

I'd prefer a separate directory for that, Hugo once sent a proposal for
that, /sys/fs/btrfs/devmap/... with enhanced information about the
devices

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

but was not a per-filesystem list of devices as your patch introduces. I
think we should consider something similar to the /dev/disk/... symlink
structure, both per-module and per-filesystem.

Example:

/sys/fs/btrfs/devmap/by-id/
  contains directories with integer numbers that represent devices

/sys/fs/btrfs/devmap/by-uuid/
  symlink to the corresponding by-id directory based on the device uuid

/sys/fs/btrfs/devmap/by-dev/
  dtto but by the the physical device name

I take the device id as the primary reference to the devices, the
physical block devices may differ, but the ids are stable.

The by-id/by-uuid/by-dev are there for users' convenience.

The /sys/fs/btrfs/<uuid>/ directory would contain subset of the devmap
and has symlinks to /sys/fs/btrfs/devmap directories.

This should present the general idea of the device-related directories,
naming or other tweaking is possible.

The existing directory 'devices' links to the physical devices (located
in sysfs), while the devmap represents the btrfs module POV, so this is
not duplicate.

> And as of now a probe interface is added, which can be used to notify
> btrfs for any change in the device status.

So, the probe  would be located in the 'by-id/n' directory.

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

* Re: [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs/<fsid>/devices
  2014-06-03 14:08   ` David Sterba
@ 2014-06-04  4:03     ` Anand Jain
  0 siblings, 0 replies; 17+ messages in thread
From: Anand Jain @ 2014-06-04  4:03 UTC (permalink / raw)
  To: dsterba, linux-btrfs, jeffm, clm, hugo


David,

  Thanks for the comments


>> As of now with out this patch the sysfs interface under dir
>> /sys/fs/btrfs/<fsid>/devices is just link to the block devs.
>
> At this point it's part of the sysfs ABI and should not be changed.

  can't we lean on the experimental clause to change it either ?
  practically is there anything thats already depending on this
  dev link ?

> Example:
>
> /sys/fs/btrfs/devmap/by-id/
>    contains directories with integer numbers that represent devices

  This won't work.
  devid isn't unique at the btrfs-module level. its under fsid.


  [IMO. its ok if the ideas doesn't match ;-) as in any case I
  will be doing it in the way the most want]


  When user come to sys/fs/btrfs their  "main"  reference of identifying
  a  "volume"  is the FSID/label.  not individual disks.
  Of course disks are the sub-references of a volume.


  I suggest - first do the way btrfs-kernel does (which is - group disks
  under fsid) And later create abstraction links as needed which we don't
  have to worry about as of now.


Thanks, Anand

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

* Re: [PATCH 0/6 v2] update sysfs per btrfs device operations
  2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
                   ` (5 preceding siblings ...)
  2014-06-03  3:36 ` [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs/<fsid>/devices Anand Jain
@ 2014-06-20  9:53 ` David Sterba
  2014-06-20 15:40   ` Chris Mason
  2014-06-20 15:42   ` Chris Mason
  6 siblings, 2 replies; 17+ messages in thread
From: David Sterba @ 2014-06-20  9:53 UTC (permalink / raw)
  To: clm; +Cc: Anand Jain, linux-btrfs, jeffm, dsterba

Hi Chris,

any reason why the patches 1-5 were not added to 3.16 queue?

On Tue, Jun 03, 2014 at 11:35:58AM +0800, Anand Jain wrote:
>   btrfs: rename add_device_membership to btrfs_kobj_add_device
>   btrfs: dev delete should remove sysfs entry
>   btrfs: dev add should add its sysfs entry
>   btrfs: dev replace should replace the sysfs entry
>   btrfs: create sprout should rename fsid on the sysfs as well

The last one was an RFC and independent (I'm going to answer Anand's
comments later)

>   btrfs: revamp /sys/fs/btrfs/<fsid>/devices

Thanks.

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

* Re: [PATCH 0/6 v2] update sysfs per btrfs device operations
  2014-06-20  9:53 ` [PATCH 0/6 v2] update sysfs per btrfs device operations David Sterba
@ 2014-06-20 15:40   ` Chris Mason
  2014-06-20 15:42   ` Chris Mason
  1 sibling, 0 replies; 17+ messages in thread
From: Chris Mason @ 2014-06-20 15:40 UTC (permalink / raw)
  To: dsterba, Anand Jain, linux-btrfs, jeffm



On 06/20/2014 05:53 AM, David Sterba wrote:
> Hi Chris,
> 
> any reason why the patches 1-5 were not added to 3.16 queue?
> 
> On Tue, Jun 03, 2014 at 11:35:58AM +0800, Anand Jain wrote:
>>   btrfs: rename add_device_membership to btrfs_kobj_add_device
>>   btrfs: dev delete should remove sysfs entry
>>   btrfs: dev add should add its sysfs entry
>>   btrfs: dev replace should replace the sysfs entry
>>   btrfs: create sprout should rename fsid on the sysfs as well

A mistake on my part.  I had them in a different bundle and missed it
(sorry Anand).  Today's pull has the locking fixes and a few others,
I'll put these in a pull early next week.

Thanks guys,
Chris

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

* Re: [PATCH 0/6 v2] update sysfs per btrfs device operations
  2014-06-20  9:53 ` [PATCH 0/6 v2] update sysfs per btrfs device operations David Sterba
  2014-06-20 15:40   ` Chris Mason
@ 2014-06-20 15:42   ` Chris Mason
  1 sibling, 0 replies; 17+ messages in thread
From: Chris Mason @ 2014-06-20 15:42 UTC (permalink / raw)
  To: dsterba, Anand Jain, linux-btrfs, jeffm



On 06/20/2014 05:53 AM, David Sterba wrote:
> Hi Chris,
> 
> any reason why the patches 1-5 were not added to 3.16 queue?
> 
> On Tue, Jun 03, 2014 at 11:35:58AM +0800, Anand Jain wrote:
>>   btrfs: rename add_device_membership to btrfs_kobj_add_device
>>   btrfs: dev delete should remove sysfs entry
>>   btrfs: dev add should add its sysfs entry
>>   btrfs: dev replace should replace the sysfs entry
>>   btrfs: create sprout should rename fsid on the sysfs as well

A mistake on my part.  I had them in a different bundle and missed it
(sorry Anand).  Today's pull has the locking fixes and a few others,
I'll put these in a pull early next week.

Thanks guys,
Chris

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

end of thread, other threads:[~2014-06-20 15:36 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-03  3:35 [PATCH 0/6 v2] update sysfs per btrfs device operations Anand Jain
2014-06-03  3:35 ` [PATCH 1/6 v2] btrfs: rename add_device_membership to btrfs_kobj_add_device Anand Jain
2014-06-03 13:23   ` David Sterba
2014-06-03  3:36 ` [PATCH 2/6 v2] btrfs: dev delete should remove sysfs entry Anand Jain
2014-06-03 13:23   ` David Sterba
2014-06-03  3:36 ` [PATCH 3/6 v2] btrfs: dev add should add its " Anand Jain
2014-06-03 13:23   ` David Sterba
2014-06-03  3:36 ` [PATCH 4/6 v2] btrfs: dev replace should replace the " Anand Jain
2014-06-03 13:39   ` David Sterba
2014-06-03  3:36 ` [PATCH 5/6 v2] btrfs: create sprout should rename fsid on the sysfs as well Anand Jain
2014-06-03 13:41   ` David Sterba
2014-06-03  3:36 ` [PATCH 6/6 RFC v2] btrfs: revamp /sys/fs/btrfs/<fsid>/devices Anand Jain
2014-06-03 14:08   ` David Sterba
2014-06-04  4:03     ` Anand Jain
2014-06-20  9:53 ` [PATCH 0/6 v2] update sysfs per btrfs device operations David Sterba
2014-06-20 15:40   ` Chris Mason
2014-06-20 15:42   ` Chris Mason

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).