qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* qdev unrealize error handling WTF?!?
@ 2020-04-27 12:33 Markus Armbruster
  2020-04-27 13:44 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2020-04-27 12:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Daniel P. Berrangé, Eduardo Habkost

Have a look at device_set_realized():

    static void device_set_realized(Object *obj, bool value, Error **errp)
    {
        DeviceState *dev = DEVICE(obj);
        DeviceClass *dc = DEVICE_GET_CLASS(dev);
        HotplugHandler *hotplug_ctrl;
        BusState *bus;
        Error *local_err = NULL;
        bool unattached_parent = false;
        static int unattached_count;

        if (dev->hotplugged && !dc->hotpluggable) {
            error_setg(errp, QERR_DEVICE_NO_HOTPLUG, object_get_typename(obj));
            return;
        }

        if (value && !dev->realized) {
            [code to realize snipped...]
        } else if (!value && dev->realized) {
            /* We want local_err to track only the first error */
            QLIST_FOREACH(bus, &dev->child_bus, sibling) {
[1]             object_property_set_bool(OBJECT(bus), false, "realized",
                                         local_err ? NULL : &local_err);
            }
            if (qdev_get_vmsd(dev)) {
[2]             vmstate_unregister(VMSTATE_IF(dev), qdev_get_vmsd(dev), dev);
            }
            if (dc->unrealize) {
[3]             dc->unrealize(dev, local_err ? NULL : &local_err);
            }
            dev->pending_deleted_event = true;
[4]         DEVICE_LISTENER_CALL(unrealize, Reverse, dev);

            if (local_err != NULL) {
                goto fail;
            }
        }

        assert(local_err == NULL);
        dev->realized = value;
        return;

    [realize-only error handling snipped...]
    fail:
        error_propagate(errp, local_err);
        if (unattached_parent) {
            object_unparent(OBJECT(dev));
            unattached_count--;
        }
    }

Can fail in two places: [1] a device on dev->child_bus fails to
unrealize, or [3] @dev itself fails to unrealize.  We hold on to the
first failure, and continue to unrealize.  device_set_realized() fails
when any of these fail.

Issue #1: What if some, but not all fail?  How can this possibly work?

Issue #2: Even if all fail, and therefore both the device and the ones
on ->child_bus all remain realized, there are side effects at [2] and
[4].

Any better ideas than &error_abort?



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: qdev unrealize error handling WTF?!?
  2020-04-27 12:33 qdev unrealize error handling WTF?!? Markus Armbruster
@ 2020-04-27 13:44 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-04-27 13:44 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel; +Cc: Daniel P. Berrangé, Eduardo Habkost

On 27/04/20 14:33, Markus Armbruster wrote:
> [1] a device on dev->child_bus fails to
> unrealize, or [3] @dev itself fails to unrealize.  We hold on to the
> first failure, and continue to unrealize.  device_set_realized() fails
> when any of these fail.
> 
> Issue #1: What if some, but not all fail?  How can this possibly work?
> 
> Issue #2: Even if all fail, and therefore both the device and the ones
> on ->child_bus all remain realized, there are side effects at [2] and
> [4].
> 
> Any better ideas than &error_abort?

I don't think we have unrealizes that fail, so removing the argument and
&error_abort is the best idea.

Paolo



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-27 13:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-27 12:33 qdev unrealize error handling WTF?!? Markus Armbruster
2020-04-27 13:44 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).