Skip to content

Commit

Permalink
vhost-user: fix the reconnect error
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Li Feng <fengli@smartx.com>
Message-Id: <20231123055431.217792-2-fengli@smartx.com>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
Li Feng authored and mstsirkin committed Dec 2, 2023
1 parent 2d37fe9 commit 298d4f8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 3 additions & 5 deletions hw/block/vhost-user-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion hw/scsi/vhost-user-scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion hw/virtio/vhost-user-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 298d4f8

Please sign in to comment.