On 06/19/17 20:49, Mark Cave-Ayland wrote: > On 19/06/17 18:09, Laszlo Ersek wrote: > >>> What seems to happen is that calling object_property_add_child() only >>> succeeds for the first instance and so a simple comparison is enough to >>> determine that the device already exists at FW_CFG_PATH. Or is this a >>> fairly terrible (ab)use of the QOM APIs? >> >> This has jogged my memory about how we ensure "at most one" for the >> vmgenid device. Please see: >> >> vmgenid_realize() [hw/acpi/vmgenid.c] >> find_vmgenid_dev() [include/hw/acpi/vmgenid.h] >> >> ... I was quite silly not to think of this on my own now, despite having >> authored commit f92063028a0e ("hw/acpi/vmgenid: prevent more than one >> vmgenid device", 2017-03-20) :/ > > Right that definitely helps - the following code seems to work correctly > when trying to instantiate a mixture of fw_cfg_io and/or fw_cfg_mem types: > > if (!object_resolve_path_type("", TYPE_FW_CFG, NULL)) { > error_setg(errp, "at most one %s device is permitted", TYPE_FW_CFG); > return; > } > > I've also copied the wording from the above commit to make everything > consistent. Does that seem okay? If so, I'll fold it into a v7 patchset.
It looks good to me, but please await Eduardo's reply as well. In particular, it should be confirmed that object_resolve_path_type() matches instances of *subclasses* as well (as I expect it would). Your test results confirm that; let's make sure it is intentional behavior. Eduardo (or someone else on the CC list), can you please comment on that? Thanks! Laszlo