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

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