aboutsummaryrefslogtreecommitdiff
path: root/qemu-storage-daemon.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2020-02-24 15:30:08 +0100
committerKevin Wolf <kwolf@redhat.com>2020-03-06 17:21:28 +0100
commit2af282ec51a27116d0402cab237b8970800f870c (patch)
tree66a3c1b090cf5e81b8c13596d89aee4a847a2b97 /qemu-storage-daemon.c
parenta2f411c4671b0b6cfe5f3b91b65d9bc8456e75ab (diff)
downloadqemu-2af282ec51a27116d0402cab237b8970800f870c.zip
qemu-2af282ec51a27116d0402cab237b8970800f870c.tar.gz
qemu-2af282ec51a27116d0402cab237b8970800f870c.tar.bz2
qemu-storage-daemon: Add --monitor option
This adds and parses the --monitor option, so that a QMP monitor can be used in the storage daemon. The monitor offers commands defined in the QAPI schema at storage-daemon/qapi/qapi-schema.json. The --monitor options currently allows to create multiple monitors with the same ID. This part of the interface is considered unstable. We will reject such configurations as soon as we have a design for the monitor subsystem to perform these checks. (In the system emulator, we depend on QemuOpts rejecting duplicate IDs.) Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20200224143008.13362-21-kwolf@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-storage-daemon.c')
-rw-r--r--qemu-storage-daemon.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c
index 82fe6cd..dd12897 100644
--- a/qemu-storage-daemon.c
+++ b/qemu-storage-daemon.c
@@ -31,13 +31,15 @@
#include "block/nbd.h"
#include "chardev/char.h"
#include "crypto/init.h"
+#include "monitor/monitor.h"
+#include "monitor/monitor-internal.h"
#include "qapi/error.h"
-#include "qapi/qapi-commands-block.h"
-#include "qapi/qapi-commands-block-core.h"
#include "qapi/qapi-visit-block.h"
#include "qapi/qapi-visit-block-core.h"
+#include "qapi/qapi-visit-control.h"
#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qstring.h"
#include "qapi/qobject-input-visitor.h"
#include "qemu-common.h"
@@ -51,6 +53,9 @@
#include "qemu/option.h"
#include "qom/object_interfaces.h"
+#include "storage-daemon/qapi/qapi-commands.h"
+#include "storage-daemon/qapi/qapi-init-commands.h"
+
#include "sysemu/runstate.h"
#include "trace/control.h"
@@ -61,6 +66,11 @@ void qemu_system_killed(int signal, pid_t pid)
exit_requested = true;
}
+void qmp_quit(Error **errp)
+{
+ exit_requested = true;
+}
+
static void help(void)
{
printf(
@@ -87,6 +97,9 @@ static void help(void)
" export the specified block node over NBD\n"
" (requires --nbd-server)\n"
"\n"
+" --monitor [chardev=]name[,mode=control][,pretty[=on|off]]\n"
+" configure a QMP monitor\n"
+"\n"
" --nbd-server addr.type=inet,addr.host=<host>,addr.port=<port>\n"
" [,tls-creds=<id>][,tls-authz=<id>]\n"
" --nbd-server addr.type=unix,addr.path=<path>\n"
@@ -110,6 +123,7 @@ enum {
OPTION_BLOCKDEV = 256,
OPTION_CHARDEV,
OPTION_EXPORT,
+ OPTION_MONITOR,
OPTION_NBD_SERVER,
OPTION_OBJECT,
};
@@ -125,6 +139,17 @@ static QemuOptsList qemu_object_opts = {
},
};
+static void init_qmp_commands(void)
+{
+ qmp_init_marshal(&qmp_commands);
+ qmp_register_command(&qmp_commands, "query-qmp-schema",
+ qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG);
+
+ QTAILQ_INIT(&qmp_cap_negotiation_commands);
+ qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
+ qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
+}
+
static void init_export(BlockExport *export, Error **errp)
{
switch (export->type) {
@@ -145,6 +170,7 @@ static void process_options(int argc, char *argv[])
{"chardev", required_argument, NULL, OPTION_CHARDEV},
{"export", required_argument, NULL, OPTION_EXPORT},
{"help", no_argument, NULL, 'h'},
+ {"monitor", required_argument, NULL, OPTION_MONITOR},
{"nbd-server", required_argument, NULL, OPTION_NBD_SERVER},
{"object", required_argument, NULL, OPTION_OBJECT},
{"trace", required_argument, NULL, 'T'},
@@ -219,6 +245,21 @@ static void process_options(int argc, char *argv[])
qapi_free_BlockExport(export);
break;
}
+ case OPTION_MONITOR:
+ {
+ Visitor *v;
+ MonitorOptions *monitor;
+
+ v = qobject_input_visitor_new_str(optarg, "chardev",
+ &error_fatal);
+ visit_type_MonitorOptions(v, NULL, &monitor, &error_fatal);
+ visit_free(v);
+
+ /* TODO Catch duplicate monitor IDs */
+ monitor_init(monitor, false, &error_fatal);
+ qapi_free_MonitorOptions(monitor);
+ break;
+ }
case OPTION_NBD_SERVER:
{
Visitor *v;
@@ -280,6 +321,8 @@ int main(int argc, char *argv[])
qemu_add_opts(&qemu_trace_opts);
qcrypto_init(&error_fatal);
bdrv_init();
+ monitor_init_globals_core();
+ init_qmp_commands();
if (!trace_init_backends()) {
return EXIT_FAILURE;