[PATCH 4/5] btrfs-progs: temporally set zoned flag for initial tree reading
From: Naohiro Aota <naohiro.aota@wdc.com>
Date: 2021-09-27 04:17:04
Subsystem:
the rest · Maintainer:
Linus Torvalds
Functions to read data/metadata e.g. read_extent_from_disk() now depend on the fs_info->zoned flag to determine if they do direct-IO or not. The flag (and zone_size) is not known before reading the chunk tree and it set to 0 while in the initial chunk tree setup process. That will cause btrfs_pread() to fail because it does not align the buffer. Use fcntl() to find out the file descriptor is opened with O_DIRECT or not, and if it is, set the zoned flag to 1 temporally for this initial process. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- kernel-shared/disk-io.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 740500f9fdc9..dd48599a5f1f 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c@@ -1302,10 +1302,22 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *oc if (ret) goto out_devices; + /* + * fs_info->zone_size (and zoned) are not known before reading the + * chunk tree, so it's 0 at this point. But, fs_info->zoned == 0 + * will cause btrfs_pread() not to use an aligned bounce buffer, + * causing EINVAL when the file is opened with O_DIRECT. Temporally + * set zoned = 1 in that case. + */ + if (fcntl(fp, F_GETFL) & O_DIRECT) + fs_info->zoned = 1; + ret = btrfs_setup_chunk_tree_and_device_map(fs_info, ocf->chunk_tree_bytenr); if (ret) goto out_chunk; + fs_info->zoned = 0; + /* Chunk tree root is unable to read, return directly */ if (!fs_info->chunk_root) return fs_info;
--
2.33.0