Commit c75dfb42 authored by yidong0635's avatar yidong0635 Committed by Tomasz Zawadzki
Browse files

nvme/perf: Free resources when abnormal exit.



There are anbormal cases, from callocated nvme qpairs until
connect io qpairs successfully .
We should free these resources when abnormal exit, and codes
just return there.

Signed-off-by: default avataryidong0635 <dongx.yi@intel.com>
Change-Id: I08de9c1fe1757a11a118ebedc326d81e2c68b077
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2985


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 4c156e63
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -612,7 +612,7 @@ nvme_init_ns_worker_ctx(struct ns_worker_ctx *ns_ctx)

	ns_ctx->u.nvme.group = spdk_nvme_poll_group_create(NULL);
	if (ns_ctx->u.nvme.group == NULL) {
		return -1;
		goto poll_group_failed;
	}

	group = ns_ctx->u.nvme.group;
@@ -622,21 +622,35 @@ nvme_init_ns_worker_ctx(struct ns_worker_ctx *ns_ctx)
		qpair = ns_ctx->u.nvme.qpair[i];
		if (!qpair) {
			printf("ERROR: spdk_nvme_ctrlr_alloc_io_qpair failed\n");
			return -1;
			goto qpair_failed;
		}

		if (spdk_nvme_poll_group_add(group, qpair)) {
			printf("ERROR: unable to add I/O qpair to poll group.\n");
			return -1;
			spdk_nvme_ctrlr_free_io_qpair(qpair);
			goto qpair_failed;
		}

		if (spdk_nvme_ctrlr_connect_io_qpair(entry->u.nvme.ctrlr, qpair)) {
			printf("ERROR: unable to connect I/O qpair.\n");
			return -1;
			spdk_nvme_poll_group_remove(group, qpair);
			spdk_nvme_ctrlr_free_io_qpair(qpair);
			goto qpair_failed;
		}
	}

	return 0;

qpair_failed:
	for (; i > 0; --i) {
		spdk_nvme_poll_group_remove(ns_ctx->u.nvme.group, ns_ctx->u.nvme.qpair[i - 1]);
		spdk_nvme_ctrlr_free_io_qpair(ns_ctx->u.nvme.qpair[i - 1]);
	}

	spdk_nvme_poll_group_destroy(ns_ctx->u.nvme.group);
poll_group_failed:
	free(ns_ctx->u.nvme.qpair);
	return -1;
}

static void