From: Fam Zheng <famz@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>, Alberto Garcia <berto@igalia.com>,
qemu-block@nongnu.org, John Snow <jsnow@redhat.com>,
qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v9 01/16] block: Release named dirty bitmaps in bdrv_close()
Date: Wed, 3 Feb 2016 16:27:31 +0800 [thread overview]
Message-ID: <20160203082731.GD25746@ad.usersys.redhat.com> (raw)
In-Reply-To: <1454081776-30130-2-git-send-email-mreitz@redhat.com>
On Fri, 01/29 16:36, Max Reitz wrote:
> bdrv_delete() is not very happy about deleting BlockDriverStates with
> dirty bitmaps still attached to them. In the past, we got around that
> very easily by relying on bdrv_close_all() bypassing bdrv_delete(), and
> bdrv_close() simply ignoring that condition. We should fix that by
> releasing all named dirty bitmaps in bdrv_close() (there should not be
> any unnamed bitmaps left) and moving the assertion from bdrv_delete()
> there.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 39 +++++++++++++++++++++++++++++++--------
> 1 file changed, 31 insertions(+), 8 deletions(-)
>
> diff --git a/block.c b/block.c
> index 5709d3d..41ab00e 100644
> --- a/block.c
> +++ b/block.c
> @@ -88,6 +88,8 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
> const BdrvChildRole *child_role, Error **errp);
>
> static void bdrv_dirty_bitmap_truncate(BlockDriverState *bs);
> +static void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs);
> +
> /* If non-zero, use only whitelisted block drivers */
> static int use_bdrv_whitelist;
>
> @@ -2157,6 +2159,9 @@ void bdrv_close(BlockDriverState *bs)
>
> notifier_list_notify(&bs->close_notifiers, bs);
>
> + bdrv_release_named_dirty_bitmaps(bs);
> + assert(QLIST_EMPTY(&bs->dirty_bitmaps));
> +
> if (bs->blk) {
> blk_dev_change_media_cb(bs->blk, false);
> }
> @@ -2366,7 +2371,6 @@ static void bdrv_delete(BlockDriverState *bs)
> assert(!bs->job);
> assert(bdrv_op_blocker_is_empty(bs));
> assert(!bs->refcnt);
> - assert(QLIST_EMPTY(&bs->dirty_bitmaps));
>
> bdrv_close(bs);
>
> @@ -3582,21 +3586,40 @@ static void bdrv_dirty_bitmap_truncate(BlockDriverState *bs)
> }
> }
>
> -void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
> +static void bdrv_do_release_matching_dirty_bitmap(BlockDriverState *bs,
> + BdrvDirtyBitmap *bitmap,
> + bool only_named)
> {
> BdrvDirtyBitmap *bm, *next;
> QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) {
> - if (bm == bitmap) {
> + if ((!bitmap || bm == bitmap) && (!only_named || bm->name)) {
> assert(!bdrv_dirty_bitmap_frozen(bm));
> - QLIST_REMOVE(bitmap, list);
> - hbitmap_free(bitmap->bitmap);
> - g_free(bitmap->name);
> - g_free(bitmap);
> - return;
> + QLIST_REMOVE(bm, list);
> + hbitmap_free(bm->bitmap);
> + g_free(bm->name);
> + g_free(bm);
> +
> + if (bitmap) {
> + return;
> + }
> }
> }
> }
>
> +void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
> +{
> + bdrv_do_release_matching_dirty_bitmap(bs, bitmap, false);
> +}
> +
> +/**
> + * Release all named dirty bitmaps attached to a BDS (for use in bdrv_close()).
> + * There must not be any frozen bitmaps attached.
> + */
> +static void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs)
> +{
> + bdrv_do_release_matching_dirty_bitmap(bs, NULL, true);
> +}
> +
> void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap)
> {
> assert(!bdrv_dirty_bitmap_frozen(bitmap));
> --
> 2.7.0
>
Reviewed-by: Fam Zheng <famz@redhat.com>
next prev parent reply other threads:[~2016-02-03 8:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-29 15:36 [Qemu-devel] [PATCH v9 00/16] block: Rework bdrv_close_all() Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 01/16] block: Release named dirty bitmaps in bdrv_close() Max Reitz
2016-02-03 8:27 ` Fam Zheng [this message]
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 02/16] iotests: Add test for eject under NBD server Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 03/16] block: Add BB-BDS remove/insert notifiers Max Reitz
2016-02-08 11:53 ` Alberto Garcia
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 04/16] virtio-blk: Functions for op blocker management Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 05/16] virtio-scsi: Catch BDS-BB removal/insertion Max Reitz
2016-02-03 8:29 ` Fam Zheng
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 06/16] nbd: Switch from close to eject notifier Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 07/16] block: Remove BDS close notifier Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 08/16] block: Use blk_remove_bs() in blk_delete() Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 09/16] blockdev: Use blk_remove_bs() in do_drive_del() Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 10/16] block: Make bdrv_close() static Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 11/16] block: Add list of all BlockDriverStates Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 12/16] blockdev: Keep track of monitor-owned BDS Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 13/16] block: Add blk_remove_all_bs() Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 14/16] block: Rewrite bdrv_close_all() Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 15/16] iotests: Add test for multiple BB on BDS tree Max Reitz
2016-01-29 15:36 ` [Qemu-devel] [PATCH v9 16/16] iotests: Add test for block jobs and BDS ejection Max Reitz
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=20160203082731.GD25746@ad.usersys.redhat.com \
--to=famz@redhat.com \
--cc=berto@igalia.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 \
/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.