@@ -258,20 +258,12 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
return -EINVAL;
}
- bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
- fs_info->bdev_holder);
+ bdev = btrfs_open_device_for_adding(fs_info, device_path);
if (IS_ERR(bdev)) {
btrfs_err(fs_info, "target device %s is invalid!", device_path);
return PTR_ERR(bdev);
}
- if (!btrfs_check_device_zone_type(fs_info, bdev)) {
- btrfs_err(fs_info,
- "dev-replace: zoned type of target device mismatch with filesystem");
- ret = -EINVAL;
- goto error;
- }
-
sync_blockdev(bdev);
list_for_each_entry(device, &fs_devices->devices, dev_list) {
@@ -2583,6 +2583,26 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
return ret;
}
+struct block_device *btrfs_open_device_for_adding(struct btrfs_fs_info *fs_info,
+ const char *device_path)
+{
+ struct block_device *bdev;
+
+ bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
+ fs_info->bdev_holder);
+ if (IS_ERR(bdev))
+ return bdev;
+
+ if (!btrfs_check_device_zone_type(fs_info, bdev)) {
+ btrfs_err(fs_info,
+ "dev-replace: zoned type of target device mismatch with filesystem");
+ blkdev_put(bdev, FMODE_EXCL);
+ return ERR_PTR(-EINVAL);
+ }
+
+ return bdev;
+}
+
int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path)
{
struct btrfs_root *root = fs_info->dev_root;
@@ -2602,16 +2622,10 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
if (sb_rdonly(sb) && !fs_devices->seeding)
return -EROFS;
- bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
- fs_info->bdev_holder);
+ bdev = btrfs_open_device_for_adding(fs_info, device_path);
if (IS_ERR(bdev))
return PTR_ERR(bdev);
- if (!btrfs_check_device_zone_type(fs_info, bdev)) {
- ret = -EINVAL;
- goto error;
- }
-
if (fs_devices->seeding) {
seeding_dev = true;
down_write(&sb->s_umount);
@@ -757,4 +757,6 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
unsigned long btrfs_chunk_item_size(int num_stripes);
bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
+struct block_device *btrfs_open_device_for_adding(struct btrfs_fs_info *fs_info,
+ const char *device_path);
#endif
We currently duplicate our device init code for adding a new device to a file system and replacing an existing device in a file system. These two init functions are subtle-y different, however they both open the disk and check it's zoned status to see if it's compatible. Combine this step into a single helper and use that helper from both init functions. The goal of this change is to move the zoned helper out of zoned.h in order to avoid using helpers that aren't defined in zoned.h. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/btrfs/dev-replace.c | 10 +--------- fs/btrfs/volumes.c | 28 +++++++++++++++++++++------- fs/btrfs/volumes.h | 2 ++ 3 files changed, 24 insertions(+), 16 deletions(-)