@samitouri / QOSamiQemu / commits / 7c12177aa3

file-posix: fix cache.direct=on check for zoned block devices

For zoned block devices with SWR zones, the order of the writes must be maintained to avoid write not at write pointer errors. Thus, cache.direct=on must be used to bypass the page cache, since the page cache uses write-back caching, where the physical order of the writes is not guaranteed. There is already a check for cache.direct=on in raw_open_common(), however, this check is done before raw_refresh_zoned_limits() has been called (which initializes bs->bl.zoned), so it is currently dead code. Fix this by moving the check to raw_refresh_zoned_limits(), such that the check is done after bs->bl.zoned has been initialized. Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Dmitry Fomichev <dmitry.fomichev@wdc.com> Fixes: 774c726ceb2a ("block: add zoned BlockDriver check to block layer") Signed-off-by: Niklas Cassel <cassel@kernel.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Message-ID: <20260617133658.2022750-1-cassel@kernel.org> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

Niklas Cassel committed Jun 17, 2026 at 15:36 UTC 7c12177aa3c9cf6d0f7262a0cbbe0a4d71416dae
1 file changed +10 -12
block/file-posix.c
+10 -12
@@ -793,18 +793,6 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
793 goto fail;
794 }
795 }
796 -#ifdef CONFIG_BLKZONED
797 - /*
798 - * The kernel page cache does not reliably work for writes to SWR zones
799 - * of zoned block device because it can not guarantee the order of writes.
800 - */
801 - if ((bs->bl.zoned != BLK_Z_NONE) &&
802 - (!(s->open_flags & O_DIRECT))) {
803 - error_setg(errp, "The driver supports zoned devices, and it requires "
804 - "cache.direct=on, which was not specified.");
805 - return -EINVAL; /* No host kernel page cache */
806 - }
807 -#endif
796
797 #ifdef __FreeBSD__
798 if (S_ISCHR(st.st_mode)) {
@@ -1455,6 +1443,16 @@ static void raw_refresh_zoned_limits(BlockDriverState *bs, struct stat *st,
1443 }
1444 bs->bl.zoned = zoned;
1445
1446 + /*
1447 + * The kernel page cache does not reliably work for writes to SWR zones of
1448 + * zoned block devices because it can not guarantee the order of writes.
1449 + */
1450 + if (!(s->open_flags & O_DIRECT)) {
1451 + error_setg(errp, "The driver supports zoned devices, and it requires "
1452 + "cache.direct=on, which was not specified.");
1453 + goto no_zoned;
1454 + }
1455 +
1456 ret = get_sysfs_long_val(st, "max_open_zones");
1457 if (ret >= 0) {
1458 bs->bl.max_open_zones = ret;