[PATCH] 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 devices the page cache is not coherent with the
on-disk contents, so all IO must use O_DIRECT. Both device-open paths only
added O_DIRECT for O_RDWR opens, so read-only tools like "btrfs check" used
buffered IO and could read stale zero pages for one mirror of duplicated
metadata, reporting a spurious

	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]>
---
 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 7f87e567..8b9c6dca 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 a54ea4dd..24971c09 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.