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