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

1bdc94
From 36cd4342651561d7dda8bccc0520a35ca505c466 Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Fri, 21 Sep 2018 12:46:30 +0200
1bdc94
Subject: [PATCH 3/3] test-bdrv-drain: Test draining job source child and
1bdc94
 parent
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180921124630.29036-4-kwolf@redhat.com>
1bdc94
Patchwork-id: 82233
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 3/3] test-bdrv-drain: Test draining job source child and parent
1bdc94
Bugzilla: 1618584
1bdc94
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
1bdc94
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
1bdc94
RH-Acked-by: John Snow <jsnow@redhat.com>
1bdc94
1bdc94
For the block job drain test, don't only test draining the source and
1bdc94
the target node, but create a backing chain for the source
1bdc94
(source_backing <- source <- source_overlay) and test draining each of
1bdc94
the nodes in it.
1bdc94
1bdc94
When using iothreads, the source node (and therefore the job) is in a
1bdc94
different AioContext than the drain, which happens from the main
1bdc94
thread. This way, the main thread waits in AIO_WAIT_WHILE() for the
1bdc94
iothread to make process and aio_wait_kick() is required to notify it.
1bdc94
The test validates that calling bdrv_wakeup() for a child or a parent
1bdc94
node will actually notify AIO_WAIT_WHILE() instead of letting it hang.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 tests/test-bdrv-drain.c | 77 ++++++++++++++++++++++++++++++++++++++++++++-----
1bdc94
 1 file changed, 69 insertions(+), 8 deletions(-)
1bdc94
1bdc94
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
1bdc94
index 7e7ba9b..8641b54 100644
1bdc94
--- a/tests/test-bdrv-drain.c
1bdc94
+++ b/tests/test-bdrv-drain.c
1bdc94
@@ -786,6 +786,7 @@ typedef struct TestBlockJob {
1bdc94
     BlockJob common;
1bdc94
     int run_ret;
1bdc94
     int prepare_ret;
1bdc94
+    bool running;
1bdc94
     bool should_complete;
1bdc94
 } TestBlockJob;
1bdc94
 
1bdc94
@@ -818,12 +819,17 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
1bdc94
 {
1bdc94
     TestBlockJob *s = container_of(job, TestBlockJob, common.job);
1bdc94
 
1bdc94
+    /* We are running the actual job code past the pause point in
1bdc94
+     * job_co_entry(). */
1bdc94
+    s->running = true;
1bdc94
+
1bdc94
     job_transition_to_ready(&s->common.job);
1bdc94
     while (!s->should_complete) {
1bdc94
         /* Avoid job_sleep_ns() because it marks the job as !busy. We want to
1bdc94
          * emulate some actual activity (probably some I/O) here so that drain
1bdc94
          * has to wait for this activity to stop. */
1bdc94
-        qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000);
1bdc94
+        qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000);
1bdc94
+
1bdc94
         job_pause_point(&s->common.job);
1bdc94
     }
1bdc94
 
1bdc94
@@ -856,11 +862,19 @@ enum test_job_result {
1bdc94
     TEST_JOB_FAIL_PREPARE,
1bdc94
 };
1bdc94
 
1bdc94
-static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
1bdc94
-                                 enum test_job_result result)
1bdc94
+enum test_job_drain_node {
1bdc94
+    TEST_JOB_DRAIN_SRC,
1bdc94
+    TEST_JOB_DRAIN_SRC_CHILD,
1bdc94
+    TEST_JOB_DRAIN_SRC_PARENT,
1bdc94
+};
1bdc94
+
1bdc94
+static void test_blockjob_common_drain_node(enum drain_type drain_type,
1bdc94
+                                            bool use_iothread,
1bdc94
+                                            enum test_job_result result,
1bdc94
+                                            enum test_job_drain_node drain_node)
1bdc94
 {
1bdc94
     BlockBackend *blk_src, *blk_target;
1bdc94
-    BlockDriverState *src, *target;
1bdc94
+    BlockDriverState *src, *src_backing, *src_overlay, *target, *drain_bs;
1bdc94
     BlockJob *job;
1bdc94
     TestBlockJob *tjob;
1bdc94
     IOThread *iothread = NULL;
1bdc94
@@ -869,8 +883,32 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
1bdc94
 
1bdc94
     src = bdrv_new_open_driver(&bdrv_test, "source", BDRV_O_RDWR,
1bdc94
                                &error_abort);
1bdc94
+    src_backing = bdrv_new_open_driver(&bdrv_test, "source-backing",
1bdc94
+                                       BDRV_O_RDWR, &error_abort);
1bdc94
+    src_overlay = bdrv_new_open_driver(&bdrv_test, "source-overlay",
1bdc94
+                                       BDRV_O_RDWR, &error_abort);
1bdc94
+
1bdc94
+    bdrv_set_backing_hd(src_overlay, src, &error_abort);
1bdc94
+    bdrv_unref(src);
1bdc94
+    bdrv_set_backing_hd(src, src_backing, &error_abort);
1bdc94
+    bdrv_unref(src_backing);
1bdc94
+
1bdc94
     blk_src = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
1bdc94
-    blk_insert_bs(blk_src, src, &error_abort);
1bdc94
+    blk_insert_bs(blk_src, src_overlay, &error_abort);
1bdc94
+
1bdc94
+    switch (drain_node) {
1bdc94
+    case TEST_JOB_DRAIN_SRC:
1bdc94
+        drain_bs = src;
1bdc94
+        break;
1bdc94
+    case TEST_JOB_DRAIN_SRC_CHILD:
1bdc94
+        drain_bs = src_backing;
1bdc94
+        break;
1bdc94
+    case TEST_JOB_DRAIN_SRC_PARENT:
1bdc94
+        drain_bs = src_overlay;
1bdc94
+        break;
1bdc94
+    default:
1bdc94
+        g_assert_not_reached();
1bdc94
+    }
1bdc94
 
1bdc94
     if (use_iothread) {
1bdc94
         iothread = iothread_new();
1bdc94
@@ -906,11 +944,21 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
1bdc94
     job_start(&job->job);
1bdc94
     aio_context_release(ctx);
1bdc94
 
1bdc94
+    if (use_iothread) {
1bdc94
+        /* job_co_entry() is run in the I/O thread, wait for the actual job
1bdc94
+         * code to start (we don't want to catch the job in the pause point in
1bdc94
+         * job_co_entry(). */
1bdc94
+        while (!tjob->running) {
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(tjob->running);
1bdc94
     g_assert_true(job->job.busy); /* We're in qemu_co_sleep_ns() */
1bdc94
 
1bdc94
-    do_drain_begin_unlocked(drain_type, src);
1bdc94
+    do_drain_begin_unlocked(drain_type, drain_bs);
1bdc94
 
1bdc94
     if (drain_type == BDRV_DRAIN_ALL) {
1bdc94
         /* bdrv_drain_all() drains both src and target */
1bdc94
@@ -921,7 +969,7 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
1bdc94
     g_assert_true(job->job.paused);
1bdc94
     g_assert_false(job->job.busy); /* The job is paused */
1bdc94
 
1bdc94
-    do_drain_end_unlocked(drain_type, src);
1bdc94
+    do_drain_end_unlocked(drain_type, drain_bs);
1bdc94
 
1bdc94
     if (use_iothread) {
1bdc94
         /* paused is reset in the I/O thread, wait for it */
1bdc94
@@ -969,7 +1017,7 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
1bdc94
 
1bdc94
     blk_unref(blk_src);
1bdc94
     blk_unref(blk_target);
1bdc94
-    bdrv_unref(src);
1bdc94
+    bdrv_unref(src_overlay);
1bdc94
     bdrv_unref(target);
1bdc94
 
1bdc94
     if (iothread) {
1bdc94
@@ -977,6 +1025,19 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
1bdc94
     }
1bdc94
 }
1bdc94
 
1bdc94
+static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
1bdc94
+                                 enum test_job_result result)
1bdc94
+{
1bdc94
+    test_blockjob_common_drain_node(drain_type, use_iothread, result,
1bdc94
+                                    TEST_JOB_DRAIN_SRC);
1bdc94
+    test_blockjob_common_drain_node(drain_type, use_iothread, result,
1bdc94
+                                    TEST_JOB_DRAIN_SRC_CHILD);
1bdc94
+    if (drain_type == BDRV_SUBTREE_DRAIN) {
1bdc94
+        test_blockjob_common_drain_node(drain_type, use_iothread, result,
1bdc94
+                                        TEST_JOB_DRAIN_SRC_PARENT);
1bdc94
+    }
1bdc94
+}
1bdc94
+
1bdc94
 static void test_blockjob_drain_all(void)
1bdc94
 {
1bdc94
     test_blockjob_common(BDRV_DRAIN_ALL, false, TEST_JOB_SUCCESS);
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94