diff mbox series

[v2,12/12] vl: list user creatable properties when 'help' is argument

Message ID 20180907075948.26917-13-marcandre.lureau@redhat.com
State New
Headers show
Series Various qemu command line options help improvements | expand

Commit Message

Marc-André Lureau Sept. 7, 2018, 7:59 a.m. UTC
Iterate over the writable class properties, sort and print them out
with the description if available.

Ex: qemu -object memory-backend-file,help
memory-backend-file.align=int
memory-backend-file.discard-data=bool
memory-backend-file.dump=bool - Set to 'off' to exclude from core dump
memory-backend-file.host-nodes=int - Binds memory to the list of NUMA host nodes
memory-backend-file.mem-path=string
memory-backend-file.merge=bool - Mark memory as mergeable
memory-backend-file.pmem=bool
memory-backend-file.policy=HostMemPolicy - Set the NUMA policy
memory-backend-file.prealloc=bool - Preallocate memory
memory-backend-file.share=bool - Mark the memory as private to QEMU or shared
memory-backend-file.size=int - Size of the memory region (ex: 500M)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 qom/object_interfaces.c |  6 +++---
 vl.c                    | 40 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 6 deletions(-)

Comments

Eric Blake Sept. 7, 2018, 1:52 p.m. UTC | #1
On 09/07/2018 02:59 AM, Marc-André Lureau wrote:
> Iterate over the writable class properties, sort and print them out
> with the description if available.
> 
> Ex: qemu -object memory-backend-file,help
> memory-backend-file.align=int
> memory-backend-file.discard-data=bool
> memory-backend-file.dump=bool - Set to 'off' to exclude from core dump
> memory-backend-file.host-nodes=int - Binds memory to the list of NUMA host nodes
> memory-backend-file.mem-path=string
> memory-backend-file.merge=bool - Mark memory as mergeable
> memory-backend-file.pmem=bool
> memory-backend-file.policy=HostMemPolicy - Set the NUMA policy
> memory-backend-file.prealloc=bool - Preallocate memory
> memory-backend-file.share=bool - Mark the memory as private to QEMU or shared
> memory-backend-file.size=int - Size of the memory region (ex: 500M)
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   qom/object_interfaces.c |  6 +++---
>   vl.c                    | 40 +++++++++++++++++++++++++++++++++++++---
>   2 files changed, 40 insertions(+), 6 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>
Paolo Bonzini Oct. 3, 2018, 1:02 p.m. UTC | #2
On 07/09/2018 09:59, Marc-André Lureau wrote:
> Iterate over the writable class properties, sort and print them out
> with the description if available.
> 
> Ex: qemu -object memory-backend-file,help
> memory-backend-file.align=int
> memory-backend-file.discard-data=bool
> memory-backend-file.dump=bool - Set to 'off' to exclude from core dump
> memory-backend-file.host-nodes=int - Binds memory to the list of NUMA host nodes
> memory-backend-file.mem-path=string
> memory-backend-file.merge=bool - Mark memory as mergeable
> memory-backend-file.pmem=bool
> memory-backend-file.policy=HostMemPolicy - Set the NUMA policy
> memory-backend-file.prealloc=bool - Preallocate memory
> memory-backend-file.share=bool - Mark the memory as private to QEMU or shared
> memory-backend-file.size=int - Size of the memory region (ex: 500M)
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  qom/object_interfaces.c |  6 +++---
>  vl.c                    | 40 +++++++++++++++++++++++++++++++++++++---
>  2 files changed, 40 insertions(+), 6 deletions(-)
> 
> diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
> index 72b97a8bed..941fd63afd 100644
> --- a/qom/object_interfaces.c
> +++ b/qom/object_interfaces.c
> @@ -141,14 +141,14 @@ Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
>  
>  int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp)
>  {
> -    bool (*type_predicate)(const char *) = opaque;
> +    bool (*type_opt_predicate)(const char *, QemuOpts *) = opaque;
>      Object *obj = NULL;
>      Error *err = NULL;
>      const char *type;
>  
>      type = qemu_opt_get(opts, "qom-type");
> -    if (type && type_predicate &&
> -        !type_predicate(type)) {
> +    if (type && type_opt_predicate &&
> +        !type_opt_predicate(type, opts)) {
>          return 0;
>      }
>  
> diff --git a/vl.c b/vl.c
> index 71765a2982..880676ecc1 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2729,8 +2729,10 @@ static int machine_set_property(void *opaque,
>   * cannot be created here, as it depends on the chardev
>   * already existing.
>   */
> -static bool object_create_initial(const char *type)
> +static bool object_create_initial(const char *type, QemuOpts *opts)
>  {
> +    ObjectClass *klass;
> +
>      if (is_help_option(type)) {
>          GSList *l, *list;
>  
> @@ -2744,6 +2746,38 @@ static bool object_create_initial(const char *type)
>          exit(0);
>      }
>  
> +    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))) {
> +            GString *str;
> +
> +            if (!prop->set) {
> +                continue;
> +            }
> +
> +            str = g_string_new(NULL);
> +            g_string_append_printf(str, "%s.%s=%s", type,
> +                                   prop->name, prop->type);
> +            if (prop->description) {
> +                g_string_append_printf(str, " - %s", prop->description);
> +            }
> +            g_ptr_array_add(array, g_string_free(str, false));
> +        }
> +        g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp);
> +        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);
> +        exit(0);
> +    }
> +
>      if (g_str_equal(type, "rng-egd") ||
>          g_str_has_prefix(type, "pr-manager-")) {
>          return false;
> @@ -2790,9 +2824,9 @@ static bool object_create_initial(const char *type)
>   * The remainder of object creation happens after the
>   * creation of chardev, fsdev, net clients and device data types.
>   */
> -static bool object_create_delayed(const char *type)
> +static bool object_create_delayed(const char *type, QemuOpts *opts)
>  {
> -    return !object_create_initial(type);
> +    return !object_create_initial(type, opts);
>  }
>  
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox series

Patch

diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 72b97a8bed..941fd63afd 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -141,14 +141,14 @@  Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
 
 int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp)
 {
-    bool (*type_predicate)(const char *) = opaque;
+    bool (*type_opt_predicate)(const char *, QemuOpts *) = opaque;
     Object *obj = NULL;
     Error *err = NULL;
     const char *type;
 
     type = qemu_opt_get(opts, "qom-type");
-    if (type && type_predicate &&
-        !type_predicate(type)) {
+    if (type && type_opt_predicate &&
+        !type_opt_predicate(type, opts)) {
         return 0;
     }
 
diff --git a/vl.c b/vl.c
index 71765a2982..880676ecc1 100644
--- a/vl.c
+++ b/vl.c
@@ -2729,8 +2729,10 @@  static int machine_set_property(void *opaque,
  * cannot be created here, as it depends on the chardev
  * already existing.
  */
-static bool object_create_initial(const char *type)
+static bool object_create_initial(const char *type, QemuOpts *opts)
 {
+    ObjectClass *klass;
+
     if (is_help_option(type)) {
         GSList *l, *list;
 
@@ -2744,6 +2746,38 @@  static bool object_create_initial(const char *type)
         exit(0);
     }
 
+    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))) {
+            GString *str;
+
+            if (!prop->set) {
+                continue;
+            }
+
+            str = g_string_new(NULL);
+            g_string_append_printf(str, "%s.%s=%s", type,
+                                   prop->name, prop->type);
+            if (prop->description) {
+                g_string_append_printf(str, " - %s", prop->description);
+            }
+            g_ptr_array_add(array, g_string_free(str, false));
+        }
+        g_ptr_array_sort(array, (GCompareFunc)qemu_pstrcmp);
+        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);
+        exit(0);
+    }
+
     if (g_str_equal(type, "rng-egd") ||
         g_str_has_prefix(type, "pr-manager-")) {
         return false;
@@ -2790,9 +2824,9 @@  static bool object_create_initial(const char *type)
  * The remainder of object creation happens after the
  * creation of chardev, fsdev, net clients and device data types.
  */
-static bool object_create_delayed(const char *type)
+static bool object_create_delayed(const char *type, QemuOpts *opts)
 {
-    return !object_create_initial(type);
+    return !object_create_initial(type, opts);
 }