From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [RFC 4/4] qdev: Make subclasses inherit properties from superclass
Date: Thu, 13 Nov 2014 16:05:21 -0200 [thread overview]
Message-ID: <1415901921-14372-5-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1415901921-14372-1-git-send-email-ehabkost@redhat.com>
Instead of scanning all parent classes every time we walk the list of
properties, just make DeviceState subclasses inherit the property list
from the parent class.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
hw/core/qdev-properties.c | 15 +--------------
hw/core/qdev.c | 42 +++++++++++++++---------------------------
qdev-monitor.c | 7 +------
qmp.c | 47 ++++++++++++++++++++++-------------------------
4 files changed, 39 insertions(+), 72 deletions(-)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index d506793..d685d72 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -836,20 +836,7 @@ static Property *qdev_prop_walk(GList *props, const char *name)
static Property *qdev_prop_find(DeviceState *dev, const char *name)
{
- ObjectClass *class;
- Property *prop;
-
- /* device properties */
- class = object_get_class(OBJECT(dev));
- do {
- prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name);
- if (prop) {
- return prop;
- }
- class = object_class_get_parent(class);
- } while (class != object_class_by_name(TYPE_DEVICE));
-
- return NULL;
+ return qdev_prop_walk(DEVICE_GET_CLASS(dev)->props, name);
}
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index b549ae6..bc26b32 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -919,21 +919,14 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
*/
void qdev_alias_all_properties(DeviceState *target, Object *source)
{
- ObjectClass *class;
GList *props;
- class = object_get_class(OBJECT(target));
- do {
- DeviceClass *dc = DEVICE_CLASS(class);
-
- for (props = dc->props; props; props = props->next) {
- Property *prop = props->data;
- object_property_add_alias(source, prop->name,
- OBJECT(target), prop->name,
- &error_abort);
- }
- class = object_class_get_parent(class);
- } while (class != object_class_by_name(TYPE_DEVICE));
+ for (props = DEVICE_GET_CLASS(target)->props; props; props = props->next) {
+ Property *prop = props->data;
+ object_property_add_alias(source, prop->name,
+ OBJECT(target), prop->name,
+ &error_abort);
+ }
}
int qdev_build_hotpluggable_device_list(Object *obj, void *opaque)
@@ -1083,7 +1076,7 @@ static void device_set_hotplugged(Object *obj, bool value, Error **err)
static void device_initfn(Object *obj)
{
DeviceState *dev = DEVICE(obj);
- ObjectClass *class;
+ GList *props;
if (qdev_hotplug) {
dev->hotplugged = 1;
@@ -1101,16 +1094,11 @@ static void device_initfn(Object *obj)
device_get_hotplugged, device_set_hotplugged,
&error_abort);
- class = object_get_class(OBJECT(dev));
- do {
- GList *props;
- for (props = DEVICE_CLASS(class)->props; props; props = props->next) {
- Property *prop = props->data;
- qdev_property_add_legacy(dev, prop, &error_abort);
- qdev_property_add_static(dev, prop, &error_abort);
- }
- class = object_class_get_parent(class);
- } while (class != object_class_by_name(TYPE_DEVICE));
+ for (props = DEVICE_GET_CLASS(dev)->props; props; props = props->next) {
+ Property *prop = props->data;
+ qdev_property_add_legacy(dev, prop, &error_abort);
+ qdev_property_add_static(dev, prop, &error_abort);
+ }
object_property_add_link(OBJECT(dev), "parent_bus", TYPE_BUS,
(Object **)&dev->parent_bus, NULL, 0,
@@ -1169,10 +1157,10 @@ static void device_class_base_init(ObjectClass *class, void *data)
{
DeviceClass *dc = DEVICE_CLASS(class);
- /* We explicitly look up properties in the superclasses,
- * so do not propagate them to the subclasses.
+ /* We inherit properties from the superclass, but we need to fix the
+ * list pointer that was memcpy()ed.
*/
- dc->props = NULL;
+ dc->props = g_list_copy(dc->props);
}
static void device_unparent(Object *obj)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index d151dfd..2d5e9f7 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -624,7 +624,6 @@ static void bus_print_dev(BusState *bus, Monitor *mon, DeviceState *dev, int ind
static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
{
- ObjectClass *class;
BusState *child;
NamedGPIOList *ngl;
@@ -641,11 +640,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
ngl->num_out);
}
}
- class = object_get_class(OBJECT(dev));
- do {
- qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent);
- class = object_class_get_parent(class);
- } while (class != object_class_by_name(TYPE_DEVICE));
+ qdev_print_props(mon, dev, DEVICE_GET_CLASS(dev)->props, indent);
bus_print_dev(dev->parent_bus, mon, dev, indent);
QLIST_FOREACH(child, &dev->child_bus, sibling) {
qbus_print(mon, child, indent);
diff --git a/qmp.c b/qmp.c
index 7d91a18..ea32d27 100644
--- a/qmp.c
+++ b/qmp.c
@@ -446,34 +446,31 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
const char *description)
{
DevicePropertyInfo *info;
+ GList *props;
- do {
- GList *props;
- for (props = DEVICE_CLASS(klass)->props; props; props = props->next) {
- Property *prop = props->data;
- if (strcmp(name, prop->name) != 0) {
- continue;
- }
-
- /*
- * TODO Properties without a parser are just for dirty hacks.
- * qdev_prop_ptr is the only such PropertyInfo. It's marked
- * for removal. This conditional should be removed along with
- * it.
- */
- if (!prop->info->set) {
- return NULL; /* no way to set it, don't show */
- }
+ for (props = DEVICE_CLASS(klass)->props; props; props = props->next) {
+ Property *prop = props->data;
+ if (strcmp(name, prop->name) != 0) {
+ continue;
+ }
- info = g_malloc0(sizeof(*info));
- info->name = g_strdup(prop->name);
- info->type = g_strdup(prop->info->name);
- info->has_description = !!prop->info->description;
- info->description = g_strdup(prop->info->description);
- return info;
+ /*
+ * TODO Properties without a parser are just for dirty hacks.
+ * qdev_prop_ptr is the only such PropertyInfo. It's marked
+ * for removal. This conditional should be removed along with
+ * it.
+ */
+ if (!prop->info->set) {
+ return NULL; /* no way to set it, don't show */
}
- klass = object_class_get_parent(klass);
- } while (klass != object_class_by_name(TYPE_DEVICE));
+
+ info = g_malloc0(sizeof(*info));
+ info->name = g_strdup(prop->name);
+ info->type = g_strdup(prop->info->name);
+ info->has_description = !!prop->info->description;
+ info->description = g_strdup(prop->info->description);
+ return info;
+ }
/* Not a qdev property, use the default type */
info = g_malloc0(sizeof(*info));
--
1.9.3
next prev parent reply other threads:[~2014-11-13 18:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-13 18:05 [Qemu-devel] [RFC 0/4] qdev: Simplify property registration/walking Eduardo Habkost
2014-11-13 18:05 ` [Qemu-devel] [RFC 1/4] qdev: Variable name style fix Eduardo Habkost
2014-11-13 18:05 ` [Qemu-devel] [RFC 2/4] qdev: Wrap DeviceClass.props setting into a function Eduardo Habkost
2014-11-13 18:05 ` [Qemu-devel] [RFC 3/4] qdev: Make DeviceClass.props a linked list Eduardo Habkost
2014-11-13 18:05 ` Eduardo Habkost [this message]
2014-11-14 15:49 ` [Qemu-devel] [RFC 0/4] qdev: Simplify property registration/walking Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415901921-14372-5-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=afaerber@suse.de \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).