diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 2114248974..d794e49dd7 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -1250,13 +1250,6 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_ int ret = 0; spdk_vhost_lock(); - bdev = spdk_bdev_get_by_name(dev_name); - if (bdev == NULL) { - SPDK_ERRLOG("%s: bdev '%s' not found\n", - name, dev_name); - ret = -ENODEV; - goto out; - } bvdev = calloc(1, sizeof(*bvdev)); if (bvdev == NULL) { @@ -1264,6 +1257,14 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_ goto out; } + ret = spdk_bdev_open_ext(dev_name, true, bdev_event_cb, bvdev, &bvdev->bdev_desc); + if (ret != 0) { + SPDK_ERRLOG("%s: could not open bdev '%s', error=%d\n", + name, dev_name, ret); + goto out; + } + bdev = spdk_bdev_desc_get_bdev(bvdev->bdev_desc); + vdev = &bvdev->vdev; vdev->virtio_features = SPDK_VHOST_BLK_FEATURES_BASE; vdev->disabled_features = SPDK_VHOST_BLK_DISABLED_FEATURES; @@ -1284,13 +1285,6 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_ vdev->virtio_features |= (1ULL << VIRTIO_BLK_F_FLUSH); } - ret = spdk_bdev_open_ext(dev_name, true, bdev_event_cb, bvdev, &bvdev->bdev_desc); - if (ret != 0) { - SPDK_ERRLOG("%s: could not open bdev '%s', error=%d\n", - name, dev_name, ret); - goto out; - } - /* * When starting qemu with vhost-user-blk multiqueue, the vhost device will * be started/stopped many times, related to the queues num, as the