From patchwork Mon Jan 25 08:24:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Valentin Rakush X-Patchwork-Id: 8104461 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E311DBEEE5 for ; Mon, 25 Jan 2016 08:25:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7B542024F for ; Mon, 25 Jan 2016 08:25:25 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id ED46F20225 for ; Mon, 25 Jan 2016 08:25:24 +0000 (UTC) Received: from localhost ([::1]:35585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNcSh-0005PX-6c for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Jan 2016 03:25:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNcSV-0005OI-3j for qemu-devel@nongnu.org; Mon, 25 Jan 2016 03:25:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNcSQ-0001gz-71 for qemu-devel@nongnu.org; Mon, 25 Jan 2016 03:25:11 -0500 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34522) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNcSP-0001gt-Rx for qemu-devel@nongnu.org; Mon, 25 Jan 2016 03:25:06 -0500 Received: by mail-pf0-x241.google.com with SMTP id 65so6539128pfd.1 for ; Mon, 25 Jan 2016 00:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=D7Z4ElYyx8TvZbflINUFedCnmHyBzuHvWvQoFk+Zlyc=; b=JX1znIAdQEFRfsrOUAEc8GtxyWIvKPyM1eVRL4GS2f7kqieSIPbM2dcPwfZWey3vJv QKT5pyFMDFbyJ1Zo7YY8Gbn1unzECGH5eoGRmINSj+OBzDtRGAuOc+Lu8incOeOjWFwY xN4qO83e9MWM1i5RkfcknEliQoob9nF4FLKIFxy9BGrR8zKNFiqHDEPLqgxv5ugfAnKV gWbHjnOG3Xe4WguPA2SYd5s59EmlgHweAVlgHIKQXcwIelyAEtIuTI11d+Iv9l4YhahS +8+YWEnB4G3y26g0YbhjDBX6mLk6pP/GR0aIzA/PHvzbeDPjzNa5lHVrG+m6kSUJZiak 8Vtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=D7Z4ElYyx8TvZbflINUFedCnmHyBzuHvWvQoFk+Zlyc=; b=Zc1Fo6ELU6RJgUARs7kvXNB/Nz0BPt6mzPz+2XD0j4qHU4MQAqWbnOi/WW3/0J/94W RY/6Dq73J5JsVJor+Qqmdoqv34YH/GBQvL1Gj8tIOcBl/x9o/soQ6+J/FGJTsGXAz0/F PyQKkJcXfnoAEN6V9hFSFGvXC3exDoVlvNgDoH7UG4LJ0VFRUEgvjaQTMrzCijZXWvnF eLNHg3RF8aWl7dex1WXp5oh8zaLzyrWsf2NAdaV8RSltroTuZwm7gZMwxUut2ibi7nar BV9SXF3LGquFjI9wMfvEnJvTSnqhFCo6AYVbocLgcXnnssy71cg/pkAbJw5UvW4FWsEh b72g== X-Gm-Message-State: AG10YOTl7qX/om4eVOEOsUVUKaGZpFqXPda4gBwvQ6JmGwFNWgF15GSAFFJmBcQXWmJjnw== X-Received: by 10.98.70.90 with SMTP id t87mr24295247pfa.110.1453710304774; Mon, 25 Jan 2016 00:25:04 -0800 (PST) Received: from vrakush.netgear.com (mail.itspartner.net. [80.249.81.165]) by smtp.gmail.com with ESMTPSA id p70sm26440060pfi.96.2016.01.25.00.25.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jan 2016 00:25:03 -0800 (PST) From: Valentin Rakush To: qemu-devel@nongnu.org Date: Mon, 25 Jan 2016 11:24:47 +0300 Message-Id: <1453710287-12706-1-git-send-email-valentin.rakush@gmail.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::241 Cc: ehabkost@redhat.com, armbru@redhat.com, lcapitulino@redhat.com, asmetanin@virtuozzo.com, den@openvz.org, Valentin Rakush , afaerber@suse.de Subject: [Qemu-devel] [PATCH v5] qom, qmp, hmp, qapi: create qom-type-prop-list for class properties X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 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-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for qom-type-prop-list command to list object class properties. A later patch will use this functionality to implement x86_64-cpu properties. Signed-off-by: Valentin Rakush Cc: Luiz Capitulino Cc: Eric Blake Cc: Markus Armbruster Cc: Andreas Färber Cc: Daniel P. Berrange Cc: Eduardo Habkost --- V5: fixes after scripts/checkpatch.pl V4: review fixes - the typename argument in the hmp command changed to be mandatory V3: commit message fix - commit message changed to reflect actual command name V2: Fixes after first review - changed command name from qom-type-list to qom-type-prop-list - changed memory allocation from g_malloc0 to g_new0 - changed parameter name from path to typename - fixed wordings and comments - fixed source code formatting - registered the command in monitor hmp-commands.hx | 13 +++++++++++++ hmp.c | 21 +++++++++++++++++++++ hmp.h | 1 + include/qom/object.h | 31 +++++++++++++++++++++++++++++++ qapi-schema.json | 19 +++++++++++++++++++ qmp-commands.hx | 6 ++++++ qmp.c | 31 +++++++++++++++++++++++++++++++ qom/object.c | 7 +++++++ 8 files changed, 129 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index bb52e4d..ee4d1e2 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1734,6 +1734,19 @@ Print QOM properties of object at location @var{path} ETEXI { + .name = "qom-type-prop-list", + .args_type = "typename:s", + .params = "typename", + .help = "list QOM class properties", + .mhandler.cmd = hmp_qom_type_prop_list, + }, + +STEXI +@item qom-type-prop-list [@var{typename}] +Print QOM properties of the type @var{typename} +ETEXI + + { .name = "qom-set", .args_type = "path:s,property:s,value:s", .params = "path property value", diff --git a/hmp.c b/hmp.c index 54f2620..6de9bf0 100644 --- a/hmp.c +++ b/hmp.c @@ -2052,6 +2052,27 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +void hmp_qom_type_prop_list(Monitor *mon, const QDict *qdict) +{ + const char *typename = qdict_get_try_str(qdict, "typename"); + ObjectPropertyInfoList *list; + Error *err = NULL; + + list = qmp_qom_type_prop_list(typename, &err); + if (!err) { + ObjectPropertyInfoList *start = list; + while (list) { + ObjectPropertyInfo *value = list->value; + + monitor_printf(mon, "%s (%s)\n", + value->name, value->type); + list = list->next; + } + qapi_free_ObjectPropertyInfoList(start); + } + hmp_handle_error(mon, &err); +} + void hmp_qom_set(Monitor *mon, const QDict *qdict) { const char *path = qdict_get_str(qdict, "path"); diff --git a/hmp.h b/hmp.h index a8c5b5a..8c12ebe 100644 --- a/hmp.h +++ b/hmp.h @@ -103,6 +103,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict); void hmp_info_memdev(Monitor *mon, const QDict *qdict); void hmp_info_memory_devices(Monitor *mon, const QDict *qdict); void hmp_qom_list(Monitor *mon, const QDict *qdict); +void hmp_qom_type_prop_list(Monitor *mon, const QDict *qdict); void hmp_qom_set(Monitor *mon, const QDict *qdict); void object_add_completion(ReadLineState *rs, int nb_args, const char *str); void object_del_completion(ReadLineState *rs, int nb_args, const char *str); diff --git a/include/qom/object.h b/include/qom/object.h index d0dafe9..0c8379d 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1013,6 +1013,37 @@ void object_property_iter_init(ObjectPropertyIterator *iter, */ ObjectProperty *object_property_iter_next(ObjectPropertyIterator *iter); +/** + * object_class_property_iter_init: + * @klass: the class owning the properties to be iterated over + * + * Initializes an iterator for traversing all properties + * registered against a class type and all parent classes. + * + * It is forbidden to modify the property list while iterating, + * whether removing or adding properties. + * + * NB For getting next property in the list the object related + * function object_property_iter_next is still used. + * + * Typical usage pattern would be + * + * + * Using object class property iterators + * + * ObjectProperty *prop; + * ObjectPropertyIterator iter; + * + * object_class property_iter_init(&iter, obj); + * while ((prop = object_property_iter_next(&iter))) { + * ... do something with prop ... + * } + * + * + */ +void object_class_property_iter_init(ObjectPropertyIterator *iter, + ObjectClass *klass); + void object_unparent(Object *obj); /** diff --git a/qapi-schema.json b/qapi-schema.json index b3038b2..2e960db 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4081,3 +4081,22 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @qom-type-prop-list: +# +# This command will list any properties of an object class +# given its typename. +# +# @typename: the typename of the class. See @qom-list-types to check +# available typenames. +# +# Returns: a list of @ObjectPropertyInfo that describe the properties +# of the class. +# +# Since: 2.6 +## +{ 'command': 'qom-type-prop-list', + 'data': { 'typename': 'str' }, + 'returns': [ 'ObjectPropertyInfo' ] } + diff --git a/qmp-commands.hx b/qmp-commands.hx index db072a6..d3be962 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3789,6 +3789,12 @@ EQMP }, { + .name = "qom-type-prop-list", + .args_type = "typename:s", + .mhandler.cmd_new = qmp_marshal_qom_type_prop_list, + }, + + { .name = "qom-set", .args_type = "path:s,property:s,value:q", .mhandler.cmd_new = qmp_marshal_qom_set, diff --git a/qmp.c b/qmp.c index 53affe2..baf25c0 100644 --- a/qmp.c +++ b/qmp.c @@ -460,6 +460,37 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, return ret; } +ObjectPropertyInfoList *qmp_qom_type_prop_list(const char *typename, Error **errp) +{ + ObjectClass *klass; + ObjectPropertyInfoList *props = NULL; + ObjectProperty *prop; + ObjectPropertyIterator iter; + + klass = object_class_by_name(typename); + if (!klass) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Object class '%s' not found", typename); + return NULL; + } + + object_class_property_iter_init(&iter, klass); + while ((prop = object_property_iter_next(&iter))) { + ObjectPropertyInfoList *entry = g_new0(ObjectPropertyInfoList, 1); + + if (entry) { + entry->value = g_new0(ObjectPropertyInfo, 1); + entry->next = props; + props = entry; + + entry->value->name = g_strdup(prop->name); + entry->value->type = g_strdup(prop->type); + } + } + + return props; +} + /* Return a DevicePropertyInfo for a qdev property. * * If a qdev property with the given name does not exist, use the given default diff --git a/qom/object.c b/qom/object.c index 5ff97ab..cabd91d 100644 --- a/qom/object.c +++ b/qom/object.c @@ -994,6 +994,13 @@ ObjectProperty *object_property_find(Object *obj, const char *name, return NULL; } +void object_class_property_iter_init(ObjectPropertyIterator *iter, + ObjectClass *klass) +{ + g_hash_table_iter_init(&iter->iter, klass->properties); + iter->nextclass = object_class_get_parent(klass); +} + void object_property_iter_init(ObjectPropertyIterator *iter, Object *obj) {