]> git.ipfire.org Git - thirdparty/qemu.git/blame - qmp.c
Include qapi/qmp/qdict.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
d38ea87a 16#include "qemu/osdep.h"
67a1de0d 17#include "qemu-version.h"
f348b6d1 18#include "qemu/cutils.h"
a0b1a66e 19#include "monitor/monitor.h"
9c17d615 20#include "sysemu/sysemu.h"
213dcb06 21#include "qemu/config-file.h"
cea25275 22#include "qemu/uuid.h"
48a32bed 23#include "qmp-commands.h"
8228e353 24#include "chardev/char.h"
fbf796fd
LC
25#include "ui/qemu-spice.h"
26#include "ui/vnc.h"
9c17d615
PB
27#include "sysemu/kvm.h"
28#include "sysemu/arch_init.h"
b4b12c62 29#include "hw/qdev.h"
9c17d615 30#include "sysemu/blockdev.h"
373340b2 31#include "sysemu/block-backend.h"
14cccb61 32#include "qom/qom-qobject.h"
e688df6b 33#include "qapi/error.h"
452fcdbc 34#include "qapi/qmp/qdict.h"
cc7a8ea7 35#include "qapi/qmp/qerror.h"
b3db211f 36#include "qapi/qobject-input-visitor.h"
69ca3ea5 37#include "hw/boards.h"
269e09f3 38#include "qom/object_interfaces.h"
6f2e2730 39#include "hw/mem/pc-dimm.h"
02419bcb 40#include "hw/acpi/acpi_dev_interface.h"
48a32bed
AL
41
42NameInfo *qmp_query_name(Error **errp)
43{
44 NameInfo *info = g_malloc0(sizeof(*info));
45
46 if (qemu_name) {
47 info->has_name = true;
48 info->name = g_strdup(qemu_name);
49 }
50
51 return info;
52}
b9c15f16 53
7daecb30 54VersionInfo *qmp_query_version(Error **errp)
b9c15f16 55{
4752cdbb 56 VersionInfo *info = g_new0(VersionInfo, 1);
b9c15f16 57
4752cdbb 58 info->qemu = g_new0(VersionTriple, 1);
3688d8c7
MAL
59 info->qemu->major = QEMU_VERSION_MAJOR;
60 info->qemu->minor = QEMU_VERSION_MINOR;
61 info->qemu->micro = QEMU_VERSION_MICRO;
b9c15f16
LC
62 info->package = g_strdup(QEMU_PKGVERSION);
63
64 return info;
65}
292a2602
LC
66
67KvmInfo *qmp_query_kvm(Error **errp)
68{
69 KvmInfo *info = g_malloc0(sizeof(*info));
70
71 info->enabled = kvm_enabled();
72 info->present = kvm_available();
73
74 return info;
75}
76
efab767e
LC
77UuidInfo *qmp_query_uuid(Error **errp)
78{
79 UuidInfo *info = g_malloc0(sizeof(*info));
efab767e 80
9c5ce8db 81 info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid);
efab767e
LC
82 return info;
83}
84
7daecb30 85void qmp_quit(Error **errp)
7a7f325e
LC
86{
87 no_shutdown = 0;
cf83f140 88 qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP);
7a7f325e
LC
89}
90
5f158f21
LC
91void qmp_stop(Error **errp)
92{
65d64f36
PX
93 /* if there is a dump in background, we should wait until the dump
94 * finished */
95 if (dump_in_progress()) {
96 error_setg(errp, "There is a dump in process, please wait.");
97 return;
98 }
99
1e998146
PB
100 if (runstate_check(RUN_STATE_INMIGRATE)) {
101 autostart = 0;
102 } else {
103 vm_stop(RUN_STATE_PAUSED);
104 }
5f158f21
LC
105}
106
38d22653
LC
107void qmp_system_reset(Error **errp)
108{
cf83f140 109 qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP);
38d22653 110}
5bc465e4
LC
111
112void qmp_system_powerdown(Error **erp)
113{
114 qemu_system_powerdown_request();
115}
755f1968 116
69ca3ea5
IM
117void qmp_cpu_add(int64_t id, Error **errp)
118{
0056ae24
MA
119 MachineClass *mc;
120
121 mc = MACHINE_GET_CLASS(current_machine);
958db90c
MA
122 if (mc->hot_add_cpu) {
123 mc->hot_add_cpu(id, errp);
69ca3ea5
IM
124 } else {
125 error_setg(errp, "Not supported");
126 }
127}
128
2b54aa87
LC
129#ifndef CONFIG_VNC
130/* If VNC support is enabled, the "true" query-vnc command is
131 defined in the VNC subsystem */
132VncInfo *qmp_query_vnc(Error **errp)
133{
c6bd8c70 134 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
2b54aa87
LC
135 return NULL;
136};
89db2177
LY
137
138VncInfo2List *qmp_query_vnc_servers(Error **errp)
139{
c6bd8c70 140 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
89db2177
LY
141 return NULL;
142};
2b54aa87 143#endif
d1f29646
LC
144
145#ifndef CONFIG_SPICE
ad0ec14b
MA
146/*
147 * qmp-commands.hx ensures that QMP command query-spice exists only
148 * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands
149 * result. However, the QAPI schema is blissfully unaware of that,
150 * and the QAPI code generator happily generates a dead
7fad30f0
MA
151 * qmp_marshal_query_spice() that calls qmp_query_spice(). Provide it
152 * one, or else linking fails. FIXME Educate the QAPI schema on
153 * CONFIG_SPICE.
ad0ec14b 154 */
d1f29646
LC
155SpiceInfo *qmp_query_spice(Error **errp)
156{
ad0ec14b 157 abort();
d1f29646
LC
158};
159#endif
e42e818b 160
e42e818b
LC
161void qmp_cont(Error **errp)
162{
373340b2 163 BlockBackend *blk;
788cf9f8 164 Error *local_err = NULL;
e42e818b 165
65d64f36
PX
166 /* if there is a dump in background, we should wait until the dump
167 * finished */
168 if (dump_in_progress()) {
169 error_setg(errp, "There is a dump in process, please wait.");
170 return;
171 }
172
ede085b3 173 if (runstate_needs_reset()) {
f231b88d 174 error_setg(errp, "Resetting the Virtual Machine is required");
e42e818b 175 return;
ad02b96a
LC
176 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
177 return;
e42e818b
LC
178 }
179
373340b2
HR
180 for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
181 blk_iostatus_reset(blk);
ab31979a 182 }
7c8eece4 183
76b1c7fe 184 /* Continuing after completed migration. Images have been inactivated to
ace21a58
KW
185 * allow the destination to take control. Need to get control back now.
186 *
187 * If there are no inactive block nodes (e.g. because the VM was just
188 * paused rather than completing a migration), bdrv_inactivate_all() simply
189 * doesn't do anything. */
190 bdrv_invalidate_cache_all(&local_err);
191 if (local_err) {
192 error_propagate(errp, local_err);
193 return;
76b1c7fe
KW
194 }
195
1e998146
PB
196 if (runstate_check(RUN_STATE_INMIGRATE)) {
197 autostart = 1;
198 } else {
199 vm_start();
200 }
e42e818b 201}
b4b12c62 202
9b9df25a
GH
203void qmp_system_wakeup(Error **errp)
204{
205 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
206}
207
57c9fafe 208ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
b4b12c62 209{
57c9fafe 210 Object *obj;
b4b12c62 211 bool ambiguous = false;
57c9fafe
AL
212 ObjectPropertyInfoList *props = NULL;
213 ObjectProperty *prop;
7746abd8 214 ObjectPropertyIterator iter;
b4b12c62 215
57c9fafe
AL
216 obj = object_resolve_path(path, &ambiguous);
217 if (obj == NULL) {
79772087
MT
218 if (ambiguous) {
219 error_setg(errp, "Path '%s' is ambiguous", path);
220 } else {
75158ebb
MA
221 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
222 "Device '%s' not found", path);
79772087 223 }
b4b12c62
AL
224 return NULL;
225 }
226
7746abd8
DB
227 object_property_iter_init(&iter, obj);
228 while ((prop = object_property_iter_next(&iter))) {
57c9fafe 229 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
b4b12c62 230
57c9fafe 231 entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
b4b12c62
AL
232 entry->next = props;
233 props = entry;
234
235 entry->value->name = g_strdup(prop->name);
236 entry->value->type = g_strdup(prop->type);
237 }
238
239 return props;
240}
eb6e8ea5 241
6eb3937e
MA
242void qmp_qom_set(const char *path, const char *property, QObject *value,
243 Error **errp)
eb6e8ea5 244{
57c9fafe 245 Object *obj;
eb6e8ea5 246
57c9fafe
AL
247 obj = object_resolve_path(path, NULL);
248 if (!obj) {
485febc6 249 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 250 "Device '%s' not found", path);
485febc6 251 return;
eb6e8ea5
AL
252 }
253
485febc6 254 object_property_set_qobject(obj, value, property, errp);
eb6e8ea5
AL
255}
256
6eb3937e 257QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
eb6e8ea5 258{
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);
6eb3937e 265 return NULL;
eb6e8ea5
AL
266 }
267
6eb3937e 268 return 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 {
70e2cb3b
KW
420 qmp_blockdev_change_medium(true, device, false, NULL, target,
421 has_arg, arg, false, 0, errp);
333a96ec
LC
422 }
423}
5eeee3fa
AL
424
425static void qom_list_types_tramp(ObjectClass *klass, void *data)
426{
427 ObjectTypeInfoList *e, **pret = data;
428 ObjectTypeInfo *info;
f86285c5 429 ObjectClass *parent = object_class_get_parent(klass);
5eeee3fa
AL
430
431 info = g_malloc0(sizeof(*info));
432 info->name = g_strdup(object_class_get_name(klass));
87467eae 433 info->has_abstract = info->abstract = object_class_is_abstract(klass);
f86285c5
EH
434 if (parent) {
435 info->has_parent = true;
436 info->parent = g_strdup(object_class_get_name(parent));
437 }
5eeee3fa
AL
438
439 e = g_malloc0(sizeof(*e));
440 e->value = info;
441 e->next = *pret;
442 *pret = e;
443}
444
445ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
446 const char *implements,
447 bool has_abstract,
448 bool abstract,
449 Error **errp)
450{
451 ObjectTypeInfoList *ret = NULL;
452
453 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
454
455 return ret;
456}
1daa31b9 457
f4eb32b5
SH
458/* Return a DevicePropertyInfo for a qdev property.
459 *
460 * If a qdev property with the given name does not exist, use the given default
461 * type. If the qdev property info should not be shown, return NULL.
462 *
463 * The caller must free the return value.
464 */
465static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
466 const char *name,
07d09c58
GA
467 const char *default_type,
468 const char *description)
f4eb32b5
SH
469{
470 DevicePropertyInfo *info;
471 Property *prop;
472
473 do {
474 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
475 if (strcmp(name, prop->name) != 0) {
476 continue;
477 }
478
479 /*
480 * TODO Properties without a parser are just for dirty hacks.
481 * qdev_prop_ptr is the only such PropertyInfo. It's marked
482 * for removal. This conditional should be removed along with
483 * it.
484 */
faabdbb7 485 if (!prop->info->set && !prop->info->create) {
f4eb32b5
SH
486 return NULL; /* no way to set it, don't show */
487 }
488
489 info = g_malloc0(sizeof(*info));
490 info->name = g_strdup(prop->name);
75ab9053
FZ
491 info->type = default_type ? g_strdup(default_type)
492 : g_strdup(prop->info->name);
07d09c58
GA
493 info->has_description = !!prop->info->description;
494 info->description = g_strdup(prop->info->description);
f4eb32b5
SH
495 return info;
496 }
497 klass = object_class_get_parent(klass);
498 } while (klass != object_class_by_name(TYPE_DEVICE));
499
500 /* Not a qdev property, use the default type */
501 info = g_malloc0(sizeof(*info));
502 info->name = g_strdup(name);
503 info->type = g_strdup(default_type);
07d09c58
GA
504 info->has_description = !!description;
505 info->description = g_strdup(description);
506
f4eb32b5
SH
507 return info;
508}
509
1daa31b9
AL
510DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
511 Error **errp)
512{
513 ObjectClass *klass;
f4eb32b5
SH
514 Object *obj;
515 ObjectProperty *prop;
7746abd8 516 ObjectPropertyIterator iter;
1daa31b9
AL
517 DevicePropertyInfoList *prop_list = NULL;
518
519 klass = object_class_by_name(typename);
520 if (klass == NULL) {
75158ebb
MA
521 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
522 "Device '%s' not found", typename);
1daa31b9
AL
523 return NULL;
524 }
525
526 klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
527 if (klass == NULL) {
7a8c153f 528 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE);
1daa31b9
AL
529 return NULL;
530 }
531
edb1523d 532 if (object_class_is_abstract(klass)) {
7a8c153f 533 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
edb1523d
MA
534 "non-abstract device type");
535 return NULL;
536 }
537
f4eb32b5 538 obj = object_new(typename);
1daa31b9 539
7746abd8
DB
540 object_property_iter_init(&iter, obj);
541 while ((prop = object_property_iter_next(&iter))) {
f4eb32b5
SH
542 DevicePropertyInfo *info;
543 DevicePropertyInfoList *entry;
544
545 /* Skip Object and DeviceState properties */
546 if (strcmp(prop->name, "type") == 0 ||
547 strcmp(prop->name, "realized") == 0 ||
548 strcmp(prop->name, "hotpluggable") == 0 ||
4115dd65 549 strcmp(prop->name, "hotplugged") == 0 ||
f4eb32b5
SH
550 strcmp(prop->name, "parent_bus") == 0) {
551 continue;
552 }
1daa31b9 553
f4eb32b5
SH
554 /* Skip legacy properties since they are just string versions of
555 * properties that we already list.
556 */
557 if (strstart(prop->name, "legacy-", NULL)) {
558 continue;
559 }
1daa31b9 560
07d09c58
GA
561 info = make_device_property_info(klass, prop->name, prop->type,
562 prop->description);
f4eb32b5
SH
563 if (!info) {
564 continue;
1daa31b9 565 }
f4eb32b5
SH
566
567 entry = g_malloc0(sizeof(*entry));
568 entry->value = info;
569 entry->next = prop_list;
570 prop_list = entry;
571 }
572
573 object_unref(obj);
1daa31b9
AL
574
575 return prop_list;
576}
e4e31c63 577
76b64a7a
AL
578CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
579{
580 return arch_query_cpu_definitions(errp);
581}
582
e09484ef
DH
583CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
584 CpuModelInfo *model,
585 Error **errp)
586{
587 return arch_query_cpu_model_expansion(type, model, errp);
588}
589
0031e0d6
DH
590CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
591 CpuModelInfo *modelb,
592 Error **errp)
593{
594 return arch_query_cpu_model_comparison(modela, modelb, errp);
595}
596
b18b6043
DH
597CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela,
598 CpuModelInfo *modelb,
599 Error **errp)
600{
601 return arch_query_cpu_model_baseline(modela, modelb, errp);
602}
603
b224e5e2
LC
604void qmp_add_client(const char *protocol, const char *fdname,
605 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
606 Error **errp)
607{
0ec7b3e7 608 Chardev *s;
b224e5e2
LC
609 int fd;
610
611 fd = monitor_get_fd(cur_mon, fdname, errp);
612 if (fd < 0) {
613 return;
614 }
615
616 if (strcmp(protocol, "spice") == 0) {
b25d81ba 617 if (!qemu_using_spice(errp)) {
b224e5e2
LC
618 close(fd);
619 return;
620 }
621 skipauth = has_skipauth ? skipauth : false;
622 tls = has_tls ? tls : false;
623 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
624 error_setg(errp, "spice failed to add client");
625 close(fd);
626 }
627 return;
628#ifdef CONFIG_VNC
629 } else if (strcmp(protocol, "vnc") == 0) {
630 skipauth = has_skipauth ? skipauth : false;
631 vnc_display_add_client(NULL, fd, skipauth);
632 return;
633#endif
634 } else if ((s = qemu_chr_find(protocol)) != NULL) {
635 if (qemu_chr_add_client(s, fd) < 0) {
636 error_setg(errp, "failed to add client");
637 close(fd);
638 return;
639 }
640 return;
641 }
642
643 error_setg(errp, "protocol '%s' is invalid", protocol);
644 close(fd);
645}
ab2d0531 646
cff8b2c6 647
6eb3937e
MA
648void qmp_object_add(const char *type, const char *id,
649 bool has_props, QObject *props, Error **errp)
cff8b2c6 650{
e64c75a9 651 QDict *pdict;
b70ce101 652 Visitor *v;
90998d58 653 Object *obj;
cff8b2c6
PB
654
655 if (props) {
656 pdict = qobject_to_qdict(props);
657 if (!pdict) {
485febc6
MA
658 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
659 return;
cff8b2c6 660 }
e64c75a9
MAL
661 QINCREF(pdict);
662 } else {
663 pdict = qdict_new();
cff8b2c6
PB
664 }
665
048abb7b 666 v = qobject_input_visitor_new(QOBJECT(pdict));
b70ce101
EB
667 obj = user_creatable_add_type(type, id, pdict, v, errp);
668 visit_free(v);
90998d58
DB
669 if (obj) {
670 object_unref(obj);
671 }
e64c75a9 672 QDECREF(pdict);
cff8b2c6
PB
673}
674
ab2d0531
PB
675void qmp_object_del(const char *id, Error **errp)
676{
90998d58 677 user_creatable_del(id, errp);
ab2d0531 678}
6f2e2730
IM
679
680MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
681{
682 MemoryDeviceInfoList *head = NULL;
683 MemoryDeviceInfoList **prev = &head;
684
685 qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
686
687 return head;
688}
02419bcb
IM
689
690ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
691{
692 bool ambig;
693 ACPIOSTInfoList *head = NULL;
694 ACPIOSTInfoList **prev = &head;
695 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
696
697 if (obj) {
698 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
699 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
700
701 adevc->ospm_status(adev, &prev);
702 } else {
703 error_setg(errp, "command is not supported, missing ACPI device");
704 }
705
706 return head;
707}
9aa3397f
VG
708
709MemoryInfo *qmp_query_memory_size_summary(Error **errp)
710{
711 MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
712
713 mem_info->base_memory = ram_size;
714
715 mem_info->plugged_memory = get_plugged_memory_size();
716 mem_info->has_plugged_memory =
717 mem_info->plugged_memory != (uint64_t)-1;
718
719 return mem_info;
720}