bdev/nvme: dynamically allocate probe_ctx

Avoid allocating a large amount of stack space when increasing
NVME_MAX_CONTROLLERS.

Change-Id: I7017e5ed9f4d4f5c860dac608c3e5ae3c35864e7
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2017-05-01 16:54:11 -07:00 committed by Jim Harris
parent d0290b6525
commit 6b4da26449

View File

@ -715,7 +715,7 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
const char *base_name, const char *base_name,
const char **names, size_t *count) const char **names, size_t *count)
{ {
struct nvme_probe_ctx probe_ctx; struct nvme_probe_ctx *probe_ctx;
struct nvme_ctrlr *nvme_ctrlr; struct nvme_ctrlr *nvme_ctrlr;
struct nvme_bdev *nvme_bdev; struct nvme_bdev *nvme_bdev;
size_t j; size_t j;
@ -725,17 +725,25 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
return -1; return -1;
} }
probe_ctx.count = 1; probe_ctx = calloc(1, sizeof(*probe_ctx));
probe_ctx.trids[0] = *trid; if (probe_ctx == NULL) {
probe_ctx.names[0] = base_name; SPDK_ERRLOG("Failed to allocate probe_ctx\n");
if (spdk_nvme_probe(trid, &probe_ctx, probe_cb, attach_cb, NULL)) { return -1;
}
probe_ctx->count = 1;
probe_ctx->trids[0] = *trid;
probe_ctx->names[0] = base_name;
if (spdk_nvme_probe(trid, probe_ctx, probe_cb, attach_cb, NULL)) {
SPDK_ERRLOG("Failed to probe for new devices\n"); SPDK_ERRLOG("Failed to probe for new devices\n");
free(probe_ctx);
return -1; return -1;
} }
nvme_ctrlr = nvme_ctrlr_get(trid); nvme_ctrlr = nvme_ctrlr_get(trid);
if (!nvme_ctrlr) { if (!nvme_ctrlr) {
SPDK_ERRLOG("Failed to find new NVMe controller\n"); SPDK_ERRLOG("Failed to find new NVMe controller\n");
free(probe_ctx);
return -1; return -1;
} }
@ -751,12 +759,14 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid,
j++; j++;
} else { } else {
SPDK_ERRLOG("Unable to return all names of created bdevs\n"); SPDK_ERRLOG("Unable to return all names of created bdevs\n");
free(probe_ctx);
return -1; return -1;
} }
} }
} }
*count = j; *count = j;
free(probe_ctx);
return 0; return 0;
} }
@ -767,7 +777,7 @@ bdev_nvme_library_init(void)
const char *val; const char *val;
int rc; int rc;
size_t i; size_t i;
struct nvme_probe_ctx probe_ctx = {}; struct nvme_probe_ctx *probe_ctx;
int retry_count; int retry_count;
sp = spdk_conf_find_section(NULL, "Nvme"); sp = spdk_conf_find_section(NULL, "Nvme");
@ -775,6 +785,12 @@ bdev_nvme_library_init(void)
return 0; return 0;
} }
probe_ctx = calloc(1, sizeof(*probe_ctx));
if (probe_ctx == NULL) {
SPDK_ERRLOG("Failed to allocate probe_ctx\n");
return -1;
}
if ((retry_count = spdk_conf_section_get_intval(sp, "RetryCount")) < 0) { if ((retry_count = spdk_conf_section_get_intval(sp, "RetryCount")) < 0) {
if ((retry_count = spdk_conf_section_get_intval(sp, "NvmeRetryCount")) < 0) { if ((retry_count = spdk_conf_section_get_intval(sp, "NvmeRetryCount")) < 0) {
retry_count = SPDK_NVME_DEFAULT_RETRY_COUNT; retry_count = SPDK_NVME_DEFAULT_RETRY_COUNT;
@ -792,21 +808,23 @@ bdev_nvme_library_init(void)
break; break;
} }
rc = spdk_nvme_transport_id_parse(&probe_ctx.trids[i], val); rc = spdk_nvme_transport_id_parse(&probe_ctx->trids[i], val);
if (rc < 0) { if (rc < 0) {
SPDK_ERRLOG("Unable to parse TransportID: %s\n", val); SPDK_ERRLOG("Unable to parse TransportID: %s\n", val);
free(probe_ctx);
return -1; return -1;
} }
val = spdk_conf_section_get_nmval(sp, "TransportID", i, 1); val = spdk_conf_section_get_nmval(sp, "TransportID", i, 1);
if (val == NULL) { if (val == NULL) {
SPDK_ERRLOG("No name provided for TransportID\n"); SPDK_ERRLOG("No name provided for TransportID\n");
free(probe_ctx);
return -1; return -1;
} }
probe_ctx.names[i] = val; probe_ctx->names[i] = val;
probe_ctx.count++; probe_ctx->count++;
} }
if ((g_timeout = spdk_conf_section_get_intval(sp, "Timeout")) < 0) { if ((g_timeout = spdk_conf_section_get_intval(sp, "Timeout")) < 0) {
@ -858,7 +876,8 @@ bdev_nvme_library_init(void)
g_nvme_hotplug_poll_core = spdk_env_get_current_core(); g_nvme_hotplug_poll_core = spdk_env_get_current_core();
} }
if (spdk_nvme_probe(NULL, &probe_ctx, probe_cb, attach_cb, NULL)) { if (spdk_nvme_probe(NULL, probe_ctx, probe_cb, attach_cb, NULL)) {
free(probe_ctx);
return -1; return -1;
} }
@ -867,6 +886,7 @@ bdev_nvme_library_init(void)
g_nvme_hotplug_poll_core, g_nvme_hotplug_poll_timeout_us); g_nvme_hotplug_poll_core, g_nvme_hotplug_poll_timeout_us);
} }
free(probe_ctx);
return 0; return 0;
} }