All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Nir Soffer <nirsof@gmail.com>
Cc: qemu-devel@nongnu.org,  Eric Blake <eblake@redhat.com>,
	qemu-block@nongnu.org,  Kevin Wolf <kwolf@redhat.com>,
	 Fam Zheng <fam@euphon.net>,  Hanna Reitz <hreitz@redhat.com>
Subject: Re: [PATCH v2 1/2] block/null: Report DATA if not reading zeroes
Date: Thu, 08 May 2025 07:03:42 +0200	[thread overview]
Message-ID: <87wmarelsh.fsf@pond.sub.org> (raw)
In-Reply-To: <87plgjg1kh.fsf@pond.sub.org> (Markus Armbruster's message of "Thu, 08 May 2025 06:37:34 +0200")

Markus Armbruster <armbru@redhat.com> writes:

> Nir Soffer <nirsof@gmail.com> writes:
>
>> 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
>
> Possibly dumb question: how is this doc change related to the code fix?
>
> Suggest to split the sentence for easier reading:
>
>    # @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.

false is a security hazard, as secure-coding-practices.rst points out.
I think it should be pointed out right here as well.  Especially since
"security hazard" is the default!

I'd do it in a separate patch, but I'm a compulsive patch splitter.



  reply	other threads:[~2025-05-08  5:04 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 ` [PATCH v2 1/2] block/null: Report DATA if not reading zeroes Nir Soffer
2025-05-08  4:37   ` Markus Armbruster
2025-05-08  5:03     ` Markus Armbruster [this message]
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=87wmarelsh.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=nirsof@gmail.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.