vhost-user: Fix stale error logs and return values in teardown paths

Commit bc85aae420 ("vhost-user: return failure if backend crash when
live migration") refactored the set_guest_notifiers error handling but
introduced two regressions across multiple vhost devices.

By moving the function call directly into the if condition, the
subsequent error_report prints the stale ret variable instead of the
actual error code. Additionally, the refactoring hardcoded a return
value of -1 rather than propagating the true error status to the
caller.

Fix these issues by storing the set_guest_notifiers result in a local
err variable.

Fixes: bc85aae420 ("vhost-user: return failure if backend crash when live migration")
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20260315231047.310029-1-visitorckw@gmail.com>
This commit is contained in:
Kuan-Wei Chiu
2026-03-15 23:10:47 +00:00
committed by Michael S. Tsirkin
parent c7209c5671
commit eef8552c47
7 changed files with 30 additions and 25 deletions

View File

@@ -102,7 +102,7 @@ vhost_user_backend_stop(VhostUserBackend *b)
{
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(b->vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int ret;
int ret, err;
if (!b->started) {
return 0;
@@ -111,9 +111,9 @@ vhost_user_backend_stop(VhostUserBackend *b)
ret = vhost_dev_stop(&b->dev, b->vdev, true);
if (k->set_guest_notifiers &&
k->set_guest_notifiers(qbus->parent, b->dev.nvqs, false) < 0) {
error_report("vhost guest notifier cleanup failed: %d", ret);
return -1;
(err = k->set_guest_notifiers(qbus->parent, b->dev.nvqs, false)) < 0) {
error_report("vhost guest notifier cleanup failed: %d", err);
return err;
}
vhost_dev_disable_notifiers(&b->dev, b->vdev);

View File

@@ -214,7 +214,7 @@ static int vhost_user_blk_stop(VirtIODevice *vdev)
VHostUserBlk *s = VHOST_USER_BLK(vdev);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int ret;
int ret, err;
bool force_stop = false;
trace_vhost_user_blk_stop_in(vdev);
@@ -234,9 +234,10 @@ static int vhost_user_blk_stop(VirtIODevice *vdev)
ret = force_stop ? vhost_dev_force_stop(&s->dev, vdev, true) :
vhost_dev_stop(&s->dev, vdev, true);
if (k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false) < 0) {
error_report("vhost guest notifier cleanup failed: %d", ret);
return -1;
err = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
if (err < 0) {
error_report("vhost guest notifier cleanup failed: %d", err);
return err;
}
vhost_dev_disable_notifiers(&s->dev, vdev);

View File

@@ -113,7 +113,7 @@ int vhost_scsi_common_stop(VHostSCSICommon *vsc)
if (k->set_guest_notifiers) {
int r = k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false);
if (r < 0) {
error_report("vhost guest notifier cleanup failed: %d", ret);
error_report("vhost guest notifier cleanup failed: %d", r);
return r;
}
}

View File

@@ -71,7 +71,7 @@ static int vub_stop(VirtIODevice *vdev)
VHostUserBase *vub = VHOST_USER_BASE(vdev);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int ret;
int ret, err;
if (!k->set_guest_notifiers) {
return 0;
@@ -79,9 +79,10 @@ static int vub_stop(VirtIODevice *vdev)
ret = vhost_dev_stop(&vub->vhost_dev, vdev, true);
if (k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false) < 0) {
error_report("vhost guest notifier cleanup failed: %d", ret);
return -1;
err = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false);
if (err < 0) {
error_report("vhost guest notifier cleanup failed: %d", err);
return err;
}
vhost_dev_disable_notifiers(&vub->vhost_dev, vdev);

View File

@@ -105,7 +105,7 @@ static int vuf_stop(VirtIODevice *vdev)
VHostUserFS *fs = VHOST_USER_FS(vdev);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int ret;
int ret, err;
if (!k->set_guest_notifiers) {
return 0;
@@ -113,9 +113,10 @@ static int vuf_stop(VirtIODevice *vdev)
ret = vhost_dev_stop(&fs->vhost_dev, vdev, true);
if (k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false) < 0) {
error_report("vhost guest notifier cleanup failed: %d", ret);
return -1;
err = k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false);
if (err < 0) {
error_report("vhost guest notifier cleanup failed: %d", err);
return err;
}
vhost_dev_disable_notifiers(&fs->vhost_dev, vdev);

View File

@@ -89,7 +89,7 @@ static int vu_scmi_stop(VirtIODevice *vdev)
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
struct vhost_dev *vhost_dev = &scmi->vhost_dev;
int ret;
int ret, err;
/* vhost_dev_is_started() check in the callers is not fully reliable. */
if (!scmi->started_vu) {
@@ -103,9 +103,10 @@ static int vu_scmi_stop(VirtIODevice *vdev)
ret = vhost_dev_stop(vhost_dev, vdev, true);
if (k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false) < 0) {
error_report("vhost guest notifier cleanup failed: %d", ret);
return -1;
err = k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false);
if (err < 0) {
error_report("vhost guest notifier cleanup failed: %d", err);
return err;
}
vhost_dev_disable_notifiers(vhost_dev, vdev);
return ret;

View File

@@ -100,7 +100,7 @@ int vhost_vsock_common_stop(VirtIODevice *vdev)
VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int ret;
int ret, err;
if (!k->set_guest_notifiers) {
return 0;
@@ -108,9 +108,10 @@ int vhost_vsock_common_stop(VirtIODevice *vdev)
ret = vhost_dev_stop(&vvc->vhost_dev, vdev, true);
if (k->set_guest_notifiers(qbus->parent, vvc->vhost_dev.nvqs, false) < 0) {
error_report("vhost guest notifier cleanup failed: %d", ret);
return -1;
err = k->set_guest_notifiers(qbus->parent, vvc->vhost_dev.nvqs, false);
if (err < 0) {
error_report("vhost guest notifier cleanup failed: %d", err);
return err;
}
vhost_dev_disable_notifiers(&vvc->vhost_dev, vdev);