lib/vhost: move dev_dirname to rte_vhost_user

Creation of sockets is specific to rte_vhost, so it
functionality responsible for setting path for them.

dev_dirname is renamed to g_vhost_user_dev_dirname
and its definition is moved to rte_vhost_user.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I9bae67667b0f6624f2daf3244a048d10e94e553c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10631
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
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: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
Tomasz Zawadzki 2021-12-08 11:47:32 +01:00 committed by Jim Harris
parent 8684b0f575
commit 1e080e5e67
4 changed files with 42 additions and 40 deletions

View File

@ -46,6 +46,8 @@
#include "spdk_internal/vhost_user.h"
char g_vhost_user_dev_dirname[PATH_MAX] = "";
static inline void
vhost_session_mem_region_calc(uint64_t *previous_start, uint64_t *start, uint64_t *end,
uint64_t *len, struct rte_vhost_mem_region *region)
@ -446,3 +448,27 @@ spdk_vhost_get_coalescing(struct spdk_vhost_dev *vdev, uint32_t *delay_base_us,
*iops_threshold = vdev->coalescing_iops_threshold;
}
}
int
spdk_vhost_set_socket_path(const char *basename)
{
int ret;
if (basename && strlen(basename) > 0) {
ret = snprintf(g_vhost_user_dev_dirname, sizeof(g_vhost_user_dev_dirname) - 2, "%s", basename);
if (ret <= 0) {
return -EINVAL;
}
if ((size_t)ret >= sizeof(g_vhost_user_dev_dirname) - 2) {
SPDK_ERRLOG("Char dev dir path length %d is too long\n", ret);
return -EINVAL;
}
if (g_vhost_user_dev_dirname[ret - 1] != '/') {
g_vhost_user_dev_dirname[ret] = '/';
g_vhost_user_dev_dirname[ret + 1] = '\0';
}
}
return 0;
}

View File

@ -46,9 +46,6 @@ bool g_packed_ring_recovery = false;
static struct spdk_cpuset g_vhost_core_mask;
/* Path to folder where character device will be created. Can be set by user. */
static char dev_dirname[PATH_MAX] = "";
/* Thread performing all vhost management operations */
static struct spdk_thread *g_vhost_init_thread;
@ -892,9 +889,9 @@ vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *ma
return -EEXIST;
}
if (snprintf(path, sizeof(path), "%s%s", dev_dirname, name) >= (int)sizeof(path)) {
SPDK_ERRLOG("Resulting socket path for controller %s is too long: %s%s\n", name, dev_dirname,
name);
if (snprintf(path, sizeof(path), "%s%s", g_vhost_user_dev_dirname, name) >= (int)sizeof(path)) {
SPDK_ERRLOG("Resulting socket path for controller %s is too long: %s%s\n",
name, g_vhost_user_dev_dirname, name);
return -EINVAL;
}
@ -1387,30 +1384,6 @@ vhost_session_set_interrupt_mode(struct spdk_vhost_session *vsession, bool inter
}
}
int
spdk_vhost_set_socket_path(const char *basename)
{
int ret;
if (basename && strlen(basename) > 0) {
ret = snprintf(dev_dirname, sizeof(dev_dirname) - 2, "%s", basename);
if (ret <= 0) {
return -EINVAL;
}
if ((size_t)ret >= sizeof(dev_dirname) - 2) {
SPDK_ERRLOG("Char dev dir path length %d is too long\n", ret);
return -EINVAL;
}
if (dev_dirname[ret - 1] != '/') {
dev_dirname[ret] = '/';
dev_dirname[ret + 1] = '\0';
}
}
return 0;
}
void
vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{
@ -1437,8 +1410,8 @@ vhost_new_connection_cb(int vid, const char *ifname)
pthread_mutex_lock(&g_vhost_mutex);
dev_dirname_len = strlen(dev_dirname);
if (strncmp(ifname, dev_dirname, dev_dirname_len) == 0) {
dev_dirname_len = strlen(g_vhost_user_dev_dirname);
if (strncmp(ifname, g_vhost_user_dev_dirname, dev_dirname_len) == 0) {
ifname += dev_dirname_len;
}
@ -1547,17 +1520,17 @@ spdk_vhost_init(spdk_vhost_init_cb init_cb)
g_vhost_init_thread = spdk_get_thread();
assert(g_vhost_init_thread != NULL);
if (dev_dirname[0] == '\0') {
if (getcwd(dev_dirname, sizeof(dev_dirname) - 1) == NULL) {
if (g_vhost_user_dev_dirname[0] == '\0') {
if (getcwd(g_vhost_user_dev_dirname, sizeof(g_vhost_user_dev_dirname) - 1) == NULL) {
SPDK_ERRLOG("getcwd failed (%d): %s\n", errno, spdk_strerror(errno));
ret = -1;
goto out;
}
len = strlen(dev_dirname);
if (dev_dirname[len - 1] != '/') {
dev_dirname[len] = '/';
dev_dirname[len + 1] = '\0';
len = strlen(g_vhost_user_dev_dirname);
if (g_vhost_user_dev_dirname[len - 1] != '/') {
g_vhost_user_dev_dirname[len] = '/';
g_vhost_user_dev_dirname[len + 1] = '\0';
}
}

View File

@ -90,6 +90,9 @@ typedef struct rte_vhost_resubmit_desc spdk_vhost_resubmit_desc;
typedef struct rte_vhost_resubmit_info spdk_vhost_resubmit_info;
typedef struct rte_vhost_inflight_desc_packed spdk_vhost_inflight_desc;
/* Path to folder where character device will be created. Can be set by user. */
extern char g_vhost_user_dev_dirname[PATH_MAX];
struct spdk_vhost_virtqueue {
struct rte_vhost_vring vring;
struct rte_vhost_ring_inflight vring_inflight;

View File

@ -313,10 +313,10 @@ create_controller_test(void)
/* Create device with too long name and path */
memset(long_name, 'x', sizeof(long_name));
long_name[PATH_MAX - 1] = 0;
snprintf(dev_dirname, sizeof(dev_dirname), "some_path/");
snprintf(g_vhost_user_dev_dirname, sizeof(g_vhost_user_dev_dirname), "some_path/");
ret = alloc_vdev(&vdev, long_name, NULL);
CU_ASSERT(ret != 0);
dev_dirname[0] = 0;
g_vhost_user_dev_dirname[0] = 0;
/* Create device when device name is already taken */
ret = alloc_vdev(&vdev, "vdev_name_0", NULL);