From nobody Tue Apr 30 01:25:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576686127; cv=none; d=zohomail.com; s=zohoarc; b=RNzORkimtj5XtVijkEnIF6krSASIyKXrJQaPgUSoyRfNCN7SmrSKKOlXayGo/be0oQWW/xIL3UaElZKjgShqjp4xHwanyRgW+4q+PdcM+x0XSGGtoR3wYTWPqgXquZTZWV/yiocd2CEfbkgVU6x4pGQZIs6svR0MwrRO5PMsGvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576686127; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JmhHiMhlijK1C0qJx4w61hjzZS+mRlDR39d3qAiWj6A=; b=a9eFMzO/DIxJzT8VJi3v7HnVyObNfwBf8jPjzM+sz1G9lzgHDiNpMl/q9Xy/LiIVwBkNNAHrH3oKvPPk4l8SlwgTnK7QKtetx1HBGcGAocA1lBSNbAJknUTVTFeCvMI4TCuqIPvoFZihJasWJCyQpQjDAvZKahyFrDhFEZiLqSs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576686127214682.1817990660351; Wed, 18 Dec 2019 08:22:07 -0800 (PST) Received: from localhost ([::1]:56554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc5N-0001gy-GF for importer@patchew.org; Wed, 18 Dec 2019 11:22:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52743) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc3c-0008Ld-UP for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihc3a-00045r-U2 for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:16 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:35200 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihc3a-0003tf-Mm for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:14 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-udeXqxBNPsCpQSIBi-eR_A-1; Wed, 18 Dec 2019 11:20:11 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7E54801E76; Wed, 18 Dec 2019 16:20:10 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-210.ams2.redhat.com [10.36.116.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 782911000325; Wed, 18 Dec 2019 16:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576686012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JmhHiMhlijK1C0qJx4w61hjzZS+mRlDR39d3qAiWj6A=; b=JridDZje8G80ttOjoHSRSbR5lC18dB+B3mI3V/QxJFYGciwgd/pbRv1xURFr8QyUXydu8N jPYjVbjz29IEGXWDUKmy0r2RlHxrrboMpEnWE4Uq+Y95d6R8PmRSSjevYiLmrwSIuYSoQV SomQlDclNVLm3yEHl1CgCno009mL+Ao= From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 1/4] monitor: Move monitor option parsing to monitor/monitor.c Date: Wed, 18 Dec 2019 17:19:49 +0100 Message-Id: <20191218161952.10202-2-kwolf@redhat.com> In-Reply-To: <20191218161952.10202-1-kwolf@redhat.com> References: <20191218161952.10202-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: udeXqxBNPsCpQSIBi-eR_A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Both the system emulators and tools with QMP support (specifically, the planned storage daemon) will need to parse monitor options, so move that code to monitor/monitor.c, which can be linked into binaries that aren't a system emulator. This patch moves the monitor option parsing from vl.c and adds an allow_hmp parameter so that callers can support QMP without HMP. Signed-off-by: Kevin Wolf Reviewed-by: Markus Armbruster --- include/monitor/monitor.h | 4 +++ include/sysemu/sysemu.h | 1 - monitor/monitor.c | 52 +++++++++++++++++++++++++++++++++++++++ vl.c | 45 +-------------------------------- 4 files changed, 57 insertions(+), 45 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index a81eeff5f8..d3e8da36a5 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -3,6 +3,7 @@ =20 #include "block/block.h" #include "qapi/qapi-types-misc.h" +#include "qemu/option.h" #include "qemu/readline.h" =20 extern __thread Monitor *cur_mon; @@ -10,12 +11,15 @@ typedef struct MonitorHMP MonitorHMP; =20 #define QMP_REQ_QUEUE_LEN_MAX 8 =20 +extern QemuOptsList qemu_mon_opts; + bool monitor_cur_is_qmp(void); =20 void monitor_init_globals(void); void monitor_init_globals_core(void); void monitor_init_qmp(Chardev *chr, bool pretty); void monitor_init_hmp(Chardev *chr, bool use_readline); +int monitor_init_opts(QemuOpts *opts, bool allow_hmp, Error **errp); void monitor_cleanup(void); =20 int monitor_suspend(Monitor *mon); diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 80c57fdc4e..bbd02cf941 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -128,7 +128,6 @@ extern QemuOptsList qemu_netdev_opts; extern QemuOptsList qemu_nic_opts; extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_global_opts; -extern QemuOptsList qemu_mon_opts; extern QemuOptsList qemu_semihosting_config_opts; =20 #endif diff --git a/monitor/monitor.c b/monitor/monitor.c index 12898b6448..316b71b928 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -609,6 +609,58 @@ void monitor_init_globals_core(void) NULL); } =20 +int monitor_init_opts(QemuOpts *opts, bool allow_hmp, Error **errp) +{ + Chardev *chr; + bool qmp; + bool pretty =3D false; + const char *chardev; + const char *mode; + + mode =3D qemu_opt_get(opts, "mode"); + if (mode =3D=3D NULL) { + mode =3D allow_hmp ? "readline" : "control"; + } + if (strcmp(mode, "readline") =3D=3D 0) { + qmp =3D false; + } else if (strcmp(mode, "control") =3D=3D 0) { + qmp =3D true; + } else { + error_setg(errp, "unknown monitor mode \"%s\"", mode); + return -1; + } + if (!allow_hmp && !qmp) { + error_setg(errp, "Only QMP is supported"); + return -1; + } + + if (!qmp && qemu_opt_get(opts, "pretty")) { + warn_report("'pretty' is deprecated for HMP monitors, it has no ef= fect " + "and will be removed in future versions"); + } + if (qemu_opt_get_bool(opts, "pretty", 0)) { + pretty =3D true; + } + + chardev =3D qemu_opt_get(opts, "chardev"); + if (!chardev) { + error_report("chardev is required"); + exit(1); + } + chr =3D qemu_chr_find(chardev); + if (chr =3D=3D NULL) { + error_setg(errp, "chardev \"%s\" not found", chardev); + return -1; + } + + if (qmp) { + monitor_init_qmp(chr, pretty); + } else { + monitor_init_hmp(chr, true); + } + return 0; +} + QemuOptsList qemu_mon_opts =3D { .name =3D "mon", .implied_opt_name =3D "chardev", diff --git a/vl.c b/vl.c index 94508300c3..352c68c897 100644 --- a/vl.c +++ b/vl.c @@ -2116,50 +2116,7 @@ static int fsdev_init_func(void *opaque, QemuOpts *o= pts, Error **errp) =20 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) { - Chardev *chr; - bool qmp; - bool pretty =3D false; - const char *chardev; - const char *mode; - - mode =3D qemu_opt_get(opts, "mode"); - if (mode =3D=3D NULL) { - mode =3D "readline"; - } - if (strcmp(mode, "readline") =3D=3D 0) { - qmp =3D false; - } else if (strcmp(mode, "control") =3D=3D 0) { - qmp =3D true; - } else { - error_setg(errp, "unknown monitor mode \"%s\"", mode); - return -1; - } - - if (!qmp && qemu_opt_get(opts, "pretty")) { - warn_report("'pretty' is deprecated for HMP monitors, it has no ef= fect " - "and will be removed in future versions"); - } - if (qemu_opt_get_bool(opts, "pretty", 0)) { - pretty =3D true; - } - - chardev =3D qemu_opt_get(opts, "chardev"); - if (!chardev) { - error_report("chardev is required"); - exit(1); - } - chr =3D qemu_chr_find(chardev); - if (chr =3D=3D NULL) { - error_setg(errp, "chardev \"%s\" not found", chardev); - return -1; - } - - if (qmp) { - monitor_init_qmp(chr, pretty); - } else { - monitor_init_hmp(chr, true); - } - return 0; + return monitor_init_opts(opts, true, errp); } =20 static void monitor_parse(const char *optarg, const char *mode, bool prett= y) --=20 2.20.1 From nobody Tue Apr 30 01:25:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576686137; cv=none; d=zohomail.com; s=zohoarc; b=I2AFr7pEe3QcS1qa6YFGVCxA/ZjoCFtsP1Gm+3YrnDvzSKKBSOA0bH2b8H2IY19dBvaTesYl4tXpj1R6ejIMZJ4nV64de5TEIFMbvQgcHpNSJdRM1cDvmrsHoBEdVcmAO7HVAT3HCE8QgobjK/TTzDQ9Z9o4Klc2FRlpA2zmq+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576686137; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uPjj6EutW3nLYKkJl8DjYSWzp/jmlPpLldnjtJ9NRpo=; b=mvq/epp/FHOA1cnP+eWJ/FiPPO3FfP8QK/zwMFFJKahbg6WKNBw7ysDB+kWwMXxrWq8kws6c8UshS55IKNmpEsROw8JVM5YEyp5Yo4TbvE8hgw77hp4I/d+WfLUVeCOWrK3QEF3eo8K1UUR1hQfeT7zf+/xdBaGxsE0P3NPwvAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576686137878691.4046798245699; Wed, 18 Dec 2019 08:22:17 -0800 (PST) Received: from localhost ([::1]:56600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc5X-00020c-U3 for importer@patchew.org; Wed, 18 Dec 2019 11:22:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53175) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc3i-00005R-Df for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihc3f-0004PB-9c for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:22 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:31653 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihc3e-0004Kz-NF for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-137-f8lHx1R7P0iFvm9tMoyK9g-1; Wed, 18 Dec 2019 11:20:14 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8042280257D; Wed, 18 Dec 2019 16:20:13 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-210.ams2.redhat.com [10.36.116.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 094701000322; Wed, 18 Dec 2019 16:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576686017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uPjj6EutW3nLYKkJl8DjYSWzp/jmlPpLldnjtJ9NRpo=; b=NUxZoYG4YKGY2m71A7F2ubjaVjk/FLm0rjHajLPERPK445lh7kslif+uCCoANdoZWb8/Lf Afu82q8bKdUfZdn2KmSDBghX8GeM72ORuH+qlnXNdqBwnwzy4Q2Cf8oSbaF0a9cKqSbc05 qxLLNQ9flFCSEldQfWAc1xtaJgBD7SA= From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 2/4] qapi: Create module 'monitor' Date: Wed, 18 Dec 2019 17:19:50 +0100 Message-Id: <20191218161952.10202-3-kwolf@redhat.com> In-Reply-To: <20191218161952.10202-1-kwolf@redhat.com> References: <20191218161952.10202-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: f8lHx1R7P0iFvm9tMoyK9g-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" misc.json contains definitions that are related to the system emulator, so it can't be used for the storage daemon. This patch moves basic functionality that is related to the monitor itself into a new monitor.json, which could be used in tools as well. Signed-off-by: Kevin Wolf --- qapi/misc.json | 212 ------------------------------------ qapi/monitor.json | 218 +++++++++++++++++++++++++++++++++++++ qapi/qapi-schema.json | 1 + monitor/monitor-internal.h | 1 + monitor/hmp-cmds.c | 1 + monitor/qmp-cmds.c | 1 + monitor/qmp.c | 2 +- tests/qmp-test.c | 2 +- ui/gtk.c | 1 + qapi/Makefile.objs | 4 +- 10 files changed, 227 insertions(+), 216 deletions(-) create mode 100644 qapi/monitor.json diff --git a/qapi/misc.json b/qapi/misc.json index 33b94e3589..cf656e9d4b 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -7,159 +7,6 @@ =20 { 'include': 'common.json' } =20 -## -# @qmp_capabilities: -# -# Enable QMP capabilities. -# -# Arguments: -# -# @enable: An optional list of QMPCapability values to enable. The -# client must not enable any capability that is not -# mentioned in the QMP greeting message. If the field is not -# provided, it means no QMP capabilities will be enabled. -# (since 2.12) -# -# Example: -# -# -> { "execute": "qmp_capabilities", -# "arguments": { "enable": [ "oob" ] } } -# <- { "return": {} } -# -# Notes: This command is valid exactly when first connecting: it must be -# issued before any other command will be accepted, and will fail once the -# monitor is accepting other commands. (see qemu docs/interop/qmp-spec.txt) -# -# The QMP client needs to explicitly enable QMP capabilities, otherwise -# all the QMP capabilities will be turned off by default. -# -# Since: 0.13 -# -## -{ 'command': 'qmp_capabilities', - 'data': { '*enable': [ 'QMPCapability' ] }, - 'allow-preconfig': true } - -## -# @QMPCapability: -# -# Enumeration of capabilities to be advertised during initial client -# connection, used for agreeing on particular QMP extension behaviors. -# -# @oob: QMP ability to support out-of-band requests. -# (Please refer to qmp-spec.txt for more information on OOB) -# -# Since: 2.12 -# -## -{ 'enum': 'QMPCapability', - 'data': [ 'oob' ] } - -## -# @VersionTriple: -# -# A three-part version number. -# -# @major: The major version number. -# -# @minor: The minor version number. -# -# @micro: The micro version number. -# -# Since: 2.4 -## -{ 'struct': 'VersionTriple', - 'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} } - - -## -# @VersionInfo: -# -# A description of QEMU's version. -# -# @qemu: The version of QEMU. By current convention, a micro -# version of 50 signifies a development branch. A micro ver= sion -# greater than or equal to 90 signifies a release candidate = for -# the next minor version. A micro version of less than 50 -# signifies a stable release. -# -# @package: QEMU will always set this field to an empty string. Downs= tream -# versions of QEMU should set this to a non-empty string. T= he -# exact format depends on the downstream however it highly -# recommended that a unique name is used. -# -# Since: 0.14.0 -## -{ 'struct': 'VersionInfo', - 'data': {'qemu': 'VersionTriple', 'package': 'str'} } - -## -# @query-version: -# -# Returns the current version of QEMU. -# -# Returns: A @VersionInfo object describing the current version of QEMU. -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "query-version" } -# <- { -# "return":{ -# "qemu":{ -# "major":0, -# "minor":11, -# "micro":5 -# }, -# "package":"" -# } -# } -# -## -{ 'command': 'query-version', 'returns': 'VersionInfo', - 'allow-preconfig': true } - -## -# @CommandInfo: -# -# Information about a QMP command -# -# @name: The command name -# -# Since: 0.14.0 -## -{ 'struct': 'CommandInfo', 'data': {'name': 'str'} } - -## -# @query-commands: -# -# Return a list of supported QMP commands by this server -# -# Returns: A list of @CommandInfo for all supported commands -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "query-commands" } -# <- { -# "return":[ -# { -# "name":"query-balloon" -# }, -# { -# "name":"system_powerdown" -# } -# ] -# } -# -# Note: This example has been shortened as the real response is too long. -# -## -{ 'command': 'query-commands', 'returns': ['CommandInfo'], - 'allow-preconfig': true } - ## # @LostTickPolicy: # @@ -300,48 +147,6 @@ ## { 'command': 'query-uuid', 'returns': 'UuidInfo', 'allow-preconfig': true } =20 -## -# @EventInfo: -# -# Information about a QMP event -# -# @name: The event name -# -# Since: 1.2.0 -## -{ 'struct': 'EventInfo', 'data': {'name': 'str'} } - -## -# @query-events: -# -# Return information on QMP events. -# -# Returns: A list of @EventInfo. -# -# Since: 1.2.0 -# -# Note: This command is deprecated, because its output doesn't reflect -# compile-time configuration. Use query-qmp-schema instead. -# -# Example: -# -# -> { "execute": "query-events" } -# <- { -# "return": [ -# { -# "name":"SHUTDOWN" -# }, -# { -# "name":"RESET" -# } -# ] -# } -# -# Note: This example has been shortened as the real response is too long. -# -## -{ 'command': 'query-events', 'returns': ['EventInfo'] } - ## # @IOThreadInfo: # @@ -764,23 +569,6 @@ ## { 'command': 'query-pci', 'returns': ['PciInfo'] } =20 -## -# @quit: -# -# This command will cause the QEMU process to exit gracefully. While every -# attempt is made to send the QMP response before terminating, this is not -# guaranteed. When using this interface, a premature EOF would not be -# unexpected. -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "quit" } -# <- { "return": {} } -## -{ 'command': 'quit' } - ## # @stop: # diff --git a/qapi/monitor.json b/qapi/monitor.json new file mode 100644 index 0000000000..a82a18da1a --- /dev/null +++ b/qapi/monitor.json @@ -0,0 +1,218 @@ +# -*- Mode: Python -*- +# + +## +# =3D Monitor definitions (shared between system emulator and tools) +## + +## +# @qmp_capabilities: +# +# Enable QMP capabilities. +# +# Arguments: +# +# @enable: An optional list of QMPCapability values to enable. The +# client must not enable any capability that is not +# mentioned in the QMP greeting message. If the field is not +# provided, it means no QMP capabilities will be enabled. +# (since 2.12) +# +# Example: +# +# -> { "execute": "qmp_capabilities", +# "arguments": { "enable": [ "oob" ] } } +# <- { "return": {} } +# +# Notes: This command is valid exactly when first connecting: it must be +# issued before any other command will be accepted, and will fail once the +# monitor is accepting other commands. (see qemu docs/interop/qmp-spec.txt) +# +# The QMP client needs to explicitly enable QMP capabilities, otherwise +# all the QMP capabilities will be turned off by default. +# +# Since: 0.13 +# +## +{ 'command': 'qmp_capabilities', + 'data': { '*enable': [ 'QMPCapability' ] }, + 'allow-preconfig': true } + +## +# @QMPCapability: +# +# Enumeration of capabilities to be advertised during initial client +# connection, used for agreeing on particular QMP extension behaviors. +# +# @oob: QMP ability to support out-of-band requests. +# (Please refer to qmp-spec.txt for more information on OOB) +# +# Since: 2.12 +# +## +{ 'enum': 'QMPCapability', + 'data': [ 'oob' ] } + +## +# @VersionTriple: +# +# A three-part version number. +# +# @major: The major version number. +# +# @minor: The minor version number. +# +# @micro: The micro version number. +# +# Since: 2.4 +## +{ 'struct': 'VersionTriple', + 'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} } + + +## +# @VersionInfo: +# +# A description of QEMU's version. +# +# @qemu: The version of QEMU. By current convention, a micro +# version of 50 signifies a development branch. A micro ver= sion +# greater than or equal to 90 signifies a release candidate = for +# the next minor version. A micro version of less than 50 +# signifies a stable release. +# +# @package: QEMU will always set this field to an empty string. Downs= tream +# versions of QEMU should set this to a non-empty string. T= he +# exact format depends on the downstream however it highly +# recommended that a unique name is used. +# +# Since: 0.14.0 +## +{ 'struct': 'VersionInfo', + 'data': {'qemu': 'VersionTriple', 'package': 'str'} } + +## +# @query-version: +# +# Returns the current version of QEMU. +# +# Returns: A @VersionInfo object describing the current version of QEMU. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-version" } +# <- { +# "return":{ +# "qemu":{ +# "major":0, +# "minor":11, +# "micro":5 +# }, +# "package":"" +# } +# } +# +## +{ 'command': 'query-version', 'returns': 'VersionInfo', + 'allow-preconfig': true } + +## +# @CommandInfo: +# +# Information about a QMP command +# +# @name: The command name +# +# Since: 0.14.0 +## +{ 'struct': 'CommandInfo', 'data': {'name': 'str'} } + +## +# @query-commands: +# +# Return a list of supported QMP commands by this server +# +# Returns: A list of @CommandInfo for all supported commands +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-commands" } +# <- { +# "return":[ +# { +# "name":"query-balloon" +# }, +# { +# "name":"system_powerdown" +# } +# ] +# } +# +# Note: This example has been shortened as the real response is too long. +# +## +{ 'command': 'query-commands', 'returns': ['CommandInfo'], + 'allow-preconfig': true } + +## +# @EventInfo: +# +# Information about a QMP event +# +# @name: The event name +# +# Since: 1.2.0 +## +{ 'struct': 'EventInfo', 'data': {'name': 'str'} } + +## +# @query-events: +# +# Return information on QMP events. +# +# Returns: A list of @EventInfo. +# +# Since: 1.2.0 +# +# Note: This command is deprecated, because its output doesn't reflect +# compile-time configuration. Use query-qmp-schema instead. +# +# Example: +# +# -> { "execute": "query-events" } +# <- { +# "return": [ +# { +# "name":"SHUTDOWN" +# }, +# { +# "name":"RESET" +# } +# ] +# } +# +# Note: This example has been shortened as the real response is too long. +# +## +{ 'command': 'query-events', 'returns': ['EventInfo'] } + +## +# @quit: +# +# This command will cause the QEMU process to exit gracefully. While every +# attempt is made to send the QMP response before terminating, this is not +# guaranteed. When using this interface, a premature EOF would not be +# unexpected. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "quit" } +# <- { "return": {} } +## +{ 'command': 'quit' } diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 9751b11f8f..be90422ffe 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -103,6 +103,7 @@ { 'include': 'qdev.json' } { 'include': 'machine.json' } { 'include': 'machine-target.json' } +{ 'include': 'monitor.json' } { 'include': 'misc.json' } { 'include': 'misc-target.json' } { 'include': 'audio.json' } diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index d78f5ca190..451aa64c1a 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -27,6 +27,7 @@ =20 #include "chardev/char-fe.h" #include "monitor/monitor.h" +#include "qapi/qapi-types-monitor.h" #include "qapi/qmp/dispatch.h" #include "qapi/qmp/json-parser.h" #include "qemu/readline.h" diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index b2551c16d1..e858fcfc49 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -33,6 +33,7 @@ #include "qapi/qapi-commands-char.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qapi/qapi-commands-net.h" #include "qapi/qapi-commands-rocker.h" #include "qapi/qapi-commands-run-state.h" diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 0880341a2d..b40a9b74de 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -34,6 +34,7 @@ #include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qapi/qapi-commands-ui.h" #include "qapi/qmp/qerror.h" #include "hw/mem/memory-device.h" diff --git a/monitor/qmp.c b/monitor/qmp.c index b67a8e7d1f..711e5d7a40 100644 --- a/monitor/qmp.c +++ b/monitor/qmp.c @@ -27,7 +27,7 @@ #include "chardev/char-io.h" #include "monitor-internal.h" #include "qapi/error.h" -#include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qjson.h" #include "qapi/qmp/qlist.h" diff --git a/tests/qmp-test.c b/tests/qmp-test.c index 1b0eb69832..7fc646ffc2 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -13,7 +13,7 @@ #include "qemu/osdep.h" #include "libqtest.h" #include "qapi/error.h" -#include "qapi/qapi-visit-misc.h" +#include "qapi/qapi-visit-monitor.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qlist.h" #include "qapi/qobject-input-visitor.h" diff --git a/ui/gtk.c b/ui/gtk.c index 692ccc7bbb..7f4d28b5fd 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -33,6 +33,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qapi/qapi-commands-misc.h" +#include "qapi/qapi-commands-monitor.h" #include "qemu/cutils.h" =20 #include "ui/console.h" diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index dd3f5e6f94..519b6f1a8e 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -6,8 +6,8 @@ util-obj-y +=3D qmp-event.o util-obj-y +=3D qapi-util.o =20 QAPI_COMMON_MODULES =3D audio authz block-core block char common crypto -QAPI_COMMON_MODULES +=3D dump error introspect job machine migration misc = net -QAPI_COMMON_MODULES +=3D qdev qom rdma rocker run-state sockets tpm +QAPI_COMMON_MODULES +=3D dump error introspect job machine migration misc = monitor +QAPI_COMMON_MODULES +=3D net qdev qom rdma rocker run-state sockets tpm QAPI_COMMON_MODULES +=3D trace transaction ui QAPI_TARGET_MODULES =3D machine-target misc-target QAPI_MODULES =3D $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES) --=20 2.20.1 From nobody Tue Apr 30 01:25:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576686275; cv=none; d=zohomail.com; s=zohoarc; b=m8AlqMhb0v+gLkDULoWvXRM0PBKYhZ/hYzFB8uwdeEFAuSc36NoBmU6Pyj3X7s26tT6ulfuxnZP3KMRBjD69BD9vNDXv5A9CeDinwYklUhjw6K1xya4cp2tl/skaou50KjQk7FVegFBxX0BPjI1Rp61asttG8FhSZX4fHGoPcKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576686275; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XC3DU+xE03xpzFSp+47bIvCQuItfIoSo7gEoBX5A53A=; b=W+Kcw0JYeswj1kEB/v8tWE0MmErqo4CbLrFOwB0JQ1Xv/b54JuicQJGD8SN+XO7HJMN1gxcf+5oK2++rol6nQyPUEHSIFG9TrK8OVudH7PnFDWPvL17XMbG0/WJfh/rDEDg1JRJl0iIITe7n01MmfS2jsyEZ6W3p4B75LJD9pQo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576686275018338.3835197192652; Wed, 18 Dec 2019 08:24:35 -0800 (PST) Received: from localhost ([::1]:56760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc7l-0005gl-Lo for importer@patchew.org; Wed, 18 Dec 2019 11:24:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53209) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc3i-000060-Mu for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihc3g-0004Ss-Di for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:22 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:22459 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihc3g-0004Ok-4I for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:20 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-93n6aiyqPKuq-UvQfxLaHg-1; Wed, 18 Dec 2019 11:20:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D69F718B5FC2; Wed, 18 Dec 2019 16:20:14 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-210.ams2.redhat.com [10.36.116.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB4021000322; Wed, 18 Dec 2019 16:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576686019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XC3DU+xE03xpzFSp+47bIvCQuItfIoSo7gEoBX5A53A=; b=Hrk2k/SHkFZSpHExORXMtfrvhjGu6yjkcoo+qcBkWjk7XXkQzgAJ60n9zZ2a2bnvFJdVuo C2zIL8+4TgPOl9VKSEIgdbHdedccxuXgNkRZ0UOyCWMlxb2QagDIdfiJDK3CjAsgdb8vlh i3ebZKWzk6K8Zpl04xt4OroqacIA5Uo= From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 3/4] monitor: Create monitor/qmp-cmds-monitor.c Date: Wed, 18 Dec 2019 17:19:51 +0100 Message-Id: <20191218161952.10202-4-kwolf@redhat.com> In-Reply-To: <20191218161952.10202-1-kwolf@redhat.com> References: <20191218161952.10202-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 93n6aiyqPKuq-UvQfxLaHg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Move all of the QMP commands handlers to implement the 'monitor' module (qapi/monitor.json) that can be shared between the system emulator and tools such as a storage daemon to a new file monitor/qmp-cmds-monitor.c. Signed-off-by: Kevin Wolf --- monitor/misc.c | 110 -------------------------- monitor/qmp-cmds-monitor.c | 153 +++++++++++++++++++++++++++++++++++++ monitor/qmp-cmds.c | 14 ---- monitor/Makefile.objs | 3 +- 4 files changed, 155 insertions(+), 125 deletions(-) create mode 100644 monitor/qmp-cmds-monitor.c diff --git a/monitor/misc.c b/monitor/misc.c index 3baa15f3bf..c647ba6313 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -67,7 +67,6 @@ #include "qemu/thread.h" #include "block/qapi.h" #include "qapi/qapi-commands.h" -#include "qapi/qapi-emit-events.h" #include "qapi/error.h" #include "qapi/qmp-event.h" #include "qapi/qapi-introspect.h" @@ -230,58 +229,6 @@ static void hmp_info_help(Monitor *mon, const QDict *q= dict) help_cmd(mon, "info"); } =20 -static void query_commands_cb(QmpCommand *cmd, void *opaque) -{ - CommandInfoList *info, **list =3D opaque; - - if (!cmd->enabled) { - return; - } - - info =3D g_malloc0(sizeof(*info)); - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->name =3D g_strdup(cmd->name); - info->next =3D *list; - *list =3D info; -} - -CommandInfoList *qmp_query_commands(Error **errp) -{ - CommandInfoList *list =3D NULL; - MonitorQMP *mon; - - assert(monitor_is_qmp(cur_mon)); - mon =3D container_of(cur_mon, MonitorQMP, common); - - qmp_for_each_command(mon->commands, query_commands_cb, &list); - - return list; -} - -EventInfoList *qmp_query_events(Error **errp) -{ - /* - * TODO This deprecated command is the only user of - * QAPIEvent_str() and QAPIEvent_lookup[]. When the command goes, - * they should go, too. - */ - EventInfoList *info, *ev_list =3D NULL; - QAPIEvent e; - - for (e =3D 0 ; e < QAPI_EVENT__MAX ; e++) { - const char *event_name =3D QAPIEvent_str(e); - assert(event_name !=3D NULL); - info =3D g_malloc0(sizeof(*info)); - info->value =3D g_malloc0(sizeof(*info->value)); - info->value->name =3D g_strdup(event_name); - - info->next =3D ev_list; - ev_list =3D info; - } - - return ev_list; -} - /* * Minor hack: generated marshalling suppressed for this command * ('gen': false in the schema) so we can parse the JSON string @@ -320,63 +267,6 @@ static void monitor_init_qmp_commands(void) qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG= ); } =20 -/* - * Accept QMP capabilities in @list for @mon. - * On success, set mon->qmp.capab[], and return true. - * On error, set @errp, and return false. - */ -static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list, - Error **errp) -{ - GString *unavailable =3D NULL; - bool capab[QMP_CAPABILITY__MAX]; - - memset(capab, 0, sizeof(capab)); - - for (; list; list =3D list->next) { - if (!mon->capab_offered[list->value]) { - if (!unavailable) { - unavailable =3D g_string_new(QMPCapability_str(list->value= )); - } else { - g_string_append_printf(unavailable, ", %s", - QMPCapability_str(list->value)); - } - } - capab[list->value] =3D true; - } - - if (unavailable) { - error_setg(errp, "Capability %s not available", unavailable->str); - g_string_free(unavailable, true); - return false; - } - - memcpy(mon->capab, capab, sizeof(capab)); - return true; -} - -void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, - Error **errp) -{ - MonitorQMP *mon; - - assert(monitor_is_qmp(cur_mon)); - mon =3D container_of(cur_mon, MonitorQMP, common); - - if (mon->commands =3D=3D &qmp_commands) { - error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, - "Capabilities negotiation is already complete, command " - "ignored"); - return; - } - - if (!qmp_caps_accept(mon, enable, errp)) { - return; - } - - mon->commands =3D &qmp_commands; -} - /* Set the current CPU defined by the user. Callers must hold BQL. */ int monitor_set_cpu(int cpu_index) { diff --git a/monitor/qmp-cmds-monitor.c b/monitor/qmp-cmds-monitor.c new file mode 100644 index 0000000000..acebfd3716 --- /dev/null +++ b/monitor/qmp-cmds-monitor.c @@ -0,0 +1,153 @@ +/* + * QMP commands related to the monitor (common functions for sysemu and to= ols) + * + * Copyright (c) 2003-2004 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" + +#include "monitor-internal.h" +#include "qemu-version.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-monitor.h" +#include "qapi/qapi-emit-events.h" + +/* + * Accept QMP capabilities in @list for @mon. + * On success, set mon->qmp.capab[], and return true. + * On error, set @errp, and return false. + */ +static bool qmp_caps_accept(MonitorQMP *mon, QMPCapabilityList *list, + Error **errp) +{ + GString *unavailable =3D NULL; + bool capab[QMP_CAPABILITY__MAX]; + + memset(capab, 0, sizeof(capab)); + + for (; list; list =3D list->next) { + if (!mon->capab_offered[list->value]) { + if (!unavailable) { + unavailable =3D g_string_new(QMPCapability_str(list->value= )); + } else { + g_string_append_printf(unavailable, ", %s", + QMPCapability_str(list->value)); + } + } + capab[list->value] =3D true; + } + + if (unavailable) { + error_setg(errp, "Capability %s not available", unavailable->str); + g_string_free(unavailable, true); + return false; + } + + memcpy(mon->capab, capab, sizeof(capab)); + return true; +} + +void qmp_qmp_capabilities(bool has_enable, QMPCapabilityList *enable, + Error **errp) +{ + MonitorQMP *mon; + + assert(monitor_is_qmp(cur_mon)); + mon =3D container_of(cur_mon, MonitorQMP, common); + + if (mon->commands =3D=3D &qmp_commands) { + error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND, + "Capabilities negotiation is already complete, command " + "ignored"); + return; + } + + if (!qmp_caps_accept(mon, enable, errp)) { + return; + } + + mon->commands =3D &qmp_commands; +} + +VersionInfo *qmp_query_version(Error **errp) +{ + VersionInfo *info =3D g_new0(VersionInfo, 1); + + info->qemu =3D g_new0(VersionTriple, 1); + info->qemu->major =3D QEMU_VERSION_MAJOR; + info->qemu->minor =3D QEMU_VERSION_MINOR; + info->qemu->micro =3D QEMU_VERSION_MICRO; + info->package =3D g_strdup(QEMU_PKGVERSION); + + return info; +} + +static void query_commands_cb(QmpCommand *cmd, void *opaque) +{ + CommandInfoList *info, **list =3D opaque; + + if (!cmd->enabled) { + return; + } + + info =3D g_malloc0(sizeof(*info)); + info->value =3D g_malloc0(sizeof(*info->value)); + info->value->name =3D g_strdup(cmd->name); + info->next =3D *list; + *list =3D info; +} + +CommandInfoList *qmp_query_commands(Error **errp) +{ + CommandInfoList *list =3D NULL; + MonitorQMP *mon; + + assert(monitor_is_qmp(cur_mon)); + mon =3D container_of(cur_mon, MonitorQMP, common); + + qmp_for_each_command(mon->commands, query_commands_cb, &list); + + return list; +} + +EventInfoList *qmp_query_events(Error **errp) +{ + /* + * TODO This deprecated command is the only user of + * QAPIEvent_str() and QAPIEvent_lookup[]. When the command goes, + * they should go, too. + */ + EventInfoList *info, *ev_list =3D NULL; + QAPIEvent e; + + for (e =3D 0 ; e < QAPI_EVENT__MAX ; e++) { + const char *event_name =3D QAPIEvent_str(e); + assert(event_name !=3D NULL); + info =3D g_malloc0(sizeof(*info)); + info->value =3D g_malloc0(sizeof(*info->value)); + info->value->name =3D g_strdup(event_name); + + info->next =3D ev_list; + ev_list =3D info; + } + + return ev_list; +} diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index b40a9b74de..22a3375194 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -15,7 +15,6 @@ =20 #include "qemu/osdep.h" #include "qemu-common.h" -#include "qemu-version.h" #include "qemu/cutils.h" #include "qemu/option.h" #include "monitor/monitor.h" @@ -52,19 +51,6 @@ NameInfo *qmp_query_name(Error **errp) return info; } =20 -VersionInfo *qmp_query_version(Error **errp) -{ - VersionInfo *info =3D g_new0(VersionInfo, 1); - - info->qemu =3D g_new0(VersionTriple, 1); - info->qemu->major =3D QEMU_VERSION_MAJOR; - info->qemu->minor =3D QEMU_VERSION_MINOR; - info->qemu->micro =3D QEMU_VERSION_MICRO; - info->package =3D g_strdup(QEMU_PKGVERSION); - - return info; -} - KvmInfo *qmp_query_kvm(Error **errp) { KvmInfo *info =3D g_malloc0(sizeof(*info)); diff --git a/monitor/Makefile.objs b/monitor/Makefile.objs index e91a8581cd..15eb6380c5 100644 --- a/monitor/Makefile.objs +++ b/monitor/Makefile.objs @@ -1,3 +1,4 @@ obj-y +=3D misc.o common-obj-y +=3D monitor.o qmp.o hmp.o -common-obj-y +=3D qmp-cmds.o hmp-cmds.o +common-obj-y +=3D qmp-cmds.o qmp-cmds-monitor.o +common-obj-y +=3D hmp-cmds.o --=20 2.20.1 From nobody Tue Apr 30 01:25:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1576686209; cv=none; d=zohomail.com; s=zohoarc; b=KTpz50cZGg3o16S4K/IOw0g9eF8KnMVX/N88UdH8HKejQlWtJZghsIUfXA7/MNHL0WKTETGGiwy/n4PlSP1JSFhJmKpxqyKnZKE4Vs0vASbEqboI5GsvXjmqZlnG2WR7TozLYRPfHnDDbXNvOM0l4LeYgSrybczCw1M6AJcF9TY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576686209; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KNe1IMjIGmXeuqdnaC4u1N+/tCWcwT0DPZLrMAIe5Lo=; b=klF/BB9PV90a9m6zMo7Ljc+L5zXK8uvfxUd6zKvxG3dbXgVmySiB1H6NV7D3LqQ5M2FUoHTqff7BCgMmCzmEmFJI/Ee/vNT7CvhrnkXkdu7KzV/enasz9uhcAuzBo5dZikoSp2RIKZcaDkrqI/blQVevzQBZbIKAJFsjblv/T8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1576686209936995.2516163995351; Wed, 18 Dec 2019 08:23:29 -0800 (PST) Received: from localhost ([::1]:56742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc6i-0004IK-Qx for importer@patchew.org; Wed, 18 Dec 2019 11:23:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53211) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihc3i-000061-Mr for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihc3g-0004Vb-W8 for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:22 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:32377 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ihc3g-0004SO-On for qemu-devel@nongnu.org; Wed, 18 Dec 2019 11:20:20 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-273-Z1S5wJneOYu0OKI4KTRKEQ-1; Wed, 18 Dec 2019 11:20:17 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1795618B5FC4; Wed, 18 Dec 2019 16:20:16 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-116-210.ams2.redhat.com [10.36.116.210]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AEA51000322; Wed, 18 Dec 2019 16:20:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576686020; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KNe1IMjIGmXeuqdnaC4u1N+/tCWcwT0DPZLrMAIe5Lo=; b=ZDJcLCyhem2KgrmZm1DA5sUAojdltwr7dtdD4+uxfDShqQ/2KjFgP0YQKjZsedQmt3DNe+ bv8KhJLfmfpLRbdsLWpukRm1aHPDZH3eoyyUdsjtN9xni4TSFzSVM1WEk+o104gjLH9M8G Gc9uVf7Dh5rUlRF477uEoiSir0Bvz9Q= From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH 4/4] monitor: Move qmp_query_qmp_schema to qmp-cmds-monitor.c Date: Wed, 18 Dec 2019 17:19:52 +0100 Message-Id: <20191218161952.10202-5-kwolf@redhat.com> In-Reply-To: <20191218161952.10202-1-kwolf@redhat.com> References: <20191218161952.10202-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: Z1S5wJneOYu0OKI4KTRKEQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" monitor/misc.c contains code that works only in the system emulator, so it can't be linked to tools like a storage daemon. In order to make schema introspection available for tools, move the function to monitor/qmp-cmds-monitor.c, which can be linked into the storage daemon. Signed-off-by: Kevin Wolf --- monitor/monitor-internal.h | 3 +++ monitor/misc.c | 16 ---------------- monitor/qmp-cmds-monitor.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h index 451aa64c1a..b91cb09ee5 100644 --- a/monitor/monitor-internal.h +++ b/monitor/monitor-internal.h @@ -180,4 +180,7 @@ void help_cmd(Monitor *mon, const char *name); void handle_hmp_command(MonitorHMP *mon, const char *cmdline); int hmp_compare_cmd(const char *name, const char *list); =20 +void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, + Error **errp); + #endif diff --git a/monitor/misc.c b/monitor/misc.c index c647ba6313..54c89b9391 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -69,7 +69,6 @@ #include "qapi/qapi-commands.h" #include "qapi/error.h" #include "qapi/qmp-event.h" -#include "qapi/qapi-introspect.h" #include "sysemu/cpus.h" #include "qemu/cutils.h" #include "tcg/tcg.h" @@ -229,21 +228,6 @@ static void hmp_info_help(Monitor *mon, const QDict *q= dict) help_cmd(mon, "info"); } =20 -/* - * Minor hack: generated marshalling suppressed for this command - * ('gen': false in the schema) so we can parse the JSON string - * directly into QObject instead of first parsing it with - * visit_type_SchemaInfoList() into a SchemaInfoList, then marshal it - * to QObject with generated output marshallers, every time. Instead, - * we do it in test-qobject-input-visitor.c, just to make sure - * qapi-gen.py's output actually conforms to the schema. - */ -static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, - Error **errp) -{ - *ret_data =3D qobject_from_qlit(&qmp_schema_qlit); -} - static void monitor_init_qmp_commands(void) { /* diff --git a/monitor/qmp-cmds-monitor.c b/monitor/qmp-cmds-monitor.c index acebfd3716..7215392f3e 100644 --- a/monitor/qmp-cmds-monitor.c +++ b/monitor/qmp-cmds-monitor.c @@ -29,6 +29,7 @@ #include "qapi/error.h" #include "qapi/qapi-commands-monitor.h" #include "qapi/qapi-emit-events.h" +#include "qapi/qapi-introspect.h" =20 /* * Accept QMP capabilities in @list for @mon. @@ -151,3 +152,18 @@ EventInfoList *qmp_query_events(Error **errp) =20 return ev_list; } + +/* + * Minor hack: generated marshalling suppressed for this command + * ('gen': false in the schema) so we can parse the JSON string + * directly into QObject instead of first parsing it with + * visit_type_SchemaInfoList() into a SchemaInfoList, then marshal it + * to QObject with generated output marshallers, every time. Instead, + * we do it in test-qobject-input-visitor.c, just to make sure + * qapi-gen.py's output actually conforms to the schema. + */ +void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, + Error **errp) +{ + *ret_data =3D qobject_from_qlit(&qmp_schema_qlit); +} --=20 2.20.1