[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 23/24] vhost-user-blk: Factor out vhost_user_blk_realize_connect()
From: |
Kevin Wolf |
Subject: |
[PULL 23/24] vhost-user-blk: Factor out vhost_user_blk_realize_connect() |
Date: |
Wed, 30 Jun 2021 18:02:05 +0200 |
This function is the part that we will want to retry if the connection
is lost during initialisation, so factor it out to keep the following
patch simpler.
The error path for vhost_dev_get_config() forgot disconnecting the
chardev, add this while touching the code.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20210609154658.350308-7-kwolf@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/block/vhost-user-blk.c | 48 ++++++++++++++++++++++++++-------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 3770f715da..e49d2e4c83 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -423,6 +423,36 @@ static void vhost_user_blk_event(void *opaque,
QEMUChrEvent event)
}
}
+static int vhost_user_blk_realize_connect(VHostUserBlk *s, Error **errp)
+{
+ DeviceState *dev = &s->parent_obj.parent_obj;
+ int ret;
+
+ s->connected = false;
+
+ ret = qemu_chr_fe_wait_connected(&s->chardev, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
+ ret = vhost_user_blk_connect(dev, errp);
+ if (ret < 0) {
+ qemu_chr_fe_disconnect(&s->chardev);
+ return ret;
+ }
+ assert(s->connected);
+
+ ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg,
+ sizeof(struct virtio_blk_config), errp);
+ if (ret < 0) {
+ qemu_chr_fe_disconnect(&s->chardev);
+ vhost_dev_cleanup(&s->dev);
+ return ret;
+ }
+
+ return 0;
+}
+
static void vhost_user_blk_device_realize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
@@ -467,22 +497,10 @@ static void vhost_user_blk_device_realize(DeviceState
*dev, Error **errp)
s->inflight = g_new0(struct vhost_inflight, 1);
s->vhost_vqs = g_new0(struct vhost_virtqueue, s->num_queues);
- s->connected = false;
-
- if (qemu_chr_fe_wait_connected(&s->chardev, errp) < 0) {
- goto virtio_err;
- }
- if (vhost_user_blk_connect(dev, errp) < 0) {
- qemu_chr_fe_disconnect(&s->chardev);
- goto virtio_err;
- }
- assert(s->connected);
-
- ret = vhost_dev_get_config(&s->dev, (uint8_t *)&s->blkcfg,
- sizeof(struct virtio_blk_config), errp);
+ ret = vhost_user_blk_realize_connect(s, errp);
if (ret < 0) {
- goto vhost_err;
+ goto virtio_err;
}
/* we're fully initialized, now we can operate, so add the handler */
@@ -491,8 +509,6 @@ static void vhost_user_blk_device_realize(DeviceState *dev,
Error **errp)
NULL, true);
return;
-vhost_err:
- vhost_dev_cleanup(&s->dev);
virtio_err:
g_free(s->vhost_vqs);
s->vhost_vqs = NULL;
--
2.31.1
- [PULL 09/24] block: bdrv_reopen_parse_backing(): don't check frozen child, (continued)
- [PULL 09/24] block: bdrv_reopen_parse_backing(): don't check frozen child, Kevin Wolf, 2021/06/30
- [PULL 10/24] block: bdrv_reopen_parse_backing(): simplify handling implicit filters, Kevin Wolf, 2021/06/30
- [PULL 11/24] block: move supports_backing check to bdrv_set_file_or_backing_noperm(), Kevin Wolf, 2021/06/30
- [PULL 13/24] block: Allow changing bs->file on reopen, Kevin Wolf, 2021/06/30
- [PULL 04/24] block: rename bdrv_replace_child to bdrv_replace_child_tran, Kevin Wolf, 2021/06/30
- [PULL 17/24] block/ssh: add support for sha256 host key fingerprints, Kevin Wolf, 2021/06/30
- [PULL 15/24] introduce QEMU_AUTO_VFREE, Kevin Wolf, 2021/06/30
- [PULL 18/24] vhost: Add Error parameter to vhost_dev_init(), Kevin Wolf, 2021/06/30
- [PULL 16/24] block/commit: use QEMU_AUTO_VFREE, Kevin Wolf, 2021/06/30
- [PULL 22/24] vhost: Distinguish errors in vhost_dev_get_config(), Kevin Wolf, 2021/06/30
- [PULL 23/24] vhost-user-blk: Factor out vhost_user_blk_realize_connect(),
Kevin Wolf <=
- [PULL 14/24] iotests: Test replacing files with x-blockdev-reopen, Kevin Wolf, 2021/06/30
- [PULL 20/24] vhost: Return 0/-errno in vhost_dev_init(), Kevin Wolf, 2021/06/30
- [PULL 24/24] vhost-user-blk: Implement reconnection during realize, Kevin Wolf, 2021/06/30
- [PULL 21/24] vhost-user-blk: Add Error parameter to vhost_user_blk_start(), Kevin Wolf, 2021/06/30
- [PULL 05/24] block: comment graph-modifying function not updating permissions, Kevin Wolf, 2021/06/30
- [PULL 19/24] vhost: Distinguish errors in vhost_backend_init(), Kevin Wolf, 2021/06/30