]> git.proxmox.com Git - qemu.git/blame - qmp.c
vnc: Simplify vnc_display_password()
[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
16#include "qemu-common.h"
17#include "sysemu.h"
18#include "qmp-commands.h"
292a2602
LC
19#include "kvm.h"
20#include "arch_init.h"
b4b12c62 21#include "hw/qdev.h"
eb6e8ea5
AL
22#include "qapi/qmp-input-visitor.h"
23#include "qapi/qmp-output-visitor.h"
48a32bed
AL
24
25NameInfo *qmp_query_name(Error **errp)
26{
27 NameInfo *info = g_malloc0(sizeof(*info));
28
29 if (qemu_name) {
30 info->has_name = true;
31 info->name = g_strdup(qemu_name);
32 }
33
34 return info;
35}
b9c15f16
LC
36
37VersionInfo *qmp_query_version(Error **err)
38{
39 VersionInfo *info = g_malloc0(sizeof(*info));
40 const char *version = QEMU_VERSION;
41 char *tmp;
42
43 info->qemu.major = strtol(version, &tmp, 10);
44 tmp++;
45 info->qemu.minor = strtol(tmp, &tmp, 10);
46 tmp++;
47 info->qemu.micro = strtol(tmp, &tmp, 10);
48 info->package = g_strdup(QEMU_PKGVERSION);
49
50 return info;
51}
292a2602
LC
52
53KvmInfo *qmp_query_kvm(Error **errp)
54{
55 KvmInfo *info = g_malloc0(sizeof(*info));
56
57 info->enabled = kvm_enabled();
58 info->present = kvm_available();
59
60 return info;
61}
62
efab767e
LC
63UuidInfo *qmp_query_uuid(Error **errp)
64{
65 UuidInfo *info = g_malloc0(sizeof(*info));
66 char uuid[64];
67
68 snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
69 qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
70 qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
71 qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
72 qemu_uuid[14], qemu_uuid[15]);
73
74 info->UUID = g_strdup(uuid);
75 return info;
76}
77
7a7f325e
LC
78void qmp_quit(Error **err)
79{
80 no_shutdown = 0;
81 qemu_system_shutdown_request();
82}
83
5f158f21
LC
84void qmp_stop(Error **errp)
85{
86 vm_stop(RUN_STATE_PAUSED);
87}
88
38d22653
LC
89void qmp_system_reset(Error **errp)
90{
91 qemu_system_reset_request();
92}
5bc465e4
LC
93
94void qmp_system_powerdown(Error **erp)
95{
96 qemu_system_powerdown_request();
97}
755f1968
LC
98
99void qmp_cpu(int64_t index, Error **errp)
100{
101 /* Just do nothing */
102}
2b54aa87
LC
103
104#ifndef CONFIG_VNC
105/* If VNC support is enabled, the "true" query-vnc command is
106 defined in the VNC subsystem */
107VncInfo *qmp_query_vnc(Error **errp)
108{
109 error_set(errp, QERR_FEATURE_DISABLED, "vnc");
110 return NULL;
111};
112#endif
d1f29646
LC
113
114#ifndef CONFIG_SPICE
115/* If SPICE support is enabled, the "true" query-spice command is
116 defined in the SPICE subsystem. Also note that we use a small
117 trick to maintain query-spice's original behavior, which is not
118 to be available in the namespace if SPICE is not compiled in */
119SpiceInfo *qmp_query_spice(Error **errp)
120{
121 error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice");
122 return NULL;
123};
124#endif
e42e818b
LC
125
126static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs)
127{
128 bdrv_iostatus_reset(bs);
129}
130
131static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
132{
133 Error **err = opaque;
134
135 if (!error_is_set(err) && bdrv_key_required(bs)) {
136 error_set(err, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs));
137 }
138}
139
140void qmp_cont(Error **errp)
141{
142 Error *local_err = NULL;
143
144 if (runstate_check(RUN_STATE_INMIGRATE)) {
145 error_set(errp, QERR_MIGRATION_EXPECTED);
146 return;
147 } else if (runstate_check(RUN_STATE_INTERNAL_ERROR) ||
148 runstate_check(RUN_STATE_SHUTDOWN)) {
149 error_set(errp, QERR_RESET_REQUIRED);
150 return;
151 }
152
153 bdrv_iterate(iostatus_bdrv_it, NULL);
154 bdrv_iterate(encrypted_bdrv_it, &local_err);
155 if (local_err) {
156 error_propagate(errp, local_err);
157 return;
158 }
159
160 vm_start();
161}
b4b12c62
AL
162
163DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp)
164{
165 DeviceState *dev;
166 bool ambiguous = false;
167 DevicePropertyInfoList *props = NULL;
168 DeviceProperty *prop;
169
170 dev = qdev_resolve_path(path, &ambiguous);
171 if (dev == NULL) {
172 error_set(errp, QERR_DEVICE_NOT_FOUND, path);
173 return NULL;
174 }
175
176 QTAILQ_FOREACH(prop, &dev->properties, node) {
177 DevicePropertyInfoList *entry = g_malloc0(sizeof(*entry));
178
179 entry->value = g_malloc0(sizeof(DevicePropertyInfo));
180 entry->next = props;
181 props = entry;
182
183 entry->value->name = g_strdup(prop->name);
184 entry->value->type = g_strdup(prop->type);
185 }
186
187 return props;
188}
eb6e8ea5
AL
189
190/* FIXME: teach qapi about how to pass through Visitors */
191int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
192{
193 const char *path = qdict_get_str(qdict, "path");
194 const char *property = qdict_get_str(qdict, "property");
195 QObject *value = qdict_get(qdict, "value");
196 Error *local_err = NULL;
197 QmpInputVisitor *mi;
198 DeviceState *dev;
199
200 dev = qdev_resolve_path(path, NULL);
201 if (!dev) {
202 error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
203 goto out;
204 }
205
206 mi = qmp_input_visitor_new(value);
207 qdev_property_set(dev, qmp_input_get_visitor(mi), property, &local_err);
208
209 qmp_input_visitor_cleanup(mi);
210
211out:
212 if (local_err) {
213 qerror_report_err(local_err);
214 error_free(local_err);
215 return -1;
216 }
217
218 return 0;
219}
220
221int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
222{
223 const char *path = qdict_get_str(qdict, "path");
224 const char *property = qdict_get_str(qdict, "property");
225 Error *local_err = NULL;
226 QmpOutputVisitor *mo;
227 DeviceState *dev;
228
229 dev = qdev_resolve_path(path, NULL);
230 if (!dev) {
231 error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
232 goto out;
233 }
234
235 mo = qmp_output_visitor_new();
236 qdev_property_get(dev, qmp_output_get_visitor(mo), property, &local_err);
237 if (!local_err) {
238 *ret = qmp_output_get_qobject(mo);
239 }
240
241 qmp_output_visitor_cleanup(mo);
242
243out:
244 if (local_err) {
245 qerror_report_err(local_err);
246 error_free(local_err);
247 return -1;
248 }
249
250 return 0;
251}