Commit 3453d972 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

job: Move .complete callback to Job



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: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
parent b69f777d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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,
    },
    .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,
    },
    .attached_aio_context   = mirror_attached_aio_context,
    .drain                  = mirror_drain,
};
+1 −1
Original line number Diff line number Diff line
@@ -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);
}

+5 −18
Original line number Diff line number Diff line
@@ -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);
+0 −10
Original line number Diff line number Diff line
@@ -153,16 +153,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.
+0 −6
Original line number Diff line number Diff line
@@ -38,12 +38,6 @@ struct BlockJobDriver {
    /** Generic JobDriver callbacks and settings */
    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
Loading