aboutsummaryrefslogtreecommitdiff
path: root/job-qmp.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-05-04 16:25:43 +0200
committerKevin Wolf <kwolf@redhat.com>2018-05-23 14:30:51 +0200
commit456273b02474780537e2bb52a72213f63bb5227a (patch)
tree0ab2748bc922e4e6c3471f01c6277dc703d0da97 /job-qmp.c
parent1a90bc8128ee7d16ce4abb131961e37084d75b16 (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.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/job-qmp.c b/job-qmp.c
index b2e18cfd9c..7f38f63336 100644
--- a/job-qmp.c
+++ b/job-qmp.c
@@ -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;
+}