nvme: Don't free and allocate the entire ns array in
nvme_ctrlr_construct_namespaces We can just reallocate here to be more efficient. Signed-off-by: Ben Walker <benjamin.walker@intel.com> Change-Id: I8cfc87da23aee6c05ff83aea2165683dddba1dbd Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10688 Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
595d12f720
commit
175e17671b
@ -2991,34 +2991,32 @@ nvme_ctrlr_construct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
uint32_t i, nn = ctrlr->cdata.nn;
|
uint32_t i, nn = ctrlr->cdata.nn;
|
||||||
|
struct spdk_nvme_ns *tmp;
|
||||||
|
|
||||||
/* ctrlr->num_ns may be 0 (startup) or a different number of namespaces (reset),
|
/* ctrlr->num_ns may be 0 (startup) or a different number of namespaces (reset),
|
||||||
* so check if we need to reallocate.
|
* so check if we need to reallocate.
|
||||||
*/
|
*/
|
||||||
if (nn != ctrlr->num_ns) {
|
if (nn != ctrlr->num_ns) {
|
||||||
nvme_ctrlr_destruct_namespaces(ctrlr);
|
tmp = spdk_realloc(ctrlr->ns, nn * sizeof(struct spdk_nvme_ns), 64);
|
||||||
|
if (tmp == NULL) {
|
||||||
if (nn == 0) {
|
|
||||||
NVME_CTRLR_WARNLOG(ctrlr, "controller has 0 namespaces\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrlr->ns = spdk_zmalloc(nn * sizeof(struct spdk_nvme_ns), 64, NULL,
|
|
||||||
SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_SHARE);
|
|
||||||
if (ctrlr->ns == NULL) {
|
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrlr->num_ns = nn;
|
if (nn > ctrlr->num_ns) {
|
||||||
} else {
|
memset(tmp + ctrlr->num_ns, 0, (nn - ctrlr->num_ns) * sizeof(struct spdk_nvme_ns));
|
||||||
/*
|
|
||||||
* The controller could have been reset with the same number of namespaces.
|
|
||||||
* If so, we still need to free the iocs specific data, to get a clean slate.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < ctrlr->num_ns; i++) {
|
|
||||||
nvme_ns_free_iocs_specific_data(&ctrlr->ns[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctrlr->ns = tmp;
|
||||||
|
ctrlr->num_ns = nn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The controller could have been reset with the same number of namespaces.
|
||||||
|
* If so, we still need to free the iocs specific data, to get a clean slate.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < ctrlr->num_ns; i++) {
|
||||||
|
nvme_ns_free_iocs_specific_data(&ctrlr->ns[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user