@samitouri / QOSamiQemu / commits / eef8552c47

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

Commit bc85aae42045 ("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: bc85aae42045 ("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>

Kuan-Wei Chiu committed Mar 15, 2026 at 23:10 UTC eef8552c474f9ed3a82cf37cf2c5b227521a5f4b
7 files changed +30 -25
backends/vhost-user.c
+4 -4
@@ -102,7 +102,7 @@ vhost_user_backend_stop(VhostUserBackend *b)
102 {
103 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(b->vdev)));
104 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
105 - int ret;
105 + int ret, err;
106
107 if (!b->started) {
108 return 0;
@@ -111,9 +111,9 @@ vhost_user_backend_stop(VhostUserBackend *b)
111 ret = vhost_dev_stop(&b->dev, b->vdev, true);
112
113 if (k->set_guest_notifiers &&
114 - k->set_guest_notifiers(qbus->parent, b->dev.nvqs, false) < 0) {
115 - error_report("vhost guest notifier cleanup failed: %d", ret);
116 - return -1;
114 + (err = k->set_guest_notifiers(qbus->parent, b->dev.nvqs, false)) < 0) {
115 + error_report("vhost guest notifier cleanup failed: %d", err);
116 + return err;
117 }
118
119 vhost_dev_disable_notifiers(&b->dev, b->vdev);
hw/block/vhost-user-blk.c
+5 -4
@@ -214,7 +214,7 @@ static int vhost_user_blk_stop(VirtIODevice *vdev)
214 VHostUserBlk *s = VHOST_USER_BLK(vdev);
215 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
216 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
217 - int ret;
217 + int ret, err;
218 bool force_stop = false;
219
220 trace_vhost_user_blk_stop_in(vdev);
@@ -234,9 +234,10 @@ static int vhost_user_blk_stop(VirtIODevice *vdev)
234 ret = force_stop ? vhost_dev_force_stop(&s->dev, vdev, true) :
235 vhost_dev_stop(&s->dev, vdev, true);
236
237 - if (k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false) < 0) {
238 - error_report("vhost guest notifier cleanup failed: %d", ret);
239 - return -1;
237 + err = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
238 + if (err < 0) {
239 + error_report("vhost guest notifier cleanup failed: %d", err);
240 + return err;
241 }
242
243 vhost_dev_disable_notifiers(&s->dev, vdev);
hw/scsi/vhost-scsi-common.c
+1 -1
@@ -113,7 +113,7 @@ int vhost_scsi_common_stop(VHostSCSICommon *vsc)
113 if (k->set_guest_notifiers) {
114 int r = k->set_guest_notifiers(qbus->parent, vsc->dev.nvqs, false);
115 if (r < 0) {
116 - error_report("vhost guest notifier cleanup failed: %d", ret);
116 + error_report("vhost guest notifier cleanup failed: %d", r);
117 return r;
118 }
119 }
hw/virtio/vhost-user-base.c
+5 -4
@@ -71,7 +71,7 @@ static int vub_stop(VirtIODevice *vdev)
71 VHostUserBase *vub = VHOST_USER_BASE(vdev);
72 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
73 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
74 - int ret;
74 + int ret, err;
75
76 if (!k->set_guest_notifiers) {
77 return 0;
@@ -79,9 +79,10 @@ static int vub_stop(VirtIODevice *vdev)
79
80 ret = vhost_dev_stop(&vub->vhost_dev, vdev, true);
81
82 - if (k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false) < 0) {
83 - error_report("vhost guest notifier cleanup failed: %d", ret);
84 - return -1;
82 + err = k->set_guest_notifiers(qbus->parent, vub->vhost_dev.nvqs, false);
83 + if (err < 0) {
84 + error_report("vhost guest notifier cleanup failed: %d", err);
85 + return err;
86 }
87
88 vhost_dev_disable_notifiers(&vub->vhost_dev, vdev);
hw/virtio/vhost-user-fs.c
+5 -4
@@ -105,7 +105,7 @@ static int vuf_stop(VirtIODevice *vdev)
105 VHostUserFS *fs = VHOST_USER_FS(vdev);
106 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
107 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
108 - int ret;
108 + int ret, err;
109
110 if (!k->set_guest_notifiers) {
111 return 0;
@@ -113,9 +113,10 @@ static int vuf_stop(VirtIODevice *vdev)
113
114 ret = vhost_dev_stop(&fs->vhost_dev, vdev, true);
115
116 - if (k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false) < 0) {
117 - error_report("vhost guest notifier cleanup failed: %d", ret);
118 - return -1;
116 + err = k->set_guest_notifiers(qbus->parent, fs->vhost_dev.nvqs, false);
117 + if (err < 0) {
118 + error_report("vhost guest notifier cleanup failed: %d", err);
119 + return err;
120 }
121
122 vhost_dev_disable_notifiers(&fs->vhost_dev, vdev);
hw/virtio/vhost-user-scmi.c
+5 -4
@@ -89,7 +89,7 @@ static int vu_scmi_stop(VirtIODevice *vdev)
89 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
90 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
91 struct vhost_dev *vhost_dev = &scmi->vhost_dev;
92 - int ret;
92 + int ret, err;
93
94 /* vhost_dev_is_started() check in the callers is not fully reliable. */
95 if (!scmi->started_vu) {
@@ -103,9 +103,10 @@ static int vu_scmi_stop(VirtIODevice *vdev)
103
104 ret = vhost_dev_stop(vhost_dev, vdev, true);
105
106 - if (k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false) < 0) {
107 - error_report("vhost guest notifier cleanup failed: %d", ret);
108 - return -1;
106 + err = k->set_guest_notifiers(qbus->parent, vhost_dev->nvqs, false);
107 + if (err < 0) {
108 + error_report("vhost guest notifier cleanup failed: %d", err);
109 + return err;
110 }
111 vhost_dev_disable_notifiers(vhost_dev, vdev);
112 return ret;
hw/virtio/vhost-vsock-common.c
+5 -4
@@ -100,7 +100,7 @@ int vhost_vsock_common_stop(VirtIODevice *vdev)
100 VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
101 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
102 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
103 - int ret;
103 + int ret, err;
104
105 if (!k->set_guest_notifiers) {
106 return 0;
@@ -108,9 +108,10 @@ int vhost_vsock_common_stop(VirtIODevice *vdev)
108
109 ret = vhost_dev_stop(&vvc->vhost_dev, vdev, true);
110
111 - if (k->set_guest_notifiers(qbus->parent, vvc->vhost_dev.nvqs, false) < 0) {
112 - error_report("vhost guest notifier cleanup failed: %d", ret);
113 - return -1;
111 + err = k->set_guest_notifiers(qbus->parent, vvc->vhost_dev.nvqs, false);
112 + if (err < 0) {
113 + error_report("vhost guest notifier cleanup failed: %d", err);
114 + return err;
115 }
116
117 vhost_dev_disable_notifiers(&vvc->vhost_dev, vdev);