Skip to content

Commit 0e0078f

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: factor out scratching of one regular super block
btrfs_scratch_superblocks open codes scratching super block of a non-zoned super block. Split the code to read, zero and write the superblock for regular devices into a separate helper. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: David Sterba <[email protected]> [ update changelog ] Signed-off-by: David Sterba <[email protected]>
1 parent 09e4486 commit 0e0078f

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

fs/btrfs/volumes.c

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,42 +2014,43 @@ static u64 btrfs_num_devices(struct btrfs_fs_info *fs_info)
20142014
return num_devices;
20152015
}
20162016

2017+
static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
2018+
struct block_device *bdev, int copy_num)
2019+
{
2020+
struct btrfs_super_block *disk_super;
2021+
struct page *page;
2022+
int ret;
2023+
2024+
disk_super = btrfs_read_dev_one_super(bdev, copy_num, false);
2025+
if (IS_ERR(disk_super))
2026+
return;
2027+
2028+
memset(&disk_super->magic, 0, sizeof(disk_super->magic));
2029+
page = virt_to_page(disk_super);
2030+
set_page_dirty(page);
2031+
lock_page(page);
2032+
/* write_on_page() unlocks the page */
2033+
ret = write_one_page(page);
2034+
if (ret)
2035+
btrfs_warn(fs_info, "error clearing superblock number %d (%d)",
2036+
copy_num, ret);
2037+
btrfs_release_disk_super(disk_super);
2038+
}
2039+
20172040
void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
20182041
struct block_device *bdev,
20192042
const char *device_path)
20202043
{
2021-
struct btrfs_super_block *disk_super;
20222044
int copy_num;
20232045

20242046
if (!bdev)
20252047
return;
20262048

20272049
for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX; copy_num++) {
2028-
struct page *page;
2029-
int ret;
2030-
2031-
disk_super = btrfs_read_dev_one_super(bdev, copy_num, false);
2032-
if (IS_ERR(disk_super))
2033-
continue;
2034-
2035-
if (bdev_is_zoned(bdev)) {
2050+
if (bdev_is_zoned(bdev))
20362051
btrfs_reset_sb_log_zones(bdev, copy_num);
2037-
continue;
2038-
}
2039-
2040-
memset(&disk_super->magic, 0, sizeof(disk_super->magic));
2041-
2042-
page = virt_to_page(disk_super);
2043-
set_page_dirty(page);
2044-
lock_page(page);
2045-
/* write_on_page() unlocks the page */
2046-
ret = write_one_page(page);
2047-
if (ret)
2048-
btrfs_warn(fs_info,
2049-
"error clearing superblock number %d (%d)",
2050-
copy_num, ret);
2051-
btrfs_release_disk_super(disk_super);
2052-
2052+
else
2053+
btrfs_scratch_superblock(fs_info, bdev, copy_num);
20532054
}
20542055

20552056
/* Notify udev that device has changed */

0 commit comments

Comments
 (0)