Blame SOURCES/kvm-test-bdrv-drain-Drain-with-block-jobs-in-an-I-O-thre.patch

1bdc94
From 226e66779d3cc43409b08618d2bbdf160c6d42d8 Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Fri, 14 Sep 2018 10:55:27 +0200
1bdc94
Subject: [PATCH 36/49] test-bdrv-drain: Drain with block jobs in an I/O thread
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180914105540.18077-30-kwolf@redhat.com>
1bdc94
Patchwork-id: 82182
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 29/42] test-bdrv-drain: Drain with block jobs in an I/O thread
1bdc94
Bugzilla: 1601212
1bdc94
RH-Acked-by: John Snow <jsnow@redhat.com>
1bdc94
RH-Acked-by: Max Reitz <mreitz@redhat.com>
1bdc94
RH-Acked-by: Fam Zheng <famz@redhat.com>
1bdc94
1bdc94
This extends the existing drain test with a block job to include
1bdc94
variants where the block job runs in a different AioContext.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Reviewed-by: Fam Zheng <famz@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 tests/test-bdrv-drain.c | 92 +++++++++++++++++++++++++++++++++++++++++++++----
1bdc94
 1 file changed, 86 insertions(+), 6 deletions(-)
1bdc94
1bdc94
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
1bdc94
index 9bcb3c7..3cf3ba3 100644
1bdc94
--- a/tests/test-bdrv-drain.c
1bdc94
+++ b/tests/test-bdrv-drain.c
1bdc94
@@ -174,6 +174,28 @@ static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs)
1bdc94
     }
1bdc94
 }
1bdc94
 
1bdc94
+static void do_drain_begin_unlocked(enum drain_type drain_type, BlockDriverState *bs)
1bdc94
+{
1bdc94
+    if (drain_type != BDRV_DRAIN_ALL) {
1bdc94
+        aio_context_acquire(bdrv_get_aio_context(bs));
1bdc94
+    }
1bdc94
+    do_drain_begin(drain_type, bs);
1bdc94
+    if (drain_type != BDRV_DRAIN_ALL) {
1bdc94
+        aio_context_release(bdrv_get_aio_context(bs));
1bdc94
+    }
1bdc94
+}
1bdc94
+
1bdc94
+static void do_drain_end_unlocked(enum drain_type drain_type, BlockDriverState *bs)
1bdc94
+{
1bdc94
+    if (drain_type != BDRV_DRAIN_ALL) {
1bdc94
+        aio_context_acquire(bdrv_get_aio_context(bs));
1bdc94
+    }
1bdc94
+    do_drain_end(drain_type, bs);
1bdc94
+    if (drain_type != BDRV_DRAIN_ALL) {
1bdc94
+        aio_context_release(bdrv_get_aio_context(bs));
1bdc94
+    }
1bdc94
+}
1bdc94
+
1bdc94
 static void test_drv_cb_common(enum drain_type drain_type, bool recursive)
1bdc94
 {
1bdc94
     BlockBackend *blk;
1bdc94
@@ -785,11 +807,13 @@ BlockJobDriver test_job_driver = {
1bdc94
     },
1bdc94
 };
1bdc94
 
1bdc94
-static void test_blockjob_common(enum drain_type drain_type)
1bdc94
+static void test_blockjob_common(enum drain_type drain_type, bool use_iothread)
1bdc94
 {
1bdc94
     BlockBackend *blk_src, *blk_target;
1bdc94
     BlockDriverState *src, *target;
1bdc94
     BlockJob *job;
1bdc94
+    IOThread *iothread = NULL;
1bdc94
+    AioContext *ctx;
1bdc94
     int ret;
1bdc94
 
1bdc94
     src = bdrv_new_open_driver(&bdrv_test, "source", BDRV_O_RDWR,
1bdc94
@@ -797,21 +821,31 @@ static void test_blockjob_common(enum drain_type drain_type)
1bdc94
     blk_src = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
1bdc94
     blk_insert_bs(blk_src, src, &error_abort);
1bdc94
 
1bdc94
+    if (use_iothread) {
1bdc94
+        iothread = iothread_new();
1bdc94
+        ctx = iothread_get_aio_context(iothread);
1bdc94
+        blk_set_aio_context(blk_src, ctx);
1bdc94
+    } else {
1bdc94
+        ctx = qemu_get_aio_context();
1bdc94
+    }
1bdc94
+
1bdc94
     target = bdrv_new_open_driver(&bdrv_test, "target", BDRV_O_RDWR,
1bdc94
                                   &error_abort);
1bdc94
     blk_target = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
1bdc94
     blk_insert_bs(blk_target, target, &error_abort);
1bdc94
 
1bdc94
+    aio_context_acquire(ctx);
1bdc94
     job = block_job_create("job0", &test_job_driver, NULL, src, 0, BLK_PERM_ALL,
1bdc94
                            0, 0, NULL, NULL, &error_abort);
1bdc94
     block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abort);
1bdc94
     job_start(&job->job);
1bdc94
+    aio_context_release(ctx);
1bdc94
 
1bdc94
     g_assert_cmpint(job->job.pause_count, ==, 0);
1bdc94
     g_assert_false(job->job.paused);
1bdc94
     g_assert_true(job->job.busy); /* We're in job_sleep_ns() */
1bdc94
 
1bdc94
-    do_drain_begin(drain_type, src);
1bdc94
+    do_drain_begin_unlocked(drain_type, src);
1bdc94
 
1bdc94
     if (drain_type == BDRV_DRAIN_ALL) {
1bdc94
         /* bdrv_drain_all() drains both src and target */
1bdc94
@@ -822,7 +856,14 @@ static void test_blockjob_common(enum drain_type drain_type)
1bdc94
     g_assert_true(job->job.paused);
1bdc94
     g_assert_false(job->job.busy); /* The job is paused */
1bdc94
 
1bdc94
-    do_drain_end(drain_type, src);
1bdc94
+    do_drain_end_unlocked(drain_type, src);
1bdc94
+
1bdc94
+    if (use_iothread) {
1bdc94
+        /* paused is reset in the I/O thread, wait for it */
1bdc94
+        while (job->job.paused) {
1bdc94
+            aio_poll(qemu_get_aio_context(), false);
1bdc94
+        }
1bdc94
+    }
1bdc94
 
1bdc94
     g_assert_cmpint(job->job.pause_count, ==, 0);
1bdc94
     g_assert_false(job->job.paused);
1bdc94
@@ -841,32 +882,64 @@ static void test_blockjob_common(enum drain_type drain_type)
1bdc94
 
1bdc94
     do_drain_end(drain_type, target);
1bdc94
 
1bdc94
+    if (use_iothread) {
1bdc94
+        /* paused is reset in the I/O thread, wait for it */
1bdc94
+        while (job->job.paused) {
1bdc94
+            aio_poll(qemu_get_aio_context(), false);
1bdc94
+        }
1bdc94
+    }
1bdc94
+
1bdc94
     g_assert_cmpint(job->job.pause_count, ==, 0);
1bdc94
     g_assert_false(job->job.paused);
1bdc94
     g_assert_true(job->job.busy); /* We're in job_sleep_ns() */
1bdc94
 
1bdc94
+    aio_context_acquire(ctx);
1bdc94
     ret = job_complete_sync(&job->job, &error_abort);
1bdc94
     g_assert_cmpint(ret, ==, 0);
1bdc94
 
1bdc94
+    if (use_iothread) {
1bdc94
+        blk_set_aio_context(blk_src, qemu_get_aio_context());
1bdc94
+    }
1bdc94
+    aio_context_release(ctx);
1bdc94
+
1bdc94
     blk_unref(blk_src);
1bdc94
     blk_unref(blk_target);
1bdc94
     bdrv_unref(src);
1bdc94
     bdrv_unref(target);
1bdc94
+
1bdc94
+    if (iothread) {
1bdc94
+        iothread_join(iothread);
1bdc94
+    }
1bdc94
 }
1bdc94
 
1bdc94
 static void test_blockjob_drain_all(void)
1bdc94
 {
1bdc94
-    test_blockjob_common(BDRV_DRAIN_ALL);
1bdc94
+    test_blockjob_common(BDRV_DRAIN_ALL, false);
1bdc94
 }
1bdc94
 
1bdc94
 static void test_blockjob_drain(void)
1bdc94
 {
1bdc94
-    test_blockjob_common(BDRV_DRAIN);
1bdc94
+    test_blockjob_common(BDRV_DRAIN, false);
1bdc94
 }
1bdc94
 
1bdc94
 static void test_blockjob_drain_subtree(void)
1bdc94
 {
1bdc94
-    test_blockjob_common(BDRV_SUBTREE_DRAIN);
1bdc94
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, false);
1bdc94
+}
1bdc94
+
1bdc94
+static void test_blockjob_iothread_drain_all(void)
1bdc94
+{
1bdc94
+    test_blockjob_common(BDRV_DRAIN_ALL, true);
1bdc94
+}
1bdc94
+
1bdc94
+static void test_blockjob_iothread_drain(void)
1bdc94
+{
1bdc94
+    test_blockjob_common(BDRV_DRAIN, true);
1bdc94
+}
1bdc94
+
1bdc94
+static void test_blockjob_iothread_drain_subtree(void)
1bdc94
+{
1bdc94
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, true);
1bdc94
 }
1bdc94
 
1bdc94
 
1bdc94
@@ -1337,6 +1410,13 @@ int main(int argc, char **argv)
1bdc94
     g_test_add_func("/bdrv-drain/blockjob/drain_subtree",
1bdc94
                     test_blockjob_drain_subtree);
1bdc94
 
1bdc94
+    g_test_add_func("/bdrv-drain/blockjob/iothread/drain_all",
1bdc94
+                    test_blockjob_iothread_drain_all);
1bdc94
+    g_test_add_func("/bdrv-drain/blockjob/iothread/drain",
1bdc94
+                    test_blockjob_iothread_drain);
1bdc94
+    g_test_add_func("/bdrv-drain/blockjob/iothread/drain_subtree",
1bdc94
+                    test_blockjob_iothread_drain_subtree);
1bdc94
+
1bdc94
     g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain);
1bdc94
     g_test_add_func("/bdrv-drain/detach/drain_all", test_detach_by_drain_all);
1bdc94
     g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain);
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94