mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-09-09 00:07:57 -06:00
vhost: return failure if stop virtqueue failed in vhost_dev_stop
This patch captures the error of vhost_virtqueue_stop() in vhost_dev_stop() and returns the error upward. Specifically, if QEMU is disconnected from the vhost backend, some actions in vhost_dev_stop() will fail, such as sending vhost-user messages to the backend (GET_VRING_BASE, SET_VRING_ENABLE) and vhost_reset_status. Considering that both set_vring_enable and vhost_reset_status require setting the specific virtio feature bit, we can capture vhost_virtqueue_stop()'s error to indicate that QEMU has lost connection with the backend. This patch is the pre patch for 'vhost-user: return failure if backend crashes when live migration', which makes the live migration aware of the loss of connection with the vhost-user backend and aborts the live migration. Signed-off-by: Haoqian He <haoqian.he@smartx.com> Message-Id: <20250416024729.3289157-3-haoqian.he@smartx.com> Tested-by: Lei Yang <leiyang@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
e0f300b36d
commit
5a317017b8
2 changed files with 18 additions and 13 deletions
|
@ -1367,7 +1367,7 @@ fail_alloc_desc:
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vhost_virtqueue_stop(struct vhost_dev *dev,
|
int vhost_virtqueue_stop(struct vhost_dev *dev,
|
||||||
struct VirtIODevice *vdev,
|
struct VirtIODevice *vdev,
|
||||||
struct vhost_virtqueue *vq,
|
struct vhost_virtqueue *vq,
|
||||||
unsigned idx)
|
unsigned idx)
|
||||||
|
@ -1380,7 +1380,7 @@ void vhost_virtqueue_stop(struct vhost_dev *dev,
|
||||||
|
|
||||||
if (virtio_queue_get_desc_addr(vdev, idx) == 0) {
|
if (virtio_queue_get_desc_addr(vdev, idx) == 0) {
|
||||||
/* Don't stop the virtqueue which might have not been started */
|
/* Don't stop the virtqueue which might have not been started */
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = dev->vhost_ops->vhost_get_vring_base(dev, &state);
|
r = dev->vhost_ops->vhost_get_vring_base(dev, &state);
|
||||||
|
@ -1411,6 +1411,7 @@ void vhost_virtqueue_stop(struct vhost_dev *dev,
|
||||||
0, virtio_queue_get_avail_size(vdev, idx));
|
0, virtio_queue_get_avail_size(vdev, idx));
|
||||||
vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx),
|
vhost_memory_unmap(dev, vq->desc, virtio_queue_get_desc_size(vdev, idx),
|
||||||
0, virtio_queue_get_desc_size(vdev, idx));
|
0, virtio_queue_get_desc_size(vdev, idx));
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vhost_virtqueue_set_busyloop_timeout(struct vhost_dev *dev,
|
static int vhost_virtqueue_set_busyloop_timeout(struct vhost_dev *dev,
|
||||||
|
@ -2135,9 +2136,10 @@ fail_features:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Host notifiers must be enabled at this point. */
|
/* Host notifiers must be enabled at this point. */
|
||||||
void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
|
int vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
/* should only be called after backend is connected */
|
/* should only be called after backend is connected */
|
||||||
assert(hdev->vhost_ops);
|
assert(hdev->vhost_ops);
|
||||||
|
@ -2156,7 +2158,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
|
||||||
vhost_dev_set_vring_enable(hdev, false);
|
vhost_dev_set_vring_enable(hdev, false);
|
||||||
}
|
}
|
||||||
for (i = 0; i < hdev->nvqs; ++i) {
|
for (i = 0; i < hdev->nvqs; ++i) {
|
||||||
vhost_virtqueue_stop(hdev,
|
rc |= vhost_virtqueue_stop(hdev,
|
||||||
vdev,
|
vdev,
|
||||||
hdev->vqs + i,
|
hdev->vqs + i,
|
||||||
hdev->vq_index + i);
|
hdev->vq_index + i);
|
||||||
|
@ -2176,6 +2178,7 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
|
||||||
hdev->started = false;
|
hdev->started = false;
|
||||||
vdev->vhost_started = false;
|
vdev->vhost_started = false;
|
||||||
hdev->vdev = NULL;
|
hdev->vdev = NULL;
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vhost_net_set_backend(struct vhost_dev *hdev,
|
int vhost_net_set_backend(struct vhost_dev *hdev,
|
||||||
|
|
|
@ -232,8 +232,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings);
|
||||||
* Stop the vhost device. After the device is stopped the notifiers
|
* Stop the vhost device. After the device is stopped the notifiers
|
||||||
* can be disabled (@vhost_dev_disable_notifiers) and the device can
|
* can be disabled (@vhost_dev_disable_notifiers) and the device can
|
||||||
* be torn down (@vhost_dev_cleanup).
|
* be torn down (@vhost_dev_cleanup).
|
||||||
|
*
|
||||||
|
* Return: 0 on success, != 0 on error when stopping dev.
|
||||||
*/
|
*/
|
||||||
void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings);
|
int vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DOC: vhost device configuration handling
|
* DOC: vhost device configuration handling
|
||||||
|
@ -333,7 +335,7 @@ int vhost_device_iotlb_miss(struct vhost_dev *dev, uint64_t iova, int write);
|
||||||
|
|
||||||
int vhost_virtqueue_start(struct vhost_dev *dev, struct VirtIODevice *vdev,
|
int vhost_virtqueue_start(struct vhost_dev *dev, struct VirtIODevice *vdev,
|
||||||
struct vhost_virtqueue *vq, unsigned idx);
|
struct vhost_virtqueue *vq, unsigned idx);
|
||||||
void vhost_virtqueue_stop(struct vhost_dev *dev, struct VirtIODevice *vdev,
|
int vhost_virtqueue_stop(struct vhost_dev *dev, struct VirtIODevice *vdev,
|
||||||
struct vhost_virtqueue *vq, unsigned idx);
|
struct vhost_virtqueue *vq, unsigned idx);
|
||||||
|
|
||||||
void vhost_dev_reset_inflight(struct vhost_inflight *inflight);
|
void vhost_dev_reset_inflight(struct vhost_inflight *inflight);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue