From patchwork Fri Jun 3 07:52:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9152239 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 469D260751 for ; Fri, 3 Jun 2016 08:39:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3908227BFA for ; Fri, 3 Jun 2016 08:39:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D68028309; Fri, 3 Jun 2016 08:39:12 +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 7B48427BFA for ; Fri, 3 Jun 2016 08:39:11 +0000 (UTC) Received: from localhost ([::1]:53290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8kdK-0005cH-MF for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 04:39:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8jwB-0007ba-KP for qemu-devel@nongnu.org; Fri, 03 Jun 2016 03:54:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8jw9-00050e-C2 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 03:54:34 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:24119) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8jw8-0004j1-Mr for qemu-devel@nongnu.org; Fri, 03 Jun 2016 03:54:33 -0400 Received: from 172.24.1.36 (EHLO szxeml422-hub.china.huawei.com) ([172.24.1.36]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CCR25176; Fri, 03 Jun 2016 15:53:33 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml422-hub.china.huawei.com (10.82.67.152) with Microsoft SMTP Server id 14.3.235.1; Fri, 3 Jun 2016 15:53:21 +0800 From: zhanghailiang To: , , , Date: Fri, 3 Jun 2016 15:52:46 +0800 Message-ID: <1464940366-9880-35-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1464940366-9880-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1464940366-9880-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.575137AA.0079, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: c5ebdd16998eaa04c1cd4e60ca5372f2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Subject: [Qemu-devel] [PATCH COLO-Frame v17 34/34] COLO: Add block replication into colo process 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: Kevin Wolf , xiecl.fnst@cn.fujitsu.com, lizhijian@cn.fujitsu.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, Max Reitz , zhanghailiang , arei.gonglei@huawei.com, stefanha@redhat.com, zhangchen.fnst@cn.fujitsu.com, hongyang.yang@easystack.cn Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make sure master start block replication after slave's block replication started. Signed-off-by: zhanghailiang Signed-off-by: Wen Congyang Signed-off-by: Li Zhijian Cc: Stefan Hajnoczi Cc: Kevin Wolf Cc: Max Reitz --- migration/colo.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ migration/migration.c | 6 +++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/migration/colo.c b/migration/colo.c index de7174f..649c01f 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -23,6 +23,8 @@ #include "net/net.h" #include "net/filter.h" #include "net/vhost_net.h" +#include "block/block.h" +#include "replication.h" static bool vmstate_loading; @@ -64,6 +66,7 @@ static void secondary_vm_do_failover(void) { int old_state; MigrationIncomingState *mis = migration_incoming_get_current(); + Error *local_err = NULL; /* Can not do failover during the process of VM's loading VMstate, Or * it will break the secondary VM. @@ -81,6 +84,11 @@ static void secondary_vm_do_failover(void) migrate_set_state(&mis->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); + replication_stop_all(true, &local_err); + if (local_err) { + error_report_err(local_err); + } + if (!autostart) { error_report("\"-S\" qemu option will be ignored in secondary side"); /* recover runstate to normal migration finish state */ @@ -159,6 +167,11 @@ static void primary_vm_do_failover(void) error_report_err(local_err); } + replication_stop_all(true, &local_err); + if (local_err) { + error_report_err(local_err); + } + /* Notify COLO thread that failover work is finished */ qemu_sem_post(&s->colo_exit_sem); } @@ -317,6 +330,15 @@ static int colo_do_checkpoint_transaction(MigrationState *s, if (local_err) { goto out; } + + /* We call this API although this may do nothing on primary side. */ + qemu_mutex_lock_iothread(); + replication_do_checkpoint_all(&local_err); + qemu_mutex_unlock_iothread(); + if (local_err) { + goto out; + } + colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err); if (local_err) { goto out; @@ -483,6 +505,12 @@ static void colo_process_checkpoint(MigrationState *s) object_unref(OBJECT(bioc)); qemu_mutex_lock_iothread(); + replication_start_all(REPLICATION_MODE_PRIMARY, &local_err); + if (local_err) { + qemu_mutex_unlock_iothread(); + goto out; + } + vm_start(); qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("stop", "run"); @@ -576,6 +604,7 @@ static void colo_wait_handle_message(QEMUFile *f, int *checkpoint_request, case COLO_MESSAGE_GUEST_SHUTDOWN: qemu_mutex_lock_iothread(); vm_stop_force_state(RUN_STATE_COLO); + replication_stop_all(false, NULL); qemu_system_shutdown_request_core(); qemu_mutex_unlock_iothread(); /* @@ -645,6 +674,14 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + qemu_mutex_lock_iothread(); + bdrv_invalidate_cache_all(&local_err); + replication_start_all(REPLICATION_MODE_SECONDARY, &local_err); + qemu_mutex_unlock_iothread(); + if (local_err) { + goto out; + } + colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY, &local_err); if (local_err) { @@ -725,6 +762,18 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + replication_get_error_all(&local_err); + if (local_err) { + qemu_mutex_unlock_iothread(); + goto out; + } + /* discard colo disk buffer */ + replication_do_checkpoint_all(&local_err); + if (local_err) { + qemu_mutex_unlock_iothread(); + goto out; + } + vmstate_loading = false; qemu_mutex_unlock_iothread(); diff --git a/migration/migration.c b/migration/migration.c index 8d735fc..9528713 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1676,7 +1676,11 @@ static void migration_completion(MigrationState *s, int current_active_state, if (!ret) { ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); - if (ret >= 0) { + /* + * Don't mark the image with BDRV_O_INACTIVE flag if + * we will go into COLO stage later. + */ + if (ret >= 0 && !migrate_colo_enabled()) { ret = bdrv_inactivate_all(); } if (ret >= 0) {