From patchwork Tue Dec 15 08:22:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 556848 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 2C1CF14018C for ; Tue, 15 Dec 2015 19:35:57 +1100 (AEDT) Received: from localhost ([::1]:35682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8l5O-0005QN-UE for incoming@patchwork.ozlabs.org; Tue, 15 Dec 2015 03:35:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8kuV-0003HE-Vr for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:24:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8kuT-0000xT-80 for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:24:39 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:29868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8kuS-0000wn-HK for qemu-devel@nongnu.org; Tue, 15 Dec 2015 03:24:37 -0500 Received: from 172.24.1.48 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.48]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BSU23424; Tue, 15 Dec 2015 16:24:24 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Tue, 15 Dec 2015 16:24:15 +0800 From: zhanghailiang To: Date: Tue, 15 Dec 2015 16:22:43 +0800 Message-ID: <1450167779-9960-23-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.566FCE39.0087, 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: 3c5e11f7b7f650631dcd31083b9b99ba 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 22/38] COLO failover: Introduce state to record failover 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 When handling failover, we do different things 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 --- v11: - fix several typos found by Dave - Add Reviewed-by tag Signed-off-by: zhanghailiang --- include/migration/failover.h | 10 ++++++++++ migration/colo-failover.c | 37 +++++++++++++++++++++++++++++++++++++ migration/colo.c | 4 ++++ trace-events | 1 + 4 files changed, 52 insertions(+) diff --git a/include/migration/failover.h b/include/migration/failover.h index 1785b52..882c625 100644 --- a/include/migration/failover.h +++ b/include/migration/failover.h @@ -15,6 +15,16 @@ #include "qemu-common.h" +typedef enum COLOFailoverStatus { + FAILOVER_STATUS_NONE = 0, + FAILOVER_STATUS_REQUEST = 1, /* Request but not handled */ + FAILOVER_STATUS_HANDLING = 2, /* In the process of handling failover */ + FAILOVER_STATUS_COMPLETED = 3, /* Finish the failover process */ +} COLOFailoverStatus; + +void failover_init_state(void); +int failover_set_state(int old_state, int new_state); +int failover_get_state(void); void failover_request_active(Error **errp); #endif diff --git a/migration/colo-failover.c b/migration/colo-failover.c index e3897c6..1b1be24 100644 --- a/migration/colo-failover.c +++ b/migration/colo-failover.c @@ -14,22 +14,59 @@ #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 COLOFailoverStatus 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_REQUEST, + FAILOVER_STATUS_HANDLING); + if (old_state != FAILOVER_STATUS_REQUEST) { + error_report("Unkown error for failover, old_state=%d", old_state); + return; + } /*TODO: Do failover work */ } void failover_request_active(Error **errp) { + if (failover_set_state(FAILOVER_STATUS_NONE, FAILOVER_STATUS_REQUEST) + != 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; +} + +int failover_set_state(int old_state, int new_state) +{ + int old; + + old = atomic_cmpxchg(&failover_state, old_state, new_state); + if (old == old_state) { + trace_colo_failover_set_state(new_state); + } + return old; +} + +int 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 7098497..176384e 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -216,6 +216,8 @@ static void colo_process_checkpoint(MigrationState *s) int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); int ret = 0; + 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) { ret = -EINVAL; @@ -324,6 +326,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) { ret = -EINVAL; diff --git a/trace-events b/trace-events index 7f76029..3992b45 100644 --- a/trace-events +++ b/trace-events @@ -1583,6 +1583,7 @@ postcopy_ram_incoming_cleanup_join(void) "" 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" # kvm-all.c kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"