提交 004e95df 编写于 作者: K Kevin Wolf

job: Convert block_job_cancel_async() to Job

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: NKevin Wolf <kwolf@redhat.com>
Reviewed-by: NMax Reitz <mreitz@redhat.com>
上级 4ad35181
...@@ -871,7 +871,7 @@ static void coroutine_fn mirror_run(void *opaque) ...@@ -871,7 +871,7 @@ static void coroutine_fn mirror_run(void *opaque)
trace_mirror_before_sleep(s, cnt, s->synced, delay_ns); trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
job_sleep_ns(&s->common.job, delay_ns); job_sleep_ns(&s->common.job, delay_ns);
if (job_is_cancelled(&s->common.job) && if (job_is_cancelled(&s->common.job) &&
(!s->synced || s->common.force)) (!s->synced || s->common.job.force_cancel))
{ {
break; break;
} }
...@@ -884,7 +884,7 @@ immediate_exit: ...@@ -884,7 +884,7 @@ immediate_exit:
* or it was cancelled prematurely so that we do not guarantee that * or it was cancelled prematurely so that we do not guarantee that
* the target is a copy of the source. * 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))); job_is_cancelled(&s->common.job)));
assert(need_drain); assert(need_drain);
mirror_wait_for_all_io(s); mirror_wait_for_all_io(s);
......
...@@ -270,19 +270,20 @@ static int block_job_prepare(BlockJob *job) ...@@ -270,19 +270,20 @@ static int block_job_prepare(BlockJob *job)
return job->job.ret; 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) { if (job->user_paused) {
block_job_iostatus_reset(job); /* Do not call job_enter here, the caller will handle it. */
} job->user_paused = false;
if (job->job.user_paused) { if (job->driver->user_resume) {
/* Do not call block_job_enter here, the caller will handle it. */ job->driver->user_resume(job);
job->job.user_paused = false; }
job->job.pause_count--; assert(job->pause_count > 0);
job->pause_count--;
} }
job->job.cancelled = true; job->cancelled = true;
/* To prevent 'force == false' overriding a previous 'force == 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) static int block_job_txn_apply(BlockJobTxn *txn, int fn(BlockJob *), bool lock)
...@@ -367,7 +368,7 @@ static void block_job_completed_txn_abort(BlockJob *job) ...@@ -367,7 +368,7 @@ static void block_job_completed_txn_abort(BlockJob *job)
* on the caller, so leave it. */ * on the caller, so leave it. */
QLIST_FOREACH(other_job, &txn->jobs, txn_list) { QLIST_FOREACH(other_job, &txn->jobs, txn_list) {
if (other_job != job) { if (other_job != job) {
block_job_cancel_async(other_job, false); job_cancel_async(&other_job->job, false);
} }
} }
while (!QLIST_EMPTY(&txn->jobs)) { while (!QLIST_EMPTY(&txn->jobs)) {
...@@ -527,7 +528,7 @@ void block_job_cancel(BlockJob *job, bool force) ...@@ -527,7 +528,7 @@ void block_job_cancel(BlockJob *job, bool force)
job_do_dismiss(&job->job); job_do_dismiss(&job->job);
return; return;
} }
block_job_cancel_async(job, force); job_cancel_async(&job->job, force);
if (!job_started(&job->job)) { if (!job_started(&job->job)) {
block_job_completed(job, -ECANCELED); block_job_completed(job, -ECANCELED);
} else if (job->job.deferred_to_main_loop) { } else if (job->job.deferred_to_main_loop) {
......
...@@ -50,12 +50,6 @@ typedef struct BlockJob { ...@@ -50,12 +50,6 @@ typedef struct BlockJob {
/** The block device on which the job is operating. */ /** The block device on which the job is operating. */
BlockBackend *blk; 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. * Set to true when the job is ready to be completed.
*/ */
......
...@@ -97,6 +97,12 @@ typedef struct Job { ...@@ -97,6 +97,12 @@ typedef struct Job {
*/ */
bool cancelled; 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. */ /** Set to true when the job has deferred work to the main loop. */
bool deferred_to_main_loop; bool deferred_to_main_loop;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册