[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [RFC PATCH 25/33] job: Convert block_job_cancel_async() to
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [RFC PATCH 25/33] job: Convert block_job_cancel_async() to Job |
Date: |
Tue, 24 Apr 2018 17:25:07 +0200 |
block_job_cancel_async() did two things that were still block job
specific:
* Setting job->force. This field makes sense on the Job level, so we can
just move it. While at it, rename it to job->force_cancel to make its
purpose more obvious.
* Resetting the I/O status. This can't be moved because generic Jobs
don't have an I/O status. What the function really implements is a
user resume, except without entering the coroutine. Consequently, it
makes sense to call the .user_resume driver callback here which
already resets the I/O status.
The old block_job_cancel_async() has two separate if statements that
check job->iostatus != BLOCK_DEVICE_IO_STATUS_OK and job->user_paused.
However, the former condition always implies the latter (as is
asserted in block_job_iostatus_reset()), so changing the explicit call
of block_job_iostatus_reset() on the former condition with the
.user_resume callback on the latter condition is equivalent and
doesn't need to access any BlockJob specific state.
Signed-off-by: Kevin Wolf <address@hidden>
---
include/block/blockjob.h | 6 ------
include/qemu/job.h | 6 ++++++
block/mirror.c | 4 ++--
blockjob.c | 25 +++++++++++++------------
4 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index e5af02f751..8477fc5a78 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -51,12 +51,6 @@ typedef struct BlockJob {
BlockBackend *blk;
/**
- * Set to true if the job should abort immediately without waiting
- * for data to be in sync.
- */
- bool force;
-
- /**
* Set to true when the job is ready to be completed.
*/
bool ready;
diff --git a/include/qemu/job.h b/include/qemu/job.h
index f456e4f27d..3351627dc0 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -97,6 +97,12 @@ typedef struct Job {
*/
bool cancelled;
+ /**
+ * Set to true if the job should abort immediately without waiting
+ * for data to be in sync.
+ */
+ bool force_cancel;
+
/** Set to true when the job has deferred work to the main loop. */
bool deferred_to_main_loop;
diff --git a/block/mirror.c b/block/mirror.c
index 3266553ffb..8e172e324d 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -865,7 +865,7 @@ static void coroutine_fn mirror_run(void *opaque)
ret = 0;
trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
- if (job_is_cancelled(&s->common.job) && s->common.force) {
+ if (job_is_cancelled(&s->common.job) && s->common.job.force_cancel) {
break;
} else if (!should_complete) {
delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0);
@@ -880,7 +880,7 @@ immediate_exit:
* or it was cancelled prematurely so that we do not guarantee that
* the target is a copy of the source.
*/
- assert(ret < 0 || ((s->common.force || !s->synced) &&
+ assert(ret < 0 || ((s->common.job.force_cancel || !s->synced) &&
job_is_cancelled(&s->common.job)));
assert(need_drain);
mirror_wait_for_all_io(s);
diff --git a/blockjob.c b/blockjob.c
index 677938a3b7..17478d2c6e 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -271,19 +271,20 @@ static int block_job_prepare(BlockJob *job)
return job->job.ret;
}
-static void block_job_cancel_async(BlockJob *job, bool force)
+static void job_cancel_async(Job *job, bool force)
{
- if (job->iostatus != BLOCK_DEVICE_IO_STATUS_OK) {
- block_job_iostatus_reset(job);
- }
- if (job->job.user_paused) {
- /* Do not call block_job_enter here, the caller will handle it. */
- job->job.user_paused = false;
- job->job.pause_count--;
+ if (job->user_paused) {
+ /* Do not call job_enter here, the caller will handle it. */
+ job->user_paused = false;
+ if (job->driver->user_resume) {
+ job->driver->user_resume(job);
+ }
+ assert(job->pause_count > 0);
+ job->pause_count--;
}
- job->job.cancelled = true;
+ job->cancelled = true;
/* To prevent 'force == false' overriding a previous 'force == true' */
- job->force |= force;
+ job->force_cancel |= force;
}
static int block_job_txn_apply(BlockJobTxn *txn, int fn(BlockJob *), bool lock)
@@ -368,7 +369,7 @@ static void block_job_completed_txn_abort(BlockJob *job)
* on the caller, so leave it. */
QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
if (other_job != job) {
- block_job_cancel_async(other_job, false);
+ job_cancel_async(&other_job->job, false);
}
}
while (!QLIST_EMPTY(&txn->jobs)) {
@@ -528,7 +529,7 @@ void block_job_cancel(BlockJob *job, bool force)
job_do_dismiss(&job->job);
return;
}
- block_job_cancel_async(job, force);
+ job_cancel_async(&job->job, force);
if (!job_started(&job->job)) {
block_job_completed(job, -ECANCELED);
} else if (job->job.deferred_to_main_loop) {
--
2.13.6
- [Qemu-block] [RFC PATCH 14/33] job: Move cancelled to Job, (continued)
- [Qemu-block] [RFC PATCH 14/33] job: Move cancelled to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 13/33] job: Add reference counting, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 16/33] job: Move defer_to_main_loop to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 18/33] job: Add job_sleep_ns(), Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 20/33] job: Replace BlockJob.completed with job_is_completed(), Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 22/33] blockjob: Split block_job_event_pending(), Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 23/33] job: Add job_event_*(), Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 19/33] job: Move pause/resume functions to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 17/33] job: Move coroutine and related code to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 21/33] job: Move BlockJobCreateFlags to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 25/33] job: Convert block_job_cancel_async() to Job,
Kevin Wolf <=
- [Qemu-block] [RFC PATCH 28/33] job: Move job_finish_sync() to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 26/33] job: Add job_drain(), Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 24/33] job: Move single job finalisation to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 27/33] job: Move .complete callback to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 31/33] job: Move completion and cancellation to Job, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 32/33] job: Add job_yield(), Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 29/33] job: Switch transactions to JobTxn, Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 33/33] job: Add job_dismiss(), Kevin Wolf, 2018/04/24
- [Qemu-block] [RFC PATCH 30/33] job: Move transactions to Job, Kevin Wolf, 2018/04/24
- Re: [Qemu-block] [Qemu-devel] [RFC PATCH 00/33] Generic background jobs, no-reply, 2018/04/24