From patchwork Thu Oct 20 11:28:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 684560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3t06Gr5NZNz9s3v for ; Thu, 20 Oct 2016 22:37:08 +1100 (AEDT) Received: from localhost ([::1]:54022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxBej-0003nb-MG for incoming@patchwork.ozlabs.org; Thu, 20 Oct 2016 07:37:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxBXM-0004ta-DB for qemu-devel@nongnu.org; Thu, 20 Oct 2016 07:29:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxBXD-0008Pq-6n for qemu-devel@nongnu.org; Thu, 20 Oct 2016 07:29:28 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:59354 helo=prv3-mh.provo.novell.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxBXC-0008PV-V2 for qemu-devel@nongnu.org; Thu, 20 Oct 2016 07:29:19 -0400 Received: from linux-xpcv.apac.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Thu, 20 Oct 2016 05:29:03 -0600 From: Lin Ma To: qemu-devel@nongnu.org Date: Thu, 20 Oct 2016 19:28:29 +0800 Message-Id: <20161020112829.14589-6-lma@suse.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20161020112829.14589-1-lma@suse.com> References: <20161020112829.14589-1-lma@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.26 Subject: [Qemu-devel] [PATCH v4 5/5] object: Add 'help' option for all available backends and properties X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, afaerber@suse.de, armbru@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" '-object help' prints available user creatable backends. '-object $typename,help' prints relevant properties. Signed-off-by: Lin Ma --- 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(-) diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h index 8b17f4d..197cd5f 100644 --- a/include/qom/object_interfaces.h +++ b/include/qom/object_interfaces.h @@ -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 diff --git a/qemu-options.hx b/qemu-options.hx index b1fbdb0..b9573ce 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -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}[,@var{prop1}=@var{value1},...] @@ -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 +@code{-object @var{typename},help} to print relevant properties. + @table @option @item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off} diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index bf59846..da8be39 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -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; + } + + 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 (object_class_is_abstract(klass)) { + printf("object type '%s' is abstract\n", type); + goto out; + } + obj = object_new(type); + 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 = { diff --git a/vl.c b/vl.c index ebd47af..1456eca 100644 --- a/vl.c +++ b/vl.c @@ -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); }