aboutsummaryrefslogtreecommitdiff
path: root/tests/test-block-iothread.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2019-04-24 17:47:34 +0200
committerKevin Wolf <kwolf@redhat.com>2019-06-04 15:22:22 +0200
commit2e9cdab3000530fdd03df7f0a5d124eaa0ae942f (patch)
tree14aea6974cf2b98315026554fb445808ec6b86f9 /tests/test-block-iothread.c
parent48946d7d64818c349e3e183838f99d8ce32a9b86 (diff)
downloadqemu-2e9cdab3000530fdd03df7f0a5d124eaa0ae942f.zip
qemu-2e9cdab3000530fdd03df7f0a5d124eaa0ae942f.tar.gz
qemu-2e9cdab3000530fdd03df7f0a5d124eaa0ae942f.tar.bz2
test-block-iothread: BlockBackend AioContext across root node change
Test that BlockBackends preserve their assigned AioContext even when the root node goes away. Inserting a new root node will move it to the right AioContext. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'tests/test-block-iothread.c')
-rw-r--r--tests/test-block-iothread.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
index 38f5999..f41082e 100644
--- a/tests/test-block-iothread.c
+++ b/tests/test-block-iothread.c
@@ -695,6 +695,38 @@ static void test_attach_second_node(void)
blk_unref(blk);
}
+static void test_attach_preserve_blk_ctx(void)
+{
+ IOThread *iothread = iothread_new();
+ AioContext *ctx = iothread_get_aio_context(iothread);
+ BlockBackend *blk;
+ BlockDriverState *bs;
+
+ blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL);
+ bs = bdrv_new_open_driver(&bdrv_test, "base", BDRV_O_RDWR, &error_abort);
+ bs->total_sectors = 65536 / BDRV_SECTOR_SIZE;
+
+ /* Add node to BlockBackend that has an iothread context assigned */
+ blk_insert_bs(blk, bs, &error_abort);
+ g_assert(blk_get_aio_context(blk) == ctx);
+ g_assert(bdrv_get_aio_context(bs) == ctx);
+
+ /* Remove the node again */
+ blk_remove_bs(blk);
+ /* TODO bs should move back to main context here */
+ g_assert(blk_get_aio_context(blk) == ctx);
+ g_assert(bdrv_get_aio_context(bs) == ctx);
+
+ /* Re-attach the node */
+ blk_insert_bs(blk, bs, &error_abort);
+ g_assert(blk_get_aio_context(blk) == ctx);
+ g_assert(bdrv_get_aio_context(bs) == ctx);
+
+ blk_set_aio_context(blk, qemu_get_aio_context(), &error_abort);
+ bdrv_unref(bs);
+ blk_unref(blk);
+}
+
int main(int argc, char **argv)
{
int i;
@@ -711,6 +743,7 @@ int main(int argc, char **argv)
g_test_add_func("/attach/blockjob", test_attach_blockjob);
g_test_add_func("/attach/second_node", test_attach_second_node);
+ g_test_add_func("/attach/preserve_blk_ctx", test_attach_preserve_blk_ctx);
g_test_add_func("/propagate/basic", test_propagate_basic);
g_test_add_func("/propagate/diamond", test_propagate_diamond);
g_test_add_func("/propagate/mirror", test_propagate_mirror);