From 259d69c00b67c02a67f3bdbeeea71c2c0af76c35 Mon Sep 17 00:00:00 2001 From: Alex Bennée Date: Mon, 7 Nov 2022 12:14:07 +0000 Subject: hw/virtio: introduce virtio_device_should_start The previous fix to virtio_device_started revealed a problem in its use by both the core and the device code. The core code should be able to handle the device "starting" while the VM isn't running to handle the restoration of migration state. To solve this duel use introduce a new helper for use by the vhost-user backends who all use it to feed a should_start variable. We can also pick up a change vhost_user_blk_set_status while we are at it which follows the same pattern. Fixes: 9f6bcfd99f (hw/virtio: move vm_running check to virtio_device_started) Signed-off-by: Alex Bennée Cc: "Michael S. Tsirkin" Message-Id: <20221107121407.1010913-1-alex.bennee@linaro.org> --- include/hw/virtio/virtio.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include') diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 1423dba379..141a253a2c 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -395,6 +395,24 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status) return vdev->started; } + return status & VIRTIO_CONFIG_S_DRIVER_OK; +} + +/** + * virtio_device_should_start() - check if device startable + * @vdev - the VirtIO device + * @status - the devices status bits + * + * This is similar to virtio_device_started() but also encapsulates a + * check on the VM status which would prevent a device starting + * anyway. + */ +static inline bool virtio_device_should_start(VirtIODevice *vdev, uint8_t status) +{ + if (vdev->use_started) { + return vdev->started; + } + if (!vdev->vm_running) { return false; } -- cgit v1.2.3-55-g7522