218e99
From 49b4262336e2875280d7d539851b5b318a86bc39 Mon Sep 17 00:00:00 2001
218e99
From: Asias He <asias@redhat.com>
218e99
Date: Thu, 12 Sep 2013 07:39:33 +0200
218e99
Subject: [PATCH 13/29] block: Introduce bs->zero_beyond_eof
218e99
218e99
RH-Author: Asias He <asias@redhat.com>
218e99
Message-id: <1378971575-22416-3-git-send-email-asias@redhat.com>
218e99
Patchwork-id: 54326
218e99
O-Subject: [RHEL7.0 qemu-kvm PATCH 2/4] block: Introduce bs->zero_beyond_eof
218e99
Bugzilla: 1007226
218e99
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
218e99
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1007226
218e99
Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=6275752
218e99
218e99
In 4146b46c42e0989cb5842e04d88ab6ccb1713a48 (block: Produce zeros when
218e99
protocols reading beyond end of file), we break qemu-iotests ./check
218e99
-qcow2 022. This happens because qcow2 temporarily sets ->growable = 1
218e99
for vmstate accesses (which are stored beyond the end of regular image
218e99
data).
218e99
218e99
We introduce the bs->zero_beyond_eof to allow qcow2_load_vmstate() to
218e99
disable ->zero_beyond_eof temporarily in addition to enable ->growable.
218e99
218e99
[Since the broken patch "block: Produce zeros when protocols reading
218e99
beyond end of file" has not been merged yet, I have applied this fix
218e99
*first* and will then apply the next patch to keep the tree bisectable.
218e99
-- Stefan]
218e99
218e99
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
Signed-off-by: Asias He <asias@redhat.com>
218e99
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
218e99
(cherry picked from commit 0d51b4debee6fb322751a57097a1d675c7a7c38d)
218e99
---
218e99
 block.c                   | 2 ++
218e99
 block/qcow2.c             | 3 +++
218e99
 include/block/block_int.h | 3 +++
218e99
 3 files changed, 8 insertions(+)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block.c                   |    2 ++
218e99
 block/qcow2.c             |    3 +++
218e99
 include/block/block_int.h |    3 +++
218e99
 3 files changed, 8 insertions(+), 0 deletions(-)
218e99
218e99
diff --git a/block.c b/block.c
218e99
index f4a89b9..dbcad0e 100644
218e99
--- a/block.c
218e99
+++ b/block.c
218e99
@@ -708,6 +708,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
218e99
 
218e99
     bs->open_flags = flags;
218e99
     bs->buffer_alignment = 512;
218e99
+    bs->zero_beyond_eof = true;
218e99
     open_flags = bdrv_open_flags(bs, flags);
218e99
     bs->read_only = !(open_flags & BDRV_O_RDWR);
218e99
 
218e99
@@ -1407,6 +1408,7 @@ void bdrv_close(BlockDriverState *bs)
218e99
         bs->valid_key = 0;
218e99
         bs->sg = 0;
218e99
         bs->growable = 0;
218e99
+        bs->zero_beyond_eof = false;
218e99
         QDECREF(bs->options);
218e99
         bs->options = NULL;
218e99
 
218e99
diff --git a/block/qcow2.c b/block/qcow2.c
218e99
index abdc202..70da5bd 100644
218e99
--- a/block/qcow2.c
218e99
+++ b/block/qcow2.c
218e99
@@ -1722,12 +1722,15 @@ static int qcow2_load_vmstate(BlockDriverState *bs, uint8_t *buf,
218e99
 {
218e99
     BDRVQcowState *s = bs->opaque;
218e99
     int growable = bs->growable;
218e99
+    bool zero_beyond_eof = bs->zero_beyond_eof;
218e99
     int ret;
218e99
 
218e99
     BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_LOAD);
218e99
     bs->growable = 1;
218e99
+    bs->zero_beyond_eof = false;
218e99
     ret = bdrv_pread(bs, qcow2_vm_state_offset(s) + pos, buf, size);
218e99
     bs->growable = growable;
218e99
+    bs->zero_beyond_eof = zero_beyond_eof;
218e99
 
218e99
     return ret;
218e99
 }
218e99
diff --git a/include/block/block_int.h b/include/block/block_int.h
218e99
index 6078dd3..267be48 100644
218e99
--- a/include/block/block_int.h
218e99
+++ b/include/block/block_int.h
218e99
@@ -268,6 +268,9 @@ struct BlockDriverState {
218e99
     /* Whether the disk can expand beyond total_sectors */
218e99
     int growable;
218e99
 
218e99
+    /* Whether produces zeros when read beyond eof */
218e99
+    bool zero_beyond_eof;
218e99
+
218e99
     /* the memory alignment required for the buffers handled by this driver */
218e99
     int buffer_alignment;
218e99
 
218e99
-- 
218e99
1.7.1
218e99