[PATCH U-BOOT 2/3] btrfs: btrfs_file_read: allow opportunistic read until the end
Qu Wenruo
quwenruo.btrfs at gmx.com
Tue Apr 18 04:02:00 CEST 2023
On 2023/4/18 09:17, Dominique Martinet wrote:
> From: Dominique Martinet <dominique.martinet at 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 at 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),
> + min(extent_num_bytes, end - cur),
> dest + cur - file_offset);
> if (ret < 0)
> goto out;
> - 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,
> + ret = lookup_data_extent(root, &path, ino, cur,
> &next_offset);
> /* <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 = 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,
> + dest + cur - file_offset);
> }
> out:
> btrfs_release_path(&path);
>
More information about the U-Boot
mailing list