2 * QEMU Management Protocol commands
4 * Copyright IBM, Corp. 2011
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
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.
16 #include "qemu/osdep.h"
17 #include "qemu-common.h"
18 #include "qemu/cutils.h"
19 #include "qemu/option.h"
20 #include "monitor/monitor.h"
21 #include "sysemu/sysemu.h"
22 #include "qemu/config-file.h"
23 #include "qemu/uuid.h"
24 #include "chardev/char.h"
25 #include "ui/qemu-spice.h"
26 #include "ui/console.h"
27 #include "sysemu/kvm.h"
28 #include "sysemu/runstate.h"
29 #include "sysemu/runstate-action.h"
30 #include "sysemu/blockdev.h"
31 #include "sysemu/block-backend.h"
32 #include "qapi/error.h"
33 #include "qapi/qapi-commands-acpi.h"
34 #include "qapi/qapi-commands-block.h"
35 #include "qapi/qapi-commands-control.h"
36 #include "qapi/qapi-commands-machine.h"
37 #include "qapi/qapi-commands-misc.h"
38 #include "qapi/qapi-commands-ui.h"
39 #include "qapi/qmp/qerror.h"
40 #include "hw/mem/memory-device.h"
41 #include "hw/acpi/acpi_dev_interface.h"
43 NameInfo *qmp_query_name(Error **errp)
45 NameInfo *info = g_malloc0(sizeof(*info));
48 info->has_name = true;
49 info->name = g_strdup(qemu_name);
55 KvmInfo *qmp_query_kvm(Error **errp)
57 KvmInfo *info = g_malloc0(sizeof(*info));
59 info->enabled = kvm_enabled();
60 info->present = accel_find("kvm");
65 UuidInfo *qmp_query_uuid(Error **errp)
67 UuidInfo *info = g_malloc0(sizeof(*info));
69 info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid);
73 void qmp_quit(Error **errp)
75 shutdown_action = SHUTDOWN_ACTION_POWEROFF;
76 qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT);
79 void qmp_stop(Error **errp)
81 /* if there is a dump in background, we should wait until the dump
83 if (dump_in_progress()) {
84 error_setg(errp, "There is a dump in process, please wait.");
88 if (runstate_check(RUN_STATE_INMIGRATE)) {
91 vm_stop(RUN_STATE_PAUSED);
95 void qmp_system_reset(Error **errp)
97 qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET);
100 void qmp_system_powerdown(Error **errp)
102 qemu_system_powerdown_request();
105 void qmp_cont(Error **errp)
109 Error *local_err = NULL;
111 /* if there is a dump in background, we should wait until the dump
113 if (dump_in_progress()) {
114 error_setg(errp, "There is a dump in process, please wait.");
118 if (runstate_needs_reset()) {
119 error_setg(errp, "Resetting the Virtual Machine is required");
121 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
123 } else if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
124 error_setg(errp, "Migration is not finalized yet");
128 for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
129 blk_iostatus_reset(blk);
132 for (job = block_job_next(NULL); job; job = block_job_next(job)) {
133 block_job_iostatus_reset(job);
136 /* Continuing after completed migration. Images have been inactivated to
137 * allow the destination to take control. Need to get control back now.
139 * If there are no inactive block nodes (e.g. because the VM was just
140 * paused rather than completing a migration), bdrv_inactivate_all() simply
141 * doesn't do anything. */
142 bdrv_invalidate_cache_all(&local_err);
144 error_propagate(errp, local_err);
148 if (runstate_check(RUN_STATE_INMIGRATE)) {
155 void qmp_system_wakeup(Error **errp)
157 if (!qemu_wakeup_suspend_enabled()) {
159 "wake-up from suspend is not supported by this guest");
163 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, errp);
166 void qmp_set_password(const char *protocol, const char *password,
167 bool has_connected, const char *connected, Error **errp)
169 int disconnect_if_connected = 0;
170 int fail_if_connected = 0;
174 if (strcmp(connected, "fail") == 0) {
175 fail_if_connected = 1;
176 } else if (strcmp(connected, "disconnect") == 0) {
177 disconnect_if_connected = 1;
178 } else if (strcmp(connected, "keep") == 0) {
181 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
186 if (strcmp(protocol, "spice") == 0) {
187 if (!qemu_using_spice(errp)) {
190 rc = qemu_spice.set_passwd(password, fail_if_connected,
191 disconnect_if_connected);
192 } else if (strcmp(protocol, "vnc") == 0) {
193 if (fail_if_connected || disconnect_if_connected) {
194 /* vnc supports "connected=keep" only */
195 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
198 /* Note that setting an empty password will not disable login through
200 rc = vnc_display_password(NULL, password);
202 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol",
208 error_setg(errp, "Could not set password");
212 void qmp_expire_password(const char *protocol, const char *whenstr,
218 if (strcmp(whenstr, "now") == 0) {
220 } else if (strcmp(whenstr, "never") == 0) {
222 } else if (whenstr[0] == '+') {
223 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
225 when = strtoull(whenstr, NULL, 10);
228 if (strcmp(protocol, "spice") == 0) {
229 if (!qemu_using_spice(errp)) {
232 rc = qemu_spice.set_pw_expire(when);
233 } else if (strcmp(protocol, "vnc") == 0) {
234 rc = vnc_display_pw_expire(NULL, when);
236 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol",
242 error_setg(errp, "Could not set password expire time");
247 void qmp_change_vnc_password(const char *password, Error **errp)
249 if (vnc_display_password(NULL, password) < 0) {
250 error_setg(errp, "Could not set password");
255 void qmp_add_client(const char *protocol, const char *fdname,
256 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
262 fd = monitor_get_fd(monitor_cur(), fdname, errp);
267 if (strcmp(protocol, "spice") == 0) {
268 if (!qemu_using_spice(errp)) {
272 skipauth = has_skipauth ? skipauth : false;
273 tls = has_tls ? tls : false;
274 if (qemu_spice.display_add_client(fd, skipauth, tls) < 0) {
275 error_setg(errp, "spice failed to add client");
280 } else if (strcmp(protocol, "vnc") == 0) {
281 skipauth = has_skipauth ? skipauth : false;
282 vnc_display_add_client(NULL, fd, skipauth);
285 } else if ((s = qemu_chr_find(protocol)) != NULL) {
286 if (qemu_chr_add_client(s, fd) < 0) {
287 error_setg(errp, "failed to add client");
294 error_setg(errp, "protocol '%s' is invalid", protocol);
299 MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
301 return qmp_memory_device_list();
304 ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
307 ACPIOSTInfoList *head = NULL;
308 ACPIOSTInfoList **prev = &head;
309 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
312 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
313 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
315 adevc->ospm_status(adev, &prev);
317 error_setg(errp, "command is not supported, missing ACPI device");
323 MemoryInfo *qmp_query_memory_size_summary(Error **errp)
325 MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
326 MachineState *ms = MACHINE(qdev_get_machine());
328 mem_info->base_memory = ms->ram_size;
330 mem_info->plugged_memory = get_plugged_memory_size();
331 mem_info->has_plugged_memory =
332 mem_info->plugged_memory != (uint64_t)-1;
337 void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
340 case DISPLAY_RELOAD_TYPE_VNC:
342 if (arg->u.vnc.has_tls_certs && arg->u.vnc.tls_certs) {
343 vnc_display_reload_certs(NULL, errp);
346 error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");