]> git.proxmox.com Git - mirror_qemu.git/blame - monitor/qmp-cmds.c
hw/xen: Create initial XenStore nodes
[mirror_qemu.git] / monitor / qmp-cmds.c
CommitLineData
48a32bed 1/*
f1b3ccfa 2 * QEMU Management Protocol commands
48a32bed
AL
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"
e6e108d1
MA
17#include "monitor-internal.h"
18#include "monitor/qdev.h"
3125af29 19#include "monitor/qmp-helpers.h"
9c17d615 20#include "sysemu/sysemu.h"
9c17d615 21#include "sysemu/kvm.h"
54d31236 22#include "sysemu/runstate.h"
e6dba048 23#include "sysemu/runstate-action.h"
373340b2 24#include "sysemu/block-backend.h"
e688df6b 25#include "qapi/error.h"
e6e108d1 26#include "qapi/qapi-init-commands.h"
fa4dcf57 27#include "qapi/qapi-commands-control.h"
112ed241 28#include "qapi/qapi-commands-misc.h"
e6e108d1 29#include "qapi/qmp/qerror.h"
37087fde 30#include "qapi/type-helpers.h"
2cc0e2e8 31#include "hw/mem/memory-device.h"
91f2fa70 32#include "hw/intc/intc.h"
8dbbca5c 33#include "hw/rdma/rdma.h"
48a32bed
AL
34
35NameInfo *qmp_query_name(Error **errp)
36{
37 NameInfo *info = g_malloc0(sizeof(*info));
38
9492718b 39 info->name = g_strdup(qemu_name);
48a32bed
AL
40 return info;
41}
b9c15f16 42
7daecb30 43void qmp_quit(Error **errp)
7a7f325e 44{
e6dba048 45 shutdown_action = SHUTDOWN_ACTION_POWEROFF;
92548938 46 qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT);
7a7f325e
LC
47}
48
5f158f21
LC
49void qmp_stop(Error **errp)
50{
65d64f36
PX
51 /* if there is a dump in background, we should wait until the dump
52 * finished */
544803c7 53 if (qemu_system_dump_in_progress()) {
65d64f36
PX
54 error_setg(errp, "There is a dump in process, please wait.");
55 return;
56 }
57
1e998146
PB
58 if (runstate_check(RUN_STATE_INMIGRATE)) {
59 autostart = 0;
60 } else {
61 vm_stop(RUN_STATE_PAUSED);
62 }
5f158f21
LC
63}
64
e42e818b
LC
65void qmp_cont(Error **errp)
66{
373340b2 67 BlockBackend *blk;
68d00e42 68 BlockJob *job;
788cf9f8 69 Error *local_err = NULL;
e42e818b 70
65d64f36
PX
71 /* if there is a dump in background, we should wait until the dump
72 * finished */
544803c7 73 if (qemu_system_dump_in_progress()) {
65d64f36
PX
74 error_setg(errp, "There is a dump in process, please wait.");
75 return;
76 }
77
ede085b3 78 if (runstate_needs_reset()) {
f231b88d 79 error_setg(errp, "Resetting the Virtual Machine is required");
e42e818b 80 return;
ad02b96a
LC
81 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
82 return;
9183dd15
VSO
83 } else if (runstate_check(RUN_STATE_FINISH_MIGRATE)) {
84 error_setg(errp, "Migration is not finalized yet");
85 return;
e42e818b
LC
86 }
87
373340b2
HR
88 for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
89 blk_iostatus_reset(blk);
ab31979a 90 }
7c8eece4 91
880eeec6
EGE
92 WITH_JOB_LOCK_GUARD() {
93 for (job = block_job_next_locked(NULL); job;
94 job = block_job_next_locked(job)) {
95 block_job_iostatus_reset_locked(job);
96 }
68d00e42
VSO
97 }
98
76b1c7fe 99 /* Continuing after completed migration. Images have been inactivated to
ace21a58
KW
100 * allow the destination to take control. Need to get control back now.
101 *
102 * If there are no inactive block nodes (e.g. because the VM was just
103 * paused rather than completing a migration), bdrv_inactivate_all() simply
104 * doesn't do anything. */
3b717194 105 bdrv_activate_all(&local_err);
ace21a58
KW
106 if (local_err) {
107 error_propagate(errp, local_err);
108 return;
76b1c7fe
KW
109 }
110
1e998146
PB
111 if (runstate_check(RUN_STATE_INMIGRATE)) {
112 autostart = 1;
113 } else {
114 vm_start();
115 }
e42e818b 116}
b4b12c62 117
b224e5e2
LC
118void qmp_add_client(const char *protocol, const char *fdname,
119 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
120 Error **errp)
121{
f916a175 122 static const struct {
3125af29
MA
123 const char *name;
124 bool (*add_client)(int fd, bool has_skipauth, bool skipauth,
125 bool has_tls, bool tls, Error **errp);
126 } protocol_table[] = {
127 { "spice", qmp_add_client_spice },
128#ifdef CONFIG_VNC
129 { "vnc", qmp_add_client_vnc },
130#endif
131#ifdef CONFIG_DBUS_DISPLAY
132 { "@dbus-display", qmp_add_client_dbus_display },
133#endif
134 };
3125af29 135 int fd, i;
b224e5e2 136
947e4744 137 fd = monitor_get_fd(monitor_cur(), fdname, errp);
b224e5e2
LC
138 if (fd < 0) {
139 return;
140 }
141
3125af29
MA
142 for (i = 0; i < ARRAY_SIZE(protocol_table); i++) {
143 if (!strcmp(protocol, protocol_table[i].name)) {
144 if (!protocol_table[i].add_client(fd, has_skipauth, skipauth,
145 has_tls, tls, errp)) {
146 close(fd);
147 }
b224e5e2
LC
148 return;
149 }
b224e5e2 150 }
3125af29 151
c3054a6e
MA
152 if (!qmp_add_client_char(fd, has_skipauth, skipauth, has_tls, tls,
153 protocol, errp)) {
3125af29 154 close(fd);
3125af29 155 }
b224e5e2 156}
e6e108d1
MA
157
158char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
159 int64_t cpu_index, Error **errp)
160{
161 char *output = NULL;
162 MonitorHMP hmp = {};
163
164 monitor_data_init(&hmp.common, false, true, false);
165
166 if (has_cpu_index) {
167 int ret = monitor_set_cpu(&hmp.common, cpu_index);
168 if (ret < 0) {
169 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
170 "a CPU number");
171 goto out;
172 }
173 }
174
175 handle_hmp_command(&hmp, command_line);
176
177 WITH_QEMU_LOCK_GUARD(&hmp.common.mon_lock) {
178 output = g_strdup(hmp.common.outbuf->str);
179 }
180
181out:
182 monitor_data_destroy(&hmp.common);
183 return output;
184}
185
186static void __attribute__((__constructor__)) monitor_init_qmp_commands(void)
187{
188 /*
189 * Two command lists:
190 * - qmp_commands contains all QMP commands
191 * - qmp_cap_negotiation_commands contains just
192 * "qmp_capabilities", to enforce capability negotiation
193 */
194
195 qmp_init_marshal(&qmp_commands);
196
197 qmp_register_command(&qmp_commands, "device_add",
198 qmp_device_add, 0, 0);
199
200 QTAILQ_INIT(&qmp_cap_negotiation_commands);
201 qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
202 qmp_marshal_qmp_capabilities,
203 QCO_ALLOW_PRECONFIG, 0);
204}