From 50b79fa6397b122f70275dc3c709ddb9d3bf3554 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Sun, 22 Dec 2019 18:03:27 -0500 Subject: [PATCH] bdevperf: Factor out getting free task from io_target to a function This patch and the next patch will simplify the nesting of task submission. Factor out the operation to get free task from io_target into a helper function bdevperf_target_get_task(). Use bdevperf_target_get_task() in bdevperf_submit_single() and reset_target(). Signed-off-by: Shuhei Matsumoto Change-Id: I4cb147a5a6c84cc2b0e517dc35a106d37affaa10 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478689 Tested-by: SPDK CI Jenkins Reviewed-by: Alexey Marchuk Reviewed-by: Tomasz Zawadzki Reviewed-by: Seth Howell Reviewed-by: Changpeng Liu Community-CI: SPDK CI Jenkins --- test/bdev/bdevperf/bdevperf.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/test/bdev/bdevperf/bdevperf.c b/test/bdev/bdevperf/bdevperf.c index 4418ce789e..403ed3fdbb 100644 --- a/test/bdev/bdevperf/bdevperf.c +++ b/test/bdev/bdevperf/bdevperf.c @@ -774,6 +774,21 @@ bdevperf_prep_zcopy_write_task(void *arg) target->current_queue_depth++; } +static struct bdevperf_task * +bdevperf_target_get_task(struct io_target *target) +{ + struct bdevperf_task *task; + + task = TAILQ_FIRST(&target->task_list); + if (!task) { + printf("Task allocation failed\n"); + abort(); + } + + TAILQ_REMOVE(&target->task_list, task, link); + return task; +} + static __thread unsigned int seed = 0; static void @@ -832,13 +847,7 @@ static void bdevperf_submit_single(struct io_target *target, struct bdevperf_task *task) { if (!task) { - if (!TAILQ_EMPTY(&target->task_list)) { - task = TAILQ_FIRST(&target->task_list); - TAILQ_REMOVE(&target->task_list, task, link); - } else { - printf("Task allocation failed\n"); - abort(); - } + task = bdevperf_target_get_task(target); } bdevperf_prep_task(task); @@ -892,19 +901,13 @@ static int reset_target(void *arg) { struct io_target *target = arg; - struct bdevperf_task *task = NULL; + struct bdevperf_task *task; int rc; spdk_poller_unregister(&target->reset_timer); /* Do reset. */ - task = TAILQ_FIRST(&target->task_list); - if (!task) { - printf("Task allocation failed\n"); - abort(); - } - TAILQ_REMOVE(&target->task_list, task, link); - + task = bdevperf_target_get_task(target); rc = spdk_bdev_reset(target->bdev_desc, target->ch, reset_cb, task); if (rc) {