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