diff --git a/app/vhost/vhost.c b/app/vhost/vhost.c index 308b101c5..ecf48e520 100644 --- a/app/vhost/vhost.c +++ b/app/vhost/vhost.c @@ -44,7 +44,6 @@ #define SPDK_VHOST_DEFAULT_ENABLE_COREDUMP true #define SPDK_VHOST_DEFAULT_MEM_SIZE 1024 -static const char *g_socket_path = NULL; static const char *g_pid_path = NULL; static void @@ -86,7 +85,7 @@ vhost_parse_arg(int ch, char *arg) g_pid_path = arg; break; case 'S': - g_socket_path = arg; + spdk_vhost_set_socket_path(arg); break; } } @@ -110,7 +109,7 @@ main(int argc, char *argv[]) } /* Blocks until the application is exiting */ - rc = spdk_app_start(&opts, spdk_vhost_startup, (void *)g_socket_path, NULL); + rc = spdk_app_start(&opts, spdk_vhost_startup, NULL, NULL); spdk_app_fini(); diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index 409759cab..f7b0e73af 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -52,6 +52,17 @@ extern "C" { */ typedef void (*spdk_vhost_fini_cb)(void); +/** + * Set the path to the directory where vhost sockets will be created. + * + * This function must be called before spdk_vhost_init(). + * + * \param basename Path to vhost socket directory + * + * \return 0 on success, negative errno on error. + */ +int spdk_vhost_set_socket_path(const char *basename); + /** * Init vhost environment. * @@ -69,7 +80,7 @@ void spdk_vhost_fini(spdk_vhost_fini_cb fini_cb); /** * Init vhost application. This is called once by SPDK app layer. * - * \param arg1 optional path to directory where sockets will be created. + * \param arg1 unused. * \param arg2 unused. */ void spdk_vhost_startup(void *arg1, void *arg2); diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 7265acaab..70dc8af45 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -1097,17 +1097,16 @@ out: return rc; } -void -spdk_vhost_startup(void *arg1, void *arg2) +int +spdk_vhost_set_socket_path(const char *basename) { int ret; - const char *basename = arg1; if (basename && strlen(basename) > 0) { ret = snprintf(dev_dirname, sizeof(dev_dirname) - 2, "%s", basename); if ((size_t)ret >= sizeof(dev_dirname) - 2) { SPDK_ERRLOG("Char dev dir path length %d is too long\n", ret); - goto out; + return -EINVAL; } if (dev_dirname[ret - 1] != '/') { @@ -1116,6 +1115,14 @@ spdk_vhost_startup(void *arg1, void *arg2) } } + return 0; +} + +void +spdk_vhost_startup(void *arg1, void *arg2) +{ + int ret; + ret = spdk_vhost_scsi_controller_construct(); if (ret != 0) { SPDK_ERRLOG("Cannot construct vhost controllers\n");