Skip to content

Commit 12b1c26

Browse files
asjkdave
authored andcommitted
Btrfs: enhance btrfs_scratch_superblock to scratch all superblocks
This patch updates and renames btrfs_scratch_superblocks, (which is used by the replace device thread), with those fixes from the scratch superblock code section of btrfs_rm_device(). The fixes are: Scratch all copies of superblock Notify kobject that superblock has been changed Update time on the device So that btrfs_rm_device() can use the function btrfs_scratch_superblocks() instead of its own scratch code. And further replace deivce code which similarly releases device back to the system, will have the fixes from the btrfs device delete. Signed-off-by: Anand Jain <[email protected]> [renamed to btrfs_scratch_superblock] Signed-off-by: David Sterba <[email protected]>
1 parent 29c36d7 commit 12b1c26

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

fs/btrfs/volumes.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,8 @@ void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_fs_info *fs_info,
19241924
if (srcdev->writeable) {
19251925
fs_devices->rw_devices--;
19261926
/* zero out the old super if it is writable */
1927-
btrfs_scratch_superblock(srcdev);
1927+
btrfs_scratch_superblocks(srcdev->bdev,
1928+
rcu_str_deref(srcdev->name));
19281929
}
19291930

19301931
if (srcdev->bdev)
@@ -1974,7 +1975,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
19741975
btrfs_sysfs_rm_device_link(fs_info->fs_devices, tgtdev);
19751976

19761977
if (tgtdev->bdev) {
1977-
btrfs_scratch_superblock(tgtdev);
1978+
btrfs_scratch_superblocks(tgtdev->bdev,
1979+
rcu_str_deref(tgtdev->name));
19781980
fs_info->fs_devices->open_devices--;
19791981
}
19801982
fs_info->fs_devices->num_devices--;
@@ -6738,22 +6740,34 @@ int btrfs_get_dev_stats(struct btrfs_root *root,
67386740
return 0;
67396741
}
67406742

6741-
int btrfs_scratch_superblock(struct btrfs_device *device)
6743+
void btrfs_scratch_superblocks(struct block_device *bdev, char *device_path)
67426744
{
67436745
struct buffer_head *bh;
67446746
struct btrfs_super_block *disk_super;
6747+
int copy_num;
67456748

6746-
bh = btrfs_read_dev_super(device->bdev);
6747-
if (IS_ERR(bh))
6748-
return PTR_ERR(bh);
6749-
disk_super = (struct btrfs_super_block *)bh->b_data;
6749+
if (!bdev)
6750+
return;
67506751

6751-
memset(&disk_super->magic, 0, sizeof(disk_super->magic));
6752-
set_buffer_dirty(bh);
6753-
sync_dirty_buffer(bh);
6754-
brelse(bh);
6752+
for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX;
6753+
copy_num++) {
67556754

6756-
return 0;
6755+
if (btrfs_read_dev_one_super(bdev, copy_num, &bh))
6756+
continue;
6757+
6758+
disk_super = (struct btrfs_super_block *)bh->b_data;
6759+
6760+
memset(&disk_super->magic, 0, sizeof(disk_super->magic));
6761+
set_buffer_dirty(bh);
6762+
sync_dirty_buffer(bh);
6763+
brelse(bh);
6764+
}
6765+
6766+
/* Notify udev that device has changed */
6767+
btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
6768+
6769+
/* Update ctime/mtime for device path for libblkid */
6770+
update_dev_time(device_path);
67576771
}
67586772

67596773
/*

fs/btrfs/volumes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
474474
struct btrfs_device *tgtdev);
475475
void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
476476
struct btrfs_device *tgtdev);
477-
int btrfs_scratch_superblock(struct btrfs_device *device);
477+
void btrfs_scratch_superblocks(struct block_device *bdev, char *device_path);
478478
int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
479479
u64 logical, u64 len, int mirror_num);
480480
unsigned long btrfs_full_stripe_len(struct btrfs_root *root,

0 commit comments

Comments
 (0)