From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXxjt-0006Yl-PI for qemu-devel@nongnu.org; Sun, 20 Oct 2013 14:28:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VXxjn-0004Or-Ps for qemu-devel@nongnu.org; Sun, 20 Oct 2013 14:28:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VXxjn-0004Om-IZ for qemu-devel@nongnu.org; Sun, 20 Oct 2013 14:28:27 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9KISQIk003921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 20 Oct 2013 14:28:26 -0400 From: Max Reitz Date: Sun, 20 Oct 2013 20:28:20 +0200 Message-Id: <1382293700-20192-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH] qcow2: Restore total_sectors value in save_vmstate List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , 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 --- block/qcow2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index c1abaff..5c05bb5 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; @@ -1946,6 +1947,10 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, bs->growable = 1; 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.3.1