]> git.proxmox.com Git - mirror_qemu.git/blame - qmp.c
jobs: fix stale wording
[mirror_qemu.git] / qmp.c
CommitLineData
48a32bed
AL
1/*
2 * QEMU Management Protocol
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"
67a1de0d 17#include "qemu-version.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
LC
25#include "ui/qemu-spice.h"
26#include "ui/vnc.h"
9c17d615
PB
27#include "sysemu/kvm.h"
28#include "sysemu/arch_init.h"
b4b12c62 29#include "hw/qdev.h"
9c17d615 30#include "sysemu/blockdev.h"
373340b2 31#include "sysemu/block-backend.h"
14cccb61 32#include "qom/qom-qobject.h"
e688df6b 33#include "qapi/error.h"
112ed241
MA
34#include "qapi/qapi-commands-block-core.h"
35#include "qapi/qapi-commands-misc.h"
36#include "qapi/qapi-commands-ui.h"
452fcdbc 37#include "qapi/qmp/qdict.h"
cc7a8ea7 38#include "qapi/qmp/qerror.h"
b3db211f 39#include "qapi/qobject-input-visitor.h"
69ca3ea5 40#include "hw/boards.h"
269e09f3 41#include "qom/object_interfaces.h"
2cc0e2e8 42#include "hw/mem/memory-device.h"
02419bcb 43#include "hw/acpi/acpi_dev_interface.h"
48a32bed
AL
44
45NameInfo *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
7daecb30 57VersionInfo *qmp_query_version(Error **errp)
b9c15f16 58{
4752cdbb 59 VersionInfo *info = g_new0(VersionInfo, 1);
b9c15f16 60
4752cdbb 61 info->qemu = g_new0(VersionTriple, 1);
3688d8c7
MAL
62 info->qemu->major = QEMU_VERSION_MAJOR;
63 info->qemu->minor = QEMU_VERSION_MINOR;
64 info->qemu->micro = QEMU_VERSION_MICRO;
b9c15f16
LC
65 info->package = g_strdup(QEMU_PKGVERSION);
66
67 return info;
68}
292a2602
LC
69
70KvmInfo *qmp_query_kvm(Error **errp)
71{
72 KvmInfo *info = g_malloc0(sizeof(*info));
73
74 info->enabled = kvm_enabled();
75 info->present = kvm_available();
76
77 return info;
78}
79
efab767e
LC
80UuidInfo *qmp_query_uuid(Error **errp)
81{
82 UuidInfo *info = g_malloc0(sizeof(*info));
efab767e 83
9c5ce8db 84 info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid);
efab767e
LC
85 return info;
86}
87
7daecb30 88void qmp_quit(Error **errp)
7a7f325e
LC
89{
90 no_shutdown = 0;
cf83f140 91 qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP);
7a7f325e
LC
92}
93
5f158f21
LC
94void qmp_stop(Error **errp)
95{
65d64f36
PX
96 /* if there is a dump in background, we should wait until the dump
97 * finished */
98 if (dump_in_progress()) {
99 error_setg(errp, "There is a dump in process, please wait.");
100 return;
101 }
102
1e998146
PB
103 if (runstate_check(RUN_STATE_INMIGRATE)) {
104 autostart = 0;
105 } else {
106 vm_stop(RUN_STATE_PAUSED);
107 }
5f158f21
LC
108}
109
38d22653
LC
110void qmp_system_reset(Error **errp)
111{
cf83f140 112 qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP);
38d22653 113}
5bc465e4
LC
114
115void qmp_system_powerdown(Error **erp)
116{
117 qemu_system_powerdown_request();
118}
755f1968 119
69ca3ea5
IM
120void qmp_cpu_add(int64_t id, Error **errp)
121{
0056ae24
MA
122 MachineClass *mc;
123
124 mc = MACHINE_GET_CLASS(current_machine);
958db90c
MA
125 if (mc->hot_add_cpu) {
126 mc->hot_add_cpu(id, errp);
69ca3ea5
IM
127 } else {
128 error_setg(errp, "Not supported");
129 }
130}
131
2b54aa87
LC
132#ifndef CONFIG_VNC
133/* If VNC support is enabled, the "true" query-vnc command is
134 defined in the VNC subsystem */
135VncInfo *qmp_query_vnc(Error **errp)
136{
c6bd8c70 137 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
2b54aa87
LC
138 return NULL;
139};
89db2177
LY
140
141VncInfo2List *qmp_query_vnc_servers(Error **errp)
142{
c6bd8c70 143 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
89db2177
LY
144 return NULL;
145};
2b54aa87 146#endif
d1f29646
LC
147
148#ifndef CONFIG_SPICE
ad0ec14b 149/*
1ef1cee7
MA
150 * qmp_unregister_commands_hack() ensures that QMP command query-spice
151 * exists only #ifdef CONFIG_SPICE. Necessary for an accurate
152 * query-commands result. However, the QAPI schema is blissfully
153 * unaware of that, and the QAPI code generator happily generates a
154 * dead qmp_marshal_query_spice() that calls qmp_query_spice().
155 * Provide it one, or else linking fails. FIXME Educate the QAPI
156 * schema on CONFIG_SPICE.
ad0ec14b 157 */
d1f29646
LC
158SpiceInfo *qmp_query_spice(Error **errp)
159{
ad0ec14b 160 abort();
d1f29646
LC
161};
162#endif
e42e818b 163
047f7038
IM
164void qmp_exit_preconfig(Error **errp)
165{
166 if (!runstate_check(RUN_STATE_PRECONFIG)) {
167 error_setg(errp, "The command is permitted only in '%s' state",
168 RunState_str(RUN_STATE_PRECONFIG));
169 return;
170 }
171 qemu_exit_preconfig_request();
172}
173
e42e818b
LC
174void qmp_cont(Error **errp)
175{
373340b2 176 BlockBackend *blk;
788cf9f8 177 Error *local_err = NULL;
e42e818b 178
65d64f36
PX
179 /* if there is a dump in background, we should wait until the dump
180 * finished */
181 if (dump_in_progress()) {
182 error_setg(errp, "There is a dump in process, please wait.");
183 return;
184 }
185
ede085b3 186 if (runstate_needs_reset()) {
f231b88d 187 error_setg(errp, "Resetting the Virtual Machine is required");
e42e818b 188 return;
ad02b96a
LC
189 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
190 return;
e42e818b
LC
191 }
192
373340b2
HR
193 for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
194 blk_iostatus_reset(blk);
ab31979a 195 }
7c8eece4 196
76b1c7fe 197 /* Continuing after completed migration. Images have been inactivated to
ace21a58
KW
198 * allow the destination to take control. Need to get control back now.
199 *
200 * If there are no inactive block nodes (e.g. because the VM was just
201 * paused rather than completing a migration), bdrv_inactivate_all() simply
202 * doesn't do anything. */
203 bdrv_invalidate_cache_all(&local_err);
204 if (local_err) {
205 error_propagate(errp, local_err);
206 return;
76b1c7fe
KW
207 }
208
1e998146
PB
209 if (runstate_check(RUN_STATE_INMIGRATE)) {
210 autostart = 1;
211 } else {
212 vm_start();
213 }
e42e818b 214}
b4b12c62 215
9b9df25a
GH
216void qmp_system_wakeup(Error **errp)
217{
218 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
219}
220
57c9fafe 221ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
b4b12c62 222{
57c9fafe 223 Object *obj;
b4b12c62 224 bool ambiguous = false;
57c9fafe
AL
225 ObjectPropertyInfoList *props = NULL;
226 ObjectProperty *prop;
7746abd8 227 ObjectPropertyIterator iter;
b4b12c62 228
57c9fafe
AL
229 obj = object_resolve_path(path, &ambiguous);
230 if (obj == NULL) {
79772087
MT
231 if (ambiguous) {
232 error_setg(errp, "Path '%s' is ambiguous", path);
233 } else {
75158ebb
MA
234 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
235 "Device '%s' not found", path);
79772087 236 }
b4b12c62
AL
237 return NULL;
238 }
239
7746abd8
DB
240 object_property_iter_init(&iter, obj);
241 while ((prop = object_property_iter_next(&iter))) {
57c9fafe 242 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
b4b12c62 243
57c9fafe 244 entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
b4b12c62
AL
245 entry->next = props;
246 props = entry;
247
248 entry->value->name = g_strdup(prop->name);
249 entry->value->type = g_strdup(prop->type);
250 }
251
252 return props;
253}
eb6e8ea5 254
6eb3937e
MA
255void qmp_qom_set(const char *path, const char *property, QObject *value,
256 Error **errp)
eb6e8ea5 257{
57c9fafe 258 Object *obj;
eb6e8ea5 259
57c9fafe
AL
260 obj = object_resolve_path(path, NULL);
261 if (!obj) {
485febc6 262 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 263 "Device '%s' not found", path);
485febc6 264 return;
eb6e8ea5
AL
265 }
266
485febc6 267 object_property_set_qobject(obj, value, property, errp);
eb6e8ea5
AL
268}
269
6eb3937e 270QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
eb6e8ea5 271{
57c9fafe 272 Object *obj;
eb6e8ea5 273
57c9fafe
AL
274 obj = object_resolve_path(path, NULL);
275 if (!obj) {
485febc6 276 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 277 "Device '%s' not found", path);
6eb3937e 278 return NULL;
eb6e8ea5
AL
279 }
280
6eb3937e 281 return object_property_get_qobject(obj, property, errp);
eb6e8ea5 282}
fbf796fd
LC
283
284void qmp_set_password(const char *protocol, const char *password,
285 bool has_connected, const char *connected, Error **errp)
286{
287 int disconnect_if_connected = 0;
288 int fail_if_connected = 0;
289 int rc;
290
291 if (has_connected) {
292 if (strcmp(connected, "fail") == 0) {
293 fail_if_connected = 1;
294 } else if (strcmp(connected, "disconnect") == 0) {
295 disconnect_if_connected = 1;
296 } else if (strcmp(connected, "keep") == 0) {
297 /* nothing */
298 } else {
c6bd8c70 299 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
300 return;
301 }
302 }
303
304 if (strcmp(protocol, "spice") == 0) {
b25d81ba 305 if (!qemu_using_spice(errp)) {
fbf796fd
LC
306 return;
307 }
308 rc = qemu_spice_set_passwd(password, fail_if_connected,
309 disconnect_if_connected);
310 if (rc != 0) {
c6bd8c70 311 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
312 }
313 return;
314 }
315
316 if (strcmp(protocol, "vnc") == 0) {
317 if (fail_if_connected || disconnect_if_connected) {
318 /* vnc supports "connected=keep" only */
c6bd8c70 319 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
320 return;
321 }
322 /* Note that setting an empty password will not disable login through
323 * this interface. */
324 rc = vnc_display_password(NULL, password);
325 if (rc < 0) {
c6bd8c70 326 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
327 }
328 return;
329 }
330
c6bd8c70 331 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
fbf796fd 332}
9ad5372d
LC
333
334void qmp_expire_password(const char *protocol, const char *whenstr,
335 Error **errp)
336{
337 time_t when;
338 int rc;
339
340 if (strcmp(whenstr, "now") == 0) {
341 when = 0;
342 } else if (strcmp(whenstr, "never") == 0) {
343 when = TIME_MAX;
344 } else if (whenstr[0] == '+') {
345 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
346 } else {
347 when = strtoull(whenstr, NULL, 10);
348 }
349
350 if (strcmp(protocol, "spice") == 0) {
b25d81ba 351 if (!qemu_using_spice(errp)) {
9ad5372d
LC
352 return;
353 }
354 rc = qemu_spice_set_pw_expire(when);
355 if (rc != 0) {
c6bd8c70 356 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
357 }
358 return;
359 }
360
361 if (strcmp(protocol, "vnc") == 0) {
362 rc = vnc_display_pw_expire(NULL, when);
363 if (rc != 0) {
c6bd8c70 364 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
365 }
366 return;
367 }
368
c6bd8c70 369 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
9ad5372d 370}
270b243f 371
333a96ec 372#ifdef CONFIG_VNC
270b243f
LC
373void qmp_change_vnc_password(const char *password, Error **errp)
374{
375 if (vnc_display_password(NULL, password) < 0) {
c6bd8c70 376 error_setg(errp, QERR_SET_PASSWD_FAILED);
270b243f
LC
377 }
378}
333a96ec 379
007fcd3e 380static void qmp_change_vnc_listen(const char *target, Error **errp)
333a96ec 381{
4db14629
GH
382 QemuOptsList *olist = qemu_find_opts("vnc");
383 QemuOpts *opts;
384
385 if (strstr(target, "id=")) {
386 error_setg(errp, "id not supported");
387 return;
388 }
389
390 opts = qemu_opts_find(olist, "default");
391 if (opts) {
392 qemu_opts_del(opts);
393 }
70b94331 394 opts = vnc_parse(target, errp);
f7801c5c
GA
395 if (!opts) {
396 return;
397 }
398
4db14629 399 vnc_display_open("default", errp);
333a96ec
LC
400}
401
402static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
403 Error **errp)
404{
405 if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
406 if (!has_arg) {
c6bd8c70 407 error_setg(errp, QERR_MISSING_PARAMETER, "password");
333a96ec
LC
408 } else {
409 qmp_change_vnc_password(arg, errp);
410 }
411 } else {
412 qmp_change_vnc_listen(target, errp);
413 }
414}
415#else
416void qmp_change_vnc_password(const char *password, Error **errp)
417{
c6bd8c70 418 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
419}
420static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
421 Error **errp)
422{
c6bd8c70 423 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
424}
425#endif /* !CONFIG_VNC */
426
427void qmp_change(const char *device, const char *target,
7daecb30 428 bool has_arg, const char *arg, Error **errp)
333a96ec
LC
429{
430 if (strcmp(device, "vnc") == 0) {
7daecb30 431 qmp_change_vnc(target, has_arg, arg, errp);
333a96ec 432 } else {
70e2cb3b
KW
433 qmp_blockdev_change_medium(true, device, false, NULL, target,
434 has_arg, arg, false, 0, errp);
333a96ec
LC
435 }
436}
5eeee3fa
AL
437
438static void qom_list_types_tramp(ObjectClass *klass, void *data)
439{
440 ObjectTypeInfoList *e, **pret = data;
441 ObjectTypeInfo *info;
f86285c5 442 ObjectClass *parent = object_class_get_parent(klass);
5eeee3fa
AL
443
444 info = g_malloc0(sizeof(*info));
445 info->name = g_strdup(object_class_get_name(klass));
87467eae 446 info->has_abstract = info->abstract = object_class_is_abstract(klass);
f86285c5
EH
447 if (parent) {
448 info->has_parent = true;
449 info->parent = g_strdup(object_class_get_name(parent));
450 }
5eeee3fa
AL
451
452 e = g_malloc0(sizeof(*e));
453 e->value = info;
454 e->next = *pret;
455 *pret = e;
456}
457
458ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
459 const char *implements,
460 bool has_abstract,
461 bool abstract,
462 Error **errp)
463{
464 ObjectTypeInfoList *ret = NULL;
465
466 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
467
468 return ret;
469}
1daa31b9 470
f4eb32b5
SH
471/* Return a DevicePropertyInfo for a qdev property.
472 *
473 * If a qdev property with the given name does not exist, use the given default
474 * type. If the qdev property info should not be shown, return NULL.
475 *
476 * The caller must free the return value.
477 */
35f63767
AK
478static ObjectPropertyInfo *make_device_property_info(ObjectClass *klass,
479 const char *name,
480 const char *default_type,
481 const char *description)
f4eb32b5 482{
35f63767 483 ObjectPropertyInfo *info;
f4eb32b5
SH
484 Property *prop;
485
486 do {
487 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
488 if (strcmp(name, prop->name) != 0) {
489 continue;
490 }
491
492 /*
493 * TODO Properties without a parser are just for dirty hacks.
494 * qdev_prop_ptr is the only such PropertyInfo. It's marked
495 * for removal. This conditional should be removed along with
496 * it.
497 */
faabdbb7 498 if (!prop->info->set && !prop->info->create) {
f4eb32b5
SH
499 return NULL; /* no way to set it, don't show */
500 }
501
502 info = g_malloc0(sizeof(*info));
503 info->name = g_strdup(prop->name);
75ab9053
FZ
504 info->type = default_type ? g_strdup(default_type)
505 : g_strdup(prop->info->name);
07d09c58
GA
506 info->has_description = !!prop->info->description;
507 info->description = g_strdup(prop->info->description);
f4eb32b5
SH
508 return info;
509 }
510 klass = object_class_get_parent(klass);
511 } while (klass != object_class_by_name(TYPE_DEVICE));
512
513 /* Not a qdev property, use the default type */
514 info = g_malloc0(sizeof(*info));
515 info->name = g_strdup(name);
516 info->type = g_strdup(default_type);
07d09c58
GA
517 info->has_description = !!description;
518 info->description = g_strdup(description);
519
f4eb32b5
SH
520 return info;
521}
522
35f63767
AK
523ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
524 Error **errp)
1daa31b9
AL
525{
526 ObjectClass *klass;
f4eb32b5
SH
527 Object *obj;
528 ObjectProperty *prop;
7746abd8 529 ObjectPropertyIterator iter;
35f63767 530 ObjectPropertyInfoList *prop_list = NULL;
1daa31b9
AL
531
532 klass = object_class_by_name(typename);
533 if (klass == NULL) {
75158ebb
MA
534 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
535 "Device '%s' not found", typename);
1daa31b9
AL
536 return NULL;
537 }
538
539 klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
540 if (klass == NULL) {
7a8c153f 541 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE);
1daa31b9
AL
542 return NULL;
543 }
544
edb1523d 545 if (object_class_is_abstract(klass)) {
7a8c153f 546 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
edb1523d
MA
547 "non-abstract device type");
548 return NULL;
549 }
550
f4eb32b5 551 obj = object_new(typename);
1daa31b9 552
7746abd8
DB
553 object_property_iter_init(&iter, obj);
554 while ((prop = object_property_iter_next(&iter))) {
35f63767
AK
555 ObjectPropertyInfo *info;
556 ObjectPropertyInfoList *entry;
f4eb32b5
SH
557
558 /* Skip Object and DeviceState properties */
559 if (strcmp(prop->name, "type") == 0 ||
560 strcmp(prop->name, "realized") == 0 ||
561 strcmp(prop->name, "hotpluggable") == 0 ||
4115dd65 562 strcmp(prop->name, "hotplugged") == 0 ||
f4eb32b5
SH
563 strcmp(prop->name, "parent_bus") == 0) {
564 continue;
565 }
1daa31b9 566
f4eb32b5
SH
567 /* Skip legacy properties since they are just string versions of
568 * properties that we already list.
569 */
570 if (strstart(prop->name, "legacy-", NULL)) {
571 continue;
572 }
1daa31b9 573
07d09c58
GA
574 info = make_device_property_info(klass, prop->name, prop->type,
575 prop->description);
f4eb32b5
SH
576 if (!info) {
577 continue;
1daa31b9 578 }
f4eb32b5
SH
579
580 entry = g_malloc0(sizeof(*entry));
961c47bb
AK
581 entry->value = info;
582 entry->next = prop_list;
583 prop_list = entry;
584 }
585
586 object_unref(obj);
587
588 return prop_list;
589}
590
591ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
592 Error **errp)
593{
594 ObjectClass *klass;
595 Object *obj = NULL;
596 ObjectProperty *prop;
597 ObjectPropertyIterator iter;
598 ObjectPropertyInfoList *prop_list = NULL;
599
600 klass = object_class_by_name(typename);
601 if (klass == NULL) {
602 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
603 "Class '%s' not found", typename);
604 return NULL;
605 }
606
607 klass = object_class_dynamic_cast(klass, TYPE_OBJECT);
608 if (klass == NULL) {
609 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_OBJECT);
610 return NULL;
611 }
612
613 if (object_class_is_abstract(klass)) {
614 object_class_property_iter_init(&iter, klass);
615 } else {
616 obj = object_new(typename);
617 object_property_iter_init(&iter, obj);
618 }
619 while ((prop = object_property_iter_next(&iter))) {
620 ObjectPropertyInfo *info;
621 ObjectPropertyInfoList *entry;
622
623 info = g_malloc0(sizeof(*info));
624 info->name = g_strdup(prop->name);
625 info->type = g_strdup(prop->type);
626 info->has_description = !!prop->description;
627 info->description = g_strdup(prop->description);
628
629 entry = g_malloc0(sizeof(*entry));
f4eb32b5
SH
630 entry->value = info;
631 entry->next = prop_list;
632 prop_list = entry;
633 }
634
635 object_unref(obj);
1daa31b9
AL
636
637 return prop_list;
638}
e4e31c63 639
76b64a7a
AL
640CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
641{
642 return arch_query_cpu_definitions(errp);
643}
644
e09484ef
DH
645CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
646 CpuModelInfo *model,
647 Error **errp)
648{
649 return arch_query_cpu_model_expansion(type, model, errp);
650}
651
0031e0d6
DH
652CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
653 CpuModelInfo *modelb,
654 Error **errp)
655{
656 return arch_query_cpu_model_comparison(modela, modelb, errp);
657}
658
b18b6043
DH
659CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela,
660 CpuModelInfo *modelb,
661 Error **errp)
662{
663 return arch_query_cpu_model_baseline(modela, modelb, errp);
664}
665
b224e5e2
LC
666void qmp_add_client(const char *protocol, const char *fdname,
667 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
668 Error **errp)
669{
0ec7b3e7 670 Chardev *s;
b224e5e2
LC
671 int fd;
672
673 fd = monitor_get_fd(cur_mon, fdname, errp);
674 if (fd < 0) {
675 return;
676 }
677
678 if (strcmp(protocol, "spice") == 0) {
b25d81ba 679 if (!qemu_using_spice(errp)) {
b224e5e2
LC
680 close(fd);
681 return;
682 }
683 skipauth = has_skipauth ? skipauth : false;
684 tls = has_tls ? tls : false;
685 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
686 error_setg(errp, "spice failed to add client");
687 close(fd);
688 }
689 return;
690#ifdef CONFIG_VNC
691 } else if (strcmp(protocol, "vnc") == 0) {
692 skipauth = has_skipauth ? skipauth : false;
693 vnc_display_add_client(NULL, fd, skipauth);
694 return;
695#endif
696 } else if ((s = qemu_chr_find(protocol)) != NULL) {
697 if (qemu_chr_add_client(s, fd) < 0) {
698 error_setg(errp, "failed to add client");
699 close(fd);
700 return;
701 }
702 return;
703 }
704
705 error_setg(errp, "protocol '%s' is invalid", protocol);
706 close(fd);
707}
ab2d0531 708
cff8b2c6 709
6eb3937e
MA
710void qmp_object_add(const char *type, const char *id,
711 bool has_props, QObject *props, Error **errp)
cff8b2c6 712{
e64c75a9 713 QDict *pdict;
b70ce101 714 Visitor *v;
90998d58 715 Object *obj;
cff8b2c6
PB
716
717 if (props) {
7dc847eb 718 pdict = qobject_to(QDict, props);
cff8b2c6 719 if (!pdict) {
485febc6
MA
720 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
721 return;
cff8b2c6 722 }
cb3e7f08 723 qobject_ref(pdict);
e64c75a9
MAL
724 } else {
725 pdict = qdict_new();
cff8b2c6
PB
726 }
727
048abb7b 728 v = qobject_input_visitor_new(QOBJECT(pdict));
b70ce101
EB
729 obj = user_creatable_add_type(type, id, pdict, v, errp);
730 visit_free(v);
90998d58
DB
731 if (obj) {
732 object_unref(obj);
733 }
cb3e7f08 734 qobject_unref(pdict);
cff8b2c6
PB
735}
736
ab2d0531
PB
737void qmp_object_del(const char *id, Error **errp)
738{
90998d58 739 user_creatable_del(id, errp);
ab2d0531 740}
6f2e2730
IM
741
742MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
743{
2cc0e2e8 744 return qmp_memory_device_list();
6f2e2730 745}
02419bcb
IM
746
747ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
748{
749 bool ambig;
750 ACPIOSTInfoList *head = NULL;
751 ACPIOSTInfoList **prev = &head;
752 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
753
754 if (obj) {
755 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
756 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
757
758 adevc->ospm_status(adev, &prev);
759 } else {
760 error_setg(errp, "command is not supported, missing ACPI device");
761 }
762
763 return head;
764}
9aa3397f
VG
765
766MemoryInfo *qmp_query_memory_size_summary(Error **errp)
767{
768 MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
769
770 mem_info->base_memory = ram_size;
771
772 mem_info->plugged_memory = get_plugged_memory_size();
773 mem_info->has_plugged_memory =
774 mem_info->plugged_memory != (uint64_t)-1;
775
776 return mem_info;
777}
469638f9
PX
778
779static QemuSemaphore x_oob_test_sem;
780
781static void __attribute__((constructor)) x_oob_test_init(void)
782{
783 qemu_sem_init(&x_oob_test_sem, 0);
784}
785
786void qmp_x_oob_test(bool lock, Error **errp)
787{
788 if (lock) {
789 qemu_sem_wait(&x_oob_test_sem);
790 } else {
791 qemu_sem_post(&x_oob_test_sem);
792 }
793}