u-boot/fs/btrfs
Qu Wenruo 11d5670125 fs/btrfs: handle data extents, which crosss stripe boundaries, correctly
[BUG]
Since btrfs supports single device RAID0 at mkfs time after btrfs-progs
v5.14, if we create a single device raid0 btrfs, and created a file
crossing stripe boundary:

  # mkfs.btrfs -m dup -d raid0 test.img
  # mount test.img mnt
  # xfs_io -f -c "pwrite 0 128K" mnt/file
  # umount mnt

Since btrfs is using 64K as stripe length, above 128K data write is
definitely going to cross at least one stripe boundary.

Then u-boot would fail to read above 128K file:

 => host bind 0 /home/adam/test.img
 => ls host 0
 <   >     131072  Fri Dec 30 00:18:25 2022  file
 => load host 0 0 file
 BTRFS: An error occurred while reading file file
 Failed to load 'file'

[CAUSE]
Unlike tree blocks read, data extent reads doesn't consider cases in which
one data extent can cross stripe boundary.

In read_data_extent(), we just call btrfs_map_block() once and read the
first mapped range.

And if the first mapped range is smaller than the desired range, it
would return error.

But since even single device btrfs can utilize RAID0 profiles, the first
mapped range can only be at most 64K for RAID0 profiles, and cause false
error.

[FIX]
Just like read_whole_eb(), we should call btrfs_map_block() in a loop
until we read all data.

Since we're here, also add extra error messages for the following cases:

- btrfs_map_block() failure
  We already have the error message for it.

- Missing device
  This should not happen, as we only support single device for now.

- __btrfs_devread() failure

With this bug fixed, btrfs driver of u-boot can properly read the above
128K file, and have the correct content:

 => host bind 0 /home/adam/test.img
 => ls host 0
 <   >     131072  Fri Dec 30 00:18:25 2022  file
 => load host 0 0 file
 131072 bytes read in 0 ms
 => md5sum 0 0x20000
 md5 for 00000000 ... 0001ffff ==> d48858312a922db7eb86377f638dbc9f
 ^^^ Above md5sum also matches.

Reported-by: Sam Winchenbach <swichenbach@tethers.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
2023-01-11 15:02:24 -05:00
..
common fs: btrfs: Crossport rbtree-utils from btrfs-progs 2020-09-07 20:57:27 -04:00
crypto fs/btrfs: add dependency on BLAKE2 hash 2022-01-18 08:31:02 -05:00
kernel-shared WS cleanup: remove excessive empty lines 2021-09-30 08:08:56 -04:00
btrfs.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
btrfs.h treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
compat.h fs: btrfs: Introduce function to resolve path in one subvolume 2020-09-07 21:00:36 -04:00
compression.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
conv-funcs.h treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
ctree.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
ctree.h treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
dev.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
dir-item.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
disk-io.c fs/btrfs: handle data extents, which crosss stripe boundaries, correctly 2023-01-11 15:02:24 -05:00
disk-io.h fs: btrfs: Cleanup the old implementation 2020-09-07 21:00:36 -04:00
extent-cache.c fs: btrfs: Crossport extent-cache.[ch] from btrfs-progs 2020-09-07 20:57:27 -04:00
extent-cache.h fs: btrfs: Crossport extent-cache.[ch] from btrfs-progs 2020-09-07 20:57:27 -04:00
extent-io.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
extent-io.h fs: btrfs: Crossport extent-io.[ch] from btrfs-progs 2020-09-07 20:57:27 -04:00
inode.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
Kconfig fs/btrfs: add dependency on BLAKE2 hash 2022-01-18 08:31:02 -05:00
Makefile treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
root-tree.c fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progs 2020-09-07 20:57:27 -04:00
subvolume.c treewide: Fix Marek's name and change my e-mail address 2022-07-21 10:14:04 +02:00
volumes.c fs: btrfs: volumes: prevent overflow for multiplying 2021-01-20 14:01:08 -05:00
volumes.h fs: btrfs: Crossport btrfs_read_sys_array() and btrfs_read_chunk_tree() 2020-09-07 20:57:27 -04:00