[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices
From: |
Paolo Bonzini |
Subject: |
Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices |
Date: |
Wed, 20 May 2020 18:24:01 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 |
On 20/05/20 17:02, Markus Armbruster wrote:
>>>
>>> qdev_realize_and_unref() remains restricted, because its reference
>>> counting would become rather confusing for bus-less devices.
>> I think it would be fine, you would just rely on the reference held by
>> the QOM parent (via the child property).
> I took one look at the contract I wrote for it, and balked :)
>
> qdev_realize()'s contract before this patch:
>
> /*
> * Realize @dev.
> * @dev must not be plugged into a bus.
> * Plug @dev into @bus. This takes a reference to @dev.
> * If @dev has no QOM parent, make one up, taking another reference.
> * On success, return true.
> * On failure, store an error through @errp and return false.
> */
> bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
>
> Simple enough.
>
> This patch merely adds "If @bus, " before "plug". Still simple enough.
>
> qdev_realize_and_unref()'s contract:
>
> /*
> * Realize @dev and drop a reference.
> * This is like qdev_realize(), except it steals a reference rather
> * than take one to plug @dev into @bus. On failure, it drops that
> * reference instead. @bus must not be null. Intended use:
> * dev = qdev_new();
> * [...]
> * qdev_realize_and_unref(dev, bus, errp);
> * Now @dev can go away without further ado.
> */
> bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp)
>
> If @bus is null, who gets to hold the stolen reference?
>
> You seem to suggest the QOM parent. What if @dev already has a parent?
The caller would still hold the stolen reference, and it would be
dropped. You cannot have a device that goes away at the end of
qdev_realize_and_unref, as long as dev has a QOM parent that clings onto
dev. Since dev will have /machine/unattached as the parent if it didn't
already have one before, the function is safe even without a bus.
Or alternatively, ignore all the stolen references stuff, and merely see
qdev_realize_and_unref as a shortcut for qdev_realize+object_unref,
because it's a common idiom.
Paolo
- [PATCH 54/55] qdev: qdev_init_nofail() is now unused, drop, (continued)
- [PATCH 54/55] qdev: qdev_init_nofail() is now unused, drop, Markus Armbruster, 2020/05/19
- [PATCH 17/55] isa: New isa_new(), isa_realize_and_unref() etc., Markus Armbruster, 2020/05/19
- [PATCH 52/55] qdev: Use qdev_realize() in qdev_device_add(), Markus Armbruster, 2020/05/19
- [PATCH 37/55] sysbus: Drop useless OBJECT() in sysbus_init_child_obj() calls, Markus Armbruster, 2020/05/19
- [PATCH 25/55] usb: New usb_new(), usb_realize_and_unref(), Markus Armbruster, 2020/05/19
- [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices, Markus Armbruster, 2020/05/19
- Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices, Paolo Bonzini, 2020/05/20
- Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices, Markus Armbruster, 2020/05/20
- Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices,
Paolo Bonzini <=
- Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices, Markus Armbruster, 2020/05/25
- Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices, Paolo Bonzini, 2020/05/25
- Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices, Markus Armbruster, 2020/05/26
- Re: [PATCH 51/55] qdev: Make qdev_realize() support bus-less devices, Paolo Bonzini, 2020/05/26
[PATCH 47/55] sysbus: Convert qdev_set_parent_bus() use with Coccinelle, part 3, Markus Armbruster, 2020/05/19
[PATCH 26/55] usb: Convert uses of usb_create(), Markus Armbruster, 2020/05/19
[PATCH 35/55] macio: Convert use of qdev_set_parent_bus(), Markus Armbruster, 2020/05/19
[PATCH 36/55] macio: Eliminate macio_init_child_obj(), Markus Armbruster, 2020/05/19
[PATCH 42/55] sysbus: New sysbus_realize(), sysbus_realize_and_unref(), Markus Armbruster, 2020/05/19