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