cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-pflash_cfi01-write-flash-contents-to-bdrv-on-incomin.patch

958e1b
From 2a3a2063076b590d9ef81a7d7cdc71520647734b Mon Sep 17 00:00:00 2001
958e1b
From: Laszlo Ersek <lersek@redhat.com>
958e1b
Date: Tue, 9 Sep 2014 16:04:57 +0200
958e1b
Subject: [PATCH 07/12] pflash_cfi01: write flash contents to bdrv on incoming migration
958e1b
958e1b
Message-id: <1410278697-29800-2-git-send-email-lersek@redhat.com>
958e1b
Patchwork-id: 60923
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 1/1] pflash_cfi01: write flash contents to bdrv on incoming migration
958e1b
Bugzilla: 1139702
958e1b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
958e1b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
958e1b
A drive that backs a pflash device is special:
958e1b
- it is very small,
958e1b
- its entire contents are kept in a RAMBlock at all times, covering the
958e1b
  guest-phys address range that provides the guest's view of the emulated
958e1b
  flash chip.
958e1b
958e1b
The pflash device model keeps the drive (the host-side file) and the
958e1b
guest-visible flash contents in sync. When migrating the guest, the
958e1b
guest-visible flash contents (the RAMBlock) is migrated by default, but on
958e1b
the target host, the drive (the host-side file) remains in full sync with
958e1b
the RAMBlock only if:
958e1b
- the source and target hosts share the storage underlying the pflash
958e1b
  drive,
958e1b
- or the migration requests full or incremental block migration too, which
958e1b
  then covers all drives.
958e1b
958e1b
Due to the special nature of pflash drives, the following scenario makes
958e1b
sense as well:
958e1b
- no full nor incremental block migration, covering all drives, alongside
958e1b
  the base migration (justified eg. by shared storage for "normal" (big)
958e1b
  drives),
958e1b
- non-shared storage for pflash drives.
958e1b
958e1b
In this case, currently only those portions of the flash drive are updated
958e1b
on the target disk that the guest reprograms while running on the target
958e1b
host.
958e1b
958e1b
In order to restore accord, dump the entire flash contents to the bdrv in
958e1b
a post_load() callback.
958e1b
958e1b
- The read-only check follows the other call-sites of pflash_update();
958e1b
- both "pfl->ro" and pflash_update() reflect / consider the case when
958e1b
  "pfl->bs" is NULL;
958e1b
- the total size of the flash device is calculated as in
958e1b
  pflash_cfi01_realize().
958e1b
958e1b
When using shared storage, or requesting full or incremental block
958e1b
migration along with the normal migration, the patch should incur a
958e1b
harmless rewrite from the target side.
958e1b
958e1b
It is assumed that, on the target host, RAM is loaded ahead of the call to
958e1b
pflash_post_load().
958e1b
958e1b
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
958e1b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
(cherry picked from commit 4c0cfc72b31a79f737a64ebbe0411e4b83e25771)
958e1b
---
958e1b
 hw/block/pflash_cfi01.c | 14 ++++++++++++++
958e1b
 1 file changed, 14 insertions(+)
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 hw/block/pflash_cfi01.c |   14 ++++++++++++++
958e1b
 1 files changed, 14 insertions(+), 0 deletions(-)
958e1b
958e1b
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
958e1b
index 18eb0bc..e8b47fb 100644
958e1b
--- a/hw/block/pflash_cfi01.c
958e1b
+++ b/hw/block/pflash_cfi01.c
958e1b
@@ -85,10 +85,13 @@ struct pflash_t {
958e1b
     void *storage;
958e1b
 };
958e1b
 
958e1b
+static int pflash_post_load(void *opaque, int version_id);
958e1b
+
958e1b
 static const VMStateDescription vmstate_pflash = {
958e1b
     .name = "pflash_cfi01",
958e1b
     .version_id = 1,
958e1b
     .minimum_version_id = 1,
958e1b
+    .post_load = pflash_post_load,
958e1b
     .fields = (VMStateField[]) {
958e1b
         VMSTATE_UINT8(wcycle, pflash_t),
958e1b
         VMSTATE_UINT8(cmd, pflash_t),
958e1b
@@ -768,3 +771,14 @@ MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl)
958e1b
 {
958e1b
     return &fl->mem;
958e1b
 }
958e1b
+
958e1b
+static int pflash_post_load(void *opaque, int version_id)
958e1b
+{
958e1b
+    pflash_t *pfl = opaque;
958e1b
+
958e1b
+    if (!pfl->ro) {
958e1b
+        DPRINTF("%s: updating bdrv for %s\n", __func__, pfl->name);
958e1b
+        pflash_update(pfl, 0, pfl->sector_len * pfl->nb_blocs);
958e1b
+    }
958e1b
+    return 0;
958e1b
+}
958e1b
-- 
958e1b
1.7.1
958e1b