[PATCH v2 10/25] vhost-user-blk: split vhost_user_blk_init()

Vladimir Sementsov-Ogievskiy posted 25 patches 4 weeks, 1 day ago
[PATCH v2 10/25] vhost-user-blk: split vhost_user_blk_init()
Posted by Vladimir Sementsov-Ogievskiy 4 weeks, 1 day ago
Split it into _init() and _connect() part, following pattern of
vhost_dev_init / vhost_dev_connect.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 hw/block/vhost-user-blk.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index c31c265a0e..9c727c3977 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -58,6 +58,7 @@ static const int user_feature_bits[] = {
 };
 
 static void vhost_user_blk_event(void *opaque, QEMUChrEvent event);
+static int vhost_user_blk_connect(DeviceState *dev, Error **errp);
 
 static void vhost_user_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
@@ -352,9 +353,6 @@ static int vhost_user_blk_init(DeviceState *dev, bool connect, Error **errp)
 
     trace_vhost_user_blk_init_in(vdev);
 
-    /* TODO: implement support for connect=false */
-    assert(connect);
-
     assert(!s->connected);
 
     s->dev.num_queues = s->num_queues;
@@ -371,6 +369,29 @@ static int vhost_user_blk_init(DeviceState *dev, bool connect, Error **errp)
         return ret;
     }
 
+    if (connect) {
+        ret = vhost_user_blk_connect(dev, errp);
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
+    trace_vhost_user_blk_init_out(vdev);
+
+    return 0;
+}
+
+static int vhost_user_blk_connect(DeviceState *dev,
+                                  Error **errp)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+    VHostUserBlk *s = VHOST_USER_BLK(vdev);
+    int ret = 0;
+
+    trace_vhost_user_blk_connect_in(vdev);
+
+    assert(!s->connected);
+
     ret = vhost_dev_connect(&s->dev, errp);
     if (ret < 0) {
         return ret;
-- 
2.48.1
Re: [PATCH v2 10/25] vhost-user-blk: split vhost_user_blk_init()
Posted by Raphael Norwitz 3 weeks, 3 days ago
Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>


On Thu, Oct 16, 2025 at 7:46 AM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> Split it into _init() and _connect() part, following pattern of
> vhost_dev_init / vhost_dev_connect.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
>  hw/block/vhost-user-blk.c | 27 ++++++++++++++++++++++++---
>  1 file changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index c31c265a0e..9c727c3977 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -58,6 +58,7 @@ static const int user_feature_bits[] = {
>  };
>
>  static void vhost_user_blk_event(void *opaque, QEMUChrEvent event);
> +static int vhost_user_blk_connect(DeviceState *dev, Error **errp);
>
>  static void vhost_user_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>  {
> @@ -352,9 +353,6 @@ static int vhost_user_blk_init(DeviceState *dev, bool connect, Error **errp)
>
>      trace_vhost_user_blk_init_in(vdev);
>
> -    /* TODO: implement support for connect=false */
> -    assert(connect);
> -
>      assert(!s->connected);
>
>      s->dev.num_queues = s->num_queues;
> @@ -371,6 +369,29 @@ static int vhost_user_blk_init(DeviceState *dev, bool connect, Error **errp)
>          return ret;
>      }
>
> +    if (connect) {
> +        ret = vhost_user_blk_connect(dev, errp);
> +        if (ret < 0) {
> +            return ret;
> +        }
> +    }
> +
> +    trace_vhost_user_blk_init_out(vdev);
> +
> +    return 0;
> +}
> +
> +static int vhost_user_blk_connect(DeviceState *dev,
> +                                  Error **errp)
> +{
> +    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> +    VHostUserBlk *s = VHOST_USER_BLK(vdev);
> +    int ret = 0;
> +
> +    trace_vhost_user_blk_connect_in(vdev);
> +
> +    assert(!s->connected);
> +
>      ret = vhost_dev_connect(&s->dev, errp);
>      if (ret < 0) {
>          return ret;
> --
> 2.48.1
>
>