From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60856) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar282-0005i6-8m for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:41:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ar27x-0003GJ-8d for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:41:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49335) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar27x-0003GF-38 for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:41:33 -0400 From: "Dr. David Alan Gilbert (git)" Date: Fri, 15 Apr 2016 12:41:30 +0100 Message-Id: <1460720490-9545-1-git-send-email-dgilbert@redhat.com> Subject: [Qemu-devel] [PATCH] Fix pflash migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, peter.maydell@linaro.org, lersek@redhat.com, kwolf@redhat.com, jsnow@redhat.com From: "Dr. David Alan Gilbert" Pflash migration (e.g. q35 + EFI variable storage) fails with the assert: bdrv_co_do_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed. This avoids the problem by delaying the pflash update until after the device loads complete. Tested by: Migrating Q35/EFI vm. Changing efi variable content (with efiboot in the guest) md5sum'ing the variable file before migration and after. This is a fix that Paolo posted in the message 570244B3.4070105@redhat.com Signed-off-by: Paolo Bonzini Signed-off-by: Dr. David Alan Gilbert --- hw/block/pflash_cfi01.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index c475c2a..106a775 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -46,6 +46,7 @@ #include "exec/address-spaces.h" #include "qemu/host-utils.h" #include "hw/sysbus.h" +#include "sysemu/sysemu.h" #define PFLASH_BUG(fmt, ...) \ do { \ @@ -97,6 +98,7 @@ struct pflash_t { MemoryRegion mem; char *name; void *storage; + VMChangeStateEntry *vmstate; }; static int pflash_post_load(void *opaque, int version_id); @@ -944,13 +946,25 @@ MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl) return &fl->mem; } +static void postload_update_cb(void *opaque, int running, RunState state) +{ + pflash_t *pfl = opaque; + + /* This is called after bdrv_invalidate_cache_all. */ + qemu_del_vm_change_state_handler(pfl->vmstate); + pfl->vmstate = NULL; + + DPRINTF("%s: updating bdrv for %s\n", __func__, pfl->name); + pflash_update(pfl, 0, pfl->sector_len * pfl->nb_blocs); +} + static int pflash_post_load(void *opaque, int version_id) { pflash_t *pfl = opaque; if (!pfl->ro) { - DPRINTF("%s: updating bdrv for %s\n", __func__, pfl->name); - pflash_update(pfl, 0, pfl->sector_len * pfl->nb_blocs); + pfl->vmstate = qemu_add_vm_change_state_handler(postload_update_cb, + pfl); } return 0; } -- 2.5.5