Linux-BTRFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups
@ 2020-02-12  9:28 Anand Jain
  2020-02-12  9:28 ` [PATCH v2 1/4] btrfs: sysfs, add UUID/devinfo kobject Anand Jain
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Anand Jain @ 2020-02-12  9:28 UTC (permalink / raw)
  To: linux-btrfs

Here, first patch creates UUID/devinfo. 2nd relocates devid kobject to
UUID/devinfo.

Patches 3 and 4 are cleanups.

Anand Jain (4):
  btrfs: sysfs, add UUID/devinfo kobject
  btrfs: sysfs, move dev_state kobject under UUID/devinfo
  btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid
  btrfs: sysfs, rename device_link add,remove functions

 fs/btrfs/dev-replace.c |  4 ++--
 fs/btrfs/sysfs.c       | 31 +++++++++++++++++++++++--------
 fs/btrfs/sysfs.h       |  4 ++--
 fs/btrfs/volumes.c     |  8 ++++----
 fs/btrfs/volumes.h     |  1 +
 5 files changed, 32 insertions(+), 16 deletions(-)

-- 
1.8.3.1


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

* [PATCH v2 1/4] btrfs: sysfs, add UUID/devinfo kobject
  2020-02-12  9:28 [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups Anand Jain
@ 2020-02-12  9:28 ` Anand Jain
  2020-02-12  9:28 ` [PATCH 2/4] btrfs: sysfs, move dev_state kobject under UUID/devinfo Anand Jain
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Anand Jain @ 2020-02-12  9:28 UTC (permalink / raw)
  To: linux-btrfs

Creates kobject /sys/fs/btrfs/UUID/devinfo to hold
btrfs_fs_devices::dev_state attribute.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: update change log.

 fs/btrfs/sysfs.c   | 15 +++++++++++++++
 fs/btrfs/volumes.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 7436422194da..6bac61c42c05 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -901,6 +901,12 @@ 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->devinfo_kobj) {
+		kobject_del(fs_devs->devinfo_kobj);
+		kobject_put(fs_devs->devinfo_kobj);
+		fs_devs->devinfo_kobj = NULL;
+	}
+
 	if (fs_devs->devices_kobj) {
 		kobject_del(fs_devs->devices_kobj);
 		kobject_put(fs_devs->devices_kobj);
@@ -1369,6 +1375,15 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs)
 		return -ENOMEM;
 	}
 
+	fs_devs->devinfo_kobj = kobject_create_and_add("devinfo",
+						       &fs_devs->fsid_kobj);
+	if (!fs_devs->devinfo_kobj) {
+		btrfs_err(fs_devs->fs_info,
+			  "failed to init sysfs devinfo kobject");
+		btrfs_sysfs_remove_fsid(fs_devs);
+		return -ENOMEM;
+	}
+
 	return 0;
 }
 
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 690d4f5a0653..309cda477589 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -258,6 +258,7 @@ struct btrfs_fs_devices {
 	/* sysfs kobjects */
 	struct kobject fsid_kobj;
 	struct kobject *devices_kobj;
+	struct kobject *devinfo_kobj;
 	struct completion kobj_unregister;
 };
 
-- 
1.8.3.1


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

* [PATCH 2/4] btrfs: sysfs, move dev_state kobject under UUID/devinfo
  2020-02-12  9:28 [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups Anand Jain
  2020-02-12  9:28 ` [PATCH v2 1/4] btrfs: sysfs, add UUID/devinfo kobject Anand Jain
@ 2020-02-12  9:28 ` Anand Jain
  2020-02-12  9:28 ` [PATCH v2 3/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Anand Jain
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Anand Jain @ 2020-02-12  9:28 UTC (permalink / raw)
  To: linux-btrfs

Originally it was planned to create dev_state under UUID/devinfo,
something got messed up, and ended up under UUID/devices instead.
If it should be ok to relocate, bring it back under UUID/devinfo.

Fixes: 668e48af7a94 (btrfs: sysfs, add devid/dev_state kobject and device
attributes)
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 6bac61c42c05..3c10e78924d0 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1295,7 +1295,7 @@ int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
 
 		init_completion(&dev->kobj_unregister);
 		error = kobject_init_and_add(&dev->devid_kobj, &devid_ktype,
-					     fs_devices->devices_kobj, "%llu",
+					     fs_devices->devinfo_kobj, "%llu",
 					     dev->devid);
 		if (error) {
 			kobject_put(&dev->devid_kobj);
-- 
1.8.3.1


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

* [PATCH v2 3/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid
  2020-02-12  9:28 [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups Anand Jain
  2020-02-12  9:28 ` [PATCH v2 1/4] btrfs: sysfs, add UUID/devinfo kobject Anand Jain
  2020-02-12  9:28 ` [PATCH 2/4] btrfs: sysfs, move dev_state kobject under UUID/devinfo Anand Jain
@ 2020-02-12  9:28 ` Anand Jain
  2020-02-12  9:28 ` [PATCH v3 4/4] btrfs: sysfs, rename device_link add,remove functions Anand Jain
  2020-02-12 17:35 ` [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups David Sterba
  4 siblings, 0 replies; 8+ messages in thread
From: Anand Jain @ 2020-02-12  9:28 UTC (permalink / raw)
  To: linux-btrfs

We have one simple function btrfs_sysfs_remove_fsid() to undo
btrfs_sysfs_add_fsid(). Which is also smart enough to check if the kobject
is initialized.

So lets use this function while retreating from the function
btrfs_sysfs_add_fsid().

One difference if btrfs_sysfs_remove_fsid() used is that, now we also call
kobject_del() which was missing before. So tested (with kobject debug
turned on) and find that there isn't any change with or without
kobject_del().

This is a cleanup patch.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: change log updated.

 fs/btrfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 3c10e78924d0..119edd4341d6 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1371,7 +1371,7 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs)
 	if (!fs_devs->devices_kobj) {
 		btrfs_err(fs_devs->fs_info,
 			  "failed to init sysfs device interface");
-		kobject_put(&fs_devs->fsid_kobj);
+		btrfs_sysfs_remove_fsid(fs_devs);
 		return -ENOMEM;
 	}
 
-- 
1.8.3.1


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

* [PATCH v3 4/4] btrfs: sysfs, rename device_link add,remove functions
  2020-02-12  9:28 [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups Anand Jain
                   ` (2 preceding siblings ...)
  2020-02-12  9:28 ` [PATCH v2 3/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Anand Jain
@ 2020-02-12  9:28 ` Anand Jain
  2020-02-12 17:35 ` [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups David Sterba
  4 siblings, 0 replies; 8+ messages in thread
From: Anand Jain @ 2020-02-12  9:28 UTC (permalink / raw)
  To: linux-btrfs

Since commit 668e48af7a94 (btrfs: sysfs, add devid/dev_state kobject and
device attributes), the functions btrfs_sysfs_add_device_link() and
btrfs_sysfs_rm_device_link() does more than just adding and removing the
device link as its name indicated.

Its time to rename them.

No functional changes.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Update change log. Change ..UUID/devices to ..UUID/devinfo
v3: Update change log.

 fs/btrfs/dev-replace.c |  4 ++--
 fs/btrfs/sysfs.c       | 12 ++++++------
 fs/btrfs/sysfs.h       |  4 ++--
 fs/btrfs/volumes.c     |  8 ++++----
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 2aad07cdaea8..131d23de5f64 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -512,7 +512,7 @@ static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
 	atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0);
 	up_write(&dev_replace->rwsem);
 
-	ret = btrfs_sysfs_add_device_link(tgt_device->fs_devices, tgt_device);
+	ret = btrfs_sysfs_add_devices_attr(tgt_device->fs_devices, tgt_device);
 	if (ret)
 		btrfs_err(fs_info, "kobj add dev failed %d", ret);
 
@@ -743,7 +743,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 	mutex_unlock(&fs_info->fs_devices->device_list_mutex);
 
 	/* replace the sysfs entry */
-	btrfs_sysfs_rm_device_link(fs_info->fs_devices, src_device);
+	btrfs_sysfs_remove_devices_attr(fs_info->fs_devices, src_device);
 	btrfs_sysfs_update_devid(tgt_device);
 	btrfs_rm_dev_replace_free_srcdev(src_device);
 
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 119edd4341d6..ef42aa16a6d3 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -960,7 +960,7 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)
 	addrm_unknown_feature_attrs(fs_info, false);
 	sysfs_remove_group(&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group);
 	sysfs_remove_files(&fs_info->fs_devices->fsid_kobj, btrfs_attrs);
-	btrfs_sysfs_rm_device_link(fs_info->fs_devices, NULL);
+	btrfs_sysfs_remove_devices_attr(fs_info->fs_devices, NULL);
 }
 
 static const char * const btrfs_feature_set_names[FEAT_MAX] = {
@@ -1149,7 +1149,7 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
 
 /* when one_device is NULL, it removes all device links */
 
-int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
+int btrfs_sysfs_remove_devices_attr(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device)
 {
 	struct hd_struct *disk;
@@ -1269,8 +1269,8 @@ static void btrfs_release_devid_kobj(struct kobject *kobj)
 	.release	= btrfs_release_devid_kobj,
 };
 
-int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
-				struct btrfs_device *one_device)
+int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices,
+				 struct btrfs_device *one_device)
 {
 	int error = 0;
 	struct btrfs_device *dev;
@@ -1395,13 +1395,13 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
 
 	btrfs_set_fs_info_ptr(fs_info);
 
-	error = btrfs_sysfs_add_device_link(fs_devs, NULL);
+	error = btrfs_sysfs_add_devices_attr(fs_devs, NULL);
 	if (error)
 		return error;
 
 	error = sysfs_create_files(fsid_kobj, btrfs_attrs);
 	if (error) {
-		btrfs_sysfs_rm_device_link(fs_devs, NULL);
+		btrfs_sysfs_remove_devices_attr(fs_devs, NULL);
 		return error;
 	}
 
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index c68582add92e..ccf33eaf9e59 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -14,9 +14,9 @@ enum btrfs_feature_set {
 
 char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
 const char * const btrfs_feature_set_name(enum btrfs_feature_set set);
-int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
+int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices,
 		struct btrfs_device *one_device);
-int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
+int btrfs_sysfs_remove_devices_attr(struct btrfs_fs_devices *fs_devices,
                 struct btrfs_device *one_device);
 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs);
 void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b092021e41e9..651a8dd89f29 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2054,7 +2054,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
 	if (device->bdev) {
 		cur_devices->open_devices--;
 		/* remove sysfs entry */
-		btrfs_sysfs_rm_device_link(fs_devices, device);
+		btrfs_sysfs_remove_devices_attr(fs_devices, device);
 	}
 
 	num_devices = btrfs_super_num_devices(fs_info->super_copy) - 1;
@@ -2174,7 +2174,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
 
 	mutex_lock(&fs_devices->device_list_mutex);
 
-	btrfs_sysfs_rm_device_link(fs_devices, tgtdev);
+	btrfs_sysfs_remove_devices_attr(fs_devices, tgtdev);
 
 	if (tgtdev->bdev)
 		fs_devices->open_devices--;
@@ -2522,7 +2522,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 				    orig_super_num_devices + 1);
 
 	/* add sysfs device entry */
-	btrfs_sysfs_add_device_link(fs_devices, device);
+	btrfs_sysfs_add_devices_attr(fs_devices, device);
 
 	/*
 	 * we've got more storage, clear any full flags on the space
@@ -2590,7 +2590,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	return ret;
 
 error_sysfs:
-	btrfs_sysfs_rm_device_link(fs_devices, device);
+	btrfs_sysfs_remove_devices_attr(fs_devices, device);
 	mutex_lock(&fs_info->fs_devices->device_list_mutex);
 	mutex_lock(&fs_info->chunk_mutex);
 	list_del_rcu(&device->dev_list);
-- 
1.8.3.1


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

* Re: [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups
  2020-02-12  9:28 [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups Anand Jain
                   ` (3 preceding siblings ...)
  2020-02-12  9:28 ` [PATCH v3 4/4] btrfs: sysfs, rename device_link add,remove functions Anand Jain
@ 2020-02-12 17:35 ` David Sterba
  2020-02-13  8:40   ` [PATCH] btrfs: fix devid attribute name Anand Jain
  4 siblings, 1 reply; 8+ messages in thread
From: David Sterba @ 2020-02-12 17:35 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Wed, Feb 12, 2020 at 05:28:09PM +0800, Anand Jain wrote:
> Here, first patch creates UUID/devinfo. 2nd relocates devid kobject to
> UUID/devinfo.
> 
> Patches 3 and 4 are cleanups.
> 
> Anand Jain (4):
>   btrfs: sysfs, add UUID/devinfo kobject
>   btrfs: sysfs, move dev_state kobject under UUID/devinfo
>   btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid
>   btrfs: sysfs, rename device_link add,remove functions

Thanks, all added to misc-next, 1 and 2 are going to 5.6-rc.

Please number the patchset iterations only, not versions of individual
patches.

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

* [PATCH] btrfs: fix devid attribute name
  2020-02-12 17:35 ` [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups David Sterba
@ 2020-02-13  8:40   ` Anand Jain
  2020-02-13 13:12     ` David Sterba
  0 siblings, 1 reply; 8+ messages in thread
From: Anand Jain @ 2020-02-13  8:40 UTC (permalink / raw)
  To: linux-btrfs

It looks like one of the attribute was missed out while renaming the
devid attribute. So fix it here.

Fixes: 668e48af7a94 (btrfs: sysfs, add devid/dev_state kobject and device
attributes)
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
Hi David, There is one trivial item which also got messed up in this
series, its about function renaming. Can we merge this in misc-next.

 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 91e2ec393a92..66cfefb03e1f 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1272,7 +1272,7 @@ static ssize_t btrfs_devinfo_in_fs_metadata_show(struct kobject *kobj,
 }
 BTRFS_ATTR(devid, in_fs_metadata, btrfs_devinfo_in_fs_metadata_show);
 
-static ssize_t btrfs_sysfs_missing_show(struct kobject *kobj,
+static ssize_t btrfs_devinfo_missing_show(struct kobject *kobj,
 					struct kobj_attribute *a, char *buf)
 {
 	int val;
@@ -1283,7 +1283,7 @@ static ssize_t btrfs_sysfs_missing_show(struct kobject *kobj,
 
 	return snprintf(buf, PAGE_SIZE, "%d\n", val);
 }
-BTRFS_ATTR(devid, missing, btrfs_sysfs_missing_show);
+BTRFS_ATTR(devid, missing, btrfs_devinfo_missing_show);
 
 static ssize_t btrfs_devinfo_replace_target_show(struct kobject *kobj,
 					         struct kobj_attribute *a,
-- 
1.8.3.1


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

* Re: [PATCH] btrfs: fix devid attribute name
  2020-02-13  8:40   ` [PATCH] btrfs: fix devid attribute name Anand Jain
@ 2020-02-13 13:12     ` David Sterba
  0 siblings, 0 replies; 8+ messages in thread
From: David Sterba @ 2020-02-13 13:12 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Thu, Feb 13, 2020 at 04:40:53PM +0800, Anand Jain wrote:
> It looks like one of the attribute was missed out while renaming the
> devid attribute. So fix it here.
> 
> Fixes: 668e48af7a94 (btrfs: sysfs, add devid/dev_state kobject and device
> attributes)
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> Hi David, There is one trivial item which also got messed up in this
> series, its about function renaming. Can we merge this in misc-next.

Yes, I noticed too, thanks for the patch.

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

end of thread, back to index

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12  9:28 [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups Anand Jain
2020-02-12  9:28 ` [PATCH v2 1/4] btrfs: sysfs, add UUID/devinfo kobject Anand Jain
2020-02-12  9:28 ` [PATCH 2/4] btrfs: sysfs, move dev_state kobject under UUID/devinfo Anand Jain
2020-02-12  9:28 ` [PATCH v2 3/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Anand Jain
2020-02-12  9:28 ` [PATCH v3 4/4] btrfs: sysfs, rename device_link add,remove functions Anand Jain
2020-02-12 17:35 ` [PATCH 0/4] btrfs: sysfs, add devinfo, fix devid and cleanups David Sterba
2020-02-13  8:40   ` [PATCH] btrfs: fix devid attribute name Anand Jain
2020-02-13 13:12     ` David Sterba

Linux-BTRFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-btrfs/0 linux-btrfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-btrfs linux-btrfs/ https://lore.kernel.org/linux-btrfs \
		linux-btrfs@vger.kernel.org
	public-inbox-index linux-btrfs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-btrfs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git