qemu-e2k/hw/s390x
David Hildenbrand 07578b0ad6 qdev: Let the hotplug_handler_unplug() caller delete the device
When unplugging a device, at one point the device will be destroyed
via object_unparent(). This will, one the one hand, unrealize the
removed device hierarchy, and on the other hand, destroy/free the
device hierarchy.

When chaining hotplug handlers, we want to overwrite a bus hotplug
handler by the machine hotplug handler, to be able to perform
some part of the plug/unplug and to forward the calls to the bus hotplug
handler.

For now, the bus hotplug handler would trigger an object_unparent(), not
allowing us to perform some unplug action on a device after we forwarded
the call to the bus hotplug handler. The device would be gone at that
point.

machine_unplug_handler(dev)
    /* eventually do unplug stuff */
    bus_unplug_handler(dev)
    /* dev is gone, we can't do more unplug stuff */

So move the object_unparent() to the original caller of the unplug. For
now, keep the unrealize() at the original places of the
object_unparent(). For implicitly chained hotplug handlers (e.g. pc
code calling acpi hotplug handlers), the object_unparent() has to be
done by the outermost caller. So when calling hotplug_handler_unplug()
from inside an unplug handler, nothing is to be done.

hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
    machine_unplug_handler(dev) {
        /* eventually do unplug stuff */
        bus_unplug_handler(dev) -> calls unrealize(dev)
        /* we can do more unplug stuff but device already unrealized */
    }
object_unparent(dev)

In the long run, every unplug action should be factored out of the
unrealize() function into the unplug handler (especially for PCI). Then
we can get rid of the additonal unrealize() calls and object_unparent()
will properly unrealize the device hierarchy after the device has been
unplugged.

hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
    machine_unplug_handler(dev) {
        /* eventually do unplug stuff */
        bus_unplug_handler(dev) -> only unplugs, does not unrealize
        /* we can do more unplug stuff */
    }
object_unparent(dev) -> will unrealize

The original approach was suggested by Igor Mammedov for the PCI
part, but I extended it to all hotplug handlers. I consider this one
step into the right direction.

To summarize:
- object_unparent() on synchronous unplugs is done by common code
-- "Caller of hotplug_handler_unplug"
- object_unparent() on asynchronous unplugs ("unplug requests") has to
  be done manually
-- "Caller of hotplug_handler_unplug"

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20190228122849.4296-2-david@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-03-06 11:51:08 -03:00
..
3270-ccw.c s390x: remove 's390-squash-mcss' option 2018-08-20 14:18:49 +02:00
ap-bridge.c s390x/vfio-ap: Implement hot plug/unplug of vfio-ap device 2019-03-04 11:49:31 +01:00
ap-device.c s390x/ap: base Adjunct Processor (AP) object model 2018-10-12 11:32:18 +02:00
ccw-device.c
ccw-device.h
css-bridge.c qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
css.c hw/s390/ccw.c: Don't take address of packed members 2018-12-20 17:07:24 +01:00
event-facility.c
ipl.c elf: Add optional function ptr to load_elf() to parse ELF notes 2019-02-05 16:50:16 +01:00
ipl.h hw/s390x/ipl: Fix alignment problems of S390IPLState members 2018-10-04 10:32:38 +02:00
Makefile.objs s390x: always provide pci support 2019-02-18 11:25:43 +01:00
s390-ccw.c s390x: remove 's390-squash-mcss' option 2018-08-20 14:18:49 +02:00
s390-pci-bus.c qdev: Let the hotplug_handler_unplug() caller delete the device 2019-03-06 11:51:08 -03:00
s390-pci-bus.h s390x/pci: Drop release timer and replace it with a flag 2019-02-04 13:47:50 +01:00
s390-pci-inst.c s390x/pci: add common function measurement block 2019-01-18 11:52:01 +01:00
s390-pci-inst.h s390x/pci: add common function measurement block 2019-01-18 11:52:01 +01:00
s390-skeys-kvm.c
s390-skeys.c qapi: make s390 commands depend on TARGET_S390X 2019-02-18 14:44:05 +01:00
s390-stattrib-kvm.c s390x/storage attributes: fix CMMA_BLOCK_SIZE usage 2018-07-11 14:36:54 +02:00
s390-stattrib.c s390x/storage attributes: fix CMMA_BLOCK_SIZE usage 2018-07-11 14:36:54 +02:00
s390-virtio-ccw.c s390x/cpumodel: default enable mepoch for z14 and later 2019-02-18 11:25:43 +01:00
s390-virtio-hcall.c
s390-virtio-hcall.h
sclp.c s390x/sclp: fix maxram calculation 2018-07-30 17:41:52 +02:00
sclpcpu.c
sclpquiesce.c
tod-kvm.c s390x/tod: Properly stop the KVM TOD while the guest is not running 2018-12-12 10:39:28 +01:00
tod-qemu.c
tod.c
trace-events
vhost-vsock-ccw.c hw/s390x: Move vhost-vsock-ccw code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-9p.c hw/s390x: Move virtio-ccw-9p code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-balloon.c hw/s390x: Move virtio-ccw-balloon code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-blk.c hw/s390x: Move virtio-ccw-blk code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-crypto.c hw/s390x: Move virtio-ccw-crypto code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-gpu.c hw/s390x: Move virtio-ccw-gpu code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-input.c hw/s390x: Move virtio-ccw-input code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-net.c hw/s390x: Move virtio-ccw-net code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-rng.c hw/s390x: Move virtio-ccw-rng code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-scsi.c hw/s390x: Move virtio-ccw-scsi code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw-serial.c hw/s390x: Move virtio-ccw-serial code to a separate file 2018-08-28 17:37:01 +02:00
virtio-ccw.c hw/s390x/virtio-ccw.c: Don't take address of fields in packed structs 2018-12-12 10:39:28 +01:00
virtio-ccw.h