Blame SOURCES/kvm-test-bdrv-drain-AIO_WAIT_WHILE-in-job-.commit-.abort.patch

357786
From 1b85fbf7ed7119dac8bc0fedfb019d0ce991d07d Mon Sep 17 00:00:00 2001
357786
From: Kevin Wolf <kwolf@redhat.com>
357786
Date: Fri, 14 Sep 2018 10:55:40 +0200
357786
Subject: [PATCH 49/49] test-bdrv-drain: AIO_WAIT_WHILE() in job .commit/.abort
357786
357786
RH-Author: Kevin Wolf <kwolf@redhat.com>
357786
Message-id: <20180914105540.18077-43-kwolf@redhat.com>
357786
Patchwork-id: 82193
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 42/42] test-bdrv-drain: AIO_WAIT_WHILE() in job .commit/.abort
357786
Bugzilla: 1601212
357786
RH-Acked-by: John Snow <jsnow@redhat.com>
357786
RH-Acked-by: Max Reitz <mreitz@redhat.com>
357786
RH-Acked-by: Fam Zheng <famz@redhat.com>
357786
357786
This adds tests for calling AIO_WAIT_WHILE() in the .commit and .abort
357786
callbacks. Both reasons why .abort could be called for a single job are
357786
tested: Either .run or .prepare could return an error.
357786
357786
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
357786
Reviewed-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 tests/test-bdrv-drain.c | 116 +++++++++++++++++++++++++++++++++++++++++++-----
357786
 1 file changed, 104 insertions(+), 12 deletions(-)
357786
357786
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
357786
index f4b57f7..d6202b2 100644
357786
--- a/tests/test-bdrv-drain.c
357786
+++ b/tests/test-bdrv-drain.c
357786
@@ -784,6 +784,8 @@ static void test_iothread_drain_subtree(void)
357786
 
357786
 typedef struct TestBlockJob {
357786
     BlockJob common;
357786
+    int run_ret;
357786
+    int prepare_ret;
357786
     bool should_complete;
357786
 } TestBlockJob;
357786
 
357786
@@ -793,7 +795,23 @@ static int test_job_prepare(Job *job)
357786
 
357786
     /* Provoke an AIO_WAIT_WHILE() call to verify there is no deadlock */
357786
     blk_flush(s->common.blk);
357786
-    return 0;
357786
+    return s->prepare_ret;
357786
+}
357786
+
357786
+static void test_job_commit(Job *job)
357786
+{
357786
+    TestBlockJob *s = container_of(job, TestBlockJob, common.job);
357786
+
357786
+    /* Provoke an AIO_WAIT_WHILE() call to verify there is no deadlock */
357786
+    blk_flush(s->common.blk);
357786
+}
357786
+
357786
+static void test_job_abort(Job *job)
357786
+{
357786
+    TestBlockJob *s = container_of(job, TestBlockJob, common.job);
357786
+
357786
+    /* Provoke an AIO_WAIT_WHILE() call to verify there is no deadlock */
357786
+    blk_flush(s->common.blk);
357786
 }
357786
 
357786
 static int coroutine_fn test_job_run(Job *job, Error **errp)
357786
@@ -809,7 +827,7 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
357786
         job_pause_point(&s->common.job);
357786
     }
357786
 
357786
-    return 0;
357786
+    return s->run_ret;
357786
 }
357786
 
357786
 static void test_job_complete(Job *job, Error **errp)
357786
@@ -827,14 +845,24 @@ BlockJobDriver test_job_driver = {
357786
         .run            = test_job_run,
357786
         .complete       = test_job_complete,
357786
         .prepare        = test_job_prepare,
357786
+        .commit         = test_job_commit,
357786
+        .abort          = test_job_abort,
357786
     },
357786
 };
357786
 
357786
-static void test_blockjob_common(enum drain_type drain_type, bool use_iothread)
357786
+enum test_job_result {
357786
+    TEST_JOB_SUCCESS,
357786
+    TEST_JOB_FAIL_RUN,
357786
+    TEST_JOB_FAIL_PREPARE,
357786
+};
357786
+
357786
+static void test_blockjob_common(enum drain_type drain_type, bool use_iothread,
357786
+                                 enum test_job_result result)
357786
 {
357786
     BlockBackend *blk_src, *blk_target;
357786
     BlockDriverState *src, *target;
357786
     BlockJob *job;
357786
+    TestBlockJob *tjob;
357786
     IOThread *iothread = NULL;
357786
     AioContext *ctx;
357786
     int ret;
357786
@@ -858,9 +886,23 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread)
357786
     blk_insert_bs(blk_target, target, &error_abort);
357786
 
357786
     aio_context_acquire(ctx);
357786
-    job = block_job_create("job0", &test_job_driver, NULL, src, 0, BLK_PERM_ALL,
357786
-                           0, 0, NULL, NULL, &error_abort);
357786
+    tjob = block_job_create("job0", &test_job_driver, NULL, src,
357786
+                            0, BLK_PERM_ALL,
357786
+                            0, 0, NULL, NULL, &error_abort);
357786
+    job = &tjob->common;
357786
     block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abort);
357786
+
357786
+    switch (result) {
357786
+    case TEST_JOB_SUCCESS:
357786
+        break;
357786
+    case TEST_JOB_FAIL_RUN:
357786
+        tjob->run_ret = -EIO;
357786
+        break;
357786
+    case TEST_JOB_FAIL_PREPARE:
357786
+        tjob->prepare_ret = -EIO;
357786
+        break;
357786
+    }
357786
+
357786
     job_start(&job->job);
357786
     aio_context_release(ctx);
357786
 
357786
@@ -918,7 +960,7 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread)
357786
 
357786
     aio_context_acquire(ctx);
357786
     ret = job_complete_sync(&job->job, &error_abort);
357786
-    g_assert_cmpint(ret, ==, 0);
357786
+    g_assert_cmpint(ret, ==, (result == TEST_JOB_SUCCESS ? 0 : -EIO));
357786
 
357786
     if (use_iothread) {
357786
         blk_set_aio_context(blk_src, qemu_get_aio_context());
357786
@@ -937,32 +979,68 @@ static void test_blockjob_common(enum drain_type drain_type, bool use_iothread)
357786
 
357786
 static void test_blockjob_drain_all(void)
357786
 {
357786
-    test_blockjob_common(BDRV_DRAIN_ALL, false);
357786
+    test_blockjob_common(BDRV_DRAIN_ALL, false, TEST_JOB_SUCCESS);
357786
 }
357786
 
357786
 static void test_blockjob_drain(void)
357786
 {
357786
-    test_blockjob_common(BDRV_DRAIN, false);
357786
+    test_blockjob_common(BDRV_DRAIN, false, TEST_JOB_SUCCESS);
357786
 }
357786
 
357786
 static void test_blockjob_drain_subtree(void)
357786
 {
357786
-    test_blockjob_common(BDRV_SUBTREE_DRAIN, false);
357786
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, false, TEST_JOB_SUCCESS);
357786
+}
357786
+
357786
+static void test_blockjob_error_drain_all(void)
357786
+{
357786
+    test_blockjob_common(BDRV_DRAIN_ALL, false, TEST_JOB_FAIL_RUN);
357786
+    test_blockjob_common(BDRV_DRAIN_ALL, false, TEST_JOB_FAIL_PREPARE);
357786
+}
357786
+
357786
+static void test_blockjob_error_drain(void)
357786
+{
357786
+    test_blockjob_common(BDRV_DRAIN, false, TEST_JOB_FAIL_RUN);
357786
+    test_blockjob_common(BDRV_DRAIN, false, TEST_JOB_FAIL_PREPARE);
357786
+}
357786
+
357786
+static void test_blockjob_error_drain_subtree(void)
357786
+{
357786
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, false, TEST_JOB_FAIL_RUN);
357786
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, false, TEST_JOB_FAIL_PREPARE);
357786
 }
357786
 
357786
 static void test_blockjob_iothread_drain_all(void)
357786
 {
357786
-    test_blockjob_common(BDRV_DRAIN_ALL, true);
357786
+    test_blockjob_common(BDRV_DRAIN_ALL, true, TEST_JOB_SUCCESS);
357786
 }
357786
 
357786
 static void test_blockjob_iothread_drain(void)
357786
 {
357786
-    test_blockjob_common(BDRV_DRAIN, true);
357786
+    test_blockjob_common(BDRV_DRAIN, true, TEST_JOB_SUCCESS);
357786
 }
357786
 
357786
 static void test_blockjob_iothread_drain_subtree(void)
357786
 {
357786
-    test_blockjob_common(BDRV_SUBTREE_DRAIN, true);
357786
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, true, TEST_JOB_SUCCESS);
357786
+}
357786
+
357786
+static void test_blockjob_iothread_error_drain_all(void)
357786
+{
357786
+    test_blockjob_common(BDRV_DRAIN_ALL, true, TEST_JOB_FAIL_RUN);
357786
+    test_blockjob_common(BDRV_DRAIN_ALL, true, TEST_JOB_FAIL_PREPARE);
357786
+}
357786
+
357786
+static void test_blockjob_iothread_error_drain(void)
357786
+{
357786
+    test_blockjob_common(BDRV_DRAIN, true, TEST_JOB_FAIL_RUN);
357786
+    test_blockjob_common(BDRV_DRAIN, true, TEST_JOB_FAIL_PREPARE);
357786
+}
357786
+
357786
+static void test_blockjob_iothread_error_drain_subtree(void)
357786
+{
357786
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, true, TEST_JOB_FAIL_RUN);
357786
+    test_blockjob_common(BDRV_SUBTREE_DRAIN, true, TEST_JOB_FAIL_PREPARE);
357786
 }
357786
 
357786
 
357786
@@ -1433,6 +1511,13 @@ int main(int argc, char **argv)
357786
     g_test_add_func("/bdrv-drain/blockjob/drain_subtree",
357786
                     test_blockjob_drain_subtree);
357786
 
357786
+    g_test_add_func("/bdrv-drain/blockjob/error/drain_all",
357786
+                    test_blockjob_error_drain_all);
357786
+    g_test_add_func("/bdrv-drain/blockjob/error/drain",
357786
+                    test_blockjob_error_drain);
357786
+    g_test_add_func("/bdrv-drain/blockjob/error/drain_subtree",
357786
+                    test_blockjob_error_drain_subtree);
357786
+
357786
     g_test_add_func("/bdrv-drain/blockjob/iothread/drain_all",
357786
                     test_blockjob_iothread_drain_all);
357786
     g_test_add_func("/bdrv-drain/blockjob/iothread/drain",
357786
@@ -1440,6 +1525,13 @@ int main(int argc, char **argv)
357786
     g_test_add_func("/bdrv-drain/blockjob/iothread/drain_subtree",
357786
                     test_blockjob_iothread_drain_subtree);
357786
 
357786
+    g_test_add_func("/bdrv-drain/blockjob/iothread/error/drain_all",
357786
+                    test_blockjob_iothread_error_drain_all);
357786
+    g_test_add_func("/bdrv-drain/blockjob/iothread/error/drain",
357786
+                    test_blockjob_iothread_error_drain);
357786
+    g_test_add_func("/bdrv-drain/blockjob/iothread/error/drain_subtree",
357786
+                    test_blockjob_iothread_error_drain_subtree);
357786
+
357786
     g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain);
357786
     g_test_add_func("/bdrv-drain/detach/drain_all", test_detach_by_drain_all);
357786
     g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain);
357786
-- 
357786
1.8.3.1
357786