vhost: move session callbacks to rte_vhost_compat

This will allow us to write some more interesting unit tests
  because we can now mock high level callbacks instead of
  low level DPDK API and also, in future, we won't have to deal with sem_wait()
  in our mocked implementation since it's a DPDK specific thing.

Change-Id: I9ed5cff216e750685c00e718025ff1802fbe32c8
Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470456
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Vitaliy Mysak 2019-09-27 16:13:04 +02:00 committed by Tomasz Zawadzki
parent 1dae563373
commit 0e96d724d8
3 changed files with 72 additions and 47 deletions

View File

@ -48,7 +48,51 @@
#include "spdk_internal/vhost_user.h" #include "spdk_internal/vhost_user.h"
extern const struct vhost_device_ops g_spdk_vhost_ops; static int
new_connection(int vid)
{
char ifname[PATH_MAX];
if (rte_vhost_get_ifname(vid, ifname, PATH_MAX) < 0) {
SPDK_ERRLOG("Couldn't get a valid ifname for device with vid %d\n", vid);
return -1;
}
return vhost_new_connection_cb(vid, ifname);
}
static int
start_device(int vid)
{
return vhost_start_device_cb(vid);
}
static void
stop_device(int vid)
{
vhost_stop_device_cb(vid);
}
static void
destroy_connection(int vid)
{
vhost_destroy_connection_cb(vid);
}
const struct vhost_device_ops g_spdk_vhost_ops = {
.new_device = start_device,
.destroy_device = stop_device,
.new_connection = new_connection,
.destroy_connection = destroy_connection,
#ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB
.get_config = get_config,
.set_config = set_config,
.vhost_nvme_admin_passthrough = vhost_nvme_admin_passthrough,
.vhost_nvme_set_cq_call = vhost_nvme_set_cq_call,
.vhost_nvme_get_cap = vhost_nvme_get_cap,
.vhost_nvme_set_bar_mr = vhost_nvme_set_bar_mr,
#endif
};
#ifndef SPDK_CONFIG_VHOST_INTERNAL_LIB #ifndef SPDK_CONFIG_VHOST_INTERNAL_LIB

View File

@ -86,32 +86,6 @@ struct vhost_session_fn_ctx {
void *user_ctx; void *user_ctx;
}; };
static int new_connection(int vid);
static int start_device(int vid);
static void stop_device(int vid);
static void destroy_connection(int vid);
#ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB
static int get_config(int vid, uint8_t *config, uint32_t len);
static int set_config(int vid, uint8_t *config, uint32_t offset,
uint32_t size, uint32_t flags);
#endif
const struct vhost_device_ops g_spdk_vhost_ops = {
.new_device = start_device,
.destroy_device = stop_device,
.new_connection = new_connection,
.destroy_connection = destroy_connection,
#ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB
.get_config = get_config,
.set_config = set_config,
.vhost_nvme_admin_passthrough = vhost_nvme_admin_passthrough,
.vhost_nvme_set_cq_call = vhost_nvme_set_cq_call,
.vhost_nvme_get_cap = vhost_nvme_get_cap,
.vhost_nvme_set_bar_mr = vhost_nvme_set_bar_mr,
#endif
};
static TAILQ_HEAD(, spdk_vhost_dev) g_vhost_devices = TAILQ_HEAD_INITIALIZER( static TAILQ_HEAD(, spdk_vhost_dev) g_vhost_devices = TAILQ_HEAD_INITIALIZER(
g_vhost_devices); g_vhost_devices);
static pthread_mutex_t g_vhost_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_vhost_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -609,7 +583,6 @@ vhost_session_mem_unregister(struct spdk_vhost_session *vsession)
assert(false); assert(false);
} }
} }
} }
struct spdk_vhost_dev * struct spdk_vhost_dev *
@ -1086,8 +1059,8 @@ _stop_session(struct spdk_vhost_session *vsession)
free(vsession->mem); free(vsession->mem);
} }
static void void
stop_device(int vid) vhost_stop_device_cb(int vid)
{ {
struct spdk_vhost_session *vsession; struct spdk_vhost_session *vsession;
@ -1109,8 +1082,8 @@ stop_device(int vid)
pthread_mutex_unlock(&g_vhost_mutex); pthread_mutex_unlock(&g_vhost_mutex);
} }
static int int
start_device(int vid) vhost_start_device_cb(int vid)
{ {
struct spdk_vhost_dev *vdev; struct spdk_vhost_dev *vdev;
struct spdk_vhost_session *vsession; struct spdk_vhost_session *vsession;
@ -1200,8 +1173,8 @@ out:
} }
#ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB #ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB
static int int
get_config(int vid, uint8_t *config, uint32_t len) vhost_get_config_cb(int vid, uint8_t *config, uint32_t len)
{ {
struct spdk_vhost_session *vsession; struct spdk_vhost_session *vsession;
struct spdk_vhost_dev *vdev; struct spdk_vhost_dev *vdev;
@ -1224,8 +1197,8 @@ out:
return rc; return rc;
} }
static int int
set_config(int vid, uint8_t *config, uint32_t offset, uint32_t size, uint32_t flags) vhost_set_config_cb(int vid, uint8_t *config, uint32_t offset, uint32_t size, uint32_t flags)
{ {
struct spdk_vhost_session *vsession; struct spdk_vhost_session *vsession;
struct spdk_vhost_dev *vdev; struct spdk_vhost_dev *vdev;
@ -1290,21 +1263,14 @@ spdk_vhost_dev_remove(struct spdk_vhost_dev *vdev)
return vdev->backend->remove_device(vdev); return vdev->backend->remove_device(vdev);
} }
static int int
new_connection(int vid) vhost_new_connection_cb(int vid, const char *ifname)
{ {
struct spdk_vhost_dev *vdev; struct spdk_vhost_dev *vdev;
struct spdk_vhost_session *vsession; struct spdk_vhost_session *vsession;
char ifname[PATH_MAX];
pthread_mutex_lock(&g_vhost_mutex); pthread_mutex_lock(&g_vhost_mutex);
if (rte_vhost_get_ifname(vid, ifname, PATH_MAX) < 0) {
SPDK_ERRLOG("Couldn't get a valid ifname for device with vid %d\n", vid);
pthread_mutex_unlock(&g_vhost_mutex);
return -1;
}
vdev = spdk_vhost_dev_find(ifname); vdev = spdk_vhost_dev_find(ifname);
if (vdev == NULL) { if (vdev == NULL) {
SPDK_ERRLOG("Couldn't find device with vid %d to create connection for.\n", vid); SPDK_ERRLOG("Couldn't find device with vid %d to create connection for.\n", vid);
@ -1353,8 +1319,8 @@ new_connection(int vid)
return 0; return 0;
} }
static void void
destroy_connection(int vid) vhost_destroy_connection_cb(int vid)
{ {
struct spdk_vhost_session *vsession; struct spdk_vhost_session *vsession;

View File

@ -315,6 +315,21 @@ int vhost_scsi_controller_construct(void);
int vhost_blk_controller_construct(void); int vhost_blk_controller_construct(void);
void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w); void vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
/*
* Vhost callbacks for vhost_device_ops interface
*/
int vhost_new_connection_cb(int vid, const char *ifname);
int vhost_start_device_cb(int vid);
void vhost_stop_device_cb(int vid);
void vhost_destroy_connection_cb(int vid);
#ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB
int vhost_get_config_cb(int vid, uint8_t *config, uint32_t len)
int vhost_set_config_cb(int vid, uint8_t *config, uint32_t offset,
uint32_t size, uint32_t flags)
#endif
/* /*
* Call a function for each session of the provided vhost device. * Call a function for each session of the provided vhost device.
* The function will be called one-by-one on each session's thread. * The function will be called one-by-one on each session's thread.