* [PATCH v2] btrfs-progs: zoned: open host-managed devices with O_DIRECT for read-only
@ 2026-07-16 11:28 Johannes Thumshirn
2026-07-16 11:37 ` Qu Wenruo
0 siblings, 1 reply; 2+ messages in thread
From: Johannes Thumshirn @ 2026-07-16 11:28 UTC (permalink / raw)
To: linux-btrfs; +Cc: Qu Wenruo, Johannes Thumshirn
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 <johannes.thumshirn@wdc.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] btrfs-progs: zoned: open host-managed devices with O_DIRECT for read-only
2026-07-16 11:28 [PATCH v2] btrfs-progs: zoned: open host-managed devices with O_DIRECT for read-only Johannes Thumshirn
@ 2026-07-16 11:37 ` Qu Wenruo
0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2026-07-16 11:37 UTC (permalink / raw)
To: Johannes Thumshirn, linux-btrfs; +Cc: Qu Wenruo
在 2026/7/16 20:58, Johannes Thumshirn 写道:
> 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 <johannes.thumshirn@wdc.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> 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
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-16 11:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 11:28 [PATCH v2] btrfs-progs: zoned: open host-managed devices with O_DIRECT for read-only Johannes Thumshirn
2026-07-16 11:37 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox