From patchwork Mon May 14 16:54:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10398975 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 BFF4D601E7 for ; Mon, 14 May 2018 17:12:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE6282838F for ; Mon, 14 May 2018 17:12:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0A6528399; Mon, 14 May 2018 17:12:31 +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 3452F2838F for ; Mon, 14 May 2018 17:12:31 +0000 (UTC) Received: from localhost ([::1]:47358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIH1S-0006sj-E5 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 May 2018 13:12:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIGl4-0008D4-G4 for qemu-devel@nongnu.org; Mon, 14 May 2018 12:55:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIGl3-0005qU-O8 for qemu-devel@nongnu.org; Mon, 14 May 2018 12:55:34 -0400 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:42013) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fIGl3-0005oh-IC for qemu-devel@nongnu.org; Mon, 14 May 2018 12:55:33 -0400 Received: by mail-pg0-x241.google.com with SMTP id p9-v6so5731580pgc.9 for ; Mon, 14 May 2018 09:55:33 -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=c3c1I96ArOBhkzzXNc0WYEI8Zrc5NZ/DICc6d2S57jo=; b=JuJqtQ8+IVbZH1vRvkeC+nHT1bJjdeSOt4yM3PC5uxJQZf+KIhZoZYtAsrjjvBqqaF t1TMKp8NhVQ3KD5/xcPjUVLdvAjDpSy94r/23MNWly2oUzFX/jjCzq8MWX5mQFyWhTy2 fDHTS04p6Zer9va1euYrLNp3xbXMoLjPCvbeNm88F4imJi0riemKp0YBpfVmTRpj82oA Lgg6cgS7pLb7vzvN47/xJdZvQKdiYxIE2YXzqvJmrRL3pJNXNxe45f/eVngAd/ekp5ip g7D5S7IIevz3SuTrEkxA+4MB0v1ohIAnWbdS3JzByEsgkIBd2eHaGHhlOuvVIHlPhfQR U2qw== 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=c3c1I96ArOBhkzzXNc0WYEI8Zrc5NZ/DICc6d2S57jo=; b=g7S6WtLhV5PQE5VtuHn6c1S0YUzrIjGfDnjXCVM7IAX1/H/EakNfUpDtAUkpIrXDiL P1fNCsPcB7lOA7k3WhxONvy+VX7nH7t35WoiS2hZYq1ZcCflTKPCHJ5BdHAfba+VfDu9 RUcQiIgr4cevBpC4dTBefIkXBC9GOagyZ6S7FFp2IHwDMAK4Pfl7lHoUyGkmY565ewTn W+DTxmUad/s/sfZrnre7UFCG1WV13QjPbL9e15M8xRD+9hmICgQmAbMvAP0WB0XK1Mo+ YcEThJdvqAPxaqxNsMKRrzy7ti13ueEnNNZ9iq0FZnZgzUwtpGXhoN0x6JCU4gVGU8/H +YkA== X-Gm-Message-State: ALKqPwfWi2tOBeK0U9Qx1uXAJYv7rLX62ErmvkyrW5TwmBG/C8HQAzQ7 LjIcgNY5USTKqp9jWoPsXVrLcA== X-Google-Smtp-Source: AB8JxZqYTUk8VbETAzmbzcbDYkv9JqGe5bkDhK3rjVRK0vjWt0JpkngxbezYKj5TAQbXPPPidYOxeg== X-Received: by 2002:a65:6604:: with SMTP id w4-v6mr9175411pgv.102.1526316931776; Mon, 14 May 2018 09:55:31 -0700 (PDT) Received: from localhost.localdomain (109.227.199.104.bc.googleusercontent.com. [104.199.227.109]) by smtp.gmail.com with ESMTPSA id u69-v6sm631448pgb.42.2018.05.14.09.55.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 May 2018 09:55:30 -0700 (PDT) From: Zhang Chen To: qemu-devel@nongnu.org Date: Tue, 15 May 2018 00:54:18 +0800 Message-Id: <20180514165424.12884-12-zhangckid@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514165424.12884-1-zhangckid@gmail.com> References: <20180514165424.12884-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 V7 RESEND 11/17] 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: Jason Wang , Markus Armbruster , "Dr . David Alan Gilbert" , Zhang Chen , Paolo Bonzini 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 | 34 ++++++++++++++++++++++++++++++++++ qapi/migration.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/migration/colo.c b/migration/colo.c index 8ca63813c2..cdff0a2490 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,39 @@ void qmp_xen_colo_do_checkpoint(Error **errp) #endif } +COLOStatus *qmp_query_colo_status(Error **errp) +{ + int state; + COLOStatus *s = g_new0(COLOStatus, 1); + + if (get_colo_mode() == COLO_MODE_UNKNOWN) { + error_setg(errp, QERR_FEATURE_DISABLED, "colo"); + s->colo_running = false; + goto out; + } else if (get_colo_mode() == COLO_MODE_PRIMARY) { + state = migrate_get_current()->state; + } else { + state = migration_incoming_get_current()->state; + } + s->colo_running = state == MIGRATION_STATUS_COLO; + +out: + s->mode = get_colo_mode(); + + 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 55dae48089..13589ba948 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1220,3 +1220,36 @@ # Since: 2.9 ## { 'command': 'xen-colo-do-checkpoint' } + +## +# @COLOStatus: +# +# The result format for 'query-colo-status'. +# +# @mode: which COLO mode the VM was in when it exited. +# +# @colo-running: true if COLO is running. +# +# @reason: describes the reason for the COLO exit. +# +# Since: 2.13 +## +{ 'struct': 'COLOStatus', + 'data': { 'mode': 'COLOMode', 'colo-running': '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", "colo-running": true, "reason": "request" } } +# +# Since: 2.13 +## +{ 'command': 'query-colo-status', + 'returns': 'COLOStatus' }