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