]> git.proxmox.com Git - mirror_qemu.git/blame - job-qmp.c
hw/core/cpu: Remove final vestiges of dynamic state tracing
[mirror_qemu.git] / job-qmp.c
CommitLineData
1a90bc81
KW
1/*
2 * QMP interface for background jobs
3 *
4 * Copyright (c) 2011 IBM Corp.
5 * Copyright (c) 2012, 2018 Red Hat, Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25
26#include "qemu/osdep.h"
1a90bc81
KW
27#include "qemu/job.h"
28#include "qapi/qapi-commands-job.h"
29#include "qapi/error.h"
243af022 30#include "trace/trace-root.h"
1a90bc81 31
96241124 32/*
6f592e5a 33 * Get a job using its ID. Called with job_mutex held.
96241124 34 */
6f592e5a 35static Job *find_job_locked(const char *id, Error **errp)
1a90bc81
KW
36{
37 Job *job;
38
96241124 39 job = job_get_locked(id);
1a90bc81
KW
40 if (!job) {
41 error_setg(errp, "Job not found");
42 return NULL;
43 }
44
1a90bc81
KW
45 return job;
46}
47
48void qmp_job_cancel(const char *id, Error **errp)
49{
96241124
EGE
50 Job *job;
51
52 JOB_LOCK_GUARD();
6f592e5a 53 job = find_job_locked(id, errp);
1a90bc81
KW
54
55 if (!job) {
56 return;
57 }
58
59 trace_qmp_job_cancel(job);
96241124 60 job_user_cancel_locked(job, true, errp);
1a90bc81
KW
61}
62
63void qmp_job_pause(const char *id, Error **errp)
64{
96241124
EGE
65 Job *job;
66
67 JOB_LOCK_GUARD();
6f592e5a 68 job = find_job_locked(id, errp);
1a90bc81
KW
69
70 if (!job) {
71 return;
72 }
73
74 trace_qmp_job_pause(job);
96241124 75 job_user_pause_locked(job, errp);
1a90bc81
KW
76}
77
78void qmp_job_resume(const char *id, Error **errp)
79{
96241124
EGE
80 Job *job;
81
82 JOB_LOCK_GUARD();
6f592e5a 83 job = find_job_locked(id, errp);
1a90bc81
KW
84
85 if (!job) {
86 return;
87 }
88
89 trace_qmp_job_resume(job);
96241124 90 job_user_resume_locked(job, errp);
1a90bc81
KW
91}
92
93void qmp_job_complete(const char *id, Error **errp)
94{
96241124
EGE
95 Job *job;
96
97 JOB_LOCK_GUARD();
6f592e5a 98 job = find_job_locked(id, errp);
1a90bc81
KW
99
100 if (!job) {
101 return;
102 }
103
104 trace_qmp_job_complete(job);
96241124 105 job_complete_locked(job, errp);
1a90bc81
KW
106}
107
108void qmp_job_finalize(const char *id, Error **errp)
109{
96241124
EGE
110 Job *job;
111
112 JOB_LOCK_GUARD();
6f592e5a 113 job = find_job_locked(id, errp);
1a90bc81
KW
114
115 if (!job) {
116 return;
117 }
118
119 trace_qmp_job_finalize(job);
96241124
EGE
120 job_ref_locked(job);
121 job_finalize_locked(job, errp);
b660a84b 122
96241124 123 job_unref_locked(job);
1a90bc81
KW
124}
125
126void qmp_job_dismiss(const char *id, Error **errp)
127{
96241124
EGE
128 Job *job;
129
130 JOB_LOCK_GUARD();
6f592e5a 131 job = find_job_locked(id, errp);
1a90bc81
KW
132
133 if (!job) {
134 return;
135 }
136
137 trace_qmp_job_dismiss(job);
96241124 138 job_dismiss_locked(&job, errp);
1a90bc81 139}
456273b0 140
880eeec6
EGE
141/* Called with job_mutex held. */
142static JobInfo *job_query_single_locked(Job *job, Error **errp)
456273b0
KW
143{
144 JobInfo *info;
a7b4f8fc
EGE
145 uint64_t progress_current;
146 uint64_t progress_total;
456273b0
KW
147
148 assert(!job_is_internal(job));
a7b4f8fc
EGE
149 progress_get_snapshot(&job->progress, &progress_current,
150 &progress_total);
456273b0 151
456273b0
KW
152 info = g_new(JobInfo, 1);
153 *info = (JobInfo) {
154 .id = g_strdup(job->id),
155 .type = job_type(job),
156 .status = job->status,
a7b4f8fc
EGE
157 .current_progress = progress_current,
158 .total_progress = progress_total,
107111bf 159 .error = job->err ?
3d1f8b07 160 g_strdup(error_get_pretty(job->err)) : NULL,
456273b0
KW
161 };
162
163 return info;
164}
165
166JobInfoList *qmp_query_jobs(Error **errp)
167{
c3033fd3 168 JobInfoList *head = NULL, **tail = &head;
456273b0
KW
169 Job *job;
170
880eeec6
EGE
171 JOB_LOCK_GUARD();
172
173 for (job = job_next_locked(NULL); job; job = job_next_locked(job)) {
c3033fd3 174 JobInfo *value;
456273b0
KW
175
176 if (job_is_internal(job)) {
177 continue;
178 }
880eeec6 179 value = job_query_single_locked(job, errp);
c3033fd3 180 if (!value) {
456273b0
KW
181 qapi_free_JobInfoList(head);
182 return NULL;
183 }
c3033fd3 184 QAPI_LIST_APPEND(tail, value);
456273b0
KW
185 }
186
187 return head;
188}