[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 11/24] test-block-iothread: Test AioContext propagati
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 11/24] test-block-iothread: Test AioContext propagation through the tree |
Date: |
Mon, 20 May 2019 18:14:40 +0200 |
Signed-off-by: Kevin Wolf <address@hidden>
---
tests/test-block-iothread.c | 131 ++++++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+)
diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
index 036ed9a3b3..938831c9bd 100644
--- a/tests/test-block-iothread.c
+++ b/tests/test-block-iothread.c
@@ -27,6 +27,7 @@
#include "block/blockjob_int.h"
#include "sysemu/block-backend.h"
#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
#include "iothread.h"
static int coroutine_fn bdrv_test_co_prwv(BlockDriverState *bs,
@@ -459,6 +460,134 @@ static void test_attach_blockjob(void)
blk_unref(blk);
}
+/*
+ * Test that changing the AioContext for one node in a tree (here through blk)
+ * changes all other nodes as well:
+ *
+ * blk
+ * |
+ * | bs_verify [blkverify]
+ * | / \
+ * | / \
+ * bs_a [bdrv_test] bs_b [bdrv_test]
+ *
+ */
+static void test_propagate_basic(void)
+{
+ IOThread *iothread = iothread_new();
+ AioContext *ctx = iothread_get_aio_context(iothread);
+ BlockBackend *blk;
+ BlockDriverState *bs_a, *bs_b, *bs_verify;
+ QDict *options;
+
+ /* Create bs_a and its BlockBackend */
+ blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
+ bs_a = bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_abort);
+ blk_insert_bs(blk, bs_a, &error_abort);
+
+ /* Create bs_b */
+ bs_b = bdrv_new_open_driver(&bdrv_test, "bs_b", BDRV_O_RDWR, &error_abort);
+
+ /* Create blkverify filter that references both bs_a and bs_b */
+ options = qdict_new();
+ qdict_put_str(options, "driver", "blkverify");
+ qdict_put_str(options, "test", "bs_a");
+ qdict_put_str(options, "raw", "bs_b");
+
+ bs_verify = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
+
+ /* Switch the AioContext */
+ blk_set_aio_context(blk, ctx);
+ g_assert(blk_get_aio_context(blk) == ctx);
+ g_assert(bdrv_get_aio_context(bs_a) == ctx);
+ g_assert(bdrv_get_aio_context(bs_verify) == ctx);
+ g_assert(bdrv_get_aio_context(bs_b) == ctx);
+
+ /* Switch the AioContext back */
+ ctx = qemu_get_aio_context();
+ blk_set_aio_context(blk, ctx);
+ g_assert(blk_get_aio_context(blk) == ctx);
+ g_assert(bdrv_get_aio_context(bs_a) == ctx);
+ g_assert(bdrv_get_aio_context(bs_verify) == ctx);
+ g_assert(bdrv_get_aio_context(bs_b) == ctx);
+
+ bdrv_unref(bs_verify);
+ bdrv_unref(bs_b);
+ bdrv_unref(bs_a);
+ blk_unref(blk);
+}
+
+/*
+ * Test that diamonds in the graph don't lead to endless recursion:
+ *
+ * blk
+ * |
+ * bs_verify [blkverify]
+ * / \
+ * / \
+ * bs_b [raw] bs_c[raw]
+ * \ /
+ * \ /
+ * bs_a [bdrv_test]
+ */
+static void test_propagate_diamond(void)
+{
+ IOThread *iothread = iothread_new();
+ AioContext *ctx = iothread_get_aio_context(iothread);
+ BlockBackend *blk;
+ BlockDriverState *bs_a, *bs_b, *bs_c, *bs_verify;
+ QDict *options;
+
+ /* Create bs_a */
+ bs_a = bdrv_new_open_driver(&bdrv_test, "bs_a", BDRV_O_RDWR, &error_abort);
+
+ /* Create bs_b and bc_c */
+ options = qdict_new();
+ qdict_put_str(options, "driver", "raw");
+ qdict_put_str(options, "file", "bs_a");
+ qdict_put_str(options, "node-name", "bs_b");
+ bs_b = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
+
+ options = qdict_new();
+ qdict_put_str(options, "driver", "raw");
+ qdict_put_str(options, "file", "bs_a");
+ qdict_put_str(options, "node-name", "bs_c");
+ bs_c = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
+
+ /* Create blkverify filter that references both bs_b and bs_c */
+ options = qdict_new();
+ qdict_put_str(options, "driver", "blkverify");
+ qdict_put_str(options, "test", "bs_b");
+ qdict_put_str(options, "raw", "bs_c");
+
+ bs_verify = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
+ blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
+ blk_insert_bs(blk, bs_verify, &error_abort);
+
+ /* Switch the AioContext */
+ blk_set_aio_context(blk, ctx);
+ g_assert(blk_get_aio_context(blk) == ctx);
+ g_assert(bdrv_get_aio_context(bs_verify) == ctx);
+ g_assert(bdrv_get_aio_context(bs_a) == ctx);
+ g_assert(bdrv_get_aio_context(bs_b) == ctx);
+ g_assert(bdrv_get_aio_context(bs_c) == ctx);
+
+ /* Switch the AioContext back */
+ ctx = qemu_get_aio_context();
+ blk_set_aio_context(blk, ctx);
+ g_assert(blk_get_aio_context(blk) == ctx);
+ g_assert(bdrv_get_aio_context(bs_verify) == ctx);
+ g_assert(bdrv_get_aio_context(bs_a) == ctx);
+ g_assert(bdrv_get_aio_context(bs_b) == ctx);
+ g_assert(bdrv_get_aio_context(bs_c) == ctx);
+
+ blk_unref(blk);
+ bdrv_unref(bs_verify);
+ bdrv_unref(bs_c);
+ bdrv_unref(bs_b);
+ bdrv_unref(bs_a);
+}
+
int main(int argc, char **argv)
{
int i;
@@ -474,6 +603,8 @@ int main(int argc, char **argv)
}
g_test_add_func("/attach/blockjob", test_attach_blockjob);
+ g_test_add_func("/propagate/basic", test_propagate_basic);
+ g_test_add_func("/propagate/diamond", test_propagate_diamond);
return g_test_run();
}
--
2.20.1
- [Qemu-block] [PULL 06/24] nvme: fix copy direction in DMA reads going to CMB, (continued)
- [Qemu-block] [PULL 06/24] nvme: fix copy direction in DMA reads going to CMB, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 04/24] qmp: forbid qmp_cont in RUN_STATE_FINISH_MIGRATE, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 03/24] block: Use BDRV_REQUEST_MAX_BYTES instead of BDRV_REQUEST_MAX_SECTORS, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 01/24] block/file-posix: Truncate in xfs_write_zeroes(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 02/24] qcow2: Define and use QCOW2_COMPRESSED_SECTOR_SIZE, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 09/24] block: Move recursion to bdrv_set_aio_context(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 12/24] block: Implement .(can_)set_aio_ctx for BlockBackend, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 07/24] block: Add bdrv_try_set_aio_context(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 05/24] iotest: fix 169: do not run qmp_cont in RUN_STATE_FINISH_MIGRATE, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 10/24] block: Propagate AioContext change to parents, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 11/24] test-block-iothread: Test AioContext propagation through the tree,
Kevin Wolf <=
- [Qemu-block] [PULL 16/24] test-block-iothread: Test AioContext propagation for block jobs, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 13/24] block: Add blk_set_allow_aio_context_change(), Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 08/24] block: Make bdrv_attach/detach_aio_context() static, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 15/24] blockjob: Remove AioContext notifiers, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 14/24] blockjob: Propagate AioContext change to all job nodes, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 17/24] block/file-posix: Unaligned O_DIRECT block-status, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 22/24] iotests.py: Let assert_qmp() accept an array, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 18/24] iotests: Test unaligned raw images with O_DIRECT, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 24/24] iotests: Make 245 faster and more reliable, Kevin Wolf, 2019/05/20
- [Qemu-block] [PULL 21/24] block: Improve "Block node is read-only" message, Kevin Wolf, 2019/05/20