diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index 16e8c69de..6fb84528d 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -42,7 +42,7 @@ #include "spdk/vhost.h" #include "vhost_internal.h" -static uint32_t g_num_ctrlrs[RTE_MAX_LCORE]; +static uint32_t *g_num_ctrlrs; /* Path to folder where character device will be created. Can be set by user. */ static char dev_dirname[PATH_MAX] = ""; @@ -1159,12 +1159,22 @@ spdk_vhost_unlock(void) int spdk_vhost_init(void) { + uint32_t last_core; + + last_core = spdk_env_get_last_core(); + g_num_ctrlrs = calloc(last_core + 1, sizeof(uint32_t)); + if (!g_num_ctrlrs) { + SPDK_ERRLOG("Could not allocate array size=%u for g_num_ctrlrs\n", + last_core + 1); + return -1; + } return 0; } void spdk_vhost_fini(void) { + free(g_num_ctrlrs); } SPDK_LOG_REGISTER_COMPONENT("vhost_ring", SPDK_LOG_VHOST_RING) diff --git a/test/unit/lib/vhost/vhost.c/vhost_ut.c b/test/unit/lib/vhost/vhost.c/vhost_ut.c index bf69d5feb..eb95ce7c4 100644 --- a/test/unit/lib/vhost/vhost.c/vhost_ut.c +++ b/test/unit/lib/vhost/vhost.c/vhost_ut.c @@ -50,6 +50,7 @@ DEFINE_STUB(spdk_app_get_core_mask, uint64_t, (void), 0); DEFINE_STUB(spdk_app_parse_core_mask, int, (const char *mask, uint64_t *cpumask), 0); DEFINE_STUB(spdk_env_get_first_core, uint32_t, (void), 0); DEFINE_STUB(spdk_env_get_next_core, uint32_t, (uint32_t prev_core), 0); +DEFINE_STUB(spdk_env_get_last_core, uint32_t, (void), 0); DEFINE_STUB_V(spdk_app_stop, (int rc)); DEFINE_STUB_V(spdk_event_call, (struct spdk_event *event)); DEFINE_STUB(spdk_poller_register, struct spdk_poller *, (spdk_poller_fn fn, void *arg,