Blame SOURCES/kvm-test-bdrv-drain-Test-draining-job-source-child-and-p.patch

26ba25
From f90f3f9a94cb09c3d568fbc9dc338b5f8c5ea17c Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Wed, 10 Oct 2018 20:22:13 +0100
26ba25
Subject: [PATCH 47/49] test-bdrv-drain: Test draining job source child and
26ba25
 parent
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181010202213.7372-35-kwolf@redhat.com>
26ba25
Patchwork-id: 82624
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 44/44] test-bdrv-drain: Test draining job source child and parent
26ba25
Bugzilla: 1637976
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Thomas Huth <thuth@redhat.com>
26ba25
26ba25
For the block job drain test, don't only test draining the source and
26ba25
the target node, but create a backing chain for the source
26ba25
(source_backing <- source <- source_overlay) and test draining each of
26ba25
the nodes in it.
26ba25
26ba25
When using iothreads, the source node (and therefore the job) is in a
26ba25
different AioContext than the drain, which happens from the main
26ba25
thread. This way, the main thread waits in AIO_WAIT_WHILE() for the
26ba25
iothread to make process and aio_wait_kick() is required to notify it.
26ba25
The test validates that calling bdrv_wakeup() for a child or a parent
26ba25
node will actually notify AIO_WAIT_WHILE() instead of letting it hang.
26ba25
26ba25
Increase the sleep time a bit (to 1 ms) because the test case is racy
26ba25
and with the shorter sleep, it didn't reproduce the bug it is supposed
26ba25
to test for me under 'rr record -n'.
26ba25
26ba25
This was because bdrv_drain_invoke_entry() (in the main thread) was only
26ba25
called after the job had already reached the pause point, so we got a
26ba25
bdrv_dec_in_flight() from the main thread and the additional
26ba25
aio_wait_kick() when the job becomes idle (that we really wanted to test
26ba25
here) wasn't even necessary any more to make progress.
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Reviewed-by: Eric Blake <eblake@redhat.com>
26ba25
Reviewed-by: Max Reitz <mreitz@redhat.com>
26ba25
(cherry picked from commit d8b3afd597d54e496809b05ac39ac29a5799664f)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 tests/test-bdrv-drain.c | 77 ++++++++++++++++++++++++++++++++++++++++++++-----
26ba25
 1 file changed, 69 insertions(+), 8 deletions(-)
26ba25
26ba25
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
26ba25
index 7e7ba9b..8641b54 100644
26ba25
--- a/tests/test-bdrv-drain.c
26ba25
+++ b/tests/test-bdrv-drain.c
26ba25
@@ -786,6 +786,7 @@ typedef struct TestBlockJob {
26ba25
     BlockJob common;
26ba25
     int run_ret;
26ba25
     int prepare_ret;
26ba25
+    bool running;
26ba25
     bool should_complete;
26ba25
 } TestBlockJob;
26ba25
 
26ba25
@@ -818,12 +819,17 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
26ba25
 {
26ba25
     TestBlockJob *s = container_of(job, TestBlockJob, common.job);
26ba25
 
26ba25
+    /* We are running the actual job code past the pause point in
26ba25
+     * job_co_entry(). */
26ba25
+    s->running = true;
26ba25
+
26ba25
     job_transition_to_ready(&s->common.job);
26ba25
     while (!s->should_complete) {
26ba25
         /* Avoid job_sleep_ns() because it marks the job as !busy. We want to
26ba25
          * emulate some actual activity (probably some I/O) here so that drain
26ba25
          * has to wait for this activity to stop. */
26ba25
-        qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000);
26ba25
+        qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000);
26ba25
+
26ba25
         job_pause_point(&s->common.job);
26ba25
     }
26ba25
 
26ba25
@@ -856,11 +862,19 @@ enum test_job_result {
26ba25
     TEST_JOB_FAIL_PREPARE,
26ba25
 };
26ba25
 
26ba25
-static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
26ba25
-                                 enum test_job_result result)
26ba25
+enum test_job_drain_node {
26ba25
+    TEST_JOB_DRAIN_SRC,
26ba25
+    TEST_JOB_DRAIN_SRC_CHILD,
26ba25
+    TEST_JOB_DRAIN_SRC_PARENT,
26ba25
+};
26ba25
+
26ba25
+static void test_blockjob_common_drain_node(enum drain_type drain_type,
26ba25
+                                            bool use_iothread,
26ba25
+                                            enum test_job_result result,
26ba25
+                                            enum test_job_drain_node drain_node)
26ba25
 {
26ba25
     BlockBackend *blk_src, *blk_target;
26ba25
-    BlockDriverState *src, *target;
26ba25
+    BlockDriverState *src, *src_backing, *src_overlay, *target, *drain_bs;
26ba25
     BlockJob *job;
26ba25
     TestBlockJob *tjob;
26ba25
     IOThread *iothread = NULL;
26ba25
@@ -869,8 +883,32 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
26ba25
 
26ba25
     src = bdrv_new_open_driver(&bdrv_test, "source", BDRV_O_RDWR,
26ba25
                                &error_abort);
26ba25
+    src_backing = bdrv_new_open_driver(&bdrv_test, "source-backing",
26ba25
+                                       BDRV_O_RDWR, &error_abort);
26ba25
+    src_overlay = bdrv_new_open_driver(&bdrv_test, "source-overlay",
26ba25
+                                       BDRV_O_RDWR, &error_abort);
26ba25
+
26ba25
+    bdrv_set_backing_hd(src_overlay, src, &error_abort);
26ba25
+    bdrv_unref(src);
26ba25
+    bdrv_set_backing_hd(src, src_backing, &error_abort);
26ba25
+    bdrv_unref(src_backing);
26ba25
+
26ba25
     blk_src = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
26ba25
-    blk_insert_bs(blk_src, src, &error_abort);
26ba25
+    blk_insert_bs(blk_src, src_overlay, &error_abort);
26ba25
+
26ba25
+    switch (drain_node) {
26ba25
+    case TEST_JOB_DRAIN_SRC:
26ba25
+        drain_bs = src;
26ba25
+        break;
26ba25
+    case TEST_JOB_DRAIN_SRC_CHILD:
26ba25
+        drain_bs = src_backing;
26ba25
+        break;
26ba25
+    case TEST_JOB_DRAIN_SRC_PARENT:
26ba25
+        drain_bs = src_overlay;
26ba25
+        break;
26ba25
+    default:
26ba25
+        g_assert_not_reached();
26ba25
+    }
26ba25
 
26ba25
     if (use_iothread) {
26ba25
         iothread = iothread_new();
26ba25
@@ -906,11 +944,21 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
26ba25
     job_start(&job->job);
26ba25
     aio_context_release(ctx);
26ba25
 
26ba25
+    if (use_iothread) {
26ba25
+        /* job_co_entry() is run in the I/O thread, wait for the actual job
26ba25
+         * code to start (we don't want to catch the job in the pause point in
26ba25
+         * job_co_entry(). */
26ba25
+        while (!tjob->running) {
26ba25
+            aio_poll(qemu_get_aio_context(), false);
26ba25
+        }
26ba25
+    }
26ba25
+
26ba25
     g_assert_cmpint(job->job.pause_count, ==, 0);
26ba25
     g_assert_false(job->job.paused);
26ba25
+    g_assert_true(tjob->running);
26ba25
     g_assert_true(job->job.busy); /* We're in qemu_co_sleep_ns() */
26ba25
 
26ba25
-    do_drain_begin_unlocked(drain_type, src);
26ba25
+    do_drain_begin_unlocked(drain_type, drain_bs);
26ba25
 
26ba25
     if (drain_type == BDRV_DRAIN_ALL) {
26ba25
         /* bdrv_drain_all() drains both src and target */
26ba25
@@ -921,7 +969,7 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
26ba25
     g_assert_true(job->job.paused);
26ba25
     g_assert_false(job->job.busy); /* The job is paused */
26ba25
 
26ba25
-    do_drain_end_unlocked(drain_type, src);
26ba25
+    do_drain_end_unlocked(drain_type, drain_bs);
26ba25
 
26ba25
     if (use_iothread) {
26ba25
         /* paused is reset in the I/O thread, wait for it */
26ba25
@@ -969,7 +1017,7 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
26ba25
 
26ba25
     blk_unref(blk_src);
26ba25
     blk_unref(blk_target);
26ba25
-    bdrv_unref(src);
26ba25
+    bdrv_unref(src_overlay);
26ba25
     bdrv_unref(target);
26ba25
 
26ba25
     if (iothread) {
26ba25
@@ -977,6 +1025,19 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
26ba25
     }
26ba25
 }
26ba25
 
26ba25
+static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
26ba25
+                                 enum test_job_result result)
26ba25
+{
26ba25
+    test_blockjob_common_drain_node(drain_type, use_iothread, result,
26ba25
+                                    TEST_JOB_DRAIN_SRC);
26ba25
+    test_blockjob_common_drain_node(drain_type, use_iothread, result,
26ba25
+                                    TEST_JOB_DRAIN_SRC_CHILD);
26ba25
+    if (drain_type == BDRV_SUBTREE_DRAIN) {
26ba25
+        test_blockjob_common_drain_node(drain_type, use_iothread, result,
26ba25
+                                        TEST_JOB_DRAIN_SRC_PARENT);
26ba25
+    }
26ba25
+}
26ba25
+
26ba25
 static void test_blockjob_drain_all(void)
26ba25
 {
26ba25
     test_blockjob_common(BDRV_DRAIN_ALL, false, TEST_JOB_SUCCESS);
26ba25
-- 
26ba25
1.8.3.1
26ba25