btrfs-progs: Refactor read_extent_data to use btrfs_fs_info

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2017-06-13 17:19:24 +08:00 committed by David Sterba
parent de8622fcd0
commit b350e8fd76
6 changed files with 26 additions and 22 deletions

View File

@ -169,7 +169,7 @@ static int write_extent_content(struct btrfs_fs_info *fs_info, int out_fd,
while (cur_offset < length) {
cur_len = min_t(u64, length - cur_offset, BUFFER_SIZE);
ret = read_extent_data(fs_info->tree_root, buffer,
ret = read_extent_data(fs_info, buffer,
logical + cur_offset, &cur_len, mirror);
if (ret < 0) {
fprintf(stderr,

View File

@ -7166,8 +7166,9 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
u64 num_bytes, unsigned long leaf_offset,
struct extent_buffer *eb) {
struct btrfs_fs_info *fs_info = root->fs_info;
u64 offset = 0;
u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
char *data;
unsigned long csum_offset;
u32 csum;
@ -7179,7 +7180,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
int mirror;
int num_copies;
if (num_bytes % root->fs_info->sectorsize)
if (num_bytes % fs_info->sectorsize)
return -EINVAL;
data = malloc(num_bytes);
@ -7191,7 +7192,7 @@ static int check_extent_csums(struct btrfs_root *root, u64 bytenr,
again:
read_len = num_bytes - offset;
/* read as much space once a time */
ret = read_extent_data(root, data + offset,
ret = read_extent_data(fs_info, data + offset,
bytenr + offset, &read_len, mirror);
if (ret)
goto out;
@ -7202,11 +7203,11 @@ again:
tmp = offset + data_checked;
csum = btrfs_csum_data((char *)data + tmp,
csum, root->fs_info->sectorsize);
csum, fs_info->sectorsize);
btrfs_csum_final(csum, (u8 *)&csum);
csum_offset = leaf_offset +
tmp / root->fs_info->sectorsize * csum_size;
tmp / fs_info->sectorsize * csum_size;
read_extent_buffer(eb, (char *)&csum_expected,
csum_offset, csum_size);
/* try another mirror */
@ -7221,7 +7222,7 @@ again:
goto again;
}
}
data_checked += root->fs_info->sectorsize;
data_checked += fs_info->sectorsize;
}
offset += read_len;
}
@ -12080,13 +12081,14 @@ static int populate_csum(struct btrfs_trans_handle *trans,
struct btrfs_root *csum_root, char *buf, u64 start,
u64 len)
{
struct btrfs_fs_info *fs_info = csum_root->fs_info;
u64 offset = 0;
u64 sectorsize;
int ret = 0;
while (offset < len) {
sectorsize = csum_root->fs_info->sectorsize;
ret = read_extent_data(csum_root, buf, start + offset,
sectorsize = fs_info->sectorsize;
ret = read_extent_data(fs_info, buf, start + offset,
&sectorsize, 0);
if (ret)
break;

View File

@ -384,17 +384,17 @@ struct extent_buffer* read_tree_block(
return ERR_PTR(ret);
}
int read_extent_data(struct btrfs_root *root, char *data,
u64 logical, u64 *len, int mirror)
int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical,
u64 *len, int mirror)
{
u64 offset = 0;
struct btrfs_multi_bio *multi = NULL;
struct btrfs_fs_info *info = root->fs_info;
struct btrfs_device *device;
int ret = 0;
u64 max_len = *len;
ret = btrfs_map_block(info, READ, logical, len, &multi, mirror, NULL);
ret = btrfs_map_block(fs_info, READ, logical, len, &multi, mirror,
NULL);
if (ret) {
fprintf(stderr, "Couldn't map the block %llu\n",
logical + offset);

View File

@ -119,7 +119,7 @@ struct extent_buffer* read_tree_block(
struct btrfs_fs_info *fs_info, u64 bytenr, u32 blocksize,
u64 parent_transid);
int read_extent_data(struct btrfs_root *root, char *data, u64 logical,
int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical,
u64 *len, int mirror);
void readahead_tree_block(struct btrfs_root *root, u64 bytenr, u32 blocksize,
u64 parent_transid);

15
file.c
View File

@ -183,20 +183,21 @@ out:
int btrfs_read_file(struct btrfs_root *root, u64 ino, u64 start, int len,
char *dest)
{
struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_key key;
struct btrfs_path path;
struct extent_buffer *leaf;
struct btrfs_inode_item *ii;
u64 isize;
int no_holes = btrfs_fs_incompat(root->fs_info, NO_HOLES);
int no_holes = btrfs_fs_incompat(fs_info, NO_HOLES);
int slot;
int read = 0;
int ret;
if (!IS_ALIGNED(start, root->fs_info->sectorsize) ||
!IS_ALIGNED(len, root->fs_info->sectorsize)) {
if (!IS_ALIGNED(start, fs_info->sectorsize) ||
!IS_ALIGNED(len, fs_info->sectorsize)) {
warning("@start and @len must be aligned to %u for function %s",
root->fs_info->sectorsize, __func__);
fs_info->sectorsize, __func__);
return -EINVAL;
}
@ -260,7 +261,7 @@ int btrfs_read_file(struct btrfs_root *root, u64 ino, u64 start, int len,
goto next;
read_extent_buffer(leaf, dest,
btrfs_file_extent_inline_start(fi), extent_len);
read += round_up(extent_len, root->fs_info->sectorsize);
read += round_up(extent_len, fs_info->sectorsize);
break;
}
@ -283,7 +284,7 @@ int btrfs_read_file(struct btrfs_root *root, u64 ino, u64 start, int len,
disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi) +
btrfs_file_extent_offset(leaf, fi);
read_len_ret = read_len;
ret = read_extent_data(root, dest + read_start - start, disk_bytenr,
ret = read_extent_data(fs_info, dest + read_start - start, disk_bytenr,
&read_len_ret, 0);
if (ret < 0)
break;
@ -319,7 +320,7 @@ next:
ii = btrfs_item_ptr(path.nodes[0], path.slots[0],
struct btrfs_inode_item);
isize = round_up(btrfs_inode_size(path.nodes[0], ii),
root->fs_info->sectorsize);
fs_info->sectorsize);
read = min_t(u64, isize - start, len);
}
out:

View File

@ -876,6 +876,7 @@ static int read_data_extent(struct metadump_struct *md,
struct async_work *async)
{
struct btrfs_root *root = md->root;
struct btrfs_fs_info *fs_info = root->fs_info;
u64 bytes_left = async->size;
u64 logical = async->start;
u64 offset = 0;
@ -890,7 +891,7 @@ static int read_data_extent(struct metadump_struct *md,
for (cur_mirror = 0; cur_mirror < num_copies; cur_mirror++) {
while (bytes_left) {
read_len = bytes_left;
ret = read_extent_data(root,
ret = read_extent_data(fs_info,
(char *)(async->buffer + offset),
logical, &read_len, cur_mirror);
if (ret < 0)