thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-Update-image-size-in-bdrv_invalidate_cache.patch

0a122b
From ceea60585e2975d7860725bb8c6c860b791a4b72 Mon Sep 17 00:00:00 2001
0a122b
From: Kevin Wolf <kwolf@redhat.com>
0a122b
Date: Mon, 17 Mar 2014 13:29:26 +0100
0a122b
Subject: [PATCH 2/6] block: Update image size in bdrv_invalidate_cache()
0a122b
0a122b
RH-Author: Kevin Wolf <kwolf@redhat.com>
0a122b
Message-id: <1395062967-16867-2-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: 58111
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH 1/2] block: Update image size in bdrv_invalidate_cache()
0a122b
Bugzilla: 1048575
0a122b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
0a122b
After migration has completed, we call bdrv_invalidate_cache() so that
0a122b
drivers which cache some data drop their stale copy of the data and
0a122b
reread it from the image file to get a new version of data that the
0a122b
source modified while the migration was running.
0a122b
0a122b
Reloading metadata from the image file is useless, though, if the size
0a122b
of the image file stays stale (this is a value that is cached for all
0a122b
image formats in block.c). Reads from (meta)data after the old EOF
0a122b
return only zeroes, causing image corruption.
0a122b
0a122b
We need to update bs->total_sectors in all layers that could potentially
0a122b
have changed their size (i.e. backing files are not a concern - if they
0a122b
are changed, we're in bigger trouble)
0a122b
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit 3456a8d1852e970688b73d03fdc44dde851759e1)
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 block.c       | 10 +++++++++-
0a122b
 block/qcow2.c |  2 ++
0a122b
 block/qed.c   |  3 +++
0a122b
 3 files changed, 14 insertions(+), 1 deletion(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block.c       |   10 +++++++++-
0a122b
 block/qcow2.c |    2 ++
0a122b
 block/qed.c   |    3 +++
0a122b
 3 files changed, 14 insertions(+), 1 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index ec8dc90..ae55535 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -4713,9 +4713,17 @@ flush_parent:
0a122b
 
0a122b
 void bdrv_invalidate_cache(BlockDriverState *bs)
0a122b
 {
0a122b
-    if (bs->drv && bs->drv->bdrv_invalidate_cache) {
0a122b
+    if (!bs->drv)  {
0a122b
+        return;
0a122b
+    }
0a122b
+
0a122b
+    if (bs->drv->bdrv_invalidate_cache) {
0a122b
         bs->drv->bdrv_invalidate_cache(bs);
0a122b
+    } else if (bs->file) {
0a122b
+        bdrv_invalidate_cache(bs->file);
0a122b
     }
0a122b
+
0a122b
+    refresh_total_sectors(bs, bs->total_sectors);
0a122b
 }
0a122b
 
0a122b
 void bdrv_invalidate_cache_all(void)
0a122b
diff --git a/block/qcow2.c b/block/qcow2.c
0a122b
index daad932..e9bd9c9 100644
0a122b
--- a/block/qcow2.c
0a122b
+++ b/block/qcow2.c
0a122b
@@ -1176,6 +1176,8 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
0a122b
 
0a122b
     qcow2_close(bs);
0a122b
 
0a122b
+    bdrv_invalidate_cache(bs->file);
0a122b
+
0a122b
     options = qdict_new();
0a122b
     qdict_put(options, QCOW2_OPT_LAZY_REFCOUNTS,
0a122b
               qbool_from_int(s->use_lazy_refcounts));
0a122b
diff --git a/block/qed.c b/block/qed.c
0a122b
index be5945b..619f2d0 100644
0a122b
--- a/block/qed.c
0a122b
+++ b/block/qed.c
0a122b
@@ -1561,6 +1561,9 @@ static void bdrv_qed_invalidate_cache(BlockDriverState *bs)
0a122b
     BDRVQEDState *s = bs->opaque;
0a122b
 
0a122b
     bdrv_qed_close(bs);
0a122b
+
0a122b
+    bdrv_invalidate_cache(bs->file);
0a122b
+
0a122b
     memset(s, 0, sizeof(BDRVQEDState));
0a122b
     bdrv_qed_open(bs, NULL, bs->open_flags, NULL);
0a122b
 }
0a122b
-- 
0a122b
1.7.1
0a122b