From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFpKI-0002KW-Ps for qemu-devel@nongnu.org; Thu, 05 Apr 2012 12:14:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFpKE-0004KC-1K for qemu-devel@nongnu.org; Thu, 05 Apr 2012 12:14:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55192) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFpKD-0004Ji-Ok for qemu-devel@nongnu.org; Thu, 05 Apr 2012 12:14:17 -0400 From: Kevin Wolf Date: Thu, 5 Apr 2012 17:52:10 +0200 Message-Id: <1333641144-13612-33-git-send-email-kwolf@redhat.com> In-Reply-To: <1333641144-13612-1-git-send-email-kwolf@redhat.com> References: <1333641144-13612-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 32/46] block: bdrv_append() fixes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Jeff Cody 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 --- block.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 33630eb..b3117ef 100644 --- a/block.c +++ b/block.c @@ -892,14 +892,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; @@ -944,11 +946,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.6.5