Skip to content

Commit 42b6742

Browse files
asjkdave
authored andcommitted
btrfs: make use of btrfs_scratch_superblocks() in btrfs_rm_device()
With the previous patches now the btrfs_scratch_superblocks() is ready to be used in btrfs_rm_device() so use it. Signed-off-by: Anand Jain <[email protected]> [ use GFP_KERNEL ] Signed-off-by: David Sterba <[email protected]>
1 parent b3d1b15 commit 42b6742

File tree

1 file changed

+13
-64
lines changed

1 file changed

+13
-64
lines changed

fs/btrfs/volumes.c

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,13 +1752,11 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
17521752
{
17531753
struct btrfs_device *device;
17541754
struct btrfs_device *next_device;
1755-
struct block_device *bdev = NULL;
1756-
struct buffer_head *bh = NULL;
1757-
struct btrfs_super_block *disk_super = NULL;
17581755
struct btrfs_fs_devices *cur_devices;
17591756
u64 num_devices;
17601757
int ret = 0;
17611758
bool clear_super = false;
1759+
char *dev_name = NULL;
17621760

17631761
mutex_lock(&uuid_mutex);
17641762

@@ -1786,6 +1784,11 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
17861784
list_del_init(&device->dev_alloc_list);
17871785
device->fs_devices->rw_devices--;
17881786
unlock_chunks(root);
1787+
dev_name = kstrdup(device->name->str, GFP_KERNEL);
1788+
if (!dev_name) {
1789+
ret = -ENOMEM;
1790+
goto error_undo;
1791+
}
17891792
clear_super = true;
17901793
}
17911794

@@ -1869,73 +1872,19 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
18691872
* remove it from the devices list and zero out the old super
18701873
*/
18711874
if (clear_super) {
1872-
u64 bytenr;
1873-
int i;
1874-
1875-
if (!disk_super) {
1876-
ret = btrfs_get_bdev_and_sb(device_path,
1877-
FMODE_WRITE | FMODE_EXCL,
1878-
root->fs_info->bdev_holder, 0,
1879-
&bdev, &bh);
1880-
if (ret) {
1881-
/*
1882-
* It could be a failed device ok for clear_super
1883-
* to fail. So return success
1884-
*/
1885-
ret = 0;
1886-
goto out;
1887-
}
1888-
1889-
disk_super = (struct btrfs_super_block *)bh->b_data;
1890-
}
1891-
/* make sure this device isn't detected as part of
1892-
* the FS anymore
1893-
*/
1894-
memset(&disk_super->magic, 0, sizeof(disk_super->magic));
1895-
set_buffer_dirty(bh);
1896-
sync_dirty_buffer(bh);
1897-
brelse(bh);
1898-
1899-
/* clear the mirror copies of super block on the disk
1900-
* being removed, 0th copy is been taken care above and
1901-
* the below would take of the rest
1902-
*/
1903-
for (i = 1; i < BTRFS_SUPER_MIRROR_MAX; i++) {
1904-
bytenr = btrfs_sb_offset(i);
1905-
if (bytenr + BTRFS_SUPER_INFO_SIZE >=
1906-
i_size_read(bdev->bd_inode))
1907-
break;
1908-
1909-
bh = __bread(bdev, bytenr / 4096,
1910-
BTRFS_SUPER_INFO_SIZE);
1911-
if (!bh)
1912-
continue;
1875+
struct block_device *bdev;
19131876

1914-
disk_super = (struct btrfs_super_block *)bh->b_data;
1915-
1916-
if (btrfs_super_bytenr(disk_super) != bytenr ||
1917-
btrfs_super_magic(disk_super) != BTRFS_MAGIC) {
1918-
brelse(bh);
1919-
continue;
1920-
}
1921-
memset(&disk_super->magic, 0,
1922-
sizeof(disk_super->magic));
1923-
set_buffer_dirty(bh);
1924-
sync_dirty_buffer(bh);
1925-
brelse(bh);
1926-
}
1927-
1928-
if (bdev) {
1929-
/* Notify udev that device has changed */
1930-
btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
1931-
1932-
/* Update ctime/mtime for device path for libblkid */
1933-
update_dev_time(device_path);
1877+
bdev = blkdev_get_by_path(dev_name, FMODE_READ | FMODE_EXCL,
1878+
root->fs_info->bdev_holder);
1879+
if (!IS_ERR(bdev)) {
1880+
btrfs_scratch_superblocks(bdev, dev_name);
19341881
blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
19351882
}
19361883
}
19371884

19381885
out:
1886+
kfree(dev_name);
1887+
19391888
mutex_unlock(&uuid_mutex);
19401889
return ret;
19411890

0 commit comments

Comments
 (0)