diff --git a/include/spdk/vhost.h b/include/spdk/vhost.h index 5cfe14a54..02296e2d7 100644 --- a/include/spdk/vhost.h +++ b/include/spdk/vhost.h @@ -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); diff --git a/lib/event/subsystems/vhost/vhost.c b/lib/event/subsystems/vhost/vhost.c index 1fdbc6aa5..a3d2c588f 100644 --- a/lib/event/subsystems/vhost/vhost.c +++ b/lib/event/subsystems/vhost/vhost.c @@ -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 diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index bdf835978..3ecf9f172 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -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