* [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state
@ 2020-02-03 11:00 Anand Jain
2020-02-03 11:00 ` [PATCH resend 1/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Anand Jain
` (4 more replies)
0 siblings, 5 replies; 11+ messages in thread
From: Anand Jain @ 2020-02-03 11:00 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
Resend:
Patch 4/4 is already integrated without the cleanup and preparatory
patches (1,2,3)/4. So I am resending those 3 patches. And the changes
in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch
4/4 has the details of the changes.
Patch 1/4 is a cleanup patch.
Patch 2/4 adds the kobject devinfo which is a preparatory to patch 4/4.
Patch 3/4 was sent before, no functional changes, change log is updated.
Patch 4/4 creates the attribute dev_state.
Anand Jain (4):
btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid
btrfs: sysfs, add UUID/devinfo kobject
btrfs: sysfs, rename device_link add,remove functions
btrfs: sysfs, add devid/dev_state kobject and device attribute
fs/btrfs/dev-replace.c | 4 +-
fs/btrfs/sysfs.c | 156 +++++++++++++++++++++++++++++++++++++++----------
fs/btrfs/sysfs.h | 4 +-
fs/btrfs/volumes.c | 8 +--
fs/btrfs/volumes.h | 3 +
5 files changed, 137 insertions(+), 38 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH resend 1/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid
2020-02-03 11:00 [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state Anand Jain
@ 2020-02-03 11:00 ` Anand Jain
2020-02-03 11:00 ` [PATCH resend 2/4] btrfs: sysfs, add UUID/devinfo kobject Anand Jain
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2020-02-03 11:00 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
We have one simple function btrfs_sysfs_remove_fsid() to cleanup
kobjects added by btrfs_sysfs_add_fsid() and calls kobject_put() and
kobject_delete() only if the kobject is initialized or not null.
So use this function while retreating in the function
btrfs_sysfs_add_fsid().
One difference though, earlier we did not call kobject_del() during
retreat in btrfs_sysfs_add_fsid() and I did experiment to figureout
if that's an error or warning, however I didn't notice any such issues
with or without kobject_del() not being called.
So this patch is just for cleanup.
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 55e4ed1af29c..8def038dc2bd 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1256,7 +1256,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;
}
--
2.23.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH resend 2/4] btrfs: sysfs, add UUID/devinfo kobject
2020-02-03 11:00 [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state Anand Jain
2020-02-03 11:00 ` [PATCH resend 1/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Anand Jain
@ 2020-02-03 11:00 ` Anand Jain
2020-02-03 11:00 ` [PATCH resend v2 3/4] btrfs: sysfs, rename device_link add,remove functions Anand Jain
` (2 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2020-02-03 11:00 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
Preparatory patch creates kobject /sys/fs/btrfs/UUID/devinfo to hold
btrfs_fs_devices::dev_state attribute.
This is being added in the mount context, that means we don't see
UUID/devinfo before the mount (yet).
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
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 8def038dc2bd..58ef2c04e5be 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);
@@ -1260,6 +1266,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 9c7d4fe5c39a..98535f1e208e 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -254,6 +254,7 @@ struct btrfs_fs_devices {
/* sysfs kobjects */
struct kobject fsid_kobj;
struct kobject *devices_kobj;
+ struct kobject *devinfo_kobj;
struct completion kobj_unregister;
};
--
2.23.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH resend v2 3/4] btrfs: sysfs, rename device_link add,remove functions
2020-02-03 11:00 [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state Anand Jain
2020-02-03 11:00 ` [PATCH resend 1/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Anand Jain
2020-02-03 11:00 ` [PATCH resend 2/4] btrfs: sysfs, add UUID/devinfo kobject Anand Jain
@ 2020-02-03 11:00 ` Anand Jain
2020-02-03 11:00 ` [PATCH v5 4/4] btrfs: sysfs, add devid/dev_state kobject and device attribute Anand Jain
2020-02-03 17:16 ` [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state David Sterba
4 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2020-02-03 11:00 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
In preparation to add btrfs_device::dev_state attribute in
/sys/fs/btrfs/UUID/devinfo
Rename btrfs_sysfs_add_device_link() and btrfs_sysfs_rm_device_link() to
btrfs_sysfs_add_devices_attr() and btrfs_sysfs_remove_devices_attr() as
these functions is going to create device attribute rather than just
the link to the disk. No functional changes.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Update change log. Change ..UUID/devices to ..UUID/devinfo
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 b6a07fa93b53..13a4ebd04a7a 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_rm_dev_replace_free_srcdev(src_device);
/* write back the superblocks */
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 58ef2c04e5be..10b9bc551330 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;
@@ -1181,8 +1181,8 @@ int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
return 0;
}
-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;
@@ -1286,13 +1286,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 3d27b39eaf94..9d97b3c8db4e 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 9cfc668f91f4..45dd254afb26 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);
--
2.23.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v5 4/4] btrfs: sysfs, add devid/dev_state kobject and device attribute
2020-02-03 11:00 [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state Anand Jain
` (2 preceding siblings ...)
2020-02-03 11:00 ` [PATCH resend v2 3/4] btrfs: sysfs, rename device_link add,remove functions Anand Jain
@ 2020-02-03 11:00 ` Anand Jain
2020-02-03 17:16 ` [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state David Sterba
4 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2020-02-03 11:00 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
New sysfs attributes that track the filesystem status of devices, stored
in the per-filesystem directory in /sys/fs/btrfs/FSID/devinfo . There's
a directory for each device, with name corresponding to the numerical
device id.
in_fs_metadata - device is in the list of fs metadata
missing - device is missing (no device node or block device)
replace_target - device is target of replace
writeable - writes from fs are allowed
These attributes reflect the state of the device::dev_state and created
at mount time.
Sample output:
$ pwd
/sys/fs/btrfs/6e1961f1-5918-4ecc-a22f-948897b409f7/devinfo/1/
$ ls
in_fs_metadata missing replace_target writeable
$ cat missing
0
The output from these attributes are 0 or 1. 0 indicates unset and 1
indicates set. These attributes are readonly.
It is observed that the device delete thread and sysfs read thread will
not race because the delete thread calls sysfs kobject_put() which in
turn waits for existing sysfs read to complete.
Note for device replace devid swap:
During the replace the target device temporarily assumes devid 0 before
assigning the devid of the soruce device.
In btrfs_dev_replace_finishing() we remove source sysfs devid using the
function btrfs_sysfs_remove_devices_attr(), so after that call
kobject_rename() to update the devid in the sysfs. This adds and calls
btrfs_sysfs_update_devid() helper function to update the device id.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
---
v5: squash [PATCH] btrfs: update devid after replace
import changes as in misc-next
changelog
rename btrfs_sysfs_xx to btrfs_devinfo_xx
reorder devinfo attributes
relocate btrfs_sysfs_update_devid with in sysfs.c
add device in the title
rename btrfs_sysfs_missing_show to btrfs_devinfo_missing_show
v4:
after patch
[PATCH v5 2/2] btrfs: reset device back to allocation state when removing
in misc-next, the device::devid_kobj remains stale, fix it by using
release.
v3:
Use optional groupid devid in BTRFS_ATTR(), it was blank in v2.
V2:
Make the devinfo attribute to carry one parameter, so now
instead of dev_state attribute, we create in_fs_metadata,
writeable, missing and replace_target attributes.
---
fs/btrfs/dev-replace.c | 1 +
fs/btrfs/sysfs.c | 155 +++++++++++++++++++++++++++++++++++------
fs/btrfs/sysfs.h | 1 +
fs/btrfs/volumes.h | 4 ++
4 files changed, 138 insertions(+), 23 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 13a4ebd04a7a..131d23de5f64 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -744,6 +744,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
/* replace the sysfs entry */
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);
/* write back the superblocks */
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 10b9bc551330..364c0db36a3f 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1158,29 +1158,117 @@ int btrfs_sysfs_remove_devices_attr(struct btrfs_fs_devices *fs_devices,
if (!fs_devices->devices_kobj)
return -EINVAL;
- if (one_device && one_device->bdev) {
- disk = one_device->bdev->bd_part;
- disk_kobj = &part_to_dev(disk)->kobj;
+ if (one_device) {
+ if (one_device->bdev) {
+ disk = one_device->bdev->bd_part;
+ disk_kobj = &part_to_dev(disk)->kobj;
+ sysfs_remove_link(fs_devices->devices_kobj,
+ disk_kobj->name);
+ }
- sysfs_remove_link(fs_devices->devices_kobj, disk_kobj->name);
- }
+ kobject_del(&one_device->devid_kobj);
+ kobject_put(&one_device->devid_kobj);
+
+ wait_for_completion(&one_device->kobj_unregister);
- if (one_device)
return 0;
+ }
- list_for_each_entry(one_device,
- &fs_devices->devices, dev_list) {
- if (!one_device->bdev)
- continue;
- disk = one_device->bdev->bd_part;
- disk_kobj = &part_to_dev(disk)->kobj;
+ list_for_each_entry(one_device, &fs_devices->devices, dev_list) {
+
+ if (one_device->bdev) {
+ disk = one_device->bdev->bd_part;
+ disk_kobj = &part_to_dev(disk)->kobj;
+ sysfs_remove_link(fs_devices->devices_kobj,
+ disk_kobj->name);
+ }
+ kobject_del(&one_device->devid_kobj);
+ kobject_put(&one_device->devid_kobj);
- sysfs_remove_link(fs_devices->devices_kobj, disk_kobj->name);
+ wait_for_completion(&one_device->kobj_unregister);
}
return 0;
}
+static ssize_t btrfs_devinfo_in_fs_metadata_show(struct kobject *kobj,
+ struct kobj_attribute *a,
+ char *buf)
+{
+ int val;
+ struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+ devid_kobj);
+
+ val = !!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state);
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+BTRFS_ATTR(devid, in_fs_metadata, btrfs_devinfo_in_fs_metadata_show);
+
+static ssize_t btrfs_devinfo_missing_show(struct kobject *kobj,
+ struct kobj_attribute *a, char *buf)
+{
+ int val;
+ struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+ devid_kobj);
+
+ val = !!test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state);
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+BTRFS_ATTR(devid, missing, btrfs_devinfo_missing_show);
+
+static ssize_t btrfs_devinfo_replace_target_show(struct kobject *kobj,
+ struct kobj_attribute *a,
+ char *buf)
+{
+ int val;
+ struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+ devid_kobj);
+
+ val = !!test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state);
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+BTRFS_ATTR(devid, replace_target, btrfs_devinfo_replace_target_show);
+
+static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj,
+ struct kobj_attribute *a, char *buf)
+{
+ int val;
+ struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+ devid_kobj);
+
+ val = !!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state);
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show);
+
+static struct attribute *devid_attrs[] = {
+ BTRFS_ATTR_PTR(devid, in_fs_metadata),
+ BTRFS_ATTR_PTR(devid, missing),
+ BTRFS_ATTR_PTR(devid, replace_target),
+ BTRFS_ATTR_PTR(devid, writeable),
+ NULL
+};
+ATTRIBUTE_GROUPS(devid);
+
+static void btrfs_release_devid_kobj(struct kobject *kobj)
+{
+ struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+ devid_kobj);
+
+ memset(&device->devid_kobj, 0, sizeof(struct kobject));
+ complete(&device->kobj_unregister);
+}
+
+static struct kobj_type devid_ktype = {
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = devid_groups,
+ .release = btrfs_release_devid_kobj,
+};
+
int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices,
struct btrfs_device *one_device)
{
@@ -1188,22 +1276,31 @@ int btrfs_sysfs_add_devices_attr(struct btrfs_fs_devices *fs_devices,
struct btrfs_device *dev;
list_for_each_entry(dev, &fs_devices->devices, dev_list) {
- struct hd_struct *disk;
- struct kobject *disk_kobj;
-
- if (!dev->bdev)
- continue;
if (one_device && one_device != dev)
continue;
- disk = dev->bdev->bd_part;
- disk_kobj = &part_to_dev(disk)->kobj;
+ if (dev->bdev) {
+ struct hd_struct *disk;
+ struct kobject *disk_kobj;
+
+ disk = dev->bdev->bd_part;
+ disk_kobj = &part_to_dev(disk)->kobj;
+
+ error = sysfs_create_link(fs_devices->devices_kobj,
+ disk_kobj, disk_kobj->name);
+ if (error)
+ break;
+ }
- error = sysfs_create_link(fs_devices->devices_kobj,
- disk_kobj, disk_kobj->name);
- if (error)
+ init_completion(&dev->kobj_unregister);
+ error = kobject_init_and_add(&dev->devid_kobj, &devid_ktype,
+ fs_devices->devinfo_kobj, "%llu",
+ dev->devid);
+ if (error) {
+ kobject_put(&dev->devid_kobj);
break;
+ }
}
return error;
@@ -1235,6 +1332,18 @@ void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices,
"sysfs: failed to create fsid for sprout");
}
+void btrfs_sysfs_update_devid(struct btrfs_device *device)
+{
+ char tmp[24];
+
+ snprintf(tmp, sizeof(tmp), "%llu", device->devid);
+
+ if (kobject_rename(&device->devid_kobj, tmp))
+ btrfs_warn(device->fs_devices->fs_info,
+ "sysfs: failed to update devid for %llu",
+ device->devid);
+}
+
/* /sys/fs/btrfs/ entry */
static struct kset *btrfs_kset;
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 9d97b3c8db4e..ccf33eaf9e59 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -34,5 +34,6 @@ void btrfs_sysfs_add_block_group_type(struct btrfs_block_group *cache);
int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
struct btrfs_space_info *space_info);
void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info);
+void btrfs_sysfs_update_devid(struct btrfs_device *device);
#endif
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 98535f1e208e..309cda477589 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -136,6 +136,10 @@ struct btrfs_device {
atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
struct extent_io_tree alloc_state;
+
+ struct completion kobj_unregister;
+ /* For sysfs/FSID/devinfo/devid/ */
+ struct kobject devid_kobj;
};
/*
--
2.23.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state
2020-02-03 11:00 [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state Anand Jain
` (3 preceding siblings ...)
2020-02-03 11:00 ` [PATCH v5 4/4] btrfs: sysfs, add devid/dev_state kobject and device attribute Anand Jain
@ 2020-02-03 17:16 ` David Sterba
2020-02-06 6:31 ` Anand Jain
4 siblings, 1 reply; 11+ messages in thread
From: David Sterba @ 2020-02-03 17:16 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs, dsterba
On Mon, Feb 03, 2020 at 07:00:08PM +0800, Anand Jain wrote:
> Resend:
> Patch 4/4 is already integrated without the cleanup and preparatory
> patches (1,2,3)/4. So I am resending those 3 patches. And the changes
> in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch
> 4/4 has the details of the changes.
All the patches have been merged and now are in linus/master branch. I
haven't reordered the patches so they're not in a group and the
preparatory patches are about 10 commits above v5.5-rc7 which is the
beginning of the branch.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state
2020-02-03 17:16 ` [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state David Sterba
@ 2020-02-06 6:31 ` Anand Jain
2020-02-06 14:11 ` David Sterba
0 siblings, 1 reply; 11+ messages in thread
From: Anand Jain @ 2020-02-06 6:31 UTC (permalink / raw)
To: dsterba, linux-btrfs, dsterba
On 2/4/20 1:16 AM, David Sterba wrote:
> On Mon, Feb 03, 2020 at 07:00:08PM +0800, Anand Jain wrote:
>> Resend:
>> Patch 4/4 is already integrated without the cleanup and preparatory
>> patches (1,2,3)/4. So I am resending those 3 patches. And the changes
>> in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch
>> 4/4 has the details of the changes.
>
> All the patches have been merged and now are in linus/master branch.
David,
> I haven't reordered the patches so they're not in a group and the
> preparatory patches are about 10 commits above v5.5-rc7 which is the
> beginning of the branch.
It will cause problem during bisect, without the preparatory patches
the devid kobject lands under devices instead of under devinfo,
that's how I noticed that preparatory patches are missing.
Thanks, Anand
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state
2020-02-06 6:31 ` Anand Jain
@ 2020-02-06 14:11 ` David Sterba
2020-02-11 4:46 ` Anand Jain
0 siblings, 1 reply; 11+ messages in thread
From: David Sterba @ 2020-02-06 14:11 UTC (permalink / raw)
To: Anand Jain; +Cc: dsterba, linux-btrfs, dsterba
On Thu, Feb 06, 2020 at 02:31:02PM +0800, Anand Jain wrote:
>
>
> On 2/4/20 1:16 AM, David Sterba wrote:
> > On Mon, Feb 03, 2020 at 07:00:08PM +0800, Anand Jain wrote:
> >> Resend:
> >> Patch 4/4 is already integrated without the cleanup and preparatory
> >> patches (1,2,3)/4. So I am resending those 3 patches. And the changes
> >> in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch
> >> 4/4 has the details of the changes.
> >
> > All the patches have been merged and now are in linus/master branch.
>
>
> David,
>
> > I haven't reordered the patches so they're not in a group and the
> > preparatory patches are about 10 commits above v5.5-rc7 which is the
> > beginning of the branch.
>
>
> It will cause problem during bisect, without the preparatory patches
> the devid kobject lands under devices instead of under devinfo,
> that's how I noticed that preparatory patches are missing.
I've tested current master and the device ids are indeed placed under
device/ and there is no devinfo/, so this needs to be fixed.
Preparatory patches I was referring to are:
bc036bb33524 btrfs: sysfs, merge btrfs_sysfs_add devices_kobj and fsid
be2cf92e0a2f btrfs: sysfs, rename btrfs_sysfs_add_device()
c6761a9ed329 btrfs: sysfs, btrfs_sysfs_add_fsid() drop unused argument parent
b5501504cb6a btrfs: sysfs, rename devices kobject holder to devices_kobj
so I'll have another look at what you sent.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state
2020-02-06 14:11 ` David Sterba
@ 2020-02-11 4:46 ` Anand Jain
2020-02-11 19:29 ` David Sterba
0 siblings, 1 reply; 11+ messages in thread
From: Anand Jain @ 2020-02-11 4:46 UTC (permalink / raw)
To: dsterba, linux-btrfs, dsterba
On 2/6/20 10:11 PM, David Sterba wrote:
> On Thu, Feb 06, 2020 at 02:31:02PM +0800, Anand Jain wrote:
>>
>>
>> On 2/4/20 1:16 AM, David Sterba wrote:
>>> On Mon, Feb 03, 2020 at 07:00:08PM +0800, Anand Jain wrote:
>>>> Resend:
>>>> Patch 4/4 is already integrated without the cleanup and preparatory
>>>> patches (1,2,3)/4. So I am resending those 3 patches. And the changes
>>>> in patch 4/4 as in misc-next is imported into patch v5 4/4 here. Patch
>>>> 4/4 has the details of the changes.
>>>
>>> All the patches have been merged and now are in linus/master branch.
>>
>>
>> David,
>>
>>> I haven't reordered the patches so they're not in a group and the
>>> preparatory patches are about 10 commits above v5.5-rc7 which is the
>>> beginning of the branch.
>>
>>
>> It will cause problem during bisect, without the preparatory patches
>> the devid kobject lands under devices instead of under devinfo,
>> that's how I noticed that preparatory patches are missing.
>
> I've tested current master and the device ids are indeed placed under
> device/ and there is no devinfo/, so this needs to be fixed.
>
> Preparatory patches I was referring to are:
>
> bc036bb33524 btrfs: sysfs, merge btrfs_sysfs_add devices_kobj and fsid
> be2cf92e0a2f btrfs: sysfs, rename btrfs_sysfs_add_device()
> c6761a9ed329 btrfs: sysfs, btrfs_sysfs_add_fsid() drop unused argument parent
> b5501504cb6a btrfs: sysfs, rename devices kobject holder to devices_kobj
>
> so I'll have another look at what you sent.
>
David,
Busy? Can I ping on this?
Those aren't the preparatory patches. The patches sent here applies
nicely on misc-next with git revert 668e48af7a94
Thanks, Anand
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state
2020-02-11 4:46 ` Anand Jain
@ 2020-02-11 19:29 ` David Sterba
2020-02-12 9:29 ` Anand Jain
0 siblings, 1 reply; 11+ messages in thread
From: David Sterba @ 2020-02-11 19:29 UTC (permalink / raw)
To: Anand Jain; +Cc: dsterba, linux-btrfs, dsterba
On Tue, Feb 11, 2020 at 12:46:58PM +0800, Anand Jain wrote:
> > I've tested current master and the device ids are indeed placed under
> > device/ and there is no devinfo/, so this needs to be fixed.
> >
> > Preparatory patches I was referring to are:
> >
> > bc036bb33524 btrfs: sysfs, merge btrfs_sysfs_add devices_kobj and fsid
> > be2cf92e0a2f btrfs: sysfs, rename btrfs_sysfs_add_device()
> > c6761a9ed329 btrfs: sysfs, btrfs_sysfs_add_fsid() drop unused argument parent
> > b5501504cb6a btrfs: sysfs, rename devices kobject holder to devices_kobj
> >
> > so I'll have another look at what you sent.
> >
> David,
>
> Busy? Can I ping on this?
>
> Those aren't the preparatory patches. The patches sent here applies
> nicely on misc-next with git revert 668e48af7a94
Do you realize that patch 668e48af7a94 had been merged to linus/master
at the time you sent the patchset a week ago? How can I do git revert?
That was in the middle of merge window, 2 weeks after code freeze. If I
don't merge a patch intentionally or by mistake, then you send me an
incremental change.
Please send update with this patch order:
* "btrfs: sysfs, add UUID/devinfo kobject"
* fixup of the device id files created under devices
* the other cleanups
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state
2020-02-11 19:29 ` David Sterba
@ 2020-02-12 9:29 ` Anand Jain
0 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2020-02-12 9:29 UTC (permalink / raw)
To: dsterba, linux-btrfs, dsterba
> * "btrfs: sysfs, add UUID/devinfo kobject"
> * fixup of the device id files created under devices
> * the other cleanups
Done. Its here:
https://patchwork.kernel.org/cover/11378051/
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2020-02-12 9:29 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-03 11:00 [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state Anand Jain
2020-02-03 11:00 ` [PATCH resend 1/4] btrfs: sysfs, use btrfs_sysfs_remove_fsid in fail return in add_fsid Anand Jain
2020-02-03 11:00 ` [PATCH resend 2/4] btrfs: sysfs, add UUID/devinfo kobject Anand Jain
2020-02-03 11:00 ` [PATCH resend v2 3/4] btrfs: sysfs, rename device_link add,remove functions Anand Jain
2020-02-03 11:00 ` [PATCH v5 4/4] btrfs: sysfs, add devid/dev_state kobject and device attribute Anand Jain
2020-02-03 17:16 ` [PATCH 0/4 RESEND 1-3/4 v5 4/4] btrfs, sysfs cleanup and add dev_state David Sterba
2020-02-06 6:31 ` Anand Jain
2020-02-06 14:11 ` David Sterba
2020-02-11 4:46 ` Anand Jain
2020-02-11 19:29 ` David Sterba
2020-02-12 9:29 ` Anand Jain
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.