From patchwork Wed Sep 2 08:23:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 513382 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 03AB614028F for ; Wed, 2 Sep 2015 18:37:45 +1000 (AEST) Received: from localhost ([::1]:35057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3Y7-0000oC-5w for incoming@patchwork.ozlabs.org; Wed, 02 Sep 2015 04:37:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44088) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3LO-00061A-Aw 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 1ZX3LK-00016k-64 for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:34 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:28277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3LJ-00015j-A6 for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:24:30 -0400 Received: from 172.24.1.51 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.51]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUG54195; Wed, 02 Sep 2015 16:24:20 +0800 (CST) Received: from localhost (10.177.25.63) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Wed, 2 Sep 2015 16:24:09 +0800 From: zhanghailiang To: Date: Wed, 2 Sep 2015 16:23:08 +0800 Message-ID: <1441182199-8328-22-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-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, yanghy@cn.fujitsu.com, zhanghailiang Subject: [Qemu-devel] [PATCH COLO-Frame v9 21/32] COLO: implement default failover treatment 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 If we detect some error in colo, we will wait for some time, hoping users also detect it. If users don't issue failover command. We will go into default failover procedure, which the PVM will takeover work while SVM is exit in default. Signed-off-by: zhanghailiang Signed-off-by: Li Zhijian --- migration/colo.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/migration/colo.c b/migration/colo.c index 141b1c8..9ad285c 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -25,6 +25,14 @@ */ #define CHECKPOINT_MAX_PEROID 200 +/* + * The delay time before qemu begin the procedure of default failover treatment. + * Unit: ms + * Fix me: This value should be able to change by command + * 'migrate-set-parameters' + */ +#define DEFAULT_FAILOVER_DELAY 2000 + static QEMUBH *colo_bh; /* colo buffer */ #define COLO_BUFFER_BASE_SIZE (4 * 1024 * 1024) @@ -277,6 +285,7 @@ static void *colo_thread(void *opaque) MigrationState *s = opaque; QEMUSizedBuffer *buffer = NULL; int64_t current_time, checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); + int64_t error_time; int fd, ret = 0; failover_init_state(); @@ -335,8 +344,25 @@ static void *colo_thread(void *opaque) } out: + current_time = error_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); if (ret < 0) { error_report("Detect some error: %s", strerror(-ret)); + /* Give users time to get involved in this verdict */ + while (current_time - error_time <= DEFAULT_FAILOVER_DELAY) { + if (failover_request_is_active()) { + error_report("Primary VM will take over work"); + break; + } + usleep(100 * 1000); + current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); + } + + qemu_mutex_lock_iothread(); + if (!failover_request_is_active()) { + error_report("Primary VM will take over work in default"); + failover_request_active(NULL); + } + qemu_mutex_unlock_iothread(); } qsb_free(buffer); @@ -414,6 +440,7 @@ void *colo_process_incoming_thread(void *opaque) QEMUFile *fb = NULL; QEMUSizedBuffer *buffer = NULL; /* Cache incoming device state */ int total_size; + int64_t error_time, current_time; int fd, ret = 0; migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, @@ -521,9 +548,28 @@ void *colo_process_incoming_thread(void *opaque) } out: + current_time = error_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); if (ret < 0) { error_report("colo incoming thread will exit, detect error: %s", strerror(-ret)); + /* Give users time to get involved in this verdict */ + while (current_time - error_time <= DEFAULT_FAILOVER_DELAY) { + if (failover_request_is_active()) { + error_report("Secondary VM will take over work"); + break; + } + usleep(100 * 1000); + current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST); + } + /* check flag again*/ + if (!failover_request_is_active()) { + /* + * We assume that Primary VM is still alive according to + * heartbeat, just kill Secondary VM + */ + error_report("SVM is going to exit in default!"); + exit(1); + } } if (fb) {