From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 29/46] job: Move .complete callback to Job
Date: Wed, 23 May 2018 15:11:38 +0200 [thread overview]
Message-ID: <20180523131155.12359-30-kwolf@redhat.com> (raw)
In-Reply-To: <20180523131155.12359-1-kwolf@redhat.com>
This moves the .complete callback that tells a READY job to complete
from BlockJobDriver to JobDriver. The wrapper function job_complete()
doesn't require anything block job specific any more and can be moved
to Job.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
include/block/blockjob.h | 10 ----------
include/block/blockjob_int.h | 6 ------
include/qemu/job.h | 8 ++++++++
block/mirror.c | 10 +++++-----
blockdev.c | 2 +-
blockjob.c | 23 +++++------------------
job.c | 16 ++++++++++++++++
tests/test-bdrv-drain.c | 6 +++---
tests/test-blockjob.c | 10 +++++-----
9 files changed, 43 insertions(+), 48 deletions(-)
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index d975efea20..85ce18a381 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -154,16 +154,6 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
void block_job_cancel(BlockJob *job, bool force);
/**
- * block_job_complete:
- * @job: The job to be completed.
- * @errp: Error object.
- *
- * Asynchronously complete the specified job.
- */
-void block_job_complete(BlockJob *job, Error **errp);
-
-
-/**
* block_job_finalize:
* @job: The job to fully commit and finish.
* @errp: Error object.
diff --git a/include/block/blockjob_int.h b/include/block/blockjob_int.h
index 38fe22d7e0..b8ca7bb0c9 100644
--- a/include/block/blockjob_int.h
+++ b/include/block/blockjob_int.h
@@ -39,12 +39,6 @@ struct BlockJobDriver {
JobDriver job_driver;
/**
- * Optional callback for job types whose completion must be triggered
- * manually.
- */
- void (*complete)(BlockJob *job, Error **errp);
-
- /**
* If the callback is not NULL, prepare will be invoked when all the jobs
* belonging to the same transaction complete; or upon this job's completion
* if it is not in a transaction.
diff --git a/include/qemu/job.h b/include/qemu/job.h
index aebc1959e6..8f7f71a9b1 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -167,6 +167,12 @@ struct JobDriver {
*/
void (*user_resume)(Job *job);
+ /**
+ * Optional callback for job types whose completion must be triggered
+ * manually.
+ */
+ void (*complete)(Job *job, Error **errp);
+
/*
* If the callback is not NULL, it will be invoked when the job has to be
* synchronously cancelled or completed; it should drain any activities
@@ -363,6 +369,8 @@ int job_apply_verb(Job *job, JobVerb verb, Error **errp);
/** The @job could not be started, free it. */
void job_early_fail(Job *job);
+/** Asynchronously complete the specified @job. */
+void job_complete(Job *job, Error **errp);;
typedef void JobDeferToMainLoopFn(Job *job, void *opaque);
diff --git a/block/mirror.c b/block/mirror.c
index a579bd8cd1..656237af5c 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -905,16 +905,16 @@ immediate_exit:
job_defer_to_main_loop(&s->common.job, mirror_exit, data);
}
-static void mirror_complete(BlockJob *job, Error **errp)
+static void mirror_complete(Job *job, Error **errp)
{
- MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
+ MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job);
BlockDriverState *target;
target = blk_bs(s->target);
if (!s->synced) {
error_setg(errp, "The active block job '%s' cannot be completed",
- job->job.id);
+ job->id);
return;
}
@@ -995,8 +995,8 @@ static const BlockJobDriver mirror_job_driver = {
.drain = block_job_drain,
.start = mirror_run,
.pause = mirror_pause,
+ .complete = mirror_complete,
},
- .complete = mirror_complete,
.attached_aio_context = mirror_attached_aio_context,
.drain = mirror_drain,
};
@@ -1010,8 +1010,8 @@ static const BlockJobDriver commit_active_job_driver = {
.drain = block_job_drain,
.start = mirror_run,
.pause = mirror_pause,
+ .complete = mirror_complete,
},
- .complete = mirror_complete,
.attached_aio_context = mirror_attached_aio_context,
.drain = mirror_drain,
};
diff --git a/blockdev.c b/blockdev.c
index 278b92ce03..0967f6ab66 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3894,7 +3894,7 @@ void qmp_block_job_complete(const char *device, Error **errp)
}
trace_qmp_block_job_complete(job);
- block_job_complete(job, errp);
+ job_complete(&job->job, errp);
aio_context_release(aio_context);
}
diff --git a/blockjob.c b/blockjob.c
index 63e166927a..0ca7672941 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -481,24 +481,6 @@ int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n)
return ratelimit_calculate_delay(&job->limit, n);
}
-void block_job_complete(BlockJob *job, Error **errp)
-{
- /* Should not be reachable via external interface for internal jobs */
- assert(job->job.id);
- if (job_apply_verb(&job->job, JOB_VERB_COMPLETE, errp)) {
- return;
- }
- if (job->job.pause_count || job_is_cancelled(&job->job) ||
- !job->driver->complete)
- {
- error_setg(errp, "The active block job '%s' cannot be completed",
- job->job.id);
- return;
- }
-
- job->driver->complete(job, errp);
-}
-
void block_job_finalize(BlockJob *job, Error **errp)
{
assert(job && job->job.id);
@@ -571,6 +553,11 @@ void block_job_cancel_sync_all(void)
}
}
+static void block_job_complete(BlockJob *job, Error **errp)
+{
+ job_complete(&job->job, errp);
+}
+
int block_job_complete_sync(BlockJob *job, Error **errp)
{
return block_job_finish_sync(job, &block_job_complete, errp);
diff --git a/job.c b/job.c
index 3772a35fcf..8ceac0b01e 100644
--- a/job.c
+++ b/job.c
@@ -556,6 +556,22 @@ int job_finalize_single(Job *job)
return 0;
}
+void job_complete(Job *job, Error **errp)
+{
+ /* Should not be reachable via external interface for internal jobs */
+ assert(job->id);
+ if (job_apply_verb(job, JOB_VERB_COMPLETE, errp)) {
+ return;
+ }
+ if (job->pause_count || job_is_cancelled(job) || !job->driver->complete) {
+ error_setg(errp, "The active block job '%s' cannot be completed",
+ job->id);
+ return;
+ }
+
+ job->driver->complete(job, errp);
+}
+
typedef struct {
Job *job;
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
index 58ea5663f0..b428aaca68 100644
--- a/tests/test-bdrv-drain.c
+++ b/tests/test-bdrv-drain.c
@@ -514,9 +514,9 @@ static void coroutine_fn test_job_start(void *opaque)
job_defer_to_main_loop(&s->common.job, test_job_completed, NULL);
}
-static void test_job_complete(BlockJob *job, Error **errp)
+static void test_job_complete(Job *job, Error **errp)
{
- TestBlockJob *s = container_of(job, TestBlockJob, common);
+ TestBlockJob *s = container_of(job, TestBlockJob, common.job);
s->should_complete = true;
}
@@ -527,8 +527,8 @@ BlockJobDriver test_job_driver = {
.user_resume = block_job_user_resume,
.drain = block_job_drain,
.start = test_job_start,
+ .complete = test_job_complete,
},
- .complete = test_job_complete,
};
static void test_blockjob_common(enum drain_type drain_type)
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
index 592a13613d..e44c608327 100644
--- a/tests/test-blockjob.c
+++ b/tests/test-blockjob.c
@@ -171,9 +171,9 @@ static void cancel_job_completed(Job *job, void *opaque)
block_job_completed(bjob, 0);
}
-static void cancel_job_complete(BlockJob *job, Error **errp)
+static void cancel_job_complete(Job *job, Error **errp)
{
- CancelJob *s = container_of(job, CancelJob, common);
+ CancelJob *s = container_of(job, CancelJob, common.job);
s->should_complete = true;
}
@@ -204,8 +204,8 @@ static const BlockJobDriver test_cancel_driver = {
.user_resume = block_job_user_resume,
.drain = block_job_drain,
.start = cancel_job_start,
+ .complete = cancel_job_complete,
},
- .complete = cancel_job_complete,
};
static CancelJob *create_common(BlockJob **pjob)
@@ -333,7 +333,7 @@ static void test_cancel_pending(void)
block_job_enter(job);
assert(job->job.status == JOB_STATUS_READY);
- block_job_complete(job, &error_abort);
+ job_complete(&job->job, &error_abort);
block_job_enter(job);
while (!s->completed) {
aio_poll(qemu_get_aio_context(), true);
@@ -357,7 +357,7 @@ static void test_cancel_concluded(void)
block_job_enter(job);
assert(job->job.status == JOB_STATUS_READY);
- block_job_complete(job, &error_abort);
+ job_complete(&job->job, &error_abort);
block_job_enter(job);
while (!s->completed) {
aio_poll(qemu_get_aio_context(), true);
--
2.13.6
next prev parent reply other threads:[~2018-05-23 13:12 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-23 13:11 [Qemu-devel] [PULL 00/46] Block layer patches Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 01/46] qemu-iotests: Fix paths for NFS Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 02/46] qemu-iotests: Filter NFS paths Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 03/46] qemu-iotests: 086 doesn't work with NFS Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 04/46] sheepdog: Remove unnecessary NULL check in sd_prealloc() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 05/46] qemu-iotests: Add more tests to "migration" group Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 06/46] qemu-iotests: Remove MIG_SOCKET from non-migration tests Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 07/46] blockjob: Update block-job-pause/resume documentation Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 08/46] blockjob: Improve BlockJobInfo.offset/len documentation Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 09/46] job: Create Job, JobDriver and job_create() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 10/46] job: Rename BlockJobType into JobType Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 11/46] job: Add JobDriver.job_type Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 12/46] job: Add job_delete() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 13/46] job: Maintain a list of all jobs Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 14/46] job: Move state transitions to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 15/46] job: Add reference counting Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 16/46] job: Move cancelled to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 17/46] job: Add Job.aio_context Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 18/46] job: Move defer_to_main_loop to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 19/46] job: Move coroutine and related code " Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 20/46] job: Add job_sleep_ns() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 21/46] job: Move pause/resume functions to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 22/46] job: Replace BlockJob.completed with job_is_completed() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 23/46] job: Move BlockJobCreateFlags to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 24/46] blockjob: Split block_job_event_pending() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 25/46] job: Add job_event_*() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 26/46] job: Move single job finalisation to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 27/46] job: Convert block_job_cancel_async() " Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 28/46] job: Add job_drain() Kevin Wolf
2018-05-23 13:11 ` Kevin Wolf [this message]
2018-05-23 13:11 ` [Qemu-devel] [PULL 30/46] job: Move job_finish_sync() to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 31/46] job: Switch transactions to JobTxn Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 32/46] job: Move transactions to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 33/46] job: Move completion and cancellation " Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 34/46] block: Cancel job in bdrv_close_all() callers Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 35/46] job: Add job_yield() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 36/46] job: Add job_dismiss() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 37/46] job: Add job_is_ready() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 38/46] job: Add job_transition_to_ready() Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 39/46] job: Move progress fields to Job Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 40/46] job: Introduce qapi/job.json Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 41/46] job: Add JOB_STATUS_CHANGE QMP event Kevin Wolf
2018-05-23 19:50 ` Eric Blake
2018-05-23 13:11 ` [Qemu-devel] [PULL 42/46] job: Add lifecycle QMP commands Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 43/46] job: Add query-jobs QMP command Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 44/46] blockjob: Remove BlockJob.driver Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 45/46] iotests: Move qmp_to_opts() to VM Kevin Wolf
2018-05-23 13:11 ` [Qemu-devel] [PULL 46/46] qemu-iotests: Test job-* with block jobs Kevin Wolf
2018-05-23 14:02 ` [Qemu-devel] [PULL 00/46] Block layer patches no-reply
2018-05-24 13:21 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180523131155.12359-30-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.