Skip to contentSkip to conversation

deprecate short-form boolean options

PATCH In review Paolo Bonzini 6 participants 21 messages Nov 3, 2020 – Nov 6, 2020

lore
Share & tools
lore
#0 lore raw

cover deprecate short-form boolean options

QemuOpts lets you write boolean options in "short form" where "abc" means "abc=on" and "noabc" means "abc=off". This is confusing, since it is not done for the first key=value pair but only if there is an implied key; it can also be grossly misused, for example "-device e1000,noid" will create a device with id equal to "off".

Unfortunately, this idiom has found wide use with -chardev (think "server,nowait") and to a lesser extent -spice.

Patch 4 in this series deprecates it for all other option groups. The first three patches avoid emitting the warning in tests (which in one case were buggy, see patch 3) or for the "help" option.

Paolo Bonzini (4):
ivshmem-test: do not use short-form boolean option
qemu-option: move help handling to get_opt_name_value
qtest: escape device name in device-introspect-test
qemu-option: warn for short-form boolean options

 chardev/char.c                       |  1 +
 docs/system/deprecated.rst           |  7 ++++
 include/qemu/option.h                |  1 +
 tests/qtest/device-introspect-test.c |  9 +++--
 tests/qtest/ivshmem-test.c           |  2 +-
 tests/test-qemu-opts.c               |  1 +
 ui/spice-core.c                      |  1 +
 util/qemu-option.c                   | 51 ++++++++++++++++------------
 8 files changed, 48 insertions(+), 25 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/4 ivshmem-test: do not use short-form boolean option

This QemuOpts idiom will be deprecated, so get rid of it in the tests.

---
 tests/qtest/ivshmem-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/ivshmem-test.c +1 -1
index d5c8b9f128..dfa69424ed 100644
@@ -135,7 +135,7 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix)
 static void setup_vm(IVState *s)
 {
     char *cmd = g_strdup_printf("-object memory-backend-file"
-                                ",id=mb1,size=1M,share,mem-path=/dev/shm%s"
+                                ",id=mb1,size=1M,share=on,mem-path=/dev/shm%s"
                                 " -device ivshmem-plain,memdev=mb1", tmpshm);
 
     setup_vm_cmd(s, cmd, false);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH for-5.2 1/4] ivshmem-test: do not use short-form boolean option

Quoted 13 lines · Paolo Bonzini

This QemuOpts idiom will be deprecated, so get rid of it in the tests.

---
 tests/qtest/ivshmem-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/ivshmem-test.c +0 -0
index d5c8b9f128..dfa69424ed 100644

tests/qtest/ivshmem-test.c static void setup_vm_cmd(IVState *s, const char *cmd, bool msix) · line 141

Quoted 8 lines
tests/qtest/ivshmem-test.c +1 -1
@@ -135,7 +135,7 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix)
 static void setup_vm(IVState *s)
 {
     char *cmd = g_strdup_printf("-object memory-backend-file"
-                                ",id=mb1,size=1M,share,mem-path=/dev/shm%s"
+                                ",id=mb1,size=1M,share=on,mem-path=/dev/shm%s"
                                 " -device ivshmem-plain,memdev=mb1", tmpshm);
 
     setup_vm_cmd(s, cmd, false);
Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH for-5.2 1/4] ivshmem-test: do not use short-form boolean option

In reply to Paolo Bonzini
Quoted 12 lines · Paolo Bonzini

This QemuOpts idiom will be deprecated, so get rid of it in the tests.

---
 tests/qtest/ivshmem-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/ivshmem-test.c +0 -0
index d5c8b9f128..dfa69424ed 100644

tests/qtest/ivshmem-test.c static void setup_vm_cmd(IVState *s, const char *cmd, bool msix) · line 141

Quoted 8 lines
tests/qtest/ivshmem-test.c +1 -1
@@ -135,7 +135,7 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix)
 static void setup_vm(IVState *s)
 {
     char *cmd = g_strdup_printf("-object memory-backend-file"
-                                ",id=mb1,size=1M,share,mem-path=/dev/shm%s"
+                                ",id=mb1,size=1M,share=on,mem-path=/dev/shm%s"
                                 " -device ivshmem-plain,memdev=mb1", tmpshm);
 
     setup_vm_cmd(s, cmd, false);
#4 lore raw

PATCH 2/4 qemu-option: move help handling to get_opt_name_value

In reply to Paolo Bonzini

Right now, help options are parsed normally and then checked specially in opt_validate---but only if coming from qemu_opts_parse or qemu_opts_parse_noisily, not if coming from qemu_opt_set.

Instead, move the check from opt_validate to the common workhorses of qemu_opts_parse and qemu_opts_parse_noisily, opts_do_parse and get_opt_name_value.

This will come in handy in a subsequent patch, which will raise a warning for "-object memory-backend-ram,share" ("flag" option with no =on/=off part) but not for "-object memory-backend-ram,help".

---
 util/qemu-option.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
util/qemu-option.c +18 -17
index b9f93a7f8b..5824b7afe2 100644
@@ -520,17 +520,13 @@ static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value,
     return opt;
 }
 
-static bool opt_validate(QemuOpt *opt, bool *help_wanted,
-                         Error **errp)
+static bool opt_validate(QemuOpt *opt, Error **errp)
 {
     const QemuOptDesc *desc;
 
     desc = find_desc_by_name(opt->opts->list->desc, opt->name);
     if (!desc && !opts_accepts_any(opt->opts)) {
         error_setg(errp, QERR_INVALID_PARAMETER, opt->name);
-        if (help_wanted && is_help_option(opt->name)) {
-            *help_wanted = true;
-        }
         return false;
     }
 
@@ -547,7 +543,7 @@ bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value,
 {
     QemuOpt *opt = opt_create(opts, name, g_strdup(value), false);
 
-    if (!opt_validate(opt, NULL, errp)) {
+    if (!opt_validate(opt, errp)) {
         qemu_opt_del(opt);
         return false;
     }
@@ -783,14 +779,17 @@ void qemu_opts_print(QemuOpts *opts, const char *separator)
 
 static const char *get_opt_name_value(const char *params,
                                       const char *firstname,
+                                      bool *help_wanted,
                                       char **name, char **value)
 {
-    const char *p, *pe, *pc;
-
-    pe = strchr(params, '=');
-    pc = strchr(params, ',');
+    const char *p;
+    size_t len;
 
-    if (!pe || (pc && pc < pe)) {
+    len = strcspn(params, "=,");
+    if (params[len] != '=') {
+        if (help_wanted && starts_with_help_option(params) == len) {
+            *help_wanted = true;
+        }
         /* found "foo,more" */
         if (firstname) {
             /* implicitly named first option */
@@ -830,7 +829,10 @@ static bool opts_do_parse(QemuOpts *opts, const char *params,
     QemuOpt *opt;
 
     for (p = params; *p;) {
-        p = get_opt_name_value(p, firstname, &option, &value);
+        p = get_opt_name_value(p, firstname, help_wanted, &option, &value);
+        if (help_wanted && *help_wanted) {
+            return false;
+        }
         firstname = NULL;
 
         if (!strcmp(option, "id")) {
@@ -841,7 +843,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *params,
 
         opt = opt_create(opts, option, value, prepend);
         g_free(option);
-        if (!opt_validate(opt, help_wanted, errp)) {
+        if (!opt_validate(opt, errp)) {
             qemu_opt_del(opt);
             return false;
         }
@@ -856,7 +858,7 @@ static char *opts_parse_id(const char *params)
     char *name, *value;
 
     for (p = params; *p;) {
-        p = get_opt_name_value(p, NULL, &name, &value);
+        p = get_opt_name_value(p, NULL, NULL, &name, &value);
         if (!strcmp(name, "id")) {
             g_free(name);
             return value;
@@ -872,11 +874,10 @@ bool has_help_option(const char *params)
 {
     const char *p;
     char *name, *value;
-    bool ret;
+    bool ret = false;
 
     for (p = params; *p;) {
-        p = get_opt_name_value(p, NULL, &name, &value);
-        ret = is_help_option(name);
+        p = get_opt_name_value(p, NULL, &ret, &name, &value);
         g_free(name);
         g_free(value);
         if (ret) {
Signature · 1 line
2.26.2
#5 lore raw

Re: [PATCH for-5.2 2/4] qemu-option: move help handling to get_opt_name_value

Quoted 9 lines · Paolo Bonzini

Right now, help options are parsed normally and then checked specially in opt_validate---but only if coming from qemu_opts_parse or qemu_opts_parse_noisily, not if coming from qemu_opt_set.

Instead, move the check from opt_validate to the common workhorses of qemu_opts_parse and qemu_opts_parse_noisily, opts_do_parse and get_opt_name_value.

Quoted 6 lines

This will come in handy in a subsequent patch, which will raise a warning for "-object memory-backend-ram,share" ("flag" option with no =on/=off part) but not for "-object memory-backend-ram,help".

I'm afraid this fails my smoke test:

    $ o=`sed -n '/HAS_ARG,/s/DEF("\([^"]*\)".*/\1/p' qemu-options.hx`
    $ for i in $o; do echo "= $i"; upstream-qemu -$i help -version; done 2>&1 | egrep -v 'QEMU emulator|Copyright'

Many output differences. False positives due to help printing lists in random order. Arbitrarily picked true positive:

    $ upstream-qemu -msg help
    msg options:
      guest-name=<bool (on/off)> - Prepends guest name for error messages but only if -name guest is set otherwise option is ignored
      timestamp=<bool (on/off)>
    $ echo $?
    1

regresses to silent failure.

#6 lore raw

Re: [PATCH for-5.2 2/4] qemu-option: move help handling to get_opt_name_value

Quoted 30 lines · Markus Armbruster
Quoted 9 lines · Paolo Bonzini

Right now, help options are parsed normally and then checked specially in opt_validate---but only if coming from qemu_opts_parse or qemu_opts_parse_noisily, not if coming from qemu_opt_set.

Instead, move the check from opt_validate to the common workhorses of qemu_opts_parse and qemu_opts_parse_noisily, opts_do_parse and get_opt_name_value.

Quoted 6 lines

This will come in handy in a subsequent patch, which will raise a warning for "-object memory-backend-ram,share" ("flag" option with no =on/=off part) but not for "-object memory-backend-ram,help".

I'm afraid this fails my smoke test:

     $ o=`sed -n '/HAS_ARG,/s/DEF("\([^"]*\)".*/\1/p' qemu-options.hx`
     $ for i in $o; do echo "= $i"; upstream-qemu -$i help -version; done 2>&1 | egrep -v 'QEMU emulator|Copyright'

Many output differences. False positives due to help printing lists in random order. Arbitrarily picked true positive:

     $ upstream-qemu -msg help
     msg options:
       guest-name=<bool (on/off)> - Prepends guest name for error messages but only if -name guest is set otherwise option is ignored
Quoted 5 lines
       timestamp=<bool (on/off)>
     $ echo $?
     1

regresses to silent failure.

Hmm, indeed. :/ Fortunately the fix is simple:

util/qemu-option.c +0 -0
index fcd1119a5d..5a3c287611 100644
@@ -947,10 +947,10 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,
     bool help_wanted = false;
 
     opts = opts_parse(list, params, permit_abbrev, false, 

&help_wanted, &err);
- if (err) {
+ if (!opts) {

+        assert(!!err + !!help_wanted == 1);
         if (help_wanted) {
             qemu_opts_print_help(list, true);
-            error_free(err);
         } else {
             error_report_err(err);
         }

I've queued 1 and 3 since they were reviewed already and are fixes for tests. I'll run these two through the whole CI and repost.

Paolo

#7 lore raw

PATCH 3/4 qtest: escape device name in device-introspect-test

In reply to Paolo Bonzini

device-introspect-test uses HMP, so it should escape the device name properly. Because of this, a few devices that had commas in their names were escaping testing.

---
 tests/qtest/device-introspect-test.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tests/qtest/device-introspect-test.c +6 -3
index 9f22340ee5..f471b0e0dd 100644
@@ -104,7 +104,9 @@ static QList *device_type_list(QTestState *qts, bool abstract)
 static void test_one_device(QTestState *qts, const char *type)
 {
     QDict *resp;
-    char *help;
+    g_autofree char *help;
+    g_autofree GRegex *comma;
+    g_autofree char *escaped;
 
     g_test_message("Testing device '%s'", type);
 
@@ -113,8 +115,9 @@ static void test_one_device(QTestState *qts, const char *type)
                type);
     qobject_unref(resp);
 
-    help = qtest_hmp(qts, "device_add \"%s,help\"", type);
-    g_free(help);
+    comma = g_regex_new(",", 0, 0, NULL);
+    escaped = g_regex_replace_literal(comma, type, -1, 0, ",,", 0, NULL);
+    help = qtest_hmp(qts, "device_add \"%s,help\"", escaped);
 }
 
 static void test_device_intro_list(void)
Signature · 1 line
2.26.2
#8 lore raw

Re: [PATCH for-5.2 3/4] qtest: escape device name in device-introspect-test

Quoted 25 lines · Paolo Bonzini

device-introspect-test uses HMP, so it should escape the device name properly. Because of this, a few devices that had commas in their names were escaping testing.

---
 tests/qtest/device-introspect-test.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tests/qtest/device-introspect-test.c +3 -1
index 9f22340ee5..f471b0e0dd 100644
@@ -104,7 +104,9 @@ static QList *device_type_list(QTestState *qts, bool abstract)
 static void test_one_device(QTestState *qts, const char *type)
 {
     QDict *resp;
-    char *help;
+    g_autofree char *help;
+    g_autofree GRegex *comma;
+    g_autofree char *escaped;
 
     g_test_message("Testing device '%s'", type);
 

tests/qtest/device-introspect-test.c static void test_one_device(QTestState *qts, const char *type) · line 121

Quoted 9 lines
tests/qtest/device-introspect-test.c +3 -2
@@ -113,8 +115,9 @@ static void test_one_device(QTestState *qts, const char *type)
                type);
     qobject_unref(resp);
 
-    help = qtest_hmp(qts, "device_add \"%s,help\"", type);
-    g_free(help);
+    comma = g_regex_new(",", 0, 0, NULL);
+    escaped = g_regex_replace_literal(comma, type, -1, 0, ",,", 0, NULL);
+    help = qtest_hmp(qts, "device_add \"%s,help\"", escaped);
 }

Having "help =" as final statement now, this looks somewhat weird at a first glance (until you look at the g_autofree at the beginning of the function). Maybe it's better to drop the help variable completely and just do:
g_free(gtest_hmp(...)) ?

Thomas

#9 lore raw

Re: [PATCH for-5.2 3/4] qtest: escape device name in device-introspect-test

I will just drop autofree usage completely, also because valgrind showed that GRegex does not support it and apparently is leaked.

Paolo

Il mer 4 nov 2020, 08:44 Thomas Huth <[email protected]> ha scritto:

Quoted 49 lines · Paolo Bonzini

Review

Quoted 10 lines

device-introspect-test uses HMP, so it should escape the device name properly. Because of this, a few devices that had commas in their names were escaping testing.

---
 tests/qtest/device-introspect-test.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/tests/qtest/device-introspect-test.c

tests/qtest/device-introspect-test.c static QList *device_type_list(QTestState *qts, bool

Quoted 4 lines

index 9f22340ee5..f471b0e0dd 100644

tests/qtest/device-introspect-test.c +0 -0
@@ -104,7 +104,9 @@ static QList *device_type_list(QTestState *qts, bool

abstract)

tests/qtest/device-introspect-test.c static void test_one_device(QTestState *qts, const

Quoted 11 lines
tests/qtest/device-introspect-test.c +3 -1
 static void test_one_device(QTestState *qts, const char *type)
 {
     QDict *resp;
-    char *help;
+    g_autofree char *help;
+    g_autofree GRegex *comma;
+    g_autofree char *escaped;
 
     g_test_message("Testing device '%s'", type);
 
@@ -113,8 +115,9 @@ static void test_one_device(QTestState *qts, const

char *type)

tests/qtest/device-introspect-test.c static void test_one_device(QTestState *qts, const char *type)

Quoted 7 lines
tests/qtest/device-introspect-test.c +2 -2
                type);
     qobject_unref(resp);
 
-    help = qtest_hmp(qts, "device_add \"%s,help\"", type);
-    g_free(help);
+    comma = g_regex_new(",", 0, 0, NULL);
+    escaped = g_regex_replace_literal(comma, type, -1, 0, ",,", 0,

NULL);

tests/qtest/device-introspect-test.c static void test_one_device(QTestState *qts, const char *type) · line 121

Quoted 2 lines
tests/qtest/device-introspect-test.c +1 -0
+    help = qtest_hmp(qts, "device_add \"%s,help\"", escaped);
 }

Having "help =" as final statement now, this looks somewhat weird at a first
glance (until you look at the g_autofree at the beginning of the function). Maybe it's better to drop the help variable completely and just do:
g_free(gtest_hmp(...)) ?

Thomas

#10 lore raw

Re: [PATCH for-5.2 3/4] qtest: escape device name in device-introspect-test

In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

device-introspect-test uses HMP, so it should escape the device name properly. Because of this, a few devices that had commas in their names were escaping testing.

$ git-grep '\.name *= *"[^"]*,' | cat
hw/block/fdc.c:    .name          = "SUNW,fdtwo"

Any others?

#11 lore raw

Re: [PATCH for-5.2 3/4] qtest: escape device name in device-introspect-test

Quoted 11 lines · Markus Armbruster
Quoted 4 lines · Paolo Bonzini

device-introspect-test uses HMP, so it should escape the device name properly. Because of this, a few devices that had commas in their names were escaping testing.

$ git-grep '\.name *= *"[^"]*,' | cat
hw/block/fdc.c:    .name          = "SUNW,fdtwo"

Any others?

Not that I know, but this is a bug anyway. :)

Paolo

#12 lore raw

Re: [PATCH for-5.2 3/4] qtest: escape device name in device-introspect-test

Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Paolo Bonzini

device-introspect-test uses HMP, so it should escape the device name properly. Because of this, a few devices that had commas in their names were escaping testing.

Quoted 5 lines
Quoted 3 lines
$ git-grep '\.name *= *"[^"]*,' | cat
hw/block/fdc.c:    .name          = "SUNW,fdtwo"
Any others?

Not that I know, but this is a bug anyway. :)

Yes, but "a few devices" made me curious.

#13 lore raw

PATCH 4/4 qemu-option: warn for short-form boolean options

In reply to Paolo Bonzini

Options such as "server" or "nowait", that are commonly found in -chardev, are sugar for "server=on" and "wait=off". This is quite surprising and also does not have any notion of typing attached. It is even possible to do "-device e1000,noid" and get a device with "id=off".

Deprecate all this, except for -chardev and -spice where it is in wide use.

---
 chardev/char.c             |  1 +
 docs/system/deprecated.rst |  7 +++++++
 include/qemu/option.h      |  1 +
 tests/test-qemu-opts.c     |  1 +
 ui/spice-core.c            |  1 +
 util/qemu-option.c         | 22 +++++++++++++++-------
 6 files changed, 26 insertions(+), 7 deletions(-)
chardev/char.c +1 -0
index 78553125d3..108da615df 100644
@@ -829,6 +829,7 @@ Chardev *qemu_chr_find(const char *name)
 
 QemuOptsList qemu_chardev_opts = {
     .name = "chardev",
+    .allow_flag_options = true, /* server, nowait, etc. */
     .implied_opt_name = "backend",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
     .desc = {
docs/system/deprecated.rst +7 -0
index 32a0e620db..0e7edf7e56 100644
@@ -146,6 +146,13 @@ Drives with interface types other than ``if=none`` are for onboard
 devices.  It is possible to use drives the board doesn't pick up with
 -device.  This usage is now deprecated.  Use ``if=none`` instead.
 
+Short-form boolean options (since 5.2)
+''''''''''''''''''''''''''''''''''''''
+
+Boolean options such as ``share=on``/``share=off`` can be written
+in short form as ``share`` and ``noshare``.  This is deprecated
+for all command-line options except ``-chardev` and ``-spice``, for
+which the short form was in wide use.
 
 QEMU Machine Protocol (QMP) commands
 ------------------------------------
include/qemu/option.h +1 -0
index ac69352e0e..046ac06a1f 100644
@@ -65,6 +65,7 @@ struct QemuOptsList {
     const char *name;
     const char *implied_opt_name;
     bool merge_lists;  /* Merge multiple uses of option into a single list? */
+    bool allow_flag_options; /* Whether to warn for short-form boolean options */
     QTAILQ_HEAD(, QemuOpts) head;
     QemuOptDesc desc[];
 };
tests/test-qemu-opts.c +1 -0
index 297ffe79dd..a74c475773 100644
@@ -77,6 +77,7 @@ static QemuOptsList opts_list_02 = {
 static QemuOptsList opts_list_03 = {
     .name = "opts_list_03",
     .implied_opt_name = "implied",
+    .allow_flag_options = true,
     .head = QTAILQ_HEAD_INITIALIZER(opts_list_03.head),
     .desc = {
         /* no elements => accept any params */
ui/spice-core.c +1 -0
index eea52f5389..08f834fa41 100644
@@ -397,6 +397,7 @@ static SpiceChannelList *qmp_query_spice_channels(void)
 
 static QemuOptsList qemu_spice_opts = {
     .name = "spice",
+    .allow_flag_options = true, /* disable-agent-file-xfer, sasl, unix, etc. */
     .head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head),
     .merge_lists = true,
     .desc = {
util/qemu-option.c +15 -7
index 5824b7afe2..8b6050fbf7 100644
@@ -779,16 +779,19 @@ void qemu_opts_print(QemuOpts *opts, const char *separator)
 
 static const char *get_opt_name_value(const char *params,
                                       const char *firstname,
+                                      bool warn_on_flag,
                                       bool *help_wanted,
                                       char **name, char **value)
 {
     const char *p;
+    const char *prefix = "";
     size_t len;
 
     len = strcspn(params, "=,");
     if (params[len] != '=') {
         if (help_wanted && starts_with_help_option(params) == len) {
             *help_wanted = true;
+            warn_on_flag = false;
         }
         /* found "foo,more" */
         if (firstname) {
@@ -801,9 +804,14 @@ static const char *get_opt_name_value(const char *params,
             if (strncmp(*name, "no", 2) == 0) {
                 memmove(*name, *name + 2, strlen(*name + 2) + 1);
                 *value = g_strdup("off");
+                prefix = "no";
             } else {
                 *value = g_strdup("on");
             }
+            if (warn_on_flag) {
+                error_report("short-form boolean option '%s%s' deprecated", prefix, *name);
+                error_printf("Please use %s=%s instead\n", *name, *value);
+            }
         }
     } else {
         /* found "foo=bar,more" */
@@ -822,14 +830,14 @@ static const char *get_opt_name_value(const char *params,
 
 static bool opts_do_parse(QemuOpts *opts, const char *params,
                           const char *firstname, bool prepend,
-                          bool *help_wanted, Error **errp)
+                          bool warn_on_flag, bool *help_wanted, Error **errp)
 {
     char *option, *value;
     const char *p;
     QemuOpt *opt;
 
     for (p = params; *p;) {
-        p = get_opt_name_value(p, firstname, help_wanted, &option, &value);
+        p = get_opt_name_value(p, firstname, warn_on_flag, help_wanted, &option, &value);
         if (help_wanted && *help_wanted) {
             return false;
         }
@@ -858,7 +866,7 @@ static char *opts_parse_id(const char *params)
     char *name, *value;
 
     for (p = params; *p;) {
-        p = get_opt_name_value(p, NULL, NULL, &name, &value);
+        p = get_opt_name_value(p, NULL, false, NULL, &name, &value);
         if (!strcmp(name, "id")) {
             g_free(name);
             return value;
@@ -877,7 +885,7 @@ bool has_help_option(const char *params)
     bool ret = false;
 
     for (p = params; *p;) {
-        p = get_opt_name_value(p, NULL, &ret, &name, &value);
+        p = get_opt_name_value(p, NULL, false, &ret, &name, &value);
         g_free(name);
         g_free(value);
         if (ret) {
@@ -897,7 +905,7 @@ bool has_help_option(const char *params)
 bool qemu_opts_do_parse(QemuOpts *opts, const char *params,
                        const char *firstname, Error **errp)
 {
-    return opts_do_parse(opts, params, firstname, false, NULL, errp);
+    return opts_do_parse(opts, params, firstname, false, false, NULL, errp);
 }
 
 static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
@@ -925,8 +933,8 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
         return NULL;
     }
 
-    if (!opts_do_parse(opts, params, firstname, defaults, help_wanted,
-                       errp)) {
+    if (!opts_do_parse(opts, params, firstname, defaults,
+                       !list->allow_flag_options, help_wanted, errp)) {
         qemu_opts_del(opts);
         return NULL;
     }
Signature · 1 line
2.26.2
#14 lore raw

Re: [PATCH for-5.2 4/4] qemu-option: warn for short-form boolean options

Quoted 35 lines · Paolo Bonzini

Options such as "server" or "nowait", that are commonly found in -chardev, are sugar for "server=on" and "wait=off". This is quite surprising and also does not have any notion of typing attached. It is even possible to do "-device e1000,noid" and get a device with "id=off".

Deprecate all this, except for -chardev and -spice where it is in wide use.

---
 chardev/char.c             |  1 +
 docs/system/deprecated.rst |  7 +++++++
 include/qemu/option.h      |  1 +
 tests/test-qemu-opts.c     |  1 +
 ui/spice-core.c            |  1 +
 util/qemu-option.c         | 22 +++++++++++++++-------
 6 files changed, 26 insertions(+), 7 deletions(-)
chardev/char.c +1 -0
index 78553125d3..108da615df 100644
@@ -829,6 +829,7 @@ Chardev *qemu_chr_find(const char *name)
 
 QemuOptsList qemu_chardev_opts = {
     .name = "chardev",
+    .allow_flag_options = true, /* server, nowait, etc. */
     .implied_opt_name = "backend",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
     .desc = {
docs/system/deprecated.rst +0 -0
index 32a0e620db..0e7edf7e56 100644

docs/system/deprecated.rst Drives with interface types other than ``if=none`` are for onboard · line 155

Quoted 10 lines
docs/system/deprecated.rst +7 -0
@@ -146,6 +146,13 @@ Drives with interface types other than ``if=none`` are for onboard
 devices.  It is possible to use drives the board doesn't pick up with
 -device.  This usage is now deprecated.  Use ``if=none`` instead.
 
+Short-form boolean options (since 5.2)
+''''''''''''''''''''''''''''''''''''''
+
+Boolean options such as ``share=on``/``share=off`` can be written
+in short form as ``share`` and ``noshare``.  This is deprecated
+for all command-line options except ``-chardev` and ``-spice``, for
+which the short form was in wide use.

So IIUC, the short form was possible to use for absolutely /any/ boolean property ?

IMHO if we're going to deprecate short forms, we should do it universally including chardev and spice. Arguably spice/chardev are the most important ones to give an explicit warning about precisely because their widespread usage means a heads up is important to users. For chardev in particular it is possible we might end up wanting to wait longer than the usual 2 cycles before removal. So if we're serious about removing the short forms long term, the sooner we deprecate & warn the better for chardev.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#15 lore raw

Re: [PATCH for-5.2 4/4] qemu-option: warn for short-form boolean options

Quoted 10 lines · Daniel P. Berrangé

docs/system/deprecated.rst Drives with interface types other than ``if=none`` are for onboard · line 155

Quoted 7 lines
docs/system/deprecated.rst +7 -0
+Short-form boolean options (since 5.2)
+''''''''''''''''''''''''''''''''''''''
+
+Boolean options such as ``share=on``/``share=off`` can be written
+in short form as ``share`` and ``noshare``.  This is deprecated
+for all command-line options except ``-chardev` and ``-spice``, for
+which the short form was in wide use.

So IIUC, the short form was possible to use for absolutely /any/ boolean property ?

s/boolean// (yikes)

Quoted 5 lines

IMHO if we're going to deprecate short forms, we should do it universally including chardev and spice. Arguably spice/chardev are the most important ones to give an explicit warning about precisely because their widespread usage means a heads up is important to users.

Chardevs will probably become user-creatable objects; for -spice I was hoping that it would be QAPIfied as "-display spice" which does not support short forms, but I'm not sure if Gerd agrees. In both cases, the problem would be taken care of in a different way.

I can certainly warn for all of them, but I was thinking of the lowest-impact option for 5.2 since we're already in soft freeze.

Paolo

#16 lore raw

Re: [PATCH for-5.2 4/4] qemu-option: warn for short-form boolean options

Quoted 12 lines · Paolo Bonzini
Quoted 10 lines · Daniel P. Berrangé

docs/system/deprecated.rst Drives with interface types other than ``if=none`` are for onboard · line 155

Quoted 7 lines
docs/system/deprecated.rst +7 -0
+Short-form boolean options (since 5.2)
+''''''''''''''''''''''''''''''''''''''
+
+Boolean options such as ``share=on``/``share=off`` can be written
+in short form as ``share`` and ``noshare``.  This is deprecated
+for all command-line options except ``-chardev` and ``-spice``, for
+which the short form was in wide use.

So IIUC, the short form was possible to use for absolutely /any/ boolean property ?

Quoted 1 line

s/boolean// (yikes)

Yup. "-device virtio-blk,drive=blk0,serial" gives you the lovely serial number "on".

Quoted 10 lines
Quoted 5 lines

IMHO if we're going to deprecate short forms, we should do it universally including chardev and spice. Arguably spice/chardev are the most important ones to give an explicit warning about precisely because their widespread usage means a heads up is important to users.

Chardevs will probably become user-creatable objects; for -spice I was hoping that it would be QAPIfied as "-display spice" which does not support short forms, but I'm not sure if Gerd agrees. In both cases, the problem would be taken care of in a different way.

Taken care of only if we deprecate -chardev and -spice wholesale, not if we keep them forever as sugar for -object.

Quoted 2 lines

I can certainly warn for all of them, but I was thinking of the lowest-impact option for 5.2 since we're already in soft freeze.

I'm quite interested in getting rid of this sugar. I'm not particular on how exactly, and I understand your reluctance to mess with 5.2.

#17 lore raw

Re: [PATCH for-5.2 4/4] qemu-option: warn for short-form boolean options

In reply to Daniel P. Berrangé
Quoted 50 lines · On Tue, 3 Nov 2020 16:08:43 +0000 Daniel P. Berrangé <[email protected]>…
Quoted 35 lines · Paolo Bonzini

Options such as "server" or "nowait", that are commonly found in -chardev, are sugar for "server=on" and "wait=off". This is quite surprising and also does not have any notion of typing attached. It is even possible to do "-device e1000,noid" and get a device with "id=off".

Deprecate all this, except for -chardev and -spice where it is in wide use.

---
 chardev/char.c             |  1 +
 docs/system/deprecated.rst |  7 +++++++
 include/qemu/option.h      |  1 +
 tests/test-qemu-opts.c     |  1 +
 ui/spice-core.c            |  1 +
 util/qemu-option.c         | 22 +++++++++++++++-------
 6 files changed, 26 insertions(+), 7 deletions(-)
chardev/char.c +1 -0
index 78553125d3..108da615df 100644
@@ -829,6 +829,7 @@ Chardev *qemu_chr_find(const char *name)
 
 QemuOptsList qemu_chardev_opts = {
     .name = "chardev",
+    .allow_flag_options = true, /* server, nowait, etc. */
     .implied_opt_name = "backend",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
     .desc = {
docs/system/deprecated.rst +0 -0
index 32a0e620db..0e7edf7e56 100644

docs/system/deprecated.rst Drives with interface types other than ``if=none`` are for onboard · line 155

Quoted 10 lines
docs/system/deprecated.rst +7 -0
@@ -146,6 +146,13 @@ Drives with interface types other than ``if=none`` are for onboard
 devices.  It is possible to use drives the board doesn't pick up with
 -device.  This usage is now deprecated.  Use ``if=none`` instead.
 
+Short-form boolean options (since 5.2)
+''''''''''''''''''''''''''''''''''''''
+
+Boolean options such as ``share=on``/``share=off`` can be written
+in short form as ``share`` and ``noshare``.  This is deprecated
+for all command-line options except ``-chardev` and ``-spice``, for
+which the short form was in wide use.  

So IIUC, the short form was possible to use for absolutely /any/ boolean property ?

Quoted 9 lines

IMHO if we're going to deprecate short forms, we should do it universally including chardev and spice. Arguably spice/chardev are the most important ones to give an explicit warning about precisely because their widespread usage means a heads up is important to users. For chardev in particular it is possible we might end up wanting to wait longer than the usual 2 cycles before removal. So if we're serious about removing the short forms long term, the sooner we deprecate & warn the better for chardev.

shall we also deprecate short forms for -cpu model,[feat|+feat|-feat] and in the end allow only -device compatible form i.e. -cpu type,feat=[on|off]

that would let us drop custom
x86_cpu_parse_featurestr,
ppc_cpu_parse_featurestr,
sparc_cpu_parse_features

and a bunch of cpu_class_by_name, where almost each target does its magic conversion of cpu_model to the type (which ranges from various prefix/suffix shuffling to completely ignoring cpu_model and returning a fixed cpu type)

Quoted 2 lines

Regards,
Daniel

#18 lore raw

Re: [PATCH for-5.2 4/4] qemu-option: warn for short-form boolean options

Quoted 8 lines · Igor Mammedov

shall we also deprecate short forms for -cpu model,[feat|+feat|-feat] and in the end allow only -device compatible form i.e. -cpu type,feat=[on|off]

that would let us drop custom
x86_cpu_parse_featurestr,
ppc_cpu_parse_featurestr,
sparc_cpu_parse_features

Quoted 4 lines

and a bunch of cpu_class_by_name, where almost each target does its magic conversion of cpu_model to the type (which ranges from various prefix/suffix shuffling to completely ignoring cpu_model and returning a fixed cpu type)

Yes please. :) But I would prefer someone else to do the work because I have quite some KVM backlog...

Paolo

#19 lore raw

Re: [PATCH for-5.2 4/4] qemu-option: warn for short-form boolean options

Quoted 9 lines · On Tue, 3 Nov 2020 22:41:40 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 8 lines · Igor Mammedov

shall we also deprecate short forms for -cpu model,[feat|+feat|-feat] and in the end allow only -device compatible form i.e. -cpu type,feat=[on|off]

that would let us drop custom
x86_cpu_parse_featurestr,
ppc_cpu_parse_featurestr,
sparc_cpu_parse_features

Quoted 8 lines
Quoted 4 lines

and a bunch of cpu_class_by_name, where almost each target does its magic conversion of cpu_model to the type (which ranges from various prefix/suffix shuffling to completely ignoring cpu_model and returning a fixed cpu type)

Yes please. :) But I would prefer someone else to do the work because I have quite some KVM backlog...

I'll look into it.

Quoted 3 lines

Paolo

#20 lore raw
In reply to Paolo Bonzini
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH for-5.2 0/4] deprecate short-form boolean options

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
1b42d99 qemu-option: warn for short-form boolean options 9927d00 qtest: escape device name in device-introspect-test dd427b7 qemu-option: move help handling to get_opt_name_value e1273b2 ivshmem-test: do not use short-form boolean option

=== OUTPUT BEGIN ===
1/4 Checking commit e1273b2eab2e (ivshmem-test: do not use short-form boolean option) 2/4 Checking commit dd427b742e3b (qemu-option: move help handling to get_opt_name_value) 3/4 Checking commit 9927d0090494 (qtest: escape device name in device-introspect-test) 4/4 Checking commit 1b42d9947c18 (qemu-option: warn for short-form boolean options)
WARNING: line over 80 characters
#56: FILE: include/qemu/option.h:68:
+ bool allow_flag_options; /* Whether to warn for short-form boolean options */

ERROR: line over 90 characters
#117: FILE: util/qemu-option.c:812:
+ error_report("short-form boolean option '%s%s' deprecated", prefix, *name);

WARNING: line over 80 characters
#136: FILE: util/qemu-option.c:840:
+ p = get_opt_name_value(p, firstname, warn_on_flag, help_wanted, &option, &value);

total: 1 errors, 2 warnings, 124 lines checked

Patch 4/4 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]