Skip to content

Commit 99994cd

Browse files
asjChris Mason
authored andcommitted
btrfs: dev delete should remove sysfs entry
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> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 9b4eaf4 commit 99994cd

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎fs/btrfs/sysfs.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,26 @@ static void init_feature_attrs(void)
605605
}
606606
}
607607

608+
int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
609+
struct btrfs_device *one_device)
610+
{
611+
struct hd_struct *disk;
612+
struct kobject *disk_kobj;
613+
614+
if (!fs_info->device_dir_kobj)
615+
return -EINVAL;
616+
617+
if (one_device) {
618+
disk = one_device->bdev->bd_part;
619+
disk_kobj = &part_to_dev(disk)->kobj;
620+
621+
sysfs_remove_link(fs_info->device_dir_kobj,
622+
disk_kobj->name);
623+
}
624+
625+
return 0;
626+
}
627+
608628
static int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info)
609629
{
610630
int error = 0;

‎fs/btrfs/sysfs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
6666
extern const char * const btrfs_feature_set_names[3];
6767
extern struct kobj_type space_info_ktype;
6868
extern struct kobj_type btrfs_raid_ktype;
69+
int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
70+
struct btrfs_device *one_device);
6971
#endif /* _BTRFS_SYSFS_H_ */

‎fs/btrfs/volumes.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "rcu-string.h"
4141
#include "math.h"
4242
#include "dev-replace.h"
43+
#include "sysfs.h"
4344

4445
static int init_first_rw_device(struct btrfs_trans_handle *trans,
4546
struct btrfs_root *root,
@@ -1680,6 +1681,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
16801681
if (device->bdev)
16811682
device->fs_devices->open_devices--;
16821683

1684+
/* remove sysfs entry */
1685+
btrfs_kobj_rm_device(root->fs_info, device);
1686+
16831687
call_rcu(&device->rcu, free_device);
16841688

16851689
num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1;

0 commit comments

Comments
 (0)