Commit 494c252a authored by Jim Harris's avatar Jim Harris
Browse files

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: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I009e8277eef41d7e3677d9f135db34d8eaf2f071

Reviewed-on: https://review.gerrithub.io/401256


Reviewed-by: default avatarMaciej Szwed <maciej.szwed@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent ee8af4e9
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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);
}
+17 −7
Original line number Diff line number Diff line
@@ -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 *