]> git.ipfire.org Git - thirdparty/qemu.git/blame - qmp.c
qapi-commands: Rearrange code
[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 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
160 * qmp_marshal_input_query_spice() that calls qmp_query_spice().
161 * Provide it one, or else linking fails.
162 * FIXME Educate the QAPI schema on CONFIG_SPICE.
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
AL
236
237/* FIXME: teach qapi about how to pass through Visitors */
485febc6 238void qmp_qom_set(QDict *qdict, QObject **ret, Error **errp)
eb6e8ea5
AL
239{
240 const char *path = qdict_get_str(qdict, "path");
241 const char *property = qdict_get_str(qdict, "property");
242 QObject *value = qdict_get(qdict, "value");
57c9fafe 243 Object *obj;
eb6e8ea5 244
57c9fafe
AL
245 obj = object_resolve_path(path, NULL);
246 if (!obj) {
485febc6 247 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 248 "Device '%s' not found", path);
485febc6 249 return;
eb6e8ea5
AL
250 }
251
485febc6 252 object_property_set_qobject(obj, value, property, errp);
eb6e8ea5
AL
253}
254
485febc6 255void qmp_qom_get(QDict *qdict, QObject **ret, Error **errp)
eb6e8ea5
AL
256{
257 const char *path = qdict_get_str(qdict, "path");
258 const char *property = qdict_get_str(qdict, "property");
57c9fafe 259 Object *obj;
eb6e8ea5 260
57c9fafe
AL
261 obj = object_resolve_path(path, NULL);
262 if (!obj) {
485febc6 263 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 264 "Device '%s' not found", path);
485febc6 265 return;
eb6e8ea5
AL
266 }
267
485febc6 268 *ret = object_property_get_qobject(obj, property, errp);
eb6e8ea5 269}
fbf796fd
LC
270
271void qmp_set_password(const char *protocol, const char *password,
272 bool has_connected, const char *connected, Error **errp)
273{
274 int disconnect_if_connected = 0;
275 int fail_if_connected = 0;
276 int rc;
277
278 if (has_connected) {
279 if (strcmp(connected, "fail") == 0) {
280 fail_if_connected = 1;
281 } else if (strcmp(connected, "disconnect") == 0) {
282 disconnect_if_connected = 1;
283 } else if (strcmp(connected, "keep") == 0) {
284 /* nothing */
285 } else {
c6bd8c70 286 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
287 return;
288 }
289 }
290
291 if (strcmp(protocol, "spice") == 0) {
b25d81ba 292 if (!qemu_using_spice(errp)) {
fbf796fd
LC
293 return;
294 }
295 rc = qemu_spice_set_passwd(password, fail_if_connected,
296 disconnect_if_connected);
297 if (rc != 0) {
c6bd8c70 298 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
299 }
300 return;
301 }
302
303 if (strcmp(protocol, "vnc") == 0) {
304 if (fail_if_connected || disconnect_if_connected) {
305 /* vnc supports "connected=keep" only */
c6bd8c70 306 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
307 return;
308 }
309 /* Note that setting an empty password will not disable login through
310 * this interface. */
311 rc = vnc_display_password(NULL, password);
312 if (rc < 0) {
c6bd8c70 313 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
314 }
315 return;
316 }
317
c6bd8c70 318 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
fbf796fd 319}
9ad5372d
LC
320
321void qmp_expire_password(const char *protocol, const char *whenstr,
322 Error **errp)
323{
324 time_t when;
325 int rc;
326
327 if (strcmp(whenstr, "now") == 0) {
328 when = 0;
329 } else if (strcmp(whenstr, "never") == 0) {
330 when = TIME_MAX;
331 } else if (whenstr[0] == '+') {
332 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
333 } else {
334 when = strtoull(whenstr, NULL, 10);
335 }
336
337 if (strcmp(protocol, "spice") == 0) {
b25d81ba 338 if (!qemu_using_spice(errp)) {
9ad5372d
LC
339 return;
340 }
341 rc = qemu_spice_set_pw_expire(when);
342 if (rc != 0) {
c6bd8c70 343 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
344 }
345 return;
346 }
347
348 if (strcmp(protocol, "vnc") == 0) {
349 rc = vnc_display_pw_expire(NULL, when);
350 if (rc != 0) {
c6bd8c70 351 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
352 }
353 return;
354 }
355
c6bd8c70 356 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
9ad5372d 357}
270b243f 358
333a96ec 359#ifdef CONFIG_VNC
270b243f
LC
360void qmp_change_vnc_password(const char *password, Error **errp)
361{
362 if (vnc_display_password(NULL, password) < 0) {
c6bd8c70 363 error_setg(errp, QERR_SET_PASSWD_FAILED);
270b243f
LC
364 }
365}
333a96ec 366
007fcd3e 367static void qmp_change_vnc_listen(const char *target, Error **errp)
333a96ec 368{
4db14629
GH
369 QemuOptsList *olist = qemu_find_opts("vnc");
370 QemuOpts *opts;
371
372 if (strstr(target, "id=")) {
373 error_setg(errp, "id not supported");
374 return;
375 }
376
377 opts = qemu_opts_find(olist, "default");
378 if (opts) {
379 qemu_opts_del(opts);
380 }
70b94331 381 opts = vnc_parse(target, errp);
f7801c5c
GA
382 if (!opts) {
383 return;
384 }
385
4db14629 386 vnc_display_open("default", errp);
333a96ec
LC
387}
388
389static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
390 Error **errp)
391{
392 if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
393 if (!has_arg) {
c6bd8c70 394 error_setg(errp, QERR_MISSING_PARAMETER, "password");
333a96ec
LC
395 } else {
396 qmp_change_vnc_password(arg, errp);
397 }
398 } else {
399 qmp_change_vnc_listen(target, errp);
400 }
401}
402#else
403void qmp_change_vnc_password(const char *password, Error **errp)
404{
c6bd8c70 405 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
406}
407static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
408 Error **errp)
409{
c6bd8c70 410 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
333a96ec
LC
411}
412#endif /* !CONFIG_VNC */
413
414void qmp_change(const char *device, const char *target,
7daecb30 415 bool has_arg, const char *arg, Error **errp)
333a96ec
LC
416{
417 if (strcmp(device, "vnc") == 0) {
7daecb30 418 qmp_change_vnc(target, has_arg, arg, errp);
333a96ec 419 } else {
7daecb30 420 qmp_change_blockdev(device, target, arg, errp);
333a96ec
LC
421 }
422}
5eeee3fa
AL
423
424static void qom_list_types_tramp(ObjectClass *klass, void *data)
425{
426 ObjectTypeInfoList *e, **pret = data;
427 ObjectTypeInfo *info;
428
429 info = g_malloc0(sizeof(*info));
430 info->name = g_strdup(object_class_get_name(klass));
431
432 e = g_malloc0(sizeof(*e));
433 e->value = info;
434 e->next = *pret;
435 *pret = e;
436}
437
438ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
439 const char *implements,
440 bool has_abstract,
441 bool abstract,
442 Error **errp)
443{
444 ObjectTypeInfoList *ret = NULL;
445
446 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
447
448 return ret;
449}
1daa31b9 450
f4eb32b5
SH
451/* Return a DevicePropertyInfo for a qdev property.
452 *
453 * If a qdev property with the given name does not exist, use the given default
454 * type. If the qdev property info should not be shown, return NULL.
455 *
456 * The caller must free the return value.
457 */
458static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
459 const char *name,
07d09c58
GA
460 const char *default_type,
461 const char *description)
f4eb32b5
SH
462{
463 DevicePropertyInfo *info;
464 Property *prop;
465
466 do {
467 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
468 if (strcmp(name, prop->name) != 0) {
469 continue;
470 }
471
472 /*
473 * TODO Properties without a parser are just for dirty hacks.
474 * qdev_prop_ptr is the only such PropertyInfo. It's marked
475 * for removal. This conditional should be removed along with
476 * it.
477 */
478 if (!prop->info->set) {
479 return NULL; /* no way to set it, don't show */
480 }
481
482 info = g_malloc0(sizeof(*info));
483 info->name = g_strdup(prop->name);
07d09c58
GA
484 info->type = g_strdup(prop->info->name);
485 info->has_description = !!prop->info->description;
486 info->description = g_strdup(prop->info->description);
f4eb32b5
SH
487 return info;
488 }
489 klass = object_class_get_parent(klass);
490 } while (klass != object_class_by_name(TYPE_DEVICE));
491
492 /* Not a qdev property, use the default type */
493 info = g_malloc0(sizeof(*info));
494 info->name = g_strdup(name);
495 info->type = g_strdup(default_type);
07d09c58
GA
496 info->has_description = !!description;
497 info->description = g_strdup(description);
498
f4eb32b5
SH
499 return info;
500}
501
1daa31b9
AL
502DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
503 Error **errp)
504{
505 ObjectClass *klass;
f4eb32b5
SH
506 Object *obj;
507 ObjectProperty *prop;
1daa31b9
AL
508 DevicePropertyInfoList *prop_list = NULL;
509
510 klass = object_class_by_name(typename);
511 if (klass == NULL) {
75158ebb
MA
512 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
513 "Device '%s' not found", typename);
1daa31b9
AL
514 return NULL;
515 }
516
517 klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
518 if (klass == NULL) {
c6bd8c70 519 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "name", TYPE_DEVICE);
1daa31b9
AL
520 return NULL;
521 }
522
f4eb32b5 523 obj = object_new(typename);
1daa31b9 524
f4eb32b5
SH
525 QTAILQ_FOREACH(prop, &obj->properties, node) {
526 DevicePropertyInfo *info;
527 DevicePropertyInfoList *entry;
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));
552 entry->value = info;
553 entry->next = prop_list;
554 prop_list = entry;
555 }
556
557 object_unref(obj);
1daa31b9
AL
558
559 return prop_list;
560}
e4e31c63 561
76b64a7a
AL
562CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
563{
564 return arch_query_cpu_definitions(errp);
565}
566
b224e5e2
LC
567void qmp_add_client(const char *protocol, const char *fdname,
568 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
569 Error **errp)
570{
571 CharDriverState *s;
572 int fd;
573
574 fd = monitor_get_fd(cur_mon, fdname, errp);
575 if (fd < 0) {
576 return;
577 }
578
579 if (strcmp(protocol, "spice") == 0) {
b25d81ba 580 if (!qemu_using_spice(errp)) {
b224e5e2
LC
581 close(fd);
582 return;
583 }
584 skipauth = has_skipauth ? skipauth : false;
585 tls = has_tls ? tls : false;
586 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
587 error_setg(errp, "spice failed to add client");
588 close(fd);
589 }
590 return;
591#ifdef CONFIG_VNC
592 } else if (strcmp(protocol, "vnc") == 0) {
593 skipauth = has_skipauth ? skipauth : false;
594 vnc_display_add_client(NULL, fd, skipauth);
595 return;
596#endif
597 } else if ((s = qemu_chr_find(protocol)) != NULL) {
598 if (qemu_chr_add_client(s, fd) < 0) {
599 error_setg(errp, "failed to add client");
600 close(fd);
601 return;
602 }
603 return;
604 }
605
606 error_setg(errp, "protocol '%s' is invalid", protocol);
607 close(fd);
608}
ab2d0531 609
cff8b2c6
PB
610void object_add(const char *type, const char *id, const QDict *qdict,
611 Visitor *v, Error **errp)
612{
613 Object *obj;
c3481247 614 ObjectClass *klass;
cff8b2c6
PB
615 const QDictEntry *e;
616 Error *local_err = NULL;
617
c3481247
EH
618 klass = object_class_by_name(type);
619 if (!klass) {
d1169464 620 error_setg(errp, "invalid object type: %s", type);
cff8b2c6
PB
621 return;
622 }
623
c3481247
EH
624 if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
625 error_setg(errp, "object type '%s' isn't supported by object-add",
626 type);
627 return;
628 }
629
630 if (object_class_is_abstract(klass)) {
631 error_setg(errp, "object type '%s' is abstract", type);
632 return;
633 }
634
cff8b2c6
PB
635 obj = object_new(type);
636 if (qdict) {
637 for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
638 object_property_set(obj, v, e->key, &local_err);
639 if (local_err) {
69252c04 640 goto out;
cff8b2c6
PB
641 }
642 }
643 }
644
bc2256c4 645 object_property_add_child(object_get_objects_root(),
a790f4ec 646 id, obj, &local_err);
269e09f3
IM
647 if (local_err) {
648 goto out;
649 }
650
a790f4ec
IM
651 user_creatable_complete(obj, &local_err);
652 if (local_err) {
bc2256c4 653 object_property_del(object_get_objects_root(),
a790f4ec
IM
654 id, &error_abort);
655 goto out;
656 }
69252c04
IM
657out:
658 if (local_err) {
659 error_propagate(errp, local_err);
660 }
cff8b2c6
PB
661 object_unref(obj);
662}
663
485febc6 664void qmp_object_add(QDict *qdict, QObject **ret, Error **errp)
cff8b2c6
PB
665{
666 const char *type = qdict_get_str(qdict, "qom-type");
667 const char *id = qdict_get_str(qdict, "id");
668 QObject *props = qdict_get(qdict, "props");
669 const QDict *pdict = NULL;
cff8b2c6
PB
670 QmpInputVisitor *qiv;
671
672 if (props) {
673 pdict = qobject_to_qdict(props);
674 if (!pdict) {
485febc6
MA
675 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
676 return;
cff8b2c6
PB
677 }
678 }
679
680 qiv = qmp_input_visitor_new(props);
485febc6 681 object_add(type, id, pdict, qmp_input_get_visitor(qiv), errp);
cff8b2c6 682 qmp_input_visitor_cleanup(qiv);
cff8b2c6
PB
683}
684
ab2d0531
PB
685void qmp_object_del(const char *id, Error **errp)
686{
687 Object *container;
688 Object *obj;
689
bc2256c4 690 container = object_get_objects_root();
ab2d0531
PB
691 obj = object_resolve_path_component(container, id);
692 if (!obj) {
693 error_setg(errp, "object id not found");
694 return;
695 }
d6edb155
LM
696
697 if (!user_creatable_can_be_deleted(USER_CREATABLE(obj), errp)) {
698 error_setg(errp, "%s is in use, can not be deleted", id);
699 return;
700 }
ab2d0531
PB
701 object_unparent(obj);
702}
6f2e2730
IM
703
704MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
705{
706 MemoryDeviceInfoList *head = NULL;
707 MemoryDeviceInfoList **prev = &head;
708
709 qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
710
711 return head;
712}
02419bcb
IM
713
714ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
715{
716 bool ambig;
717 ACPIOSTInfoList *head = NULL;
718 ACPIOSTInfoList **prev = &head;
719 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
720
721 if (obj) {
722 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
723 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
724
725 adevc->ospm_status(adev, &prev);
726 } else {
727 error_setg(errp, "command is not supported, missing ACPI device");
728 }
729
730 return head;
731}