monitor: Refactoring in preparation for qemu-storage-daemon
cover monitor: Refactoring in preparation for qemu-storage-daemon
This series creates a QAPI module 'monitor' that can be used from tools outside the system emulator and movees some monitor initialisation code from vl.c to monitor code.
It is split from the series to introduce qemu-storage-daemon because these refactorings make sense on their own as cleanups.
Kevin Wolf (4):
monitor: Move monitor option parsing to monitor/monitor.c
qapi: Create module 'monitor'
monitor: Create monitor/qmp-cmds-monitor.c
monitor: Move qmp_query_qmp_schema to qmp-cmds-monitor.c
qapi/misc.json | 212 ------------------------------------ qapi/monitor.json | 218 +++++++++++++++++++++++++++++++++++++ qapi/qapi-schema.json | 1 + include/monitor/monitor.h | 4 + include/sysemu/sysemu.h | 1 - monitor/monitor-internal.h | 4 + monitor/hmp-cmds.c | 1 + monitor/misc.c | 126 --------------------- monitor/monitor.c | 52 +++++++++ monitor/qmp-cmds-monitor.c | 169 ++++++++++++++++++++++++++++ monitor/qmp-cmds.c | 15 +-- monitor/qmp.c | 2 +- tests/qmp-test.c | 2 +- ui/gtk.c | 1 + vl.c | 45 +------- monitor/Makefile.objs | 3 +- qapi/Makefile.objs | 4 +- 17 files changed, 458 insertions(+), 402 deletions(-) create mode 100644 qapi/monitor.json create mode 100644 monitor/qmp-cmds-monitor.c
Signature · 1 line
2.20.1
PATCH 1/4 monitor: Move monitor option parsing to monitor/monitor.c
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.
--- include/monitor/monitor.h | 4 +++ include/sysemu/sysemu.h | 1 - monitor/monitor.c | 52 +++++++++++++++++++++++++++++++++++++++ vl.c | 45 +-------------------------------- 4 files changed, 57 insertions(+), 45 deletions(-)
include/monitor/monitor.h +4 -0
@@ -3,6 +3,7 @@#include "block/block.h" #include "qapi/qapi-types-misc.h" +#include "qemu/option.h" #include "qemu/readline.h" extern __threadMonitor *cur_mon;
@@ -10,12 +11,15 @@ typedef struct MonitorHMP MonitorHMP;#define QMP_REQ_QUEUE_LEN_MAX 8 +extern QemuOptsList qemu_mon_opts; +bool monitor_cur_is_qmp (void );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 );int monitor_suspend (Monitor *mon);
include/sysemu/sysemu.h +0 -1
@@ -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;#endif
monitor/monitor.c +52 -0
58 lines not on this page · raw message
vl.c +1 -44
51 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH 1/4] monitor: Move monitor option parsing to monitor/monitor.c
Quoted 7 lines · Kevin Wolf
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.cand adds anallow_hmpparameter so that callers can support QMP without HMP.
New parameter is always true after this series.
Please split this patch: one patch to move the code, one to add the parameter. Delay the second one until you have a user.
Quoted 70 lines
Signed-off-by Kevin Wolf <[email protected]>--- include/monitor/monitor.h | 4 +++ include/sysemu/sysemu.h | 1 - monitor/monitor.c | 52 +++++++++++++++++++++++++++++++++++++++ vl.c | 45 +-------------------------------- 4 files changed, 57 insertions(+), 45 deletions(-)include/monitor/monitor.h +4
-0@@ -3,6 +3,7 @@#include "block/block.h" #include "qapi/qapi-types-misc.h" +#include "qemu/option.h" #include "qemu/readline.h" extern __threadMonitor *cur_mon;@@ -10,12 +11,15 @@ typedef struct MonitorHMP MonitorHMP;#define QMP_REQ_QUEUE_LEN_MAX 8 +extern QemuOptsList qemu_mon_opts; +bool monitor_cur_is_qmp (void );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 );int monitor_suspend (Monitor *mon);include/sysemu/sysemu.h +0
-1@@ -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;#endif monitor/monitor.c +14
-0@@ -609,6 +609,58 @@ void monitor_init_globals_core(void) NULL); } +int monitor_init_opts (QemuOpts *opts,bool allow_hmp,Error **errp) +{ +Chardev *chr; +bool qmp; +bool pretty = false; +const char *chardev; +const char *mode; + + mode =qemu_opt_get (opts,"mode" ); +if (mode ==NULL ) { + mode = allow_hmp ?"readline" :"control" ; + } +if (strcmp (mode,"readline" ) ==0 ) { + qmp = false;
monitor/monitor.c void monitor_init_globals_core(void) · line 635
Quoted 10 lines
monitor/monitor.c +10
-0+ }else if (strcmp (mode,"control" ) ==0 ) { + qmp = 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 ; + }
I'm not sure we should recognize "mode" when !allow_hmp. Hard to decide as long as allow_hmp is always true.
Quoted 77 lines
monitor/monitor.c +28
-0+ +if (!qmp &&qemu_opt_get (opts,"pretty" )) { +warn_report ("'pretty' is deprecated for HMP monitors, it has no effect " +"and will be removed in future versions" ); + } +if (qemu_opt_get_bool (opts,"pretty" ,0 )) { + pretty = true; + } + + chardev =qemu_opt_get (opts,"chardev" ); +if (!chardev) { +error_report ("chardev is required" ); +exit (1 ); + } + chr =qemu_chr_find (chardev); +if (chr ==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 = { .name ="mon" , .implied_opt_name ="chardev" ,vl.c +0
-38@@ -2116,50 +2116,7 @@ static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)static int mon_init_func (void *opaque,QemuOpts *opts,Error **errp) { -Chardev *chr; -bool qmp; -bool pretty = false; -const char *chardev; -const char *mode; - - mode =qemu_opt_get (opts,"mode" ); -if (mode ==NULL ) { - mode ="readline" ; - } -if (strcmp (mode,"readline" ) ==0 ) { - qmp = false; - }else if (strcmp (mode,"control" ) ==0 ) { - qmp = 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 effect " -"and will be removed in future versions" ); - } -if (qemu_opt_get_bool (opts,"pretty" ,0 )) { - pretty = true; - } - - chardev =qemu_opt_get (opts,"chardev" ); -if (!chardev) { -error_report ("chardev is required" ); -exit (1 ); - } - chr =qemu_chr_find (chardev); -if (chr ==NULL ) { -error_setg (errp,"chardev \"%s\" not found" , chardev); -return -1 ; - } -
vl.c static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp) · line 2122
Quoted 10 lines
vl.c +1
-6-if (qmp) { -monitor_init_qmp (chr, pretty); - }else { -monitor_init_hmp (chr, true); - } -return 0 ; +return monitor_init_opts (opts, true, errp); }static void monitor_parse (const char *optarg,const char *mode,bool pretty)
Less the new @allow_hmp parameter:
PATCH 2/4 qapi: Create module 'monitor'
In reply to Kevin Wolfmisc.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.
--- 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
qapi/misc.json +0 -212
@@ -7,159 +7,6 @@ { 'include': 'common.json' } -## -# @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 version -# 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. Downstream -# versions of QEMU should set this to a non-empty string. The -# 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 } -## -# @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'] } -## -# @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: #
qapi/monitor.json new file +218 -0
218 lines not on this page · raw message
qapi/qapi-schema.json +1 -0
@@ -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' }
monitor/monitor-internal.h +1 -0
@@ -27,6 +27,7 @@#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"
monitor/hmp-cmds.c +1 -0
@@ -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"
monitor/qmp-cmds.c +1 -0
@@ -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"
monitor/qmp.c +1 -1
@@ -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"
tests/qmp-test.c +1 -1
@@ -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"
ui/gtk.c +1 -0
@@ -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" #include "ui/console.h"
qapi/Makefile.objs +2 -2
@@ -6,8 +6,8 @@ util-obj-y += qmp-event.o util-obj-y += qapi-util.o QAPI_COMMON_MODULES = audio authz block-core block char common crypto -QAPI_COMMON_MODULES += dump error introspect job machine migration misc net -QAPI_COMMON_MODULES += qdev qom rdma rocker run-state sockets tpm +QAPI_COMMON_MODULES += dump error introspect job machine migration misc monitor +QAPI_COMMON_MODULES += net qdev qom rdma rocker run-state sockets tpm QAPI_COMMON_MODULES += trace transaction ui QAPI_TARGET_MODULES = machine-target misc-target QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES)
Signature · 1 line
2.20.1
Re: [PATCH 2/4] qapi: Create module 'monitor'
Quoted 372 lines · Kevin Wolf
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 <[email protected]>--- 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.jsonqapi/misc.json +0
-212@@ -7,159 +7,6 @@ { 'include': 'common.json' } -## -# @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 version -# 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. Downstream -# versions of QEMU should set this to a non-empty string. The -# 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 } -## -# @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'] } -## -# @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: #qapi/monitor.json new file +109
-0@@ -0,0 +1,218 @@ +# -*- Mode: Python -*- +# + +## +# = 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 version +# 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. Downstream +# versions of QEMU should set this to a non-empty string. The +# 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,
qapi/monitor.json line 119
Quoted 10 lines
qapi/monitor.json new file +10
-0+# "minor":11, +# "micro":5 +# }, +# "package":"" +# } +# } +# +## +{ 'command': 'query-version', 'returns': 'VersionInfo', + 'allow-preconfig': true }
Borderline. I guess you move query-version (along with VersionInfo, VersionTriple) because qmp_greeting() uses it.
Quoted 89 lines
qapi/monitor.json new file +89
-0+ +## +# @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
qapi/monitor.json line 218
Quoted 10 lines
qapi/monitor.json new file +10
-0+# unexpected. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "quit" } +# <- { "return": {} } +## +{ 'command': 'quit' }
Borderline.
Perhaps it's just a matter of naming. monitor.json suggests it's about the monitor. It's in fact about QMP, plus whatever else any program sporting a QMP monitor has. Can we find a name for that? Hmm... control.json?
[...]
qapi/Makefile.objs util-obj-y += qmp-event.o · line 9
Quoted 11 lines
qapi/Makefile.objs +1
-2@@ -6,8 +6,8 @@ util-obj-y += qmp-event.o util-obj-y += qapi-util.o QAPI_COMMON_MODULES = audio authz block-core block char common crypto -QAPI_COMMON_MODULES += dump error introspect job machine migration misc net -QAPI_COMMON_MODULES += qdev qom rdma rocker run-state sockets tpm +QAPI_COMMON_MODULES += dump error introspect job machine migration misc monitor
Long line.
Quoted 4 lines
qapi/Makefile.objs +1
-0+QAPI_COMMON_MODULES += net qdev qom rdma rocker run-state sockets tpm QAPI_COMMON_MODULES += trace transaction ui QAPI_TARGET_MODULES = machine-target misc-target QAPI_MODULES = $(QAPI_COMMON_MODULES) $(QAPI_TARGET_MODULES)
Re: [PATCH 2/4] qapi: Create module 'monitor'
Am 18.12.2019 um 20:20 hat Markus Armbruster geschrieben:
Quoted 30 lines
Quoted 28 lines · Kevin Wolf
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 <[email protected]>qapi/monitor.json new file +21
-0+## +# @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":"" +# }
Quoted 8 lines
qapi/monitor.json line 119
Quoted 5 lines
qapi/monitor.json new file +5
-0+# } +# +## +{ 'command': 'query-version', 'returns': 'VersionInfo', + 'allow-preconfig': true }Borderline. I guess you move query-version (along with VersionInfo, VersionTriple) because
qmp_greeting()uses it.
Also because if querying the version makes sense for QEMU, it probably also makes sense for any other tool.
Quoted 19 lines
Quoted 6 lines
qapi/monitor.json new file +6
-0+## +# @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 beqapi/monitor.json line 218
Quoted 10 lines
qapi/monitor.json new file +10
-0+# unexpected. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "quit" } +# <- { "return": {} } +## +{ 'command': 'quit' }Borderline.
Quoted 4 lines
Perhaps it's just a matter of naming. monitor.json suggests it's about the monitor. It's in fact about QMP, plus whatever else any program sporting a QMP monitor has. Can we find a name for that? Hmm... control.json?
As this is what should make sense for every tool implementing QMP, how about something like base.json or core.json?
Kevin
Re: [PATCH 2/4] qapi: Create module 'monitor'
In reply to Markus ArmbrusterAm 18.12.2019 um 20:20 hat Markus Armbruster geschrieben:
Quoted 7 lines
Quoted 7 lines
qapi/Makefile.objs +0
-0@@ -6,8 +6,8 @@ util-obj-y += qmp-event.o util-obj-y += qapi-util.o
Quoted 6 lines
qapi/Makefile.objs util-obj-y += qmp-event.o · line 9
Quoted 4 lines
qapi/Makefile.objs +1
-2QAPI_COMMON_MODULES = audio authz block-core block char common crypto -QAPI_COMMON_MODULES += dump error introspect job machine migration misc net -QAPI_COMMON_MODULES += qdev qom rdma rocker run-state sockets tpm +QAPI_COMMON_MODULES += dump error introspect job machine migration misc monitorLong line.
I went to fix this, but it's only 79 characters, so I think this is a false alarm.
Kevin
PATCH 3/4 monitor: Create monitor/qmp-cmds-monitor.c
In reply to Kevin WolfMove 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.
--- 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
monitor/misc.c +0 -110
@@ -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 *qdict)help_cmd (mon,"info" ); } -static void query_commands_cb (QmpCommand *cmd,void *opaque) -{ -CommandInfoList *info, **list = opaque; - -if (!cmd->enabled) { -return ; - } - - info =g_malloc0 (sizeof (*info)); - info->value =g_malloc0 (sizeof (*info->value)); - info->value->name =g_strdup (cmd->name); - info->next = *list; - *list = info; -} - -CommandInfoList *qmp_query_commands (Error **errp) -{ -CommandInfoList *list =NULL ; -MonitorQMP *mon; - -assert (monitor_is_qmp (cur_mon)); - mon =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 =NULL ; -QAPIEvent e; - -for (e =0 ; e <QAPI_EVENT__MAX ; e++) { -const char *event_name =QAPIEvent_str (e); -assert (event_name !=NULL ); - info =g_malloc0 (sizeof (*info)); - info->value =g_malloc0 (sizeof (*info->value)); - info->value->name =g_strdup (event_name); - - info->next = ev_list; - ev_list = 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); } -/* -* 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 =NULL ; -bool capab[QMP_CAPABILITY__MAX ]; - -memset (capab,0 ,sizeof (capab)); - -for (; list; list = list->next) { -if (!mon->capab_offered[list->value]) { -if (!unavailable) { - unavailable =g_string_new (QMPCapability_str (list->value)); - }else { -g_string_append_printf (unavailable,", %s" , -QMPCapability_str (list->value)); - } - } - capab[list->value] = 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 =container_of (cur_mon, MonitorQMP, common); - -if (mon->commands == &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 = &qmp_commands; -} -/* Set the current CPU defined by the user. Callers must hold BQL. */ int monitor_set_cpu (int cpu_index) {
monitor/qmp-cmds-monitor.c new file +153 -0
153 lines not on this page · raw message
monitor/qmp-cmds.c +0 -14
@@ -15,7 +15,6 @@#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; } -VersionInfo *qmp_query_version (Error **errp) -{ -VersionInfo *info =g_new0 (VersionInfo,1 ); - - info->qemu =g_new0 (VersionTriple,1 ); - info->qemu->major =QEMU_VERSION_MAJOR ; - info->qemu->minor =QEMU_VERSION_MINOR ; - info->qemu->micro =QEMU_VERSION_MICRO ; - info->package =g_strdup (QEMU_PKGVERSION ); - -return info; -} -KvmInfo *qmp_query_kvm (Error **errp) {KvmInfo *info =g_malloc0 (sizeof (*info));
monitor/Makefile.objs +2 -1
@@ -1,3 +1,4 @@ obj-y += misc.o common-obj-y += monitor.o qmp.o hmp.o -common-obj-y += qmp-cmds.o hmp-cmds.o +common-obj-y += qmp-cmds.o qmp-cmds-monitor.o +common-obj-y += hmp-cmds.o
Signature · 1 line
2.20.1
PATCH 4/4 monitor: Move qmp_query_qmp_schema to qmp-cmds-monitor.c
In reply to Kevin Wolfmonitor/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.
--- monitor/monitor-internal.h | 3 +++ monitor/misc.c | 16 ---------------- monitor/qmp-cmds-monitor.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-)
monitor/monitor-internal.h +3 -0
@@ -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); +void qmp_query_qmp_schema (QDict *qdict,QObject **ret_data, +Error **errp); +#endif
monitor/misc.c +0 -16
@@ -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 *qdict)help_cmd (mon,"info" ); } -/* -* 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 =qobject_from_qlit (&qmp_schema_qlit); -} -static void monitor_init_qmp_commands (void ) {/*
monitor/qmp-cmds-monitor.c +16 -0
@@ -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" /* * Accept QMP capabilities in @list for @mon.
@@ -151,3 +152,18 @@ EventInfoList *qmp_query_events(Error **errp)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 =qobject_from_qlit (&qmp_schema_qlit); +}
Signature · 1 line
2.20.1