From 494c252abd08b2bfb22e420e7dd7d7b479d02c08 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 23 Feb 2018 10:56:40 -0700 Subject: [PATCH] test/blob: make bs_dev_common.c asynchronous Unit tests that use this will still immediately execute the messages by default. But upcoming changes to queue persists will need to leverage testing asynchronous behavior so these changes enable that. While here, fix some bugs where _bs_flush_scheduler() did not fully flush the queue of scheduled ops. Signed-off-by: Jim Harris Change-Id: I009e8277eef41d7e3677d9f135db34d8eaf2f071 Reviewed-on: https://review.gerrithub.io/401256 Reviewed-by: Maciej Szwed Tested-by: SPDK Automated Test System Reviewed-by: Shuhei Matsumoto Reviewed-by: Daniel Verkamp --- test/unit/lib/blob/blob.c/blob_ut.c | 9 +++++---- test/unit/lib/blob/bs_dev_common.c | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index c415a5176..90b2cb209 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -105,11 +105,12 @@ _bs_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx) static void _bs_flush_scheduler(void) { - struct scheduled_ops *ops, *tmp; + struct scheduled_ops *ops; - TAILQ_FOREACH_SAFE(ops, &g_scheduled_ops, ops_queue, tmp) { - ops->fn(ops->ctx); + while (!TAILQ_EMPTY(&g_scheduled_ops)) { + ops = TAILQ_FIRST(&g_scheduled_ops); TAILQ_REMOVE(&g_scheduled_ops, ops, ops_queue); + ops->fn(ops->ctx); free(ops); } } @@ -1873,10 +1874,10 @@ bs_destroy(void) CU_ASSERT(g_bserrno == 0); /* Loading an non-existent blob store should fail. */ - g_bserrno = -1; g_bs = NULL; dev = init_dev(); + g_bserrno = 0; spdk_bs_load(dev, &opts, bs_op_with_handle_complete, NULL); CU_ASSERT(g_bserrno != 0); } diff --git a/test/unit/lib/blob/bs_dev_common.c b/test/unit/lib/blob/bs_dev_common.c index a4f10f676..b24de2126 100644 --- a/test/unit/lib/blob/bs_dev_common.c +++ b/test/unit/lib/blob/bs_dev_common.c @@ -31,6 +31,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "spdk/io_channel.h" + #define DEV_BUFFER_SIZE (64 * 1024 * 1024) #define DEV_BUFFER_BLOCKLEN (4096) #define DEV_BUFFER_BLOCKCNT (DEV_BUFFER_SIZE / DEV_BUFFER_BLOCKLEN) @@ -56,6 +58,14 @@ dev_destroy(struct spdk_bs_dev *dev) free(dev); } +static void +dev_complete(void *arg) +{ + struct spdk_bs_dev_cb_args *cb_args = arg; + + cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); +} + static void dev_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload, uint64_t lba, uint32_t lba_count, @@ -67,7 +77,7 @@ dev_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload length = lba_count * DEV_BUFFER_BLOCKLEN; SPDK_CU_ASSERT_FATAL(offset + length <= DEV_BUFFER_SIZE); memcpy(payload, &g_dev_buffer[offset], length); - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); + spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } static void @@ -81,7 +91,7 @@ dev_write(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payloa length = lba_count * DEV_BUFFER_BLOCKLEN; SPDK_CU_ASSERT_FATAL(offset + length <= DEV_BUFFER_SIZE); memcpy(&g_dev_buffer[offset], payload, length); - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); + spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } static void @@ -115,7 +125,7 @@ dev_readv(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, offset += iov[i].iov_len; } - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); + spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } static void @@ -137,14 +147,14 @@ dev_writev(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, offset += iov[i].iov_len; } - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); + spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } static void dev_flush(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, struct spdk_bs_dev_cb_args *cb_args) { - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); + spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } static void @@ -158,7 +168,7 @@ dev_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, length = lba_count * DEV_BUFFER_BLOCKLEN; SPDK_CU_ASSERT_FATAL(offset + length <= DEV_BUFFER_SIZE); memset(&g_dev_buffer[offset], 0, length); - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); + spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } static void @@ -172,7 +182,7 @@ dev_write_zeroes(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, length = lba_count * DEV_BUFFER_BLOCKLEN; SPDK_CU_ASSERT_FATAL(offset + length <= DEV_BUFFER_SIZE); memset(&g_dev_buffer[offset], 0, length); - cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); + spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } static struct spdk_bs_dev *