From patchwork Thu Jul 21 12:05:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 9241533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D50BF607D3 for ; Thu, 21 Jul 2016 12:06:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C364720649 for ; Thu, 21 Jul 2016 12:06:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5F9A27E66; Thu, 21 Jul 2016 12:06:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 447D220649 for ; Thu, 21 Jul 2016 12:06:30 +0000 (UTC) Received: from localhost ([::1]:40371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQCkH-0005yE-BY for patchwork-qemu-devel@patchwork.kernel.org; Thu, 21 Jul 2016 08:06:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQCjn-0005t4-Ck for qemu-devel@nongnu.org; Thu, 21 Jul 2016 08:06:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQCjh-0005dh-Cq for qemu-devel@nongnu.org; Thu, 21 Jul 2016 08:05:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53889) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQCjh-0005dd-7M for qemu-devel@nongnu.org; Thu, 21 Jul 2016 08:05:53 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9916C05AA56 for ; Thu, 21 Jul 2016 12:05:52 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-112-45.ams2.redhat.com [10.36.112.45]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6LC5ovI006602; Thu, 21 Jul 2016 08:05:50 -0400 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 21 Jul 2016 14:05:46 +0200 Message-Id: <1469102746-20588-1-git-send-email-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 21 Jul 2016 12:05:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] spapr: fix spapr-nvram migration X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , dgibson@redhat.com, thuth@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When spapr-nvram is backed by a file using pflash interface, migration fails on the destination guest with assert: bdrv_co_pwritev: Assertion `!(bs->open_flags & 0x0800)' failed. This avoids the problem by delaying the pflash update until after the device loads complete. This fix is similar to the one for the pflash_cfi01 migration: 90c647d Fix pflash migration Signed-off-by: Laurent Vivier Reviewed-by: Paolo Bonzini --- hw/nvram/spapr_nvram.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c index 019f25d..4de5f70 100644 --- a/hw/nvram/spapr_nvram.c +++ b/hw/nvram/spapr_nvram.c @@ -39,6 +39,7 @@ typedef struct sPAPRNVRAM { uint32_t size; uint8_t *buf; BlockBackend *blk; + VMChangeStateEntry *vmstate; } sPAPRNVRAM; #define TYPE_VIO_SPAPR_NVRAM "spapr-nvram" @@ -185,19 +186,25 @@ static int spapr_nvram_pre_load(void *opaque) return 0; } +static void postload_update_cb(void *opaque, int running, RunState state) +{ + sPAPRNVRAM *nvram = opaque; + + /* This is called after bdrv_invalidate_cache_all. */ + + qemu_del_vm_change_state_handler(nvram->vmstate); + nvram->vmstate = NULL; + + blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size, 0); +} + static int spapr_nvram_post_load(void *opaque, int version_id) { sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(opaque); if (nvram->blk) { - int alen = blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size, 0); - - if (alen < 0) { - return alen; - } - if (alen != nvram->size) { - return -1; - } + nvram->vmstate = qemu_add_vm_change_state_handler(postload_update_cb, + nvram); } return 0;