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 <tomasz.zawadzki@intel.com>
Change-Id: I757f96e2fb0861c97b07ce279a7c04c77a2ad11f

Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12373
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Tomasz Zawadzki 2022-04-25 15:01:41 +02:00
parent 91426dc600
commit 34c7b6c18c
2 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -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,