apic: Stop timer on reset
[qemu-kvm.git] / qmp.c
blobc74dde6c90716369893d8c4a56598cc4c8483bb0
1 /*
2 * QEMU Management Protocol
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
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-common.h"
17 #include "sysemu.h"
18 #include "qmp-commands.h"
19 #include "kvm.h"
20 #include "arch_init.h"
21 #include "hw/qdev.h"
22 #include "qapi/qmp-input-visitor.h"
23 #include "qapi/qmp-output-visitor.h"
25 NameInfo *qmp_query_name(Error **errp)
27 NameInfo *info = g_malloc0(sizeof(*info));
29 if (qemu_name) {
30 info->has_name = true;
31 info->name = g_strdup(qemu_name);
34 return info;
37 VersionInfo *qmp_query_version(Error **err)
39 VersionInfo *info = g_malloc0(sizeof(*info));
40 const char *version = QEMU_VERSION;
41 char *tmp;
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);
50 return info;
53 KvmInfo *qmp_query_kvm(Error **errp)
55 KvmInfo *info = g_malloc0(sizeof(*info));
57 info->enabled = kvm_enabled();
58 info->present = kvm_available();
60 return info;
63 UuidInfo *qmp_query_uuid(Error **errp)
65 UuidInfo *info = g_malloc0(sizeof(*info));
66 char uuid[64];
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]);
74 info->UUID = g_strdup(uuid);
75 return info;
78 void qmp_quit(Error **err)
80 no_shutdown = 0;
81 qemu_system_shutdown_request();
84 void qmp_stop(Error **errp)
86 vm_stop(RUN_STATE_PAUSED);
89 void qmp_system_reset(Error **errp)
91 qemu_system_reset_request();
94 void qmp_system_powerdown(Error **erp)
96 qemu_system_powerdown_request();
99 void qmp_cpu(int64_t index, Error **errp)
101 /* Just do nothing */
104 #ifndef CONFIG_VNC
105 /* If VNC support is enabled, the "true" query-vnc command is
106 defined in the VNC subsystem */
107 VncInfo *qmp_query_vnc(Error **errp)
109 error_set(errp, QERR_FEATURE_DISABLED, "vnc");
110 return NULL;
112 #endif
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 */
119 SpiceInfo *qmp_query_spice(Error **errp)
121 error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice");
122 return NULL;
124 #endif
126 static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs)
128 bdrv_iostatus_reset(bs);
131 static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs)
133 Error **err = opaque;
135 if (!error_is_set(err) && bdrv_key_required(bs)) {
136 error_set(err, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs));
140 void qmp_cont(Error **errp)
142 Error *local_err = NULL;
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;
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;
160 vm_start();
163 DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp)
165 DeviceState *dev;
166 bool ambiguous = false;
167 DevicePropertyInfoList *props = NULL;
168 DeviceProperty *prop;
170 dev = qdev_resolve_path(path, &ambiguous);
171 if (dev == NULL) {
172 error_set(errp, QERR_DEVICE_NOT_FOUND, path);
173 return NULL;
176 QTAILQ_FOREACH(prop, &dev->properties, node) {
177 DevicePropertyInfoList *entry = g_malloc0(sizeof(*entry));
179 entry->value = g_malloc0(sizeof(DevicePropertyInfo));
180 entry->next = props;
181 props = entry;
183 entry->value->name = g_strdup(prop->name);
184 entry->value->type = g_strdup(prop->type);
187 return props;
190 /* FIXME: teach qapi about how to pass through Visitors */
191 int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
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;
200 dev = qdev_resolve_path(path, NULL);
201 if (!dev) {
202 error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
203 goto out;
206 mi = qmp_input_visitor_new(value);
207 qdev_property_set(dev, qmp_input_get_visitor(mi), property, &local_err);
209 qmp_input_visitor_cleanup(mi);
211 out:
212 if (local_err) {
213 qerror_report_err(local_err);
214 error_free(local_err);
215 return -1;
218 return 0;
221 int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
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;
229 dev = qdev_resolve_path(path, NULL);
230 if (!dev) {
231 error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
232 goto out;
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);
241 qmp_output_visitor_cleanup(mo);
243 out:
244 if (local_err) {
245 qerror_report_err(local_err);
246 error_free(local_err);
247 return -1;
250 return 0;