static const BlockJobDriver backup_job_driver = {
.job_driver = {
.instance_size = sizeof(BackupBlockJob),
+ .job_type = JOB_TYPE_BACKUP,
},
- .job_type = JOB_TYPE_BACKUP,
.start = backup_run,
.commit = backup_commit,
.abort = backup_abort,
static const BlockJobDriver commit_job_driver = {
.job_driver = {
.instance_size = sizeof(CommitBlockJob),
+ .job_type = JOB_TYPE_COMMIT,
},
- .job_type = JOB_TYPE_COMMIT,
.start = commit_run,
};
static const BlockJobDriver mirror_job_driver = {
.job_driver = {
.instance_size = sizeof(MirrorBlockJob),
+ .job_type = JOB_TYPE_MIRROR,
},
- .job_type = JOB_TYPE_MIRROR,
.start = mirror_run,
.complete = mirror_complete,
.pause = mirror_pause,
static const BlockJobDriver commit_active_job_driver = {
.job_driver = {
.instance_size = sizeof(MirrorBlockJob),
+ .job_type = JOB_TYPE_COMMIT,
},
- .job_type = JOB_TYPE_COMMIT,
.start = mirror_run,
.complete = mirror_complete,
.pause = mirror_pause,
static const BlockJobDriver stream_job_driver = {
.job_driver = {
.instance_size = sizeof(StreamBlockJob),
+ .job_type = JOB_TYPE_STREAM,
},
- .job_type = JOB_TYPE_STREAM,
.start = stream_run,
};
static char *child_job_get_parent_desc(BdrvChild *c)
{
BlockJob *job = c->opaque;
- return g_strdup_printf("%s job '%s'",
- JobType_str(job->driver->job_type),
- job->job.id);
+ return g_strdup_printf("%s job '%s'", job_type_str(&job->job), job->job.id);
}
static void child_job_drained_begin(BdrvChild *c)
return NULL;
}
info = g_new0(BlockJobInfo, 1);
- info->type = g_strdup(JobType_str(job->driver->job_type));
+ info->type = g_strdup(job_type_str(&job->job));
info->device = g_strdup(job->job.id);
info->len = job->len;
info->busy = atomic_read(&job->busy);
return;
}
- qapi_event_send_block_job_cancelled(job->driver->job_type,
+ qapi_event_send_block_job_cancelled(job_type(&job->job),
job->job.id,
job->len,
job->offset,
return;
}
- qapi_event_send_block_job_completed(job->driver->job_type,
+ qapi_event_send_block_job_completed(job_type(&job->job),
job->job.id,
job->len,
job->offset,
{
block_job_state_transition(job, BLOCK_JOB_STATUS_PENDING);
if (!job->auto_finalize && !block_job_is_internal(job)) {
- qapi_event_send_block_job_pending(job->driver->job_type,
+ qapi_event_send_block_job_pending(job_type(&job->job),
job->job.id,
&error_abort);
}
block_job_sleep_timer_cb, job);
error_setg(&job->blocker, "block device is in use by block job: %s",
- JobType_str(driver->job_type));
+ job_type_str(&job->job));
block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort);
bs->job = job;
return;
}
- qapi_event_send_block_job_ready(job->driver->job_type,
+ qapi_event_send_block_job_ready(job_type(&job->job),
job->job.id,
job->len,
job->offset,
/** Generic JobDriver callbacks and settings */
JobDriver job_driver;
- /** String describing the operation, part of query-block-jobs QMP API */
- JobType job_type;
-
/** Mandatory: Entrypoint for the Coroutine. */
CoroutineEntry *start;
#ifndef JOB_H
#define JOB_H
+#include "qapi/qapi-types-block-core.h"
+
typedef struct JobDriver JobDriver;
/**
struct JobDriver {
/** Derived Job struct size */
size_t instance_size;
+
+ /** Enum describing the operation */
+ JobType job_type;
};
*/
void *job_create(const char *job_id, const JobDriver *driver, Error **errp);
+/** Returns the JobType of a given Job. */
+JobType job_type(const Job *job);
+
+/** Returns the enum string for the JobType of a given Job. */
+const char *job_type_str(const Job *job);
+
#endif
#include "qemu/job.h"
#include "qemu/id.h"
+JobType job_type(const Job *job)
+{
+ return job->driver->job_type;
+}
+
+const char *job_type_str(const Job *job)
+{
+ return JobType_str(job_type(job));
+}
+
void *job_create(const char *job_id, const JobDriver *driver, Error **errp)
{
Job *job;