thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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