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