Blame SOURCES/kvm-qcow2-Restore-total_sectors-value-in-save_vmstate.patch

218e99
From f03758aa88454cd2efe72b7623b855331c5ee22c Mon Sep 17 00:00:00 2001
218e99
From: Max Reitz <mreitz@redhat.com>
218e99
Date: Fri, 1 Nov 2013 14:23:15 +0100
218e99
Subject: [PATCH 27/81] qcow2: Restore total_sectors value in save_vmstate
218e99
218e99
RH-Author: Max Reitz <mreitz@redhat.com>
218e99
Message-id: <1383315797-30938-2-git-send-email-mreitz@redhat.com>
218e99
Patchwork-id: 55216
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 1/3] qcow2: Restore total_sectors value in save_vmstate
218e99
Bugzilla: 1025740
218e99
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
218e99
218e99
BZ: 1025740
218e99
218e99
Since df2a6f29a5, bdrv_co_do_writev increases the total_sectors value of
218e99
a growable block devices on writes after the current end. This leads to
218e99
the virtual disk apparently growing in qcow2_save_vmstate, which in turn
218e99
affects the disk size captured by the internal snapshot taken directly
218e99
afterwards through e.g. the HMP savevm command. Such a "grown" snapshot
218e99
cannot be loaded after reopening the qcow2 image, since its disk size
218e99
differs from the actual virtual disk size (writing a VM state does not
218e99
actually increase the virtual disk size).
218e99
218e99
Fix this by restoring total_sectors at the end of qcow2_save_vmstate.
218e99
218e99
Signed-off-by: Max Reitz <mreitz@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
(cherry picked from commit eedff66f21e542650d895801549ce05ac108278b)
218e99
218e99
Signed-off-by: Max Reitz <mreitz@redhat.com>
218e99
---
218e99
 block/qcow2.c | 6 ++++++
218e99
 1 file changed, 6 insertions(+)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block/qcow2.c |    6 ++++++
218e99
 1 files changed, 6 insertions(+), 0 deletions(-)
218e99
218e99
diff --git a/block/qcow2.c b/block/qcow2.c
218e99
index 8e894b9..f4adf35 100644
218e99
--- a/block/qcow2.c
218e99
+++ b/block/qcow2.c
218e99
@@ -1716,6 +1716,7 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
218e99
                               int64_t pos)
218e99
 {
218e99
     BDRVQcowState *s = bs->opaque;
218e99
+    int64_t total_sectors = bs->total_sectors;
218e99
     int growable = bs->growable;
218e99
     int ret;
218e99
 
218e99
@@ -1724,6 +1725,11 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
218e99
     ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov);
218e99
     bs->growable = growable;
218e99
 
218e99
+    /* bdrv_co_do_writev will have increased the total_sectors value to include
218e99
+     * the VM state - the VM state is however not an actual part of the block
218e99
+     * device, therefore, we need to restore the old value. */
218e99
+    bs->total_sectors = total_sectors;
218e99
+
218e99
     return ret;
218e99
 }
218e99
 
218e99
-- 
218e99
1.7.1
218e99