fix: unrealize virtio device if we fail to hotplug it
PATCH 1/1 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 byvm_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.
--- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+)
hw/virtio/virtio.c +1 -0
@@ -2491,6 +2491,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)virtio_bus_device_plugged (vdev, &err);if (err !=NULL ) {error_propagate (errp, err); + vdc->unrealize (dev,NULL );return ; }
Signature · 1 line
2.12.2.windows.2
Quoted 24 lines · linzhecheng
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 crashProblem happens in
virtio_vmstate_changewhich is called byvm_state_notify:
vdev’sparent_busis NULL, so qdev_get_parent_bus(DEVICE(vdev)) will crash.virtio_vmstate_changeis added to the listvm_change_state_headatvirtio_blk_device_realize(virtio_init), but after hotplug virtio-blk failed,virtio_vmstate_changewill not be removed fromvm_change_state_head. Adding unrealize function of virtio-blk device can solve this problem.
Quoted 4 lines
Signed-off-by linzhecheng <[email protected]>--- hw/virtio/virtio.c | 1 + 1 file changed, 1 insertion(+)