From: Nir Soffer <nirsof@gmail.com>
To: qemu-devel@nongnu.org
Cc: Eric Blake <eblake@redhat.com>,
qemu-block@nongnu.org, Markus Armbruster <armbru@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Hanna Reitz <hreitz@redhat.com>, Nir Soffer <nirsof@gmail.com>
Subject: [PATCH v2 1/2] block/null: Report DATA if not reading zeroes
Date: Wed, 30 Apr 2025 23:37:16 +0300 [thread overview]
Message-ID: <20250430203717.16359-2-nirsof@gmail.com> (raw)
In-Reply-To: <20250430203717.16359-1-nirsof@gmail.com>
If read-zeroes is not set, we did not report BDRV_BLOCK_DATA or
BDRV_BLOCK_ZERO. This is not consistent with other drivers and can
confuse users or other programs:
% qemu-img map --output json "json:{'driver': 'raw', 'file': {'driver': 'null-co', 'size': '1g'}}"
[{ "start": 0, "length": 1073741824, "depth": 0, "present": false, "zero": false, "data": false, "compressed": false}]
% qemu-nbd "json:{'driver': 'raw', 'file': {'driver': 'null-co', 'size': '1g'}}" &
% nbdinfo --map nbd://127.0.0.1
0 1073741824 1 hole
With this change we report DATA in this case:
% ./qemu-img map --output json "json:{'driver': 'raw', 'file': {'driver': 'null-co', 'size': '1g'}}"
[{ "start": 0, "length": 1073741824, "depth": 0, "present": true, "zero": false, "data": true, "compressed": false, "offset": 0}]
% ./qemu-nbd "json:{'driver': 'raw', 'file': {'driver': 'null-co', 'size': '1g'}}" &
% nbdinfo --map nbd://127.0.0.1
0 1073741824 0 data
Signed-off-by: Nir Soffer <nirsof@gmail.com>
---
block/null.c | 4 +---
qapi/block-core.json | 5 +++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/block/null.c b/block/null.c
index dc0b1fdbd9..7ba87bd9a9 100644
--- a/block/null.c
+++ b/block/null.c
@@ -239,9 +239,7 @@ static int coroutine_fn null_co_block_status(BlockDriverState *bs,
*map = offset;
*file = bs;
- if (s->read_zeroes) {
- ret |= BDRV_BLOCK_ZERO;
- }
+ ret |= s->read_zeroes ? BDRV_BLOCK_ZERO : BDRV_BLOCK_DATA;
return ret;
}
diff --git a/qapi/block-core.json b/qapi/block-core.json
index b1937780e1..7c95c9e36a 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3293,8 +3293,9 @@
# requests. Default to zero which completes requests immediately.
# (Since 2.4)
#
-# @read-zeroes: if true, reads from the device produce zeroes; if
-# false, the buffer is left unchanged.
+# @read-zeroes: if true, emulate a sparse image, and reads from the
+# device produce zeroes; if false, emulate an allocated image but
+# reads from the device leave the buffer unchanged.
# (default: false; since: 4.1)
#
# Since: 2.9
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2025-04-30 20:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 20:37 [PATCH v2 0/2] block/null: Add read-pattern option Nir Soffer
2025-04-30 20:37 ` Nir Soffer [this message]
2025-05-08 4:37 ` [PATCH v2 1/2] block/null: Report DATA if not reading zeroes Markus Armbruster
2025-05-08 5:03 ` Markus Armbruster
2025-05-08 5:20 ` Markus Armbruster
2025-05-16 21:35 ` Nir Soffer
2025-05-16 21:32 ` Nir Soffer
2025-05-16 21:31 ` Nir Soffer
2025-04-30 20:37 ` [PATCH v2 2/2] block/null: Add read-pattern option Nir Soffer
2025-05-08 5:28 ` Markus Armbruster
2025-05-08 14:30 ` Eric Blake
2025-05-09 7:19 ` Markus Armbruster
2025-05-16 21:12 ` Nir Soffer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250430203717.16359-2-nirsof@gmail.com \
--to=nirsof@gmail.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.