]>
Commit | Line | Data |
---|---|---|
48a32bed | 1 | /* |
f1b3ccfa | 2 | * QEMU Management Protocol commands |
48a32bed AL |
3 | * |
4 | * Copyright IBM, Corp. 2011 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <aliguori@us.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
6b620ca3 PB |
12 | * Contributions after 2012-01-13 are licensed under the terms of the |
13 | * GNU GPL, version 2 or (at your option) any later version. | |
48a32bed AL |
14 | */ |
15 | ||
d38ea87a | 16 | #include "qemu/osdep.h" |
a8d25326 | 17 | #include "qemu-common.h" |
f348b6d1 | 18 | #include "qemu/cutils.h" |
922a01a0 | 19 | #include "qemu/option.h" |
a0b1a66e | 20 | #include "monitor/monitor.h" |
9c17d615 | 21 | #include "sysemu/sysemu.h" |
213dcb06 | 22 | #include "qemu/config-file.h" |
cea25275 | 23 | #include "qemu/uuid.h" |
8228e353 | 24 | #include "chardev/char.h" |
fbf796fd | 25 | #include "ui/qemu-spice.h" |
fb246f05 | 26 | #include "ui/console.h" |
9c17d615 | 27 | #include "sysemu/kvm.h" |
54d31236 | 28 | #include "sysemu/runstate.h" |
e6dba048 | 29 | #include "sysemu/runstate-action.h" |
9c17d615 | 30 | #include "sysemu/blockdev.h" |
373340b2 | 31 | #include "sysemu/block-backend.h" |
e688df6b | 32 | #include "qapi/error.h" |
27c9188f | 33 | #include "qapi/qapi-commands-acpi.h" |
5a16818b | 34 | #include "qapi/qapi-commands-block.h" |
fa4dcf57 | 35 | #include "qapi/qapi-commands-control.h" |
8ac25c84 | 36 | #include "qapi/qapi-commands-machine.h" |
112ed241 MA |
37 | #include "qapi/qapi-commands-misc.h" |
38 | #include "qapi/qapi-commands-ui.h" | |
37087fde | 39 | #include "qapi/type-helpers.h" |
cc7a8ea7 | 40 | #include "qapi/qmp/qerror.h" |
2cc0e2e8 | 41 | #include "hw/mem/memory-device.h" |
02419bcb | 42 | #include "hw/acpi/acpi_dev_interface.h" |
8dbbca5c | 43 | #include "hw/rdma/rdma.h" |
48a32bed AL |
44 | |
45 | NameInfo *qmp_query_name(Error **errp) | |
46 | { | |
47 | NameInfo *info = g_malloc0(sizeof(*info)); | |
48 | ||
49 | if (qemu_name) { | |
50 | info->has_name = true; | |
51 | info->name = g_strdup(qemu_name); | |
52 | } | |
53 | ||
54 | return info; | |
55 | } | |
b9c15f16 | 56 | |
292a2602 LC |
57 | KvmInfo *qmp_query_kvm(Error **errp) |
58 | { | |
59 | KvmInfo *info = g_malloc0(sizeof(*info)); | |
60 | ||
61 | info->enabled = kvm_enabled(); | |
4f9205be | 62 | info->present = accel_find("kvm"); |
292a2602 LC |
63 | |
64 | return info; | |
65 | } | |
66 | ||
efab767e LC |
67 | UuidInfo *qmp_query_uuid(Error **errp) |
68 | { | |
69 | UuidInfo *info = g_malloc0(sizeof(*info)); | |
efab767e | 70 | |
9c5ce8db | 71 | info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid); |
efab767e LC |
72 | return info; |
73 | } | |
74 | ||
7daecb30 | 75 | void qmp_quit(Error **errp) |
7a7f325e | 76 | { |
e6dba048 | 77 | shutdown_action = SHUTDOWN_ACTION_POWEROFF; |
92548938 | 78 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT); |
7a7f325e LC |
79 | } |
80 | ||
5f158f21 LC |
81 | void qmp_stop(Error **errp) |
82 | { | |
65d64f36 PX |
83 | /* if there is a dump in background, we should wait until the dump |
84 | * finished */ | |
85 | if (dump_in_progress()) { | |
86 | error_setg(errp, "There is a dump in process, please wait."); | |
87 | return; | |
88 | } | |
89 | ||
1e998146 PB |
90 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
91 | autostart = 0; | |
92 | } else { | |
93 | vm_stop(RUN_STATE_PAUSED); | |
94 | } | |
5f158f21 LC |
95 | } |
96 | ||
38d22653 LC |
97 | void qmp_system_reset(Error **errp) |
98 | { | |
92548938 | 99 | qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET); |
38d22653 | 100 | } |
5bc465e4 | 101 | |
ec48595e | 102 | void qmp_system_powerdown(Error **errp) |
5bc465e4 LC |
103 | { |
104 | qemu_system_powerdown_request(); | |
105 | } | |
755f1968 | 106 | |
e42e818b LC |
107 | void qmp_cont(Error **errp) |
108 | { | |
373340b2 | 109 | BlockBackend *blk; |
68d00e42 | 110 | BlockJob *job; |
788cf9f8 | 111 | Error *local_err = NULL; |
e42e818b | 112 | |
65d64f36 PX |
113 | /* if there is a dump in background, we should wait until the dump |
114 | * finished */ | |
115 | if (dump_in_progress()) { | |
116 | error_setg(errp, "There is a dump in process, please wait."); | |
117 | return; | |
118 | } | |
119 | ||
ede085b3 | 120 | if (runstate_needs_reset()) { |
f231b88d | 121 | error_setg(errp, "Resetting the Virtual Machine is required"); |
e42e818b | 122 | return; |
ad02b96a LC |
123 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
124 | return; | |
9183dd15 VSO |
125 | } else if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { |
126 | error_setg(errp, "Migration is not finalized yet"); | |
127 | return; | |
e42e818b LC |
128 | } |
129 | ||
373340b2 HR |
130 | for (blk = blk_next(NULL); blk; blk = blk_next(blk)) { |
131 | blk_iostatus_reset(blk); | |
ab31979a | 132 | } |
7c8eece4 | 133 | |
68d00e42 VSO |
134 | for (job = block_job_next(NULL); job; job = block_job_next(job)) { |
135 | block_job_iostatus_reset(job); | |
136 | } | |
137 | ||
76b1c7fe | 138 | /* Continuing after completed migration. Images have been inactivated to |
ace21a58 KW |
139 | * allow the destination to take control. Need to get control back now. |
140 | * | |
141 | * If there are no inactive block nodes (e.g. because the VM was just | |
142 | * paused rather than completing a migration), bdrv_inactivate_all() simply | |
143 | * doesn't do anything. */ | |
144 | bdrv_invalidate_cache_all(&local_err); | |
145 | if (local_err) { | |
146 | error_propagate(errp, local_err); | |
147 | return; | |
76b1c7fe KW |
148 | } |
149 | ||
1e998146 PB |
150 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
151 | autostart = 1; | |
152 | } else { | |
153 | vm_start(); | |
154 | } | |
e42e818b | 155 | } |
b4b12c62 | 156 | |
9b9df25a GH |
157 | void qmp_system_wakeup(Error **errp) |
158 | { | |
fb064112 DHB |
159 | if (!qemu_wakeup_suspend_enabled()) { |
160 | error_setg(errp, | |
161 | "wake-up from suspend is not supported by this guest"); | |
162 | return; | |
163 | } | |
164 | ||
165 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, errp); | |
9b9df25a GH |
166 | } |
167 | ||
fbf796fd LC |
168 | void qmp_set_password(const char *protocol, const char *password, |
169 | bool has_connected, const char *connected, Error **errp) | |
170 | { | |
171 | int disconnect_if_connected = 0; | |
172 | int fail_if_connected = 0; | |
173 | int rc; | |
174 | ||
175 | if (has_connected) { | |
176 | if (strcmp(connected, "fail") == 0) { | |
177 | fail_if_connected = 1; | |
178 | } else if (strcmp(connected, "disconnect") == 0) { | |
179 | disconnect_if_connected = 1; | |
180 | } else if (strcmp(connected, "keep") == 0) { | |
181 | /* nothing */ | |
182 | } else { | |
c6bd8c70 | 183 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
fbf796fd LC |
184 | return; |
185 | } | |
186 | } | |
187 | ||
188 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 189 | if (!qemu_using_spice(errp)) { |
fbf796fd LC |
190 | return; |
191 | } | |
08ad2626 | 192 | rc = qemu_spice.set_passwd(password, fail_if_connected, |
fbf796fd | 193 | disconnect_if_connected); |
9272186d | 194 | } else if (strcmp(protocol, "vnc") == 0) { |
fbf796fd LC |
195 | if (fail_if_connected || disconnect_if_connected) { |
196 | /* vnc supports "connected=keep" only */ | |
c6bd8c70 | 197 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
fbf796fd LC |
198 | return; |
199 | } | |
200 | /* Note that setting an empty password will not disable login through | |
201 | * this interface. */ | |
202 | rc = vnc_display_password(NULL, password); | |
9272186d MA |
203 | } else { |
204 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", | |
205 | "'vnc' or 'spice'"); | |
fbf796fd LC |
206 | return; |
207 | } | |
208 | ||
9272186d MA |
209 | if (rc != 0) { |
210 | error_setg(errp, "Could not set password"); | |
211 | } | |
fbf796fd | 212 | } |
9ad5372d LC |
213 | |
214 | void qmp_expire_password(const char *protocol, const char *whenstr, | |
215 | Error **errp) | |
216 | { | |
217 | time_t when; | |
218 | int rc; | |
219 | ||
220 | if (strcmp(whenstr, "now") == 0) { | |
221 | when = 0; | |
222 | } else if (strcmp(whenstr, "never") == 0) { | |
223 | when = TIME_MAX; | |
224 | } else if (whenstr[0] == '+') { | |
225 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); | |
226 | } else { | |
227 | when = strtoull(whenstr, NULL, 10); | |
228 | } | |
229 | ||
230 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 231 | if (!qemu_using_spice(errp)) { |
9ad5372d LC |
232 | return; |
233 | } | |
08ad2626 | 234 | rc = qemu_spice.set_pw_expire(when); |
9272186d | 235 | } else if (strcmp(protocol, "vnc") == 0) { |
9ad5372d | 236 | rc = vnc_display_pw_expire(NULL, when); |
9272186d MA |
237 | } else { |
238 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", | |
239 | "'vnc' or 'spice'"); | |
9ad5372d LC |
240 | return; |
241 | } | |
242 | ||
9272186d MA |
243 | if (rc != 0) { |
244 | error_setg(errp, "Could not set password expire time"); | |
245 | } | |
9ad5372d | 246 | } |
270b243f | 247 | |
333a96ec | 248 | #ifdef CONFIG_VNC |
270b243f LC |
249 | void qmp_change_vnc_password(const char *password, Error **errp) |
250 | { | |
251 | if (vnc_display_password(NULL, password) < 0) { | |
9272186d | 252 | error_setg(errp, "Could not set password"); |
270b243f LC |
253 | } |
254 | } | |
05eb4a25 | 255 | #endif |
5eeee3fa | 256 | |
b224e5e2 LC |
257 | void qmp_add_client(const char *protocol, const char *fdname, |
258 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, | |
259 | Error **errp) | |
260 | { | |
0ec7b3e7 | 261 | Chardev *s; |
b224e5e2 LC |
262 | int fd; |
263 | ||
947e4744 | 264 | fd = monitor_get_fd(monitor_cur(), fdname, errp); |
b224e5e2 LC |
265 | if (fd < 0) { |
266 | return; | |
267 | } | |
268 | ||
269 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 270 | if (!qemu_using_spice(errp)) { |
b224e5e2 LC |
271 | close(fd); |
272 | return; | |
273 | } | |
274 | skipauth = has_skipauth ? skipauth : false; | |
275 | tls = has_tls ? tls : false; | |
864a024c | 276 | if (qemu_spice.display_add_client(fd, skipauth, tls) < 0) { |
b224e5e2 LC |
277 | error_setg(errp, "spice failed to add client"); |
278 | close(fd); | |
279 | } | |
280 | return; | |
281 | #ifdef CONFIG_VNC | |
282 | } else if (strcmp(protocol, "vnc") == 0) { | |
283 | skipauth = has_skipauth ? skipauth : false; | |
284 | vnc_display_add_client(NULL, fd, skipauth); | |
285 | return; | |
286 | #endif | |
287 | } else if ((s = qemu_chr_find(protocol)) != NULL) { | |
288 | if (qemu_chr_add_client(s, fd) < 0) { | |
289 | error_setg(errp, "failed to add client"); | |
290 | close(fd); | |
291 | return; | |
292 | } | |
293 | return; | |
294 | } | |
295 | ||
296 | error_setg(errp, "protocol '%s' is invalid", protocol); | |
297 | close(fd); | |
298 | } | |
ab2d0531 | 299 | |
cff8b2c6 | 300 | |
6f2e2730 IM |
301 | MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) |
302 | { | |
2cc0e2e8 | 303 | return qmp_memory_device_list(); |
6f2e2730 | 304 | } |
02419bcb IM |
305 | |
306 | ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) | |
307 | { | |
308 | bool ambig; | |
309 | ACPIOSTInfoList *head = NULL; | |
310 | ACPIOSTInfoList **prev = &head; | |
311 | Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig); | |
312 | ||
313 | if (obj) { | |
314 | AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); | |
315 | AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj); | |
316 | ||
317 | adevc->ospm_status(adev, &prev); | |
318 | } else { | |
319 | error_setg(errp, "command is not supported, missing ACPI device"); | |
320 | } | |
321 | ||
322 | return head; | |
323 | } | |
9aa3397f VG |
324 | |
325 | MemoryInfo *qmp_query_memory_size_summary(Error **errp) | |
326 | { | |
327 | MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo)); | |
b326b6ea | 328 | MachineState *ms = MACHINE(qdev_get_machine()); |
9aa3397f | 329 | |
b326b6ea | 330 | mem_info->base_memory = ms->ram_size; |
9aa3397f VG |
331 | |
332 | mem_info->plugged_memory = get_plugged_memory_size(); | |
333 | mem_info->has_plugged_memory = | |
334 | mem_info->plugged_memory != (uint64_t)-1; | |
335 | ||
336 | return mem_info; | |
337 | } | |
9cc07651 ZC |
338 | |
339 | void qmp_display_reload(DisplayReloadOptions *arg, Error **errp) | |
340 | { | |
341 | switch (arg->type) { | |
342 | case DISPLAY_RELOAD_TYPE_VNC: | |
343 | #ifdef CONFIG_VNC | |
344 | if (arg->u.vnc.has_tls_certs && arg->u.vnc.tls_certs) { | |
345 | vnc_display_reload_certs(NULL, errp); | |
346 | } | |
347 | #else | |
348 | error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'"); | |
349 | #endif | |
350 | break; | |
351 | default: | |
352 | abort(); | |
353 | } | |
354 | } | |
37087fde DB |
355 | |
356 | #ifdef CONFIG_PROFILER | |
357 | ||
358 | int64_t dev_time; | |
359 | ||
360 | HumanReadableText *qmp_x_query_profile(Error **errp) | |
361 | { | |
362 | g_autoptr(GString) buf = g_string_new(""); | |
363 | static int64_t last_cpu_exec_time; | |
364 | int64_t cpu_exec_time; | |
365 | int64_t delta; | |
366 | ||
367 | cpu_exec_time = tcg_cpu_exec_time(); | |
368 | delta = cpu_exec_time - last_cpu_exec_time; | |
369 | ||
370 | g_string_append_printf(buf, "async time %" PRId64 " (%0.3f)\n", | |
371 | dev_time, dev_time / (double)NANOSECONDS_PER_SECOND); | |
372 | g_string_append_printf(buf, "qemu time %" PRId64 " (%0.3f)\n", | |
373 | delta, delta / (double)NANOSECONDS_PER_SECOND); | |
374 | last_cpu_exec_time = cpu_exec_time; | |
375 | dev_time = 0; | |
376 | ||
377 | return human_readable_text_from_str(buf); | |
378 | } | |
379 | #else | |
380 | HumanReadableText *qmp_x_query_profile(Error **errp) | |
381 | { | |
382 | error_setg(errp, "Internal profiler not compiled"); | |
383 | return NULL; | |
384 | } | |
385 | #endif | |
8dbbca5c DB |
386 | |
387 | static int qmp_x_query_rdma_foreach(Object *obj, void *opaque) | |
388 | { | |
389 | RdmaProvider *rdma; | |
390 | RdmaProviderClass *k; | |
391 | GString *buf = opaque; | |
392 | ||
393 | if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) { | |
394 | rdma = RDMA_PROVIDER(obj); | |
395 | k = RDMA_PROVIDER_GET_CLASS(obj); | |
396 | if (k->format_statistics) { | |
397 | k->format_statistics(rdma, buf); | |
398 | } else { | |
399 | g_string_append_printf(buf, | |
400 | "RDMA statistics not available for %s.\n", | |
401 | object_get_typename(obj)); | |
402 | } | |
403 | } | |
404 | ||
405 | return 0; | |
406 | } | |
407 | ||
408 | HumanReadableText *qmp_x_query_rdma(Error **errp) | |
409 | { | |
410 | g_autoptr(GString) buf = g_string_new(""); | |
411 | ||
412 | object_child_foreach_recursive(object_get_root(), | |
413 | qmp_x_query_rdma_foreach, buf); | |
414 | ||
415 | return human_readable_text_from_str(buf); | |
416 | } |