Commit a5599094 authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Ben Walker
Browse files

vhost: add completion callback to lib init



Prepare vhost lib init to be asynchronous. We'll need
it for setting up the upcoming poll groups.

Change-Id: I3c66b3f17f8635d4b705dd988393431193938971
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452205


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 92d6eaa9
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -49,8 +49,13 @@ extern "C" {
#endif

/**
 * Callback funcion for spdk_vhost_fini().
 * Callback for spdk_vhost_init().
 *
 * \param rc 0 on success, negative errno on failure
 */
typedef void (*spdk_vhost_init_cb)(int rc);

/** Callback for spdk_vhost_fini(). */
typedef void (*spdk_vhost_fini_cb)(void);

/**
@@ -67,14 +72,14 @@ int spdk_vhost_set_socket_path(const char *basename);
/**
 * Init vhost environment.
 *
 * \return 0 on success, -1 on failure.
 * \param init_cb Function to be called when the initialization is complete.
 */
int spdk_vhost_init(void);
void spdk_vhost_init(spdk_vhost_init_cb init_cb);

/**
 * Clean up the environment of vhost after finishing the vhost application.
 * Clean up the environment of vhost.
 *
 * \param fini_cb Called when the cleanup operation completes.
 * \param fini_cb Function to be called when the cleanup is complete.
 */
void spdk_vhost_fini(spdk_vhost_fini_cb fini_cb);

+7 −5
Original line number Diff line number Diff line
@@ -38,15 +38,17 @@
#include "spdk_internal/event.h"

static void
spdk_vhost_subsystem_init(void)
spdk_vhost_subsystem_init_done(int rc)
{
	int rc = 0;

	rc = spdk_vhost_init();

	spdk_subsystem_init_next(rc);
}

static void
spdk_vhost_subsystem_init(void)
{
	spdk_vhost_init(spdk_vhost_subsystem_init_done);
}

static void
spdk_vhost_subsystem_fini_done(void)
{
+15 −8
Original line number Diff line number Diff line
@@ -1433,8 +1433,8 @@ spdk_vhost_unlock(void)
	pthread_mutex_unlock(&g_spdk_vhost_mutex);
}

int
spdk_vhost_init(void)
void
spdk_vhost_init(spdk_vhost_init_cb init_cb)
{
	uint32_t last_core;
	size_t len;
@@ -1443,7 +1443,8 @@ spdk_vhost_init(void)
	if (dev_dirname[0] == '\0') {
		if (getcwd(dev_dirname, sizeof(dev_dirname) - 1) == NULL) {
			SPDK_ERRLOG("getcwd failed (%d): %s\n", errno, spdk_strerror(errno));
			return -1;
			ret = -1;
			goto out;
		}

		len = strlen(dev_dirname);
@@ -1458,30 +1459,36 @@ spdk_vhost_init(void)
	if (!g_num_ctrlrs) {
		SPDK_ERRLOG("Could not allocate array size=%u for g_num_ctrlrs\n",
			    last_core + 1);
		return -1;
		ret = -1;
		goto out;
	}

	ret = spdk_vhost_scsi_controller_construct();
	if (ret != 0) {
		SPDK_ERRLOG("Cannot construct vhost controllers\n");
		return -1;
		ret = -1;
		goto out;
	}

	ret = spdk_vhost_blk_controller_construct();
	if (ret != 0) {
		SPDK_ERRLOG("Cannot construct vhost block controllers\n");
		return -1;
		ret = -1;
		goto out;
	}

#ifdef SPDK_CONFIG_VHOST_INTERNAL_LIB
	ret = spdk_vhost_nvme_controller_construct();
	if (ret != 0) {
		SPDK_ERRLOG("Cannot construct vhost NVMe controllers\n");
		return -1;
		ret = -1;
		goto out;
	}
#endif

	return 0;
	ret = 0;
out:
	init_cb(ret);
}

static void