From patchwork Fri Dec 2 18:37:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "James J. Nutaro" X-Patchwork-Id: 9458955 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 D073F6074E for ; Fri, 2 Dec 2016 18:37:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7A652856E for ; Fri, 2 Dec 2016 18:37:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBC8228589; Fri, 2 Dec 2016 18:37:52 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 A973F2856E for ; Fri, 2 Dec 2016 18:37:51 +0000 (UTC) Received: from localhost ([::1]:36023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCsiT-0003Kd-H8 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 02 Dec 2016 13:37:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCsi9-0003KR-4P for qemu-devel@nongnu.org; Fri, 02 Dec 2016 13:37:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCsi1-0000kV-Os for qemu-devel@nongnu.org; Fri, 02 Dec 2016 13:37:25 -0500 Received: from mta02.ornl.gov ([128.219.177.136]:64621) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cCsi1-0000jn-DE for qemu-devel@nongnu.org; Fri, 02 Dec 2016 13:37:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ornl.gov; i=@ornl.gov; q=dns/txt; s=p20151116; t=1480703841; x=1512239841; h=from:to:subject:date:message-id: content-transfer-encoding:mime-version; bh=/qSrdoRl2PTMXr1WZhASvTM+LltIAI/vtfyVOpyGSEg=; b=t3JecTD0phzxLV9xq4TZ1lwxSJtQSH1RHftXkuFiZun3A+1UX+1LxCIT dig6L9iXUr2Tcj6NVSADNRC+hfjzsERM2NSaiBIDDRTu2usjswY4golMi QpCI7CqGM+5KqoznDQDFjkeXMQjWoTbWtZM6xiNfTqC36X1bRNqG48m4d JYW5h7A10pl7ylNBAyF4A74rFJ9cCw/pwHpOXmHi2pEfQ5bUgo2Mplj76 09tj8UNtRAI9H5obIrk8PaL7HTsaHgumV/pgRB6MoaumH+X2KVVT0ycpX 6XwNz41WnVFR60mOOatkHoUyCr5M+J97ltMTGYw7DmsXXVrduUgNYt4cp A==; X-SG: RELAYLIST X-IronPort-AV: E=Sophos;i="5.33,287,1477972800"; d="scan'208";a="193189" Received: from emgwy2.ornl.gov ([160.91.254.10]) by iron2.ornl.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Dec 2016 13:37:16 -0500 Received: from EXCHCS32.ornl.gov (exchcs32.ornl.gov [128.219.12.146]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by emgwy2.ornl.gov (Postfix) with ESMTPS id 3tVjYm4bsdz6vpK; Fri, 2 Dec 2016 13:37:16 -0500 (EST) Received: from EXCHCS32.ornl.gov (128.219.12.146) by EXCHCS32.ornl.gov (128.219.12.146) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Fri, 2 Dec 2016 13:37:16 -0500 Received: from EXCHCS32.ornl.gov ([fe80::2408:8b8c:e63d:2a33]) by EXCHCS32.ornl.gov ([fe80::2408:8b8c:e63d:2a33%17]) with mapi id 15.00.1178.000; Fri, 2 Dec 2016 13:37:16 -0500 From: "Nutaro, James J." To: "'lma@suse.com'" , "qemu-devel@nongnu.org" Thread-Topic: =?gb2312?B?W1FlbXUtZGV2ZWxdILTwuLSjuiAgW1BBVENIIHY0IDUvNV0gb2JqZWN0OiBB?= =?gb2312?B?ZGQgJ2hlbHAnIG9wdGlvbiBmb3IgYWxsIGF2YWlsYWJsZSBiYWNrZW5kcyBh?= =?gb2312?Q?nd_properties?= Thread-Index: AdJMyxUDMRv3/tTPRfqGXcJYjnUg1Q== Date: Fri, 2 Dec 2016 18:37:15 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [128.219.12.132] MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 128.219.177.136 Subject: [Qemu-devel] =?gb2312?b?ILTwuLSjuiAgW1BBVENIIHY0IDUvNV0gb2JqZWN0?= =?gb2312?b?OiBBZGQgJ2hlbHAnIG9wdGlvbiBmb3IgYWxsIGF2YWlsYWJsZSBiYWNrZW5k?= =?gb2312?b?cyBhbmQgcHJvcGVydGllcw==?= 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hi Lin, My comments are inline with the patch. ping... >>> Lin Ma 2016/10/20 星期四 下午 7:28 >>> '-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(-) -- 2.9.2 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}[,@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} 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; + } + 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 = { diff --git a/vl.c b/vl.c index ebd47af..145 6eca 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); }