All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Eric Blake <eblake@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, nsoffer@redhat.com,
	Kevin Wolf <kwolf@redhat.com>,  Max Reitz <mreitz@redhat.com>
Subject: Re: [PATCH] qemu-img: Use "depth":-1 to make backing probes obvious
Date: Fri, 11 Jun 2021 11:16:21 +0300	[thread overview]
Message-ID: <8ea330fb-ee0e-9f8d-f780-33f0897bc1e6@virtuozzo.com> (raw)
In-Reply-To: <0a92c583-68b4-c072-68cf-1c6a17a7517e@virtuozzo.com>

11.06.2021 11:08, Vladimir Sementsov-Ogievskiy wrote:
> 11.06.2021 00:39, Eric Blake wrote:
>> The recently-added NBD context qemu:allocation-depth makes an obvious
>> case for why it is important to distinguish between locally-present
>> data (even with that data is sparse) [shown as depth 1 over NBD], and
>> data that could not be found anywhere in the backing chain [shown as
>> depth 0].  But qemu-img map --output=json predates that addition, and
>> has the unfortunate behavior that all portions of the backing chain
>> that resolve without finding a hit in any backing layer report the
>> same depth as the final backing layer.  This makes it harder to
>> reconstruct a qcow2 backing chain using just 'qemu-img map' output
>> when using "backing":null to artificially limit a backing chain,
>> because it is impossible to distinguish between a
>> QCOW2_CLUSTER_UNALLOCATED (which defers to a [missing] backing file)
>> and a QCOW2_CLUSTER_ZERO_PLAIN cluster (which would override any
>> backing file), since both types of clusters otherwise show as
>> "data":false,"zero":true" (but note that we can distinguish a
>> QCOW2_CLUSTER_ZERO_ALLOCATED, which would also have an "offset":
>> listing).
>>
>> The task of reconstructing a qcow2 chain was made harder in commit
>> 0da9856851 (nbd: server: Report holes for raw images), because prior
>> to that point, it was possible to abuse NBD's block status command to
>> see which portions of a qcow2 file resulted in BDRV_BLOCK_ALLOCATED
>> (showing up as NBD_STATE_ZERO in isolation) vs. missing from the chain
>> (showing up as NBD_STATE_ZERO|NBD_STATE_HOLE); but now qemu reports
>> more accurate sparseness information over NBD.
>>
>> An obvious solution is to make 'qemu-img map --output=json' visually
>> distinguish between clusters that have a local allocation from those
>> that are found nowhere in the chain, by adding "depth":-1 as the new
>> witness of data that could not be tied to a specific backing image.
>> Several iotests are impacted, but glancing through the changes shows
>> that it is an improvement in that it shows more accurate details.
>>
>> Note that the documentation is specifically worded to allow qemu-img
>> to report "depth":-1 both in the scenario where the last file in the
>> backing chain still defers the cluster (corresponding to
>> BDRV_BLOCK_ALLOCATED not being set anywhere in the chain), and in the
>> scenario where qemu is unable to determine which backing chain element
>> (if any) provides the data.  The latter case does not exist now, but
>> I'm considering an upcoming patch to add a BDRV_BLOCK_BACKING that
>> would let a specific driver (such as NBD) inform the block layer that
>> it is known that a cluster comes from a backing layer, but where there
>> is insufficient data to determine which layer.
>>
>> As a quick demonstration:
>>
>>      # Create a qcow2 image with a raw backing file:
>>      $ qemu-img create base.raw $((4*64*1024))
>>      $ qemu-img create -f qcow2 -b base.raw -F raw top.qcow2
>>
>>      # Write to first 3 clusters of base:
>>      $ qemu-io -f raw -c "w -P 65 0 64k" -c "w -P 66 64k 64k" \
>>        -c "w -P 67 128k 64k" base.raw
>>
>>      # Write to second and third clusters of top, hiding base:
>>      $ qemu-io -f qcow2 -c "w -P 69 64k 64k" -c "w -z 128k 64k" top.qcow2
>>
>>      # Examine the full backing chain
>>      $ qemu-img map --output=json -f qcow2 top.qcow2
>>      [{ "start": 0, "length": 65536, "depth": 1, "zero": false, "data": true, "offset": 0},
>>      { "start": 65536, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": 327680},
>>      { "start": 131072, "length": 65536, "depth": 0, "zero": true, "data": false},
>>      { "start": 196608, "length": 65536, "depth": 1, "zero": true, "data": false, "offset": 196608}]
>>
>>      # Repeat, but with the backing chain clamped. Pre-patch:
>>      $ qemu-img map --output=json -f qcow2 json:'{"driver":"qcow2", \
>>        "backing":null, "file":{"driver":"file", "filename":"top.qcow2"}}'
>>      [{ "start": 0, "length": 65536, "depth": 0, "zero": true, "data": false},
>>      { "start": 65536, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": 327680},
>>      { "start": 131072, "length": 131072, "depth": 0, "zero": true, "data": false}]
>>
>>      # Repeat, but post-patch:
>>      $ qemu-img map --output=json -f qcow2 json:'{"driver":"qcow2", \
>>        "backing":null, "file":{"driver":"file", "filename":"top.qcow2"}}'
>>      [{ "start": 0, "length": 65536, "depth": -1, "zero": true, "data": false},
>>      { "start": 65536, "length": 65536, "depth": 0, "zero": false, "data": true, "offset": 327680},
>>      { "start": 131072, "length": 65536, "depth": 0, "zero": true, "data": false},
>>      { "start": 196608, "length": 65536, "depth": -1, "zero": true, "data": false}]
>>
>> Note that pre-patch, it was impossible to determine which portions of
>> the qcow2 file override the backing file because the "depth":0 regions
>> were combined, so even though qemu internally can tell the difference
>> between sclusters 2 and 3, the command line user could not.  But
>> post-patch, the "depth":-1 markings match the "depth":1 markings when
>> the backing chain is intact, and it becomes obvious which clusters are
>> important.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> I'm not sure do we need a kind of new option or deprecation period for such incompatible change..

I see Kevin worries about same thing..

So, probably better is just add a new optional boolean field, that shows that data is "nowhere in the chain". Such change is a lot more compatible.

> 
> Personally I'm OK with it and like the idea:
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>


-- 
Best regards,
Vladimir


      reply	other threads:[~2021-06-11  8:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10 21:39 [PATCH] qemu-img: Use "depth":-1 to make backing probes obvious Eric Blake
2021-06-11  8:08 ` Vladimir Sementsov-Ogievskiy
2021-06-11  8:16   ` Vladimir Sementsov-Ogievskiy [this message]

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=8ea330fb-ee0e-9f8d-f780-33f0897bc1e6@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=nsoffer@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.