From da08be0f6515841ce3fd290232bcd4ea8bff48d5 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 28 Sep 2020 09:47:11 +0900 Subject: [PATCH] test/app_stub: 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 Change-Id: I4640d15015437bdb54ceeb0d1d0269c7ec3ceeb7 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4433 Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- test/app/stub/stub.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/app/stub/stub.c b/test/app/stub/stub.c index 83d9f706f..95d55379a 100644 --- a/test/app/stub/stub.c +++ b/test/app/stub/stub.c @@ -43,22 +43,20 @@ static struct spdk_poller *g_poller; struct ctrlr_entry { struct spdk_nvme_ctrlr *ctrlr; - struct ctrlr_entry *next; + TAILQ_ENTRY(ctrlr_entry) link; }; -static struct ctrlr_entry *g_controllers = NULL; +static TAILQ_HEAD(, ctrlr_entry) g_controllers = TAILQ_HEAD_INITIALIZER(g_controllers); static void cleanup(void) { - struct ctrlr_entry *ctrlr_entry = g_controllers; - - while (ctrlr_entry) { - struct ctrlr_entry *next = ctrlr_entry->next; + struct ctrlr_entry *ctrlr_entry, *tmp; + TAILQ_FOREACH_SAFE(ctrlr_entry, &g_controllers, link, tmp) { + TAILQ_REMOVE(&g_controllers, ctrlr_entry, link); spdk_nvme_detach(ctrlr_entry->ctrlr); free(ctrlr_entry); - ctrlr_entry = next; } } @@ -100,8 +98,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, } entry->ctrlr = ctrlr; - entry->next = g_controllers; - g_controllers = entry; + TAILQ_INSERT_TAIL(&g_controllers, entry, link); } static int