qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 07/11] block: Fix backing file child when modifying graph
Date: Tue, 14 Jul 2015 17:39:28 +0200	[thread overview]
Message-ID: <1436888372-27871-8-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1436888372-27871-1-git-send-email-kwolf@redhat.com>

This patch moves bdrv_attach_child() from the individual places that add
a backing file to a BDS to bdrv_set_backing_hd(), which is called by all
of them. It also adds bdrv_detach_child() there.

For normal operation (starting with one backing file chain and not
changing it until the topmost image is closed) and live snapshots, this
constitutes no change in behaviour.

For all other cases, this is a fix for the bug that the old backing file
was still referenced as a child, and the new one wasn't referenced.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block.c                   | 5 +++--
 include/block/block_int.h | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index d5c9f03..d088ee0 100644
--- a/block.c
+++ b/block.c
@@ -1141,6 +1141,7 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
     if (bs->backing_hd) {
         assert(bs->backing_blocker);
         bdrv_op_unblock_all(bs->backing_hd, bs->backing_blocker);
+        bdrv_detach_child(bs->backing_child);
     } else if (backing_hd) {
         error_setg(&bs->backing_blocker,
                    "node is used as backing hd of '%s'",
@@ -1151,8 +1152,10 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
     if (!backing_hd) {
         error_free(bs->backing_blocker);
         bs->backing_blocker = NULL;
+        bs->backing_child = NULL;
         goto out;
     }
+    bs->backing_child = bdrv_attach_child(bs, backing_hd, &child_backing);
     bs->open_flags &= ~BDRV_O_NO_BACKING;
     pstrcpy(bs->backing_file, sizeof(bs->backing_file), backing_hd->filename);
     pstrcpy(bs->backing_format, sizeof(bs->backing_format),
@@ -1236,7 +1239,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
         goto free_exit;
     }
 
-    bdrv_attach_child(bs, backing_hd, &child_backing);
     bdrv_set_backing_hd(bs, backing_hd);
 
 free_exit:
@@ -2171,7 +2173,6 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top)
     /* The contents of 'tmp' will become bs_top, as we are
      * swapping bs_new and bs_top contents. */
     bdrv_set_backing_hd(bs_top, bs_new);
-    bdrv_attach_child(bs_top, bs_new, &child_backing);
 }
 
 static void bdrv_delete(BlockDriverState *bs)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index ec244b5..14ad4c3 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -379,6 +379,7 @@ struct BlockDriverState {
     char exact_filename[PATH_MAX];
 
     BlockDriverState *backing_hd;
+    BdrvChild *backing_child;
     BlockDriverState *file;
 
     NotifierList close_notifiers;
-- 
1.8.3.1

  parent reply	other threads:[~2015-07-14 15:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-14 15:39 [Qemu-devel] [PULL 00/11] Block layer patches for 2.4.0-rc1 Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 01/11] nvme: implement the Flush command Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 02/11] nvme: properly report volatile write caches Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 03/11] block: Move bdrv_attach_child() calls up the call chain Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 04/11] block: Introduce bdrv_open_child() Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 05/11] block: Introduce bdrv_unref_child() Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 06/11] block: Reorder cleanups in bdrv_close() Kevin Wolf
2015-07-14 15:39 ` Kevin Wolf [this message]
2015-07-14 15:39 ` [Qemu-devel] [PULL 08/11] rbd: remove unused constants and fields Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 09/11] MAINTAINERS: update email address Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 10/11] rbd: make qemu's cache setting override any ceph setting Kevin Wolf
2015-07-14 15:39 ` [Qemu-devel] [PULL 11/11] rbd: fix ceph settings precedence Kevin Wolf
2015-07-14 17:50 ` [Qemu-devel] [PULL 00/11] Block layer patches for 2.4.0-rc1 Peter Maydell

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=1436888372-27871-8-git-send-email-kwolf@redhat.com \
    --to=kwolf@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 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).