fix some vhost-user issues
cover fix some vhost-user issues
Li Feng (2):
vhost-user: fix the reconnect error
vhost-user-scsi: free the inflight area when reset
hw/block/vhost-user-blk.c | 8 +++----- hw/scsi/vhost-user-scsi.c | 19 ++++++++++++++++++- hw/virtio/vhost-user-gpio.c | 3 ++- hw/virtio/virtio.c | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/2 vhost-user: fix the reconnect error
If the error occurs in vhost_dev_init, the value of s->connected is set to true in advance, and there is no chance to enter this function execution again in the future.
--- hw/block/vhost-user-blk.c | 8 +++----- hw/scsi/vhost-user-scsi.c | 3 ++- hw/virtio/vhost-user-gpio.c | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-)
hw/block/vhost-user-blk.c +3 -5
@@ -326,7 +326,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)if (s->connected) {return 0 ; } - s->connected = true; s->dev.num_queues = s->num_queues; s->dev.nvqs = s->num_queues;
@@ -343,15 +342,14 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)return ret; } + s->connected = true; +/* restore vhost state */ if (virtio_device_started (vdev, vdev->status)) { ret =vhost_user_blk_start (vdev, errp); -if (ret <0 ) { -return ret; - } } -return 0 ; +return ret; }static void vhost_user_blk_disconnect (DeviceState *dev)
hw/scsi/vhost-user-scsi.c +2 -1
@@ -147,7 +147,6 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)if (s->connected) {return 0 ; } - s->connected = true; vsc->dev.num_queues = vs->conf.num_queues; vsc->dev.nvqs =VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues;
@@ -161,6 +160,8 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)return ret; } + s->connected = true; +/* restore vhost state */ if (virtio_device_started (vdev, vdev->status)) { ret =vhost_user_scsi_start (s, errp);
hw/virtio/vhost-user-gpio.c +2 -1
@@ -229,7 +229,6 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp)if (gpio->connected) {return 0 ; } - gpio->connected = true;vhost_dev_set_config_notifier (vhost_dev, &gpio_ops); gpio->vhost_user.supports_config = true;
@@ -243,6 +242,8 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp)return ret; } + gpio->connected = true; +/* restore vhost state */ if (virtio_device_started (vdev, vdev->status)) {vu_gpio_start (vdev);
Signature · 1 line
2.42.0
Re: [PATCH 1/2] vhost-user: fix the reconnect error
Quoted 8 lines · Li Feng
If the error occurs in
vhost_dev_init, the value ofs->connectedis set to true in advance, and there is no chance to enter this function execution again in the future.Signed-off-by Li Feng <[email protected]>
Quoted 82 lines
---
hw/block/vhost-user-blk.c | 8 +++----- hw/scsi/vhost-user-scsi.c | 3 ++- hw/virtio/vhost-user-gpio.c | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-)hw/block/vhost-user-blk.c +3
-5@@ -326,7 +326,6 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)if (s->connected) {return 0 ; } - s->connected = true; s->dev.num_queues = s->num_queues; s->dev.nvqs = s->num_queues;@@ -343,15 +342,14 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)return ret; } + s->connected = true; +/* restore vhost state */ if (virtio_device_started (vdev, vdev->status)) { ret =vhost_user_blk_start (vdev, errp); -if (ret <0 ) { -return ret; - } } -return 0 ; +return ret; }static void vhost_user_blk_disconnect (DeviceState *dev)hw/scsi/vhost-user-scsi.c +2
-1@@ -147,7 +147,6 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)if (s->connected) {return 0 ; } - s->connected = true; vsc->dev.num_queues = vs->conf.num_queues; vsc->dev.nvqs =VIRTIO_SCSI_VQ_NUM_FIXED + vs->conf.num_queues;@@ -161,6 +160,8 @@ static int vhost_user_scsi_connect(DeviceState *dev, Error **errp)return ret; } + s->connected = true; +/* restore vhost state */ if (virtio_device_started (vdev, vdev->status)) { ret =vhost_user_scsi_start (s, errp);hw/virtio/vhost-user-gpio.c +2
-1@@ -229,7 +229,6 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp)if (gpio->connected) {return 0 ; } - gpio->connected = true;vhost_dev_set_config_notifier (vhost_dev, &gpio_ops); gpio->vhost_user.supports_config = true;@@ -243,6 +242,8 @@ static int vu_gpio_connect(DeviceState *dev, Error **errp)return ret; } + gpio->connected = true; +/* restore vhost state */ if (virtio_device_started (vdev, vdev->status)) {vu_gpio_start (vdev);Signature · 1 line
2.42.0
PATCH 2/2 vhost-user-scsi: free the inflight area when reset
In reply to Li FengKeep it the same to vhost-user-blk.
At the same time, fix the vhost_reset_device.
--- hw/scsi/vhost-user-scsi.c | 16 ++++++++++++++++ hw/virtio/virtio.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-)
hw/scsi/vhost-user-scsi.c +16 -0
@@ -360,6 +360,20 @@ static Property vhost_user_scsi_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void vhost_user_scsi_reset (VirtIODevice *vdev) +{ +VHostUserSCSI *s =VHOST_USER_SCSI (vdev); +VHostSCSICommon *vsc =VHOST_SCSI_COMMON (s); + +vhost_dev_free_inflight (vsc->inflight); +} + +static struct vhost_dev *vhost_user_scsi_get_vhost (VirtIODevice *vdev) +{ +VHostSCSICommon *vsc =VHOST_SCSI_COMMON (vdev); +return &vsc->dev; +} +static const VMStateDescription vmstate_vhost_scsi = { .name ="virtio-scsi" , .minimum_version_id =1 ,
@@ -385,6 +399,8 @@ static void vhost_user_scsi_class_init(ObjectClass *klass, void *data) vdc->set_config = vhost_scsi_common_set_config; vdc->set_status = vhost_user_scsi_set_status; fwc->get_dev_path = vhost_scsi_common_get_fw_dev_path; + vdc->reset = vhost_user_scsi_reset; + vdc->get_vhost = vhost_user_scsi_get_vhost; }static void vhost_user_scsi_instance_init (Object *obj)
hw/virtio/virtio.c +1 -1
@@ -2137,7 +2137,7 @@ void virtio_reset(void *opaque) vdev->device_endian =virtio_default_endian (); } -if (vdev->vhost_started) { +if (vdev->vhost_started && k->get_vhost) {vhost_reset_device (k->get_vhost (vdev)); }
Signature · 1 line
2.42.0
Re: [PATCH 2/2] vhost-user-scsi: free the inflight area when reset
Quoted 8 lines · Li Feng
Keep it the same to vhost-user-blk.
At the same time, fix thevhost_reset_device.Signed-off-by Li Feng <[email protected]>
Quoted 55 lines
---
hw/scsi/vhost-user-scsi.c| 16 ++++++++++++++++hw/virtio/virtio.c| 2 +-2 files changed, 17 insertions(+), 1 deletion(-)hw/scsi/vhost-user-scsi.c +16
-0@@ -360,6 +360,20 @@ static Property vhost_user_scsi_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +static void vhost_user_scsi_reset (VirtIODevice *vdev) +{ +VHostUserSCSI *s =VHOST_USER_SCSI (vdev); +VHostSCSICommon *vsc =VHOST_SCSI_COMMON (s); + +vhost_dev_free_inflight (vsc->inflight); +} + +static struct vhost_dev *vhost_user_scsi_get_vhost (VirtIODevice *vdev) +{ +VHostSCSICommon *vsc =VHOST_SCSI_COMMON (vdev); +return &vsc->dev; +} +static const VMStateDescription vmstate_vhost_scsi = { .name ="virtio-scsi" , .minimum_version_id =1 ,@@ -385,6 +399,8 @@ static void vhost_user_scsi_class_init(ObjectClass *klass, void *data) vdc->set_config = vhost_scsi_common_set_config; vdc->set_status = vhost_user_scsi_set_status; fwc->get_dev_path = vhost_scsi_common_get_fw_dev_path; + vdc->reset = vhost_user_scsi_reset; + vdc->get_vhost = vhost_user_scsi_get_vhost; }static void vhost_user_scsi_instance_init (Object *obj)hw/virtio/virtio.c +1
-1@@ -2137,7 +2137,7 @@ void virtio_reset(void *opaque) vdev->device_endian =virtio_default_endian (); } -if (vdev->vhost_started) { +if (vdev->vhost_started && k->get_vhost) {vhost_reset_device (k->get_vhost (vdev)); }Signature · 1 line
2.42.0