From: Max Reitz <mreitz@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, eblake@redhat.com,
jsnow@redhat.com, famz@redhat.com, den@openvz.org,
stefanha@redhat.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v16 13/22] qcow2: add persistent dirty bitmaps support
Date: Mon, 27 Feb 2017 15:38:30 +0100 [thread overview]
Message-ID: <01c5d48f-09c0-06e2-5a67-5467470c4fbe@redhat.com> (raw)
In-Reply-To: <20170225170758.427066-14-vsementsov@virtuozzo.com>
[-- Attachment #1: Type: text/plain, Size: 3684 bytes --]
On 25.02.2017 18:07, Vladimir Sementsov-Ogievskiy wrote:
> Store persistent dirty bitmaps in qcow2 image.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> block.c | 6 +-
> block/qcow2-bitmap.c | 473 +++++++++++++++++++++++++++++++++++++++++++++++++++
> block/qcow2.c | 9 +
> block/qcow2.h | 1 +
> 4 files changed, 486 insertions(+), 3 deletions(-)
>
> diff --git a/block.c b/block.c
> index a0346c80c6..16cf522219 100644
> --- a/block.c
> +++ b/block.c
> @@ -2322,9 +2322,6 @@ static void bdrv_close(BlockDriverState *bs)
> bdrv_flush(bs);
> bdrv_drain(bs); /* in case flush left pending I/O */
>
> - bdrv_release_named_dirty_bitmaps(bs);
> - assert(QLIST_EMPTY(&bs->dirty_bitmaps));
> -
> if (bs->drv) {
> BdrvChild *child, *next;
>
> @@ -2363,6 +2360,9 @@ static void bdrv_close(BlockDriverState *bs)
> bs->full_open_options = NULL;
> }
>
> + bdrv_release_named_dirty_bitmaps(bs);
> + assert(QLIST_EMPTY(&bs->dirty_bitmaps));
> +
> QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_next) {
> g_free(ban);
> }
Might deserve an own patch, but I don't mind.
> diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
> index ba72b7d2ac..e377215d5c 100644
> --- a/block/qcow2-bitmap.c
> +++ b/block/qcow2-bitmap.c
[...]
> @@ -127,6 +145,70 @@ static int check_table_entry(uint64_t entry, int cluster_size)
> return 0;
> }
>
> +static int check_constraints_on_bitmap(BlockDriverState *bs,
> + const char *name,
> + uint32_t granularity,
> + Error **errp)
> +{
> + BDRVQcow2State *s = bs->opaque;
> + int granularity_bits = ctz32(granularity);
> + int64_t len = bdrv_getlength(bs);
> +
> + assert(granularity > 0);
> + assert((granularity & (granularity - 1)) == 0);
> +
> + if (len < 0) {
> + error_setg_errno(errp, -len, "Failed to get size of '%s'",
> + bdrv_get_device_or_node_name(bs));
> + return len;
> + }
> +
> + if (granularity_bits > BME_MAX_GRANULARITY_BITS) {
> + error_setg(errp, "Granularity exceeds maximum (%u bytes)",
> + 1 << BME_MAX_GRANULARITY_BITS);
This will overflow because 1 << 31 is not representable in int (and 1 is
an int). The %u saves it by converting it back, but it's still
implementation-defined behavior at most.
I'd prefer a plain 1ull and %ull. That way, this would be save no matter
what value BME_MAX_GRANULARITY_BITS is.
> + return -EINVAL;
> + }
> + if (granularity_bits < BME_MIN_GRANULARITY_BITS) {
> + error_setg(errp, "Granularity is under minimum (%u bytes)",
> + 1 << BME_MIN_GRANULARITY_BITS);
The same applies here, although this does not have the overflow issue.
Rest looks good (to me O:-)).
Max
> + return -EINVAL;
> + }
> +
> + if ((len > (uint64_t)BME_MAX_PHYS_SIZE << granularity_bits) ||
> + (len > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size <<
> + granularity_bits))
> + {
> + error_setg(errp, "Too much space will be occupied by the bitmap. "
> + "Use larger granularity");
> + return -EINVAL;
> + }
> +
> + if (strlen(name) > BME_MAX_NAME_SIZE) {
> + error_setg(errp, "Name length exceeds maximum (%u characters)",
> + BME_MAX_NAME_SIZE);
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
next prev parent reply other threads:[~2017-02-27 14:38 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-25 17:07 [Qemu-devel] [PATCH v16 00/22] qcow2: persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 01/22] specs/qcow2: fix bitmap granularity qemu-specific note Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 02/22] specs/qcow2: do not use wording 'bitmap header' Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 03/22] hbitmap: improve dirty iter Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 04/22] tests: add hbitmap iter test Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 05/22] block: fix bdrv_dirty_bitmap_granularity signature Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 06/22] block/dirty-bitmap: add deserialize_ones func Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 07/22] qcow2-refcount: rename inc_refcounts() and make it public Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 08/22] qcow2: add bitmaps extension Vladimir Sementsov-Ogievskiy
2017-02-27 12:27 ` Max Reitz
2017-02-27 23:09 ` John Snow
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 09/22] qcow2: autoloading dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-02-27 12:50 ` Max Reitz
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 10/22] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 11/22] block: introduce persistent dirty bitmaps Vladimir Sementsov-Ogievskiy
2017-02-27 13:38 ` Max Reitz
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 12/22] block/dirty-bitmap: add bdrv_dirty_bitmap_next() Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 13/22] qcow2: add persistent dirty bitmaps support Vladimir Sementsov-Ogievskiy
2017-02-27 14:38 ` Max Reitz [this message]
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 14/22] block: add bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 15/22] qcow2: add .bdrv_can_store_new_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-27 14:46 ` Max Reitz
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 16/22] qmp: add persistent flag to block-dirty-bitmap-add Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 17/22] qmp: add autoload parameter " Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 18/22] qmp: add x-debug-block-dirty-bitmap-sha256 Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 19/22] iotests: test qcow2 persistent dirty bitmap Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 20/22] block/dirty-bitmap: add bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 21/22] qcow2: add .bdrv_remove_persistent_dirty_bitmap Vladimir Sementsov-Ogievskiy
2017-02-25 17:07 ` [Qemu-devel] [PATCH v16 22/22] qmp: block-dirty-bitmap-remove: remove persistent Vladimir Sementsov-Ogievskiy
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=01c5d48f-09c0-06e2-5a67-5467470c4fbe@redhat.com \
--to=mreitz@redhat.com \
--cc=armbru@redhat.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@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 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).