lib/vhost: separate out vhost_user backend callbacks
Previously spdk_vhost_dev_backend held callbacks for vhost_blk and vhost_scsi functionality, along with ones that are called by the vhost_user backend. This patch separates out those callbacks into two structures: - spdk_vhost_dev_backend - to be implemented by vhost_blk and vhost_scsi - spdk_vhost_user_dev_backend - is only implemented by vhost_user backend, callbacks for session managment specific to that transport Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: I348090df5dddeb2b1945b082b85aec53d03c781b Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11812 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
c010a71f27
commit
f9fccbae63
@ -833,7 +833,7 @@ _stop_session(struct spdk_vhost_session *vsession)
|
||||
int rc;
|
||||
uint16_t i;
|
||||
|
||||
rc = vdev->backend->stop_session(vsession);
|
||||
rc = vdev->user_backend->stop_session(vsession);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("Couldn't stop device with vid %d.\n", vsession->vid);
|
||||
return rc;
|
||||
@ -908,12 +908,12 @@ new_connection(int vid)
|
||||
}
|
||||
|
||||
if (posix_memalign((void **)&vsession, SPDK_CACHE_LINE_SIZE, sizeof(*vsession) +
|
||||
vdev->backend->session_ctx_size)) {
|
||||
vdev->user_backend->session_ctx_size)) {
|
||||
SPDK_ERRLOG("vsession alloc failed\n");
|
||||
spdk_vhost_unlock();
|
||||
return -1;
|
||||
}
|
||||
memset(vsession, 0, sizeof(*vsession) + vdev->backend->session_ctx_size);
|
||||
memset(vsession, 0, sizeof(*vsession) + vdev->user_backend->session_ctx_size);
|
||||
|
||||
vsession->vdev = vdev;
|
||||
vsession->vid = vid;
|
||||
@ -1058,7 +1058,7 @@ start_device(int vid)
|
||||
vhost_user_session_set_coalescing(vdev, vsession, NULL);
|
||||
vhost_session_mem_register(vsession->mem);
|
||||
vsession->initialized = true;
|
||||
rc = vdev->backend->start_session(vsession);
|
||||
rc = vdev->user_backend->start_session(vsession);
|
||||
if (rc != 0) {
|
||||
vhost_session_mem_unregister(vsession->mem);
|
||||
free(vsession->mem);
|
||||
@ -1712,7 +1712,7 @@ vhost_dev_thread_exit(void *arg1)
|
||||
|
||||
int
|
||||
vhost_user_dev_register(struct spdk_vhost_dev *vdev, const char *name, struct spdk_cpuset *cpumask,
|
||||
const struct spdk_vhost_dev_backend *backend)
|
||||
const struct spdk_vhost_user_dev_backend *user_backend)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
@ -1735,7 +1735,7 @@ vhost_user_dev_register(struct spdk_vhost_dev *vdev, const char *name, struct sp
|
||||
}
|
||||
|
||||
vdev->registered = true;
|
||||
vdev->backend = backend;
|
||||
vdev->user_backend = user_backend;
|
||||
TAILQ_INIT(&vdev->vsessions);
|
||||
|
||||
vhost_user_dev_set_coalescing(vdev, SPDK_VHOST_COALESCING_DELAY_BASE_US,
|
||||
|
@ -116,7 +116,8 @@ vhost_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
|
||||
|
||||
int
|
||||
vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
|
||||
const struct spdk_vhost_dev_backend *backend)
|
||||
const struct spdk_vhost_dev_backend *backend,
|
||||
const struct spdk_vhost_user_dev_backend *user_backend)
|
||||
{
|
||||
struct spdk_cpuset cpumask = {};
|
||||
int rc;
|
||||
@ -143,7 +144,9 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = vhost_user_dev_register(vdev, name, &cpumask, backend);
|
||||
vdev->backend = backend;
|
||||
|
||||
rc = vhost_user_dev_register(vdev, name, &cpumask, user_backend);
|
||||
if (rc != 0) {
|
||||
free(vdev->name);
|
||||
return rc;
|
||||
|
@ -1534,10 +1534,13 @@ vhost_blk_get_config(struct spdk_vhost_dev *vdev, uint8_t *config,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
|
||||
static const struct spdk_vhost_user_dev_backend vhost_blk_user_device_backend = {
|
||||
.session_ctx_size = sizeof(struct spdk_vhost_blk_session) - sizeof(struct spdk_vhost_session),
|
||||
.start_session = vhost_blk_start,
|
||||
.stop_session = vhost_blk_stop,
|
||||
};
|
||||
|
||||
static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
|
||||
.vhost_get_config = vhost_blk_get_config,
|
||||
.dump_info_json = vhost_blk_dump_info_json,
|
||||
.write_config_json = vhost_blk_write_config_json,
|
||||
@ -1617,7 +1620,8 @@ spdk_vhost_blk_construct(const char *name, const char *cpumask, const char *dev_
|
||||
|
||||
bvdev->bdev = bdev;
|
||||
bvdev->readonly = req.readonly;
|
||||
ret = vhost_dev_register(vdev, name, cpumask, &vhost_blk_device_backend);
|
||||
ret = vhost_dev_register(vdev, name, cpumask, &vhost_blk_device_backend,
|
||||
&vhost_blk_user_device_backend);
|
||||
if (ret != 0) {
|
||||
spdk_put_io_channel(bvdev->dummy_io_channel);
|
||||
spdk_bdev_close(bvdev->bdev_desc);
|
||||
|
@ -185,6 +185,7 @@ struct spdk_vhost_dev {
|
||||
bool packed_ring_recovery;
|
||||
|
||||
const struct spdk_vhost_dev_backend *backend;
|
||||
const struct spdk_vhost_user_dev_backend *user_backend;
|
||||
|
||||
/* Saved original values used to setup coalescing to avoid integer
|
||||
* rounding issues during save/load config.
|
||||
@ -226,7 +227,7 @@ typedef int (*spdk_vhost_session_fn)(struct spdk_vhost_dev *vdev,
|
||||
*/
|
||||
typedef void (*spdk_vhost_dev_fn)(struct spdk_vhost_dev *vdev, void *arg);
|
||||
|
||||
struct spdk_vhost_dev_backend {
|
||||
struct spdk_vhost_user_dev_backend {
|
||||
/**
|
||||
* Size of additional per-session context data
|
||||
* allocated whenever a new client connects.
|
||||
@ -235,7 +236,9 @@ struct spdk_vhost_dev_backend {
|
||||
|
||||
int (*start_session)(struct spdk_vhost_session *vsession);
|
||||
int (*stop_session)(struct spdk_vhost_session *vsession);
|
||||
};
|
||||
|
||||
struct spdk_vhost_dev_backend {
|
||||
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);
|
||||
@ -404,7 +407,8 @@ vhost_dev_has_feature(struct spdk_vhost_session *vsession, unsigned feature_id)
|
||||
}
|
||||
|
||||
int vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
|
||||
const struct spdk_vhost_dev_backend *backend);
|
||||
const struct spdk_vhost_dev_backend *backend,
|
||||
const struct spdk_vhost_user_dev_backend *user_backend);
|
||||
int vhost_dev_unregister(struct spdk_vhost_dev *vdev);
|
||||
|
||||
void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
|
||||
@ -504,7 +508,7 @@ int vhost_user_session_set_coalescing(struct spdk_vhost_dev *vdev,
|
||||
int vhost_user_dev_set_coalescing(struct spdk_vhost_dev *vdev, uint32_t delay_base_us,
|
||||
uint32_t iops_threshold);
|
||||
int vhost_user_dev_register(struct spdk_vhost_dev *vdev, const char *name,
|
||||
struct spdk_cpuset *cpumask, const struct spdk_vhost_dev_backend *backend);
|
||||
struct spdk_cpuset *cpumask, const struct spdk_vhost_user_dev_backend *user_backend);
|
||||
int vhost_user_dev_unregister(struct spdk_vhost_dev *vdev);
|
||||
int vhost_user_init(void);
|
||||
typedef void (*vhost_fini_cb)(void *ctx);
|
||||
|
@ -150,10 +150,13 @@ static int vhost_scsi_dev_remove(struct spdk_vhost_dev *vdev);
|
||||
static int vhost_scsi_dev_param_changed(struct spdk_vhost_dev *vdev,
|
||||
unsigned scsi_tgt_num);
|
||||
|
||||
static const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = {
|
||||
static const struct spdk_vhost_user_dev_backend spdk_vhost_scsi_user_device_backend = {
|
||||
.session_ctx_size = sizeof(struct spdk_vhost_scsi_session) - sizeof(struct spdk_vhost_session),
|
||||
.start_session = vhost_scsi_start,
|
||||
.stop_session = vhost_scsi_stop,
|
||||
};
|
||||
|
||||
static const struct spdk_vhost_dev_backend spdk_vhost_scsi_device_backend = {
|
||||
.dump_info_json = vhost_scsi_dump_info_json,
|
||||
.write_config_json = vhost_scsi_write_config_json,
|
||||
.remove_device = vhost_scsi_dev_remove,
|
||||
@ -875,7 +878,8 @@ spdk_vhost_scsi_dev_construct(const char *name, const char *cpumask)
|
||||
|
||||
spdk_vhost_lock();
|
||||
rc = vhost_dev_register(&svdev->vdev, name, cpumask,
|
||||
&spdk_vhost_scsi_device_backend);
|
||||
&spdk_vhost_scsi_device_backend,
|
||||
&spdk_vhost_scsi_user_device_backend);
|
||||
|
||||
if (rc) {
|
||||
free(svdev);
|
||||
|
@ -102,6 +102,7 @@ spdk_call_unaffinitized(void *cb(void *arg), void *arg)
|
||||
}
|
||||
|
||||
static struct spdk_vhost_dev_backend g_vdev_backend;
|
||||
static struct spdk_vhost_user_dev_backend g_vdev_user_backend;
|
||||
|
||||
static int
|
||||
test_setup(void)
|
||||
@ -120,7 +121,7 @@ alloc_vdev(struct spdk_vhost_dev **vdev_p, const char *name, const char *cpumask
|
||||
CU_ASSERT(rc == 0);
|
||||
SPDK_CU_ASSERT_FATAL(vdev != NULL);
|
||||
memset(vdev, 0, sizeof(*vdev));
|
||||
rc = vhost_dev_register(vdev, name, cpumask, &g_vdev_backend);
|
||||
rc = vhost_dev_register(vdev, name, cpumask, &g_vdev_backend, &g_vdev_user_backend);
|
||||
if (rc == 0) {
|
||||
*vdev_p = vdev;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user