qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Fam Zheng <famz@redhat.com>, Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, jsnow@redhat.com,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>, Jeff Cody <jcody@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 3/5] block: Allow NULL file for bdrv_get_block_status()
Date: Wed, 31 May 2017 16:53:39 +0200	[thread overview]
Message-ID: <6d1ca99c-ea04-1ce1-cf46-7d95d5d0cdb8@redhat.com> (raw)
In-Reply-To: <20170525063444.GC27936@lemon.lan>

[-- Attachment #1: Type: text/plain, Size: 3722 bytes --]

On 2017-05-25 08:34, Fam Zheng wrote:
> On Wed, 05/24 15:28, Eric Blake wrote:
>> Not all callers care about which BDS owns the mapping for a given
>> range of the file.  This patch merely simplifies the callers by
>> consolidating the logic in the common call point, while guaranteeing
>> a non-NULL file to all the driver callbacks, for no semantic change.
>>
>> However, this will also set the stage for a future cleanup: when a
>> caller does not care about which BDS owns an offset, it would be
>> nice to allow the driver to optimize things to not have to return
>> BDRV_BLOCK_OFFSET_VALID in the first place.  In the case of fragmented
>> allocation (for example, it's fairly easy to create a qcow2 image
>> where consecutive guest addresses are not at consecutive host
>> addresses), the current contract requires bdrv_get_block_status()
>> to clamp *pnum to the limit where host addresses are no longer
>> consecutive, but allowing a NULL file means that *pnum could be
>> set to the full length of known-allocated data.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>>
>> ---
>> v2: new patch
> 
> Yes. any particular reason why this patch is useful, besides simplifying
> callers?
> 
> 
>> ---
>>  block/io.c     | 15 +++++++++------
>>  block/mirror.c |  3 +--
>>  block/qcow2.c  |  4 +---
>>  qemu-img.c     | 10 ++++------
>>  4 files changed, 15 insertions(+), 17 deletions(-)
>>
>> diff --git a/block/io.c b/block/io.c
>> index 8e6c3fe..eea74cb 100644
>> --- a/block/io.c
>> +++ b/block/io.c
>> @@ -706,7 +706,6 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)
>>  {
>>      int64_t target_sectors, ret, nb_sectors, sector_num = 0;
>>      BlockDriverState *bs = child->bs;
>> -    BlockDriverState *file;
>>      int n;
>>
>>      target_sectors = bdrv_nb_sectors(bs);
>> @@ -719,7 +718,7 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)
>>          if (nb_sectors <= 0) {
>>              return 0;
>>          }
>> -        ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &n, &file);
>> +        ret = bdrv_get_block_status(bs, sector_num, nb_sectors, &n, NULL);
>>          if (ret < 0) {
>>              error_report("error getting block status at sector %" PRId64 ": %s",
>>                           sector_num, strerror(-ret));
>> @@ -1737,8 +1736,9 @@ typedef struct BdrvCoGetBlockStatusData {
>>   * 'nb_sectors' is the max value 'pnum' should be set to.  If nb_sectors goes
>>   * beyond the end of the disk image it will be clamped.
>>   *
>> - * If returned value is positive and BDRV_BLOCK_OFFSET_VALID bit is set, 'file'
>> - * points to the BDS which the sector range is allocated in.
>> + * If returned value is positive, BDRV_BLOCK_OFFSET_VALID bit is set, and
>> + * 'file' is non-NULL, then '*file' points to the BDS which the sector range
>> + * is allocated in.
> 
> Sounds good.
> 
>>   */
>>  static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>>                                                       int64_t sector_num,
>> @@ -1748,7 +1748,11 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>>      int64_t total_sectors;
>>      int64_t n;
>>      int64_t ret, ret2;
>> +    BlockDriverState *tmpfile;
>>
>> +    if (!file) {
>> +        file = &tmpfile;
>> +    }
> 
> I don't like this hunk. Instead, how about replacing all "*file = ..." with
> "tmpfile = ..." and add "if (file) { *file = tmpfile; }" before returning?

Sounds fine to me, but in that case I'd like to request a different
variable name. Maybe do what we have with errp/local_error and make it
local_file or something?

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 498 bytes --]

  parent reply	other threads:[~2017-05-31 14:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 20:28 [Qemu-devel] [PATCH v2 0/5] more blkdebug tweaks Eric Blake
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 1/5] qemu-io: Don't die on second open Eric Blake
2017-05-25  0:50   ` Fam Zheng
2017-05-31 14:18   ` Max Reitz
2017-05-31 15:12     ` Eric Blake
2017-05-31 15:56       ` Max Reitz
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 2/5] block: Guarantee that *file is set on bdrv_get_block_status() Eric Blake
2017-05-25  6:18   ` Fam Zheng
2017-05-31 14:42   ` Max Reitz
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 3/5] block: Allow NULL file for bdrv_get_block_status() Eric Blake
2017-05-25  6:34   ` Fam Zheng
2017-05-25 13:57     ` Eric Blake
2017-05-31 14:53     ` Max Reitz [this message]
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 4/5] block: Simplify use of BDRV_BLOCK_RAW Eric Blake
2017-05-25  6:35   ` Fam Zheng
2017-05-31 14:56   ` Max Reitz
2017-05-24 20:28 ` [Qemu-devel] [PATCH v2 5/5] blkdebug: Support .bdrv_co_get_block_status Eric Blake
2017-05-25  6:37   ` Fam Zheng
2017-05-31 15:00   ` Max Reitz
2017-05-25 14:36 ` [Qemu-devel] [PATCH v2 0/5] more blkdebug tweaks Fam Zheng

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=6d1ca99c-ea04-1ce1-cf46-7d95d5d0cdb8@redhat.com \
    --to=mreitz@redhat.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).