From patchwork Mon Sep 26 10:16:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lin Ma X-Patchwork-Id: 9350441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 319BF6077B for ; Mon, 26 Sep 2016 10:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21F6E2880C for ; Mon, 26 Sep 2016 10:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 165FB28ADF; Mon, 26 Sep 2016 10:17:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C209C2880C for ; Mon, 26 Sep 2016 10:17:53 +0000 (UTC) Received: from localhost ([::1]:43074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boSyu-0001bR-Rx for patchwork-qemu-devel@patchwork.kernel.org; Mon, 26 Sep 2016 06:17:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49318) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boSyG-0001YY-AZ for qemu-devel@nongnu.org; Mon, 26 Sep 2016 06:17:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1boSyB-0005Gq-TU for qemu-devel@nongnu.org; Mon, 26 Sep 2016 06:17:11 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:58163 helo=prv3-mh.provo.novell.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boSyB-0005Fn-Kz for qemu-devel@nongnu.org; Mon, 26 Sep 2016 06:17:07 -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); Mon, 26 Sep 2016 04:16:49 -0600 From: Lin Ma To: qemu-devel@nongnu.org Date: Mon, 26 Sep 2016 18:16:27 +0800 Message-Id: <20160926101627.14296-4-lma@suse.com> X-Mailer: git-send-email 2.9.2 In-Reply-To: <20160926101627.14296-1-lma@suse.com> References: <20160926101627.14296-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 v3 3/3] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP '-object help' prints available user creatable backends. '-object $typename,help' prints relevant properties. Signed-off-by: Lin Ma --- backends/hostmem.c | 4 ++++ crypto/secret.c | 4 ++++ crypto/tlscreds.c | 4 ++++ include/qom/object_interfaces.h | 2 ++ net/filter.c | 4 ++++ qemu-options.hx | 7 +++++- qom/object_interfaces.c | 48 +++++++++++++++++++++++++++++++++++++++++ vl.c | 5 +++++ 8 files changed, 77 insertions(+), 1 deletion(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index b7a208d..eea9dce 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -261,6 +261,10 @@ static void host_memory_backend_init(Object *obj) HostMemPolicy_lookup, host_memory_backend_get_policy, host_memory_backend_set_policy, NULL); + object_property_set_description(obj, "policy", + "Data format: one of " + HostMemPolicy_value_str, + &error_abort); } MemoryRegion * diff --git a/crypto/secret.c b/crypto/secret.c index 285ab7a..71d06e3 100644 --- a/crypto/secret.c +++ b/crypto/secret.c @@ -382,6 +382,10 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data) qcrypto_secret_prop_get_format, qcrypto_secret_prop_set_format, NULL); + object_class_property_set_description(oc, "format", + "Data format: one of " + QCryptoSecretFormat_value_str, + &error_abort); object_class_property_add_str(oc, "data", qcrypto_secret_prop_get_data, qcrypto_secret_prop_set_data, diff --git a/crypto/tlscreds.c b/crypto/tlscreds.c index a896553..d3af38a 100644 --- a/crypto/tlscreds.c +++ b/crypto/tlscreds.c @@ -237,6 +237,10 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data) qcrypto_tls_creds_prop_get_endpoint, qcrypto_tls_creds_prop_set_endpoint, NULL); + object_class_property_set_description(oc, "endpoint", + "Data format: one of " + QCryptoTLSCredsEndpoint_value_str, + &error_abort); object_class_property_add_str(oc, "priority", qcrypto_tls_creds_prop_get_priority, qcrypto_tls_creds_prop_set_priority, 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/net/filter.c b/net/filter.c index 1dfd2ca..205fb49 100644 --- a/net/filter.c +++ b/net/filter.c @@ -182,6 +182,10 @@ static void netfilter_init(Object *obj) NetFilterDirection_lookup, netfilter_get_direction, netfilter_set_direction, NULL); + object_property_set_description(obj, "queue", + "Data format: one of " + NetFilterDirection_value_str, + &error_abort); object_property_add_str(obj, "status", netfilter_get_status, netfilter_set_status, NULL); diff --git a/qemu-options.hx b/qemu-options.hx index 0b621bb..978d37b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3759,7 +3759,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},...] @@ -3769,6 +3771,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 9288242..70c1e44 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,53 @@ void user_creatable_del(const char *id, Error **errp) object_unparent(obj); } +int user_creatable_help_func(void *opaque, QemuOpts *opts, Error **errp) +{ + char *type = NULL; + Object *obj = NULL; + 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)); + printf("%s\n", name); + } + g_slist_free(list); + goto out; + } + + if (!type || !qemu_opt_has_help_opt(opts)) { + return 0; + } + + if (!object_class_by_name(type)) { + printf("invalid object type: %s\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: + g_free(type); + 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 215a6f9..c5ce7ea 100644 --- a/vl.c +++ b/vl.c @@ -4090,6 +4090,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); }