]> git.proxmox.com Git - mirror_qemu.git/blame - qmp.c
qobject: use a QObjectBase_ struct
[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"
6f2e2730 42#include "hw/mem/pc-dimm.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
e42e818b
LC
164void qmp_cont(Error **errp)
165{
373340b2 166 BlockBackend *blk;
788cf9f8 167 Error *local_err = NULL;
e42e818b 168
65d64f36
PX
169 /* if there is a dump in background, we should wait until the dump
170 * finished */
171 if (dump_in_progress()) {
172 error_setg(errp, "There is a dump in process, please wait.");
173 return;
174 }
175
ede085b3 176 if (runstate_needs_reset()) {
f231b88d 177 error_setg(errp, "Resetting the Virtual Machine is required");
e42e818b 178 return;
ad02b96a
LC
179 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
180 return;
e42e818b
LC
181 }
182
373340b2
HR
183 for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
184 blk_iostatus_reset(blk);
ab31979a 185 }
7c8eece4 186
76b1c7fe 187 /* Continuing after completed migration. Images have been inactivated to
ace21a58
KW
188 * allow the destination to take control. Need to get control back now.
189 *
190 * If there are no inactive block nodes (e.g. because the VM was just
191 * paused rather than completing a migration), bdrv_inactivate_all() simply
192 * doesn't do anything. */
193 bdrv_invalidate_cache_all(&local_err);
194 if (local_err) {
195 error_propagate(errp, local_err);
196 return;
76b1c7fe
KW
197 }
198
1e998146
PB
199 if (runstate_check(RUN_STATE_INMIGRATE)) {
200 autostart = 1;
201 } else {
202 vm_start();
203 }
e42e818b 204}
b4b12c62 205
9b9df25a
GH
206void qmp_system_wakeup(Error **errp)
207{
208 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
209}
210
57c9fafe 211ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
b4b12c62 212{
57c9fafe 213 Object *obj;
b4b12c62 214 bool ambiguous = false;
57c9fafe
AL
215 ObjectPropertyInfoList *props = NULL;
216 ObjectProperty *prop;
7746abd8 217 ObjectPropertyIterator iter;
b4b12c62 218
57c9fafe
AL
219 obj = object_resolve_path(path, &ambiguous);
220 if (obj == NULL) {
79772087
MT
221 if (ambiguous) {
222 error_setg(errp, "Path '%s' is ambiguous", path);
223 } else {
75158ebb
MA
224 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
225 "Device '%s' not found", path);
79772087 226 }
b4b12c62
AL
227 return NULL;
228 }
229
7746abd8
DB
230 object_property_iter_init(&iter, obj);
231 while ((prop = object_property_iter_next(&iter))) {
57c9fafe 232 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
b4b12c62 233
57c9fafe 234 entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
b4b12c62
AL
235 entry->next = props;
236 props = entry;
237
238 entry->value->name = g_strdup(prop->name);
239 entry->value->type = g_strdup(prop->type);
240 }
241
242 return props;
243}
eb6e8ea5 244
6eb3937e
MA
245void qmp_qom_set(const char *path, const char *property, QObject *value,
246 Error **errp)
eb6e8ea5 247{
57c9fafe 248 Object *obj;
eb6e8ea5 249
57c9fafe
AL
250 obj = object_resolve_path(path, NULL);
251 if (!obj) {
485febc6 252 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 253 "Device '%s' not found", path);
485febc6 254 return;
eb6e8ea5
AL
255 }
256
485febc6 257 object_property_set_qobject(obj, value, property, errp);
eb6e8ea5
AL
258}
259
6eb3937e 260QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
eb6e8ea5 261{
57c9fafe 262 Object *obj;
eb6e8ea5 263
57c9fafe
AL
264 obj = object_resolve_path(path, NULL);
265 if (!obj) {
485febc6 266 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 267 "Device '%s' not found", path);
6eb3937e 268 return NULL;
eb6e8ea5
AL
269 }
270
6eb3937e 271 return object_property_get_qobject(obj, property, errp);
eb6e8ea5 272}
fbf796fd
LC
273
274void qmp_set_password(const char *protocol, const char *password,
275 bool has_connected, const char *connected, Error **errp)
276{
277 int disconnect_if_connected = 0;
278 int fail_if_connected = 0;
279 int rc;
280
281 if (has_connected) {
282 if (strcmp(connected, "fail") == 0) {
283 fail_if_connected = 1;
284 } else if (strcmp(connected, "disconnect") == 0) {
285 disconnect_if_connected = 1;
286 } else if (strcmp(connected, "keep") == 0) {
287 /* nothing */
288 } else {
c6bd8c70 289 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
290 return;
291 }
292 }
293
294 if (strcmp(protocol, "spice") == 0) {
b25d81ba 295 if (!qemu_using_spice(errp)) {
fbf796fd
LC
296 return;
297 }
298 rc = qemu_spice_set_passwd(password, fail_if_connected,
299 disconnect_if_connected);
300 if (rc != 0) {
c6bd8c70 301 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
302 }
303 return;
304 }
305
306 if (strcmp(protocol, "vnc") == 0) {
307 if (fail_if_connected || disconnect_if_connected) {
308 /* vnc supports "connected=keep" only */
c6bd8c70 309 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
310 return;
311 }
312 /* Note that setting an empty password will not disable login through
313 * this interface. */
314 rc = vnc_display_password(NULL, password);
315 if (rc < 0) {
c6bd8c70 316 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
317 }
318 return;
319 }
320
c6bd8c70 321 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
fbf796fd 322}
9ad5372d
LC
323
324void qmp_expire_password(const char *protocol, const char *whenstr,
325 Error **errp)
326{
327 time_t when;
328 int rc;
329
330 if (strcmp(whenstr, "now") == 0) {
331 when = 0;
332 } else if (strcmp(whenstr, "never") == 0) {
333 when = TIME_MAX;
334 } else if (whenstr[0] == '+') {
335 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
336 } else {
337 when = strtoull(whenstr, NULL, 10);
338 }
339
340 if (strcmp(protocol, "spice") == 0) {
b25d81ba 341 if (!qemu_using_spice(errp)) {
9ad5372d
LC
342 return;
343 }
344 rc = qemu_spice_set_pw_expire(when);
345 if (rc != 0) {
c6bd8c70 346 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
347 }
348 return;
349 }
350
351 if (strcmp(protocol, "vnc") == 0) {
352 rc = vnc_display_pw_expire(NULL, when);
353 if (rc != 0) {
c6bd8c70 354 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
355 }
356 return;
357 }
358
c6bd8c70 359 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
9ad5372d 360}
270b243f 361
333a96ec 362#ifdef CONFIG_VNC
270b243f
LC
363void qmp_change_vnc_password(const char *password, Error **errp)
364{
365 if (vnc_display_password(NULL, password) < 0) {
c6bd8c70 366 error_setg(errp, QERR_SET_PASSWD_FAILED);
270b243f
LC
367 }
368}
333a96ec 369
007fcd3e 370static void qmp_change_vnc_listen(const char *target, Error **errp)
333a96ec 371{
4db14629
GH
372 QemuOptsList *olist = qemu_find_opts("vnc");
373 QemuOpts *opts;
374
375 if (strstr(target, "id=")) {
376 error_setg(errp, "id not supported");
377 return;
378 }
379
380 opts = qemu_opts_find(olist, "default");
381 if (opts) {
382 qemu_opts_del(opts);
383 }
70b94331 384 opts = vnc_parse(target, errp);
f7801c5c
GA
385 if (!opts) {
386 return;
387 }
388
4db14629 389 vnc_display_open("default", errp);
333a96ec
LC
390}
391
392static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
393 Error **errp)
394{
395 if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
396 if (!has_arg) {
c6bd8c70 397 error_setg(errp, QERR_MISSING_PARAMETER, "password");
333a96ec
LC
398 } else {
399 qmp_change_vnc_password(arg, errp);
400 }
401 } else {
402 qmp_change_vnc_listen(target, errp);
403 }
404}
405#else
406void qmp_change_vnc_password(const char *password, Error **errp)
407{
c6bd8c70 408 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
409}
410static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
411 Error **errp)
412{
c6bd8c70 413 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
414}
415#endif /* !CONFIG_VNC */
416
417void qmp_change(const char *device, const char *target,
7daecb30 418 bool has_arg, const char *arg, Error **errp)
333a96ec
LC
419{
420 if (strcmp(device, "vnc") == 0) {
7daecb30 421 qmp_change_vnc(target, has_arg, arg, errp);
333a96ec 422 } else {
70e2cb3b
KW
423 qmp_blockdev_change_medium(true, device, false, NULL, target,
424 has_arg, arg, false, 0, errp);
333a96ec
LC
425 }
426}
5eeee3fa
AL
427
428static void qom_list_types_tramp(ObjectClass *klass, void *data)
429{
430 ObjectTypeInfoList *e, **pret = data;
431 ObjectTypeInfo *info;
f86285c5 432 ObjectClass *parent = object_class_get_parent(klass);
5eeee3fa
AL
433
434 info = g_malloc0(sizeof(*info));
435 info->name = g_strdup(object_class_get_name(klass));
87467eae 436 info->has_abstract = info->abstract = object_class_is_abstract(klass);
f86285c5
EH
437 if (parent) {
438 info->has_parent = true;
439 info->parent = g_strdup(object_class_get_name(parent));
440 }
5eeee3fa
AL
441
442 e = g_malloc0(sizeof(*e));
443 e->value = info;
444 e->next = *pret;
445 *pret = e;
446}
447
448ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
449 const char *implements,
450 bool has_abstract,
451 bool abstract,
452 Error **errp)
453{
454 ObjectTypeInfoList *ret = NULL;
455
456 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
457
458 return ret;
459}
1daa31b9 460
f4eb32b5
SH
461/* Return a DevicePropertyInfo for a qdev property.
462 *
463 * If a qdev property with the given name does not exist, use the given default
464 * type. If the qdev property info should not be shown, return NULL.
465 *
466 * The caller must free the return value.
467 */
35f63767
AK
468static ObjectPropertyInfo *make_device_property_info(ObjectClass *klass,
469 const char *name,
470 const char *default_type,
471 const char *description)
f4eb32b5 472{
35f63767 473 ObjectPropertyInfo *info;
f4eb32b5
SH
474 Property *prop;
475
476 do {
477 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
478 if (strcmp(name, prop->name) != 0) {
479 continue;
480 }
481
482 /*
483 * TODO Properties without a parser are just for dirty hacks.
484 * qdev_prop_ptr is the only such PropertyInfo. It's marked
485 * for removal. This conditional should be removed along with
486 * it.
487 */
faabdbb7 488 if (!prop->info->set && !prop->info->create) {
f4eb32b5
SH
489 return NULL; /* no way to set it, don't show */
490 }
491
492 info = g_malloc0(sizeof(*info));
493 info->name = g_strdup(prop->name);
75ab9053
FZ
494 info->type = default_type ? g_strdup(default_type)
495 : g_strdup(prop->info->name);
07d09c58
GA
496 info->has_description = !!prop->info->description;
497 info->description = g_strdup(prop->info->description);
f4eb32b5
SH
498 return info;
499 }
500 klass = object_class_get_parent(klass);
501 } while (klass != object_class_by_name(TYPE_DEVICE));
502
503 /* Not a qdev property, use the default type */
504 info = g_malloc0(sizeof(*info));
505 info->name = g_strdup(name);
506 info->type = g_strdup(default_type);
07d09c58
GA
507 info->has_description = !!description;
508 info->description = g_strdup(description);
509
f4eb32b5
SH
510 return info;
511}
512
35f63767
AK
513ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
514 Error **errp)
1daa31b9
AL
515{
516 ObjectClass *klass;
f4eb32b5
SH
517 Object *obj;
518 ObjectProperty *prop;
7746abd8 519 ObjectPropertyIterator iter;
35f63767 520 ObjectPropertyInfoList *prop_list = NULL;
1daa31b9
AL
521
522 klass = object_class_by_name(typename);
523 if (klass == NULL) {
75158ebb
MA
524 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
525 "Device '%s' not found", typename);
1daa31b9
AL
526 return NULL;
527 }
528
529 klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
530 if (klass == NULL) {
7a8c153f 531 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE);
1daa31b9
AL
532 return NULL;
533 }
534
edb1523d 535 if (object_class_is_abstract(klass)) {
7a8c153f 536 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
edb1523d
MA
537 "non-abstract device type");
538 return NULL;
539 }
540
f4eb32b5 541 obj = object_new(typename);
1daa31b9 542
7746abd8
DB
543 object_property_iter_init(&iter, obj);
544 while ((prop = object_property_iter_next(&iter))) {
35f63767
AK
545 ObjectPropertyInfo *info;
546 ObjectPropertyInfoList *entry;
f4eb32b5
SH
547
548 /* Skip Object and DeviceState properties */
549 if (strcmp(prop->name, "type") == 0 ||
550 strcmp(prop->name, "realized") == 0 ||
551 strcmp(prop->name, "hotpluggable") == 0 ||
4115dd65 552 strcmp(prop->name, "hotplugged") == 0 ||
f4eb32b5
SH
553 strcmp(prop->name, "parent_bus") == 0) {
554 continue;
555 }
1daa31b9 556
f4eb32b5
SH
557 /* Skip legacy properties since they are just string versions of
558 * properties that we already list.
559 */
560 if (strstart(prop->name, "legacy-", NULL)) {
561 continue;
562 }
1daa31b9 563
07d09c58
GA
564 info = make_device_property_info(klass, prop->name, prop->type,
565 prop->description);
f4eb32b5
SH
566 if (!info) {
567 continue;
1daa31b9 568 }
f4eb32b5
SH
569
570 entry = g_malloc0(sizeof(*entry));
961c47bb
AK
571 entry->value = info;
572 entry->next = prop_list;
573 prop_list = entry;
574 }
575
576 object_unref(obj);
577
578 return prop_list;
579}
580
581ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
582 Error **errp)
583{
584 ObjectClass *klass;
585 Object *obj = NULL;
586 ObjectProperty *prop;
587 ObjectPropertyIterator iter;
588 ObjectPropertyInfoList *prop_list = NULL;
589
590 klass = object_class_by_name(typename);
591 if (klass == NULL) {
592 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
593 "Class '%s' not found", typename);
594 return NULL;
595 }
596
597 klass = object_class_dynamic_cast(klass, TYPE_OBJECT);
598 if (klass == NULL) {
599 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_OBJECT);
600 return NULL;
601 }
602
603 if (object_class_is_abstract(klass)) {
604 object_class_property_iter_init(&iter, klass);
605 } else {
606 obj = object_new(typename);
607 object_property_iter_init(&iter, obj);
608 }
609 while ((prop = object_property_iter_next(&iter))) {
610 ObjectPropertyInfo *info;
611 ObjectPropertyInfoList *entry;
612
613 info = g_malloc0(sizeof(*info));
614 info->name = g_strdup(prop->name);
615 info->type = g_strdup(prop->type);
616 info->has_description = !!prop->description;
617 info->description = g_strdup(prop->description);
618
619 entry = g_malloc0(sizeof(*entry));
f4eb32b5
SH
620 entry->value = info;
621 entry->next = prop_list;
622 prop_list = entry;
623 }
624
625 object_unref(obj);
1daa31b9
AL
626
627 return prop_list;
628}
e4e31c63 629
76b64a7a
AL
630CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
631{
632 return arch_query_cpu_definitions(errp);
633}
634
e09484ef
DH
635CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
636 CpuModelInfo *model,
637 Error **errp)
638{
639 return arch_query_cpu_model_expansion(type, model, errp);
640}
641
0031e0d6
DH
642CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
643 CpuModelInfo *modelb,
644 Error **errp)
645{
646 return arch_query_cpu_model_comparison(modela, modelb, errp);
647}
648
b18b6043
DH
649CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela,
650 CpuModelInfo *modelb,
651 Error **errp)
652{
653 return arch_query_cpu_model_baseline(modela, modelb, errp);
654}
655
b224e5e2
LC
656void qmp_add_client(const char *protocol, const char *fdname,
657 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
658 Error **errp)
659{
0ec7b3e7 660 Chardev *s;
b224e5e2
LC
661 int fd;
662
663 fd = monitor_get_fd(cur_mon, fdname, errp);
664 if (fd < 0) {
665 return;
666 }
667
668 if (strcmp(protocol, "spice") == 0) {
b25d81ba 669 if (!qemu_using_spice(errp)) {
b224e5e2
LC
670 close(fd);
671 return;
672 }
673 skipauth = has_skipauth ? skipauth : false;
674 tls = has_tls ? tls : false;
675 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
676 error_setg(errp, "spice failed to add client");
677 close(fd);
678 }
679 return;
680#ifdef CONFIG_VNC
681 } else if (strcmp(protocol, "vnc") == 0) {
682 skipauth = has_skipauth ? skipauth : false;
683 vnc_display_add_client(NULL, fd, skipauth);
684 return;
685#endif
686 } else if ((s = qemu_chr_find(protocol)) != NULL) {
687 if (qemu_chr_add_client(s, fd) < 0) {
688 error_setg(errp, "failed to add client");
689 close(fd);
690 return;
691 }
692 return;
693 }
694
695 error_setg(errp, "protocol '%s' is invalid", protocol);
696 close(fd);
697}
ab2d0531 698
cff8b2c6 699
6eb3937e
MA
700void qmp_object_add(const char *type, const char *id,
701 bool has_props, QObject *props, Error **errp)
cff8b2c6 702{
e64c75a9 703 QDict *pdict;
b70ce101 704 Visitor *v;
90998d58 705 Object *obj;
cff8b2c6
PB
706
707 if (props) {
7dc847eb 708 pdict = qobject_to(QDict, props);
cff8b2c6 709 if (!pdict) {
485febc6
MA
710 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
711 return;
cff8b2c6 712 }
e64c75a9
MAL
713 QINCREF(pdict);
714 } else {
715 pdict = qdict_new();
cff8b2c6
PB
716 }
717
048abb7b 718 v = qobject_input_visitor_new(QOBJECT(pdict));
b70ce101
EB
719 obj = user_creatable_add_type(type, id, pdict, v, errp);
720 visit_free(v);
90998d58
DB
721 if (obj) {
722 object_unref(obj);
723 }
e64c75a9 724 QDECREF(pdict);
cff8b2c6
PB
725}
726
ab2d0531
PB
727void qmp_object_del(const char *id, Error **errp)
728{
90998d58 729 user_creatable_del(id, errp);
ab2d0531 730}
6f2e2730
IM
731
732MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
733{
52c95cae 734 return qmp_pc_dimm_device_list();
6f2e2730 735}
02419bcb
IM
736
737ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
738{
739 bool ambig;
740 ACPIOSTInfoList *head = NULL;
741 ACPIOSTInfoList **prev = &head;
742 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
743
744 if (obj) {
745 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
746 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
747
748 adevc->ospm_status(adev, &prev);
749 } else {
750 error_setg(errp, "command is not supported, missing ACPI device");
751 }
752
753 return head;
754}
9aa3397f
VG
755
756MemoryInfo *qmp_query_memory_size_summary(Error **errp)
757{
758 MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
759
760 mem_info->base_memory = ram_size;
761
762 mem_info->plugged_memory = get_plugged_memory_size();
763 mem_info->has_plugged_memory =
764 mem_info->plugged_memory != (uint64_t)-1;
765
766 return mem_info;
767}
469638f9
PX
768
769static QemuSemaphore x_oob_test_sem;
770
771static void __attribute__((constructor)) x_oob_test_init(void)
772{
773 qemu_sem_init(&x_oob_test_sem, 0);
774}
775
776void qmp_x_oob_test(bool lock, Error **errp)
777{
778 if (lock) {
779 qemu_sem_wait(&x_oob_test_sem);
780 } else {
781 qemu_sem_post(&x_oob_test_sem);
782 }
783}