diff options
author | Kevin Wolf <kwolf@redhat.com> | 2018-05-04 16:25:43 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2018-05-23 14:30:51 +0200 |
commit | 456273b02474780537e2bb52a72213f63bb5227a (patch) | |
tree | 0ab2748bc922e4e6c3471f01c6277dc703d0da97 /job-qmp.c | |
parent | 1a90bc8128ee7d16ce4abb131961e37084d75b16 (diff) |
job: Add query-jobs QMP command
This adds a minimal query-jobs implementation that shouldn't pose many
design questions. It can later be extended to expose more information,
and especially job-specific information.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'job-qmp.c')
-rw-r--r-- | job-qmp.c | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -132,3 +132,57 @@ void qmp_job_dismiss(const char *id, Error **errp) job_dismiss(&job, errp); aio_context_release(aio_context); } + +static JobInfo *job_query_single(Job *job, Error **errp) +{ + JobInfo *info; + const char *errmsg = NULL; + + assert(!job_is_internal(job)); + + if (job->ret < 0) { + errmsg = strerror(-job->ret); + } + + info = g_new(JobInfo, 1); + *info = (JobInfo) { + .id = g_strdup(job->id), + .type = job_type(job), + .status = job->status, + .current_progress = job->progress_current, + .total_progress = job->progress_total, + .has_error = !!errmsg, + .error = g_strdup(errmsg), + }; + + return info; +} + +JobInfoList *qmp_query_jobs(Error **errp) +{ + JobInfoList *head = NULL, **p_next = &head; + Job *job; + + for (job = job_next(NULL); job; job = job_next(job)) { + JobInfoList *elem; + AioContext *aio_context; + + if (job_is_internal(job)) { + continue; + } + elem = g_new0(JobInfoList, 1); + aio_context = job->aio_context; + aio_context_acquire(aio_context); + elem->value = job_query_single(job, errp); + aio_context_release(aio_context); + if (!elem->value) { + g_free(elem); + qapi_free_JobInfoList(head); + return NULL; + } + *p_next = elem; + p_next = &elem->next; + } + + return head; +} |