Skip to contentSkip to conversation

qemu-img/io/nbd: Support help options for --object

PATCH In review Kevin Wolf 2 participants 12 messages Oct 11, 2019 – Oct 14, 2019

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/4 vl: Split off user_creatable_print_help()

In reply to Kevin Wolf

Printing help for --object is something that we don't only want in the system emulator, but also in tools that support --object. Move it into a separate function in qom/object_interfaces.c to make the code accessible for tools.

---
 include/qom/object_interfaces.h | 12 +++++++
 qom/object_interfaces.c         | 61 +++++++++++++++++++++++++++++++++
 vl.c                            | 52 +---------------------------
 3 files changed, 74 insertions(+), 51 deletions(-)
include/qom/object_interfaces.h +12 -0
index 682ba1d9b0..3e4e1d928b 100644
@@ -132,6 +132,18 @@ typedef bool (*user_creatable_add_opts_predicate)(const char *type);
 int user_creatable_add_opts_foreach(void *opaque,
                                     QemuOpts *opts, Error **errp);
 
+/**
+ * user_creatable_print_help:
+ * @type: the QOM type to be added
+ * @opts: options to create
+ *
+ * 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.
+ */
+bool user_creatable_print_help(const char *type, QemuOpts *opts);
+
 /**
  * user_creatable_del:
  * @id: the unique ID for the object
qom/object_interfaces.c +61 -0

75 lines not on this page · raw message

vl.c +1 -51

58 lines not on this page · raw message

Signature · 1 line
2.20.1

Kevin Wolf

author
#0 lore raw

cover qemu-img/io/nbd: Support help options for --object

This series fixes that the tools don't consider help options for --object and just treat them as regular object properties. For example:

    $ ./qemu-io --object secret,help
    qemu-io: Parameter 'id' is missing

With these patches, we get the expected behaviour like in the system emulator.

Kevin Wolf (4):
vl: Split off user_creatable_print_help()
qemu-io: Support help options for --object
qemu-img: Support help options for --object
qemu-nbd: Support help options for --object

 include/qom/object_interfaces.h | 12 +++++++
 qemu-img.c                      | 34 +++++++++++-------
 qemu-io.c                       |  9 ++++-
 qemu-nbd.c                      |  9 ++++-
 qom/object_interfaces.c         | 61 +++++++++++++++++++++++++++++++++
 vl.c                            | 52 +---------------------------
 6 files changed, 111 insertions(+), 66 deletions(-)
Signature · 1 line
2.20.1
author
#5 lore raw

PATCH 2/4 qemu-io: Support help options for --object

Instead of parsing help options as normal object properties and returning an error, provide the same help functionality as the system emulator in qemu-io, too.

---
 qemu-io.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
qemu-io.c +8 -1
index f64eca6940..91e3276592 100644
@@ -475,6 +475,13 @@ static QemuOptsList qemu_object_opts = {
     },
 };
 
+static bool qemu_io_object_print_help(const char *type, QemuOpts *opts)
+{
+    if (user_creatable_print_help(type, opts)) {
+        exit(0);
+    }
+    return true;
+}
 
 static QemuOptsList file_opts = {
     .name = "file",
@@ -622,7 +629,7 @@ int main(int argc, char **argv)
 
     qemu_opts_foreach(&qemu_object_opts,
                       user_creatable_add_opts_foreach,
-                      NULL, &error_fatal);
+                      qemu_io_object_print_help, &error_fatal);
 
     if (!trace_init_backends()) {
         exit(1);
Signature · 1 line
2.20.1
author
#7 lore raw

PATCH 3/4 qemu-img: Support help options for --object

In reply to Kevin Wolf

Instead of parsing help options as normal object properties and returning an error, provide the same help functionality as the system emulator in qemu-img, too.

---
 qemu-img.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)
qemu-img.c +21 -13
index 384c6f38bc..8b03ef8171 100644
@@ -214,6 +214,14 @@ static QemuOptsList qemu_object_opts = {
     },
 };
 
+static bool qemu_img_object_print_help(const char *type, QemuOpts *opts)
+{
+    if (user_creatable_print_help(type, opts)) {
+        exit(0);
+    }
+    return true;
+}
+
 static QemuOptsList qemu_source_opts = {
     .name = "source",
     .implied_opt_name = "file",
@@ -516,7 +524,7 @@ static int img_create(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         goto fail;
     }
 
@@ -766,7 +774,7 @@ static int img_check(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         return 1;
     }
 
@@ -979,7 +987,7 @@ static int img_commit(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         return 1;
     }
 
@@ -1362,7 +1370,7 @@ static int img_compare(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         ret = 2;
         goto out4;
     }
@@ -2210,7 +2218,7 @@ static int img_convert(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         goto fail_getopt;
     }
 
@@ -2776,7 +2784,7 @@ static int img_info(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         return 1;
     }
 
@@ -3002,7 +3010,7 @@ static int img_map(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         return 1;
     }
 
@@ -3154,7 +3162,7 @@ static int img_snapshot(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         return 1;
     }
 
@@ -3321,7 +3329,7 @@ static int img_rebase(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         return 1;
     }
 
@@ -3742,7 +3750,7 @@ static int img_resize(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         return 1;
     }
 
@@ -3986,7 +3994,7 @@ static int img_amend(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         ret = -1;
         goto out_no_progress;
     }
@@ -4630,7 +4638,7 @@ static int img_dd(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         ret = -1;
         goto out;
     }
@@ -4907,7 +4915,7 @@ static int img_measure(int argc, char **argv)
 
     if (qemu_opts_foreach(&qemu_object_opts,
                           user_creatable_add_opts_foreach,
-                          NULL, &error_fatal)) {
+                          qemu_img_object_print_help, &error_fatal)) {
         goto out;
     }
 
Signature · 1 line
2.20.1
author
#9 lore raw

PATCH 4/4 qemu-nbd: Support help options for --object

In reply to Kevin Wolf

Instead of parsing help options as normal object properties and returning an error, provide the same help functionality as the system emulator in qemu-nbd, too.

---
 qemu-nbd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
qemu-nbd.c +8 -1
index 9032b6de2a..caacf0ed73 100644
@@ -507,6 +507,13 @@ static QemuOptsList qemu_object_opts = {
     },
 };
 
+static bool qemu_nbd_object_print_help(const char *type, QemuOpts *opts)
+{
+    if (user_creatable_print_help(type, opts)) {
+        exit(0);
+    }
+    return true;
+}
 
 
 static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, bool list,
@@ -902,7 +909,7 @@ int main(int argc, char **argv)
 
     qemu_opts_foreach(&qemu_object_opts,
                       user_creatable_add_opts_foreach,
-                      NULL, &error_fatal);
+                      qemu_nbd_object_print_help, &error_fatal);
 
     if (!trace_init_backends()) {
         exit(1);
Signature · 1 line
2.20.1
Reviewed-by on v1 4/4
#10 lore raw

Re: [PATCH 4/4] qemu-nbd: Support help options for --object

Quoted 8 lines · Kevin Wolf

Instead of parsing help options as normal object properties and returning an error, provide the same help functionality as the system emulator in qemu-nbd, too.

---
  qemu-nbd.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)

Missing a change in qemu-nbd.texi for man page coverage. But the patch is a strict improvement, so even if we have to add a followup patch for documentation, I'm okay with:

This patch touches NBD, but I'm assuming it's easier to take the series through your tree.

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

Re: [PATCH 1/4] vl: Split off user_creatable_print_help()

In reply to Kevin Wolf
Quoted 1 line · Kevin Wolf

Printing help for --object is something that we don't only want in the

s/don't/not/

Quoted 13 lines

system emulator, but also in tools that support --object. Move it into a separate function in qom/object_interfaces.c to make the code accessible for tools.

---
  include/qom/object_interfaces.h | 12 +++++++
  qom/object_interfaces.c         | 61 +++++++++++++++++++++++++++++++++
  vl.c                            | 52 +---------------------------
  3 files changed, 74 insertions(+), 51 deletions(-)
include/qom/object_interfaces.h +0 -0
index 682ba1d9b0..3e4e1d928b 100644

include/qom/object_interfaces.h

Quoted 1 line
include/qom/object_interfaces.h +0 -1
--- a/include/qom/object_interfaces.h
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v1 3/4
#8 lore raw

Re: [PATCH 3/4] qemu-img: Support help options for --object

In reply to Kevin Wolf
Quoted 9 lines · Kevin Wolf

Instead of parsing help options as normal object properties and returning an error, provide the same help functionality as the system emulator in qemu-img, too.

---
  qemu-img.c | 34 +++++++++++++++++++++-------------
  1 file changed, 21 insertions(+), 13 deletions(-)

Missing man page documentation of this new feature. Perhaps iotest coverage is also warranted? (qemu-io is only for testing purposes, so I don't care about that in patch 2 as much as I do here)

But the patch itself is a strict improvement, so

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

Re: [PATCH 2/4] qemu-io: Support help options for --object

In reply to Kevin Wolf
Quoted 9 lines · Kevin Wolf

Instead of parsing help options as normal object properties and returning an error, provide the same help functionality as the system emulator in qemu-io, too.

---
  qemu-io.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
author
#11 lore raw

Re: [PATCH 4/4] qemu-nbd: Support help options for --object

In reply to Eric Blake

Am 11.10.2019 um 23:39 hat Eric Blake geschrieben:

Quoted 8 lines · Kevin Wolf
Quoted 5 lines

Instead of parsing help options as normal object properties and returning an error, provide the same help functionality as the system emulator in qemu-nbd, too.

Missing a change in qemu-nbd.texi for man page coverage.

Hm... Both qemu-img and qemu-nbd manpages refer to qemu(1) for the details. I wouldn't mind copying the text for '-object help' from there anyway, but unfortunately it doesn't even exist. :-)

So this looks like a separate patch that fixes it for qemu, too.

Quoted 7 lines

But the patch is a strict improvement, so even if we have to add a followup patch for documentation, I'm okay with:

This patch touches NBD, but I'm assuming it's easier to take the series through your tree.

Yes, thanks.

Kevin

author
#3 lore raw

Re: [PATCH 1/4] vl: Split off user_creatable_print_help()

In reply to Eric Blake

Am 11.10.2019 um 23:35 hat Eric Blake geschrieben:

Quoted 4 lines · Kevin Wolf
Quoted 1 line

Printing help for --object is something that we don't only want in the

s/don't/not/

Can someone send a fix for the English grammar? It's obviously broken and doesn't know what it wants. Actually, maybe do-support was a bad idea and we should just revert it and restore consistent use of proper verb-second word order?

(Hm, actually, since this seems to negate "only" rather than the verb, does "...that we want not only in..." work without patching the grammar?)

(Thanks for the correction.)

Kevin

Quoted 5 lines
Quoted 5 lines

system emulator, but also in tools that support --object. Move it into a separate function in qom/object_interfaces.c to make the code accessible for tools.

#4 lore raw

Re: [PATCH 1/4] vl: Split off user_creatable_print_help()

Quoted 10 lines · Kevin Wolf

Am 11.10.2019 um 23:35 hat Eric Blake geschrieben:

Quoted 4 lines · Kevin Wolf
Quoted 1 line

Printing help for --object is something that we don't only want in the

s/don't/not/

Can someone send a fix for the English grammar? It's obviously broken and doesn't know what it wants. Actually, maybe do-support was a bad idea and we should just revert it and restore consistent use of proper verb-second word order?

Lol

Quoted 4 lines

(Hm, actually, since this seems to negate "only" rather than the verb, does "...that we want not only in..." work without patching the grammar?)

Yes, that formulation also works.

Quoted 10 lines

(Thanks for the correction.)

Kevin

Quoted 5 lines
Quoted 5 lines

system emulator, but also in tools that support --object. Move it into a separate function in qom/object_interfaces.c to make the code accessible for tools.

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