From 65bedb496ffa1815fece261cd0a2703b4c9fb8f3 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 13 May 2022 10:37:06 +0200 Subject: [PATCH] lib/vhost: add enum to differentiate the vhost backends Each spdk_vhost_dev_backend is local to either SCSI or BLK backends, so its not possible to gauge which backend is used by the vdev on generic vhost layer. Added a `type` field with matching enums to differentiate between the two. Later patches will check that field in vhost.c. Signed-off-by: Tomasz Zawadzki Change-Id: I2a95961b9f9b5f070db7b22d44cf5114a24b1067 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12675 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto --- lib/vhost/vhost_blk.c | 5 +++-- lib/vhost/vhost_internal.h | 7 +++++++ lib/vhost/vhost_scsi.c | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 601e9a93e..03c76c338 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -129,7 +129,7 @@ to_blk_dev(struct spdk_vhost_dev *vdev) return NULL; } - if (vdev->backend != &vhost_blk_device_backend) { + if (vdev->backend->type != VHOST_BACKEND_BLK) { SPDK_ERRLOG("%s: not a vhost-blk device\n", vdev->name); return NULL; } @@ -140,7 +140,7 @@ to_blk_dev(struct spdk_vhost_dev *vdev) static struct spdk_vhost_blk_session * to_blk_session(struct spdk_vhost_session *vsession) { - assert(vsession->vdev->backend == &vhost_blk_device_backend); + assert(vsession->vdev->backend->type == VHOST_BACKEND_BLK); return (struct spdk_vhost_blk_session *)vsession; } @@ -1562,6 +1562,7 @@ static const struct spdk_vhost_user_dev_backend vhost_blk_user_device_backend = }; static const struct spdk_vhost_dev_backend vhost_blk_device_backend = { + .type = VHOST_BACKEND_BLK, .vhost_get_config = vhost_blk_get_config, .dump_info_json = vhost_blk_dump_info_json, .write_config_json = vhost_blk_write_config_json, diff --git a/lib/vhost/vhost_internal.h b/lib/vhost/vhost_internal.h index ef26acdd8..9ffeb9e17 100644 --- a/lib/vhost/vhost_internal.h +++ b/lib/vhost/vhost_internal.h @@ -248,7 +248,14 @@ struct spdk_vhost_user_dev_backend { int (*stop_session)(struct spdk_vhost_session *vsession); }; +enum vhost_backend_type { + VHOST_BACKEND_BLK = 0, + VHOST_BACKEND_SCSI, +}; + struct spdk_vhost_dev_backend { + enum vhost_backend_type type; + int (*vhost_get_config)(struct spdk_vhost_dev *vdev, uint8_t *config, uint32_t len); int (*vhost_set_config)(struct spdk_vhost_dev *vdev, uint8_t *config, uint32_t offset, uint32_t size, uint32_t flags); diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index dd7b0fc0e..a9d656658 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -157,6 +157,7 @@ static const struct spdk_vhost_user_dev_backend spdk_vhost_scsi_user_device_back }; static const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = { + .type = VHOST_BACKEND_SCSI, .dump_info_json = vhost_scsi_dump_info_json, .write_config_json = vhost_scsi_write_config_json, .remove_device = vhost_scsi_dev_remove, @@ -851,7 +852,7 @@ to_scsi_dev(struct spdk_vhost_dev *ctrlr) return NULL; } - if (ctrlr->backend != &spdk_vhost_scsi_device_backend) { + if (ctrlr->backend->type != VHOST_BACKEND_SCSI) { SPDK_ERRLOG("%s: not a vhost-scsi device.\n", ctrlr->name); return NULL; } @@ -862,7 +863,7 @@ to_scsi_dev(struct spdk_vhost_dev *ctrlr) static struct spdk_vhost_scsi_session * to_scsi_session(struct spdk_vhost_session *vsession) { - assert(vsession->vdev->backend == &spdk_vhost_scsi_device_backend); + assert(vsession->vdev->backend->type == VHOST_BACKEND_SCSI); return (struct spdk_vhost_scsi_session *)vsession; }