From patchwork Tue Dec 15 08:22:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 556850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3341A14030D for ; Tue, 15 Dec 2015 19:37:10 +1100 (AEDT) Received: from localhost ([::1]:35693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8l6Z-0007Yg-VO for incoming@patchwork.ozlabs.org; Tue, 15 Dec 2015 03:37:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8kuu-0003wi-GD for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:25:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8kur-00012I-8F for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:25:04 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:30268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8kuq-00011x-De for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:25:01 -0500 Received: from 172.24.1.48 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BSU23498; Tue, 15 Dec 2015 16:24:51 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Tue, 15 Dec 2015 16:24:41 +0800 From: zhanghailiang To: Date: Tue, 15 Dec 2015 16:22:59 +0800 Message-ID: <1450167779-9960-39-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1450167779-9960-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1450167779-9960-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.0A020202.566FCE53.00CA, 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: 445007b1e711e64389feba7fe4d62ddb X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: lizhijian@cn.fujitsu.com, quintela@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, hongyang.yang@easystack.cn Subject: [Qemu-devel] [PATCH COLO-Frame v12 38/38] COLO: Add block replication into colo process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- migration/colo.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ trace-events | 2 ++ 2 files changed, 62 insertions(+) diff --git a/migration/colo.c b/migration/colo.c index b7a7ad6..d748fb5 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -21,6 +21,7 @@ #include "qapi-event.h" #include "net/filter.h" #include "net/net.h" +#include "block/block_int.h" static bool vmstate_loading; @@ -55,6 +56,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. @@ -72,6 +74,12 @@ static void secondary_vm_do_failover(void) migrate_set_state(&mis->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); + bdrv_stop_replication_all(true, &local_err); + if (local_err) { + error_report_err(local_err); + } + trace_colo_stop_block_replication("failover"); + if (!autostart) { error_report("\"-S\" qemu option will be ignored in secondary side"); /* recover runstate to normal migration finish state */ @@ -107,6 +115,7 @@ static void primary_vm_do_failover(void) { MigrationState *s = migrate_get_current(); int old_state; + Error *local_err = NULL; migrate_set_state(&s->state, MIGRATION_STATUS_COLO, MIGRATION_STATUS_COMPLETED); @@ -134,6 +143,12 @@ static void primary_vm_do_failover(void) qemu_set_default_filters_status(false); /* Flush the residuary buffered packts */ qemu_release_default_filters_packets(); + + bdrv_stop_replication_all(true, &local_err); + if (local_err) { + error_report_err(local_err); + } + trace_colo_stop_block_replication("failover"); } void colo_do_failover(MigrationState *s) @@ -240,6 +255,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s, int colo_shutdown; size_t size; QEMUFile *trans = NULL; + Error *local_err = NULL; ret = colo_put_cmd(s->to_dst_file, COLO_COMMAND_CHECKPOINT_REQUEST); if (ret < 0) { @@ -278,6 +294,16 @@ 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(); + bdrv_do_checkpoint_all(&local_err); + qemu_mutex_unlock_iothread(); + if (local_err) { + error_report_err(local_err); + ret = -1; + goto out; + } + ret = colo_put_cmd(s->to_dst_file, COLO_COMMAND_VMSTATE_SEND); if (ret < 0) { goto out; @@ -324,6 +350,10 @@ static int colo_do_checkpoint_transaction(MigrationState *s, qemu_release_default_filters_packets(); if (colo_shutdown) { + qemu_mutex_lock_iothread(); + bdrv_stop_replication_all(false, NULL); + trace_colo_stop_block_replication("shutdown"); + qemu_mutex_unlock_iothread(); colo_put_cmd(s->to_dst_file, COLO_COMMAND_GUEST_SHUTDOWN); qemu_fflush(s->to_dst_file); colo_shutdown_requested = 0; @@ -378,6 +408,7 @@ static void colo_process_checkpoint(MigrationState *s) QEMUSizedBuffer *buffer = NULL; int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); int ret = 0; + Error *local_err = NULL; failover_init_state(); ret = colo_init_buffer_filters(); @@ -414,6 +445,15 @@ static void colo_process_checkpoint(MigrationState *s) } qemu_mutex_lock_iothread(); + /* start block replication */ + bdrv_start_replication_all(REPLICATION_MODE_PRIMARY, &local_err); + if (local_err) { + qemu_mutex_unlock_iothread(); + error_report_err(local_err); + ret = -EINVAL; + goto out; + } + trace_colo_start_block_replication(); vm_start(); qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("stop", "run"); @@ -506,6 +546,8 @@ static int colo_wait_handle_cmd(QEMUFile *f, int *checkpoint_request) case COLO_COMMAND_GUEST_SHUTDOWN: qemu_mutex_lock_iothread(); vm_stop_force_state(RUN_STATE_COLO); + bdrv_stop_replication_all(false, NULL); + trace_colo_stop_block_replication("shutdown"); qemu_system_shutdown_request_core(); qemu_mutex_unlock_iothread(); /* the main thread will exit and termiante the whole @@ -537,6 +579,7 @@ void *colo_process_incoming_thread(void *opaque) uint64_t total_size; int ret = 0; uint64_t value; + Error *local_err = NULL; migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); @@ -572,6 +615,16 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + qemu_mutex_lock_iothread(); + /* start block replication */ + bdrv_start_replication_all(REPLICATION_MODE_SECONDARY, &local_err); + qemu_mutex_unlock_iothread(); + if (local_err) { + error_report_err(local_err); + goto out; + } + trace_colo_start_block_replication(); + ret = colo_put_cmd(mis->to_src_file, COLO_COMMAND_CHECKPOINT_READY); if (ret < 0) { goto out; @@ -651,6 +704,13 @@ void *colo_process_incoming_thread(void *opaque) qemu_mutex_unlock_iothread(); goto out; } + /* discard colo disk buffer */ + bdrv_do_checkpoint_all(&local_err); + if (local_err) { + vmstate_loading = false; + qemu_mutex_unlock_iothread(); + goto out; + } vmstate_loading = false; qemu_mutex_unlock_iothread(); diff --git a/trace-events b/trace-events index 3992b45..3951689 100644 --- a/trace-events +++ b/trace-events @@ -1584,6 +1584,8 @@ colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" colo_put_cmd(const char *msg) "Send '%s' cmd" colo_get_cmd(const char *msg) "Receive '%s' cmd" colo_failover_set_state(int new_state) "new state %d" +colo_start_block_replication(void) "Block replication is started" +colo_stop_block_replication(const char *reason) "Block replication is stopped(reason: '%s')" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"