Skip to contentSkip to conversation

qemu-storage-daemon: Remove QemuOpts from --object parser

PATCH Superseded Kevin Wolf 3 participants 18 messages Sep 30, 2020 – Oct 5, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

v2 cover qemu-storage-daemon: Remove QemuOpts from --object parser

This replaces the QemuOpts-based help code for --object in the storage daemon with code based on the keyval parser.

v2:
- Fixed double comma by reusing the existing key and value parsers [Eric]
- More tests to cover the additional cases

Kevin Wolf (4):
keyval: Parse help options
qom: Factor out helpers from user_creatable_print_help()
qom: Add user_creatable_print_help_from_qdict()
qemu-storage-daemon: Remove QemuOpts from --object parser

 include/qemu/option.h                |   2 +-
 include/qom/object_interfaces.h      |   9 ++
 qapi/qobject-input-visitor.c         |   2 +-
 qom/object_interfaces.c              |  99 ++++++++-----
 storage-daemon/qemu-storage-daemon.c |  15 +-
 tests/test-keyval.c                  | 205 +++++++++++++++++++--------
 util/keyval.c                        |  38 ++++-
 7 files changed, 252 insertions(+), 118 deletions(-)
Signature · 1 line
2.25.4
author
#1 lore raw

PATCH v2 1/4 keyval: Parse help options

This adds a new parameter 'help' to keyval_parse() that enables parsing of help options. If NULL is passed, the function behaves the same as before. But if a bool pointer is given, it contains the information whether an option "help" without value was given (which would otherwise either result in an error or be interpreted as the value for an implied key).

---
 include/qemu/option.h                |   2 +-
 qapi/qobject-input-visitor.c         |   2 +-
 storage-daemon/qemu-storage-daemon.c |   2 +-
 tests/test-keyval.c                  | 205 +++++++++++++++++++--------
 util/keyval.c                        |  38 ++++-
 5 files changed, 179 insertions(+), 70 deletions(-)
include/qemu/option.h +1 -1
index 05e8a15c73..ac69352e0e 100644
@@ -149,6 +149,6 @@ void qemu_opts_free(QemuOptsList *list);
 QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
 
 QDict *keyval_parse(const char *params, const char *implied_key,
-                    Error **errp);
+                    bool *help, Error **errp);
 
 #endif
qapi/qobject-input-visitor.c +1 -1
index f918a05e5f..7b184b50a7 100644
@@ -757,7 +757,7 @@ Visitor *qobject_input_visitor_new_str(const char *str,
         assert(args);
         v = qobject_input_visitor_new(QOBJECT(args));
     } else {
-        args = keyval_parse(str, implied_key, errp);
+        args = keyval_parse(str, implied_key, NULL, errp);
         if (!args) {
             return NULL;
         }
storage-daemon/qemu-storage-daemon.c +1 -1
index e6157ff518..bb9cb740f0 100644
@@ -278,7 +278,7 @@ static void process_options(int argc, char *argv[])
                 }
                 qemu_opts_del(opts);
 
-                args = keyval_parse(optarg, "qom-type", &error_fatal);
+                args = keyval_parse(optarg, "qom-type", NULL, &error_fatal);
                 user_creatable_add_dict(args, true, &error_fatal);
                 qobject_unref(args);
                 break;
tests/test-keyval.c +143 -62

503 lines not on this page · raw message

util/keyval.c +33 -5
index 13def4af54..c8ce3bb6c9 100644
@@ -166,7 +166,7 @@ static QObject *keyval_parse_put(QDict *cur,
  * On failure, return NULL.
  */
 static const char *keyval_parse_one(QDict *qdict, const char *params,
-                                    const char *implied_key,
+                                    const char *implied_key, bool *help,
                                     Error **errp)
 {
     const char *key, *key_end, *s, *end;
@@ -238,13 +238,20 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
     if (key == implied_key) {
         assert(!*s);
         s = params;
+    } else if (*s == '=') {
+        s++;
     } else {
-        if (*s != '=') {
+        if (help && !strncmp(key, "help", s - key)) {
+            *help = true;
+            if (*s) {
+                s++;
+            }
+            return s;
+        } else {
             error_setg(errp, "Expected '=' after parameter '%.*s'",
                        (int)(s - key), key);
             return NULL;
         }
-        s++;
     }
 
     val = qstring_new();
@@ -260,6 +267,15 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
         qstring_append_chr(val, *s++);
     }
 
+    if (help && key == implied_key) {
+        const char *str_val = qstring_get_str(val);
+        if (!strcmp(str_val, "help")) {
+            *help = true;
+            qobject_unref(val);
+            return s;
+        }
+    }
+
     if (!keyval_parse_put(cur, key_in_cur, val, key, key_end, errp)) {
         return NULL;
     }
@@ -388,21 +404,33 @@ static QObject *keyval_listify(QDict *cur, GSList *key_of_cur, Error **errp)
 
 /*
  * Parse @params in QEMU's traditional KEY=VALUE,... syntax.
+ *
  * If @implied_key, the first KEY= can be omitted.  @implied_key is
  * implied then, and VALUE can't be empty or contain ',' or '='.
+ *
+ * If @help is given, an option "help" without a value isn't added to
+ * the resulting dictionary, but instead sets @help to true. If no
+ * help option is found, @help is false on return. All other options
+ * are parsed and returned normally so that context specific help can
+ * be printed.
+ *
  * On success, return a dictionary of the parsed keys and values.
  * On failure, store an error through @errp and return NULL.
  */
 QDict *keyval_parse(const char *params, const char *implied_key,
-                    Error **errp)
+                    bool *help, Error **errp)
 {
     QDict *qdict = qdict_new();
     QObject *listified;
     const char *s;
 
+    if (help) {
+        *help = false;
+    }
+
     s = params;
     while (*s) {
-        s = keyval_parse_one(qdict, s, implied_key, errp);
+        s = keyval_parse_one(qdict, s, implied_key, help, errp);
         if (!s) {
             qobject_unref(qdict);
             return NULL;
Signature · 1 line
2.25.4
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] keyval: Parse help options

Quoted 13 lines · Kevin Wolf

This adds a new parameter 'help' to keyval_parse() that enables parsing of help options. If NULL is passed, the function behaves the same as before. But if a bool pointer is given, it contains the information whether an option "help" without value was given (which would otherwise either result in an error or be interpreted as the value for an implied key).

---

tests/test-keyval.c +3 -0
+
+    /* "help" is only a help option if it has no value */
+    qdict = keyval_parse("help=on", NULL, &help, &error_abort);

tests/test-keyval.c static void test_keyval_parse(void) · line 202

Quoted 10 lines
tests/test-keyval.c +10 -0
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "help"), ==, "on");
+    g_assert_false(help);
+    qobject_unref(qdict);
+
+    /* Double comma after "help" in an implied key is not a help option */
+    qdict = keyval_parse("help,,abc", "implied", &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_false(help);
+    qobject_unref(qdict);

Worth checking qdict_get_try_str(qdict, "implied") for "help,abc"?

Quoted 6 lines
tests/test-keyval.c +6 -0
+
+    /* Without implied key and without value, it's an error */
+    qdict = keyval_parse("help,,abc", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);
+

tests/test-keyval.c static void test_keyval_parse(void) · line 218

Quoted 10 lines
tests/test-keyval.c +10 -0
+    /* "help" as the only option */
+    qdict = keyval_parse("help", NULL, &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 0);
+    g_assert_true(help);
+    qobject_unref(qdict);
+
+    /* "help" as the first part of the key */
+    qdict = keyval_parse("help.abc", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);

Worth checking qdict_get_try_str(qdict, "help.abc") for "on"? (at least, that's my guess as what happened)

tests/test-keyval.c static void test_keyval_parse(void) · line 223

Quoted 5 lines
tests/test-keyval.c +5 -0
+
+    /* "help" as the last part of the key */
+    qdict = keyval_parse("abc.help", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);

[1]

tests/test-keyval.c static void test_keyval_parse(void) · line 229

Quoted 6 lines
tests/test-keyval.c +6 -0
+
+    /* "help" is not a value for the implied key if &help is given */
+    qdict = keyval_parse("help", "implied", &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 0);
+    g_assert_true(help);
+    qobject_unref(qdict);

Worth checking that the qdict does not contain "implied"? Perhaps by checking qdict_size() == 0?

Quoted 15 lines
tests/test-keyval.c +15 -0
+
+    /* "help" is a value for the implied key when passing NULL for help */
+    qdict = keyval_parse("help", "implied", NULL, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "help");
+    qobject_unref(qdict);
+
+    /* "help.abc" is a value for the implied key */
+    qdict = keyval_parse("help.abc", "implied", &help, &err);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "help.abc");
+    g_assert_false(help);
+    qobject_unref(qdict);
+
+    /* "abc.help" is a value for the implied key */

tests/test-keyval.c static void test_keyval_parse(void) · line 254

Quoted 10 lines
tests/test-keyval.c +10 -0
+    qdict = keyval_parse("abc.help", "implied", &help, &err);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "abc.help");
+    g_assert_false(help);
+    qobject_unref(qdict);
+
+    /* "help" as the last part of the key */
+    qdict = keyval_parse("abc.help", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);

duplicates [1]

Quoted 8 lines
tests/test-keyval.c +7 -0
+
+    /* Other keys before and after help are still parsed normally */
+    qdict = keyval_parse("number=42,help,foo=bar", NULL, &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 2);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "number"), ==, "42");
+    g_assert_cmpstr(qdict_get_try_str(qdict, "foo"), ==, "bar");
+    g_assert_true(help);

tests/test-keyval.c static void test_keyval_parse(void) · line 271

Quoted 10 lines
tests/test-keyval.c +9 -0
+    qobject_unref(qdict);
+
+    /* ...even with an implied key */
+    qdict = keyval_parse("val,help,foo=bar", "implied", &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 2);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "val");
+    g_assert_cmpstr(qdict_get_try_str(qdict, "foo"), ==, "bar");
+    g_assert_true(help);
+    qobject_unref(qdict);
 }

Overall a nice set of additions. You could tweak it further, but I'm no longer seeing a hole like last time.

Quoted 11 lines

+++ b/util/keyval.c

util/keyval.c +1 -1
@@ -166,7 +166,7 @@ static QObject *keyval_parse_put(QDict *cur,
  * On failure, return NULL.
  */
 static const char *keyval_parse_one(QDict *qdict, const char *params,
-                                    const char *implied_key,
+                                    const char *implied_key, bool *help,
                                     Error **errp)
 {
     const char *key, *key_end, *s, *end;

util/keyval.c static const char *keyval_parse_one(QDict *qdict, const char *params, · line 244

Quoted 8 lines
util/keyval.c +3 -1
@@ -238,13 +238,20 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
     if (key == implied_key) {
         assert(!*s);
         s = params;
+    } else if (*s == '=') {
+        s++;
     } else {
-        if (*s != '=') {
+        if (help && !strncmp(key, "help", s - key)) {

Should this use is_help_option() to also accept "?", or are we okay demanding exactly "help"?

util/keyval.c static const char *keyval_parse_one(QDict *qdict, const char *params, · line 255

Quoted 12 lines
util/keyval.c +6 -1
+            *help = true;
+            if (*s) {
+                s++;
+            }
+            return s;
+        } else {
             error_setg(errp, "Expected '=' after parameter '%.*s'",
                        (int)(s - key), key);
             return NULL;
         }
-        s++;
     }

Assuming you can touch up the testsuite before the pull request, and assuming we don't care about "?",

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
author
#3 lore raw

Re: [PATCH v2 1/4] keyval: Parse help options

Am 30.09.2020 um 15:35 hat Eric Blake geschrieben:

Quoted 11 lines · Kevin Wolf
Quoted 9 lines

This adds a new parameter 'help' to keyval_parse() that enables parsing of help options. If NULL is passed, the function behaves the same as before. But if a bool pointer is given, it contains the information whether an option "help" without value was given (which would otherwise either result in an error or be interpreted as the value for an implied key).

---

Quoted 15 lines

tests/test-keyval.c static void test_keyval_parse(void) · line 202

Quoted 13 lines
tests/test-keyval.c +13 -0
+
+    /* "help" is only a help option if it has no value */
+    qdict = keyval_parse("help=on", NULL, &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "help"), ==, "on");
+    g_assert_false(help);
+    qobject_unref(qdict);
+
+    /* Double comma after "help" in an implied key is not a help option */
+    qdict = keyval_parse("help,,abc", "implied", &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_false(help);
+    qobject_unref(qdict);

Worth checking qdict_get_try_str(qdict, "implied") for "help,abc"?

Yes, this makes sense.

Quoted 11 lines
Quoted 11 lines
tests/test-keyval.c +11 -0
+
+    /* Without implied key and without value, it's an error */
+    qdict = keyval_parse("help,,abc", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);
+
+    /* "help" as the only option */
+    qdict = keyval_parse("help", NULL, &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 0);
+    g_assert_true(help);
+    qobject_unref(qdict);
Quoted 8 lines

tests/test-keyval.c static void test_keyval_parse(void) · line 218

Quoted 5 lines
tests/test-keyval.c +5 -0
+
+    /* "help" as the first part of the key */
+    qdict = keyval_parse("help.abc", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);

Worth checking qdict_get_try_str(qdict, "help.abc") for "on"? (at least, that's my guess as what happened)

The keyval parser doesn't support boolean options like this (I think this is intentional because it would be ambiguous with implied keys).

This is an error case, and I don't think the QDict has defined content then. But if anything, we would want to check that it's empty.

Quoted 15 lines

tests/test-keyval.c static void test_keyval_parse(void) · line 223

Quoted 5 lines
tests/test-keyval.c +5 -0
+
+    /* "help" as the last part of the key */
+    qdict = keyval_parse("abc.help", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);

[1]

tests/test-keyval.c static void test_keyval_parse(void) · line 229

Quoted 6 lines
tests/test-keyval.c +6 -0
+
+    /* "help" is not a value for the implied key if &help is given */
+    qdict = keyval_parse("help", "implied", &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 0);
+    g_assert_true(help);
+    qobject_unref(qdict);
Quoted 2 lines

Worth checking that the qdict does not contain "implied"? Perhaps by checking qdict_size() == 0?

Already there, the first line after keyval_parse(). :-)

Quoted 19 lines
Quoted 19 lines
tests/test-keyval.c +19 -0
+
+    /* "help" is a value for the implied key when passing NULL for help */
+    qdict = keyval_parse("help", "implied", NULL, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "help");
+    qobject_unref(qdict);
+
+    /* "help.abc" is a value for the implied key */
+    qdict = keyval_parse("help.abc", "implied", &help, &err);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "help.abc");
+    g_assert_false(help);
+    qobject_unref(qdict);
+
+    /* "abc.help" is a value for the implied key */
+    qdict = keyval_parse("abc.help", "implied", &help, &err);
+    g_assert_cmpuint(qdict_size(qdict), ==, 1);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "abc.help");
+    g_assert_false(help);
Quoted 8 lines

tests/test-keyval.c static void test_keyval_parse(void) · line 223

Quoted 6 lines
tests/test-keyval.c +6 -0
+    qobject_unref(qdict);
+
+    /* "help" as the last part of the key */
+    qdict = keyval_parse("abc.help", NULL, &help, &err);
+    error_free_or_abort(&err);
+    g_assert(!qdict);

duplicates [1]

So we can be extra sure!

Somehow I suspect I wanted to test another case here, but I'm not sure which one. Maybe the same with an implied key? Or I can just remove it.

Quoted 36 lines
Quoted 8 lines
tests/test-keyval.c +7 -0
+
+    /* Other keys before and after help are still parsed normally */
+    qdict = keyval_parse("number=42,help,foo=bar", NULL, &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 2);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "number"), ==, "42");
+    g_assert_cmpstr(qdict_get_try_str(qdict, "foo"), ==, "bar");
+    g_assert_true(help);

tests/test-keyval.c static void test_keyval_parse(void) · line 271

Quoted 10 lines
tests/test-keyval.c +9 -0
+    qobject_unref(qdict);
+
+    /* ...even with an implied key */
+    qdict = keyval_parse("val,help,foo=bar", "implied", &help, &error_abort);
+    g_assert_cmpuint(qdict_size(qdict), ==, 2);
+    g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "val");
+    g_assert_cmpstr(qdict_get_try_str(qdict, "foo"), ==, "bar");
+    g_assert_true(help);
+    qobject_unref(qdict);
 }

Overall a nice set of additions. You could tweak it further, but I'm no longer seeing a hole like last time.

Quoted 14 lines

+++ b/util/keyval.c

util/keyval.c +1 -1
@@ -166,7 +166,7 @@ static QObject *keyval_parse_put(QDict *cur,
  * On failure, return NULL.
  */
 static const char *keyval_parse_one(QDict *qdict, const char *params,
-                                    const char *implied_key,
+                                    const char *implied_key, bool *help,
                                     Error **errp)
 {
     const char *key, *key_end, *s, *end;
@@ -238,13 +238,20 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
     if (key == implied_key) {
         assert(!*s);
         s = params;
Quoted 8 lines

util/keyval.c static const char *keyval_parse_one(QDict *qdict, const char *params, · line 244

Quoted 5 lines
util/keyval.c +3 -1
+    } else if (*s == '=') {
+        s++;
     } else {
-        if (*s != '=') {
+        if (help && !strncmp(key, "help", s - key)) {

Should this use is_help_option() to also accept "?", or are we okay demanding exactly "help"?

The comment for is_help_option() calls "?" deprecated, so I think we don't want to enable it in a new parser.

Quoted 13 lines

util/keyval.c static const char *keyval_parse_one(QDict *qdict, const char *params, · line 255

Quoted 12 lines
util/keyval.c +6 -1
+            *help = true;
+            if (*s) {
+                s++;
+            }
+            return s;
+        } else {
             error_setg(errp, "Expected '=' after parameter '%.*s'",
                        (int)(s - key), key);
             return NULL;
         }
-        s++;
     }
Quoted 4 lines

Assuming you can touch up the testsuite before the pull request, and assuming we don't care about "?",

Thanks!

Kevin

#4 lore raw

Re: [PATCH v2 1/4] keyval: Parse help options

Quoted 10 lines · Kevin Wolf

Am 30.09.2020 um 15:35 hat Eric Blake geschrieben:

Quoted 9 lines · Kevin Wolf
Quoted 8 lines

This adds a new parameter 'help' to keyval_parse() that enables parsing of help options. If NULL is passed, the function behaves the same as before. But if a bool pointer is given, it contains the information whether an option "help" without value was given (which would otherwise either result in an error or be interpreted as the value for an implied key).

[...]

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines

+++ b/util/keyval.c

util/keyval.c +1 -1
@@ -166,7 +166,7 @@ static QObject *keyval_parse_put(QDict *cur,
  * On failure, return NULL.
  */
 static const char *keyval_parse_one(QDict *qdict, const char *params,
-                                    const char *implied_key,
+                                    const char *implied_key, bool *help,
                                     Error **errp)
 {
     const char *key, *key_end, *s, *end;
@@ -238,13 +238,20 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
     if (key == implied_key) {
         assert(!*s);
         s = params;
Quoted 8 lines

util/keyval.c static const char *keyval_parse_one(QDict *qdict, const char *params, · line 244

Quoted 5 lines
util/keyval.c +3 -1
+    } else if (*s == '=') {
+        s++;
     } else {
-        if (*s != '=') {
+        if (help && !strncmp(key, "help", s - key)) {

Should this use is_help_option() to also accept "?", or are we okay demanding exactly "help"?

Quoted 2 lines

The comment for is_help_option() calls "?" deprecated, so I think we don't want to enable it in a new parser.

Valid point.

But do we really want comparisons for "help" inline everywhere we want to check for non-deprecated help requests? Would a common helper function be better?

On the deprecation of "?": the comment is more than eight years old (commit c8057f951d6). We didn't have a deprecation process back then, but we did purge '?' from the documentation. Can we finally drop it? I'm going to ask that in a new thread.

[...]

author
#5 lore raw

Re: [PATCH v2 1/4] keyval: Parse help options

Am 01.10.2020 um 12:34 hat Markus Armbruster geschrieben:

Quoted 36 lines
Quoted 10 lines · Kevin Wolf

Am 30.09.2020 um 15:35 hat Eric Blake geschrieben:

Quoted 9 lines · Kevin Wolf
Quoted 8 lines

This adds a new parameter 'help' to keyval_parse() that enables parsing of help options. If NULL is passed, the function behaves the same as before. But if a bool pointer is given, it contains the information whether an option "help" without value was given (which would otherwise either result in an error or be interpreted as the value for an implied key).

[...]

Quoted 23 lines
Quoted 22 lines
Quoted 11 lines

+++ b/util/keyval.c

util/keyval.c +1 -1
@@ -166,7 +166,7 @@ static QObject *keyval_parse_put(QDict *cur,
  * On failure, return NULL.
  */
 static const char *keyval_parse_one(QDict *qdict, const char *params,
-                                    const char *implied_key,
+                                    const char *implied_key, bool *help,
                                     Error **errp)
 {
     const char *key, *key_end, *s, *end;

util/keyval.c static const char *keyval_parse_one(QDict *qdict, const char *params, · line 244

Quoted 8 lines
util/keyval.c +3 -1
@@ -238,13 +238,20 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
     if (key == implied_key) {
         assert(!*s);
         s = params;
+    } else if (*s == '=') {
+        s++;
     } else {
-        if (*s != '=') {
+        if (help && !strncmp(key, "help", s - key)) {

Should this use is_help_option() to also accept "?", or are we okay demanding exactly "help"?

Quoted 8 lines
Quoted 2 lines

The comment for is_help_option() calls "?" deprecated, so I think we don't want to enable it in a new parser.

Valid point.

But do we really want comparisons for "help" inline everywhere we want to check for non-deprecated help requests? Would a common helper function be better?

How many more parsers are we going to add? I thought we intended the keyval parser to be the one canoncial place in the long term?

If you prefer, I can make this a second static inline function in include/qemu/help_option.h (that would have to work both as strcmp and as strncmp), but I don't see a second user that would make it a "common" helper.

Quoted 4 lines

On the deprecation of "?": the comment is more than eight years old (commit c8057f951d6). We didn't have a deprecation process back then, but we did purge '?' from the documentation. Can we finally drop it? I'm going to ask that in a new thread.

I guess we can.

Kevin

#6 lore raw

Re: [PATCH v2 1/4] keyval: Parse help options

In reply to Kevin Wolf

Fried brain today, I have to go through this real slow. I apologize in advance for being denser and more error-prone than usual.

Quoted 8 lines · Kevin Wolf

This adds a new parameter 'help' to keyval_parse() that enables parsing of help options. If NULL is passed, the function behaves the same as before. But if a bool pointer is given, it contains the information whether an option "help" without value was given (which would otherwise either result in an error or be interpreted as the value for an implied key).

You change the parser, but neglected to update the grammar in the big file comment.

I made the mistake of attempting to review the parser change without fixing up the grammar first, and got lost in the weeds. In part because today is not my day, but also because doing parsers without a grammar never works out well for me.

Grammar from the big file comment:

* KEY=VALUE,... syntax:
*

 *   key-vals     = [ key-val { ',' key-val } [ ',' ] ]
 *   key-val      = key '=' val
 *   key          = key-fragment { '.' key-fragment }
 *   key-fragment = / [^=,.]* /
 *   val          = { / [^,]* / | ',,' }

and

* Additional syntax for use with an implied key:
*

 *   key-vals-ik  = val-no-key [ ',' key-vals ]
 *   val-no-key   = / [^=,]* /

*
* where no-key is syntactic sugar for implied-key=val-no-key.

According to the commit message, we want to recognize "help" in place of key-val and val-no-key, but only for callers that opt in.

This is more complex than recognizing it in place of just key-vals. The commit message doesn't say why the extra complexity is wanted. Peeking ahead in the series, I can see it's for supporting

-object TYPE,help

in addition to

-object help

I see.

Making help support opt-in complicates things. Is there a genuine use for not supporting help? Or is just to keep the users that don't support help yet (but should) working without change? Mind, I'm not asking you to make them work, I'm only asking whether you can think of a genuine case where help should not work.

What are the existing users that don't support help? Let's see... many in tests/test-keyval.c (ignore), and qobject_input_visitor_new_str(). That one's used for qemu-system-FOO -audiodev, -display, -blockdev, and for qemu-storage-daemon --blockdev, --export, --monitor, --nbd-server.

Attempting to get help for them fails like this:

    $ bld-x86/storage-daemon/qemu-storage-daemon --blockdev help
    qemu-storage-daemon: Invalid parameter 'help'
    $ bld-x86/storage-daemon/qemu-storage-daemon --blockdev file,help
    qemu-storage-daemon: Expected '=' after parameter 'help'

I believe making them fail like

qemu-storage-daemon: no help available

would actually be an improvement.

If we get rid of the case "help is not supported", the grammar update isn't too bad, something like

* key-val = 'help' | key '=' val

and

* key-vals-ik = 'help' | val-no-key [ ',' key-vals ]

Done for today, hope my brain unfries itself overnight.

[...]

#7 lore raw

Re: [PATCH v2 1/4] keyval: Parse help options

Markus Armbruster <[email protected]> writes:

[...]

Quoted 18 lines

Making help support opt-in complicates things. Is there a genuine use for not supporting help? Or is just to keep the users that don't support help yet (but should) working without change? Mind, I'm not asking you to make them work, I'm only asking whether you can think of a genuine case where help should not work.

What are the existing users that don't support help? Let's see... many in tests/test-keyval.c (ignore), and qobject_input_visitor_new_str(). That one's used for qemu-system-FOO -audiodev, -display, -blockdev, and for qemu-storage-daemon --blockdev, --export, --monitor, --nbd-server.

Attempting to get help for them fails like this:

    $ bld-x86/storage-daemon/qemu-storage-daemon --blockdev help
    qemu-storage-daemon: Invalid parameter 'help'
    $ bld-x86/storage-daemon/qemu-storage-daemon --blockdev file,help
    qemu-storage-daemon: Expected '=' after parameter 'help'
Quoted 5 lines

I believe making them fail like

qemu-storage-daemon: no help available

would actually be an improvement.

Potential issue: if an option's implied key may have the value "help", then option argument "help" can be either parsed as "give me help", or as "implied-key=help".

None of the existing options have this issue:

* audiodev: union Audiodev, implied key "driver" is enum AudiodevDriver, "help" is not among its values

* display: union DisplayOptions, implied key "type" is enum DisplayType, "help" is not among its values

* blockdev: union BlockdevOptions, implied key "driver is enum BlockdevDriver, "help" is not among its values

* export: union BlockExport, implied key "type" is enum BlockExportType, "help" is not among its values

* monitor: struct MonitorOptions, implied key "mode"is enum MonitorMode, "help" is not among its values

* nbd-server: struct NbdServerOptions, no implied key.

We're good.

What's the risk of not staying good?

The implied keys above are all QAPI enums.

The only existing QAPI enum with a value 'help' is QKeyCode.

The only existing C enum with a name that ends in _HELP is the one defining Mac keycodes in hw/input/adb-keys.h.

For completeness, I double-checked non of the existing occurences of string "help" are used as values of option parameters.

We'll almost certainly stay good.

What if we manage to mess this up against all odds?

In my opinion, consistency in getting help is more important than consistency within a badly designed option: option argument "help" should give you help even when that means you can't omit the implied key when its value is "help".

[...]

author
#8 lore raw

PATCH v2 2/4 qom: Factor out helpers from user_creatable_print_help()

In reply to Kevin Wolf

This creates separate helper functions for printing a list of user creatable object types and for printing a list of properties of a given type. This allows using these parts without having a QemuOpts.

---
 qom/object_interfaces.c | 90 ++++++++++++++++++++++++-----------------
 1 file changed, 52 insertions(+), 38 deletions(-)
qom/object_interfaces.c +52 -38
index e8e1523960..3fd1da157e 100644
@@ -214,54 +214,68 @@ char *object_property_help(const char *name, const char *type,
     return g_string_free(str, false);
 }
 
-bool user_creatable_print_help(const char *type, QemuOpts *opts)
+static void user_creatable_print_types(void)
+{
+    GSList *l, *list;
+
+    printf("List of user creatable objects:\n");
+    list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
+    for (l = list; l != NULL; l = l->next) {
+        ObjectClass *oc = OBJECT_CLASS(l->data);
+        printf("  %s\n", object_class_get_name(oc));
+    }
+    g_slist_free(list);
+}
+
+static bool user_creatable_print_type_properites(const char *type)
 {
     ObjectClass *klass;
+    ObjectPropertyIterator iter;
+    ObjectProperty *prop;
+    GPtrArray *array;
+    int i;
 
-    if (is_help_option(type)) {
-        GSList *l, *list;
+    klass = object_class_by_name(type);
+    if (!klass) {
+        return false;
+    }
 
-        printf("List of user creatable objects:\n");
-        list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
-        for (l = list; l != NULL; l = l->next) {
-            ObjectClass *oc = OBJECT_CLASS(l->data);
-            printf("  %s\n", object_class_get_name(oc));
+    array = g_ptr_array_new();
+    object_class_property_iter_init(&iter, klass);
+    while ((prop = object_property_iter_next(&iter))) {
+        if (!prop->set) {
+            continue;
         }
-        g_slist_free(list);
-        return true;
+
+        g_ptr_array_add(array,
+                        object_property_help(prop->name, prop->type,
+                                             prop->defval, prop->description));
     }
+    g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
+    if (array->len > 0) {
+        printf("%s options:\n", type);
+    } else {
+        printf("There are no options for %s.\n", type);
+    }
+    for (i = 0; i < array->len; i++) {
+        printf("%s\n", (char *)array->pdata[i]);
+    }
+    g_ptr_array_set_free_func(array, g_free);
+    g_ptr_array_free(array, true);
+    return true;
+}
 
-    klass = object_class_by_name(type);
-    if (klass && qemu_opt_has_help_opt(opts)) {
-        ObjectPropertyIterator iter;
-        ObjectProperty *prop;
-        GPtrArray *array = g_ptr_array_new();
-        int i;
-
-        object_class_property_iter_init(&iter, klass);
-        while ((prop = object_property_iter_next(&iter))) {
-            if (!prop->set) {
-                continue;
-            }
-
-            g_ptr_array_add(array,
-                            object_property_help(prop->name, prop->type,
-                                                 prop->defval, prop->description));
-        }
-        g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
-        if (array->len > 0) {
-            printf("%s options:\n", type);
-        } else {
-            printf("There are no options for %s.\n", type);
-        }
-        for (i = 0; i < array->len; i++) {
-            printf("%s\n", (char *)array->pdata[i]);
-        }
-        g_ptr_array_set_free_func(array, g_free);
-        g_ptr_array_free(array, true);
+bool user_creatable_print_help(const char *type, QemuOpts *opts)
+{
+    if (is_help_option(type)) {
+        user_creatable_print_types();
         return true;
     }
 
+    if (qemu_opt_has_help_opt(opts)) {
+        return user_creatable_print_type_properites(type);
+    }
+
     return false;
 }
 
Signature · 1 line
2.25.4
Reviewed-by on v2 2/4
#9 lore raw

Re: [PATCH v2 2/4] qom: Factor out helpers from user_creatable_print_help()

Quoted 8 lines · Kevin Wolf

This creates separate helper functions for printing a list of user creatable object types and for printing a list of properties of a given type. This allows using these parts without having a QemuOpts.

---
 qom/object_interfaces.c | 90 ++++++++++++++++++++++++-----------------
 1 file changed, 52 insertions(+), 38 deletions(-)

I don't see any changes from v1, so my R-b from there could have been applied.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v2 2/4
#10 lore raw

Re: [PATCH v2 2/4] qom: Factor out helpers from user_creatable_print_help()

In reply to Kevin Wolf
Quoted 3 lines · Kevin Wolf

This creates separate helper functions for printing a list of user creatable object types and for printing a list of properties of a given type. This allows using these parts without having a QemuOpts.

Does the last sentence allude to a future patch? If yes, I suggest to phrase it as "This will allow ..."

Quoted 105 lines
---
 qom/object_interfaces.c | 90 ++++++++++++++++++++++++-----------------
 1 file changed, 52 insertions(+), 38 deletions(-)
qom/object_interfaces.c +47 -38
index e8e1523960..3fd1da157e 100644
@@ -214,54 +214,68 @@ char *object_property_help(const char *name, const char *type,
     return g_string_free(str, false);
 }
 
-bool user_creatable_print_help(const char *type, QemuOpts *opts)
+static void user_creatable_print_types(void)
+{
+    GSList *l, *list;
+
+    printf("List of user creatable objects:\n");
+    list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
+    for (l = list; l != NULL; l = l->next) {
+        ObjectClass *oc = OBJECT_CLASS(l->data);
+        printf("  %s\n", object_class_get_name(oc));
+    }
+    g_slist_free(list);
+}
+
+static bool user_creatable_print_type_properites(const char *type)
 {
     ObjectClass *klass;
+    ObjectPropertyIterator iter;
+    ObjectProperty *prop;
+    GPtrArray *array;
+    int i;
 
-    if (is_help_option(type)) {
-        GSList *l, *list;
+    klass = object_class_by_name(type);
+    if (!klass) {
+        return false;
+    }
 
-        printf("List of user creatable objects:\n");
-        list = object_class_get_list_sorted(TYPE_USER_CREATABLE, false);
-        for (l = list; l != NULL; l = l->next) {
-            ObjectClass *oc = OBJECT_CLASS(l->data);
-            printf("  %s\n", object_class_get_name(oc));
+    array = g_ptr_array_new();
+    object_class_property_iter_init(&iter, klass);
+    while ((prop = object_property_iter_next(&iter))) {
+        if (!prop->set) {
+            continue;
         }
-        g_slist_free(list);
-        return true;
+
+        g_ptr_array_add(array,
+                        object_property_help(prop->name, prop->type,
+                                             prop->defval, prop->description));
     }
+    g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
+    if (array->len > 0) {
+        printf("%s options:\n", type);
+    } else {
+        printf("There are no options for %s.\n", type);
+    }
+    for (i = 0; i < array->len; i++) {
+        printf("%s\n", (char *)array->pdata[i]);
+    }
+    g_ptr_array_set_free_func(array, g_free);
+    g_ptr_array_free(array, true);
+    return true;
+}
 
-    klass = object_class_by_name(type);
-    if (klass && qemu_opt_has_help_opt(opts)) {
-        ObjectPropertyIterator iter;
-        ObjectProperty *prop;
-        GPtrArray *array = g_ptr_array_new();
-        int i;
-
-        object_class_property_iter_init(&iter, klass);
-        while ((prop = object_property_iter_next(&iter))) {
-            if (!prop->set) {
-                continue;
-            }
-
-            g_ptr_array_add(array,
-                            object_property_help(prop->name, prop->type,
-                                                 prop->defval, prop->description));
-        }
-        g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp0);
-        if (array->len > 0) {
-            printf("%s options:\n", type);
-        } else {
-            printf("There are no options for %s.\n", type);
-        }
-        for (i = 0; i < array->len; i++) {
-            printf("%s\n", (char *)array->pdata[i]);
-        }
-        g_ptr_array_set_free_func(array, g_free);
-        g_ptr_array_free(array, true);
+bool user_creatable_print_help(const char *type, QemuOpts *opts)
+{
+    if (is_help_option(type)) {

qom/object_interfaces.c char *object_property_help(const char *name, const char *type, · line 280

Quoted 10 lines
qom/object_interfaces.c +5 -0
+        user_creatable_print_types();
         return true;
     }
 
+    if (qemu_opt_has_help_opt(opts)) {
+        return user_creatable_print_type_properites(type);
+    }
+
     return false;
 }

I'd make user_creatable_print_types() return true for summetry with user_creatable_print_type_properites(), but that's a matter of taste.

author
#11 lore raw

PATCH v2 3/4 qom: Add user_creatable_print_help_from_qdict()

In reply to Kevin Wolf

This adds a function that, given a QDict of non-help options, prints help for user creatable objects.

---
 include/qom/object_interfaces.h | 9 +++++++++
 qom/object_interfaces.c         | 9 +++++++++
 2 files changed, 18 insertions(+)
include/qom/object_interfaces.h +9 -0
index f118fb516b..53b114b11a 100644
@@ -161,6 +161,15 @@ int user_creatable_add_opts_foreach(void *opaque,
  */
 bool user_creatable_print_help(const char *type, QemuOpts *opts);
 
+/**
+ * user_creatable_print_help_from_qdict:
+ * @args: options to create
+ *
+ * Prints help considering the other options given in @args (if "qom-type" is
+ * given and valid, print properties for the type, otherwise print valid types)
+ */
+void user_creatable_print_help_from_qdict(QDict *args);
+
 /**
  * user_creatable_del:
  * @id: the unique ID for the object
qom/object_interfaces.c +9 -0
index 3fd1da157e..ed896fe764 100644
@@ -279,6 +279,15 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)
     return false;
 }
 
+void user_creatable_print_help_from_qdict(QDict *args)
+{
+    const char *type = qdict_get_try_str(args, "qom-type");
+
+    if (!type || !user_creatable_print_type_properites(type)) {
+        user_creatable_print_types();
+    }
+}
+
 bool user_creatable_del(const char *id, Error **errp)
 {
     Object *container;
Signature · 1 line
2.25.4
Reviewed-by on v2 3/4
#12 lore raw

Re: [PATCH v2 3/4] qom: Add user_creatable_print_help_from_qdict()

Quoted 8 lines · Kevin Wolf

This adds a function that, given a QDict of non-help options, prints help for user creatable objects.

---
 include/qom/object_interfaces.h | 9 +++++++++
 qom/object_interfaces.c         | 9 +++++++++
 2 files changed, 18 insertions(+)

As with v1,

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#13 lore raw

Re: [PATCH v2 3/4] qom: Add user_creatable_print_help_from_qdict()

In reply to Kevin Wolf
Quoted 34 lines · Kevin Wolf

This adds a function that, given a QDict of non-help options, prints help for user creatable objects.

---
 include/qom/object_interfaces.h | 9 +++++++++
 qom/object_interfaces.c         | 9 +++++++++
 2 files changed, 18 insertions(+)
include/qom/object_interfaces.h +9 -0
index f118fb516b..53b114b11a 100644
@@ -161,6 +161,15 @@ int user_creatable_add_opts_foreach(void *opaque,
  */
 bool user_creatable_print_help(const char *type, QemuOpts *opts);
 
+/**
+ * user_creatable_print_help_from_qdict:
+ * @args: options to create
+ *
+ * Prints help considering the other options given in @args (if "qom-type" is
+ * given and valid, print properties for the type, otherwise print valid types)
+ */
+void user_creatable_print_help_from_qdict(QDict *args);
+
 /**
  * user_creatable_del:
  * @id: the unique ID for the object
qom/object_interfaces.c +0 -0
index 3fd1da157e..ed896fe764 100644

qom/object_interfaces.c bool user_creatable_print_help(const char *type, QemuOpts *opts) · line 288

Quoted 10 lines
qom/object_interfaces.c +7 -0
@@ -279,6 +279,15 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)
     return false;
 }
 
+void user_creatable_print_help_from_qdict(QDict *args)
+{
+    const char *type = qdict_get_try_str(args, "qom-type");
+
+    if (!type || !user_creatable_print_type_properites(type)) {
+        user_creatable_print_types();
+    }

Existing user_creatable_print_help():

1. "qom-type=help,..." and its sugared forms, in particular "help"

List QOM types and succeed.

2. "qom-type=T,help,..."

2a. If T names a QOM type

List T's properties and succeed.

2b. If T does not name a QOM type

Fail. Callers typically interpret this as "no help requested", proceed, then choke on invalid qom-type=T.

New user_creatable_print_help() treats case 2b like case 1.

Intentional?

Quoted 5 lines
qom/object_interfaces.c +2 -0
+}
+
 bool user_creatable_del(const char *id, Error **errp)
 {
     Object *container;
Reviewed-by
#14 lore raw

Re: [PATCH v2 3/4] qom: Add user_creatable_print_help_from_qdict()

Quoted 55 lines · Markus Armbruster
Quoted 34 lines · Kevin Wolf

This adds a function that, given a QDict of non-help options, prints help for user creatable objects.

---
 include/qom/object_interfaces.h | 9 +++++++++
 qom/object_interfaces.c         | 9 +++++++++
 2 files changed, 18 insertions(+)
include/qom/object_interfaces.h +9 -0
index f118fb516b..53b114b11a 100644
@@ -161,6 +161,15 @@ int user_creatable_add_opts_foreach(void *opaque,
  */
 bool user_creatable_print_help(const char *type, QemuOpts *opts);
 
+/**
+ * user_creatable_print_help_from_qdict:
+ * @args: options to create
+ *
+ * Prints help considering the other options given in @args (if "qom-type" is
+ * given and valid, print properties for the type, otherwise print valid types)
+ */
+void user_creatable_print_help_from_qdict(QDict *args);
+
 /**
  * user_creatable_del:
  * @id: the unique ID for the object
qom/object_interfaces.c +0 -0
index 3fd1da157e..ed896fe764 100644

qom/object_interfaces.c bool user_creatable_print_help(const char *type, QemuOpts *opts) · line 288

Quoted 10 lines
qom/object_interfaces.c +7 -0
@@ -279,6 +279,15 @@ bool user_creatable_print_help(const char *type, QemuOpts *opts)
     return false;
 }
 
+void user_creatable_print_help_from_qdict(QDict *args)
+{
+    const char *type = qdict_get_try_str(args, "qom-type");
+
+    if (!type || !user_creatable_print_type_properites(type)) {
+        user_creatable_print_types();
+    }

Existing user_creatable_print_help():

1. "qom-type=help,..." and its sugared forms, in particular "help"

List QOM types and succeed.

2. "qom-type=T,help,..."

Quoted 8 lines

2a. If T names a QOM type

List T's properties and succeed.

2b. If T does not name a QOM type

Fail. Callers typically interpret this as "no help requested", proceed, then choke on invalid qom-type=T.

And of course

3. Else

No help requested; fail.

Quoted 3 lines

New user_creatable_print_help() treats case 2b like case 1.

Intentional?

The next patch relies on this, so I figure the answer is yes.

The difference to user_creatable_print_help() is subtle. Perhaps the contract should point it out explicitly. Up to you.

By the way, the contract of user_creatable_print_help() is inaccurate:

* Prints help if requested in @opts.
*
* Returns: true if @opts contained a help option and help was printed, false
* if no help option was found.

One, it prints help when either @type or @opts request it.

Two, "if no help option was found" is misleading: case 2b.

Not this patch's problem.

Quoted 6 lines

qom/object_interfaces.c bool user_creatable_print_help(const char *type, QemuOpts *opts) · line 293

Quoted 6 lines
qom/object_interfaces.c +2 -0
+}
+
 bool user_creatable_del(const char *id, Error **errp)
 {
     Object *container;
author
#15 lore raw

PATCH v2 4/4 qemu-storage-daemon: Remove QemuOpts from --object parser

In reply to Kevin Wolf

The command line parser for --object parses the input twice: Once into QemuOpts just for detecting help options, and then again into a QDict using the keyval parser for actually creating the object.

Now that the keyval parser can also detect help options, we can simplify this and remove the QemuOpts part.

---
 storage-daemon/qemu-storage-daemon.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
storage-daemon/qemu-storage-daemon.c +4 -11
index bb9cb740f0..7cbdbf0b23 100644
@@ -264,21 +264,14 @@ static void process_options(int argc, char *argv[])
             }
         case OPTION_OBJECT:
             {
-                QemuOpts *opts;
-                const char *type;
                 QDict *args;
+                bool help;
 
-                /* FIXME The keyval parser rejects 'help' arguments, so we must
-                 * unconditionall try QemuOpts first. */
-                opts = qemu_opts_parse(&qemu_object_opts,
-                                       optarg, true, &error_fatal);
-                type = qemu_opt_get(opts, "qom-type");
-                if (type && user_creatable_print_help(type, opts)) {
+                args = keyval_parse(optarg, "qom-type", &help, &error_fatal);
+                if (help) {
+                    user_creatable_print_help_from_qdict(args);
                     exit(EXIT_SUCCESS);
                 }
-                qemu_opts_del(opts);
-
-                args = keyval_parse(optarg, "qom-type", NULL, &error_fatal);
                 user_creatable_add_dict(args, true, &error_fatal);
                 qobject_unref(args);
                 break;
Signature · 1 line
2.25.4
Reviewed-by on v2 4/4
#16 lore raw
Quoted 11 lines · Kevin Wolf

The command line parser for --object parses the input twice: Once into QemuOpts just for detecting help options, and then again into a QDict using the keyval parser for actually creating the object.

Now that the keyval parser can also detect help options, we can simplify this and remove the QemuOpts part.

---
 storage-daemon/qemu-storage-daemon.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

As with v1,

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v2 4/4
#17 lore raw
In reply to Kevin Wolf
Quoted 32 lines · Kevin Wolf

The command line parser for --object parses the input twice: Once into QemuOpts just for detecting help options, and then again into a QDict using the keyval parser for actually creating the object.

Now that the keyval parser can also detect help options, we can simplify this and remove the QemuOpts part.

---
 storage-daemon/qemu-storage-daemon.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
storage-daemon/qemu-storage-daemon.c +2 -8
index bb9cb740f0..7cbdbf0b23 100644
@@ -264,21 +264,14 @@ static void process_options(int argc, char *argv[])
             }
         case OPTION_OBJECT:
             {
-                QemuOpts *opts;
-                const char *type;
                 QDict *args;
+                bool help;
 
-                /* FIXME The keyval parser rejects 'help' arguments, so we must
-                 * unconditionall try QemuOpts first. */
-                opts = qemu_opts_parse(&qemu_object_opts,
-                                       optarg, true, &error_fatal);
-                type = qemu_opt_get(opts, "qom-type");
-                if (type && user_creatable_print_help(type, opts)) {
+                args = keyval_parse(optarg, "qom-type", &help, &error_fatal);

storage-daemon/qemu-storage-daemon.c static void process_options(int argc, char *argv[]) · line 277

Quoted 10 lines
storage-daemon/qemu-storage-daemon.c +2 -3
+                if (help) {
+                    user_creatable_print_help_from_qdict(args);
                     exit(EXIT_SUCCESS);
                 }
-                qemu_opts_del(opts);
-
-                args = keyval_parse(optarg, "qom-type", NULL, &error_fatal);
                 user_creatable_add_dict(args, true, &error_fatal);
                 qobject_unref(args);
                 break;