Commit 57a4b0f1 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

test/nvme_overhead&startup: Replace next pointer by TAILQ



This will make the object relationship cleaner and the asynchronous
detach operation easier to implement.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I3095d59b632ea2fc29fc44f8da330cb98c50bed1
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4434


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent da08be0f
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@

struct ctrlr_entry {
	struct spdk_nvme_ctrlr			*ctrlr;
	struct ctrlr_entry			*next;
	TAILQ_ENTRY(ctrlr_entry)		link;
	char					name[1024];
};

@@ -95,7 +95,7 @@ struct perf_task {

static bool g_enable_histogram = false;

static struct ctrlr_entry *g_ctrlr = NULL;
static TAILQ_HEAD(, ctrlr_entry) g_ctrlr = TAILQ_HEAD_INITIALIZER(g_ctrlr);
static struct ns_entry *g_ns = NULL;

static uint64_t g_tsc_rate;
@@ -176,8 +176,7 @@ register_ctrlr(struct spdk_nvme_ctrlr *ctrlr)

	entry->ctrlr = ctrlr;

	entry->next = g_ctrlr;
	g_ctrlr = entry;
	TAILQ_INSERT_TAIL(&g_ctrlr, entry, link);

	num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
	/* Only register the first namespace. */
@@ -645,7 +644,7 @@ static void
cleanup(void)
{
	struct ns_entry *ns_entry = g_ns;
	struct ctrlr_entry *ctrlr_entry = g_ctrlr;
	struct ctrlr_entry *ctrlr_entry, *tmp_ctrlr_entry;

	while (ns_entry) {
		struct ns_entry *next = ns_entry->next;
@@ -656,12 +655,10 @@ cleanup(void)
		ns_entry = next;
	}

	while (ctrlr_entry) {
		struct ctrlr_entry *next = ctrlr_entry->next;

	TAILQ_FOREACH_SAFE(ctrlr_entry, &g_ctrlr, link, tmp_ctrlr_entry) {
		TAILQ_REMOVE(&g_ctrlr, ctrlr_entry, link);
		spdk_nvme_detach(ctrlr_entry->ctrlr);
		free(ctrlr_entry);
		ctrlr_entry = next;
	}
}

+14 −18
Original line number Diff line number Diff line
@@ -39,19 +39,19 @@

struct ctrlr_entry {
	struct spdk_nvme_ctrlr		*ctrlr;
	struct ctrlr_entry	*next;
	TAILQ_ENTRY(ctrlr_entry)	link;
	char				name[1024];
};

struct ns_entry {
	struct spdk_nvme_ctrlr	*ctrlr;
	struct spdk_nvme_ns	*ns;
	struct ns_entry		*next;
	TAILQ_ENTRY(ns_entry)	link;
	struct spdk_nvme_qpair	*qpair;
};

static struct ctrlr_entry *g_controllers = NULL;
static struct ns_entry *g_namespaces = NULL;
static TAILQ_HEAD(, ctrlr_entry) g_controllers = TAILQ_HEAD_INITIALIZER(g_controllers);
static TAILQ_HEAD(, ns_entry) g_namespaces = TAILQ_HEAD_INITIALIZER(g_namespaces);
static int g_startup_time = 0;

static bool
@@ -92,28 +92,24 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
	snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);

	entry->ctrlr = ctrlr;
	entry->next = g_controllers;
	g_controllers = entry;
	TAILQ_INSERT_TAIL(&g_controllers, entry, link);
}

static void
cleanup(void)
{
	struct ns_entry *ns_entry = g_namespaces;
	struct ctrlr_entry *ctrlr_entry = g_controllers;
	struct ns_entry *ns_entry, *tmp_ns_entry;
	struct ctrlr_entry *ctrlr_entry, *tmp_ctrlr_entry;

	while (ns_entry) {
		struct ns_entry *next = ns_entry->next;
	TAILQ_FOREACH_SAFE(ns_entry, &g_namespaces, link, tmp_ns_entry) {
		TAILQ_REMOVE(&g_namespaces, ns_entry, link);
		free(ns_entry);
		ns_entry = next;
	}

	while (ctrlr_entry) {
		struct ctrlr_entry *next = ctrlr_entry->next;

	TAILQ_FOREACH_SAFE(ctrlr_entry, &g_controllers, link, tmp_ctrlr_entry) {
		TAILQ_REMOVE(&g_controllers, ctrlr_entry, link);
		spdk_nvme_detach(ctrlr_entry->ctrlr);
		free(ctrlr_entry);
		ctrlr_entry = next;
	}
}

@@ -198,7 +194,7 @@ int main(int argc, char **argv)
		return 1;
	}

	if (g_controllers == NULL) {
	if (TAILQ_EMPTY(&g_controllers)) {
		fprintf(stderr, "no NVMe controllers found\n");
		return 0;
	}