From patchwork Wed Jan 20 09:42:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Valentin Rakush X-Patchwork-Id: 8070251 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D68299F6FA for ; Wed, 20 Jan 2016 09:43:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1AF4203FB for ; Wed, 20 Jan 2016 09:43:47 +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 0A2E4203DC for ; Wed, 20 Jan 2016 09:43:47 +0000 (UTC) Received: from localhost ([::1]:41311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLpIo-0004I2-G5 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Jan 2016 04:43:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLpIe-0004Ge-PW for qemu-devel@nongnu.org; Wed, 20 Jan 2016 04:43:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLpIZ-00012W-0c for qemu-devel@nongnu.org; Wed, 20 Jan 2016 04:43:36 -0500 Received: from mail-lb0-x241.google.com ([2a00:1450:4010:c04::241]:32953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLpIY-00012G-KJ for qemu-devel@nongnu.org; Wed, 20 Jan 2016 04:43:30 -0500 Received: by mail-lb0-x241.google.com with SMTP id bc4so170355lbc.0 for ; Wed, 20 Jan 2016 01:43:30 -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=2sSO3CL9JDJvOhB/0hqKeA6drW1ZepxDAWtQ09GP8i8=; b=tkc7ZquK18UZVeJZpaia062B14QuC4adrOXyYyJBZEzvFviUg37jgzp+U7NTK9MTNT zMgblhpoEFrA3Ly0kgkyPW+T8trQBoJAk/s0nwfA8MB+xtOjYNswWgGD5U0yPPhaVdvS SOowHO7jzOk3Y/M2yZ1TdMq56F4Zo4TdU5T1YBRYoq9n/deLyc8yrH8SHCLdQKCw84H7 VDCJP5X/OVspKA7bNQqJwW+6oDyC2qsj3HdScr1HKBWNuOV0wpKNLtokZqsPwOZrfolI uDwCqYk+/+OgOtRPMaj5SVgmSH02z4Yx2X4wLANpTJkQ8zCVSR+sVMMAZ4JILZ+a00yh x8hw== 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=2sSO3CL9JDJvOhB/0hqKeA6drW1ZepxDAWtQ09GP8i8=; b=G94bLxJ+Vfa6gCdM06TKBlUznNQMgCQ72l0xdmF5UA9gp6N0+ty/k9E8xlY5uQSM3M k+e+fBShSGdR4GaNY4bxYkbXEQbwdnSfPIT7VzTDQy+35/ijWDO7/VGkUYAV7FutNvHe GU4HT7L8ldw1T/Yps6GdLO8U58BHAWZE0vlc6RJV9Whkr6aUXeKoSpbmR1GDjnBNf3pq QJB7ELcU+2P20Omkc/wIGSrv9GG022Bq6efvcDh+xwJlnkC0vUBPoVj9ZlSOMWhg73dM TkxyjTJHq+M14YYgng+zrBcKgB8z0qr/wc/HW9hjk22UxKQT1A8lKoVrYtk30699NiRb 7lRA== X-Gm-Message-State: AG10YOTQSGccH9gDtl1Y+/NkbHRV6VSXmdX5ApFssMOzCsJvkc0Exe4b+qbt+P3DQKYY5w== X-Received: by 10.112.180.7 with SMTP id dk7mr12132795lbc.65.1453283009620; Wed, 20 Jan 2016 01:43:29 -0800 (PST) Received: from vrakush.its.local (mail.itspartner.net. [80.249.81.165]) by smtp.gmail.com with ESMTPSA id qa9sm4418428lbb.40.2016.01.20.01.43.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jan 2016 01:43:28 -0800 (PST) From: Valentin Rakush To: qemu-devel@nongnu.org Date: Wed, 20 Jan 2016 12:42:38 +0300 Message-Id: <1453282958-385-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: 2a00:1450:4010:c04::241 Cc: armbru@redhat.com, lcapitulino@redhat.com, asmetanin@virtuozzo.com, den@openvz.org, Valentin Rakush , afaerber@suse.de Subject: [Qemu-devel] [PATCH] qom, qmp, hmp, qapi: create qom-type-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-list command that supposed to list object class properties. Will use this functionality further to implement x86_64 cpu properties. Additionally object_class_property_iterator_init function is implemented for consistency. Signed-off-by: Valentin Rakush Cc: Luiz Capitulino Cc: Eric Blake Cc: Markus Armbruster Cc: Andreas Färber Cc: Daniel P. Berrange --- hmp.c | 26 ++++++++++++++++++++++++++ hmp.h | 1 + include/qom/object.h | 31 +++++++++++++++++++++++++++++++ qapi-schema.json | 19 +++++++++++++++++++ qmp-commands.hx | 6 ++++++ qmp.c | 29 +++++++++++++++++++++++++++++ qom/object.c | 8 ++++++++ 7 files changed, 120 insertions(+) diff --git a/hmp.c b/hmp.c index 54f2620..64aa991 100644 --- a/hmp.c +++ b/hmp.c @@ -2052,6 +2052,32 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, &err); } +void hmp_qom_type_list(Monitor *mon, const QDict *qdict) +{ + const char *path = qdict_get_try_str(qdict, "path"); + ObjectPropertyInfoList *list; + Error *err = NULL; + + if (path == NULL) { + monitor_printf(mon, "/\n"); + return; + } + + list = qmp_qom_type_list(path, &err); + if (err == NULL) { + ObjectPropertyInfoList *start = list; + while (list != NULL) { + 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..d81cd4c 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_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..f8ca725 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 klass to iter properties for + * + * Initializes an iterator for traversing all properties + * registered against a klass 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..c50d24c 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4081,3 +4081,22 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + +## +# @qom-type-list: +# +# This command will list any properties of a object class +# given a path in the object class model. +# +# @path: the path within the object class model. See @qom-list-types +# to check available object class names. +# +# Returns: a list of @ObjectPropertyInfo that describe the properties of the +# object class. +# +# Since: 2.6 +## +{ 'command': 'qom-type-list', + 'data': { 'path': 'str' }, + 'returns': [ 'ObjectPropertyInfo' ] } + diff --git a/qmp-commands.hx b/qmp-commands.hx index db072a6..4e5dd48 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3789,6 +3789,12 @@ EQMP }, { + .name = "qom-type-list", + .args_type = "path:s", + .mhandler.cmd_new = qmp_marshal_qom_type_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 3ff6db7..86dd1f2 100644 --- a/qmp.c +++ b/qmp.c @@ -448,6 +448,35 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, return ret; } +ObjectPropertyInfoList *qmp_qom_type_list(const char *path, Error **errp) +{ + ObjectClass *klass; + ObjectPropertyInfoList *props = NULL; + ObjectProperty* prop; + ObjectPropertyIterator iter; + + klass = object_class_by_name(path); + if (klass == NULL) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Object class '%s' not found", path); + return NULL; + } + + object_class_property_iter_init(&iter, klass); + while ((prop = object_property_iter_next(&iter))) { + ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); + + entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); + 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..a158076 100644 --- a/qom/object.c +++ b/qom/object.c @@ -994,6 +994,14 @@ 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) {