From patchwork Thu Sep 29 08:46:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9355963 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 5C3316077A for ; Thu, 29 Sep 2016 08:53:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D54229920 for ; Thu, 29 Sep 2016 08:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41E9329922; Thu, 29 Sep 2016 08:53:32 +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 56DA029920 for ; Thu, 29 Sep 2016 08:53:29 +0000 (UTC) Received: from localhost ([::1]:35663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpX5r-0000v4-Q8 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 29 Sep 2016 04:53:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpX0E-0004Z2-Vu for qemu-devel@nongnu.org; Thu, 29 Sep 2016 04:47:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpX0D-0002xk-Qs for qemu-devel@nongnu.org; Thu, 29 Sep 2016 04:47:38 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:22493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpX0A-0002wf-VW for qemu-devel@nongnu.org; Thu, 29 Sep 2016 04:47:37 -0400 Received: from 172.24.1.47 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.47]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DRU11179; Thu, 29 Sep 2016 16:47:07 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Thu, 29 Sep 2016 16:47:01 +0800 From: zhanghailiang To: , Date: Thu, 29 Sep 2016 16:46:33 +0800 Message-ID: <1475138797-9908-14-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1475138797-9908-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1475138797-9908-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH COLO-Frame (Base) v20 13/17] COLO: Introduce state to record failover 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: xiecl.fnst@cn.fujitsu.com, lizhijian@cn.fujitsu.com, zhangchen.fnst@cn.fujitsu.com, qemu-devel@nongnu.org, dgilbert@redhat.com, zhanghailiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When handling failover, COLO processes differently according to the different stage of failover process, here we introduce a global atomic variable to record the status of failover. We add four failover status to indicate the different stage of failover process. You should use the helpers to get and set the value. Signed-off-by: zhanghailiang Reviewed-by: Dr. David Alan Gilbert --- v20: - Convert 'enum COLOFailoverStatus' to qapi v19: - fix comments v11: - fix several typos found by Dave - Add Reviewed-by tag --- include/migration/failover.h | 5 +++++ migration/colo-failover.c | 41 +++++++++++++++++++++++++++++++++++++++++ migration/colo.c | 4 ++++ migration/trace-events | 1 + qapi-schema.json | 18 ++++++++++++++++++ 5 files changed, 69 insertions(+) diff --git a/include/migration/failover.h b/include/migration/failover.h index 3274735..7e0f36a 100644 --- a/include/migration/failover.h +++ b/include/migration/failover.h @@ -14,7 +14,12 @@ #define QEMU_FAILOVER_H #include "qemu-common.h" +#include "qapi-types.h" +void failover_init_state(void); +FailoverStatus failover_set_state(FailoverStatus old_state, + FailoverStatus new_state); +FailoverStatus failover_get_state(void); void failover_request_active(Error **errp); #endif diff --git a/migration/colo-failover.c b/migration/colo-failover.c index e31fc10..6cca039 100644 --- a/migration/colo-failover.c +++ b/migration/colo-failover.c @@ -15,22 +15,63 @@ #include "migration/failover.h" #include "qmp-commands.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" +#include "trace.h" static QEMUBH *failover_bh; +static FailoverStatus failover_state; static void colo_failover_bh(void *opaque) { + int old_state; + qemu_bh_delete(failover_bh); failover_bh = NULL; + + old_state = failover_set_state(FAILOVER_STATUS_REQUIRE, + FAILOVER_STATUS_ACTIVE); + if (old_state != FAILOVER_STATUS_REQUIRE) { + error_report("Unknown error for failover, old_state = %s", + FailoverStatus_lookup[old_state]); + return; + } + /* TODO: Do failover work */ } void failover_request_active(Error **errp) { + if (failover_set_state(FAILOVER_STATUS_NONE, + FAILOVER_STATUS_REQUIRE) != FAILOVER_STATUS_NONE) { + error_setg(errp, "COLO failover is already actived"); + return; + } failover_bh = qemu_bh_new(colo_failover_bh, NULL); qemu_bh_schedule(failover_bh); } +void failover_init_state(void) +{ + failover_state = FAILOVER_STATUS_NONE; +} + +FailoverStatus failover_set_state(FailoverStatus old_state, + FailoverStatus new_state) +{ + FailoverStatus old; + + old = atomic_cmpxchg(&failover_state, old_state, new_state); + if (old == old_state) { + trace_colo_failover_set_state(FailoverStatus_lookup[new_state]); + } + return old; +} + +FailoverStatus failover_get_state(void) +{ + return atomic_read(&failover_state); +} + void qmp_x_colo_lost_heartbeat(Error **errp) { if (get_colo_mode() == COLO_MODE_UNKNOWN) { diff --git a/migration/colo.c b/migration/colo.c index 31b3029..b94972c 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -232,6 +232,8 @@ static void colo_process_checkpoint(MigrationState *s) Error *local_err = NULL; int ret; + failover_init_state(); + s->rp_state.from_dst_file = qemu_file_get_return_path(s->to_dst_file); if (!s->rp_state.from_dst_file) { error_report("Open QEMUFile from_dst_file failed"); @@ -330,6 +332,8 @@ void *colo_process_incoming_thread(void *opaque) migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_COLO); + failover_init_state(); + mis->to_src_file = qemu_file_get_return_path(mis->from_src_file); if (!mis->to_src_file) { error_report("COLO incoming thread: Open QEMUFile to_src_file failed"); diff --git a/migration/trace-events b/migration/trace-events index f374c8c..94134f7 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -212,3 +212,4 @@ migration_tls_incoming_handshake_complete(void) "" colo_vm_state_change(const char *old, const char *new) "Change '%s' => '%s'" colo_send_message(const char *msg) "Send '%s' message" colo_receive_message(const char *msg) "Receive '%s' message" +colo_failover_set_state(const char *new_state) "new state %s" diff --git a/qapi-schema.json b/qapi-schema.json index 55b59bc..92e49a5 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -856,6 +856,24 @@ 'data': [ 'unknown', 'primary', 'secondary'] } ## +# @FailoverStatus +# +# An enumeration of COLO failover status +# +# @none: no failover has ever happened +# +# @require: got failover requirement but not handled +# +# @active: in the process of doing failover +# +# @completed: finish the process of failover +# +# Since: 2.8 +## +{ 'enum': 'FailoverStatus', + 'data': [ 'none', 'require', 'active', 'completed'] } + +## # @x-colo-lost-heartbeat # # Tell qemu that heartbeat is lost, request it to do takeover procedures.