qemu-patch-raspberry4/hw/virtio
linzhecheng 7abea552ab fix: unrealize virtio device if we fail to hotplug it
If we fail to hotplug virtio-blk device and then suspend
or shutdown VM, qemu is likely to crash.

Re-production steps:
1. Run VM named vm001
2. Create a virtio-blk.xml which contains wrong configurations:
<disk device="lun" rawio="yes" type="block">
  <driver cache="none" io="native" name="qemu" type="raw" />
  <source dev="/dev/mapper/11-dm" />
  <target bus="virtio" dev="vdx" />
</disk>
3. Run command : virsh attach-device vm001 virtio-blk.xml
error: Failed to attach device from blk-scsi.xml
error: internal error: unable to execute QEMU command 'device_add': Please set scsi=off for virtio-blk devices in order to use virtio 1.0
it means hotplug virtio-blk device failed.
4. Suspend or shutdown VM will leads to qemu crash

Problem happens in virtio_vmstate_change which is called by
vm_state_notify:
vdev’s parent_bus is NULL, so qdev_get_parent_bus(DEVICE(vdev)) will crash.
virtio_vmstate_change is added to the list vm_change_state_head at virtio_blk_device_realize(virtio_init),
but after hotplug virtio-blk failed, virtio_vmstate_change will not be removed from vm_change_state_head.
Adding unrealize function of virtio-blk device can solve this problem.

Signed-off-by: linzhecheng <linzhecheng@huawei.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-11-16 17:46:53 +02:00
..
Makefile.objs stubs: move vhost stubs to stubs/vhost.o 2017-01-16 17:52:35 +01:00
trace-events trace-events: fix code style: print 0x before hex numbers 2017-08-01 12:13:07 +01:00
vhost-backend.c vhost: fix a memory leak 2017-08-02 00:13:25 +03:00
vhost-stub.c stubs: move vhost stubs to stubs/vhost.o 2017-01-16 17:52:35 +01:00
vhost-user.c vhost-user: fix legacy cross-endian configurations 2017-08-02 00:13:25 +03:00
vhost-vsock.c migration: pre_save return int 2017-09-27 11:35:59 +01:00
vhost.c virtio/vhost: reset dev->log after syncing 2017-10-15 05:54:41 +03:00
virtio-balloon.c Convert single line fprintf(.../n) to warn_report() 2017-09-19 14:09:34 +02:00
virtio-bus.c virtio: Fix error handling in virtio_bus_device_plugged 2017-03-22 17:54:32 +02:00
virtio-crypto-pci.c virtio-crypto: Convert to DEFINE_PROP_LINK 2017-07-14 12:04:43 +02:00
virtio-crypto.c virtio-crypto: Convert to DEFINE_PROP_LINK 2017-07-14 12:04:43 +02:00
virtio-mmio.c virtio-mmio: switch to linux headers 2017-01-18 22:59:53 +02:00
virtio-pci.c virtio-pci: Replace modern_as with direct access to modern_bar 2017-10-15 05:54:44 +03:00
virtio-pci.h virtio-pci: Replace modern_as with direct access to modern_bar 2017-10-15 05:54:44 +03:00
virtio-rng.c virtio-rng: Convert to DEFINE_PROP_LINK 2017-07-14 12:04:42 +02:00
virtio.c fix: unrealize virtio device if we fail to hotplug it 2017-11-16 17:46:53 +02:00