aboutsummaryrefslogtreecommitdiff
path: root/hw/virtio
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2022-08-02 10:49:58 +0100
committerMichael S. Tsirkin <mst@redhat.com>2022-10-07 09:41:51 -0400
commit9f6bcfd99f46377888059d8539befec9505f57fb (patch)
tree7ebee167ba59b63f6c9058217b0f86c1336cd547 /hw/virtio
parenta27612311988aff8f29a68ed5eaecde3bf6cdf99 (diff)
downloadqemu-9f6bcfd99f46377888059d8539befec9505f57fb.zip
qemu-9f6bcfd99f46377888059d8539befec9505f57fb.tar.gz
qemu-9f6bcfd99f46377888059d8539befec9505f57fb.tar.bz2
hw/virtio: move vm_running check to virtio_device_started
All the boilerplate virtio code does the same thing (or should at least) of checking to see if the VM is running before attempting to start VirtIO. Push the logic up to the common function to avoid getting a copy and paste wrong. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20220802095010.3330793-11-alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'hw/virtio')
-rw-r--r--hw/virtio/vhost-user-fs.c6
-rw-r--r--hw/virtio/vhost-user-i2c.c6
-rw-r--r--hw/virtio/vhost-user-rng.c6
-rw-r--r--hw/virtio/vhost-user-vsock.c6
-rw-r--r--hw/virtio/vhost-vsock.c6
5 files changed, 5 insertions, 25 deletions
diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
index e513e4f..d2bebba 100644
--- a/hw/virtio/vhost-user-fs.c
+++ b/hw/virtio/vhost-user-fs.c
@@ -122,11 +122,7 @@ static void vuf_stop(VirtIODevice *vdev)
static void vuf_set_status(VirtIODevice *vdev, uint8_t status)
{
VHostUserFS *fs = VHOST_USER_FS(vdev);
- bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
-
- if (!vdev->vm_running) {
- should_start = false;
- }
+ bool should_start = virtio_device_started(vdev, status);
if (fs->vhost_dev.started == should_start) {
return;
diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
index 6020eee..b930cf6 100644
--- a/hw/virtio/vhost-user-i2c.c
+++ b/hw/virtio/vhost-user-i2c.c
@@ -93,11 +93,7 @@ static void vu_i2c_stop(VirtIODevice *vdev)
static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status)
{
VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
- bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
-
- if (!vdev->vm_running) {
- should_start = false;
- }
+ bool should_start = virtio_device_started(vdev, status);
if (i2c->vhost_dev.started == should_start) {
return;
diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c
index 3a7bf8e..a9c1c4b 100644
--- a/hw/virtio/vhost-user-rng.c
+++ b/hw/virtio/vhost-user-rng.c
@@ -90,11 +90,7 @@ static void vu_rng_stop(VirtIODevice *vdev)
static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status)
{
VHostUserRNG *rng = VHOST_USER_RNG(vdev);
- bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
-
- if (!vdev->vm_running) {
- should_start = false;
- }
+ bool should_start = virtio_device_started(vdev, status);
if (rng->vhost_dev.started == should_start) {
return;
diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c
index 0f8ff99..22c1616 100644
--- a/hw/virtio/vhost-user-vsock.c
+++ b/hw/virtio/vhost-user-vsock.c
@@ -55,11 +55,7 @@ const VhostDevConfigOps vsock_ops = {
static void vuv_set_status(VirtIODevice *vdev, uint8_t status)
{
VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
- bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
-
- if (!vdev->vm_running) {
- should_start = false;
- }
+ bool should_start = virtio_device_started(vdev, status);
if (vvc->vhost_dev.started == should_start) {
return;
diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
index 0338de8..8031c16 100644
--- a/hw/virtio/vhost-vsock.c
+++ b/hw/virtio/vhost-vsock.c
@@ -70,13 +70,9 @@ static int vhost_vsock_set_running(VirtIODevice *vdev, int start)
static void vhost_vsock_set_status(VirtIODevice *vdev, uint8_t status)
{
VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
- bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
+ bool should_start = virtio_device_started(vdev, status);
int ret;
- if (!vdev->vm_running) {
- should_start = false;
- }
-
if (vvc->vhost_dev.started == should_start) {
return;
}