qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 09/22] qcow2: autoloading dirty bitmaps
Date: Mon, 27 Feb 2017 13:50:32 +0100	[thread overview]
Message-ID: <15df3d2b-17e9-a229-154e-dfdb502216ad@redhat.com> (raw)
In-Reply-To: <20170225170758.427066-10-vsementsov@virtuozzo.com>

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

On 25.02.2017 18:07, Vladimir Sementsov-Ogievskiy wrote:
> Auto loading bitmaps are bitmaps in Qcow2, with the AUTO flag set. They
> are loaded when the image is opened and become BdrvDirtyBitmaps for the
> corresponding drive.
> 
> Extra data in bitmaps is not supported for now.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block/qcow2-bitmap.c | 367 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  block/qcow2.c        |   7 +
>  block/qcow2.h        |   2 +
>  3 files changed, 376 insertions(+)
> 
> diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
> index b8e472b3e8..73a6e87038 100644
> --- a/block/qcow2-bitmap.c
> +++ b/block/qcow2-bitmap.c

[...]

> +static int update_ext_header_and_dir_in_place(BlockDriverState *bs,
> +                                              Qcow2BitmapList *bm_list)
> +{
> +    BDRVQcow2State *s = bs->opaque;
> +    int ret;
> +
> +    if (!(s->autoclear_features & QCOW2_AUTOCLEAR_BITMAPS) ||
> +        bm_list == NULL || QSIMPLEQ_EMPTY(bm_list) ||
> +        bitmap_list_count(bm_list) != s->nb_bitmaps)
> +    {
> +        return -EINVAL;
> +    }
> +
> +    s->autoclear_features &= ~(uint64_t)QCOW2_AUTOCLEAR_BITMAPS;
> +    ret = update_header_sync(bs);
> +    if (ret < 0) {
> +        /* Two variants are possible here:
> +         * 1. Autoclear flag is dropped, all bitmaps will be lost.
> +         * 2. Autoclear flag is not dropped, old state is left.
> +         */
> +        return ret;
> +    }
> +
> +    /* autoclear bit is not set, so we can safely update bitmap directory */
> +
> +    ret = bitmap_list_store(bs, bm_list, &s->bitmap_directory_offset,
> +                            &s->bitmap_directory_size, true);
> +    if (ret < 0) {
> +        /* autoclear bit is cleared, so all leaked clusters would be removed on
> +         * qemu-img check */
> +        return ret;
> +    }
> +
> +    ret = update_header_sync(bs);
> +    if (ret < 0) {
> +        /* autoclear bit is cleared, so all leaked clusters would be removed on
> +         * qemu-img check */
> +        return ret;
> +    }
> +
> +    s->autoclear_features |= QCOW2_AUTOCLEAR_BITMAPS;
> +    return update_header_sync(bs);
> +    /* If final update_header_sync() fails, two variants are possible:
> +     * 1. Autoclear flag is not set, all bitmaps will be lost.
> +     * 2. Autoclear flag is set, header and directory are successfully updated.
> +     */

Oh, nice. Thanks for the explanations, too. This way I'm very much fine
with update_header_sync() failing if bdrv_flush() fails.

> +}
> +
> +/* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */
> +static void release_dirty_bitmap_helper(gpointer bitmap,
> +                                        gpointer bs)
> +{
> +    bdrv_release_dirty_bitmap(bs, bitmap);
> +}

[...]

> diff --git a/block/qcow2.c b/block/qcow2.c
> index 6cd411f9c5..f4bb9d46de 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -1237,6 +1237,13 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
>          goto fail;
>      }
>  
> +    qcow2_load_autoloading_dirty_bitmaps(bs, &local_err);
> +    if (local_err != NULL) {
> +        error_propagate(errp, local_err);
> +        ret = -EINVAL;
> +        goto fail;
> +    }
> +
>      /* Clear unknown autoclear feature bits */
>      need_update_header |= s->autoclear_features & ~QCOW2_AUTOCLEAR_MASK;
>  

I think it would be better to load the dirty bitmaps after clearing
unknown autoclear bits, because loading the bitmaps may result in
modifications of the image file.

Max


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

  reply	other threads:[~2017-02-27 12:50 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 [this message]
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
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=15df3d2b-17e9-a229-154e-dfdb502216ad@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).