nvmf: return early in nvmf_transport_poll_group_create

When buf_cache_size is 0, just return early.  This
allows us to un-indent a large section of code.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I167da677fdcd0504c6f2bfdb8b1a818155642f66
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17333
Community-CI: Mellanox Build Bot
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2023-03-24 22:37:02 +00:00
parent 2597ebbede
commit 280a3abc9c

View File

@ -551,37 +551,40 @@ nvmf_transport_poll_group_create(struct spdk_nvmf_transport *transport,
STAILQ_INIT(&tgroup->pending_buf_queue);
STAILQ_INIT(&tgroup->buf_cache);
if (transport->opts.buf_cache_size) {
tgroup->buf_cache_size = transport->opts.buf_cache_size;
bufs = calloc(tgroup->buf_cache_size, sizeof(struct spdk_nvmf_transport_pg_cache_buf *));
if (!bufs) {
SPDK_ERRLOG("Memory allocation failed, can't reserve buffers for the pg buffer cache\n");
return tgroup;
}
if (spdk_mempool_get_bulk(transport->data_buf_pool, (void **)bufs, tgroup->buf_cache_size)) {
tgroup->buf_cache_size = (uint32_t)spdk_mempool_count(transport->data_buf_pool);
SPDK_NOTICELOG("Unable to reserve the full number of buffers for the pg buffer cache. "
"Decrease the number of cached buffers from %u to %u\n",
transport->opts.buf_cache_size, tgroup->buf_cache_size);
/* Sanity check */
assert(tgroup->buf_cache_size <= transport->opts.buf_cache_size);
/* Try again with less number of buffers */
if (spdk_mempool_get_bulk(transport->data_buf_pool, (void **)bufs, tgroup->buf_cache_size)) {
SPDK_NOTICELOG("Failed to reserve %u buffers\n", tgroup->buf_cache_size);
tgroup->buf_cache_size = 0;
}
}
for (i = 0; i < tgroup->buf_cache_size; i++) {
STAILQ_INSERT_HEAD(&tgroup->buf_cache, bufs[i], link);
}
tgroup->buf_cache_count = tgroup->buf_cache_size;
free(bufs);
if (transport->opts.buf_cache_size == 0) {
/* We aren't going to allocate any buffers for the cache, so just return now. */
return tgroup;
}
tgroup->buf_cache_size = transport->opts.buf_cache_size;
bufs = calloc(tgroup->buf_cache_size, sizeof(struct spdk_nvmf_transport_pg_cache_buf *));
if (!bufs) {
SPDK_ERRLOG("Memory allocation failed, can't reserve buffers for the pg buffer cache\n");
return tgroup;
}
if (spdk_mempool_get_bulk(transport->data_buf_pool, (void **)bufs, tgroup->buf_cache_size)) {
tgroup->buf_cache_size = (uint32_t)spdk_mempool_count(transport->data_buf_pool);
SPDK_NOTICELOG("Unable to reserve the full number of buffers for the pg buffer cache. "
"Decrease the number of cached buffers from %u to %u\n",
transport->opts.buf_cache_size, tgroup->buf_cache_size);
/* Sanity check */
assert(tgroup->buf_cache_size <= transport->opts.buf_cache_size);
/* Try again with less number of buffers */
if (spdk_mempool_get_bulk(transport->data_buf_pool, (void **)bufs, tgroup->buf_cache_size)) {
SPDK_NOTICELOG("Failed to reserve %u buffers\n", tgroup->buf_cache_size);
tgroup->buf_cache_size = 0;
}
}
for (i = 0; i < tgroup->buf_cache_size; i++) {
STAILQ_INSERT_HEAD(&tgroup->buf_cache, bufs[i], link);
}
tgroup->buf_cache_count = tgroup->buf_cache_size;
free(bufs);
return tgroup;
}