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