[PATCH v2] btrfs-progs: zoned: open host-managed devices with O_DIRECT for read-only

Johannes Thumshirn <[email protected]>
Newsgroups org.kernel.vger.linux-btrfs
Message-ID <[email protected]>
On host-managed zoned block devices the page cache cannot be used for
writing to the device because it does not guarantee ordering, therefore
direct I/O is used to write any on-disk data structures.

But reading in btrfs-progs is still performed using buffered I/O. This
mix of direct and buffered I/O can lead to stale page cache entries
being handed off to btrfs-progs and tools like "btrfs check" can report
spurious errors like:

	checksum verify failed on <bytenr> wanted 0x00000000 found 0xb6bde3e4

even though both copies are intact on disk.

Drop the O_RDWR condition so host-managed zoned devices always use
O_DIRECT, matching btrfstune.

Signed-off-by: Johannes Thumshirn <[email protected]>
---
Changes to v1:
- reworded commit message

 kernel-shared/disk-io.c | 2 +-
 kernel-shared/volumes.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index 7f87e567f0b1..8b9c6dcac967 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1722,7 +1722,7 @@ struct btrfs_fs_info *open_ctree_fs_info(struct open_ctree_args *oca)
 	if (!(oca->flags & OPEN_CTREE_WRITES))
 		oflags = O_RDONLY;

-	if ((oflags & O_RDWR) && zoned_model(oca->filename) == ZONED_HOST_MANAGED)
+	if (zoned_model(oca->filename) == ZONED_HOST_MANAGED)
 		oflags |= O_DIRECT;

 	fp = open(oca->filename, oflags);
diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c
index f35b59bcc20e..e2b6708ad872 100644
--- a/kernel-shared/volumes.c
+++ b/kernel-shared/volumes.c
@@ -697,7 +697,7 @@ int btrfs_open_devices(struct btrfs_fs_info *fs_info,
 			continue;
 		}

-		if ((flags & O_RDWR) && zoned_model(device->name) == ZONED_HOST_MANAGED)
+		if (zoned_model(device->name) == ZONED_HOST_MANAGED)
 			flags |= O_DIRECT;

 		fd = open(device->name, flags);
--
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.