vhost-user: Fix stale error logs and return values in teardown paths
PATCH 1/1 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 <[email protected]>
--- backends/vhost-user.c | 8 ++++---- hw/block/vhost-user-blk.c | 9 +++++---- hw/scsi/vhost-scsi-common.c | 2 +- hw/virtio/vhost-user-base.c | 9 +++++---- hw/virtio/vhost-user-fs.c | 9 +++++---- hw/virtio/vhost-user-scmi.c | 9 +++++---- hw/virtio/vhost-vsock-common.c | 9 +++++---- 7 files changed, 30 insertions(+), 25 deletions(-)
backends/vhost-user.c +4 -4
@@ -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);
hw/block/vhost-user-blk.c +5 -4
@@ -209,7 +209,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;if (!s->started_vu) {
@@ -227,9 +227,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);
hw/scsi/vhost-scsi-common.c +1 -1
@@ -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; } }
hw/virtio/vhost-user-base.c +5 -4
@@ -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);
hw/virtio/vhost-user-fs.c +5 -4
@@ -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);
hw/virtio/vhost-user-scmi.c +5 -4
@@ -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;
hw/virtio/vhost-vsock-common.c +5 -4
@@ -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);
Signature · 1 line
2.53.0.851.ga537e3e6e9-goog