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