Skip to content

Commit

Permalink
job: Add job_dismiss()
Browse files Browse the repository at this point in the history
This moves block_job_dismiss() to the Job layer.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
  • Loading branch information
kevmw committed May 23, 2018
1 parent 198c49c commit 5f9a6a0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
10 changes: 6 additions & 4 deletions blockdev.c
Expand Up @@ -3915,14 +3915,16 @@ void qmp_block_job_finalize(const char *id, Error **errp)
void qmp_block_job_dismiss(const char *id, Error **errp)
{
AioContext *aio_context;
BlockJob *job = find_block_job(id, &aio_context, errp);
BlockJob *bjob = find_block_job(id, &aio_context, errp);
Job *job;

if (!job) {
if (!bjob) {
return;
}

trace_qmp_block_job_dismiss(job);
block_job_dismiss(&job, errp);
trace_qmp_block_job_dismiss(bjob);
job = &bjob->job;
job_dismiss(&job, errp);
aio_context_release(aio_context);
}

Expand Down
13 changes: 0 additions & 13 deletions blockjob.c
Expand Up @@ -242,19 +242,6 @@ int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n)
return ratelimit_calculate_delay(&job->limit, n);
}

void block_job_dismiss(BlockJob **jobptr, Error **errp)
{
BlockJob *job = *jobptr;
/* similarly to _complete, this is QMP-interface only. */
assert(job->job.id);
if (job_apply_verb(&job->job, JOB_VERB_DISMISS, errp)) {
return;
}

job_do_dismiss(&job->job);
*jobptr = NULL;
}

void block_job_progress_update(BlockJob *job, uint64_t done)
{
job->offset += done;
Expand Down
9 changes: 0 additions & 9 deletions include/block/blockjob.h
Expand Up @@ -140,15 +140,6 @@ void block_job_remove_all_bdrv(BlockJob *job);
*/
void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);

/**
* block_job_dismiss:
* @job: The job to be dismissed.
* @errp: Error object.
*
* Remove a concluded job from the query list.
*/
void block_job_dismiss(BlockJob **job, Error **errp);

/**
* block_job_progress_update:
* @job: The job that has made progress
Expand Down
7 changes: 6 additions & 1 deletion include/qemu/job.h
Expand Up @@ -487,6 +487,12 @@ int job_complete_sync(Job *job, Error **errp);
*/
void job_finalize(Job *job, Error **errp);

/**
* Remove the concluded @job from the query list and resets the passed pointer
* to %NULL. Returns an error if the job is not actually concluded.
*/
void job_dismiss(Job **job, Error **errp);

typedef void JobDeferToMainLoopFn(Job *job, void *opaque);

/**
Expand Down Expand Up @@ -515,6 +521,5 @@ int job_finish_sync(Job *job, void (*finish)(Job *, Error **errp), Error **errp)

/* TODO To be removed from the public interface */
void job_state_transition(Job *job, JobStatus s1);
void job_do_dismiss(Job *job);

#endif
15 changes: 14 additions & 1 deletion job.c
Expand Up @@ -568,7 +568,7 @@ void job_user_resume(Job *job, Error **errp)
job_resume(job);
}

void job_do_dismiss(Job *job)
static void job_do_dismiss(Job *job)
{
assert(job);
job->busy = false;
Expand All @@ -581,6 +581,19 @@ void job_do_dismiss(Job *job)
job_unref(job);
}

void job_dismiss(Job **jobptr, Error **errp)
{
Job *job = *jobptr;
/* similarly to _complete, this is QMP-interface only. */
assert(job->id);
if (job_apply_verb(job, JOB_VERB_DISMISS, errp)) {
return;
}

job_do_dismiss(job);
*jobptr = NULL;
}

void job_early_fail(Job *job)
{
assert(job->status == JOB_STATUS_CREATED);
Expand Down
4 changes: 2 additions & 2 deletions tests/test-blockjob.c
Expand Up @@ -233,8 +233,8 @@ static void cancel_common(CancelJob *s)

job_cancel_sync(&job->job);
if (sts != JOB_STATUS_CREATED && sts != JOB_STATUS_CONCLUDED) {
BlockJob *dummy = job;
block_job_dismiss(&dummy, &error_abort);
Job *dummy = &job->job;
job_dismiss(&dummy, &error_abort);
}
assert(job->job.status == JOB_STATUS_NULL);
job_unref(&job->job);
Expand Down

0 comments on commit 5f9a6a0

Please sign in to comment.