From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com,
marcandre.lureau@redhat.com, pbonzini@redhat.com
Subject: [PATCH 6/6] qemu-storage-daemon: Use qmp_chardev_add() for --chardev
Date: Fri, 23 Oct 2020 12:12:22 +0200 [thread overview]
Message-ID: <20201023101222.250147-7-kwolf@redhat.com> (raw)
In-Reply-To: <20201023101222.250147-1-kwolf@redhat.com>
While this makes the code quite a bit longer and arguably isn't very
elegant, it removes the dependency on QemuOpts from the --chardev option
of the storage daemon.
Going through qmp_chardev_add() already now ensures that semantics and
accessible features won't change incompatibly once we QAPIfy it fully.
Note that there are a few differences between the command line option
-chardev in the system emulator and chardev-add in QMP. The --chardev
option of qemu-storage-daemon will follow QMP in these respects:
* All chardev types using ChardevHostdev accept a "path" option on the
command line, but QMP renamed it to "device"
* ChardevSocket:
- Intentionally different defaults (documented as such): server=false
and wait=true (if server=true) on the command line, but server=true
and wait=false in QMP.
- Accidentally different defaults: tight=true on the command line, but
tight=false in QMP (this is a bug in commit 776b97d3).
- QMP has a nested SocketAddressLegacy field, whereas the command line
accepts "path"/"host"/"port"/"fd"/etc. on the top level.
- The command line has a "delay" option, but QMP has "nodelay"
* ChardevUdp has two SocketAddressLegacy fields, the command line has
"host"/"port"/"localaddr"/"localport" on the top level with defaults
for values that are mandatory in SocketAddressLegacy
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
storage-daemon/qemu-storage-daemon.c | 47 ++++++++++++++++++++++------
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/storage-daemon/qemu-storage-daemon.c b/storage-daemon/qemu-storage-daemon.c
index e419ba9f19..b543c30951 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -37,6 +37,7 @@
#include "qapi/error.h"
#include "qapi/qapi-visit-block-core.h"
#include "qapi/qapi-visit-block-export.h"
+#include "qapi/qapi-visit-char.h"
#include "qapi/qapi-visit-control.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qstring.h"
@@ -207,18 +208,46 @@ static void process_options(int argc, char *argv[])
}
case OPTION_CHARDEV:
{
- /* TODO This interface is not stable until we QAPIfy it */
- QemuOpts *opts = qemu_opts_parse_noisily(&qemu_chardev_opts,
- optarg, true);
- if (opts == NULL) {
- exit(EXIT_FAILURE);
- }
+ QDict *args;
+ Visitor *v;
+ ChardevBackend *chr_options;
+ char *id;
+ bool help;
- if (!qemu_chr_new_from_opts(opts, NULL, &error_fatal)) {
- /* No error, but NULL returned means help was printed */
+ args = keyval_parse(optarg, "type", &help, &error_fatal);
+ if (help) {
+ if (qdict_haskey(args, "type")) {
+ /* TODO Print help based on the QAPI schema */
+ qemu_opts_print_help(&qemu_chardev_opts, true);
+ } else {
+ qemu_chr_print_types();
+ }
exit(EXIT_SUCCESS);
}
- qemu_opts_del(opts);
+
+ /*
+ * TODO Flattened version of chardev-add in the QAPI schema
+ *
+ * While it's not there, parse 'id' manually from the QDict
+ * and treat everything else as the 'backend' option for
+ * chardev-add.
+ */
+ id = g_strdup(qdict_get_try_str(args, "id"));
+ if (!id) {
+ error_report("Parameter 'id' is missing");
+ exit(EXIT_FAILURE);
+ }
+ qdict_del(args, "id");
+
+ v = qobject_input_visitor_new_keyval(QOBJECT(args));
+ visit_set_flat_simple_unions(v, true);
+ visit_type_ChardevBackend(v, NULL, &chr_options, &error_fatal);
+ visit_free(v);
+
+ qmp_chardev_add(id, chr_options, &error_fatal);
+ qapi_free_ChardevBackend(chr_options);
+ g_free(id);
+ qobject_unref(args);
break;
}
case OPTION_EXPORT:
--
2.28.0
next prev parent reply other threads:[~2020-10-23 10:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-23 10:12 [PATCH 0/6] qemu-storage-daemon: QAPIfy --chardev Kevin Wolf
2020-10-23 10:12 ` [PATCH 1/6] char/stdio: Fix QMP default for 'signal' Kevin Wolf
2020-10-23 10:38 ` Marc-André Lureau
2020-10-23 12:12 ` Markus Armbruster
2020-10-23 10:12 ` [PATCH 2/6] char: Factor out qemu_chr_print_types() Kevin Wolf
2020-10-23 10:38 ` Marc-André Lureau
2020-10-23 12:15 ` Markus Armbruster
2020-10-23 10:12 ` [PATCH 3/6] qapi: Remove wrapper struct for simple unions Kevin Wolf
2020-10-23 10:40 ` Marc-André Lureau
2020-10-23 11:06 ` Marc-André Lureau
2020-10-23 12:28 ` Kevin Wolf
2020-10-23 12:49 ` Markus Armbruster
2020-10-23 14:06 ` Kevin Wolf
2020-10-23 10:12 ` [PATCH 4/6] qapi: Optionally parse simple unions as flat Kevin Wolf
2020-10-23 10:12 ` [PATCH 5/6] tests/qapi-schema: Flat representation of simple unions Kevin Wolf
2020-10-23 10:12 ` Kevin Wolf [this message]
2020-10-26 13:33 ` [PATCH 6/6] qemu-storage-daemon: Use qmp_chardev_add() for --chardev Markus Armbruster
2020-10-23 10:36 ` [PATCH 0/6] qemu-storage-daemon: QAPIfy --chardev Daniel P. Berrangé
2020-10-23 11:05 ` Paolo Bonzini
2020-10-23 11:56 ` Kevin Wolf
2020-10-23 13:40 ` Markus Armbruster
2020-10-23 16:08 ` Paolo Bonzini
2020-10-25 17:42 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201023101222.250147-7-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.