
On 2023/4/18 09:17, Dominique Martinet wrote:
From: Dominique Martinet dominique.martinet@atmark-techno.com
btrfs_file_read main 'aligned read' loop would limit the last read to the aligned end even if the data is present in the extent: there is no reason not to read the data that we know will be presented correctly.
If that somehow fails cur only advances up to the aligned_end anyway and the file tail is read through the old code unchanged; this could be required if e.g. the end data is inlined.
Signed-off-by: Dominique Martinet dominique.martinet@atmark-techno.com
fs/btrfs/inode.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3d6e39e6544d..efffec0f2e68 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -663,7 +663,8 @@ int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len, struct btrfs_path path; struct btrfs_key key; u64 aligned_start = round_down(file_offset, fs_info->sectorsize);
- u64 aligned_end = round_down(file_offset + len, fs_info->sectorsize);
- u64 end = file_offset + len;
- u64 aligned_end = round_down(end, fs_info->sectorsize); u64 next_offset; u64 cur = aligned_start; int ret = 0;
@@ -743,26 +744,26 @@ int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len, extent_num_bytes = btrfs_file_extent_num_bytes(path.nodes[0], fi); ret = btrfs_read_extent_reg(&path, fi, cur,
min(extent_num_bytes, aligned_end - cur),
if (ret < 0) goto out;min(extent_num_bytes, end - cur), dest + cur - file_offset);
cur += min(extent_num_bytes, aligned_end - cur);
cur += min(extent_num_bytes, end - cur);
}
/* Read the tailing unaligned part*/
Can we remove this part completely?
IIRC if we read until the target end, the unaligned end part can be completely removed then.
Thanks, Qu
- if (file_offset + len != aligned_end) {
- if (file_offset + len != cur) { btrfs_release_path(&path);
ret = lookup_data_extent(root, &path, ino, aligned_end,
/* <0 is error, >0 means no extent */ if (ret) goto out; fi = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_file_extent_item);ret = lookup_data_extent(root, &path, ino, cur, &next_offset);
ret = read_and_truncate_page(&path, fi, aligned_end,
file_offset + len - aligned_end,
dest + aligned_end - file_offset);
ret = read_and_truncate_page(&path, fi, cur,
file_offset + len - cur,
} out: btrfs_release_path(&path);dest + cur - file_offset);