]>
git.proxmox.com Git - mirror_qemu.git/blob - job-qmp.c
2 * QMP interface for background jobs
4 * Copyright (c) 2011 IBM Corp.
5 * Copyright (c) 2012, 2018 Red Hat, Inc.
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
26 #include "qemu/osdep.h"
27 #include "qemu-common.h"
29 #include "qapi/qapi-commands-job.h"
30 #include "qapi/error.h"
31 #include "trace-root.h"
33 /* Get a job using its ID and acquire its AioContext */
34 static Job
*find_job(const char *id
, AioContext
**aio_context
, Error
**errp
)
42 error_setg(errp
, "Job not found");
46 *aio_context
= job
->aio_context
;
47 aio_context_acquire(*aio_context
);
52 void qmp_job_cancel(const char *id
, Error
**errp
)
54 AioContext
*aio_context
;
55 Job
*job
= find_job(id
, &aio_context
, errp
);
61 trace_qmp_job_cancel(job
);
62 job_user_cancel(job
, true, errp
);
63 aio_context_release(aio_context
);
66 void qmp_job_pause(const char *id
, Error
**errp
)
68 AioContext
*aio_context
;
69 Job
*job
= find_job(id
, &aio_context
, errp
);
75 trace_qmp_job_pause(job
);
76 job_user_pause(job
, errp
);
77 aio_context_release(aio_context
);
80 void qmp_job_resume(const char *id
, Error
**errp
)
82 AioContext
*aio_context
;
83 Job
*job
= find_job(id
, &aio_context
, errp
);
89 trace_qmp_job_resume(job
);
90 job_user_resume(job
, errp
);
91 aio_context_release(aio_context
);
94 void qmp_job_complete(const char *id
, Error
**errp
)
96 AioContext
*aio_context
;
97 Job
*job
= find_job(id
, &aio_context
, errp
);
103 trace_qmp_job_complete(job
);
104 job_complete(job
, errp
);
105 aio_context_release(aio_context
);
108 void qmp_job_finalize(const char *id
, Error
**errp
)
110 AioContext
*aio_context
;
111 Job
*job
= find_job(id
, &aio_context
, errp
);
117 trace_qmp_job_finalize(job
);
118 job_finalize(job
, errp
);
119 aio_context_release(aio_context
);
122 void qmp_job_dismiss(const char *id
, Error
**errp
)
124 AioContext
*aio_context
;
125 Job
*job
= find_job(id
, &aio_context
, errp
);
131 trace_qmp_job_dismiss(job
);
132 job_dismiss(&job
, errp
);
133 aio_context_release(aio_context
);
136 static JobInfo
*job_query_single(Job
*job
, Error
**errp
)
140 assert(!job_is_internal(job
));
142 info
= g_new(JobInfo
, 1);
144 .id
= g_strdup(job
->id
),
145 .type
= job_type(job
),
146 .status
= job
->status
,
147 .current_progress
= job
->progress_current
,
148 .total_progress
= job
->progress_total
,
149 .has_error
= !!job
->err
,
150 .error
= job
->err
? \
151 g_strdup(error_get_pretty(job
->err
)) : NULL
,
157 JobInfoList
*qmp_query_jobs(Error
**errp
)
159 JobInfoList
*head
= NULL
, **p_next
= &head
;
162 for (job
= job_next(NULL
); job
; job
= job_next(job
)) {
164 AioContext
*aio_context
;
166 if (job_is_internal(job
)) {
169 elem
= g_new0(JobInfoList
, 1);
170 aio_context
= job
->aio_context
;
171 aio_context_acquire(aio_context
);
172 elem
->value
= job_query_single(job
, errp
);
173 aio_context_release(aio_context
);
176 qapi_free_JobInfoList(head
);
180 p_next
= &elem
->next
;