Convert the *_orphan() device-creation calls in hw/xen to the new parented API introduced earlier in this series, so every onboard device gets a stable path in the composition tree instead of landing in /machine/unattached with an unstable device[N] name.
The parent for each device is the object that owns its lifetime: the machine for board-created devices, the containing device for composite children. Names follow existing QOM conventions. Per-site rationale (reviewers: dispute the modeling here): hw/xen/xen-bus.c:1152 | qdev_new | qdev_get_machine() | "xen-bridge" | init helper called from 3 board paths with no parent arg; use qdev_get_machine() (already used in this subsystem) hw/xen/xen-legacy-backend.c:601 | qdev_new | qdev_get_machine() | "xen-sysdev" | init helper with no parent arg; qdev_get_machine() already used just above in xen_set_dynamic_sysbus() hw/xen/xen-pvh-common.c:176 | sysbus_create_simple | OBJECT(s) | "virtio-mmio[*]" | board-init helper receives XenPVHMachineState *s; loop-created hw/xen/xen-pvh-common.c:196 | qdev_new | OBJECT(s) | "tpm" | board-init helper receives XenPVHMachineState *s hw/xen/xen_pt_graphics.c:402 | pci_create_simple | OBJECT(s) | "isa-bridge" | called from XenPCIPassthroughState realize; s is the composite passthrough device Link: https://lore.kernel.org/qemu-devel/[email protected]/ AI-used-for: code (refactoring) Signed-off-by: Alexander Graf <[email protected]> --- hw/xen/xen-bus.c | 5 +++-- hw/xen/xen-legacy-backend.c | 5 +++-- hw/xen/xen-pvh-common.c | 7 ++++--- hw/xen/xen_pt_graphics.c | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 746014416b..934ff33402 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -1149,10 +1149,11 @@ type_init(xen_register_types) void xen_bus_init(void) { - DeviceState *dev = qdev_new_orphan(TYPE_XEN_BRIDGE); + DeviceState *dev = qdev_new(qdev_get_machine(), "xen-bridge", + TYPE_XEN_BRIDGE); BusState *bus = qbus_new(TYPE_XEN_BUS, dev, NULL); - sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); qbus_set_bus_hotplug_handler(bus); qemu_create_nic_bus_devices(bus, TYPE_XEN_DEVICE, "xen-net-device", diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c index 29c90a388c..0e1da18d12 100644 --- a/hw/xen/xen-legacy-backend.c +++ b/hw/xen/xen-legacy-backend.c @@ -598,8 +598,9 @@ void xen_be_init(void) exit(1); } - xen_sysdev = qdev_new_orphan(TYPE_XENSYSDEV); - sysbus_realize_and_unref(SYS_BUS_DEVICE(xen_sysdev), &error_fatal); + xen_sysdev = qdev_new(qdev_get_machine(), "xen-sysdev", + TYPE_XENSYSDEV); + sysbus_realize(SYS_BUS_DEVICE(xen_sysdev), &error_fatal); xen_sysbus = qbus_new(TYPE_XENSYSBUS, xen_sysdev, "xen-sysbus"); qbus_set_bus_hotplug_handler(xen_sysbus); diff --git a/hw/xen/xen-pvh-common.c b/hw/xen/xen-pvh-common.c index 17f545d07c..dae523f723 100644 --- a/hw/xen/xen-pvh-common.c +++ b/hw/xen/xen-pvh-common.c @@ -173,7 +173,8 @@ static void xen_create_virtio_mmio_devices(XenPVHMachineState *s) qemu_irq irq = qemu_allocate_irq(xen_set_irq, NULL, s->cfg.virtio_mmio_irq_base + i); - sysbus_create_simple_orphan("virtio-mmio", base, irq); + sysbus_create_simple(OBJECT(s), "virtio-mmio[*]", "virtio-mmio", + base, irq); trace_xen_create_virtio_mmio_devices(i, s->cfg.virtio_mmio_irq_base + i, @@ -193,7 +194,7 @@ static void xen_enable_tpm(XenPVHMachineState *s) error_report("Couldn't find tmp0 backend"); return; } - dev = qdev_new_orphan(TYPE_TPM_TIS_SYSBUS); + dev = qdev_new(OBJECT(s), "tpm", TYPE_TPM_TIS_SYSBUS); /* * FIXME This use of &err is is wrong. If both calls fail, the * second will trip error_setv()'s assertion. If just one call @@ -204,7 +205,7 @@ static void xen_enable_tpm(XenPVHMachineState *s) object_property_set_link(OBJECT(dev), "tpmdev", OBJECT(be), &err); object_property_set_str(OBJECT(dev), "tpmdev", be->id, &err); busdev = SYS_BUS_DEVICE(dev); - sysbus_realize_and_unref(busdev, &error_fatal); + sysbus_realize(busdev, &error_fatal); sysbus_mmio_map(busdev, 0, s->cfg.tpm.base); trace_xen_enable_tpm(s->cfg.tpm.base); diff --git a/hw/xen/xen_pt_graphics.c b/hw/xen/xen_pt_graphics.c index 4457209e83..2841b45ca1 100644 --- a/hw/xen/xen_pt_graphics.c +++ b/hw/xen/xen_pt_graphics.c @@ -399,7 +399,8 @@ void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s, } /* Currently IGD drivers always need to access PCH by 1f.0. */ - bridge_dev = pci_create_simple_orphan(bus, PCI_DEVFN(0x1f, 0), + bridge_dev = pci_create_simple(OBJECT(s), "isa-bridge", bus, + PCI_DEVFN(0x1f, 0), "igd-passthrough-isa-bridge"); /* -- 2.47.1
