summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohn Snow2018-08-30 03:57:31 +0200
committerMax Reitz2018-08-31 16:28:33 +0200
commiteb23654dbe43b549ea2a9ebff9d8edf544d34a73 (patch)
tree4801dd246bf808450c131683b57fd50c1f8dbcaf /tests
parentblock/mirror: utilize job_exit shim (diff)
downloadqemu-eb23654dbe43b549ea2a9ebff9d8edf544d34a73.tar.gz
qemu-eb23654dbe43b549ea2a9ebff9d8edf544d34a73.tar.xz
qemu-eb23654dbe43b549ea2a9ebff9d8edf544d34a73.zip
jobs: utilize job_exit shim
Utilize the job_exit shim by not calling job_defer_to_main_loop, and where applicable, converting the deferred callback into the job_exit callback. This converts backup, stream, create, and the unit tests all at once. Most of these jobs do not see any changes to the order in which they clean up their resources, except the test-blockjob-txn test, which now puts down its bs before job_completed is called. This is safe for the same reason the reordering in the mirror job is safe, because job_completed no longer runs under two locks, making the unref safe even if it causes a flush. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-id: 20180830015734.19765-7-jsnow@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-bdrv-drain.c6
-rw-r--r--tests/test-blockjob-txn.c11
-rw-r--r--tests/test-blockjob.c10
3 files changed, 6 insertions, 21 deletions
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
index 6bda4451c1..89ac15e88a 100644
--- a/tests/test-bdrv-drain.c
+++ b/tests/test-bdrv-drain.c
@@ -752,11 +752,6 @@ typedef struct TestBlockJob {
bool should_complete;
} TestBlockJob;
-static void test_job_completed(Job *job, void *opaque)
-{
- job_completed(job, 0);
-}
-
static int coroutine_fn test_job_run(Job *job, Error **errp)
{
TestBlockJob *s = container_of(job, TestBlockJob, common.job);
@@ -770,7 +765,6 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
job_pause_point(&s->common.job);
}
- job_defer_to_main_loop(&s->common.job, test_job_completed, NULL);
return 0;
}
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
index 82cedee78b..ef29f35e44 100644
--- a/tests/test-blockjob-txn.c
+++ b/tests/test-blockjob-txn.c
@@ -24,17 +24,11 @@ typedef struct {
int *result;
} TestBlockJob;
-static void test_block_job_complete(Job *job, void *opaque)
+static void test_block_job_exit(Job *job)
{
BlockJob *bjob = container_of(job, BlockJob, job);
BlockDriverState *bs = blk_bs(bjob->blk);
- int rc = (intptr_t)opaque;
- if (job_is_cancelled(job)) {
- rc = -ECANCELED;
- }
-
- job_completed(job, rc);
bdrv_unref(bs);
}
@@ -54,8 +48,6 @@ static int coroutine_fn test_block_job_run(Job *job, Error **errp)
}
}
- job_defer_to_main_loop(job, test_block_job_complete,
- (void *)(intptr_t)s->rc);
return s->rc;
}
@@ -81,6 +73,7 @@ static const BlockJobDriver test_block_job_driver = {
.user_resume = block_job_user_resume,
.drain = block_job_drain,
.run = test_block_job_run,
+ .exit = test_block_job_exit,
},
};
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
index 408a226939..ad4a65bc78 100644
--- a/tests/test-blockjob.c
+++ b/tests/test-blockjob.c
@@ -163,11 +163,10 @@ typedef struct CancelJob {
bool completed;
} CancelJob;
-static void cancel_job_completed(Job *job, void *opaque)
+static void cancel_job_exit(Job *job)
{
- CancelJob *s = opaque;
+ CancelJob *s = container_of(job, CancelJob, common.job);
s->completed = true;
- job_completed(job, 0);
}
static void cancel_job_complete(Job *job, Error **errp)
@@ -182,7 +181,7 @@ static int coroutine_fn cancel_job_run(Job *job, Error **errp)
while (!s->should_complete) {
if (job_is_cancelled(&s->common.job)) {
- goto defer;
+ return 0;
}
if (!job_is_ready(&s->common.job) && s->should_converge) {
@@ -192,8 +191,6 @@ static int coroutine_fn cancel_job_run(Job *job, Error **errp)
job_sleep_ns(&s->common.job, 100000);
}
- defer:
- job_defer_to_main_loop(&s->common.job, cancel_job_completed, s);
return 0;
}
@@ -204,6 +201,7 @@ static const BlockJobDriver test_cancel_driver = {
.user_resume = block_job_user_resume,
.drain = block_job_drain,
.run = cancel_job_run,
+ .exit = cancel_job_exit,
.complete = cancel_job_complete,
},
};