From 9055f9350836c7f363e407a8e518da0e846e3f62 Mon Sep 17 00:00:00 2001 Message-Id: <9055f9350836c7f363e407a8e518da0e846e3f62.1334770230.git.minovotn@redhat.com> In-Reply-To: <5e4659718c6d6ee9ab11b269d929a292a71b3ab0.1334770230.git.minovotn@redhat.com> References: <5e4659718c6d6ee9ab11b269d929a292a71b3ab0.1334770230.git.minovotn@redhat.com> From: Paolo Bonzini Date: Fri, 13 Apr 2012 16:27:12 +0200 Subject: [PATCH 04/18] block: bdrv_append() fixes RH-Author: Paolo Bonzini Message-id: <1334334446-31987-3-git-send-email-pbonzini@redhat.com> Patchwork-id: 39214 O-Subject: [RHEL 6.3 qemu-kvm PATCH 02/16] block: bdrv_append() fixes Bugzilla: 806432 RH-Acked-by: Laszlo Ersek RH-Acked-by: Kevin Wolf RH-Acked-by: Jeffrey Cody From: Jeff Cody Bugzilla: 806432 A few fixups for bdrv_append(): The new bs (bs_new) passed into bdrv_append() should be anonymous. Rather than call bdrv_make_anon() to enforce this, use an assert to catch when a caller is passing in a bs_new that is not anonymous. Also, the new top layer should have its backing_format reflect the original top's format. And last, after the swap of bs contents, the device_name will have been copied down. This needs to be cleared to reflect the anonymity of the bs that was pushed down. Signed-off-by: Jeff Cody Signed-off-by: Kevin Wolf (cherry-picked from upstream commit f6801b83d0e77ca025867800d805ee80f6bda938) --- block.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) Signed-off-by: Michal Novotny --- block.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 6063f90..54f1fc1 100644 --- a/block.c +++ b/block.c @@ -758,14 +758,16 @@ void bdrv_make_anon(BlockDriverState *bs) * This will modify the BlockDriverState fields, and swap contents * between bs_new and bs_top. Both bs_new and bs_top are modified. * + * bs_new is required to be anonymous. + * * This function does not create any image files. */ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) { BlockDriverState tmp; - /* the new bs must not be in bdrv_states */ - bdrv_make_anon(bs_new); + /* bs_new must be anonymous */ + assert(bs_new->device_name[0] == '\0'); tmp = *bs_new; @@ -799,11 +801,18 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) * swapping bs_new and bs_top contents. */ tmp.backing_hd = bs_new; pstrcpy(tmp.backing_file, sizeof(tmp.backing_file), bs_top->filename); + bdrv_get_format(bs_top, tmp.backing_format, sizeof(tmp.backing_format)); /* swap contents of the fixed new bs and the current top */ *bs_new = *bs_top; *bs_top = tmp; + /* device_name[] was carried over from the old bs_top. bs_new + * shouldn't be in bdrv_states, so we need to make device_name[] + * reflect the anonymity of bs_new + */ + bs_new->device_name[0] = '\0'; + /* clear the copied fields in the new backing file */ bdrv_detach_dev(bs_new, bs_new->dev); -- 1.7.7.6