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: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I3095d59b632ea2fc29fc44f8da330cb98c50bed1 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4434 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
da08be0f65
commit
57a4b0f179
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
struct ctrlr_entry {
|
struct ctrlr_entry {
|
||||||
struct spdk_nvme_ctrlr *ctrlr;
|
struct spdk_nvme_ctrlr *ctrlr;
|
||||||
struct ctrlr_entry *next;
|
TAILQ_ENTRY(ctrlr_entry) link;
|
||||||
char name[1024];
|
char name[1024];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ struct perf_task {
|
|||||||
|
|
||||||
static bool g_enable_histogram = false;
|
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 struct ns_entry *g_ns = NULL;
|
||||||
|
|
||||||
static uint64_t g_tsc_rate;
|
static uint64_t g_tsc_rate;
|
||||||
@ -176,8 +176,7 @@ register_ctrlr(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
|
|
||||||
entry->ctrlr = ctrlr;
|
entry->ctrlr = ctrlr;
|
||||||
|
|
||||||
entry->next = g_ctrlr;
|
TAILQ_INSERT_TAIL(&g_ctrlr, entry, link);
|
||||||
g_ctrlr = entry;
|
|
||||||
|
|
||||||
num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
|
num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
|
||||||
/* Only register the first namespace. */
|
/* Only register the first namespace. */
|
||||||
@ -645,7 +644,7 @@ static void
|
|||||||
cleanup(void)
|
cleanup(void)
|
||||||
{
|
{
|
||||||
struct ns_entry *ns_entry = g_ns;
|
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) {
|
while (ns_entry) {
|
||||||
struct ns_entry *next = ns_entry->next;
|
struct ns_entry *next = ns_entry->next;
|
||||||
@ -656,12 +655,10 @@ cleanup(void)
|
|||||||
ns_entry = next;
|
ns_entry = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ctrlr_entry) {
|
TAILQ_FOREACH_SAFE(ctrlr_entry, &g_ctrlr, link, tmp_ctrlr_entry) {
|
||||||
struct ctrlr_entry *next = ctrlr_entry->next;
|
TAILQ_REMOVE(&g_ctrlr, ctrlr_entry, link);
|
||||||
|
|
||||||
spdk_nvme_detach(ctrlr_entry->ctrlr);
|
spdk_nvme_detach(ctrlr_entry->ctrlr);
|
||||||
free(ctrlr_entry);
|
free(ctrlr_entry);
|
||||||
ctrlr_entry = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,19 +39,19 @@
|
|||||||
|
|
||||||
struct ctrlr_entry {
|
struct ctrlr_entry {
|
||||||
struct spdk_nvme_ctrlr *ctrlr;
|
struct spdk_nvme_ctrlr *ctrlr;
|
||||||
struct ctrlr_entry *next;
|
TAILQ_ENTRY(ctrlr_entry) link;
|
||||||
char name[1024];
|
char name[1024];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ns_entry {
|
struct ns_entry {
|
||||||
struct spdk_nvme_ctrlr *ctrlr;
|
struct spdk_nvme_ctrlr *ctrlr;
|
||||||
struct spdk_nvme_ns *ns;
|
struct spdk_nvme_ns *ns;
|
||||||
struct ns_entry *next;
|
TAILQ_ENTRY(ns_entry) link;
|
||||||
struct spdk_nvme_qpair *qpair;
|
struct spdk_nvme_qpair *qpair;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct ctrlr_entry *g_controllers = NULL;
|
static TAILQ_HEAD(, ctrlr_entry) g_controllers = TAILQ_HEAD_INITIALIZER(g_controllers);
|
||||||
static struct ns_entry *g_namespaces = NULL;
|
static TAILQ_HEAD(, ns_entry) g_namespaces = TAILQ_HEAD_INITIALIZER(g_namespaces);
|
||||||
static int g_startup_time = 0;
|
static int g_startup_time = 0;
|
||||||
|
|
||||||
static bool
|
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);
|
snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);
|
||||||
|
|
||||||
entry->ctrlr = ctrlr;
|
entry->ctrlr = ctrlr;
|
||||||
entry->next = g_controllers;
|
TAILQ_INSERT_TAIL(&g_controllers, entry, link);
|
||||||
g_controllers = entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cleanup(void)
|
cleanup(void)
|
||||||
{
|
{
|
||||||
struct ns_entry *ns_entry = g_namespaces;
|
struct ns_entry *ns_entry, *tmp_ns_entry;
|
||||||
struct ctrlr_entry *ctrlr_entry = g_controllers;
|
struct ctrlr_entry *ctrlr_entry, *tmp_ctrlr_entry;
|
||||||
|
|
||||||
while (ns_entry) {
|
TAILQ_FOREACH_SAFE(ns_entry, &g_namespaces, link, tmp_ns_entry) {
|
||||||
struct ns_entry *next = ns_entry->next;
|
TAILQ_REMOVE(&g_namespaces, ns_entry, link);
|
||||||
free(ns_entry);
|
free(ns_entry);
|
||||||
ns_entry = next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ctrlr_entry) {
|
TAILQ_FOREACH_SAFE(ctrlr_entry, &g_controllers, link, tmp_ctrlr_entry) {
|
||||||
struct ctrlr_entry *next = ctrlr_entry->next;
|
TAILQ_REMOVE(&g_controllers, ctrlr_entry, link);
|
||||||
|
|
||||||
spdk_nvme_detach(ctrlr_entry->ctrlr);
|
spdk_nvme_detach(ctrlr_entry->ctrlr);
|
||||||
free(ctrlr_entry);
|
free(ctrlr_entry);
|
||||||
ctrlr_entry = next;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +194,7 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_controllers == NULL) {
|
if (TAILQ_EMPTY(&g_controllers)) {
|
||||||
fprintf(stderr, "no NVMe controllers found\n");
|
fprintf(stderr, "no NVMe controllers found\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user