Skip to contentSkip to conversation

qdev: Introduce DEFINE_PROP_LINK

PATCH Superseded Fam Zheng 3 participants 15 messages Jun 28, 2017

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

cover qdev: Introduce DEFINE_PROP_LINK

Link properties of devices created with object_property_add_link() are not reflected in HMP "info qtree". For example, whether a virtio-blk device has an iothread (i.e. has enabled data plane) can not be introspected easily.

Introduce a new type of qdev property to fix that.

Because QOM is not my most familiar area, only virtio devices are converted in this version. If the new API is okay, other devices can be worked on either in v2 or in a follow up series.

Fam Zheng (7):
qom: Make link property API public
qom: Handle property lookup failure in object_resolve_link
qom: Save type name in LinkProperty
qdev: Introduce DEFINE_PROP_LINK
virtio-blk: Use DEFINE_PROP_LINK
virtio-scsi: Use DEFINE_PROP_LINK
virtio-rng: Use DEFINE_PROP_LINK

 hw/block/dataplane/virtio-blk.c |  2 +-
 hw/block/virtio-blk.c           |  7 ++--
 hw/core/qdev-properties.c       | 81 +++++++++++++++++++++++++++++++++++++++++
 hw/scsi/virtio-scsi-dataplane.c |  2 +-
 hw/scsi/virtio-scsi.c           | 15 ++------
 hw/virtio/virtio-pci.c          |  6 ---
 hw/virtio/virtio-rng.c          | 16 ++------
 include/hw/qdev-core.h          |  3 ++
 include/hw/qdev-properties.h    | 11 ++++++
 include/hw/virtio/virtio-blk.h  |  2 +-
 include/hw/virtio/virtio-rng.h  |  2 +-
 include/hw/virtio/virtio-scsi.h |  2 +-
 include/qom/object.h            | 14 +++++++
 qom/object.c                    | 24 ++++++------
 14 files changed, 136 insertions(+), 51 deletions(-)
Signature · 1 line
2.9.4
author
#1 lore raw

PATCH 1/7 qom: Make link property API public

The get/set pair and the struct will be reused by qdev link prop, make them public.

---
 include/qom/object.h | 13 +++++++++++++
 qom/object.c         | 18 ++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)
include/qom/object.h +13 -0
index abaeb8c..4659e6a 100644
@@ -1613,4 +1613,17 @@ Object *container_get(Object *root, const char *path);
  * Returns the instance_size of the given @typename.
  */
 size_t object_type_get_instance_size(const char *typename);
+
+typedef struct {
+    Object **child;
+    void (*check)(Object *, const char *, Object *, Error **);
+    ObjectPropertyLinkFlags flags;
+} LinkProperty;
+
+void object_get_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp);
+void object_set_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp);
 #endif
qom/object.c +6 -12
index 5f6fdfa..3868370 100644
@@ -1434,15 +1434,9 @@ void object_property_allow_set_link(Object *obj, const char *name,
     /* Allow the link to be set, always */
 }
 
-typedef struct {
-    Object **child;
-    void (*check)(Object *, const char *, Object *, Error **);
-    ObjectPropertyLinkFlags flags;
-} LinkProperty;
-
-static void object_get_link_property(Object *obj, Visitor *v,
-                                     const char *name, void *opaque,
-                                     Error **errp)
+void object_get_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp)
 {
     LinkProperty *lprop = opaque;
     Object **child = lprop->child;
@@ -1498,9 +1492,9 @@ static Object *object_resolve_link(Object *obj, const char *name,
     return target;
 }
 
-static void object_set_link_property(Object *obj, Visitor *v,
-                                     const char *name, void *opaque,
-                                     Error **errp)
+void object_set_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp)
 {
     Error *local_err = NULL;
     LinkProperty *prop = opaque;
Signature · 1 line
2.9.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/7] qom: Make link property API public

Quoted 4 lines · Fam Zheng

The get/set pair and the struct will be reused by qdev link prop, make them public.

Maybe it's better to make it a separate header file. No other objections.

Paolo

Quoted 64 lines
---
 include/qom/object.h | 13 +++++++++++++
 qom/object.c         | 18 ++++++------------
 2 files changed, 19 insertions(+), 12 deletions(-)
include/qom/object.h +13 -0
index abaeb8c..4659e6a 100644
@@ -1613,4 +1613,17 @@ Object *container_get(Object *root, const char *path);
  * Returns the instance_size of the given @typename.
  */
 size_t object_type_get_instance_size(const char *typename);
+
+typedef struct {
+    Object **child;
+    void (*check)(Object *, const char *, Object *, Error **);
+    ObjectPropertyLinkFlags flags;
+} LinkProperty;
+
+void object_get_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp);
+void object_set_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp);
 #endif
qom/object.c +6 -12
index 5f6fdfa..3868370 100644
@@ -1434,15 +1434,9 @@ void object_property_allow_set_link(Object *obj, const char *name,
     /* Allow the link to be set, always */
 }
 
-typedef struct {
-    Object **child;
-    void (*check)(Object *, const char *, Object *, Error **);
-    ObjectPropertyLinkFlags flags;
-} LinkProperty;
-
-static void object_get_link_property(Object *obj, Visitor *v,
-                                     const char *name, void *opaque,
-                                     Error **errp)
+void object_get_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp)
 {
     LinkProperty *lprop = opaque;
     Object **child = lprop->child;
@@ -1498,9 +1492,9 @@ static Object *object_resolve_link(Object *obj, const char *name,
     return target;
 }
 
-static void object_set_link_property(Object *obj, Visitor *v,
-                                     const char *name, void *opaque,
-                                     Error **errp)
+void object_set_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp)
 {
     Error *local_err = NULL;
     LinkProperty *prop = opaque;
#3 lore raw

Re: [Qemu-devel] [PATCH 1/7] qom: Make link property API public

Am 28.06.2017 um 15:32 schrieb Paolo Bonzini:

Quoted 7 lines · Fam Zheng
Quoted 4 lines

The get/set pair and the struct will be reused by qdev link prop, make them public.

Maybe it's better to make it a separate header file. No other objections.

So you think it should be added?

The alternative would be moving info qom-tree forward and finally deprecating info qtree. There was a patch of mine to make it list properties with -v or so, but there were StringOutputVisitor dependencies where it got stuck in review.

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
author
#4 lore raw

Re: [Qemu-devel] [PATCH 1/7] qom: Make link property API public

Quoted 4 lines · Andreas Färber

The alternative would be moving info qom-tree forward and finally deprecating info qtree. There was a patch of mine to make it list properties with -v or so, but there were StringOutputVisitor dependencies where it got stuck in review.

No objection to enhancing info qom-tree, but also no idea how to help. :)

BTW, will it print much more information than "info qtree"? If so deprecating it sounds like a bad idea for me. "info qtree" output is already lengthy. As HMP is for human, it would be nice if the output is easy to extract interesting information with eyeball, rather than dumping everything.

Fam

author
#5 lore raw

PATCH 2/7 qom: Handle property lookup failure in object_resolve_link

In reply to Fam Zheng

Since we have made object_set_link_property a public function, it is possible that it will be called with a nonexistent property name. Let's survive this error case and report error to avoid segfault in the future.

---
 qom/object.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qom/object.c +4 -1
index 3868370..dd9c3fa 100644
@@ -1470,7 +1470,10 @@ static Object *object_resolve_link(Object *obj, const char *name,
     Object *target;
 
     /* Go from link<FOO> to FOO.  */
-    type = object_property_get_type(obj, name, NULL);
+    type = object_property_get_type(obj, name, errp);
+    if (!type) {
+        return NULL;
+    }
     target_type = g_strndup(&type[5], strlen(type) - 6);
     target = object_resolve_path_type(path, target_type, &ambiguous);
 
Signature · 1 line
2.9.4
author
#6 lore raw

PATCH 3/7 qom: Save type name in LinkProperty

In reply to Fam Zheng
---
 include/qom/object.h | 1 +
 qom/object.c         | 1 +
 2 files changed, 2 insertions(+)
include/qom/object.h +1 -0
index 4659e6a..262cd44 100644
@@ -1618,6 +1618,7 @@ typedef struct {
     Object **child;
     void (*check)(Object *, const char *, Object *, Error **);
     ObjectPropertyLinkFlags flags;
+    const char *type;
 } LinkProperty;
 
 void object_get_link_property(Object *obj, Visitor *v,
qom/object.c +1 -0
index dd9c3fa..b3073a6 100644
@@ -1562,6 +1562,7 @@ void object_property_add_link(Object *obj, const char *name,
     prop->child = child;
     prop->check = check;
     prop->flags = flags;
+    prop->type = type;
 
     full_type = g_strdup_printf("link<%s>", type);
 
Signature · 1 line
2.9.4
author
#7 lore raw

PATCH 4/7 qdev: Introduce DEFINE_PROP_LINK

In reply to Fam Zheng

This property can be used to replace the object_property_add_link in device code, to add a link to other objects.

It's implemented by creating a wrapper property that basically forwards operations to a QOM "link-FOO" property, which handles the check callback and flags. The feature that is missing from QOM is the dynamic child pointer which is done in the added code with the usual "offset" approach.

---
 hw/core/qdev-properties.c    | 81 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/qdev-core.h       |  3 ++
 include/hw/qdev-properties.h | 11 ++++++
 3 files changed, 95 insertions(+)
hw/core/qdev-properties.c +81 -0
index 68cd653..3801379 100644
@@ -1192,3 +1192,84 @@ PropertyInfo qdev_prop_size = {
     .set = set_size,
     .set_default_value = set_default_value_uint,
 };
+
+/* --- object link property --- */
+
+static ObjectProperty *link_property_get_or_create(Object *obj, Property *prop,
+                                                   Error **errp)
+{
+    Error *local_err = NULL;
+    Object **child = qdev_get_prop_ptr(DEVICE(obj), prop);
+    char *link_prop_name = g_strdup_printf("link-%s", prop->name);
+    ObjectProperty *op = object_property_find(obj, link_prop_name, NULL);
+
+    if (op) {
+        goto out;
+    }
+    object_property_add_link(obj, link_prop_name, prop->link.type,
+                             child, prop->link.check,
+                             prop->link.flags, &local_err);
+
+    if (local_err) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
+    op = object_property_find(obj, link_prop_name, errp);
+out:
+    g_free(link_prop_name);
+    return op;
+}
+
+static void get_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp)
+{
+    Property *prop = opaque;
+    ObjectProperty *op = link_property_get_or_create(obj, prop, NULL);
+    char *link_prop_name;
+
+    if (!op) {
+        return;
+    }
+    link_prop_name = g_strdup_printf("link-%s", name);
+    object_get_link_property(obj, v, link_prop_name, op->opaque, errp);
+    g_free(link_prop_name);
+}
+
+static void set_link_property(Object *obj, Visitor *v,
+                              const char *name, void *opaque,
+                              Error **errp)
+{
+    Object *target;
+    Property *prop = opaque;
+    Object **link_ptr = qdev_get_prop_ptr(DEVICE(obj), prop);
+    ObjectProperty *op = link_property_get_or_create(obj, prop, errp);
+    char *link_prop_name;
+    Error *local_err = NULL;
+
+    if (!op) {
+        return;
+    }
+
+    link_prop_name = g_strdup_printf("link-%s", name);
+    object_set_link_property(obj, v, link_prop_name, op->opaque, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
+    target = object_property_get_link(obj, link_prop_name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        goto out;
+    }
+    *link_ptr = target;
+
+out:
+    g_free(link_prop_name);
+}
+
+PropertyInfo qdev_prop_link = {
+    .name = "link",
+    .get = get_link_property,
+    .set = set_link_property,
+};
include/hw/qdev-core.h +3 -0
index 9d7c1c0..a520226 100644
@@ -233,6 +233,9 @@ struct Property {
     int          arrayoffset;
     PropertyInfo *arrayinfo;
     int          arrayfieldsize;
+    /* Only @check and @flags are used; @child is unuseful because we need a
+     * dynamic pointer in @obj as derived from @offset. */
+    LinkProperty link;
 };
 
 struct PropertyInfo {
include/hw/qdev-properties.h +11 -0
index 39bf4b2..c9ccc9e 100644
@@ -30,6 +30,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
 extern PropertyInfo qdev_prop_blocksize;
 extern PropertyInfo qdev_prop_pci_host_devaddr;
 extern PropertyInfo qdev_prop_arraylen;
+extern PropertyInfo qdev_prop_link;
 
 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
         .name      = (_name),                                    \
@@ -117,6 +118,16 @@ extern PropertyInfo qdev_prop_arraylen;
         .arrayoffset = offsetof(_state, _arrayfield),                   \
         }
 
+#define DEFINE_PROP_LINK(_name, _state, _field, _type, _check, _flags) {\
+        .name = (_name),                                                \
+        .info = &(qdev_prop_link),                                      \
+        .offset = offsetof(_state, _field)                              \
+            + type_check(Object *, typeof_field(_state, _field)),       \
+        .link.check = _check,                                           \
+        .link.flags = _flags,                                           \
+        .link.type  = _type,                                            \
+        }
+
 #define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
     DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
 #define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
Signature · 1 line
2.9.4
#8 lore raw
Quoted 6 lines · Fam Zheng

It's implemented by creating a wrapper property that basically forwards operations to a QOM "link-FOO" property, which handles the check callback and flags. The feature that is missing from QOM is the dynamic child pointer which is done in the added code with the usual "offset" approach.

Would it be possible to add a ".create" field to PropertyInfo? Then there's no need to introduce the wrapper.

Also, I think _check and _flags can be always qdev_prop_allow_set_link_before_realize and OBJ_PROP_LINK_UNREF_ON_RELEASE for DEFINE_PROP_LINK.

Paolo

author
#9 lore raw
Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Fam Zheng
Quoted 8 lines
Quoted 5 lines

It's implemented by creating a wrapper property that basically forwards operations to a QOM "link-FOO" property, which handles the check callback and flags. The feature that is missing from QOM is the dynamic child pointer which is done in the added code with the usual "offset" approach.

Would it be possible to add a ".create" field to PropertyInfo? Then there's no need to introduce the wrapper.

QOM setter/getter want a LinkProperty opaque pointer, but qdev uses a Property pointer. I don't see a way to adapt that with .create(). Can you elaborate?

Quoted 4 lines

Also, I think _check and _flags can be always qdev_prop_allow_set_link_before_realize and OBJ_PROP_LINK_UNREF_ON_RELEASE for DEFINE_PROP_LINK.

A quick grep gave me some object_property_add_link() callers using different parameters, but I don't know if they should use DEFINE_PROP_LINK.

Fam

#10 lore raw
Quoted 9 lines · Fam Zheng
Quoted 7 lines
Quoted 5 lines

It's implemented by creating a wrapper property that basically forwards operations to a QOM "link-FOO" property, which handles the check callback and flags. The feature that is missing from QOM is the dynamic child pointer which is done in the added code with the usual "offset" approach.

Would it be possible to add a ".create" field to PropertyInfo? Then there's no need to introduce the wrapper.

QOM setter/getter want a LinkProperty opaque pointer, but qdev uses a Property pointer. I don't see a way to adapt that with .create(). Can you elaborate?

The .create() callback would call object_property_add_link directly. There would be no change in the properties at the QOM level, but the PropertyInfo lets "info qtree" show the property.

Paolo

author
#11 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Fam Zheng
Quoted 5 lines
Quoted 5 lines

It's implemented by creating a wrapper property that basically forwards operations to a QOM "link-FOO" property, which handles the check callback and flags. The feature that is missing from QOM is the dynamic child pointer which is done in the added code with the usual "offset" approach.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Would it be possible to add a ".create" field to PropertyInfo? Then there's no need to introduce the wrapper.

QOM setter/getter want a LinkProperty opaque pointer, but qdev uses a Property pointer. I don't see a way to adapt that with .create(). Can you elaborate?

The .create() callback would call object_property_add_link directly. There would be no change in the properties at the QOM level, but the PropertyInfo lets "info qtree" show the property.

Thanks, I see, I'll try it in v2 if Andreas agrees on the general idea.

Fam

author
#12 lore raw

PATCH 5/7 virtio-blk: Use DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/block/dataplane/virtio-blk.c | 2 +-
 hw/block/virtio-blk.c           | 7 +++----
 hw/virtio/virtio-pci.c          | 2 --
 include/hw/virtio/virtio-blk.h  | 2 +-
 4 files changed, 5 insertions(+), 8 deletions(-)
hw/block/dataplane/virtio-blk.c +1 -1
index 5556f0e..6fdc6f6 100644
@@ -116,7 +116,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *conf,
     s->conf = conf;
 
     if (conf->iothread) {
-        s->iothread = conf->iothread;
+        s->iothread = IOTHREAD(conf->iothread);
         object_ref(OBJECT(s->iothread));
         s->ctx = iothread_get_aio_context(s->iothread);
     } else {
hw/block/virtio-blk.c +3 -4
index 604d37d..aa2c38c 100644
@@ -981,10 +981,6 @@ static void virtio_blk_instance_init(Object *obj)
 {
     VirtIOBlock *s = VIRTIO_BLK(obj);
 
-    object_property_add_link(obj, "iothread", TYPE_IOTHREAD,
-                             (Object **)&s->conf.iothread,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
     device_add_bootindex_property(obj, &s->conf.conf.bootindex,
                                   "bootindex", "/disk@0,0",
                                   DEVICE(obj), NULL);
@@ -1012,6 +1008,9 @@ static Property virtio_blk_properties[] = {
     DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, 0,
                     true),
     DEFINE_PROP_UINT16("num-queues", VirtIOBlock, conf.num_queues, 1),
+    DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD,
+                     qdev_prop_allow_set_link_before_realize,
+                     OBJ_PROP_LINK_UNREF_ON_RELEASE),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/virtio/virtio-pci.c +0 -2
index 20d6a08..e6960ae 100644
@@ -1996,8 +1996,6 @@ static void virtio_blk_pci_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_BLK);
-    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothread",
-                              &error_abort);
     object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev),
                               "bootindex", &error_abort);
 }
include/hw/virtio/virtio-blk.h +1 -1
index d3c8a6f..94a9f0c 100644
@@ -33,7 +33,7 @@ struct virtio_blk_inhdr
 struct VirtIOBlkConf
 {
     BlockConf conf;
-    IOThread *iothread;
+    Object *iothread;
     char *serial;
     uint32_t scsi;
     uint32_t config_wce;
Signature · 1 line
2.9.4
author
#13 lore raw

PATCH 6/7 virtio-scsi: Use DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/scsi/virtio-scsi-dataplane.c |  2 +-
 hw/scsi/virtio-scsi.c           | 15 ++++-----------
 hw/virtio/virtio-pci.c          |  2 --
 include/hw/virtio/virtio-scsi.h |  2 +-
 4 files changed, 6 insertions(+), 15 deletions(-)
hw/scsi/virtio-scsi-dataplane.c +1 -1
index 944ea4e..887c100 100644
@@ -40,7 +40,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp)
             error_setg(errp, "ioeventfd is required for iothread");
             return;
         }
-        s->ctx = iothread_get_aio_context(vs->conf.iothread);
+        s->ctx = iothread_get_aio_context(IOTHREAD(vs->conf.iothread));
     } else {
         if (!virtio_device_ioeventfd_enabled(vdev)) {
             return;
hw/scsi/virtio-scsi.c +4 -11
index f46f06d..afe4389 100644
@@ -897,16 +897,6 @@ static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
     virtio_scsi_dataplane_setup(s, errp);
 }
 
-static void virtio_scsi_instance_init(Object *obj)
-{
-    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(obj);
-
-    object_property_add_link(obj, "iothread", TYPE_IOTHREAD,
-                             (Object **)&vs->conf.iothread,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort);
-}
-
 void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -934,6 +924,10 @@ static Property virtio_scsi_properties[] = {
                                            VIRTIO_SCSI_F_HOTPLUG, true),
     DEFINE_PROP_BIT("param_change", VirtIOSCSI, host_features,
                                                 VIRTIO_SCSI_F_CHANGE, true),
+    DEFINE_PROP_LINK("iothread", VirtIOSCSI, parent_obj.conf.iothread,
+                     TYPE_IOTHREAD,
+                     qdev_prop_allow_set_link_before_realize,
+                     OBJ_PROP_LINK_UNREF_ON_RELEASE),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -988,7 +982,6 @@ static const TypeInfo virtio_scsi_info = {
     .name = TYPE_VIRTIO_SCSI,
     .parent = TYPE_VIRTIO_SCSI_COMMON,
     .instance_size = sizeof(VirtIOSCSI),
-    .instance_init = virtio_scsi_instance_init,
     .class_init = virtio_scsi_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_HOTPLUG_HANDLER },
hw/virtio/virtio-pci.c +0 -2
index e6960ae..eb03ba5 100644
@@ -2065,8 +2065,6 @@ static void virtio_scsi_pci_instance_init(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_SCSI);
-    object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothread",
-                              &error_abort);
 }
 
 static const TypeInfo virtio_scsi_pci_info = {
include/hw/virtio/virtio-scsi.h +1 -1
index de6ae5a..1decc40 100644
@@ -56,7 +56,7 @@ struct VirtIOSCSIConf {
 #endif
     CharBackend chardev;
     uint32_t boot_tpgt;
-    IOThread *iothread;
+    Object *iothread;
 };
 
 struct VirtIOSCSI;
Signature · 1 line
2.9.4
author
#14 lore raw

PATCH 7/7 virtio-rng: Use DEFINE_PROP_LINK

In reply to Fam Zheng
---
 hw/virtio/virtio-pci.c         |  2 --
 hw/virtio/virtio-rng.c         | 16 ++++------------
 include/hw/virtio/virtio-rng.h |  2 +-
 3 files changed, 5 insertions(+), 15 deletions(-)
hw/virtio/virtio-pci.c +0 -2
index eb03ba5..0938db4 100644
@@ -2459,8 +2459,6 @@ static void virtio_rng_initfn(Object *obj)
 
     virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
                                 TYPE_VIRTIO_RNG);
-    object_property_add_alias(obj, "rng", OBJECT(&dev->vdev), "rng",
-                              &error_abort);
 }
 
 static const TypeInfo virtio_rng_pci_info = {
hw/virtio/virtio-rng.c +4 -12
index a6ee501..218778b 100644
@@ -199,7 +199,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
                                  "rng", NULL);
     }
 
-    vrng->rng = vrng->conf.rng;
+    vrng->rng = RNG_BACKEND(vrng->conf.rng);
     if (vrng->rng == NULL) {
         error_setg(errp, "'rng' parameter expects a valid object");
         return;
@@ -246,6 +246,9 @@ static Property virtio_rng_properties[] = {
      */
     DEFINE_PROP_UINT64("max-bytes", VirtIORNG, conf.max_bytes, INT64_MAX),
     DEFINE_PROP_UINT32("period", VirtIORNG, conf.period_ms, 1 << 16),
+    DEFINE_PROP_LINK("rng", VirtIORNG, conf.rng, TYPE_RNG_BACKEND,
+                     qdev_prop_allow_set_link_before_realize,
+                     OBJ_PROP_LINK_UNREF_ON_RELEASE),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -262,21 +265,10 @@ static void virtio_rng_class_init(ObjectClass *klass, void *data)
     vdc->get_features = get_features;
 }
 
-static void virtio_rng_initfn(Object *obj)
-{
-    VirtIORNG *vrng = VIRTIO_RNG(obj);
-
-    object_property_add_link(obj, "rng", TYPE_RNG_BACKEND,
-                             (Object **)&vrng->conf.rng,
-                             qdev_prop_allow_set_link_before_realize,
-                             OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
-}
-
 static const TypeInfo virtio_rng_info = {
     .name = TYPE_VIRTIO_RNG,
     .parent = TYPE_VIRTIO_DEVICE,
     .instance_size = sizeof(VirtIORNG),
-    .instance_init = virtio_rng_initfn,
     .class_init = virtio_rng_class_init,
 };
 
include/hw/virtio/virtio-rng.h +1 -1
index 922dce7..8d45597 100644
@@ -23,7 +23,7 @@
         OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG)
 
 struct VirtIORNGConf {
-    RngBackend *rng;
+    Object *rng;
     uint64_t max_bytes;
     uint32_t period_ms;
     RngRandom *default_backend;
Signature · 1 line
2.9.4