]> git.ipfire.org Git - thirdparty/qemu.git/blame - qmp.c
Include qapi/qmp/qerror.h exactly where needed
[thirdparty/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
16#include "qemu-common.h"
9c17d615 17#include "sysemu/sysemu.h"
48a32bed 18#include "qmp-commands.h"
dccfcd0e 19#include "sysemu/char.h"
fbf796fd
LC
20#include "ui/qemu-spice.h"
21#include "ui/vnc.h"
9c17d615
PB
22#include "sysemu/kvm.h"
23#include "sysemu/arch_init.h"
b4b12c62 24#include "hw/qdev.h"
9c17d615 25#include "sysemu/blockdev.h"
14cccb61 26#include "qom/qom-qobject.h"
cc7a8ea7 27#include "qapi/qmp/qerror.h"
cff8b2c6
PB
28#include "qapi/qmp/qobject.h"
29#include "qapi/qmp-input-visitor.h"
69ca3ea5 30#include "hw/boards.h"
269e09f3 31#include "qom/object_interfaces.h"
6f2e2730 32#include "hw/mem/pc-dimm.h"
02419bcb 33#include "hw/acpi/acpi_dev_interface.h"
48a32bed
AL
34
35NameInfo *qmp_query_name(Error **errp)
36{
37 NameInfo *info = g_malloc0(sizeof(*info));
38
39 if (qemu_name) {
40 info->has_name = true;
41 info->name = g_strdup(qemu_name);
42 }
43
44 return info;
45}
b9c15f16 46
7daecb30 47VersionInfo *qmp_query_version(Error **errp)
b9c15f16 48{
4752cdbb 49 VersionInfo *info = g_new0(VersionInfo, 1);
b9c15f16
LC
50 const char *version = QEMU_VERSION;
51 char *tmp;
52
4752cdbb
EB
53 info->qemu = g_new0(VersionTriple, 1);
54 info->qemu->major = strtol(version, &tmp, 10);
b9c15f16 55 tmp++;
4752cdbb 56 info->qemu->minor = strtol(tmp, &tmp, 10);
b9c15f16 57 tmp++;
4752cdbb 58 info->qemu->micro = strtol(tmp, &tmp, 10);
b9c15f16
LC
59 info->package = g_strdup(QEMU_PKGVERSION);
60
61 return info;
62}
292a2602
LC
63
64KvmInfo *qmp_query_kvm(Error **errp)
65{
66 KvmInfo *info = g_malloc0(sizeof(*info));
67
68 info->enabled = kvm_enabled();
69 info->present = kvm_available();
70
71 return info;
72}
73
efab767e
LC
74UuidInfo *qmp_query_uuid(Error **errp)
75{
76 UuidInfo *info = g_malloc0(sizeof(*info));
77 char uuid[64];
78
79 snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
80 qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
81 qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
82 qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
83 qemu_uuid[14], qemu_uuid[15]);
84
85 info->UUID = g_strdup(uuid);
86 return info;
87}
88
7daecb30 89void qmp_quit(Error **errp)
7a7f325e
LC
90{
91 no_shutdown = 0;
92 qemu_system_shutdown_request();
93}
94
5f158f21
LC
95void qmp_stop(Error **errp)
96{
1e998146
PB
97 if (runstate_check(RUN_STATE_INMIGRATE)) {
98 autostart = 0;
99 } else {
100 vm_stop(RUN_STATE_PAUSED);
101 }
5f158f21
LC
102}
103
38d22653
LC
104void qmp_system_reset(Error **errp)
105{
106 qemu_system_reset_request();
107}
5bc465e4
LC
108
109void qmp_system_powerdown(Error **erp)
110{
111 qemu_system_powerdown_request();
112}
755f1968
LC
113
114void qmp_cpu(int64_t index, Error **errp)
115{
116 /* Just do nothing */
117}
2b54aa87 118
69ca3ea5
IM
119void qmp_cpu_add(int64_t id, Error **errp)
120{
0056ae24
MA
121 MachineClass *mc;
122
123 mc = MACHINE_GET_CLASS(current_machine);
958db90c
MA
124 if (mc->hot_add_cpu) {
125 mc->hot_add_cpu(id, errp);
69ca3ea5
IM
126 } else {
127 error_setg(errp, "Not supported");
128 }
129}
130
2b54aa87
LC
131#ifndef CONFIG_VNC
132/* If VNC support is enabled, the "true" query-vnc command is
133 defined in the VNC subsystem */
134VncInfo *qmp_query_vnc(Error **errp)
135{
c6bd8c70 136 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
2b54aa87
LC
137 return NULL;
138};
89db2177
LY
139
140VncInfo2List *qmp_query_vnc_servers(Error **errp)
141{
c6bd8c70 142 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
89db2177
LY
143 return NULL;
144};
2b54aa87 145#endif
d1f29646
LC
146
147#ifndef CONFIG_SPICE
ad0ec14b
MA
148/*
149 * qmp-commands.hx ensures that QMP command query-spice exists only
150 * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands
151 * result. However, the QAPI schema is blissfully unaware of that,
152 * and the QAPI code generator happily generates a dead
153 * qmp_marshal_input_query_spice() that calls qmp_query_spice().
154 * Provide it one, or else linking fails.
155 * FIXME Educate the QAPI schema on CONFIG_SPICE.
156 */
d1f29646
LC
157SpiceInfo *qmp_query_spice(Error **errp)
158{
ad0ec14b 159 abort();
d1f29646
LC
160};
161#endif
e42e818b 162
e42e818b
LC
163void qmp_cont(Error **errp)
164{
4d2855a3 165 Error *local_err = NULL;
ab31979a 166 BlockDriverState *bs;
e42e818b 167
ede085b3 168 if (runstate_needs_reset()) {
f231b88d 169 error_setg(errp, "Resetting the Virtual Machine is required");
e42e818b 170 return;
ad02b96a
LC
171 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
172 return;
e42e818b
LC
173 }
174
ab31979a
MA
175 for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
176 bdrv_iostatus_reset(bs);
177 }
178 for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
4d2855a3
MA
179 bdrv_add_key(bs, NULL, &local_err);
180 if (local_err) {
181 error_propagate(errp, local_err);
ab31979a
MA
182 return;
183 }
e42e818b
LC
184 }
185
1e998146
PB
186 if (runstate_check(RUN_STATE_INMIGRATE)) {
187 autostart = 1;
188 } else {
189 vm_start();
190 }
e42e818b 191}
b4b12c62 192
9b9df25a
GH
193void qmp_system_wakeup(Error **errp)
194{
195 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
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;
b4b12c62 204
57c9fafe
AL
205 obj = object_resolve_path(path, &ambiguous);
206 if (obj == NULL) {
79772087
MT
207 if (ambiguous) {
208 error_setg(errp, "Path '%s' is ambiguous", path);
209 } else {
75158ebb
MA
210 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
211 "Device '%s' not found", path);
79772087 212 }
b4b12c62
AL
213 return NULL;
214 }
215
57c9fafe
AL
216 QTAILQ_FOREACH(prop, &obj->properties, node) {
217 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
b4b12c62 218
57c9fafe 219 entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
b4b12c62
AL
220 entry->next = props;
221 props = entry;
222
223 entry->value->name = g_strdup(prop->name);
224 entry->value->type = g_strdup(prop->type);
225 }
226
227 return props;
228}
eb6e8ea5
AL
229
230/* FIXME: teach qapi about how to pass through Visitors */
485febc6 231void qmp_qom_set(QDict *qdict, QObject **ret, Error **errp)
eb6e8ea5
AL
232{
233 const char *path = qdict_get_str(qdict, "path");
234 const char *property = qdict_get_str(qdict, "property");
235 QObject *value = qdict_get(qdict, "value");
57c9fafe 236 Object *obj;
eb6e8ea5 237
57c9fafe
AL
238 obj = object_resolve_path(path, NULL);
239 if (!obj) {
485febc6 240 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 241 "Device '%s' not found", path);
485febc6 242 return;
eb6e8ea5
AL
243 }
244
485febc6 245 object_property_set_qobject(obj, value, property, errp);
eb6e8ea5
AL
246}
247
485febc6 248void qmp_qom_get(QDict *qdict, QObject **ret, Error **errp)
eb6e8ea5
AL
249{
250 const char *path = qdict_get_str(qdict, "path");
251 const char *property = qdict_get_str(qdict, "property");
57c9fafe 252 Object *obj;
eb6e8ea5 253
57c9fafe
AL
254 obj = object_resolve_path(path, NULL);
255 if (!obj) {
485febc6 256 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 257 "Device '%s' not found", path);
485febc6 258 return;
eb6e8ea5
AL
259 }
260
485febc6 261 *ret = object_property_get_qobject(obj, property, errp);
eb6e8ea5 262}
fbf796fd
LC
263
264void qmp_set_password(const char *protocol, const char *password,
265 bool has_connected, const char *connected, Error **errp)
266{
267 int disconnect_if_connected = 0;
268 int fail_if_connected = 0;
269 int rc;
270
271 if (has_connected) {
272 if (strcmp(connected, "fail") == 0) {
273 fail_if_connected = 1;
274 } else if (strcmp(connected, "disconnect") == 0) {
275 disconnect_if_connected = 1;
276 } else if (strcmp(connected, "keep") == 0) {
277 /* nothing */
278 } else {
c6bd8c70 279 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
280 return;
281 }
282 }
283
284 if (strcmp(protocol, "spice") == 0) {
b25d81ba 285 if (!qemu_using_spice(errp)) {
fbf796fd
LC
286 return;
287 }
288 rc = qemu_spice_set_passwd(password, fail_if_connected,
289 disconnect_if_connected);
290 if (rc != 0) {
c6bd8c70 291 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
292 }
293 return;
294 }
295
296 if (strcmp(protocol, "vnc") == 0) {
297 if (fail_if_connected || disconnect_if_connected) {
298 /* vnc supports "connected=keep" only */
c6bd8c70 299 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
300 return;
301 }
302 /* Note that setting an empty password will not disable login through
303 * this interface. */
304 rc = vnc_display_password(NULL, password);
305 if (rc < 0) {
c6bd8c70 306 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
307 }
308 return;
309 }
310
c6bd8c70 311 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
fbf796fd 312}
9ad5372d
LC
313
314void qmp_expire_password(const char *protocol, const char *whenstr,
315 Error **errp)
316{
317 time_t when;
318 int rc;
319
320 if (strcmp(whenstr, "now") == 0) {
321 when = 0;
322 } else if (strcmp(whenstr, "never") == 0) {
323 when = TIME_MAX;
324 } else if (whenstr[0] == '+') {
325 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
326 } else {
327 when = strtoull(whenstr, NULL, 10);
328 }
329
330 if (strcmp(protocol, "spice") == 0) {
b25d81ba 331 if (!qemu_using_spice(errp)) {
9ad5372d
LC
332 return;
333 }
334 rc = qemu_spice_set_pw_expire(when);
335 if (rc != 0) {
c6bd8c70 336 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
337 }
338 return;
339 }
340
341 if (strcmp(protocol, "vnc") == 0) {
342 rc = vnc_display_pw_expire(NULL, when);
343 if (rc != 0) {
c6bd8c70 344 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
345 }
346 return;
347 }
348
c6bd8c70 349 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
9ad5372d 350}
270b243f 351
333a96ec 352#ifdef CONFIG_VNC
270b243f
LC
353void qmp_change_vnc_password(const char *password, Error **errp)
354{
355 if (vnc_display_password(NULL, password) < 0) {
c6bd8c70 356 error_setg(errp, QERR_SET_PASSWD_FAILED);
270b243f
LC
357 }
358}
333a96ec 359
007fcd3e 360static void qmp_change_vnc_listen(const char *target, Error **errp)
333a96ec 361{
4db14629
GH
362 QemuOptsList *olist = qemu_find_opts("vnc");
363 QemuOpts *opts;
364
365 if (strstr(target, "id=")) {
366 error_setg(errp, "id not supported");
367 return;
368 }
369
370 opts = qemu_opts_find(olist, "default");
371 if (opts) {
372 qemu_opts_del(opts);
373 }
70b94331 374 opts = vnc_parse(target, errp);
f7801c5c
GA
375 if (!opts) {
376 return;
377 }
378
4db14629 379 vnc_display_open("default", errp);
333a96ec
LC
380}
381
382static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
383 Error **errp)
384{
385 if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
386 if (!has_arg) {
c6bd8c70 387 error_setg(errp, QERR_MISSING_PARAMETER, "password");
333a96ec
LC
388 } else {
389 qmp_change_vnc_password(arg, errp);
390 }
391 } else {
392 qmp_change_vnc_listen(target, errp);
393 }
394}
395#else
396void qmp_change_vnc_password(const char *password, Error **errp)
397{
c6bd8c70 398 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
399}
400static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
401 Error **errp)
402{
c6bd8c70 403 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
404}
405#endif /* !CONFIG_VNC */
406
407void qmp_change(const char *device, const char *target,
7daecb30 408 bool has_arg, const char *arg, Error **errp)
333a96ec
LC
409{
410 if (strcmp(device, "vnc") == 0) {
7daecb30 411 qmp_change_vnc(target, has_arg, arg, errp);
333a96ec 412 } else {
7daecb30 413 qmp_change_blockdev(device, target, arg, errp);
333a96ec
LC
414 }
415}
5eeee3fa
AL
416
417static void qom_list_types_tramp(ObjectClass *klass, void *data)
418{
419 ObjectTypeInfoList *e, **pret = data;
420 ObjectTypeInfo *info;
421
422 info = g_malloc0(sizeof(*info));
423 info->name = g_strdup(object_class_get_name(klass));
424
425 e = g_malloc0(sizeof(*e));
426 e->value = info;
427 e->next = *pret;
428 *pret = e;
429}
430
431ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
432 const char *implements,
433 bool has_abstract,
434 bool abstract,
435 Error **errp)
436{
437 ObjectTypeInfoList *ret = NULL;
438
439 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
440
441 return ret;
442}
1daa31b9 443
f4eb32b5
SH
444/* Return a DevicePropertyInfo for a qdev property.
445 *
446 * If a qdev property with the given name does not exist, use the given default
447 * type. If the qdev property info should not be shown, return NULL.
448 *
449 * The caller must free the return value.
450 */
451static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
452 const char *name,
07d09c58
GA
453 const char *default_type,
454 const char *description)
f4eb32b5
SH
455{
456 DevicePropertyInfo *info;
457 Property *prop;
458
459 do {
460 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
461 if (strcmp(name, prop->name) != 0) {
462 continue;
463 }
464
465 /*
466 * TODO Properties without a parser are just for dirty hacks.
467 * qdev_prop_ptr is the only such PropertyInfo. It's marked
468 * for removal. This conditional should be removed along with
469 * it.
470 */
471 if (!prop->info->set) {
472 return NULL; /* no way to set it, don't show */
473 }
474
475 info = g_malloc0(sizeof(*info));
476 info->name = g_strdup(prop->name);
07d09c58
GA
477 info->type = g_strdup(prop->info->name);
478 info->has_description = !!prop->info->description;
479 info->description = g_strdup(prop->info->description);
f4eb32b5
SH
480 return info;
481 }
482 klass = object_class_get_parent(klass);
483 } while (klass != object_class_by_name(TYPE_DEVICE));
484
485 /* Not a qdev property, use the default type */
486 info = g_malloc0(sizeof(*info));
487 info->name = g_strdup(name);
488 info->type = g_strdup(default_type);
07d09c58
GA
489 info->has_description = !!description;
490 info->description = g_strdup(description);
491
f4eb32b5
SH
492 return info;
493}
494
1daa31b9
AL
495DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
496 Error **errp)
497{
498 ObjectClass *klass;
f4eb32b5
SH
499 Object *obj;
500 ObjectProperty *prop;
1daa31b9
AL
501 DevicePropertyInfoList *prop_list = NULL;
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) {
c6bd8c70 512 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "name", TYPE_DEVICE);
1daa31b9
AL
513 return NULL;
514 }
515
f4eb32b5 516 obj = object_new(typename);
1daa31b9 517
f4eb32b5
SH
518 QTAILQ_FOREACH(prop, &obj->properties, node) {
519 DevicePropertyInfo *info;
520 DevicePropertyInfoList *entry;
521
522 /* Skip Object and DeviceState properties */
523 if (strcmp(prop->name, "type") == 0 ||
524 strcmp(prop->name, "realized") == 0 ||
525 strcmp(prop->name, "hotpluggable") == 0 ||
4115dd65 526 strcmp(prop->name, "hotplugged") == 0 ||
f4eb32b5
SH
527 strcmp(prop->name, "parent_bus") == 0) {
528 continue;
529 }
1daa31b9 530
f4eb32b5
SH
531 /* Skip legacy properties since they are just string versions of
532 * properties that we already list.
533 */
534 if (strstart(prop->name, "legacy-", NULL)) {
535 continue;
536 }
1daa31b9 537
07d09c58
GA
538 info = make_device_property_info(klass, prop->name, prop->type,
539 prop->description);
f4eb32b5
SH
540 if (!info) {
541 continue;
1daa31b9 542 }
f4eb32b5
SH
543
544 entry = g_malloc0(sizeof(*entry));
545 entry->value = info;
546 entry->next = prop_list;
547 prop_list = entry;
548 }
549
550 object_unref(obj);
1daa31b9
AL
551
552 return prop_list;
553}
e4e31c63 554
76b64a7a
AL
555CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
556{
557 return arch_query_cpu_definitions(errp);
558}
559
b224e5e2
LC
560void qmp_add_client(const char *protocol, const char *fdname,
561 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
562 Error **errp)
563{
564 CharDriverState *s;
565 int fd;
566
567 fd = monitor_get_fd(cur_mon, fdname, errp);
568 if (fd < 0) {
569 return;
570 }
571
572 if (strcmp(protocol, "spice") == 0) {
b25d81ba 573 if (!qemu_using_spice(errp)) {
b224e5e2
LC
574 close(fd);
575 return;
576 }
577 skipauth = has_skipauth ? skipauth : false;
578 tls = has_tls ? tls : false;
579 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
580 error_setg(errp, "spice failed to add client");
581 close(fd);
582 }
583 return;
584#ifdef CONFIG_VNC
585 } else if (strcmp(protocol, "vnc") == 0) {
586 skipauth = has_skipauth ? skipauth : false;
587 vnc_display_add_client(NULL, fd, skipauth);
588 return;
589#endif
590 } else if ((s = qemu_chr_find(protocol)) != NULL) {
591 if (qemu_chr_add_client(s, fd) < 0) {
592 error_setg(errp, "failed to add client");
593 close(fd);
594 return;
595 }
596 return;
597 }
598
599 error_setg(errp, "protocol '%s' is invalid", protocol);
600 close(fd);
601}
ab2d0531 602
cff8b2c6
PB
603void object_add(const char *type, const char *id, const QDict *qdict,
604 Visitor *v, Error **errp)
605{
606 Object *obj;
c3481247 607 ObjectClass *klass;
cff8b2c6
PB
608 const QDictEntry *e;
609 Error *local_err = NULL;
610
c3481247
EH
611 klass = object_class_by_name(type);
612 if (!klass) {
d1169464 613 error_setg(errp, "invalid object type: %s", type);
cff8b2c6
PB
614 return;
615 }
616
c3481247
EH
617 if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
618 error_setg(errp, "object type '%s' isn't supported by object-add",
619 type);
620 return;
621 }
622
623 if (object_class_is_abstract(klass)) {
624 error_setg(errp, "object type '%s' is abstract", type);
625 return;
626 }
627
cff8b2c6
PB
628 obj = object_new(type);
629 if (qdict) {
630 for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
631 object_property_set(obj, v, e->key, &local_err);
632 if (local_err) {
69252c04 633 goto out;
cff8b2c6
PB
634 }
635 }
636 }
637
bc2256c4 638 object_property_add_child(object_get_objects_root(),
a790f4ec 639 id, obj, &local_err);
269e09f3
IM
640 if (local_err) {
641 goto out;
642 }
643
a790f4ec
IM
644 user_creatable_complete(obj, &local_err);
645 if (local_err) {
bc2256c4 646 object_property_del(object_get_objects_root(),
a790f4ec
IM
647 id, &error_abort);
648 goto out;
649 }
69252c04
IM
650out:
651 if (local_err) {
652 error_propagate(errp, local_err);
653 }
cff8b2c6
PB
654 object_unref(obj);
655}
656
485febc6 657void qmp_object_add(QDict *qdict, QObject **ret, Error **errp)
cff8b2c6
PB
658{
659 const char *type = qdict_get_str(qdict, "qom-type");
660 const char *id = qdict_get_str(qdict, "id");
661 QObject *props = qdict_get(qdict, "props");
662 const QDict *pdict = NULL;
cff8b2c6
PB
663 QmpInputVisitor *qiv;
664
665 if (props) {
666 pdict = qobject_to_qdict(props);
667 if (!pdict) {
485febc6
MA
668 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
669 return;
cff8b2c6
PB
670 }
671 }
672
673 qiv = qmp_input_visitor_new(props);
485febc6 674 object_add(type, id, pdict, qmp_input_get_visitor(qiv), errp);
cff8b2c6 675 qmp_input_visitor_cleanup(qiv);
cff8b2c6
PB
676}
677
ab2d0531
PB
678void qmp_object_del(const char *id, Error **errp)
679{
680 Object *container;
681 Object *obj;
682
bc2256c4 683 container = object_get_objects_root();
ab2d0531
PB
684 obj = object_resolve_path_component(container, id);
685 if (!obj) {
686 error_setg(errp, "object id not found");
687 return;
688 }
d6edb155
LM
689
690 if (!user_creatable_can_be_deleted(USER_CREATABLE(obj), errp)) {
691 error_setg(errp, "%s is in use, can not be deleted", id);
692 return;
693 }
ab2d0531
PB
694 object_unparent(obj);
695}
6f2e2730
IM
696
697MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
698{
699 MemoryDeviceInfoList *head = NULL;
700 MemoryDeviceInfoList **prev = &head;
701
702 qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
703
704 return head;
705}
02419bcb
IM
706
707ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
708{
709 bool ambig;
710 ACPIOSTInfoList *head = NULL;
711 ACPIOSTInfoList **prev = &head;
712 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
713
714 if (obj) {
715 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
716 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
717
718 adevc->ospm_status(adev, &prev);
719 } else {
720 error_setg(errp, "command is not supported, missing ACPI device");
721 }
722
723 return head;
724}