From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbuUX-0003kl-8L for qemu-devel@nongnu.org; Thu, 31 Oct 2013 11:49:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VbuUR-0004Dk-AB for qemu-devel@nongnu.org; Thu, 31 Oct 2013 11:49:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbuUR-0004DV-0A for qemu-devel@nongnu.org; Thu, 31 Oct 2013 11:48:55 -0400 From: Kevin Wolf Date: Thu, 31 Oct 2013 16:48:16 +0100 Message-Id: <1383234524-372-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1383234524-372-1-git-send-email-kwolf@redhat.com> References: <1383234524-372-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 02/30] qcow2: Restore total_sectors value in save_vmstate 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: Max Reitz Since df2a6f29a5, bdrv_co_do_writev increases the total_sectors value of a growable block devices on writes after the current end. This leads to the virtual disk apparently growing in qcow2_save_vmstate, which in turn affects the disk size captured by the internal snapshot taken directly afterwards through e.g. the HMP savevm command. Such a "grown" snapshot cannot be loaded after reopening the qcow2 image, since its disk size differs from the actual virtual disk size (writing a VM state does not actually increase the virtual disk size). Fix this by restoring total_sectors at the end of qcow2_save_vmstate. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/qcow2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index c1abaff..4a3e8b4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1939,6 +1939,7 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos) { BDRVQcowState *s = bs->opaque; + int64_t total_sectors = bs->total_sectors; int growable = bs->growable; int ret; @@ -1947,6 +1948,11 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov); bs->growable = growable; + /* bdrv_co_do_writev will have increased the total_sectors value to include + * the VM state - the VM state is however not an actual part of the block + * device, therefore, we need to restore the old value. */ + bs->total_sectors = total_sectors; + return ret; } -- 1.8.1.4