blob: ef155ff3aa0464f7a351df3fcb132ae0cf81d074 [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
16#include "qemu-common.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010017#include "sysemu/sysemu.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050018#include "qmp-commands.h"
Paolo Bonzinidccfcd02013-04-08 16:55:25 +020019#include "sysemu/char.h"
Luiz Capitulinofbf796f2011-12-07 11:17:51 -020020#include "ui/qemu-spice.h"
21#include "ui/vnc.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010022#include "sysemu/kvm.h"
23#include "sysemu/arch_init.h"
Anthony Liguorib4b12c62011-12-12 14:29:34 -060024#include "hw/qdev.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010025#include "sysemu/blockdev.h"
Paolo Bonzini14cccb62012-12-17 18:19:50 +010026#include "qom/qom-qobject.h"
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +010027#include "qapi/qmp/qobject.h"
28#include "qapi/qmp-input-visitor.h"
Igor Mammedov69ca3ea2013-04-30 15:41:25 +020029#include "hw/boards.h"
Igor Mammedov269e09f2014-01-16 17:34:38 +010030#include "qom/object_interfaces.h"
Igor Mammedov6f2e2732014-06-16 19:12:25 +020031#include "hw/mem/pc-dimm.h"
Igor Mammedov02419bc2014-06-16 19:12:28 +020032#include "hw/acpi/acpi_dev_interface.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050033
34NameInfo *qmp_query_name(Error **errp)
35{
36 NameInfo *info = g_malloc0(sizeof(*info));
37
38 if (qemu_name) {
39 info->has_name = true;
40 info->name = g_strdup(qemu_name);
41 }
42
43 return info;
44}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030045
Markus Armbruster7daecb32014-05-02 13:26:31 +020046VersionInfo *qmp_query_version(Error **errp)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030047{
48 VersionInfo *info = g_malloc0(sizeof(*info));
49 const char *version = QEMU_VERSION;
50 char *tmp;
51
52 info->qemu.major = strtol(version, &tmp, 10);
53 tmp++;
54 info->qemu.minor = strtol(tmp, &tmp, 10);
55 tmp++;
56 info->qemu.micro = strtol(tmp, &tmp, 10);
57 info->package = g_strdup(QEMU_PKGVERSION);
58
59 return info;
60}
Luiz Capitulino292a2602011-09-12 15:10:53 -030061
62KvmInfo *qmp_query_kvm(Error **errp)
63{
64 KvmInfo *info = g_malloc0(sizeof(*info));
65
66 info->enabled = kvm_enabled();
67 info->present = kvm_available();
68
69 return info;
70}
71
Luiz Capitulinoefab7672011-09-13 17:16:25 -030072UuidInfo *qmp_query_uuid(Error **errp)
73{
74 UuidInfo *info = g_malloc0(sizeof(*info));
75 char uuid[64];
76
77 snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
78 qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
79 qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
80 qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
81 qemu_uuid[14], qemu_uuid[15]);
82
83 info->UUID = g_strdup(uuid);
84 return info;
85}
86
Markus Armbruster7daecb32014-05-02 13:26:31 +020087void qmp_quit(Error **errp)
Luiz Capitulino7a7f3252011-09-15 14:20:28 -030088{
89 no_shutdown = 0;
90 qemu_system_shutdown_request();
91}
92
Luiz Capitulino5f158f22011-09-15 14:34:39 -030093void qmp_stop(Error **errp)
94{
Paolo Bonzini1e998142012-10-23 14:54:21 +020095 if (runstate_check(RUN_STATE_INMIGRATE)) {
96 autostart = 0;
97 } else {
98 vm_stop(RUN_STATE_PAUSED);
99 }
Luiz Capitulino5f158f22011-09-15 14:34:39 -0300100}
101
Luiz Capitulino38d22652011-09-15 14:41:46 -0300102void qmp_system_reset(Error **errp)
103{
104 qemu_system_reset_request();
105}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -0300106
107void qmp_system_powerdown(Error **erp)
108{
109 qemu_system_powerdown_request();
110}
Luiz Capitulino755f1962011-10-06 14:31:39 -0300111
112void qmp_cpu(int64_t index, Error **errp)
113{
114 /* Just do nothing */
115}
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200116
Igor Mammedov69ca3ea2013-04-30 15:41:25 +0200117void qmp_cpu_add(int64_t id, Error **errp)
118{
Marcel Apfelbaum0056ae22014-03-05 19:30:47 +0200119 MachineClass *mc;
120
121 mc = MACHINE_GET_CLASS(current_machine);
Marcel Apfelbaum958db902014-04-09 20:34:53 +0300122 if (mc->hot_add_cpu) {
123 mc->hot_add_cpu(id, errp);
Igor Mammedov69ca3ea2013-04-30 15:41:25 +0200124 } else {
125 error_setg(errp, "Not supported");
126 }
127}
128
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200129#ifndef CONFIG_VNC
130/* If VNC support is enabled, the "true" query-vnc command is
131 defined in the VNC subsystem */
132VncInfo *qmp_query_vnc(Error **errp)
133{
134 error_set(errp, QERR_FEATURE_DISABLED, "vnc");
135 return NULL;
136};
137#endif
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200138
139#ifndef CONFIG_SPICE
140/* If SPICE support is enabled, the "true" query-spice command is
141 defined in the SPICE subsystem. Also note that we use a small
142 trick to maintain query-spice's original behavior, which is not
143 to be available in the namespace if SPICE is not compiled in */
144SpiceInfo *qmp_query_spice(Error **errp)
145{
146 error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice");
147 return NULL;
148};
149#endif
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200150
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200151void qmp_cont(Error **errp)
152{
Markus Armbrusterab319792014-05-02 13:26:42 +0200153 BlockDriverState *bs;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200154
Hu Taoede085b2013-04-26 11:24:40 +0800155 if (runstate_needs_reset()) {
Cole Robinsonf231b882014-03-21 19:42:26 -0400156 error_setg(errp, "Resetting the Virtual Machine is required");
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200157 return;
Luiz Capitulinoad02b962012-04-27 13:33:36 -0300158 } else if (runstate_check(RUN_STATE_SUSPENDED)) {
159 return;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200160 }
161
Markus Armbrusterab319792014-05-02 13:26:42 +0200162 for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
163 bdrv_iostatus_reset(bs);
164 }
165 for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) {
166 if (bdrv_key_required(bs)) {
167 error_set(errp, QERR_DEVICE_ENCRYPTED,
168 bdrv_get_device_name(bs),
169 bdrv_get_encrypted_filename(bs));
170 return;
171 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200172 }
173
Paolo Bonzini1e998142012-10-23 14:54:21 +0200174 if (runstate_check(RUN_STATE_INMIGRATE)) {
175 autostart = 1;
176 } else {
177 vm_start();
178 }
Luiz Capitulinoe42e8182011-11-22 17:58:31 -0200179}
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600180
Gerd Hoffmann9b9df252012-02-23 13:45:21 +0100181void qmp_system_wakeup(Error **errp)
182{
183 qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
184}
185
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600186ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600187{
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600188 Object *obj;
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600189 bool ambiguous = false;
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600190 ObjectPropertyInfoList *props = NULL;
191 ObjectProperty *prop;
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600192
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600193 obj = object_resolve_path(path, &ambiguous);
194 if (obj == NULL) {
Michael Tokarev79772082014-05-04 12:23:59 +0400195 if (ambiguous) {
196 error_setg(errp, "Path '%s' is ambiguous", path);
197 } else {
198 error_set(errp, QERR_DEVICE_NOT_FOUND, path);
199 }
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600200 return NULL;
201 }
202
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600203 QTAILQ_FOREACH(prop, &obj->properties, node) {
204 ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600205
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600206 entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
Anthony Liguorib4b12c62011-12-12 14:29:34 -0600207 entry->next = props;
208 props = entry;
209
210 entry->value->name = g_strdup(prop->name);
211 entry->value->type = g_strdup(prop->type);
212 }
213
214 return props;
215}
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600216
217/* FIXME: teach qapi about how to pass through Visitors */
218int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
219{
220 const char *path = qdict_get_str(qdict, "path");
221 const char *property = qdict_get_str(qdict, "property");
222 QObject *value = qdict_get(qdict, "value");
223 Error *local_err = NULL;
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600224 Object *obj;
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600225
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600226 obj = object_resolve_path(path, NULL);
227 if (!obj) {
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600228 error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
229 goto out;
230 }
231
Paolo Bonzini9f5f1352012-02-01 16:58:47 +0100232 object_property_set_qobject(obj, value, property, &local_err);
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600233
234out:
235 if (local_err) {
236 qerror_report_err(local_err);
237 error_free(local_err);
238 return -1;
239 }
240
241 return 0;
242}
243
244int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
245{
246 const char *path = qdict_get_str(qdict, "path");
247 const char *property = qdict_get_str(qdict, "property");
248 Error *local_err = NULL;
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600249 Object *obj;
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600250
Anthony Liguori57c9faf2012-01-30 08:55:55 -0600251 obj = object_resolve_path(path, NULL);
252 if (!obj) {
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600253 error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
254 goto out;
255 }
256
Paolo Bonzini9f5f1352012-02-01 16:58:47 +0100257 *ret = object_property_get_qobject(obj, property, &local_err);
Anthony Liguorieb6e8ea2011-12-12 14:29:35 -0600258
259out:
260 if (local_err) {
261 qerror_report_err(local_err);
262 error_free(local_err);
263 return -1;
264 }
265
266 return 0;
267}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200268
269void qmp_set_password(const char *protocol, const char *password,
270 bool has_connected, const char *connected, Error **errp)
271{
272 int disconnect_if_connected = 0;
273 int fail_if_connected = 0;
274 int rc;
275
276 if (has_connected) {
277 if (strcmp(connected, "fail") == 0) {
278 fail_if_connected = 1;
279 } else if (strcmp(connected, "disconnect") == 0) {
280 disconnect_if_connected = 1;
281 } else if (strcmp(connected, "keep") == 0) {
282 /* nothing */
283 } else {
284 error_set(errp, QERR_INVALID_PARAMETER, "connected");
285 return;
286 }
287 }
288
289 if (strcmp(protocol, "spice") == 0) {
Markus Armbrusterb25d81b2015-01-13 17:07:15 +0100290 if (!qemu_using_spice(errp)) {
Luiz Capitulinofbf796f2011-12-07 11:17:51 -0200291 return;
292 }
293 rc = qemu_spice_set_passwd(password, fail_if_connected,
294 disconnect_if_connected);
295 if (rc != 0) {
296 error_set(errp, QERR_SET_PASSWD_FAILED);
297 }
298 return;
299 }
300
301 if (strcmp(protocol, "vnc") == 0) {
302 if (fail_if_connected || disconnect_if_connected) {
303 /* vnc supports "connected=keep" only */
304 error_set(errp, QERR_INVALID_PARAMETER, "connected");
305 return;
306 }
307 /* Note that setting an empty password will not disable login through
308 * this interface. */
309 rc = vnc_display_password(NULL, password);
310 if (rc < 0) {
311 error_set(errp, QERR_SET_PASSWD_FAILED);
312 }
313 return;
314 }
315
316 error_set(errp, QERR_INVALID_PARAMETER, "protocol");
317}
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200318
319void qmp_expire_password(const char *protocol, const char *whenstr,
320 Error **errp)
321{
322 time_t when;
323 int rc;
324
325 if (strcmp(whenstr, "now") == 0) {
326 when = 0;
327 } else if (strcmp(whenstr, "never") == 0) {
328 when = TIME_MAX;
329 } else if (whenstr[0] == '+') {
330 when = time(NULL) + strtoull(whenstr+1, NULL, 10);
331 } else {
332 when = strtoull(whenstr, NULL, 10);
333 }
334
335 if (strcmp(protocol, "spice") == 0) {
Markus Armbrusterb25d81b2015-01-13 17:07:15 +0100336 if (!qemu_using_spice(errp)) {
Luiz Capitulino9ad53722011-12-07 11:47:57 -0200337 return;
338 }
339 rc = qemu_spice_set_pw_expire(when);
340 if (rc != 0) {
341 error_set(errp, QERR_SET_PASSWD_FAILED);
342 }
343 return;
344 }
345
346 if (strcmp(protocol, "vnc") == 0) {
347 rc = vnc_display_pw_expire(NULL, when);
348 if (rc != 0) {
349 error_set(errp, QERR_SET_PASSWD_FAILED);
350 }
351 return;
352 }
353
354 error_set(errp, QERR_INVALID_PARAMETER, "protocol");
355}
Luiz Capitulino270b2432011-12-08 11:45:55 -0200356
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200357#ifdef CONFIG_VNC
Luiz Capitulino270b2432011-12-08 11:45:55 -0200358void qmp_change_vnc_password(const char *password, Error **errp)
359{
360 if (vnc_display_password(NULL, password) < 0) {
361 error_set(errp, QERR_SET_PASSWD_FAILED);
362 }
363}
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200364
Paolo Bonzini007fcd3e2012-10-18 09:01:01 +0200365static void qmp_change_vnc_listen(const char *target, Error **errp)
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200366{
Gerd Hoffmann4db14622014-09-16 12:33:03 +0200367 QemuOptsList *olist = qemu_find_opts("vnc");
368 QemuOpts *opts;
369
370 if (strstr(target, "id=")) {
371 error_setg(errp, "id not supported");
372 return;
373 }
374
375 opts = qemu_opts_find(olist, "default");
376 if (opts) {
377 qemu_opts_del(opts);
378 }
379 opts = vnc_parse_func(target);
380 vnc_display_open("default", errp);
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200381}
382
383static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
384 Error **errp)
385{
386 if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) {
387 if (!has_arg) {
388 error_set(errp, QERR_MISSING_PARAMETER, "password");
389 } else {
390 qmp_change_vnc_password(arg, errp);
391 }
392 } else {
393 qmp_change_vnc_listen(target, errp);
394 }
395}
396#else
397void qmp_change_vnc_password(const char *password, Error **errp)
398{
399 error_set(errp, QERR_FEATURE_DISABLED, "vnc");
400}
401static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
402 Error **errp)
403{
404 error_set(errp, QERR_FEATURE_DISABLED, "vnc");
405}
406#endif /* !CONFIG_VNC */
407
408void qmp_change(const char *device, const char *target,
Markus Armbruster7daecb32014-05-02 13:26:31 +0200409 bool has_arg, const char *arg, Error **errp)
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200410{
411 if (strcmp(device, "vnc") == 0) {
Markus Armbruster7daecb32014-05-02 13:26:31 +0200412 qmp_change_vnc(target, has_arg, arg, errp);
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200413 } else {
Markus Armbruster7daecb32014-05-02 13:26:31 +0200414 qmp_change_blockdev(device, target, arg, errp);
Luiz Capitulino333a96e2011-12-08 11:13:50 -0200415 }
416}
Anthony Liguori5eeee3f2011-12-22 14:40:54 -0600417
418static void qom_list_types_tramp(ObjectClass *klass, void *data)
419{
420 ObjectTypeInfoList *e, **pret = data;
421 ObjectTypeInfo *info;
422
423 info = g_malloc0(sizeof(*info));
424 info->name = g_strdup(object_class_get_name(klass));
425
426 e = g_malloc0(sizeof(*e));
427 e->value = info;
428 e->next = *pret;
429 *pret = e;
430}
431
432ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
433 const char *implements,
434 bool has_abstract,
435 bool abstract,
436 Error **errp)
437{
438 ObjectTypeInfoList *ret = NULL;
439
440 object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
441
442 return ret;
443}
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500444
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200445/* Return a DevicePropertyInfo for a qdev property.
446 *
447 * If a qdev property with the given name does not exist, use the given default
448 * type. If the qdev property info should not be shown, return NULL.
449 *
450 * The caller must free the return value.
451 */
452static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
453 const char *name,
Gonglei07d09c52014-10-07 14:33:23 +0800454 const char *default_type,
455 const char *description)
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200456{
457 DevicePropertyInfo *info;
458 Property *prop;
459
460 do {
461 for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
462 if (strcmp(name, prop->name) != 0) {
463 continue;
464 }
465
466 /*
467 * TODO Properties without a parser are just for dirty hacks.
468 * qdev_prop_ptr is the only such PropertyInfo. It's marked
469 * for removal. This conditional should be removed along with
470 * it.
471 */
472 if (!prop->info->set) {
473 return NULL; /* no way to set it, don't show */
474 }
475
476 info = g_malloc0(sizeof(*info));
477 info->name = g_strdup(prop->name);
Gonglei07d09c52014-10-07 14:33:23 +0800478 info->type = g_strdup(prop->info->name);
479 info->has_description = !!prop->info->description;
480 info->description = g_strdup(prop->info->description);
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200481 return info;
482 }
483 klass = object_class_get_parent(klass);
484 } while (klass != object_class_by_name(TYPE_DEVICE));
485
486 /* Not a qdev property, use the default type */
487 info = g_malloc0(sizeof(*info));
488 info->name = g_strdup(name);
489 info->type = g_strdup(default_type);
Gonglei07d09c52014-10-07 14:33:23 +0800490 info->has_description = !!description;
491 info->description = g_strdup(description);
492
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200493 return info;
494}
495
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500496DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
497 Error **errp)
498{
499 ObjectClass *klass;
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200500 Object *obj;
501 ObjectProperty *prop;
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500502 DevicePropertyInfoList *prop_list = NULL;
503
504 klass = object_class_by_name(typename);
505 if (klass == NULL) {
506 error_set(errp, QERR_DEVICE_NOT_FOUND, typename);
507 return NULL;
508 }
509
510 klass = object_class_dynamic_cast(klass, TYPE_DEVICE);
511 if (klass == NULL) {
512 error_set(errp, QERR_INVALID_PARAMETER_VALUE,
513 "name", TYPE_DEVICE);
514 return NULL;
515 }
516
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200517 obj = object_new(typename);
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500518
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200519 QTAILQ_FOREACH(prop, &obj->properties, node) {
520 DevicePropertyInfo *info;
521 DevicePropertyInfoList *entry;
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500522
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200523 /* Skip Object and DeviceState properties */
524 if (strcmp(prop->name, "type") == 0 ||
525 strcmp(prop->name, "realized") == 0 ||
526 strcmp(prop->name, "hotpluggable") == 0 ||
Stefan Hajnoczi4115dd62014-07-09 14:01:31 +0200527 strcmp(prop->name, "hotplugged") == 0 ||
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200528 strcmp(prop->name, "parent_bus") == 0) {
529 continue;
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500530 }
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200531
532 /* Skip legacy properties since they are just string versions of
533 * properties that we already list.
534 */
535 if (strstart(prop->name, "legacy-", NULL)) {
536 continue;
537 }
538
Gonglei07d09c52014-10-07 14:33:23 +0800539 info = make_device_property_info(klass, prop->name, prop->type,
540 prop->description);
Stefan Hajnoczif4eb32b2014-05-20 14:29:01 +0200541 if (!info) {
542 continue;
543 }
544
545 entry = g_malloc0(sizeof(*entry));
546 entry->value = info;
547 entry->next = prop_list;
548 prop_list = entry;
549 }
550
551 object_unref(obj);
Anthony Liguori1daa31b2012-08-10 11:04:09 -0500552
553 return prop_list;
554}
Anthony Liguorie4e31c62012-08-10 11:04:13 -0500555
Anthony Liguori76b64a72012-08-14 22:17:36 -0500556CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
557{
558 return arch_query_cpu_definitions(errp);
559}
560
Luiz Capitulinob224e5e2012-09-13 16:52:20 -0300561void qmp_add_client(const char *protocol, const char *fdname,
562 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
563 Error **errp)
564{
565 CharDriverState *s;
566 int fd;
567
568 fd = monitor_get_fd(cur_mon, fdname, errp);
569 if (fd < 0) {
570 return;
571 }
572
573 if (strcmp(protocol, "spice") == 0) {
Markus Armbrusterb25d81b2015-01-13 17:07:15 +0100574 if (!qemu_using_spice(errp)) {
Luiz Capitulinob224e5e2012-09-13 16:52:20 -0300575 close(fd);
576 return;
577 }
578 skipauth = has_skipauth ? skipauth : false;
579 tls = has_tls ? tls : false;
580 if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) {
581 error_setg(errp, "spice failed to add client");
582 close(fd);
583 }
584 return;
585#ifdef CONFIG_VNC
586 } else if (strcmp(protocol, "vnc") == 0) {
587 skipauth = has_skipauth ? skipauth : false;
588 vnc_display_add_client(NULL, fd, skipauth);
589 return;
590#endif
591 } else if ((s = qemu_chr_find(protocol)) != NULL) {
592 if (qemu_chr_add_client(s, fd) < 0) {
593 error_setg(errp, "failed to add client");
594 close(fd);
595 return;
596 }
597 return;
598 }
599
600 error_setg(errp, "protocol '%s' is invalid", protocol);
601 close(fd);
602}
Paolo Bonziniab2d0532013-12-20 23:21:09 +0100603
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100604void object_add(const char *type, const char *id, const QDict *qdict,
605 Visitor *v, Error **errp)
606{
607 Object *obj;
Eduardo Habkostc3481242014-04-16 14:39:38 -0300608 ObjectClass *klass;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100609 const QDictEntry *e;
610 Error *local_err = NULL;
611
Eduardo Habkostc3481242014-04-16 14:39:38 -0300612 klass = object_class_by_name(type);
613 if (!klass) {
Paolo Bonzinid1169462014-05-14 17:43:13 +0800614 error_setg(errp, "invalid object type: %s", type);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100615 return;
616 }
617
Eduardo Habkostc3481242014-04-16 14:39:38 -0300618 if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
619 error_setg(errp, "object type '%s' isn't supported by object-add",
620 type);
621 return;
622 }
623
624 if (object_class_is_abstract(klass)) {
625 error_setg(errp, "object type '%s' is abstract", type);
626 return;
627 }
628
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100629 obj = object_new(type);
630 if (qdict) {
631 for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
632 object_property_set(obj, v, e->key, &local_err);
633 if (local_err) {
Igor Mammedov69252c02014-01-16 17:34:36 +0100634 goto out;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100635 }
636 }
637 }
638
Igor Mammedova790f4e2014-06-02 15:24:59 +0200639 object_property_add_child(container_get(object_get_root(), "/objects"),
640 id, obj, &local_err);
Igor Mammedov269e09f2014-01-16 17:34:38 +0100641 if (local_err) {
642 goto out;
643 }
644
Igor Mammedova790f4e2014-06-02 15:24:59 +0200645 user_creatable_complete(obj, &local_err);
646 if (local_err) {
647 object_property_del(container_get(object_get_root(), "/objects"),
648 id, &error_abort);
649 goto out;
650 }
Igor Mammedov69252c02014-01-16 17:34:36 +0100651out:
652 if (local_err) {
653 error_propagate(errp, local_err);
654 }
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +0100655 object_unref(obj);
656}
657
658int qmp_object_add(Monitor *mon, const QDict *qdict, QObject **ret)
659{
660 const char *type = qdict_get_str(qdict, "qom-type");
661 const char *id = qdict_get_str(qdict, "id");
662 QObject *props = qdict_get(qdict, "props");
663 const QDict *pdict = NULL;
664 Error *local_err = NULL;
665 QmpInputVisitor *qiv;
666
667 if (props) {
668 pdict = qobject_to_qdict(props);
669 if (!pdict) {
670 error_set(&local_err, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
671 goto out;
672 }
673 }
674
675 qiv = qmp_input_visitor_new(props);
676 object_add(type, id, pdict, qmp_input_get_visitor(qiv), &local_err);
677 qmp_input_visitor_cleanup(qiv);
678
679out:
680 if (local_err) {
681 qerror_report_err(local_err);
682 error_free(local_err);
683 return -1;
684 }
685
686 return 0;
687}
688
Paolo Bonziniab2d0532013-12-20 23:21:09 +0100689void qmp_object_del(const char *id, Error **errp)
690{
691 Object *container;
692 Object *obj;
693
694 container = container_get(object_get_root(), "/objects");
695 obj = object_resolve_path_component(container, id);
696 if (!obj) {
697 error_setg(errp, "object id not found");
698 return;
699 }
700 object_unparent(obj);
701}
Igor Mammedov6f2e2732014-06-16 19:12:25 +0200702
703MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
704{
705 MemoryDeviceInfoList *head = NULL;
706 MemoryDeviceInfoList **prev = &head;
707
708 qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
709
710 return head;
711}
Igor Mammedov02419bc2014-06-16 19:12:28 +0200712
713ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
714{
715 bool ambig;
716 ACPIOSTInfoList *head = NULL;
717 ACPIOSTInfoList **prev = &head;
718 Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig);
719
720 if (obj) {
721 AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
722 AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj);
723
724 adevc->ospm_status(adev, &prev);
725 } else {
726 error_setg(errp, "command is not supported, missing ACPI device");
727 }
728
729 return head;
730}