diff --git a/lib/nvme/nvme_pcie_common.c b/lib/nvme/nvme_pcie_common.c index a64a3a278..90f8ce01d 100644 --- a/lib/nvme/nvme_pcie_common.c +++ b/lib/nvme/nvme_pcie_common.c @@ -530,14 +530,14 @@ _nvme_pcie_ctrlr_create_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme int rc; /* Statistics may already be allocated in the case of controller reset */ - if (!pqpair->stat) { - if (qpair->poll_group) { - struct nvme_pcie_poll_group *group = SPDK_CONTAINEROF(qpair->poll_group, - struct nvme_pcie_poll_group, group); + if (qpair->poll_group) { + struct nvme_pcie_poll_group *group = SPDK_CONTAINEROF(qpair->poll_group, + struct nvme_pcie_poll_group, group); - pqpair->stat = &group->stats; - pqpair->shared_stats = true; - } else { + pqpair->stat = &group->stats; + pqpair->shared_stats = true; + } else { + if (pqpair->stat == NULL) { pqpair->stat = calloc(1, sizeof(*pqpair->stat)); if (!pqpair->stat) { SPDK_ERRLOG("Failed to allocate qpair statistics\n"); @@ -547,7 +547,6 @@ _nvme_pcie_ctrlr_create_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme } } - rc = nvme_pcie_ctrlr_cmd_create_io_cq(ctrlr, qpair, nvme_completion_create_cq_cb, qpair); if (rc != 0) { diff --git a/lib/nvme/nvme_tcp.c b/lib/nvme/nvme_tcp.c index 2b474bc83..52fdf6f96 100644 --- a/lib/nvme/nvme_tcp.c +++ b/lib/nvme/nvme_tcp.c @@ -2048,10 +2048,16 @@ nvme_tcp_ctrlr_connect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpa tqpair->stats = &tgroup->stats; tqpair->shared_stats = true; } else { - tqpair->stats = calloc(1, sizeof(*tqpair->stats)); - if (!tqpair->stats) { - SPDK_ERRLOG("tcp stats memory allocation failed\n"); - return -ENOMEM; + /* When resetting a controller, we disconnect adminq and then reconnect. The stats + * is not freed when disconnecting. So when reconnecting, don't allocate memory + * again. + */ + if (tqpair->stats == NULL) { + tqpair->stats = calloc(1, sizeof(*tqpair->stats)); + if (!tqpair->stats) { + SPDK_ERRLOG("tcp stats memory allocation failed\n"); + return -ENOMEM; + } } }