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: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452205 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
92d6eaa95c
commit
a5599094da
@ -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);
|
||||
|
||||
|
@ -37,14 +37,16 @@
|
||||
|
||||
#include "spdk_internal/event.h"
|
||||
|
||||
static void
|
||||
spdk_vhost_subsystem_init_done(int rc)
|
||||
{
|
||||
spdk_subsystem_init_next(rc);
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_vhost_subsystem_init(void)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
rc = spdk_vhost_init();
|
||||
|
||||
spdk_subsystem_init_next(rc);
|
||||
spdk_vhost_init(spdk_vhost_subsystem_init_done);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user