9ae3a8
From 3ab144fe22a867a0ffcce396302b62b0f2ac4c29 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Fri, 1 Nov 2013 14:23:16 +0100
9ae3a8
Subject: [PATCH 28/81] qcow2: Unset zero_beyond_eof in save_vmstate
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383315797-30938-3-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55217
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 2/3] qcow2: Unset zero_beyond_eof 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
Saving the VM state is done using bdrv_pwrite. This function may perform
9ae3a8
a read-modify-write, which in this case results in data being read from
9ae3a8
beyond the end of the virtual disk. Since we are actually trying to
9ae3a8
access an area which is not a part of the virtual disk, zero_beyond_eof
9ae3a8
has to be set to false before performing the partial write, otherwise
9ae3a8
the VM state may become corrupted.
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 6e13610aa454beba52944e8df6d93158d68ab911)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2.c | 3 +++
9ae3a8
 1 file changed, 3 insertions(+)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2.c |    3 +++
9ae3a8
 1 files changed, 3 insertions(+), 0 deletions(-)
9ae3a8
9ae3a8
diff --git a/block/qcow2.c b/block/qcow2.c
9ae3a8
index f4adf35..c2728c9 100644
9ae3a8
--- a/block/qcow2.c
9ae3a8
+++ b/block/qcow2.c
9ae3a8
@@ -1718,12 +1718,15 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
9ae3a8
     BDRVQcowState *s = bs->opaque;
9ae3a8
     int64_t total_sectors = bs->total_sectors;
9ae3a8
     int growable = bs->growable;
9ae3a8
+    bool zero_beyond_eof = bs->zero_beyond_eof;
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
     BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_SAVE);
9ae3a8
     bs->growable = 1;
9ae3a8
+    bs->zero_beyond_eof = false;
9ae3a8
     ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov);
9ae3a8
     bs->growable = growable;
9ae3a8
+    bs->zero_beyond_eof = zero_beyond_eof;
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
-- 
9ae3a8
1.7.1
9ae3a8