Commit ff37c89f authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: move missing device handling in a dedicate function

This simplifies the code flow in read_one_chunk and makes error handling
when handling missing devices a bit simpler by reducing it to a single
check if something went wrong. No functional changes.
Reviewed-by: default avatarSu Yue <l@damenly.su>
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent de6bc7f5
...@@ -7060,6 +7060,27 @@ static void warn_32bit_meta_chunk(struct btrfs_fs_info *fs_info, ...@@ -7060,6 +7060,27 @@ static void warn_32bit_meta_chunk(struct btrfs_fs_info *fs_info,
} }
#endif #endif
static struct btrfs_device *handle_missing_device(struct btrfs_fs_info *fs_info,
u64 devid, u8 *uuid)
{
struct btrfs_device *dev;
if (!btrfs_test_opt(fs_info, DEGRADED)) {
btrfs_report_missing_device(fs_info, devid, uuid, true);
return ERR_PTR(-ENOENT);
}
dev = add_missing_dev(fs_info->fs_devices, devid, uuid);
if (IS_ERR(dev)) {
btrfs_err(fs_info, "failed to init missing device %llu: %ld",
devid, PTR_ERR(dev));
return dev;
}
btrfs_report_missing_device(fs_info, devid, uuid, false);
return dev;
}
static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf, static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
struct btrfs_chunk *chunk) struct btrfs_chunk *chunk)
{ {
...@@ -7147,28 +7168,17 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf, ...@@ -7147,28 +7168,17 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
BTRFS_UUID_SIZE); BTRFS_UUID_SIZE);
args.uuid = uuid; args.uuid = uuid;
map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices, &args); map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices, &args);
if (!map->stripes[i].dev &&
!btrfs_test_opt(fs_info, DEGRADED)) {
free_extent_map(em);
btrfs_report_missing_device(fs_info, devid, uuid, true);
return -ENOENT;
}
if (!map->stripes[i].dev) { if (!map->stripes[i].dev) {
map->stripes[i].dev = map->stripes[i].dev = handle_missing_device(fs_info,
add_missing_dev(fs_info->fs_devices, devid, devid, uuid);
uuid);
if (IS_ERR(map->stripes[i].dev)) { if (IS_ERR(map->stripes[i].dev)) {
free_extent_map(em); free_extent_map(em);
btrfs_err(fs_info,
"failed to init missing dev %llu: %ld",
devid, PTR_ERR(map->stripes[i].dev));
return PTR_ERR(map->stripes[i].dev); return PTR_ERR(map->stripes[i].dev);
} }
btrfs_report_missing_device(fs_info, devid, uuid, false);
} }
set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, set_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
&(map->stripes[i].dev->dev_state)); &(map->stripes[i].dev->dev_state));
} }
write_lock(&map_tree->lock); write_lock(&map_tree->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment