Cleanup vhost device and update connection state when initialization fails.

Signed-off-by: Konstantin Khlebnikov <khlebni...@yandex-team.ru>
---
 hw/block/vhost-user-blk.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 1a42ae9187..35ac188ca4 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -340,18 +340,24 @@ static int vhost_user_blk_connect(DeviceState *dev, Error 
**errp)
     ret = vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0,
                          errp);
     if (ret < 0) {
-        return ret;
+        goto err_init;
     }
 
     /* restore vhost state */
     if (virtio_device_started(vdev, vdev->status)) {
         ret = vhost_user_blk_start(vdev, errp);
         if (ret < 0) {
-            return ret;
+            goto err_start;
         }
     }
 
     return 0;
+
+err_start:
+    vhost_dev_cleanup(&s->dev);
+err_init:
+    s->connected = false;
+    return ret;
 }
 
 static void vhost_user_blk_disconnect(DeviceState *dev)


Reply via email to