Skip to contentSkip to conversation

object: Add 'help' option for all available backends and properties

PATCH Nutaro, James J. 1 participant 1 message Dec 2, 2016

lore
Share & tools
lore
#0 lore raw

Hi Lin,

My comments are inline with the patch.

ping...

Quoted 1 line
Quoted 1 line
Quoted 1 line

Lin Ma <address@hidden> 2016/10/20 星期四 下午 7:28 >>>

'-object help' prints available user creatable backends. '-object $typename,help' prints relevant properties.

---
include/qom/object_interfaces.h | 2 ++
qemu-options.hx | 7 +++++-
qom/object_interfaces.c | 55 +++++++++++++++++++++++++++++++++++++++++
vl.c | 5 ++++

4 files changed, 68 insertions(+), 1 deletion(-)
include/qom/object_interfaces.h +0 -0
index 8b17f4d..197cd5f 100644
@@ -165,4 +165,6 @@ int user_creatable_add_opts_foreach(void *opaque,
  */

void user_creatable_del(const char *id, Error **errp);

+int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp); +
#endif

qemu-options.hx +0 -0
index b1fbdb0..b9573ce 100644
@@ -3761,7 +3761,9 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
         "                          create a new object of type TYPENAME 

setting properties\n"
" in the order they are specified. Note that
the 'id'\n"
" property must be set. These objects are
placed in the\n"

-    "                     '/objects' path.\n",
+    "                     '/objects' path.\n"
+    "                     Use '-object help' to print available backend types 

and\n"
+ " '-object typename,help' to print relevant
properties.\n",
QEMU_ARCH_ALL)
STEXI
@item -object @var{typename}[,@address@hidden,...]
@@ -3771,6 +3773,9 @@ in the order they are specified. Note that the 'id' property must be set. These objects are placed in the '/objects' path.

+Use @code{-object help} to print available backend types and address@hidden @var{typename},help} to print relevant properties. +
@table @option

@item -object memory-backend-file,address@hidden,address@hidden,address@hidden,address@hidden|off}

qom/object_interfaces.c +0 -0
index bf59846..da8be39 100644
@@ -5,6 +5,7 @@

#include "qapi-visit.h"
#include "qapi/qmp-output-visitor.h"
#include "qapi/opts-visitor.h"
+#include "qemu/help_option.h"

void user_creatable_complete(Object *obj, Error **errp)
{
@@ -212,6 +213,60 @@ void user_creatable_del(const char *id, Error **errp)

         object_unparent(obj);
}

+int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp) +{

+    const char *type = NULL;
+    Object *obj = NULL;
+    ObjectClass *klass;
+    ObjectProperty *prop;
+    ObjectPropertyIterator iter;
+
+    type = qemu_opt_get(opts, "qom-type");
+    if (type && is_help_option(type)) {
+           GSList *list;
+           printf("Available object backend types:\n");
+           for (list = object_class_get_list(TYPE_USER_CREATABLE, false);  \
+                           list;                                               
                                                  \
+                           list = list->next) {
+                   const char *name;
+                   name = object_class_get_name(OBJECT_CLASS(list->data));
+                   if (strcmp(name, TYPE_USER_CREATABLE)) {
+                           printf("%s\n", name);
+                   }
+           }
+           g_slist_free(list);
+           goto out;

+ }
+

Is obj == NULL at this call to goto out? If so, you could simply return 1.

+ if (!type || !qemu_opt_has_help_opt(opts)) {
+ return 0;
+ }
+
+ klass = object_class_by_name(type);
+ if (!klass) {
+ printf("invalid object type: %s\n", type);
+ goto out;
+ }

If obj == NULL here too?

+ if (object_class_is_abstract(klass)) {
+ printf("object type '%s' is abstract\n", type);
+ goto out;
+ }

And here?

+ obj = object_new(type);

If this is the only place that obj is set to a non-NULL value, then the goto calls above can be replaced with returns.

+ object_property_iter_init(&iter, obj);
+
+ while ((prop = object_property_iter_next(&iter))) {
+ if (prop->description) {
+ printf("%s (%s, %s)\n", prop->name, prop->type,
prop->description);
+ } else {
+ printf("%s (%s)\n", prop->name, prop->type);
+ }
+ }
+
+out:
+ object_unref(obj);
+ return 1;
+}
+

static void register_types(void)

{
         static const TypeInfo uc_interface_info = {
vl.c +0 -0
index ebd47af..145

6eca 100644

vl.c +5 -0
@@ -4100,6 +4100,11 @@ int main(int argc, char **argv, char **envp)
                 exit(0);
         }
 
+    if (qemu_opts_foreach(qemu_find_opts("object"), user_creatable_help_func,
+                                                 NULL, NULL)) {
+           exit(1);
+    }
+
         if (!trace_init_backends()) {
                 exit(1);
         }
Signature · 1 line
2.9.2