From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9vjY-0003mF-9n for qemu-devel@nongnu.org; Mon, 06 Jun 2016 10:42:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9vjW-0007QI-AY for qemu-devel@nongnu.org; Mon, 06 Jun 2016 10:42:27 -0400 From: Max Reitz Date: Mon, 6 Jun 2016 16:42:10 +0200 Message-Id: <20160606144212.24074-2-mreitz@redhat.com> In-Reply-To: <20160606144212.24074-1-mreitz@redhat.com> References: <20160606144212.24074-1-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v2 1/3] block: Allow replacement of a BDS by its overlay List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Max Reitz , Kevin Wolf , Fam Zheng change_parent_backing_link() asserts that the BDS to be replaced is not used as a backing file. However, we may want to replace a BDS by its overlay in which case that very link should not be redirected. Signed-off-by: Max Reitz --- block.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index f54bc25..16463aa 100644 --- a/block.c +++ b/block.c @@ -2224,9 +2224,22 @@ void bdrv_close_all(void) static void change_parent_backing_link(BlockDriverState *from, BlockDriverState *to) { - BdrvChild *c, *next; + BdrvChild *c, *next, *to_c; QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { + if (c->role == &child_backing) { + /* Allow @from to be in a backing chain, but only if it is @to's + * backing chain. Do not replace @from by @to there. */ + QLIST_FOREACH(to_c, &to->children, next) { + if (to_c == c) { + break; + } + } + if (to_c) { + continue; + } + } + assert(c->role != &child_backing); bdrv_ref(to); bdrv_replace_child(c, to); -- 2.8.3