From patchwork Sun Oct 30 10:47:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 688878 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 3t6Dwn345cz9t1S for ; Sun, 30 Oct 2016 21:57:45 +1100 (AEDT) Received: from localhost ([::1]:57757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0no6-0004p5-Kj for incoming@patchwork.ozlabs.org; Sun, 30 Oct 2016 06:57:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0nef-0005gI-Pi for qemu-devel@nongnu.org; Sun, 30 Oct 2016 06:47:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c0nee-0001Jw-OY for qemu-devel@nongnu.org; Sun, 30 Oct 2016 06:47:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43256) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c0nee-0001Jr-GY for qemu-devel@nongnu.org; Sun, 30 Oct 2016 06:47:56 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCB502D1275; Sun, 30 Oct 2016 10:47:55 +0000 (UTC) Received: from localhost (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9UAlsR0004758; Sun, 30 Oct 2016 06:47:55 -0400 From: Amit Shah To: Peter Maydell Date: Sun, 30 Oct 2016 16:17:06 +0530 Message-Id: <1477824430-1460-15-git-send-email-amit.shah@redhat.com> In-Reply-To: <1477824430-1460-1-git-send-email-amit.shah@redhat.com> References: <1477824430-1460-1-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sun, 30 Oct 2016 10:47:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/18] COLO: Implement the process of failover for primary VM 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: qemu list , zhang.zhanghailiang@huawei.com, "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: zhanghailiang For primary side, if COLO gets failover request from users. To be exact, gets 'x_colo_lost_heartbeat' command. COLO thread will exit the loop while the failover BH does the cleanup work and resumes VM. Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Amit Shah Signed-off-by: Amit Shah --- include/migration/colo.h | 3 +++ include/migration/failover.h | 1 + migration/colo-failover.c | 2 +- migration/colo.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/include/migration/colo.h b/include/migration/colo.h index e9ac2c3..e32eef4 100644 --- a/include/migration/colo.h +++ b/include/migration/colo.h @@ -32,4 +32,7 @@ void *colo_process_incoming_thread(void *opaque); bool migration_incoming_in_colo_state(void); COLOMode get_colo_mode(void); + +/* failover */ +void colo_do_failover(MigrationState *s); #endif diff --git a/include/migration/failover.h b/include/migration/failover.h index 7e0f36a..ad91ef2 100644 --- a/include/migration/failover.h +++ b/include/migration/failover.h @@ -21,5 +21,6 @@ FailoverStatus failover_set_state(FailoverStatus old_state, FailoverStatus new_state); FailoverStatus failover_get_state(void); void failover_request_active(Error **errp); +bool failover_request_is_active(void); #endif diff --git a/migration/colo-failover.c b/migration/colo-failover.c index 6cca039..cc229f5 100644 --- a/migration/colo-failover.c +++ b/migration/colo-failover.c @@ -36,7 +36,7 @@ static void colo_failover_bh(void *opaque) return; } - /* TODO: Do failover work */ + colo_do_failover(NULL); } void failover_request_active(Error **errp) diff --git a/migration/colo.c b/migration/colo.c index 6b32c91..04f7c55 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -41,6 +41,40 @@ bool migration_incoming_in_colo_state(void) return mis && (mis->state == MIGRATION_STATUS_COLO); } +static bool colo_runstate_is_stopped(void) +{ + return runstate_check(RUN_STATE_COLO) || !runstate_is_running(); +} + +static void primary_vm_do_failover(void) +{ + MigrationState *s = migrate_get_current(); + int old_state; + + migrate_set_state(&s->state, MIGRATION_STATUS_COLO, + MIGRATION_STATUS_COMPLETED); + + old_state = failover_set_state(FAILOVER_STATUS_ACTIVE, + FAILOVER_STATUS_COMPLETED); + if (old_state != FAILOVER_STATUS_ACTIVE) { + error_report("Incorrect state (%s) while doing failover for Primary VM", + FailoverStatus_lookup[old_state]); + return; + } +} + +void colo_do_failover(MigrationState *s) +{ + /* Make sure VM stopped while failover happened. */ + if (!colo_runstate_is_stopped()) { + vm_stop_force_state(RUN_STATE_COLO); + } + + if (get_colo_mode() == COLO_MODE_PRIMARY) { + primary_vm_do_failover(); + } +} + static void colo_send_message(QEMUFile *f, COLOMessage msg, Error **errp) { @@ -162,9 +196,20 @@ static int colo_do_checkpoint_transaction(MigrationState *s, bioc->usage = 0; qemu_mutex_lock_iothread(); + if (failover_get_state() != FAILOVER_STATUS_NONE) { + qemu_mutex_unlock_iothread(); + goto out; + } vm_stop_force_state(RUN_STATE_COLO); qemu_mutex_unlock_iothread(); trace_colo_vm_state_change("run", "stop"); + /* + * Failover request bh could be called after vm_stop_force_state(), + * So we need check failover_request_is_active() again. + */ + if (failover_get_state() != FAILOVER_STATUS_NONE) { + goto out; + } /* Disable block migration */ s->params.blk = 0; @@ -259,6 +304,11 @@ static void colo_process_checkpoint(MigrationState *s) trace_colo_vm_state_change("stop", "run"); while (s->state == MIGRATION_STATUS_COLO) { + if (failover_get_state() != FAILOVER_STATUS_NONE) { + error_report("failover request"); + goto out; + } + current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); if (current_time - checkpoint_time < s->parameters.x_checkpoint_delay) {