From: Fam Zheng <famz@redhat.com>
To: Jeff Cody <jcody@redhat.com>
Cc: kwolf@redhat.com, hbrock@redhat.com, qemu-devel@nongnu.org,
rjones@redhat.com, imain@redhat.com, stefanha@redhat.com,
pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 08/11] block: simplify bdrv_drop_intermediate
Date: Thu, 25 Jul 2013 09:34:28 +0800 [thread overview]
Message-ID: <20130725013428.GA28284@T430s.redhat.com> (raw)
In-Reply-To: <20130724231602.GA19811@localhost.localdomain>
On Wed, 07/24 19:16, Jeff Cody wrote:
> On Wed, Jul 17, 2013 at 05:42:13PM +0800, Fam Zheng wrote:
> > bdrv_drop_intermediate used a local list to iterate through backing
> > chain and delete each BDS. It is simplified while adopting to refcount
> > mechanism.
> >
>
> Hi Fam,
>
> The reason for the local list is to keep the BDS deletion
> transactional, so it can be rolled back in case of error (see below)
>
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > block.c | 71 ++++++++++-------------------------------------------------------
> > 1 file changed, 11 insertions(+), 60 deletions(-)
> >
> > diff --git a/block.c b/block.c
> > index 57a3876..499de22 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -2027,12 +2027,6 @@ BlockDriverState *bdrv_find_overlay(BlockDriverState *active,
> > return overlay;
> > }
> >
> > -typedef struct BlkIntermediateStates {
> > - BlockDriverState *bs;
> > - QSIMPLEQ_ENTRY(BlkIntermediateStates) entry;
> > -} BlkIntermediateStates;
> > -
> > -
> > /*
> > * Drops images above 'base' up to and including 'top', and sets the image
> > * above 'top' to have base as its backing file.
> > @@ -2062,15 +2056,9 @@ typedef struct BlkIntermediateStates {
> > int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
> > BlockDriverState *base)
> > {
> > - BlockDriverState *intermediate;
> > - BlockDriverState *base_bs = NULL;
> > BlockDriverState *new_top_bs = NULL;
> > - BlkIntermediateStates *intermediate_state, *next;
> > int ret = -EIO;
> >
> > - QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) states_to_delete;
> > - QSIMPLEQ_INIT(&states_to_delete);
> > -
> > if (!top->drv || !base->drv) {
> > goto exit;
> > }
> > @@ -2082,58 +2070,21 @@ int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
> > goto exit;
> > }
> >
> > - /* special case of new_top_bs->backing_hd already pointing to base - nothing
> > - * to do, no intermediate images */
> > - if (new_top_bs->backing_hd == base) {
> > - ret = 0;
> > - goto exit;
> > - }
> > -
> > - intermediate = top;
> > -
> > - /* now we will go down through the list, and add each BDS we find
> > - * into our deletion queue, until we hit the 'base'
> > - */
> > - while (intermediate) {
> > - intermediate_state = g_malloc0(sizeof(BlkIntermediateStates));
> > - intermediate_state->bs = intermediate;
> > - QSIMPLEQ_INSERT_TAIL(&states_to_delete, intermediate_state, entry);
> > -
> > - if (intermediate->backing_hd == base) {
> > - base_bs = intermediate->backing_hd;
> > - break;
> > + while (new_top_bs->backing_hd && new_top_bs->backing_hd != base) {
> > + BlockDriverState *backing = new_top_bs->backing_hd;
> > + if (backing == NULL) {
> > + goto exit;
>
> If you simplify it until just a while loop that unrefs/deletes the BDS
> inside the loop as you navigate the chain, then any error exit leaves
> you in a bad state, with a potentially invalid chain. This is one
> such error potential.
>
Yes, I'll fix this.
--
Fam
next prev parent reply other threads:[~2013-07-25 1:34 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 9:42 [Qemu-devel] [PATCH v2 00/11] Point-in-time snapshot exporting over NBD Fam Zheng
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 01/11] block: replace in_use with refcnt_soft and refcnt_hard Fam Zheng
2013-07-17 12:26 ` Paolo Bonzini
2013-07-18 4:53 ` Fam Zheng
2013-07-23 9:36 ` Stefan Hajnoczi
2013-07-23 10:32 ` Fam Zheng
2013-07-23 13:34 ` Stefan Hajnoczi
2013-07-24 0:39 ` Fam Zheng
2013-07-24 7:35 ` Stefan Hajnoczi
2013-07-24 7:44 ` Fam Zheng
2013-07-25 7:52 ` Stefan Hajnoczi
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 02/11] block: use refcnt for bs->backing_hd and bs->file Fam Zheng
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 03/11] block: use refcnt for drive_init/drive_uninit Fam Zheng
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 04/11] block: use refcnt for device attach/detach Fam Zheng
2013-07-23 9:44 ` Stefan Hajnoczi
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 05/11] migration: omit drive ref as we have bdrv_ref now Fam Zheng
2013-07-23 9:49 ` Stefan Hajnoczi
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 06/11] xen_disk: simplify blk_disconnect with refcnt Fam Zheng
2013-07-23 9:50 ` Stefan Hajnoczi
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 07/11] block: hold hard reference for backup/mirror target Fam Zheng
2013-07-23 9:52 ` Stefan Hajnoczi
2013-07-25 6:08 ` Fam Zheng
2013-07-25 7:59 ` Stefan Hajnoczi
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 08/11] block: simplify bdrv_drop_intermediate Fam Zheng
2013-07-24 23:16 ` Jeff Cody
2013-07-25 1:34 ` Fam Zheng [this message]
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 09/11] block: add assertion to check refcount before deleting Fam Zheng
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 10/11] block: add option 'backing' to -drive options Fam Zheng
2013-07-17 12:36 ` Paolo Bonzini
2013-07-17 12:58 ` Kevin Wolf
2013-07-17 13:13 ` Paolo Bonzini
2013-07-17 13:48 ` Kevin Wolf
2013-07-17 14:16 ` Paolo Bonzini
2013-07-17 15:09 ` Kevin Wolf
2013-07-17 15:23 ` Paolo Bonzini
2013-07-23 20:07 ` Ian Main
2013-07-22 6:07 ` Fam Zheng
2013-07-23 19:57 ` Ian Main
2013-07-17 9:42 ` [Qemu-devel] [PATCH v2 11/11] qmp: add command 'blockdev-backup' Fam Zheng
2013-07-17 12:44 ` Eric Blake
2013-07-18 4:41 ` Fam Zheng
2013-07-19 10:16 ` Wenchao Xia
2013-07-23 10:10 ` Stefan Hajnoczi
2013-07-19 10:41 ` [Qemu-devel] [PATCH v2 00/11] Point-in-time snapshot exporting over NBD Wenchao Xia
2013-07-23 1:52 ` Wenchao Xia
2013-07-23 6:35 ` Paolo Bonzini
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=20130725013428.GA28284@T430s.redhat.com \
--to=famz@redhat.com \
--cc=hbrock@redhat.com \
--cc=imain@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rjones@redhat.com \
--cc=stefanha@redhat.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.