mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 02:54:58 -06:00
vhost-user: return failure if backend crash when live migration
Live migration should be terminated if the vhost-user backend crashes before the migration completes. Specifically, since the vhost device will be stopped when VM is stopped before the end of the live migration, in current implementation if the backend crashes, vhost-user device set_status() won't return failure, live migration won't perceive the disconnection between QEMU and the backend. When the VM is migrated to the destination, the inflight IO will be resubmitted, and if the IO was completed out of order before, it will cause IO error. To fix this issue: 1. Add the return value to set_status() for VirtioDeviceClass. a. For the vhost-user device, return failure when the backend crashes. b. For other virtio devices, always return 0. 2. Return failure if vhost_dev_stop() failed for vhost-user device. If QEMU loses connection with the vhost-user backend, virtio set_status() can return failure to the upper layer, migration_completion() can handle the error, terminate the live migration, and restore the VM, so that inflight IO can be completed normally. Signed-off-by: Haoqian He <haoqian.he@smartx.com> Message-Id: <20250416024729.3289157-4-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
5a317017b8
commit
bc85aae420
26 changed files with 160 additions and 109 deletions
|
@ -204,7 +204,7 @@ err_host_notifiers:
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void vhost_user_blk_stop(VirtIODevice *vdev)
|
||||
static int vhost_user_blk_stop(VirtIODevice *vdev)
|
||||
{
|
||||
VHostUserBlk *s = VHOST_USER_BLK(vdev);
|
||||
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
|
||||
|
@ -212,26 +212,26 @@ static void vhost_user_blk_stop(VirtIODevice *vdev)
|
|||
int ret;
|
||||
|
||||
if (!s->started_vu) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
s->started_vu = false;
|
||||
|
||||
if (!k->set_guest_notifiers) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
vhost_dev_stop(&s->dev, vdev, true);
|
||||
ret = vhost_dev_stop(&s->dev, vdev, true);
|
||||
|
||||
ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
|
||||
if (ret < 0) {
|
||||
if (k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false) < 0) {
|
||||
error_report("vhost guest notifier cleanup failed: %d", ret);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
vhost_dev_disable_notifiers(&s->dev, vdev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void vhost_user_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
||||
static int vhost_user_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
||||
{
|
||||
VHostUserBlk *s = VHOST_USER_BLK(vdev);
|
||||
bool should_start = virtio_device_should_start(vdev, status);
|
||||
|
@ -239,11 +239,11 @@ static void vhost_user_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
|||
int ret;
|
||||
|
||||
if (!s->connected) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vhost_dev_is_started(&s->dev) == should_start) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (should_start) {
|
||||
|
@ -253,9 +253,12 @@ static void vhost_user_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
|||
qemu_chr_fe_disconnect(&s->chardev);
|
||||
}
|
||||
} else {
|
||||
vhost_user_blk_stop(vdev);
|
||||
ret = vhost_user_blk_stop(vdev);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
|
||||
|
|
|
@ -1270,7 +1270,7 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features,
|
|||
return features;
|
||||
}
|
||||
|
||||
static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
||||
static int virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
||||
{
|
||||
VirtIOBlock *s = VIRTIO_BLK(vdev);
|
||||
|
||||
|
@ -1279,7 +1279,7 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
|||
}
|
||||
|
||||
if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A guest that supports VIRTIO_BLK_F_CONFIG_WCE must be able to send
|
||||
|
@ -1302,6 +1302,7 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
|
|||
virtio_vdev_has_feature(vdev,
|
||||
VIRTIO_BLK_F_WCE));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue