]> git.proxmox.com Git - mirror_qemu.git/blame - qmp.c
vnc: fix memleak of the "vnc-worker-output" name
[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
d38ea87a 16#include "qemu/osdep.h"
67a1de0d 17#include "qemu-version.h"
f348b6d1 18#include "qemu/cutils.h"
922a01a0 19#include "qemu/option.h"
a0b1a66e 20#include "monitor/monitor.h"
9c17d615 21#include "sysemu/sysemu.h"
213dcb06 22#include "qemu/config-file.h"
cea25275 23#include "qemu/uuid.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"
112ed241
MA
34#include "qapi/qapi-commands-block-core.h"
35#include "qapi/qapi-commands-misc.h"
36#include "qapi/qapi-commands-ui.h"
452fcdbc 37#include "qapi/qmp/qdict.h"
cc7a8ea7 38#include "qapi/qmp/qerror.h"
b3db211f 39#include "qapi/qobject-input-visitor.h"
69ca3ea5 40#include "hw/boards.h"
269e09f3 41#include "qom/object_interfaces.h"
2cc0e2e8 42#include "hw/mem/memory-device.h"
02419bcb 43#include "hw/acpi/acpi_dev_interface.h"
48a32bed
AL
44
45NameInfo *qmp_query_name(Error **errp)
46{
47 NameInfo *info = g_malloc0(sizeof(*info));
48
49 if (qemu_name) {
50 info->has_name = true;
51 info->name = g_strdup(qemu_name);
52 }
53
54 return info;
55}
b9c15f16 56
7daecb30 57VersionInfo *qmp_query_version(Error **errp)
b9c15f16 58{
4752cdbb 59 VersionInfo *info = g_new0(VersionInfo, 1);
b9c15f16 60
4752cdbb 61 info->qemu = g_new0(VersionTriple, 1);
3688d8c7
MAL
62 info->qemu->major = QEMU_VERSION_MAJOR;
63 info->qemu->minor = QEMU_VERSION_MINOR;
64 info->qemu->micro = QEMU_VERSION_MICRO;
b9c15f16
LC
65 info->package = g_strdup(QEMU_PKGVERSION);
66
67 return info;
68}
292a2602
LC
69
70KvmInfo *qmp_query_kvm(Error **errp)
71{
72 KvmInfo *info = g_malloc0(sizeof(*info));
73
74 info->enabled = kvm_enabled();
75 info->present = kvm_available();
76
77 return info;
78}
79
efab767e
LC
80UuidInfo *qmp_query_uuid(Error **errp)
81{
82 UuidInfo *info = g_malloc0(sizeof(*info));
efab767e 83
9c5ce8db 84 info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid);
efab767e
LC
85 return info;
86}
87
7daecb30 88void qmp_quit(Error **errp)
7a7f325e
LC
89{
90 no_shutdown = 0;
cf83f140 91 qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP);
7a7f325e
LC
92}
93
5f158f21
LC
94void qmp_stop(Error **errp)
95{
65d64f36
PX
96 /* if there is a dump in background, we should wait until the dump
97 * finished */
98 if (dump_in_progress()) {
99 error_setg(errp, "There is a dump in process, please wait.");
100 return;
101 }
102
1e998146
PB
103 if (runstate_check(RUN_STATE_INMIGRATE)) {
104 autostart = 0;
105 } else {
106 vm_stop(RUN_STATE_PAUSED);
107 }
5f158f21
LC
108}
109
38d22653
LC
110void qmp_system_reset(Error **errp)
111{
cf83f140 112 qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP);
38d22653 113}
5bc465e4
LC
114
115void qmp_system_powerdown(Error **erp)
116{
117 qemu_system_powerdown_request();
118}
755f1968 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
361ac948 132void qmp_x_exit_preconfig(Error **errp)
047f7038
IM
133{
134 if (!runstate_check(RUN_STATE_PRECONFIG)) {
135 error_setg(errp, "The command is permitted only in '%s' state",
136 RunState_str(RUN_STATE_PRECONFIG));
137 return;
138 }
139 qemu_exit_preconfig_request();
140}
141
e42e818b
LC
142void qmp_cont(Error **errp)
143{
373340b2 144 BlockBackend *blk;
788cf9f8 145 Error *local_err = NULL;
e42e818b 146
65d64f36
PX
147 /* if there is a dump in background, we should wait until the dump
148 * finished */
149 if (dump_in_progress()) {
150 error_setg(errp, "There is a dump in process, please wait.");
151 return;
152 }
153
ede085b3 154 if (runstate_needs_reset()) {
f231b88d 155 error_setg(errp, "Resetting the Virtual Machine is required");
e42e818b 156 return;
ad02b96a
LC
157 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
158 return;
e42e818b
LC
159 }
160
373340b2
HR
161 for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
162 blk_iostatus_reset(blk);
ab31979a 163 }
7c8eece4 164
76b1c7fe 165 /* Continuing after completed migration. Images have been inactivated to
ace21a58
KW
166 * allow the destination to take control. Need to get control back now.
167 *
168 * If there are no inactive block nodes (e.g. because the VM was just
169 * paused rather than completing a migration), bdrv_inactivate_all() simply
170 * doesn't do anything. */
171 bdrv_invalidate_cache_all(&local_err);
172 if (local_err) {
173 error_propagate(errp, local_err);
174 return;
76b1c7fe
KW
175 }
176
1e998146
PB
177 if (runstate_check(RUN_STATE_INMIGRATE)) {
178 autostart = 1;
179 } else {
180 vm_start();
181 }
e42e818b 182}
b4b12c62 183
9b9df25a
GH
184void qmp_system_wakeup(Error **errp)
185{
186 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
187}
188
57c9fafe 189ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
b4b12c62 190{
57c9fafe 191 Object *obj;
b4b12c62 192 bool ambiguous = false;
57c9fafe
AL
193 ObjectPropertyInfoList *props = NULL;
194 ObjectProperty *prop;
7746abd8 195 ObjectPropertyIterator iter;
b4b12c62 196
57c9fafe
AL
197 obj = object_resolve_path(path, &ambiguous);
198 if (obj == NULL) {
79772087
MT
199 if (ambiguous) {
200 error_setg(errp, "Path '%s' is ambiguous", path);
201 } else {
75158ebb
MA
202 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
203 "Device '%s' not found", path);
79772087 204 }
b4b12c62
AL
205 return NULL;
206 }
207
7746abd8
DB
208 object_property_iter_init(&iter, obj);
209 while ((prop = object_property_iter_next(&iter))) {
57c9fafe 210 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
b4b12c62 211
57c9fafe 212 entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
b4b12c62
AL
213 entry->next = props;
214 props = entry;
215
216 entry->value->name = g_strdup(prop->name);
217 entry->value->type = g_strdup(prop->type);
218 }
219
220 return props;
221}
eb6e8ea5 222
6eb3937e
MA
223void qmp_qom_set(const char *path, const char *property, QObject *value,
224 Error **errp)
eb6e8ea5 225{
57c9fafe 226 Object *obj;
eb6e8ea5 227
57c9fafe
AL
228 obj = object_resolve_path(path, NULL);
229 if (!obj) {
485febc6 230 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
75158ebb 231 "Device '%s' not found", path);
485febc6 232 return;
eb6e8ea5
AL
233 }
234
485febc6 235 object_property_set_qobject(obj, value, property, errp);
eb6e8ea5
AL
236}
237
6eb3937e 238QObject *qmp_qom_get(const char *path, const char *property, 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);
6eb3937e 246 return NULL;
eb6e8ea5
AL
247 }
248
6eb3937e 249 return object_property_get_qobject(obj, property, errp);
eb6e8ea5 250}
fbf796fd
LC
251
252void qmp_set_password(const char *protocol, const char *password,
253 bool has_connected, const char *connected, Error **errp)
254{
255 int disconnect_if_connected = 0;
256 int fail_if_connected = 0;
257 int rc;
258
259 if (has_connected) {
260 if (strcmp(connected, "fail") == 0) {
261 fail_if_connected = 1;
262 } else if (strcmp(connected, "disconnect") == 0) {
263 disconnect_if_connected = 1;
264 } else if (strcmp(connected, "keep") == 0) {
265 /* nothing */
266 } else {
c6bd8c70 267 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
268 return;
269 }
270 }
271
272 if (strcmp(protocol, "spice") == 0) {
b25d81ba 273 if (!qemu_using_spice(errp)) {
fbf796fd
LC
274 return;
275 }
276 rc = qemu_spice_set_passwd(password, fail_if_connected,
277 disconnect_if_connected);
278 if (rc != 0) {
c6bd8c70 279 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
280 }
281 return;
282 }
283
284 if (strcmp(protocol, "vnc") == 0) {
285 if (fail_if_connected || disconnect_if_connected) {
286 /* vnc supports "connected=keep" only */
c6bd8c70 287 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
fbf796fd
LC
288 return;
289 }
290 /* Note that setting an empty password will not disable login through
291 * this interface. */
292 rc = vnc_display_password(NULL, password);
293 if (rc < 0) {
c6bd8c70 294 error_setg(errp, QERR_SET_PASSWD_FAILED);
fbf796fd
LC
295 }
296 return;
297 }
298
c6bd8c70 299 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
fbf796fd 300}
9ad5372d
LC
301
302void qmp_expire_password(const char *protocol, const char *whenstr,
303 Error **errp)
304{
305 time_t when;
306 int rc;
307
308 if (strcmp(whenstr, "now") == 0) {
309 when = 0;
310 } else if (strcmp(whenstr, "never") == 0) {
311 when = TIME_MAX;
312 } else if (whenstr[0] == '+') {
313 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
314 } else {
315 when = strtoull(whenstr, NULL, 10);
316 }
317
318 if (strcmp(protocol, "spice") == 0) {
b25d81ba 319 if (!qemu_using_spice(errp)) {
9ad5372d
LC
320 return;
321 }
322 rc = qemu_spice_set_pw_expire(when);
323 if (rc != 0) {
c6bd8c70 324 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
325 }
326 return;
327 }
328
329 if (strcmp(protocol, "vnc") == 0) {
330 rc = vnc_display_pw_expire(NULL, when);
331 if (rc != 0) {
c6bd8c70 332 error_setg(errp, QERR_SET_PASSWD_FAILED);
9ad5372d
LC
333 }
334 return;
335 }
336
c6bd8c70 337 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
9ad5372d 338}
270b243f 339
333a96ec 340#ifdef CONFIG_VNC
270b243f
LC
341void qmp_change_vnc_password(const char *password, Error **errp)
342{
343 if (vnc_display_password(NULL, password) < 0) {
c6bd8c70 344 error_setg(errp, QERR_SET_PASSWD_FAILED);
270b243f
LC
345 }
346}
333a96ec 347
007fcd3e 348static void qmp_change_vnc_listen(const char *target, Error **errp)
333a96ec 349{
4db14629
GH
350 QemuOptsList *olist = qemu_find_opts("vnc");
351 QemuOpts *opts;
352
353 if (strstr(target, "id=")) {
354 error_setg(errp, "id not supported");
355 return;
356 }
357
358 opts = qemu_opts_find(olist, "default");
359 if (opts) {
360 qemu_opts_del(opts);
361 }
70b94331 362 opts = vnc_parse(target, errp);
f7801c5c
GA
363 if (!opts) {
364 return;
365 }
366
4db14629 367 vnc_display_open("default", errp);
333a96ec
LC
368}
369
370static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
371 Error **errp)
372{
373 if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
374 if (!has_arg) {
c6bd8c70 375 error_setg(errp, QERR_MISSING_PARAMETER, "password");
333a96ec
LC
376 } else {
377 qmp_change_vnc_password(arg, errp);
378 }
379 } else {
380 qmp_change_vnc_listen(target, errp);
381 }
382}
333a96ec
LC
383#endif /* !CONFIG_VNC */
384
385void qmp_change(const char *device, const char *target,
7daecb30 386 bool has_arg, const char *arg, Error **errp)
333a96ec
LC
387{
388 if (strcmp(device, "vnc") == 0) {
05eb4a25 389#ifdef CONFIG_VNC
7daecb30 390 qmp_change_vnc(target, has_arg, arg, errp);
05eb4a25
MAL
391#else
392 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
393#endif
333a96ec 394 } else {
70e2cb3b
KW
395 qmp_blockdev_change_medium(true, device, false, NULL, target,
396 has_arg, arg, false, 0, errp);
333a96ec
LC
397 }
398}
5eeee3fa
AL
399
400static void qom_list_types_tramp(ObjectClass *klass, void *data)
401{
402 ObjectTypeInfoList *e, **pret = data;
403 ObjectTypeInfo *info;
f86285c5 404 ObjectClass *parent = object_class_get_parent(klass);
5eeee3fa
AL
405
406 info = g_malloc0(sizeof(*info));
407 info->name = g_strdup(object_class_get_name(klass));
87467eae 408 info->has_abstract = info->abstract = object_class_is_abstract(klass);
f86285c5
EH
409 if (parent) {
410 info->has_parent = true;
411 info->parent = g_strdup(object_class_get_name(parent));
412 }
5eeee3fa
AL
413
414 e = g_malloc0(sizeof(*e));
415 e->value = info;
416 e->next = *pret;
417 *pret = e;
418}
419
420ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
421 const char *implements,
422 bool has_abstract,
423 bool abstract,
424 Error **errp)
425{
426 ObjectTypeInfoList *ret = NULL;
427
428 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
429
430 return ret;
431}
1daa31b9 432
f4eb32b5
SH
433/* Return a DevicePropertyInfo for a qdev property.
434 *
435 * If a qdev property with the given name does not exist, use the given default
436 * type. If the qdev property info should not be shown, return NULL.
437 *
438 * The caller must free the return value.
439 */
35f63767
AK
440static ObjectPropertyInfo *make_device_property_info(ObjectClass *klass,
441 const char *name,
442 const char *default_type,
443 const char *description)
f4eb32b5 444{
35f63767 445 ObjectPropertyInfo *info;
f4eb32b5
SH
446 Property *prop;
447
448 do {
449 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
450 if (strcmp(name, prop->name) != 0) {
451 continue;
452 }
453
454 /*
455 * TODO Properties without a parser are just for dirty hacks.
456 * qdev_prop_ptr is the only such PropertyInfo. It's marked
457 * for removal. This conditional should be removed along with
458 * it.
459 */
faabdbb7 460 if (!prop->info->set && !prop->info->create) {
f4eb32b5
SH
461 return NULL; /* no way to set it, don't show */
462 }
463
464 info = g_malloc0(sizeof(*info));
465 info->name = g_strdup(prop->name);
75ab9053
FZ
466 info->type = default_type ? g_strdup(default_type)
467 : g_strdup(prop->info->name);
07d09c58
GA
468 info->has_description = !!prop->info->description;
469 info->description = g_strdup(prop->info->description);
f4eb32b5
SH
470 return info;
471 }
472 klass = object_class_get_parent(klass);
473 } while (klass != object_class_by_name(TYPE_DEVICE));
474
475 /* Not a qdev property, use the default type */
476 info = g_malloc0(sizeof(*info));
477 info->name = g_strdup(name);
478 info->type = g_strdup(default_type);
07d09c58
GA
479 info->has_description = !!description;
480 info->description = g_strdup(description);
481
f4eb32b5
SH
482 return info;
483}
484
35f63767
AK
485ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
486 Error **errp)
1daa31b9
AL
487{
488 ObjectClass *klass;
f4eb32b5
SH
489 Object *obj;
490 ObjectProperty *prop;
7746abd8 491 ObjectPropertyIterator iter;
35f63767 492 ObjectPropertyInfoList *prop_list = NULL;
1daa31b9
AL
493
494 klass = object_class_by_name(typename);
495 if (klass == NULL) {
75158ebb
MA
496 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
497 "Device '%s' not found", typename);
1daa31b9
AL
498 return NULL;
499 }
500
501 klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
502 if (klass == NULL) {
7a8c153f 503 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE);
1daa31b9
AL
504 return NULL;
505 }
506
edb1523d 507 if (object_class_is_abstract(klass)) {
7a8c153f 508 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
edb1523d
MA
509 "non-abstract device type");
510 return NULL;
511 }
512
f4eb32b5 513 obj = object_new(typename);
1daa31b9 514
7746abd8
DB
515 object_property_iter_init(&iter, obj);
516 while ((prop = object_property_iter_next(&iter))) {
35f63767
AK
517 ObjectPropertyInfo *info;
518 ObjectPropertyInfoList *entry;
f4eb32b5
SH
519
520 /* Skip Object and DeviceState properties */
521 if (strcmp(prop->name, "type") == 0 ||
522 strcmp(prop->name, "realized") == 0 ||
523 strcmp(prop->name, "hotpluggable") == 0 ||
4115dd65 524 strcmp(prop->name, "hotplugged") == 0 ||
f4eb32b5
SH
525 strcmp(prop->name, "parent_bus") == 0) {
526 continue;
527 }
1daa31b9 528
f4eb32b5
SH
529 /* Skip legacy properties since they are just string versions of
530 * properties that we already list.
531 */
532 if (strstart(prop->name, "legacy-", NULL)) {
533 continue;
534 }
1daa31b9 535
07d09c58
GA
536 info = make_device_property_info(klass, prop->name, prop->type,
537 prop->description);
f4eb32b5
SH
538 if (!info) {
539 continue;
1daa31b9 540 }
f4eb32b5
SH
541
542 entry = g_malloc0(sizeof(*entry));
961c47bb
AK
543 entry->value = info;
544 entry->next = prop_list;
545 prop_list = entry;
546 }
547
548 object_unref(obj);
549
550 return prop_list;
551}
552
553ObjectPropertyInfoList *qmp_qom_list_properties(const char *typename,
554 Error **errp)
555{
556 ObjectClass *klass;
557 Object *obj = NULL;
558 ObjectProperty *prop;
559 ObjectPropertyIterator iter;
560 ObjectPropertyInfoList *prop_list = NULL;
561
562 klass = object_class_by_name(typename);
563 if (klass == NULL) {
564 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
565 "Class '%s' not found", typename);
566 return NULL;
567 }
568
569 klass = object_class_dynamic_cast(klass, TYPE_OBJECT);
570 if (klass == NULL) {
571 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_OBJECT);
572 return NULL;
573 }
574
575 if (object_class_is_abstract(klass)) {
576 object_class_property_iter_init(&iter, klass);
577 } else {
578 obj = object_new(typename);
579 object_property_iter_init(&iter, obj);
580 }
581 while ((prop = object_property_iter_next(&iter))) {
582 ObjectPropertyInfo *info;
583 ObjectPropertyInfoList *entry;
584
585 info = g_malloc0(sizeof(*info));
586 info->name = g_strdup(prop->name);
587 info->type = g_strdup(prop->type);
588 info->has_description = !!prop->description;
589 info->description = g_strdup(prop->description);
590
591 entry = g_malloc0(sizeof(*entry));
f4eb32b5
SH
592 entry->value = info;
593 entry->next = prop_list;
594 prop_list = entry;
595 }
596
597 object_unref(obj);
1daa31b9
AL
598
599 return prop_list;
600}
e4e31c63 601
76b64a7a
AL
602CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
603{
604 return arch_query_cpu_definitions(errp);
605}
606
e09484ef
DH
607CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
608 CpuModelInfo *model,
609 Error **errp)
610{
611 return arch_query_cpu_model_expansion(type, model, errp);
612}
613
0031e0d6
DH
614CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
615 CpuModelInfo *modelb,
616 Error **errp)
617{
618 return arch_query_cpu_model_comparison(modela, modelb, errp);
619}
620
b18b6043
DH
621CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela,
622 CpuModelInfo *modelb,
623 Error **errp)
624{
625 return arch_query_cpu_model_baseline(modela, modelb, errp);
626}
627
b224e5e2
LC
628void qmp_add_client(const char *protocol, const char *fdname,
629 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
630 Error **errp)
631{
0ec7b3e7 632 Chardev *s;
b224e5e2
LC
633 int fd;
634
635 fd = monitor_get_fd(cur_mon, fdname, errp);
636 if (fd < 0) {
637 return;
638 }
639
640 if (strcmp(protocol, "spice") == 0) {
b25d81ba 641 if (!qemu_using_spice(errp)) {
b224e5e2
LC
642 close(fd);
643 return;
644 }
645 skipauth = has_skipauth ? skipauth : false;
646 tls = has_tls ? tls : false;
647 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
648 error_setg(errp, "spice failed to add client");
649 close(fd);
650 }
651 return;
652#ifdef CONFIG_VNC
653 } else if (strcmp(protocol, "vnc") == 0) {
654 skipauth = has_skipauth ? skipauth : false;
655 vnc_display_add_client(NULL, fd, skipauth);
656 return;
657#endif
658 } else if ((s = qemu_chr_find(protocol)) != NULL) {
659 if (qemu_chr_add_client(s, fd) < 0) {
660 error_setg(errp, "failed to add client");
661 close(fd);
662 return;
663 }
664 return;
665 }
666
667 error_setg(errp, "protocol '%s' is invalid", protocol);
668 close(fd);
669}
ab2d0531 670
cff8b2c6 671
6eb3937e
MA
672void qmp_object_add(const char *type, const char *id,
673 bool has_props, QObject *props, Error **errp)
cff8b2c6 674{
e64c75a9 675 QDict *pdict;
b70ce101 676 Visitor *v;
90998d58 677 Object *obj;
cff8b2c6
PB
678
679 if (props) {
7dc847eb 680 pdict = qobject_to(QDict, props);
cff8b2c6 681 if (!pdict) {
485febc6
MA
682 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
683 return;
cff8b2c6 684 }
cb3e7f08 685 qobject_ref(pdict);
e64c75a9
MAL
686 } else {
687 pdict = qdict_new();
cff8b2c6
PB
688 }
689
048abb7b 690 v = qobject_input_visitor_new(QOBJECT(pdict));
b70ce101
EB
691 obj = user_creatable_add_type(type, id, pdict, v, errp);
692 visit_free(v);
90998d58
DB
693 if (obj) {
694 object_unref(obj);
695 }
cb3e7f08 696 qobject_unref(pdict);
cff8b2c6
PB
697}
698
ab2d0531
PB
699void qmp_object_del(const char *id, Error **errp)
700{
90998d58 701 user_creatable_del(id, errp);
ab2d0531 702}
6f2e2730
IM
703
704MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
705{
2cc0e2e8 706 return qmp_memory_device_list();
6f2e2730 707}
02419bcb
IM
708
709ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
710{
711 bool ambig;
712 ACPIOSTInfoList *head = NULL;
713 ACPIOSTInfoList **prev = &head;
714 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
715
716 if (obj) {
717 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
718 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
719
720 adevc->ospm_status(adev, &prev);
721 } else {
722 error_setg(errp, "command is not supported, missing ACPI device");
723 }
724
725 return head;
726}
9aa3397f
VG
727
728MemoryInfo *qmp_query_memory_size_summary(Error **errp)
729{
730 MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
731
732 mem_info->base_memory = ram_size;
733
734 mem_info->plugged_memory = get_plugged_memory_size();
735 mem_info->has_plugged_memory =
736 mem_info->plugged_memory != (uint64_t)-1;
737
738 return mem_info;
739}