|
|
357786 |
From 2986609502d393267e97d2bb874427acef906a61 Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Date: Mon, 10 Sep 2018 18:17:44 +0200
|
|
|
357786 |
Subject: [PATCH 06/25] jobs: utilize job_exit shim
|
|
|
357786 |
|
|
|
357786 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Message-id: <20180910181803.11781-7-jsnow@redhat.com>
|
|
|
357786 |
Patchwork-id: 82106
|
|
|
357786 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 06/25] jobs: utilize job_exit shim
|
|
|
357786 |
Bugzilla: 1626061
|
|
|
357786 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
357786 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
Utilize the job_exit shim by not calling job_defer_to_main_loop, and
|
|
|
357786 |
where applicable, converting the deferred callback into the job_exit
|
|
|
357786 |
callback.
|
|
|
357786 |
|
|
|
357786 |
This converts backup, stream, create, and the unit tests all at once.
|
|
|
357786 |
Most of these jobs do not see any changes to the order in which they
|
|
|
357786 |
clean up their resources, except the test-blockjob-txn test, which
|
|
|
357786 |
now puts down its bs before job_completed is called.
|
|
|
357786 |
|
|
|
357786 |
This is safe for the same reason the reordering in the mirror job is
|
|
|
357786 |
safe, because job_completed no longer runs under two locks, making
|
|
|
357786 |
the unref safe even if it causes a flush.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Message-id: 20180830015734.19765-7-jsnow@redhat.com
|
|
|
357786 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
(cherry picked from commit eb23654dbe43b549ea2a9ebff9d8edf544d34a73)
|
|
|
357786 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
block/backup.c | 16 ----------------
|
|
|
357786 |
block/create.c | 14 +++-----------
|
|
|
357786 |
block/stream.c | 22 +++++++---------------
|
|
|
357786 |
tests/test-bdrv-drain.c | 6 ------
|
|
|
357786 |
tests/test-blockjob-txn.c | 11 ++---------
|
|
|
357786 |
tests/test-blockjob.c | 10 ++++------
|
|
|
357786 |
6 files changed, 16 insertions(+), 63 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/block/backup.c b/block/backup.c
|
|
|
357786 |
index a5bf699..08a5b74 100644
|
|
|
357786 |
--- a/block/backup.c
|
|
|
357786 |
+++ b/block/backup.c
|
|
|
357786 |
@@ -380,18 +380,6 @@ static BlockErrorAction backup_error_action(BackupBlockJob *job,
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-typedef struct {
|
|
|
357786 |
- int ret;
|
|
|
357786 |
-} BackupCompleteData;
|
|
|
357786 |
-
|
|
|
357786 |
-static void backup_complete(Job *job, void *opaque)
|
|
|
357786 |
-{
|
|
|
357786 |
- BackupCompleteData *data = opaque;
|
|
|
357786 |
-
|
|
|
357786 |
- job_completed(job, data->ret);
|
|
|
357786 |
- g_free(data);
|
|
|
357786 |
-}
|
|
|
357786 |
-
|
|
|
357786 |
static bool coroutine_fn yield_and_check(BackupBlockJob *job)
|
|
|
357786 |
{
|
|
|
357786 |
uint64_t delay_ns;
|
|
|
357786 |
@@ -483,7 +471,6 @@ static void backup_incremental_init_copy_bitmap(BackupBlockJob *job)
|
|
|
357786 |
static int coroutine_fn backup_run(Job *opaque_job, Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
BackupBlockJob *job = container_of(opaque_job, BackupBlockJob, common.job);
|
|
|
357786 |
- BackupCompleteData *data;
|
|
|
357786 |
BlockDriverState *bs = blk_bs(job->common.blk);
|
|
|
357786 |
int64_t offset, nb_clusters;
|
|
|
357786 |
int ret = 0;
|
|
|
357786 |
@@ -584,9 +571,6 @@ static int coroutine_fn backup_run(Job *opaque_job, Error **errp)
|
|
|
357786 |
qemu_co_rwlock_unlock(&job->flush_rwlock);
|
|
|
357786 |
hbitmap_free(job->copy_bitmap);
|
|
|
357786 |
|
|
|
357786 |
- data = g_malloc(sizeof(*data));
|
|
|
357786 |
- data->ret = ret;
|
|
|
357786 |
- job_defer_to_main_loop(&job->common.job, backup_complete, data);
|
|
|
357786 |
return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
diff --git a/block/create.c b/block/create.c
|
|
|
357786 |
index 26a385c..9534121 100644
|
|
|
357786 |
--- a/block/create.c
|
|
|
357786 |
+++ b/block/create.c
|
|
|
357786 |
@@ -34,28 +34,20 @@ typedef struct BlockdevCreateJob {
|
|
|
357786 |
Job common;
|
|
|
357786 |
BlockDriver *drv;
|
|
|
357786 |
BlockdevCreateOptions *opts;
|
|
|
357786 |
- int ret;
|
|
|
357786 |
} BlockdevCreateJob;
|
|
|
357786 |
|
|
|
357786 |
-static void blockdev_create_complete(Job *job, void *opaque)
|
|
|
357786 |
-{
|
|
|
357786 |
- BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);
|
|
|
357786 |
-
|
|
|
357786 |
- job_completed(job, s->ret);
|
|
|
357786 |
-}
|
|
|
357786 |
-
|
|
|
357786 |
static int coroutine_fn blockdev_create_run(Job *job, Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);
|
|
|
357786 |
+ int ret;
|
|
|
357786 |
|
|
|
357786 |
job_progress_set_remaining(&s->common, 1);
|
|
|
357786 |
- s->ret = s->drv->bdrv_co_create(s->opts, errp);
|
|
|
357786 |
+ ret = s->drv->bdrv_co_create(s->opts, errp);
|
|
|
357786 |
job_progress_update(&s->common, 1);
|
|
|
357786 |
|
|
|
357786 |
qapi_free_BlockdevCreateOptions(s->opts);
|
|
|
357786 |
- job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL);
|
|
|
357786 |
|
|
|
357786 |
- return s->ret;
|
|
|
357786 |
+ return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static const JobDriver blockdev_create_job_driver = {
|
|
|
357786 |
diff --git a/block/stream.c b/block/stream.c
|
|
|
357786 |
index 26a7753..67e1e72 100644
|
|
|
357786 |
--- a/block/stream.c
|
|
|
357786 |
+++ b/block/stream.c
|
|
|
357786 |
@@ -54,20 +54,16 @@ static int coroutine_fn stream_populate(BlockBackend *blk,
|
|
|
357786 |
return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_READ);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-typedef struct {
|
|
|
357786 |
- int ret;
|
|
|
357786 |
-} StreamCompleteData;
|
|
|
357786 |
-
|
|
|
357786 |
-static void stream_complete(Job *job, void *opaque)
|
|
|
357786 |
+static void stream_exit(Job *job)
|
|
|
357786 |
{
|
|
|
357786 |
StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
|
|
|
357786 |
BlockJob *bjob = &s->common;
|
|
|
357786 |
- StreamCompleteData *data = opaque;
|
|
|
357786 |
BlockDriverState *bs = blk_bs(bjob->blk);
|
|
|
357786 |
BlockDriverState *base = s->base;
|
|
|
357786 |
Error *local_err = NULL;
|
|
|
357786 |
+ int ret = job->ret;
|
|
|
357786 |
|
|
|
357786 |
- if (!job_is_cancelled(job) && bs->backing && data->ret == 0) {
|
|
|
357786 |
+ if (!job_is_cancelled(job) && bs->backing && ret == 0) {
|
|
|
357786 |
const char *base_id = NULL, *base_fmt = NULL;
|
|
|
357786 |
if (base) {
|
|
|
357786 |
base_id = s->backing_file_str;
|
|
|
357786 |
@@ -75,11 +71,11 @@ static void stream_complete(Job *job, void *opaque)
|
|
|
357786 |
base_fmt = base->drv->format_name;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
- data->ret = bdrv_change_backing_file(bs, base_id, base_fmt);
|
|
|
357786 |
+ ret = bdrv_change_backing_file(bs, base_id, base_fmt);
|
|
|
357786 |
bdrv_set_backing_hd(bs, base, &local_err);
|
|
|
357786 |
if (local_err) {
|
|
|
357786 |
error_report_err(local_err);
|
|
|
357786 |
- data->ret = -EPERM;
|
|
|
357786 |
+ ret = -EPERM;
|
|
|
357786 |
goto out;
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
@@ -93,14 +89,12 @@ out:
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
g_free(s->backing_file_str);
|
|
|
357786 |
- job_completed(job, data->ret);
|
|
|
357786 |
- g_free(data);
|
|
|
357786 |
+ job->ret = ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static int coroutine_fn stream_run(Job *job, Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
StreamBlockJob *s = container_of(job, StreamBlockJob, common.job);
|
|
|
357786 |
- StreamCompleteData *data;
|
|
|
357786 |
BlockBackend *blk = s->common.blk;
|
|
|
357786 |
BlockDriverState *bs = blk_bs(blk);
|
|
|
357786 |
BlockDriverState *base = s->base;
|
|
|
357786 |
@@ -203,9 +197,6 @@ static int coroutine_fn stream_run(Job *job, Error **errp)
|
|
|
357786 |
|
|
|
357786 |
out:
|
|
|
357786 |
/* Modify backing chain and close BDSes in main loop */
|
|
|
357786 |
- data = g_malloc(sizeof(*data));
|
|
|
357786 |
- data->ret = ret;
|
|
|
357786 |
- job_defer_to_main_loop(&s->common.job, stream_complete, data);
|
|
|
357786 |
return ret;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -215,6 +206,7 @@ static const BlockJobDriver stream_job_driver = {
|
|
|
357786 |
.job_type = JOB_TYPE_STREAM,
|
|
|
357786 |
.free = block_job_free,
|
|
|
357786 |
.run = stream_run,
|
|
|
357786 |
+ .exit = stream_exit,
|
|
|
357786 |
.user_resume = block_job_user_resume,
|
|
|
357786 |
.drain = block_job_drain,
|
|
|
357786 |
},
|
|
|
357786 |
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
|
|
|
357786 |
index 8937894..403446e 100644
|
|
|
357786 |
--- a/tests/test-bdrv-drain.c
|
|
|
357786 |
+++ b/tests/test-bdrv-drain.c
|
|
|
357786 |
@@ -496,11 +496,6 @@ typedef struct TestBlockJob {
|
|
|
357786 |
bool should_complete;
|
|
|
357786 |
} TestBlockJob;
|
|
|
357786 |
|
|
|
357786 |
-static void test_job_completed(Job *job, void *opaque)
|
|
|
357786 |
-{
|
|
|
357786 |
- job_completed(job, 0);
|
|
|
357786 |
-}
|
|
|
357786 |
-
|
|
|
357786 |
static int coroutine_fn test_job_run(Job *job, Error **errp)
|
|
|
357786 |
{
|
|
|
357786 |
TestBlockJob *s = container_of(job, TestBlockJob, common.job);
|
|
|
357786 |
@@ -510,7 +505,6 @@ static int coroutine_fn test_job_run(Job *job, Error **errp)
|
|
|
357786 |
job_sleep_ns(&s->common.job, 100000);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- job_defer_to_main_loop(&s->common.job, test_job_completed, NULL);
|
|
|
357786 |
return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
|
|
|
357786 |
index 82cedee..ef29f35 100644
|
|
|
357786 |
--- a/tests/test-blockjob-txn.c
|
|
|
357786 |
+++ b/tests/test-blockjob-txn.c
|
|
|
357786 |
@@ -24,17 +24,11 @@ typedef struct {
|
|
|
357786 |
int *result;
|
|
|
357786 |
} TestBlockJob;
|
|
|
357786 |
|
|
|
357786 |
-static void test_block_job_complete(Job *job, void *opaque)
|
|
|
357786 |
+static void test_block_job_exit(Job *job)
|
|
|
357786 |
{
|
|
|
357786 |
BlockJob *bjob = container_of(job, BlockJob, job);
|
|
|
357786 |
BlockDriverState *bs = blk_bs(bjob->blk);
|
|
|
357786 |
- int rc = (intptr_t)opaque;
|
|
|
357786 |
|
|
|
357786 |
- if (job_is_cancelled(job)) {
|
|
|
357786 |
- rc = -ECANCELED;
|
|
|
357786 |
- }
|
|
|
357786 |
-
|
|
|
357786 |
- job_completed(job, rc);
|
|
|
357786 |
bdrv_unref(bs);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -54,8 +48,6 @@ static int coroutine_fn test_block_job_run(Job *job, Error **errp)
|
|
|
357786 |
}
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- job_defer_to_main_loop(job, test_block_job_complete,
|
|
|
357786 |
- (void *)(intptr_t)s->rc);
|
|
|
357786 |
return s->rc;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -81,6 +73,7 @@ static const BlockJobDriver test_block_job_driver = {
|
|
|
357786 |
.user_resume = block_job_user_resume,
|
|
|
357786 |
.drain = block_job_drain,
|
|
|
357786 |
.run = test_block_job_run,
|
|
|
357786 |
+ .exit = test_block_job_exit,
|
|
|
357786 |
},
|
|
|
357786 |
};
|
|
|
357786 |
|
|
|
357786 |
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
|
|
|
357786 |
index 408a226..ad4a65b 100644
|
|
|
357786 |
--- a/tests/test-blockjob.c
|
|
|
357786 |
+++ b/tests/test-blockjob.c
|
|
|
357786 |
@@ -163,11 +163,10 @@ typedef struct CancelJob {
|
|
|
357786 |
bool completed;
|
|
|
357786 |
} CancelJob;
|
|
|
357786 |
|
|
|
357786 |
-static void cancel_job_completed(Job *job, void *opaque)
|
|
|
357786 |
+static void cancel_job_exit(Job *job)
|
|
|
357786 |
{
|
|
|
357786 |
- CancelJob *s = opaque;
|
|
|
357786 |
+ CancelJob *s = container_of(job, CancelJob, common.job);
|
|
|
357786 |
s->completed = true;
|
|
|
357786 |
- job_completed(job, 0);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
static void cancel_job_complete(Job *job, Error **errp)
|
|
|
357786 |
@@ -182,7 +181,7 @@ static int coroutine_fn cancel_job_run(Job *job, Error **errp)
|
|
|
357786 |
|
|
|
357786 |
while (!s->should_complete) {
|
|
|
357786 |
if (job_is_cancelled(&s->common.job)) {
|
|
|
357786 |
- goto defer;
|
|
|
357786 |
+ return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
if (!job_is_ready(&s->common.job) && s->should_converge) {
|
|
|
357786 |
@@ -192,8 +191,6 @@ static int coroutine_fn cancel_job_run(Job *job, Error **errp)
|
|
|
357786 |
job_sleep_ns(&s->common.job, 100000);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- defer:
|
|
|
357786 |
- job_defer_to_main_loop(&s->common.job, cancel_job_completed, s);
|
|
|
357786 |
return 0;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
@@ -204,6 +201,7 @@ static const BlockJobDriver test_cancel_driver = {
|
|
|
357786 |
.user_resume = block_job_user_resume,
|
|
|
357786 |
.drain = block_job_drain,
|
|
|
357786 |
.run = cancel_job_run,
|
|
|
357786 |
+ .exit = cancel_job_exit,
|
|
|
357786 |
.complete = cancel_job_complete,
|
|
|
357786 |
},
|
|
|
357786 |
};
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|