Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Anand Jain and committed by
Chris Mason
99994cde 9b4eaf43

+26
+20
fs/btrfs/sysfs.c
··· 605 605 } 606 606 } 607 607 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 + 608 628 static int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info) 609 629 { 610 630 int error = 0;
+2
fs/btrfs/sysfs.h
··· 66 66 extern const char * const btrfs_feature_set_names[3]; 67 67 extern struct kobj_type space_info_ktype; 68 68 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); 69 71 #endif /* _BTRFS_SYSFS_H_ */
+4
fs/btrfs/volumes.c
··· 40 40 #include "rcu-string.h" 41 41 #include "math.h" 42 42 #include "dev-replace.h" 43 + #include "sysfs.h" 43 44 44 45 static int init_first_rw_device(struct btrfs_trans_handle *trans, 45 46 struct btrfs_root *root, ··· 1680 1679 1681 1680 if (device->bdev) 1682 1681 device->fs_devices->open_devices--; 1682 + 1683 + /* remove sysfs entry */ 1684 + btrfs_kobj_rm_device(root->fs_info, device); 1683 1685 1684 1686 call_rcu(&device->rcu, free_device); 1685 1687