btrfs-progs/tune
Qu Wenruo 738bb7f0f0 btrfs-progs: tune: properly open zoned devices for RW
[BUG]
There is a report that, for zoned devices btrfstune is unable to convert
it to block group tree.

 # btrfstune /dev/nullb0 --convert-to-block-group-tree
 Error reading 1342193664, -1
 Error reading 1342193664, -1
 ERROR: cannot read chunk root
 ERROR: open ctree failed

[CAUSE]
For read-write opened zoned devices, all the read/write has to be
aligned to its sector size.

However btrfs stores its metadata by extent_buffer::data[], which has
all the structures before it, thus never aligned to zoned device sector
size.

Normally we would require btrfs_pread() and btrfs_pwrite() to do the
extra alignment, but during open_ctree(), we are not aware if a device
is zoned or not.

Thus we rely on if the fd is opened with O_DIRECT flag, if the fd has
O_DIRECT, then we would temporarily set fs_info->zoned for chunk tree
read.

Unforunately not all open_ctree_fd() callers have the flags set
properly, and btrfstune is one of the missing call site.

This makes all the read not properly aligned and cause read failure.

[FIX]
Just manually check if the target device is a zoned one, and set
O_DIRECT accordingly.

Issue: #765
Pull-request: #767
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-04-18 19:16:00 +02:00
..
change-csum.c btrfs-progs: fix all variable shadowing 2023-10-10 19:16:29 +02:00
change-metadata-uuid.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
change-uuid.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
convert-bgt.c btrfs-progs: tune: add the missing newline for --convert-from-block-group-tree 2024-04-02 20:49:55 +02:00
main.c btrfs-progs: tune: properly open zoned devices for RW 2024-04-18 19:16:00 +02:00
quota.c btrfs-progs: drop btrfs_init_path 2023-10-03 01:11:56 +02:00
seeding.c btrfs-progs: clean up includes, using include-what-you-use 2023-10-03 01:11:57 +02:00
tune.h btrfs-progs: tune: recover from failed btrfstune -m|M 2023-10-03 01:11:55 +02:00