From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzCH-0003oP-IR for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRzCE-0001f9-BU for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:29 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:26819) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzCC-0001eA-9c for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:26 -0500 From: zhanghailiang Date: Sat, 6 Feb 2016 17:28:52 +0800 Message-ID: <1454750932-7556-41-git-send-email-zhang.zhanghailiang@huawei.com> In-Reply-To: <1454750932-7556-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1454750932-7556-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH COLO-Frame v14 40/40] COLO: Add block replication into colo process List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , xiecl.fnst@cn.fujitsu.com, lizhijian@cn.fujitsu.com, quintela@redhat.com, armbru@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, zhanghailiang , arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, zhangchen.fnst@cn.fujitsu.com, Max Reitz , hongyang.yang@easystack.cn 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 --- v14: - Remove the trace call --- migration/colo.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ migration/migration.c | 6 +++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/migration/colo.c b/migration/colo.c index afbb0e1..27d15f3 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -20,6 +20,7 @@ #include "qapi-event.h" #include "net/net.h" #include "net/filter.h" +#include "replication.h" static bool vmstate_loading; @@ -54,6 +55,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. @@ -71,6 +73,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 */ @@ -169,6 +176,11 @@ static void primary_vm_do_failover(void) } qemu_foreach_netfilter(colo_flush_filter_packets, NULL, NULL); + 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_sem); } @@ -328,6 +340,14 @@ static int colo_do_checkpoint_transaction(MigrationState *s, 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_put_cmd(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err); if (local_err) { goto out; @@ -485,6 +505,13 @@ static void colo_process_checkpoint(MigrationState *s) } qemu_mutex_lock_iothread(); + /* start block replication */ + 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"); @@ -580,6 +607,7 @@ static void colo_wait_handle_cmd(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(); /* the main thread will exit and terminate the whole @@ -649,6 +677,14 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + qemu_mutex_lock_iothread(); + /* start block replication */ + replication_start_all(REPLICATION_MODE_SECONDARY, &local_err); + qemu_mutex_unlock_iothread(); + if (local_err) { + goto out; + } + colo_put_cmd(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY, &local_err); if (local_err) { @@ -726,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 5833baf..5a650c6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1597,7 +1597,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 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) { -- 1.8.3.1