mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-12 08:49:33 +00:00
btrfs-progs: extract metadata restore read code into its own helper
For metadata restore, our logical address is mapped to a single device with logical address 1:1 mapped to device physical address. Move this part of code into a helper, this will make later extent buffer read path refactoer much easier. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
7a0c4b5dc1
commit
01c25d73f1
@ -291,6 +291,30 @@ out:
|
||||
|
||||
}
|
||||
|
||||
static int read_on_restore(struct extent_buffer *eb)
|
||||
{
|
||||
struct btrfs_fs_info *fs_info = eb->fs_info;
|
||||
struct btrfs_device *device;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* For on_restoring mode, there should be only one device, and logical
|
||||
* address is mapped 1:1 to device physical offset.
|
||||
*/
|
||||
list_for_each_entry(device, &fs_info->fs_devices->devices, dev_list) {
|
||||
if (device->devid == 1)
|
||||
break;
|
||||
}
|
||||
device->total_ios++;
|
||||
|
||||
ret = btrfs_pread(device->fd, eb->data, eb->len, eb->start,
|
||||
eb->fs_info->zoned);
|
||||
if (ret != eb->len)
|
||||
ret = -EIO;
|
||||
else
|
||||
ret = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirror)
|
||||
{
|
||||
@ -305,7 +329,9 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirr
|
||||
read_len = bytes_left;
|
||||
device = NULL;
|
||||
|
||||
if (!info->on_restoring) {
|
||||
if (info->on_restoring)
|
||||
return read_on_restore(eb);
|
||||
|
||||
ret = btrfs_map_block(info, READ, eb->start + offset,
|
||||
&read_len, &multi, mirror, NULL);
|
||||
if (ret) {
|
||||
@ -325,17 +351,6 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirr
|
||||
eb->dev_bytenr = multi->stripes[0].physical;
|
||||
kfree(multi);
|
||||
multi = NULL;
|
||||
} else {
|
||||
/* special case for restore metadump */
|
||||
list_for_each_entry(device, &info->fs_devices->devices, dev_list) {
|
||||
if (device->devid == 1)
|
||||
break;
|
||||
}
|
||||
|
||||
eb->fd = device->fd;
|
||||
eb->dev_bytenr = eb->start;
|
||||
device->total_ios++;
|
||||
}
|
||||
|
||||
if (read_len > bytes_left)
|
||||
read_len = bytes_left;
|
||||
|
Loading…
Reference in New Issue
Block a user