From patchwork Wed Jun 27 20:41:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10492659 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 0905F601A0 for ; Wed, 27 Jun 2018 20:58:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D6A42A02F for ; Wed, 27 Jun 2018 20:58:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00DC32A05D; Wed, 27 Jun 2018 20:58:42 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 9143B2A02F for ; Wed, 27 Jun 2018 20:58:42 +0000 (UTC) Received: from localhost ([::1]:33190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYHWT-0007w8-RM for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Jun 2018 16:58:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYHHA-0004Ck-IK for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:42:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYHH9-0006ay-DL for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:42:52 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:42551) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYHH9-0006ab-6k for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:42:51 -0400 Received: by mail-pg0-x241.google.com with SMTP id c10-v6so1423936pgu.9 for ; Wed, 27 Jun 2018 13:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CUHDpejl1Yfbe3KWR9UH3WKXVdZ/Cg9dmENYGdQT85I=; b=Ufo4yhIB2cnCCYyRP3UGWpFg6OgpEhgwC7/yeGDjWPdVLClH5nIbN9kAToeTvfhU6w YEEcuFBW96ejZlKAmjhCnNLHSMfZxagswVUMG3dPfkcUNCWD64twoxv4zLtR7KawIF5F kno4s+AyzmGvaY8ZrxmBVeB/JrnEDBgDBBriXcBRo9atOCBYWt7NjrKbYjs4/xtR+UTG yFxP8cnhWo8yX1N1AS6vlQRNt299li9gHdYQR1gG4Uwaaw30jnmGHni9e19eF/14Q0Bm 5ARpjS/2yJiTf4vHb9zU8RM23R3B/ihXqBWEhu6/SieflKEldsqfCcBrEXyZ0TfFzPfa LcKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CUHDpejl1Yfbe3KWR9UH3WKXVdZ/Cg9dmENYGdQT85I=; b=cIqKg8qMiSHs+Q8fPR0/beA5I5bBXFmMsOfVxRkC4VG3bsKGTwB/3Bd7H74pU6fxvW uPW5iuzneeBKujXzslDIRnalegpe8/O7MpijHbE4/6Q4W5YgX3kZsppYvQwoSqGqCKpE wWYUZpPCknMaAEvt83yP3fd0Z6V67LFZrClLcO94tXcOoSJELY15V1YIi6bPzAXx3Pk6 g3eI6MmtMF+YfrJe4conSJx6R2T/xEQZ99Jg5fYip3KyAdQKE5i6S9N0bFNjVZTV8dZB Oq6SPR/XbKM3vPD1JhD2+I3GvZBBagX7lPj97LSWv8j8RDm/+wjDjsbY01HYppm13YBs /rFA== X-Gm-Message-State: APt69E1l10S6G0yM+hmZoViCqkTQJyg13jni+7iAIT113iWYLjqfT7Vh d6B6FzwCEtxm7scY6viVcV9vCQ== X-Google-Smtp-Source: AAOMgpc65cG28Rnd6bGT0QIpzKoCUw3NITz1mqlB0hef/vWROf3uz1VFhpROaPSztmtj6J82NK/RwA== X-Received: by 2002:a65:4c87:: with SMTP id m7-v6mr6385065pgt.98.1530132170029; Wed, 27 Jun 2018 13:42:50 -0700 (PDT) Received: from localhost.localdomain (155.150.229.35.bc.googleusercontent.com. [35.229.150.155]) by smtp.gmail.com with ESMTPSA id c67-v6sm9690428pfj.173.2018.06.27.13.42.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 13:42:49 -0700 (PDT) From: Zhang Chen To: qemu-devel@nongnu.org, Paolo Bonzini , Juan Quintela , "Dr . David Alan Gilbert" , Jason Wang , Eric Blake , Markus Armbruster Date: Thu, 28 Jun 2018 04:41:28 +0800 Message-Id: <20180627204136.4177-13-zhangckid@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180627204136.4177-1-zhangckid@gmail.com> References: <20180627204136.4177-1-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH V9 12/20] qapi: Add new command to query colo status 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: zhanghailiang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Libvirt or other high level software can use this command query colo status. You can test this command like that: {'execute':'query-colo-status'} Signed-off-by: Zhang Chen --- migration/colo.c | 39 +++++++++++++++++++++++++++++++++++++++ qapi/migration.json | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/migration/colo.c b/migration/colo.c index 8fdb79ac73..eb21978bff 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -29,6 +29,7 @@ #include "net/colo.h" #include "block/block.h" #include "qapi/qapi-events-migration.h" +#include "qapi/qmp/qerror.h" static bool vmstate_loading; static Notifier packets_compare_notifier; @@ -237,6 +238,44 @@ void qmp_xen_colo_do_checkpoint(Error **errp) #endif } +COLOStatus *qmp_query_colo_status(Error **errp) +{ + int state; + COLOStatus *s = g_new0(COLOStatus, 1); + + s->mode = get_colo_mode(); + + switch (s->mode) { + case COLO_MODE_NONE: + error_setg(errp, "COLO is disabled"); + state = MIGRATION_STATUS_NONE; + break; + case COLO_MODE_PRIMARY: + state = migrate_get_current()->state; + break; + case COLO_MODE_SECONDARY: + state = migration_incoming_get_current()->state; + break; + default: + abort(); + } + + s->active = state == MIGRATION_STATUS_COLO; + + switch (failover_get_state()) { + case FAILOVER_STATUS_NONE: + s->reason = COLO_EXIT_REASON_NONE; + break; + case FAILOVER_STATUS_REQUIRE: + s->reason = COLO_EXIT_REASON_REQUEST; + break; + default: + s->reason = COLO_EXIT_REASON_ERROR; + } + + return s; +} + static void colo_send_message(QEMUFile *f, COLOMessage msg, Error **errp) { diff --git a/qapi/migration.json b/qapi/migration.json index c24f114104..73c64686ec 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1248,6 +1248,40 @@ ## { 'command': 'xen-colo-do-checkpoint' } +## +# @COLOStatus: +# +# The result format for 'query-colo-status'. +# +# @mode: COLO running mode. If COLO is running, this field will return +# 'primary' or 'secondary'. +# +# @active: true if COLO is active. +# +# @reason: describes the reason for the COLO exit. +# +# Since: 3.0 +## +{ 'struct': 'COLOStatus', + 'data': { 'mode': 'COLOMode', 'active': 'bool', 'reason': 'COLOExitReason' } } + +## +# @query-colo-status: +# +# Query COLO status while the vm is running. +# +# Returns: A @COLOStatus object showing the status. +# +# Example: +# +# -> { "execute": "query-colo-status" } +# <- { "return": { "mode": "primary", "active": true, "reason": "request" } } +# +# Since: 3.0 +## +{ 'command': 'query-colo-status', + 'returns': 'COLOStatus' } + ## # @migrate-recover: #