Reviewed-by: Raphael Norwitz <raphael.s.norwitz@gmail.com>
On Thu, Oct 16, 2025 at 7:47 AM Vladimir Sementsov-Ogievskiy
<vsementsov@yandex-team.ru> wrote:
>
> vhost_user_blk_connect() has two callers:
>
> - vhost_user_blk_realize_connect(), which directly set .connected = false
> before call
>
> - vhost_user_blk_event(), where we want this check
>
> Move the check to the only caller which needs it, to simplify further
> refactoring.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> ---
> hw/block/vhost-user-blk.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index a92426f18c..57214a69cd 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -352,9 +352,7 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)
>
> trace_vhost_user_blk_connect_in(vdev);
>
> - if (s->connected) {
> - return 0;
> - }
> + assert(!s->connected);
>
> s->dev.num_queues = s->num_queues;
> s->dev.nvqs = s->num_queues;
> @@ -411,10 +409,12 @@ static void vhost_user_blk_event(void *opaque, QEMUChrEvent event)
>
> switch (event) {
> case CHR_EVENT_OPENED:
> - if (vhost_user_blk_connect(dev, &local_err) < 0) {
> - error_report_err(local_err);
> - qemu_chr_fe_disconnect(&s->chardev);
> - return;
> + if (!s->connected) {
> + if (vhost_user_blk_connect(dev, &local_err) < 0) {
> + error_report_err(local_err);
> + qemu_chr_fe_disconnect(&s->chardev);
> + return;
> + }
> }
> break;
> case CHR_EVENT_CLOSED:
> --
> 2.48.1
>
>