yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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