All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, armbru@redhat.com,
	jsnow@redhat.com, famz@redhat.com, den@openvz.org,
	stefanha@redhat.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v22 19/30] qcow2: add persistent dirty bitmaps support
Date: Thu, 29 Jun 2017 21:18:52 -0500	[thread overview]
Message-ID: <f92fea0e-fe66-6888-dcd2-10782aec4fd2@redhat.com> (raw)
In-Reply-To: <20170628120530.31251-20-vsementsov@virtuozzo.com>

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

On 06/28/2017 07:05 AM, Vladimir Sementsov-Ogievskiy wrote:
> Store persistent dirty bitmaps in qcow2 image.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2-bitmap.c | 475 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  block/qcow2.c        |   9 +
>  block/qcow2.h        |   1 +
>  3 files changed, 485 insertions(+)
> 

> +
> +/* store_bitmap_data()
> + * Store bitmap to image, filling bitmap table accordingly.
> + */
> +static uint64_t *store_bitmap_data(BlockDriverState *bs,
> +                                   BdrvDirtyBitmap *bitmap,
> +                                   uint32_t *bitmap_table_size, Error **errp)
> +{
> +    int ret;
> +    BDRVQcow2State *s = bs->opaque;
> +    int64_t sector;
> +    uint64_t sbc;
> +    uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap);

This grabs the size (currently in sectors, although I plan to fix it to
be in bytes)...

> +    const char *bm_name = bdrv_dirty_bitmap_name(bitmap);
> +    uint8_t *buf = NULL;
> +    BdrvDirtyBitmapIter *dbi;
> +    uint64_t *tb;
> +    uint64_t tb_size =
> +            size_to_clusters(s,
> +                bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size));

...then finds out how many bytes are required to serialize the entire
image, where bm_size should be the same as before...

> +    while ((sector = bdrv_dirty_iter_next(dbi)) != -1) {
> +        uint64_t cluster = sector / sbc;
> +        uint64_t end, write_size;
> +        int64_t off;
> +
> +        sector = cluster * sbc;
> +        end = MIN(bm_size, sector + sbc);
> +        write_size =
> +            bdrv_dirty_bitmap_serialization_size(bitmap, sector, end - sector);

But here, rather than tackling the entire image at once, you are
subdividing your queries along arbitrary lines. But nowhere do I see a
call to bdrv_dirty_bitmap_serialization_align() to make sure your
end-sector value is properly aligned; if it is not aligned, you will
trigger an assertion failure here...

> +        assert(write_size <= s->cluster_size);
> +
> +        off = qcow2_alloc_clusters(bs, s->cluster_size);
> +        if (off < 0) {
> +            error_setg_errno(errp, -off,
> +                             "Failed to allocate clusters for bitmap '%s'",
> +                             bm_name);
> +            goto fail;
> +        }
> +        tb[cluster] = off;
> +
> +        bdrv_dirty_bitmap_serialize_part(bitmap, buf, sector, end - sector);

...and again here, during serialization_chunk().

I don't know if that means you need a v23 series, or if we can just
patch it in as a followup (perhaps by having me add the usage during my
byte-based dirty-bitmap series).  I guess it depends on whether we can
come up with any bitmap granularity (between 512 bytes and 2M is all the
more we are currently supporting, right?) that differs from the qcow2
cluster granularity in a manner that iteration by qcow2 clusters is no
longer guaranteed to be bitmap-granularity aligned, and thus trigger an
assertion failure on your code as-is.

I also think it's pretty gross to be calculating the iteration bounds by
sectors rather than bytes, when we are really worried about clusters
(it's easier to track just bytes/clusters than it is to track
bytes/sectors/clusters) - but that one is more along the lines of the
sector-to-byte conversions I've been tackling, so I won't insist on you
changing it if there is no other reason for a v23.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


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

  reply	other threads:[~2017-06-30  2:19 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-28 12:05 [Qemu-devel] [PATCH v22 00/30] qcow2: persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 01/30] specs/qcow2: fix bitmap granularity qemu-specific note Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 02/30] specs/qcow2: do not use wording 'bitmap header' Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 03/30] hbitmap: improve dirty iter Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 04/30] tests: add hbitmap iter test Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 05/30] block: fix bdrv_dirty_bitmap_granularity signature Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 06/30] block/dirty-bitmap: add deserialize_ones func Vladimir Sementsov-Ogievskiy
2017-06-30  1:55   ` Eric Blake
2017-06-30  2:01     ` Eric Blake
2017-06-30 17:52       ` John Snow
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 07/30] qcow2-refcount: rename inc_refcounts() and make it public Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 08/30] qcow2: add bitmaps extension Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 09/30] block/dirty-bitmap: fix comment for BlockDirtyBitmap.disabled field Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 10/30] block/dirty-bitmap: add readonly field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2017-06-30  1:21   ` Max Reitz
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 11/30] qcow2: autoloading dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-06-30  1:35   ` Eric Blake
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 12/30] block: refactor bdrv_reopen_commit Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 13/30] block: new bdrv_reopen_bitmaps_rw interface Vladimir Sementsov-Ogievskiy
2017-06-28 12:10   ` Vladimir Sementsov-Ogievskiy
2017-06-28 12:36     ` Eric Blake
2017-06-28 13:02       ` Vladimir Sementsov-Ogievskiy
2017-06-28 13:13         ` Vladimir Sementsov-Ogievskiy
2017-06-28 13:34           ` Vladimir Sementsov-Ogievskiy
2017-06-28 13:31         ` Paolo Bonzini
2017-06-28 14:36           ` Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 14/30] qcow2: support .bdrv_reopen_bitmaps_rw Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 15/30] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 16/30] block: bdrv_close: release bitmaps after drv->bdrv_close Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 17/30] block: introduce persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-06-30  1:43   ` Eric Blake
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 18/30] block/dirty-bitmap: add bdrv_dirty_bitmap_next() Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 19/30] qcow2: add persistent dirty bitmaps support Vladimir Sementsov-Ogievskiy
2017-06-30  2:18   ` Eric Blake [this message]
2017-06-30  2:23     ` Max Reitz
2017-06-30 17:47       ` Eric Blake
2017-06-30 17:58         ` John Snow
2017-06-30 18:28           ` Eric Blake
2017-07-02 14:01         ` Max Reitz
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 20/30] qcow2: store bitmaps on reopening image as read-only Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 21/30] block: add bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 22/30] qcow2: add .bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 23/30] qmp: add persistent flag to block-dirty-bitmap-add Vladimir Sementsov-Ogievskiy
2017-07-07  7:54   ` Markus Armbruster
2017-07-07  8:07     ` Vladimir Sementsov-Ogievskiy
2017-07-07 12:21     ` Vladimir Sementsov-Ogievskiy
2017-07-07 13:25       ` Markus Armbruster
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 24/30] qmp: add autoload parameter " Vladimir Sementsov-Ogievskiy
2017-07-07  7:54   ` Markus Armbruster
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 25/30] qmp: add x-debug-block-dirty-bitmap-sha256 Vladimir Sementsov-Ogievskiy
2017-07-07  8:05   ` Markus Armbruster
2017-07-07  8:13     ` Daniel P. Berrange
2017-07-07  9:00       ` Markus Armbruster
2017-07-07 12:43         ` Vladimir Sementsov-Ogievskiy
2017-07-07 13:53           ` Markus Armbruster
2017-07-07 20:57             ` John Snow
2017-07-10  6:49               ` Markus Armbruster
2017-07-10 16:29                 ` John Snow
2017-07-07 12:30       ` [Qemu-devel] [Qemu-block] " Eric Blake
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 26/30] iotests: test qcow2 persistent dirty bitmap Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 27/30] block/dirty-bitmap: add bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 28/30] qcow2: add .bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 29/30] qmp: block-dirty-bitmap-remove: remove persistent Vladimir Sementsov-Ogievskiy
2017-06-28 12:05 ` [Qemu-devel] [PATCH v22 30/30] block: release persistent bitmaps on inactivate Vladimir Sementsov-Ogievskiy
2017-06-28 13:01 ` [Qemu-devel] [PATCH v22 00/30] qcow2: persistent dirty bitmaps Paolo Bonzini
2017-06-28 13:53   ` Vladimir Sementsov-Ogievskiy
2017-06-29 21:16 ` John Snow
2017-06-30  2:38 ` Max Reitz
2017-11-17 16:04 ` Eric Blake
2017-11-17 16:17   ` Vladimir Sementsov-Ogievskiy
2017-11-17 16:56     ` Eric Blake

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=f92fea0e-fe66-6888-dcd2-10782aec4fd2@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=famz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@virtuozzo.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 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.