From patchwork Mon May 14 03:23:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10396805 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 24809601E7 for ; Mon, 14 May 2018 06:38:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07E792866C for ; Mon, 14 May 2018 06:38:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F07F1287BB; Mon, 14 May 2018 06:38:15 +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 8B0552866C for ; Mon, 14 May 2018 06:38:15 +0000 (UTC) Received: from localhost ([::1]:42969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fI77e-00024B-Ow for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 May 2018 02:38:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fI6WX-0006dK-OR for qemu-devel@nongnu.org; Mon, 14 May 2018 01:59:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fI46i-0000Uc-NS for qemu-devel@nongnu.org; Sun, 13 May 2018 23:25:05 -0400 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]:45501) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fI46i-0000Te-Hm for qemu-devel@nongnu.org; Sun, 13 May 2018 23:25:04 -0400 Received: by mail-pg0-x22a.google.com with SMTP id w3-v6so4844595pgv.12 for ; Sun, 13 May 2018 20:25:04 -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=kOzj4YnKHIPIR9M+mgiQwcTIHh9IZ4z+ZsihpF83qNw=; b=K01uZL1DJtlRTzc874f4cu+oRfXfNi6wWAnt2pfBM7t8ve45nD18q8G1VE+0rwKxgP MxV35+RKCQj+i8yqdRfZMHZaeITAALScNlfCM/FBJsmlBUPM1cnsFscKSfhGBTOywDa8 49uCXFnC166YTaynfFo4fk0HoqLEpxDw2C3uU1HQbjxqPqghTg/9rdS098nA+WaYPYLW 0LWV+eFqx7ytmb1htaNKNa5a1IpBRiSK6A3mzNEkbw0dWNWFSBmyT8PXHTs4/k6pHg4c Qu+CZ0mH+WMtYNOSNuQPi8trX5eK9/L1cP1z4oxj8KhMix7jxMrlu3dius9VwaT2pSvP I/sg== 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=kOzj4YnKHIPIR9M+mgiQwcTIHh9IZ4z+ZsihpF83qNw=; b=fiUtcn8d2R14leIyF2fat/VCN493F/KozbK6Mz6IMoRGmZ97w+E/XNYS/u2heHhR/B xFmk0e2LUQzI+UFV77QwRzc3yewlFWdDmmte2t/2K4S1T8agOOmasn/bFHXMMdMu9D6q nNaUe9CQxIKN9Vt2vuNQLFAVeo94CS9s5b+WE9CcGG/guwiqwbLZFGpuZ2KG791gVSta YJoLB13Nlyn+W5kKCvUpoS+XHaEWn3bVRIVxhSbMHeWUjQp+wXiZOggoEkEniJOSm1gX HnxDVxeP+zz5xyzyMgQaQy3dIKRP5BNDB5OIx+tOfu9F1yROIdl4KmRKCPuklx9NVI02 33TA== X-Gm-Message-State: ALKqPweS799Fh3A47QJDk4TY98VZh3q36Uqip50xG+FKkFS2IOUcmuOP KTdwK9boRqx6sFOSz7n4A0xpvw== X-Google-Smtp-Source: AB8JxZprnPgqJ846ugguJ901NCBdasg2xOVv473s9yQadN1uuxp5wormgggai99FPPiBfBjYQirwZA== X-Received: by 2002:a63:6110:: with SMTP id v16-v6mr6893624pgb.292.1526268303357; Sun, 13 May 2018 20:25:03 -0700 (PDT) Received: from localhost.localdomain (109.227.199.104.bc.googleusercontent.com. [104.199.227.109]) by smtp.gmail.com with ESMTPSA id p6-v6sm17183532pfg.157.2018.05.13.20.24.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 13 May 2018 20:25:02 -0700 (PDT) From: Zhang Chen To: qemu-devel@nongnu.org Date: Mon, 14 May 2018 11:23:42 +0800 Message-Id: <1526268228-27951-12-git-send-email-zhangckid@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526268228-27951-1-git-send-email-zhangckid@gmail.com> References: <1526268228-27951-1-git-send-email-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22a Subject: [Qemu-devel] [PATCH V7 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 8ca6381..314344c 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 55dae48..13589ba 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' }