|
|
383d26 |
From dcfc2f6514b672e68b62effbbc04c88ca16ac89a Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
Date: Tue, 26 Jun 2018 09:48:19 +0200
|
|
|
383d26 |
Subject: [PATCH 50/89] job: Move .complete callback to Job
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
Message-id: <20180626094856.6924-37-kwolf@redhat.com>
|
|
|
383d26 |
Patchwork-id: 81084
|
|
|
383d26 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 36/73] job: Move .complete callback to Job
|
|
|
383d26 |
Bugzilla: 1513543
|
|
|
383d26 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
This moves the .complete callback that tells a READY job to complete
|
|
|
383d26 |
from BlockJobDriver to JobDriver. The wrapper function job_complete()
|
|
|
383d26 |
doesn't require anything block job specific any more and can be moved
|
|
|
383d26 |
to Job.
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
(cherry picked from commit 3453d97243c72988c89a0105fa9546890eae7bd4)
|
|
|
383d26 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
---
|
|
|
383d26 |
block/mirror.c | 10 +++++-----
|
|
|
383d26 |
blockdev.c | 2 +-
|
|
|
383d26 |
blockjob.c | 23 +++++------------------
|
|
|
383d26 |
include/block/blockjob.h | 10 ----------
|
|
|
383d26 |
include/block/blockjob_int.h | 6 ------
|
|
|
383d26 |
include/qemu/job.h | 8 ++++++++
|
|
|
383d26 |
job.c | 16 ++++++++++++++++
|
|
|
383d26 |
tests/test-bdrv-drain.c | 6 +++---
|
|
|
383d26 |
tests/test-blockjob.c | 10 +++++-----
|
|
|
383d26 |
9 files changed, 43 insertions(+), 48 deletions(-)
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/block/mirror.c b/block/mirror.c
|
|
|
383d26 |
index a579bd8..656237a 100644
|
|
|
383d26 |
--- a/block/mirror.c
|
|
|
383d26 |
+++ b/block/mirror.c
|
|
|
383d26 |
@@ -905,16 +905,16 @@ immediate_exit:
|
|
|
383d26 |
job_defer_to_main_loop(&s->common.job, mirror_exit, data);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
-static void mirror_complete(BlockJob *job, Error **errp)
|
|
|
383d26 |
+static void mirror_complete(Job *job, Error **errp)
|
|
|
383d26 |
{
|
|
|
383d26 |
- MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
|
|
|
383d26 |
+ MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
|
|
|
383d26 |
BlockDriverState *target;
|
|
|
383d26 |
|
|
|
383d26 |
target = blk_bs(s->target);
|
|
|
383d26 |
|
|
|
383d26 |
if (!s->synced) {
|
|
|
383d26 |
error_setg(errp, "The active block job '%s' cannot be completed",
|
|
|
383d26 |
- job->job.id);
|
|
|
383d26 |
+ job->id);
|
|
|
383d26 |
return;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
@@ -995,8 +995,8 @@ static const BlockJobDriver mirror_job_driver = {
|
|
|
383d26 |
.drain = block_job_drain,
|
|
|
383d26 |
.start = mirror_run,
|
|
|
383d26 |
.pause = mirror_pause,
|
|
|
383d26 |
+ .complete = mirror_complete,
|
|
|
383d26 |
},
|
|
|
383d26 |
- .complete = mirror_complete,
|
|
|
383d26 |
.attached_aio_context = mirror_attached_aio_context,
|
|
|
383d26 |
.drain = mirror_drain,
|
|
|
383d26 |
};
|
|
|
383d26 |
@@ -1010,8 +1010,8 @@ static const BlockJobDriver commit_active_job_driver = {
|
|
|
383d26 |
.drain = block_job_drain,
|
|
|
383d26 |
.start = mirror_run,
|
|
|
383d26 |
.pause = mirror_pause,
|
|
|
383d26 |
+ .complete = mirror_complete,
|
|
|
383d26 |
},
|
|
|
383d26 |
- .complete = mirror_complete,
|
|
|
383d26 |
.attached_aio_context = mirror_attached_aio_context,
|
|
|
383d26 |
.drain = mirror_drain,
|
|
|
383d26 |
};
|
|
|
383d26 |
diff --git a/blockdev.c b/blockdev.c
|
|
|
383d26 |
index 89df7d9..c2b2be1 100644
|
|
|
383d26 |
--- a/blockdev.c
|
|
|
383d26 |
+++ b/blockdev.c
|
|
|
383d26 |
@@ -3941,7 +3941,7 @@ void qmp_block_job_complete(const char *device, Error **errp)
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
trace_qmp_block_job_complete(job);
|
|
|
383d26 |
- block_job_complete(job, errp);
|
|
|
383d26 |
+ job_complete(&job->job, errp);
|
|
|
383d26 |
aio_context_release(aio_context);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/blockjob.c b/blockjob.c
|
|
|
383d26 |
index 63e1669..0ca7672 100644
|
|
|
383d26 |
--- a/blockjob.c
|
|
|
383d26 |
+++ b/blockjob.c
|
|
|
383d26 |
@@ -481,24 +481,6 @@ int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n)
|
|
|
383d26 |
return ratelimit_calculate_delay(&job->limit, n);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
-void block_job_complete(BlockJob *job, Error **errp)
|
|
|
383d26 |
-{
|
|
|
383d26 |
- /* Should not be reachable via external interface for internal jobs */
|
|
|
383d26 |
- assert(job->job.id);
|
|
|
383d26 |
- if (job_apply_verb(&job->job, JOB_VERB_COMPLETE, errp)) {
|
|
|
383d26 |
- return;
|
|
|
383d26 |
- }
|
|
|
383d26 |
- if (job->job.pause_count || job_is_cancelled(&job->job) ||
|
|
|
383d26 |
- !job->driver->complete)
|
|
|
383d26 |
- {
|
|
|
383d26 |
- error_setg(errp, "The active block job '%s' cannot be completed",
|
|
|
383d26 |
- job->job.id);
|
|
|
383d26 |
- return;
|
|
|
383d26 |
- }
|
|
|
383d26 |
-
|
|
|
383d26 |
- job->driver->complete(job, errp);
|
|
|
383d26 |
-}
|
|
|
383d26 |
-
|
|
|
383d26 |
void block_job_finalize(BlockJob *job, Error **errp)
|
|
|
383d26 |
{
|
|
|
383d26 |
assert(job && job->job.id);
|
|
|
383d26 |
@@ -571,6 +553,11 @@ void block_job_cancel_sync_all(void)
|
|
|
383d26 |
}
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
+static void block_job_complete(BlockJob *job, Error **errp)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ job_complete(&job->job, errp);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
int block_job_complete_sync(BlockJob *job, Error **errp)
|
|
|
383d26 |
{
|
|
|
383d26 |
return block_job_finish_sync(job, &block_job_complete, errp);
|
|
|
383d26 |
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
|
|
|
383d26 |
index d975efe..85ce18a 100644
|
|
|
383d26 |
--- a/include/block/blockjob.h
|
|
|
383d26 |
+++ b/include/block/blockjob.h
|
|
|
383d26 |
@@ -154,16 +154,6 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
|
|
|
383d26 |
void block_job_cancel(BlockJob *job, bool force);
|
|
|
383d26 |
|
|
|
383d26 |
/**
|
|
|
383d26 |
- * block_job_complete:
|
|
|
383d26 |
- * @job: The job to be completed.
|
|
|
383d26 |
- * @errp: Error object.
|
|
|
383d26 |
- *
|
|
|
383d26 |
- * Asynchronously complete the specified job.
|
|
|
383d26 |
- */
|
|
|
383d26 |
-void block_job_complete(BlockJob *job, Error **errp);
|
|
|
383d26 |
-
|
|
|
383d26 |
-
|
|
|
383d26 |
-/**
|
|
|
383d26 |
* block_job_finalize:
|
|
|
383d26 |
* @job: The job to fully commit and finish.
|
|
|
383d26 |
* @errp: Error object.
|
|
|
383d26 |
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
|
|
|
383d26 |
index 38fe22d..b8ca7bb 100644
|
|
|
383d26 |
--- a/include/block/blockjob_int.h
|
|
|
383d26 |
+++ b/include/block/blockjob_int.h
|
|
|
383d26 |
@@ -39,12 +39,6 @@ struct BlockJobDriver {
|
|
|
383d26 |
JobDriver job_driver;
|
|
|
383d26 |
|
|
|
383d26 |
/**
|
|
|
383d26 |
- * Optional callback for job types whose completion must be triggered
|
|
|
383d26 |
- * manually.
|
|
|
383d26 |
- */
|
|
|
383d26 |
- void (*complete)(BlockJob *job, Error **errp);
|
|
|
383d26 |
-
|
|
|
383d26 |
- /**
|
|
|
383d26 |
* If the callback is not NULL, prepare will be invoked when all the jobs
|
|
|
383d26 |
* belonging to the same transaction complete; or upon this job's completion
|
|
|
383d26 |
* if it is not in a transaction.
|
|
|
383d26 |
diff --git a/include/qemu/job.h b/include/qemu/job.h
|
|
|
383d26 |
index aebc195..8f7f71a 100644
|
|
|
383d26 |
--- a/include/qemu/job.h
|
|
|
383d26 |
+++ b/include/qemu/job.h
|
|
|
383d26 |
@@ -167,6 +167,12 @@ struct JobDriver {
|
|
|
383d26 |
*/
|
|
|
383d26 |
void (*user_resume)(Job *job);
|
|
|
383d26 |
|
|
|
383d26 |
+ /**
|
|
|
383d26 |
+ * Optional callback for job types whose completion must be triggered
|
|
|
383d26 |
+ * manually.
|
|
|
383d26 |
+ */
|
|
|
383d26 |
+ void (*complete)(Job *job, Error **errp);
|
|
|
383d26 |
+
|
|
|
383d26 |
/*
|
|
|
383d26 |
* If the callback is not NULL, it will be invoked when the job has to be
|
|
|
383d26 |
* synchronously cancelled or completed; it should drain any activities
|
|
|
383d26 |
@@ -363,6 +369,8 @@ int job_apply_verb(Job *job, JobVerb verb, Error **errp);
|
|
|
383d26 |
/** The @job could not be started, free it. */
|
|
|
383d26 |
void job_early_fail(Job *job);
|
|
|
383d26 |
|
|
|
383d26 |
+/** Asynchronously complete the specified @job. */
|
|
|
383d26 |
+void job_complete(Job *job, Error **errp);;
|
|
|
383d26 |
|
|
|
383d26 |
typedef void JobDeferToMainLoopFn(Job *job, void *opaque);
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/job.c b/job.c
|
|
|
383d26 |
index 3772a35..8ceac0b 100644
|
|
|
383d26 |
--- a/job.c
|
|
|
383d26 |
+++ b/job.c
|
|
|
383d26 |
@@ -556,6 +556,22 @@ int job_finalize_single(Job *job)
|
|
|
383d26 |
return 0;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
+void job_complete(Job *job, Error **errp)
|
|
|
383d26 |
+{
|
|
|
383d26 |
+ /* Should not be reachable via external interface for internal jobs */
|
|
|
383d26 |
+ assert(job->id);
|
|
|
383d26 |
+ if (job_apply_verb(job, JOB_VERB_COMPLETE, errp)) {
|
|
|
383d26 |
+ return;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+ if (job->pause_count || job_is_cancelled(job) || !job->driver->complete) {
|
|
|
383d26 |
+ error_setg(errp, "The active block job '%s' cannot be completed",
|
|
|
383d26 |
+ job->id);
|
|
|
383d26 |
+ return;
|
|
|
383d26 |
+ }
|
|
|
383d26 |
+
|
|
|
383d26 |
+ job->driver->complete(job, errp);
|
|
|
383d26 |
+}
|
|
|
383d26 |
+
|
|
|
383d26 |
|
|
|
383d26 |
typedef struct {
|
|
|
383d26 |
Job *job;
|
|
|
383d26 |
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
|
|
|
383d26 |
index 58ea566..b428aac 100644
|
|
|
383d26 |
--- a/tests/test-bdrv-drain.c
|
|
|
383d26 |
+++ b/tests/test-bdrv-drain.c
|
|
|
383d26 |
@@ -514,9 +514,9 @@ static void coroutine_fn test_job_start(void *opaque)
|
|
|
383d26 |
job_defer_to_main_loop(&s->common.job, test_job_completed, NULL);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
-static void test_job_complete(BlockJob *job, Error **errp)
|
|
|
383d26 |
+static void test_job_complete(Job *job, Error **errp)
|
|
|
383d26 |
{
|
|
|
383d26 |
- TestBlockJob *s = container_of(job, TestBlockJob, common);
|
|
|
383d26 |
+ TestBlockJob *s = container_of(job, TestBlockJob, common.job);
|
|
|
383d26 |
s->should_complete = true;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
@@ -527,8 +527,8 @@ BlockJobDriver test_job_driver = {
|
|
|
383d26 |
.user_resume = block_job_user_resume,
|
|
|
383d26 |
.drain = block_job_drain,
|
|
|
383d26 |
.start = test_job_start,
|
|
|
383d26 |
+ .complete = test_job_complete,
|
|
|
383d26 |
},
|
|
|
383d26 |
- .complete = test_job_complete,
|
|
|
383d26 |
};
|
|
|
383d26 |
|
|
|
383d26 |
static void test_blockjob_common(enum drain_type drain_type)
|
|
|
383d26 |
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
|
|
|
383d26 |
index 592a136..e44c608 100644
|
|
|
383d26 |
--- a/tests/test-blockjob.c
|
|
|
383d26 |
+++ b/tests/test-blockjob.c
|
|
|
383d26 |
@@ -171,9 +171,9 @@ static void cancel_job_completed(Job *job, void *opaque)
|
|
|
383d26 |
block_job_completed(bjob, 0);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
-static void cancel_job_complete(BlockJob *job, Error **errp)
|
|
|
383d26 |
+static void cancel_job_complete(Job *job, Error **errp)
|
|
|
383d26 |
{
|
|
|
383d26 |
- CancelJob *s = container_of(job, CancelJob, common);
|
|
|
383d26 |
+ CancelJob *s = container_of(job, CancelJob, common.job);
|
|
|
383d26 |
s->should_complete = true;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
@@ -204,8 +204,8 @@ static const BlockJobDriver test_cancel_driver = {
|
|
|
383d26 |
.user_resume = block_job_user_resume,
|
|
|
383d26 |
.drain = block_job_drain,
|
|
|
383d26 |
.start = cancel_job_start,
|
|
|
383d26 |
+ .complete = cancel_job_complete,
|
|
|
383d26 |
},
|
|
|
383d26 |
- .complete = cancel_job_complete,
|
|
|
383d26 |
};
|
|
|
383d26 |
|
|
|
383d26 |
static CancelJob *create_common(BlockJob **pjob)
|
|
|
383d26 |
@@ -333,7 +333,7 @@ static void test_cancel_pending(void)
|
|
|
383d26 |
block_job_enter(job);
|
|
|
383d26 |
assert(job->job.status == JOB_STATUS_READY);
|
|
|
383d26 |
|
|
|
383d26 |
- block_job_complete(job, &error_abort);
|
|
|
383d26 |
+ job_complete(&job->job, &error_abort);
|
|
|
383d26 |
block_job_enter(job);
|
|
|
383d26 |
while (!s->completed) {
|
|
|
383d26 |
aio_poll(qemu_get_aio_context(), true);
|
|
|
383d26 |
@@ -357,7 +357,7 @@ static void test_cancel_concluded(void)
|
|
|
383d26 |
block_job_enter(job);
|
|
|
383d26 |
assert(job->job.status == JOB_STATUS_READY);
|
|
|
383d26 |
|
|
|
383d26 |
- block_job_complete(job, &error_abort);
|
|
|
383d26 |
+ job_complete(&job->job, &error_abort);
|
|
|
383d26 |
block_job_enter(job);
|
|
|
383d26 |
while (!s->completed) {
|
|
|
383d26 |
aio_poll(qemu_get_aio_context(), true);
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|