mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-30 06:50:57 +00:00
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>
This commit is contained in:
parent
a276123119
commit
9f6bcfd99f
@ -122,11 +122,7 @@ static void vuf_stop(VirtIODevice *vdev)
|
|||||||
static void vuf_set_status(VirtIODevice *vdev, uint8_t status)
|
static void vuf_set_status(VirtIODevice *vdev, uint8_t status)
|
||||||
{
|
{
|
||||||
VHostUserFS *fs = VHOST_USER_FS(vdev);
|
VHostUserFS *fs = VHOST_USER_FS(vdev);
|
||||||
bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
|
bool should_start = virtio_device_started(vdev, status);
|
||||||
|
|
||||||
if (!vdev->vm_running) {
|
|
||||||
should_start = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs->vhost_dev.started == should_start) {
|
if (fs->vhost_dev.started == should_start) {
|
||||||
return;
|
return;
|
||||||
|
@ -93,11 +93,7 @@ static void vu_i2c_stop(VirtIODevice *vdev)
|
|||||||
static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status)
|
static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status)
|
||||||
{
|
{
|
||||||
VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
|
VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
|
||||||
bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
|
bool should_start = virtio_device_started(vdev, status);
|
||||||
|
|
||||||
if (!vdev->vm_running) {
|
|
||||||
should_start = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i2c->vhost_dev.started == should_start) {
|
if (i2c->vhost_dev.started == should_start) {
|
||||||
return;
|
return;
|
||||||
|
@ -90,11 +90,7 @@ static void vu_rng_stop(VirtIODevice *vdev)
|
|||||||
static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status)
|
static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status)
|
||||||
{
|
{
|
||||||
VHostUserRNG *rng = VHOST_USER_RNG(vdev);
|
VHostUserRNG *rng = VHOST_USER_RNG(vdev);
|
||||||
bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
|
bool should_start = virtio_device_started(vdev, status);
|
||||||
|
|
||||||
if (!vdev->vm_running) {
|
|
||||||
should_start = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rng->vhost_dev.started == should_start) {
|
if (rng->vhost_dev.started == should_start) {
|
||||||
return;
|
return;
|
||||||
|
@ -55,11 +55,7 @@ const VhostDevConfigOps vsock_ops = {
|
|||||||
static void vuv_set_status(VirtIODevice *vdev, uint8_t status)
|
static void vuv_set_status(VirtIODevice *vdev, uint8_t status)
|
||||||
{
|
{
|
||||||
VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
|
VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
|
||||||
bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
|
bool should_start = virtio_device_started(vdev, status);
|
||||||
|
|
||||||
if (!vdev->vm_running) {
|
|
||||||
should_start = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vvc->vhost_dev.started == should_start) {
|
if (vvc->vhost_dev.started == should_start) {
|
||||||
return;
|
return;
|
||||||
|
@ -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)
|
static void vhost_vsock_set_status(VirtIODevice *vdev, uint8_t status)
|
||||||
{
|
{
|
||||||
VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
|
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;
|
int ret;
|
||||||
|
|
||||||
if (!vdev->vm_running) {
|
|
||||||
should_start = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vvc->vhost_dev.started == should_start) {
|
if (vvc->vhost_dev.started == should_start) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ struct VirtIODevice
|
|||||||
VirtQueue *vq;
|
VirtQueue *vq;
|
||||||
MemoryListener listener;
|
MemoryListener listener;
|
||||||
uint16_t device_id;
|
uint16_t device_id;
|
||||||
|
/* @vm_running: current VM running state via virtio_vmstate_change() */
|
||||||
bool vm_running;
|
bool vm_running;
|
||||||
bool broken; /* device in invalid state, needs reset */
|
bool broken; /* device in invalid state, needs reset */
|
||||||
bool use_disabled_flag; /* allow use of 'disable' flag when needed */
|
bool use_disabled_flag; /* allow use of 'disable' flag when needed */
|
||||||
@ -376,6 +377,10 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status)
|
|||||||
return vdev->started;
|
return vdev->started;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!vdev->vm_running) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return status & VIRTIO_CONFIG_S_DRIVER_OK;
|
return status & VIRTIO_CONFIG_S_DRIVER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user