blob: 7ee9bcfdcf123a55438c106e0202982381045f9e [file] [log] [blame]
Anthony Liguori48a32be2011-09-02 12:34:48 -05001/*
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 *
Paolo Bonzini6b620ca2012-01-13 17:44:23 +010012 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
Anthony Liguori48a32be2011-09-02 12:34:48 -050014 */
15
Peter Maydelld38ea872016-01-29 17:50:05 +000016#include "qemu/osdep.h"
Fam Zheng67a1de02016-06-01 17:44:21 +080017#include "qemu-version.h"
Veronia Bahaaf348b6d2016-03-20 19:16:19 +020018#include "qemu/cutils.h"
Markus Armbrustera0b1a662015-03-17 18:16:21 +010019#include "monitor/monitor.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010020#include "sysemu/sysemu.h"
Marc-André Lureau213dcb02016-12-12 20:22:24 +030021#include "qemu/config-file.h"
Fam Zhengcea25272016-09-21 12:27:14 +080022#include "qemu/uuid.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050023#include "qmp-commands.h"
Marc-André Lureau8228e352017-01-26 17:19:46 +040024#include "chardev/char.h"
Luiz Capitulinofbf796f2011-12-07 11:17:51 -020025#include "ui/qemu-spice.h"
26#include "ui/vnc.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010027#include "sysemu/kvm.h"
28#include "sysemu/arch_init.h"
Anthony Liguorib4b12c62011-12-12 14:29:34 -060029#include "hw/qdev.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010030#include "sysemu/blockdev.h"
Max Reitz373340b2015-10-19 17:53:22 +020031#include "sysemu/block-backend.h"
Paolo Bonzini14cccb62012-12-17 18:19:50 +010032#include "qom/qom-qobject.h"
Markus Armbrustercc7a8ea2015-03-17 17:22:46 +010033#include "qapi/qmp/qerror.h"
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +010034#include "qapi/qmp/qobject.h"
Daniel P. Berrangeb3db2112016-09-30 15:45:27 +010035#include "qapi/qobject-input-visitor.h"
Igor Mammedov69ca3ea2013-04-30 15:41:25 +020036#include "hw/boards.h"
Igor Mammedov269e09f2014-01-16 17:34:38 +010037#include "qom/object_interfaces.h"
Igor Mammedov6f2e2732014-06-16 19:12:25 +020038#include "hw/mem/pc-dimm.h"
Igor Mammedov02419bc2014-06-16 19:12:28 +020039#include "hw/acpi/acpi_dev_interface.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050040
41NameInfo *qmp_query_name(Error **errp)
42{
43 NameInfo *info = g_malloc0(sizeof(*info));
44
45 if (qemu_name) {
46 info->has_name = true;
47 info->name = g_strdup(qemu_name);
48 }
49
50 return info;
51}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030052
Markus Armbruster7daecb32014-05-02 13:26:31 +020053VersionInfo *qmp_query_version(Error **errp)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030054{
Eric Blake4752cdb2015-05-04 09:05:31 -060055 VersionInfo *info = g_new0(VersionInfo, 1);
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030056
Eric Blake4752cdb2015-05-04 09:05:31 -060057 info->qemu = g_new0(VersionTriple, 1);
Marc-André Lureau3688d8c2016-09-12 13:18:56 +040058 info->qemu->major = QEMU_VERSION_MAJOR;
59 info->qemu->minor = QEMU_VERSION_MINOR;
60 info->qemu->micro = QEMU_VERSION_MICRO;
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030061 info->package = g_strdup(QEMU_PKGVERSION);
62
63 return info;
64}
Luiz Capitulino292a2602011-09-12 15:10:53 -030065
66KvmInfo *qmp_query_kvm(Error **errp)
67{
68 KvmInfo *info = g_malloc0(sizeof(*info));
69
70 info->enabled = kvm_enabled();
71 info->present = kvm_available();
72
73 return info;
74}
75
Luiz Capitulinoefab7672011-09-13 17:16:25 -030076UuidInfo *qmp_query_uuid(Error **errp)
77{
78 UuidInfo *info = g_malloc0(sizeof(*info));
Luiz Capitulinoefab7672011-09-13 17:16:25 -030079
Fam Zheng9c5ce8d2016-09-21 12:27:22 +080080 info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid);
Luiz Capitulinoefab7672011-09-13 17:16:25 -030081 return info;
82}
83
Markus Armbruster7daecb32014-05-02 13:26:31 +020084void qmp_quit(Error **errp)
Luiz Capitulino7a7f3252011-09-15 14:20:28 -030085{
86 no_shutdown = 0;
Eric Blakecf83f142017-05-15 16:41:13 -050087 qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP);
Luiz Capitulino7a7f3252011-09-15 14:20:28 -030088}
89
Luiz Capitulino5f158f22011-09-15 14:34:39 -030090void qmp_stop(Error **errp)
91{
Peter Xu65d64f32016-02-18 13:16:49 +080092 /* if there is a dump in background, we should wait until the dump
93 * finished */
94 if (dump_in_progress()) {
95 error_setg(errp, "There is a dump in process, please wait.");
96 return;
97 }
98
Paolo Bonzini1e998142012-10-23 14:54:21 +020099 if (runstate_check(RUN_STATE_INMIGRATE)) {
100 autostart = 0;
101 } else {
102 vm_stop(RUN_STATE_PAUSED);
103 }
Luiz Capitulino5f158f22011-09-15 14:34:39 -0300104}
105
Luiz Capitulino38d22652011-09-15 14:41:46 -0300106void qmp_system_reset(Error **errp)
107{
Eric Blakecf83f142017-05-15 16:41:13 -0500108 qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP);
Luiz Capitulino38d22652011-09-15 14:41:46 -0300109}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -0300110
111void qmp_system_powerdown(Error **erp)
112{
113 qemu_system_powerdown_request();
114}
Luiz Capitulino755f1962011-10-06 14:31:39 -0300115
116void qmp_cpu(int64_t index, Error **errp)
117{
118 /* Just do nothing */
119}
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200120
Igor Mammedov69ca3ea2013-04-30 15:41:25 +0200121void qmp_cpu_add(int64_t id, Error **errp)
122{
Marcel Apfelbaum0056ae22014-03-05 19:30:47 +0200123 MachineClass *mc;
124
125 mc = MACHINE_GET_CLASS(current_machine);
Marcel Apfelbaum958db902014-04-09 20:34:53 +0300126 if (mc->hot_add_cpu) {
127 mc->hot_add_cpu(id, errp);
Igor Mammedov69ca3ea2013-04-30 15:41:25 +0200128 } else {
129 error_setg(errp, "Not supported");
130 }
131}
132
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200133#ifndef CONFIG_VNC
134/* If VNC support is enabled, the "true" query-vnc command is
135 defined in the VNC subsystem */
136VncInfo *qmp_query_vnc(Error **errp)
137{
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100138 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200139 return NULL;
140};
Leon Yu89db21772015-02-02 05:08:51 +0000141
142VncInfo2List *qmp_query_vnc_servers(Error **errp)
143{
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100144 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
Leon Yu89db21772015-02-02 05:08:51 +0000145 return NULL;
146};
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200147#endif
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200148
149#ifndef CONFIG_SPICE
Markus Armbrusterad0ec142015-01-13 15:56:11 +0100150/*
151 * qmp-commands.hx ensures that QMP command query-spice exists only
152 * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands
153 * result. However, the QAPI schema is blissfully unaware of that,
154 * and the QAPI code generator happily generates a dead
Markus Armbruster7fad30f2015-09-16 13:06:19 +0200155 * qmp_marshal_query_spice() that calls qmp_query_spice(). Provide it
156 * one, or else linking fails. FIXME Educate the QAPI schema on
157 * CONFIG_SPICE.
Markus Armbrusterad0ec142015-01-13 15:56:11 +0100158 */
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200159SpiceInfo *qmp_query_spice(Error **errp)
160{
Markus Armbrusterad0ec142015-01-13 15:56:11 +0100161 abort();
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200162};
163#endif
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200164
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200165void qmp_cont(Error **errp)
166{
Markus Armbruster4d2855a2015-01-29 10:37:00 +0100167 Error *local_err = NULL;
Max Reitz373340b2015-10-19 17:53:22 +0200168 BlockBackend *blk;
Markus Armbrusterab319792014-05-02 13:26:42 +0200169 BlockDriverState *bs;
Kevin Wolf88be7b42016-05-20 18:49:07 +0200170 BdrvNextIterator it;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200171
Peter Xu65d64f32016-02-18 13:16:49 +0800172 /* if there is a dump in background, we should wait until the dump
173 * finished */
174 if (dump_in_progress()) {
175 error_setg(errp, "There is a dump in process, please wait.");
176 return;
177 }
178
Hu Taoede085b2013-04-26 11:24:40 +0800179 if (runstate_needs_reset()) {
Cole Robinsonf231b882014-03-21 19:42:26 -0400180 error_setg(errp, "Resetting the Virtual Machine is required");
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200181 return;
Luiz Capitulinoad02b962012-04-27 13:33:36 -0300182 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
183 return;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200184 }
185
Max Reitz373340b2015-10-19 17:53:22 +0200186 for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
187 blk_iostatus_reset(blk);
Markus Armbrusterab319792014-05-02 13:26:42 +0200188 }
Kevin Wolf7c8eece2016-03-22 18:58:50 +0100189
Kevin Wolf88be7b42016-05-20 18:49:07 +0200190 for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
Markus Armbruster4d2855a2015-01-29 10:37:00 +0100191 bdrv_add_key(bs, NULL, &local_err);
192 if (local_err) {
193 error_propagate(errp, local_err);
Markus Armbrusterab319792014-05-02 13:26:42 +0200194 return;
195 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200196 }
197
Kevin Wolf76b1c7f2015-12-22 14:07:08 +0100198 /* Continuing after completed migration. Images have been inactivated to
Kevin Wolface21a52017-05-04 18:52:36 +0200199 * allow the destination to take control. Need to get control back now.
200 *
201 * If there are no inactive block nodes (e.g. because the VM was just
202 * paused rather than completing a migration), bdrv_inactivate_all() simply
203 * doesn't do anything. */
204 bdrv_invalidate_cache_all(&local_err);
205 if (local_err) {
206 error_propagate(errp, local_err);
207 return;
Kevin Wolf76b1c7f2015-12-22 14:07:08 +0100208 }
209
Paolo Bonzini1e998142012-10-23 14:54:21 +0200210 if (runstate_check(RUN_STATE_INMIGRATE)) {
211 autostart = 1;
212 } else {
213 vm_start();
214 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200215}
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600216
Gerd Hoffmann9b9df252012-02-23 13:45:21 +0100217void qmp_system_wakeup(Error **errp)
218{
219 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
220}
221
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600222ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600223{
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600224 Object *obj;
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600225 bool ambiguous = false;
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600226 ObjectPropertyInfoList *props = NULL;
227 ObjectProperty *prop;
Daniel P. Berrange7746abd2015-12-09 12:34:02 +0000228 ObjectPropertyIterator iter;
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600229
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600230 obj = object_resolve_path(path, &ambiguous);
231 if (obj == NULL) {
Michael Tokarev79772082014-05-04 12:23:59 +0400232 if (ambiguous) {
233 error_setg(errp, "Path '%s' is ambiguous", path);
234 } else {
Markus Armbruster75158eb2015-03-16 08:57:47 +0100235 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
236 "Device '%s' not found", path);
Michael Tokarev79772082014-05-04 12:23:59 +0400237 }
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600238 return NULL;
239 }
240
Daniel P. Berrange7746abd2015-12-09 12:34:02 +0000241 object_property_iter_init(&iter, obj);
242 while ((prop = object_property_iter_next(&iter))) {
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600243 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600244
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600245 entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600246 entry->next = props;
247 props = entry;
248
249 entry->value->name = g_strdup(prop->name);
250 entry->value->type = g_strdup(prop->type);
251 }
252
253 return props;
254}
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600255
Markus Armbruster6eb39372015-09-16 13:06:25 +0200256void qmp_qom_set(const char *path, const char *property, QObject *value,
257 Error **errp)
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600258{
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600259 Object *obj;
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600260
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600261 obj = object_resolve_path(path, NULL);
262 if (!obj) {
Markus Armbruster485febc2015-03-13 17:25:50 +0100263 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
Markus Armbruster75158eb2015-03-16 08:57:47 +0100264 "Device '%s' not found", path);
Markus Armbruster485febc2015-03-13 17:25:50 +0100265 return;
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600266 }
267
Markus Armbruster485febc2015-03-13 17:25:50 +0100268 object_property_set_qobject(obj, value, property, errp);
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600269}
270
Markus Armbruster6eb39372015-09-16 13:06:25 +0200271QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600272{
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600273 Object *obj;
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600274
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600275 obj = object_resolve_path(path, NULL);
276 if (!obj) {
Markus Armbruster485febc2015-03-13 17:25:50 +0100277 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
Markus Armbruster75158eb2015-03-16 08:57:47 +0100278 "Device '%s' not found", path);
Markus Armbruster6eb39372015-09-16 13:06:25 +0200279 return NULL;
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600280 }
281
Markus Armbruster6eb39372015-09-16 13:06:25 +0200282 return object_property_get_qobject(obj, property, errp);
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600283}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200284
285void qmp_set_password(const char *protocol, const char *password,
286 bool has_connected, const char *connected, Error **errp)
287{
288 int disconnect_if_connected = 0;
289 int fail_if_connected = 0;
290 int rc;
291
292 if (has_connected) {
293 if (strcmp(connected, "fail") == 0) {
294 fail_if_connected = 1;
295 } else if (strcmp(connected, "disconnect") == 0) {
296 disconnect_if_connected = 1;
297 } else if (strcmp(connected, "keep") == 0) {
298 /* nothing */
299 } else {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100300 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200301 return;
302 }
303 }
304
305 if (strcmp(protocol, "spice") == 0) {
Markus Armbrusterb25d81b2015-01-13 17:07:15 +0100306 if (!qemu_using_spice(errp)) {
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200307 return;
308 }
309 rc = qemu_spice_set_passwd(password, fail_if_connected,
310 disconnect_if_connected);
311 if (rc != 0) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100312 error_setg(errp, QERR_SET_PASSWD_FAILED);
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200313 }
314 return;
315 }
316
317 if (strcmp(protocol, "vnc") == 0) {
318 if (fail_if_connected || disconnect_if_connected) {
319 /* vnc supports "connected=keep" only */
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100320 error_setg(errp, QERR_INVALID_PARAMETER, "connected");
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200321 return;
322 }
323 /* Note that setting an empty password will not disable login through
324 * this interface. */
325 rc = vnc_display_password(NULL, password);
326 if (rc < 0) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100327 error_setg(errp, QERR_SET_PASSWD_FAILED);
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200328 }
329 return;
330 }
331
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100332 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200333}
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200334
335void qmp_expire_password(const char *protocol, const char *whenstr,
336 Error **errp)
337{
338 time_t when;
339 int rc;
340
341 if (strcmp(whenstr, "now") == 0) {
342 when = 0;
343 } else if (strcmp(whenstr, "never") == 0) {
344 when = TIME_MAX;
345 } else if (whenstr[0] == '+') {
346 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
347 } else {
348 when = strtoull(whenstr, NULL, 10);
349 }
350
351 if (strcmp(protocol, "spice") == 0) {
Markus Armbrusterb25d81b2015-01-13 17:07:15 +0100352 if (!qemu_using_spice(errp)) {
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200353 return;
354 }
355 rc = qemu_spice_set_pw_expire(when);
356 if (rc != 0) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100357 error_setg(errp, QERR_SET_PASSWD_FAILED);
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200358 }
359 return;
360 }
361
362 if (strcmp(protocol, "vnc") == 0) {
363 rc = vnc_display_pw_expire(NULL, when);
364 if (rc != 0) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100365 error_setg(errp, QERR_SET_PASSWD_FAILED);
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200366 }
367 return;
368 }
369
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100370 error_setg(errp, QERR_INVALID_PARAMETER, "protocol");
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200371}
Luiz Capitulino270b2432011-12-08 11:45:55 -0200372
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200373#ifdef CONFIG_VNC
Luiz Capitulino270b2432011-12-08 11:45:55 -0200374void qmp_change_vnc_password(const char *password, Error **errp)
375{
376 if (vnc_display_password(NULL, password) < 0) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100377 error_setg(errp, QERR_SET_PASSWD_FAILED);
Luiz Capitulino270b2432011-12-08 11:45:55 -0200378 }
379}
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200380
Paolo Bonzini007fcd3e2012-10-18 09:01:01 +0200381static void qmp_change_vnc_listen(const char *target, Error **errp)
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200382{
Gerd Hoffmann4db14622014-09-16 12:33:03 +0200383 QemuOptsList *olist = qemu_find_opts("vnc");
384 QemuOpts *opts;
385
386 if (strstr(target, "id=")) {
387 error_setg(errp, "id not supported");
388 return;
389 }
390
391 opts = qemu_opts_find(olist, "default");
392 if (opts) {
393 qemu_opts_del(opts);
394 }
Markus Armbruster70b94332015-02-13 12:50:26 +0100395 opts = vnc_parse(target, errp);
Gongleif7801c52015-02-05 17:43:35 +0800396 if (!opts) {
397 return;
398 }
399
Gerd Hoffmann4db14622014-09-16 12:33:03 +0200400 vnc_display_open("default", errp);
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200401}
402
403static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
404 Error **errp)
405{
406 if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
407 if (!has_arg) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100408 error_setg(errp, QERR_MISSING_PARAMETER, "password");
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200409 } else {
410 qmp_change_vnc_password(arg, errp);
411 }
412 } else {
413 qmp_change_vnc_listen(target, errp);
414 }
415}
416#else
417void qmp_change_vnc_password(const char *password, Error **errp)
418{
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100419 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200420}
421static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
422 Error **errp)
423{
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +0100424 error_setg(errp, QERR_FEATURE_DISABLED, "vnc");
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200425}
426#endif /* !CONFIG_VNC */
427
428void qmp_change(const char *device, const char *target,
Markus Armbruster7daecb32014-05-02 13:26:31 +0200429 bool has_arg, const char *arg, Error **errp)
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200430{
431 if (strcmp(device, "vnc") == 0) {
Markus Armbruster7daecb32014-05-02 13:26:31 +0200432 qmp_change_vnc(target, has_arg, arg, errp);
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200433 } else {
Kevin Wolf70e2cb32016-09-20 13:38:47 +0200434 qmp_blockdev_change_medium(true, device, false, NULL, target,
435 has_arg, arg, false, 0, errp);
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200436 }
437}
Anthony Liguori5eeee3f2011-12-22 14:40:54 -0600438
439static void qom_list_types_tramp(ObjectClass *klass, void *data)
440{
441 ObjectTypeInfoList *e, **pret = data;
442 ObjectTypeInfo *info;
443
444 info = g_malloc0(sizeof(*info));
445 info->name = g_strdup(object_class_get_name(klass));
446
447 e = g_malloc0(sizeof(*e));
448 e->value = info;
449 e->next = *pret;
450 *pret = e;
451}
452
453ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
454 const char *implements,
455 bool has_abstract,
456 bool abstract,
457 Error **errp)
458{
459 ObjectTypeInfoList *ret = NULL;
460
461 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
462
463 return ret;
464}
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500465
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200466/* Return a DevicePropertyInfo for a qdev property.
467 *
468 * If a qdev property with the given name does not exist, use the given default
469 * type. If the qdev property info should not be shown, return NULL.
470 *
471 * The caller must free the return value.
472 */
473static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
474 const char *name,
Gonglei07d09c52014-10-07 14:33:23 +0800475 const char *default_type,
476 const char *description)
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200477{
478 DevicePropertyInfo *info;
479 Property *prop;
480
481 do {
482 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
483 if (strcmp(name, prop->name) != 0) {
484 continue;
485 }
486
487 /*
488 * TODO Properties without a parser are just for dirty hacks.
489 * qdev_prop_ptr is the only such PropertyInfo. It's marked
490 * for removal. This conditional should be removed along with
491 * it.
492 */
493 if (!prop->info->set) {
494 return NULL; /* no way to set it, don't show */
495 }
496
497 info = g_malloc0(sizeof(*info));
498 info->name = g_strdup(prop->name);
Gonglei07d09c52014-10-07 14:33:23 +0800499 info->type = g_strdup(prop->info->name);
500 info->has_description = !!prop->info->description;
501 info->description = g_strdup(prop->info->description);
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200502 return info;
503 }
504 klass = object_class_get_parent(klass);
505 } while (klass != object_class_by_name(TYPE_DEVICE));
506
507 /* Not a qdev property, use the default type */
508 info = g_malloc0(sizeof(*info));
509 info->name = g_strdup(name);
510 info->type = g_strdup(default_type);
Gonglei07d09c52014-10-07 14:33:23 +0800511 info->has_description = !!description;
512 info->description = g_strdup(description);
513
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200514 return info;
515}
516
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500517DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
518 Error **errp)
519{
520 ObjectClass *klass;
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200521 Object *obj;
522 ObjectProperty *prop;
Daniel P. Berrange7746abd2015-12-09 12:34:02 +0000523 ObjectPropertyIterator iter;
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500524 DevicePropertyInfoList *prop_list = NULL;
525
526 klass = object_class_by_name(typename);
527 if (klass == NULL) {
Markus Armbruster75158eb2015-03-16 08:57:47 +0100528 error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
529 "Device '%s' not found", typename);
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500530 return NULL;
531 }
532
533 klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
534 if (klass == NULL) {
Lin Ma7a8c1532017-01-25 13:27:03 +0800535 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE);
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500536 return NULL;
537 }
538
Markus Armbrusteredb15232015-10-01 10:59:57 +0200539 if (object_class_is_abstract(klass)) {
Lin Ma7a8c1532017-01-25 13:27:03 +0800540 error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename",
Markus Armbrusteredb15232015-10-01 10:59:57 +0200541 "non-abstract device type");
542 return NULL;
543 }
544
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200545 obj = object_new(typename);
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500546
Daniel P. Berrange7746abd2015-12-09 12:34:02 +0000547 object_property_iter_init(&iter, obj);
548 while ((prop = object_property_iter_next(&iter))) {
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200549 DevicePropertyInfo *info;
550 DevicePropertyInfoList *entry;
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500551
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200552 /* Skip Object and DeviceState properties */
553 if (strcmp(prop->name, "type") == 0 ||
554 strcmp(prop->name, "realized") == 0 ||
555 strcmp(prop->name, "hotpluggable") == 0 ||
Stefan Hajnoczi4115dd62014-07-09 14:01:31 +0200556 strcmp(prop->name, "hotplugged") == 0 ||
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200557 strcmp(prop->name, "parent_bus") == 0) {
558 continue;
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500559 }
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200560
561 /* Skip legacy properties since they are just string versions of
562 * properties that we already list.
563 */
564 if (strstart(prop->name, "legacy-", NULL)) {
565 continue;
566 }
567
Gonglei07d09c52014-10-07 14:33:23 +0800568 info = make_device_property_info(klass, prop->name, prop->type,
569 prop->description);
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200570 if (!info) {
571 continue;
572 }
573
574 entry = g_malloc0(sizeof(*entry));
575 entry->value = info;
576 entry->next = prop_list;
577 prop_list = entry;
578 }
579
580 object_unref(obj);
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500581
582 return prop_list;
583}
Anthony Liguorie4e31c62012-08-10 11:04:13 -0500584
Anthony Liguori76b64a72012-08-14 22:17:36 -0500585CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
586{
587 return arch_query_cpu_definitions(errp);
588}
589
David Hildenbrande09484e2016-09-05 10:52:39 +0200590CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
591 CpuModelInfo *model,
592 Error **errp)
593{
594 return arch_query_cpu_model_expansion(type, model, errp);
595}
596
David Hildenbrand0031e0d2016-09-05 10:52:40 +0200597CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
598 CpuModelInfo *modelb,
599 Error **errp)
600{
601 return arch_query_cpu_model_comparison(modela, modelb, errp);
602}
603
David Hildenbrandb18b6042016-09-05 10:52:41 +0200604CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela,
605 CpuModelInfo *modelb,
606 Error **errp)
607{
608 return arch_query_cpu_model_baseline(modela, modelb, errp);
609}
610
Luiz Capitulinob224e5e2012-09-13 16:52:20 -0300611void qmp_add_client(const char *protocol, const char *fdname,
612 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
613 Error **errp)
614{
Marc-André Lureau0ec7b3e2016-12-07 16:20:22 +0300615 Chardev *s;
Luiz Capitulinob224e5e2012-09-13 16:52:20 -0300616 int fd;
617
618 fd = monitor_get_fd(cur_mon, fdname, errp);
619 if (fd < 0) {
620 return;
621 }
622
623 if (strcmp(protocol, "spice") == 0) {
Markus Armbrusterb25d81b2015-01-13 17:07:15 +0100624 if (!qemu_using_spice(errp)) {
Luiz Capitulinob224e5e2012-09-13 16:52:20 -0300625 close(fd);
626 return;
627 }
628 skipauth = has_skipauth ? skipauth : false;
629 tls = has_tls ? tls : false;
630 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
631 error_setg(errp, "spice failed to add client");
632 close(fd);
633 }
634 return;
635#ifdef CONFIG_VNC
636 } else if (strcmp(protocol, "vnc") == 0) {
637 skipauth = has_skipauth ? skipauth : false;
638 vnc_display_add_client(NULL, fd, skipauth);
639 return;
640#endif
641 } else if ((s = qemu_chr_find(protocol)) != NULL) {
642 if (qemu_chr_add_client(s, fd) < 0) {
643 error_setg(errp, "failed to add client");
644 close(fd);
645 return;
646 }
647 return;
648 }
649
650 error_setg(errp, "protocol '%s' is invalid", protocol);
651 close(fd);
652}
Paolo Bonziniab2d0532013-12-20 23:21:09 +0100653
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100654
Markus Armbruster6eb39372015-09-16 13:06:25 +0200655void qmp_object_add(const char *type, const char *id,
656 bool has_props, QObject *props, Error **errp)
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100657{
Marc-André Lureaue64c75a2016-09-23 00:39:25 +0400658 QDict *pdict;
Eric Blakeb70ce1012016-06-09 10:48:38 -0600659 Visitor *v;
Daniel P. Berrange90998d52016-02-10 18:40:59 +0000660 Object *obj;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100661
662 if (props) {
663 pdict = qobject_to_qdict(props);
664 if (!pdict) {
Markus Armbruster485febc2015-03-13 17:25:50 +0100665 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
666 return;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100667 }
Marc-André Lureaue64c75a2016-09-23 00:39:25 +0400668 QINCREF(pdict);
669 } else {
670 pdict = qdict_new();
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100671 }
672
Markus Armbruster048abb72017-03-03 13:32:39 +0100673 v = qobject_input_visitor_new(QOBJECT(pdict));
Eric Blakeb70ce1012016-06-09 10:48:38 -0600674 obj = user_creatable_add_type(type, id, pdict, v, errp);
675 visit_free(v);
Daniel P. Berrange90998d52016-02-10 18:40:59 +0000676 if (obj) {
677 object_unref(obj);
678 }
Marc-André Lureaue64c75a2016-09-23 00:39:25 +0400679 QDECREF(pdict);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100680}
681
Paolo Bonziniab2d0532013-12-20 23:21:09 +0100682void qmp_object_del(const char *id, Error **errp)
683{
Daniel P. Berrange90998d52016-02-10 18:40:59 +0000684 user_creatable_del(id, errp);
Paolo Bonziniab2d0532013-12-20 23:21:09 +0100685}
Igor Mammedov6f2e2732014-06-16 19:12:25 +0200686
687MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
688{
689 MemoryDeviceInfoList *head = NULL;
690 MemoryDeviceInfoList **prev = &head;
691
692 qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
693
694 return head;
695}
Igor Mammedov02419bc2014-06-16 19:12:28 +0200696
697ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
698{
699 bool ambig;
700 ACPIOSTInfoList *head = NULL;
701 ACPIOSTInfoList **prev = &head;
702 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
703
704 if (obj) {
705 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
706 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
707
708 adevc->ospm_status(adev, &prev);
709 } else {
710 error_setg(errp, "command is not supported, missing ACPI device");
711 }
712
713 return head;
714}