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