Commit fc0a2362 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

vhost: add API to set socket path



This lets us drop the basename parameter from spdk_vhost_startup(),
which is a step toward making vhost initialization happen as part of the
event subsystem instead of in the spdk_app_start() callback.

Change-Id: I4fe18c4c3f12b706e73ae74500be58f1582110fd
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/403225


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 245e2e98
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -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();

+12 −1
Original line number Diff line number Diff line
@@ -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);
+11 −4
Original line number Diff line number Diff line
@@ -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");