The XenBackendInfo .create callbacks (vif, console, vbd) create a
XenDevice in response to xenstore hotplug events.  The lifetime
owner is the xen-bridge device that hosts the XenBus, so parent
each device there.  The failure paths already call object_unparent()
so nothing else changes; the reference previously dropped by
qdev_realize_and_unref() is now the parent's child<> property.

Assisted-by: Kiro
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/block/xen-block.c  | 5 +++--
 hw/char/xen_console.c | 5 +++--
 hw/net/xen_nic.c      | 5 +++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 9dd69faa02..46d94a9a95 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -1074,7 +1074,8 @@ static void xen_block_device_create(XenBackendInstance 
*backend,
         goto fail;
     }
 
-    xendev = XEN_DEVICE(qdev_new_orphan(type));
+    xendev = XEN_DEVICE(qdev_new(OBJECT(BUS(xenbus)->parent), "vbd[*]",
+                                 type));
     blockdev = XEN_BLOCK_DEVICE(xendev);
 
     if (!object_property_set_str(OBJECT(xendev), "vdev", vdev,
@@ -1099,7 +1100,7 @@ static void xen_block_device_create(XenBackendInstance 
*backend,
     blockdev->iothread = iothread;
     blockdev->drive = drive;
 
-    if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
+    if (!qdev_realize(DEVICE(xendev), BUS(xenbus), errp)) {
         error_prepend(errp, "realization of device %s failed: ", type);
         goto fail;
     }
diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c
index cd440b82f4..40449b34e8 100644
--- a/hw/char/xen_console.c
+++ b/hw/char/xen_console.c
@@ -562,7 +562,8 @@ static void xen_console_device_create(XenBackendInstance 
*backend,
         goto fail;
     }
 
-    xendev = XEN_DEVICE(qdev_new_orphan(TYPE_XEN_CONSOLE_DEVICE));
+    xendev = XEN_DEVICE(qdev_new(OBJECT(BUS(xenbus)->parent), "console[*]",
+                                 TYPE_XEN_CONSOLE_DEVICE));
     con = XEN_CONSOLE_DEVICE(xendev);
 
     con->dev = number;
@@ -610,7 +611,7 @@ static void xen_console_device_create(XenBackendInstance 
*backend,
         goto fail;
     }
 
-    if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
+    if (qdev_realize(DEVICE(xendev), BUS(xenbus), errp)) {
         xen_backend_set_device(backend, xendev);
         goto done;
     }
diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c
index 212281aac7..ff748ae070 100644
--- a/hw/net/xen_nic.c
+++ b/hw/net/xen_nic.c
@@ -619,13 +619,14 @@ static void xen_net_device_create(XenBackendInstance 
*backend,
         goto fail;
     }
 
-    xendev = XEN_DEVICE(qdev_new_orphan(TYPE_XEN_NET_DEVICE));
+    xendev = XEN_DEVICE(qdev_new(OBJECT(BUS(xenbus)->parent), "vif[*]",
+                                 TYPE_XEN_NET_DEVICE));
     net = XEN_NET_DEVICE(xendev);
 
     net->dev = number;
     memcpy(&net->conf.macaddr, &mac, sizeof(mac));
 
-    if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
+    if (qdev_realize(DEVICE(xendev), BUS(xenbus), errp)) {
         xen_backend_set_device(backend, xendev);
         return;
     }
-- 
2.47.1


Reply via email to