From 34c7b6c18cd2449eef860fadbd5456cf62cc1626 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Mon, 25 Apr 2022 15:01:41 +0200 Subject: [PATCH] lib/vhost: expose spdk_bdev to virtio_blk transports There are configuration details that are needed to configure the virtio device based on spdk_bdev properties. Please see vhost_blk_get_config() for an example of vhost_user retrieving properties of bdev such as size or supported I/O type. Rather than trying to anticipate every such property, add vhost_blk_get_bdev() to allow usage of bdev API directly. Signed-off-by: Tomasz Zawadzki Change-Id: I757f96e2fb0861c97b07ce279a7c04c77a2ad11f Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12373 Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins --- lib/vhost/vhost_blk.c | 17 ++++++++++++----- lib/vhost/vhost_internal.h | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 03c76c338..88d5f73cf 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -137,6 +137,16 @@ to_blk_dev(struct spdk_vhost_dev *vdev) return SPDK_CONTAINEROF(vdev, struct spdk_vhost_blk_dev, vdev); } +struct spdk_bdev * +vhost_blk_get_bdev(struct spdk_vhost_dev *vdev) +{ + struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev); + + assert(bvdev != NULL); + + return bvdev->bdev; +} + static struct spdk_vhost_blk_session * to_blk_session(struct spdk_vhost_session *vsession) { @@ -460,7 +470,7 @@ blk_request_queue_io(struct spdk_vhost_dev *vdev, struct spdk_io_channel *ch, struct spdk_vhost_blk_task *task) { int rc; - struct spdk_bdev *bdev = task->bdev_io->bdev; + struct spdk_bdev *bdev = vhost_blk_get_bdev(vdev); task->bdev_io_wait.bdev = bdev; task->bdev_io_wait.cb_fn = blk_request_resubmit; @@ -1495,15 +1505,12 @@ vhost_blk_get_config(struct spdk_vhost_dev *vdev, uint8_t *config, uint32_t len) { struct virtio_blk_config blkcfg; - struct spdk_vhost_blk_dev *bvdev; struct spdk_bdev *bdev; uint32_t blk_size; uint64_t blkcnt; memset(&blkcfg, 0, sizeof(blkcfg)); - bvdev = to_blk_dev(vdev); - assert(bvdev != NULL); - bdev = bvdev->bdev; + bdev = vhost_blk_get_bdev(vdev); if (bdev == NULL) { /* We can't just return -1 here as this GET_CONFIG message might * be caused by a QEMU VM reboot. Returning -1 will indicate an diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index d38c853a3..b26304b61 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -521,6 +521,10 @@ int remove_vhost_controller(struct spdk_vhost_dev *vdev); struct spdk_io_channel *vhost_blk_get_io_channel(struct spdk_vhost_dev *vdev); void vhost_blk_put_io_channel(struct spdk_io_channel *ch); +/* The spdk_bdev pointer should only be used to retrieve + * the device properties, ex. number of blocks or I/O type supported. */ +struct spdk_bdev *vhost_blk_get_bdev(struct spdk_vhost_dev *vdev); + /* Function calls from vhost.c to rte_vhost_user.c, * shall removed once virtio transport abstraction is complete. */ int vhost_user_session_set_coalescing(struct spdk_vhost_dev *dev,