From patchwork Wed Sep 2 08:23:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 513379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id D743014027F for ; Wed, 2 Sep 2015 18:35:17 +1000 (AEST) Received: from localhost ([::1]:35025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3Vk-0005e1-1C for incoming@patchwork.ozlabs.org; Wed, 02 Sep 2015 04:35:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3LN-000605-Ha for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZX3LM-00017J-0B for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:33 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:21287) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3LK-00015n-By for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:31 -0400 Received: from 172.24.1.49 (EHLO SZXEML424-HUB.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BMF54147; Wed, 02 Sep 2015 16:24:12 +0800 (CST) Received: from localhost (10.177.25.63) by SZXEML424-HUB.china.huawei.com (10.82.67.153) with Microsoft SMTP Server id 14.3.235.1; Wed, 2 Sep 2015 16:24:00 +0800 From: zhanghailiang To: Date: Wed, 2 Sep 2015 16:23:04 +0800 Message-ID: <1441182199-8328-18-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1441182199-8328-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1441182199-8328-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.25.63] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.55E6B22E.0057, 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: b196c87e248d8508311d6254c09f7021 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, Markus Armbruster , yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, Luiz Capitulino , arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, yanghy@cn.fujitsu.com, zhanghailiang Subject: [Qemu-devel] [PATCH COLO-Frame v9 17/32] COLO failover: Introduce a new command to trigger a failover 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 We leave users to choose whatever heartbeat solution they want, if the heartbeat is lost, or other errors they detect, they can use command 'colo_lost_heartbeat' to tell COLO to do failover, COLO will do operations accordingly. For example, if the command is sent to the PVM, the Primary side will exit COLO mode and take over operation. If sent to the Secondary, the secondary will run failover work, then take over server operation to become the new Primary. Cc: Luiz Capitulino Cc: Eric Blake Cc: Markus Armbruster Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Signed-off-by: Yang Hongyang --- hmp-commands.hx | 15 +++++++++++++++ hmp.c | 8 ++++++++ hmp.h | 1 + include/migration/colo.h | 4 ++++ include/migration/failover.h | 20 ++++++++++++++++++++ migration/Makefile.objs | 2 +- migration/colo-comm.c | 11 +++++++++++ migration/colo-failover.c | 41 +++++++++++++++++++++++++++++++++++++++++ migration/colo.c | 1 + qapi-schema.json | 26 ++++++++++++++++++++++++++ qmp-commands.hx | 19 +++++++++++++++++++ stubs/migration-colo.c | 8 ++++++++ 12 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 include/migration/failover.h create mode 100644 migration/colo-failover.c diff --git a/hmp-commands.hx b/hmp-commands.hx index e56baec..9065a23 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1034,6 +1034,21 @@ Set the parameter @var{parameter} for migration. ETEXI { + .name = "colo_lost_heartbeat", + .args_type = "", + .params = "", + .help = "Tell COLO that heartbeat is lost,\n\t\t\t" + "a failover or takeover is needed.", + .mhandler.cmd = hmp_colo_lost_heartbeat, + }, + +STEXI +@item colo_lost_heartbeat +@findex colo_lost_heartbeat +Tell COLO that heartbeat is lost, a failover or takeover is needed. +ETEXI + + { .name = "client_migrate_info", .args_type = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?", .params = "protocol hostname port tls-port cert-subject", diff --git a/hmp.c b/hmp.c index 09e3cda..94b0149 100644 --- a/hmp.c +++ b/hmp.c @@ -1273,6 +1273,14 @@ void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +void hmp_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + + qmp_colo_lost_heartbeat(&err); + hmp_handle_error(mon, &err); +} + void hmp_set_password(Monitor *mon, const QDict *qdict) { const char *protocol = qdict_get_str(qdict, "protocol"); diff --git a/hmp.h b/hmp.h index a21dbbb..a90ab65 100644 --- a/hmp.h +++ b/hmp.h @@ -68,6 +68,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict); void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict); void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict); void hmp_client_migrate_info(Monitor *mon, const QDict *qdict); +void hmp_colo_lost_heartbeat(Monitor *mon, const QDict *qdict); void hmp_set_password(Monitor *mon, const QDict *qdict); void hmp_expire_password(Monitor *mon, const QDict *qdict); void hmp_eject(Monitor *mon, const QDict *qdict); diff --git a/include/migration/colo.h b/include/migration/colo.h index 5c43391..21f5c5d 100644 --- a/include/migration/colo.h +++ b/include/migration/colo.h @@ -17,6 +17,7 @@ #include "migration/migration.h" #include "block/coroutine.h" #include "qemu/thread.h" +#include "qemu/main-loop.h" bool colo_supported(void); void colo_info_mig_init(void); @@ -29,6 +30,9 @@ bool migration_incoming_enable_colo(void); void migration_incoming_exit_colo(void); void *colo_process_incoming_thread(void *opaque); bool migration_incoming_in_colo_state(void); + +int get_colo_mode(void); + /* ram cache */ int colo_init_ram_cache(void); void colo_release_ram_cache(void); diff --git a/include/migration/failover.h b/include/migration/failover.h new file mode 100644 index 0000000..1785b52 --- /dev/null +++ b/include/migration/failover.h @@ -0,0 +1,20 @@ +/* + * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) + * (a.k.a. Fault Tolerance or Continuous Replication) + * + * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD. + * Copyright (c) 2015 FUJITSU LIMITED + * Copyright (c) 2015 Intel Corporation + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_FAILOVER_H +#define QEMU_FAILOVER_H + +#include "qemu-common.h" + +void failover_request_active(Error **errp); + +#endif diff --git a/migration/Makefile.objs b/migration/Makefile.objs index cb7bd30..50d8392 100644 --- a/migration/Makefile.objs +++ b/migration/Makefile.objs @@ -1,6 +1,6 @@ common-obj-y += migration.o tcp.o -common-obj-$(CONFIG_COLO) += colo.o common-obj-y += colo-comm.o +common-obj-$(CONFIG_COLO) += colo.o colo-failover.o common-obj-y += vmstate.o common-obj-y += qemu-file.o qemu-file-buf.o qemu-file-unix.o qemu-file-stdio.o common-obj-y += xbzrle.o diff --git a/migration/colo-comm.c b/migration/colo-comm.c index 0808d6c..1b6f690 100644 --- a/migration/colo-comm.c +++ b/migration/colo-comm.c @@ -20,6 +20,17 @@ typedef struct { static COLOInfo colo_info; +int get_colo_mode(void) +{ + if (migration_in_colo_state()) { + return COLO_MODE_PRIMARY; + } else if (migration_incoming_in_colo_state()) { + return COLO_MODE_SECONDARY; + } else { + return COLO_MODE_UNKNOWN; + } +} + static void colo_info_pre_save(void *opaque) { COLOInfo *s = opaque; diff --git a/migration/colo-failover.c b/migration/colo-failover.c new file mode 100644 index 0000000..af068d3 --- /dev/null +++ b/migration/colo-failover.c @@ -0,0 +1,41 @@ +/* + * COarse-grain LOck-stepping Virtual Machines for Non-stop Service (COLO) + * (a.k.a. Fault Tolerance or Continuous Replication) + * + * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO., LTD. + * Copyright (c) 2015 FUJITSU LIMITED + * Copyright (c) 2015 Intel Corporation + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "migration/colo.h" +#include "migration/failover.h" +#include "qmp-commands.h" +#include "qapi/qmp/qerror.h" + +static QEMUBH *failover_bh; + +static void colo_failover_bh(void *opaque) +{ + qemu_bh_delete(failover_bh); + failover_bh = NULL; + /*TODO: Do failover work */ +} + +void failover_request_active(Error **errp) +{ + failover_bh = qemu_bh_new(colo_failover_bh, NULL); + qemu_bh_schedule(failover_bh); +} + +void qmp_colo_lost_heartbeat(Error **errp) +{ + if (get_colo_mode() == COLO_MODE_UNKNOWN) { + error_setg(errp, QERR_FEATURE_DISABLED, "colo"); + return; + } + + failover_request_active(errp); +} diff --git a/migration/colo.c b/migration/colo.c index 07e0c1b..574028a 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -17,6 +17,7 @@ #include "trace.h" #include "qemu/error-report.h" #include "qemu/sockets.h" +#include "migration/failover.h" /* * checkpoint interval: unit ms diff --git a/qapi-schema.json b/qapi-schema.json index 6a3796e..8468552 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -695,6 +695,32 @@ 'vmstate-received', 'vmstate-loaded', 'guest-shutdown', 'ram-steal'] } +## +# @COLOMode +# +# The colo mode +# +# @unknown: unknown mode +# +# @primary: master side +# +# @secondary: slave side +# +# Since: 2.5 +## +{ 'enum': 'COLOMode', + 'data': [ 'unknown', 'primary', 'secondary'] } + +## +# @colo-lost-heartbeat +# +# Tell qemu that heartbeat is lost, request it to do takeover procedures. +# +# Since: 2.5 +## +{ 'command': 'colo-lost-heartbeat' } + +## # @MouseInfo: # # Information about a mouse device. diff --git a/qmp-commands.hx b/qmp-commands.hx index b06c09c..fc8ccbb 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -781,6 +781,25 @@ Example: EQMP { + .name = "colo-lost-heartbeat", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_colo_lost_heartbeat, + }, + +SQMP +colo-lost-heartbeat +-------------------- + +Tell COLO that heartbeat is lost, a failover or takeover is needed. + +Example: + +-> { "execute": "colo-lost-heartbeat" } +<- { "return": {} } + +EQMP + + { .name = "client_migrate_info", .args_type = "protocol:s,hostname:s,port:i?,tls-port:i?,cert-subject:s?", .params = "protocol hostname port tls-port cert-subject", diff --git a/stubs/migration-colo.c b/stubs/migration-colo.c index c49ee1a..41dacaf 100644 --- a/stubs/migration-colo.c +++ b/stubs/migration-colo.c @@ -11,6 +11,7 @@ */ #include "migration/colo.h" +#include "qmp-commands.h" bool colo_supported(void) { @@ -35,3 +36,10 @@ void *colo_process_incoming_thread(void *opaque) { return NULL; } + +void qmp_colo_lost_heartbeat(Error **errp) +{ + error_setg(errp, "COLO is not supported, please rerun configure" + " with --enable-colo option in order to support" + " COLO feature"); +}