]>
Commit | Line | Data |
---|---|---|
48a32bed AL |
1 | /* |
2 | * QEMU Management Protocol | |
3 | * | |
4 | * Copyright IBM, Corp. 2011 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
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" |
67a1de0d | 17 | #include "qemu-version.h" |
f348b6d1 | 18 | #include "qemu/cutils.h" |
a0b1a66e | 19 | #include "monitor/monitor.h" |
9c17d615 | 20 | #include "sysemu/sysemu.h" |
213dcb06 | 21 | #include "qemu/config-file.h" |
cea25275 | 22 | #include "qemu/uuid.h" |
48a32bed | 23 | #include "qmp-commands.h" |
8228e353 | 24 | #include "chardev/char.h" |
fbf796fd LC |
25 | #include "ui/qemu-spice.h" |
26 | #include "ui/vnc.h" | |
9c17d615 PB |
27 | #include "sysemu/kvm.h" |
28 | #include "sysemu/arch_init.h" | |
b4b12c62 | 29 | #include "hw/qdev.h" |
9c17d615 | 30 | #include "sysemu/blockdev.h" |
373340b2 | 31 | #include "sysemu/block-backend.h" |
14cccb61 | 32 | #include "qom/qom-qobject.h" |
cc7a8ea7 | 33 | #include "qapi/qmp/qerror.h" |
cff8b2c6 | 34 | #include "qapi/qmp/qobject.h" |
b3db211f | 35 | #include "qapi/qobject-input-visitor.h" |
69ca3ea5 | 36 | #include "hw/boards.h" |
269e09f3 | 37 | #include "qom/object_interfaces.h" |
6f2e2730 | 38 | #include "hw/mem/pc-dimm.h" |
02419bcb | 39 | #include "hw/acpi/acpi_dev_interface.h" |
48a32bed AL |
40 | |
41 | NameInfo *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 | } | |
b9c15f16 | 52 | |
7daecb30 | 53 | VersionInfo *qmp_query_version(Error **errp) |
b9c15f16 | 54 | { |
4752cdbb | 55 | VersionInfo *info = g_new0(VersionInfo, 1); |
b9c15f16 | 56 | |
4752cdbb | 57 | info->qemu = g_new0(VersionTriple, 1); |
3688d8c7 MAL |
58 | info->qemu->major = QEMU_VERSION_MAJOR; |
59 | info->qemu->minor = QEMU_VERSION_MINOR; | |
60 | info->qemu->micro = QEMU_VERSION_MICRO; | |
b9c15f16 LC |
61 | info->package = g_strdup(QEMU_PKGVERSION); |
62 | ||
63 | return info; | |
64 | } | |
292a2602 LC |
65 | |
66 | KvmInfo *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 | ||
efab767e LC |
76 | UuidInfo *qmp_query_uuid(Error **errp) |
77 | { | |
78 | UuidInfo *info = g_malloc0(sizeof(*info)); | |
efab767e | 79 | |
9c5ce8db | 80 | info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid); |
efab767e LC |
81 | return info; |
82 | } | |
83 | ||
7daecb30 | 84 | void qmp_quit(Error **errp) |
7a7f325e LC |
85 | { |
86 | no_shutdown = 0; | |
cf83f140 | 87 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP); |
7a7f325e LC |
88 | } |
89 | ||
5f158f21 LC |
90 | void qmp_stop(Error **errp) |
91 | { | |
65d64f36 PX |
92 | /* 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 | ||
1e998146 PB |
99 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
100 | autostart = 0; | |
101 | } else { | |
102 | vm_stop(RUN_STATE_PAUSED); | |
103 | } | |
5f158f21 LC |
104 | } |
105 | ||
38d22653 LC |
106 | void qmp_system_reset(Error **errp) |
107 | { | |
cf83f140 | 108 | qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP); |
38d22653 | 109 | } |
5bc465e4 LC |
110 | |
111 | void qmp_system_powerdown(Error **erp) | |
112 | { | |
113 | qemu_system_powerdown_request(); | |
114 | } | |
755f1968 | 115 | |
69ca3ea5 IM |
116 | void qmp_cpu_add(int64_t id, Error **errp) |
117 | { | |
0056ae24 MA |
118 | MachineClass *mc; |
119 | ||
120 | mc = MACHINE_GET_CLASS(current_machine); | |
958db90c MA |
121 | if (mc->hot_add_cpu) { |
122 | mc->hot_add_cpu(id, errp); | |
69ca3ea5 IM |
123 | } else { |
124 | error_setg(errp, "Not supported"); | |
125 | } | |
126 | } | |
127 | ||
2b54aa87 LC |
128 | #ifndef CONFIG_VNC |
129 | /* If VNC support is enabled, the "true" query-vnc command is | |
130 | defined in the VNC subsystem */ | |
131 | VncInfo *qmp_query_vnc(Error **errp) | |
132 | { | |
c6bd8c70 | 133 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
2b54aa87 LC |
134 | return NULL; |
135 | }; | |
89db2177 LY |
136 | |
137 | VncInfo2List *qmp_query_vnc_servers(Error **errp) | |
138 | { | |
c6bd8c70 | 139 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
89db2177 LY |
140 | return NULL; |
141 | }; | |
2b54aa87 | 142 | #endif |
d1f29646 LC |
143 | |
144 | #ifndef CONFIG_SPICE | |
ad0ec14b MA |
145 | /* |
146 | * qmp-commands.hx ensures that QMP command query-spice exists only | |
147 | * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands | |
148 | * result. However, the QAPI schema is blissfully unaware of that, | |
149 | * and the QAPI code generator happily generates a dead | |
7fad30f0 MA |
150 | * qmp_marshal_query_spice() that calls qmp_query_spice(). Provide it |
151 | * one, or else linking fails. FIXME Educate the QAPI schema on | |
152 | * CONFIG_SPICE. | |
ad0ec14b | 153 | */ |
d1f29646 LC |
154 | SpiceInfo *qmp_query_spice(Error **errp) |
155 | { | |
ad0ec14b | 156 | abort(); |
d1f29646 LC |
157 | }; |
158 | #endif | |
e42e818b | 159 | |
e42e818b LC |
160 | void qmp_cont(Error **errp) |
161 | { | |
373340b2 | 162 | BlockBackend *blk; |
788cf9f8 | 163 | Error *local_err = NULL; |
e42e818b | 164 | |
65d64f36 PX |
165 | /* if there is a dump in background, we should wait until the dump |
166 | * finished */ | |
167 | if (dump_in_progress()) { | |
168 | error_setg(errp, "There is a dump in process, please wait."); | |
169 | return; | |
170 | } | |
171 | ||
ede085b3 | 172 | if (runstate_needs_reset()) { |
f231b88d | 173 | error_setg(errp, "Resetting the Virtual Machine is required"); |
e42e818b | 174 | return; |
ad02b96a LC |
175 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
176 | return; | |
e42e818b LC |
177 | } |
178 | ||
373340b2 HR |
179 | for (blk = blk_next(NULL); blk; blk = blk_next(blk)) { |
180 | blk_iostatus_reset(blk); | |
ab31979a | 181 | } |
7c8eece4 | 182 | |
76b1c7fe | 183 | /* Continuing after completed migration. Images have been inactivated to |
ace21a58 KW |
184 | * allow the destination to take control. Need to get control back now. |
185 | * | |
186 | * If there are no inactive block nodes (e.g. because the VM was just | |
187 | * paused rather than completing a migration), bdrv_inactivate_all() simply | |
188 | * doesn't do anything. */ | |
189 | bdrv_invalidate_cache_all(&local_err); | |
190 | if (local_err) { | |
191 | error_propagate(errp, local_err); | |
192 | return; | |
76b1c7fe KW |
193 | } |
194 | ||
1e998146 PB |
195 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
196 | autostart = 1; | |
197 | } else { | |
198 | vm_start(); | |
199 | } | |
e42e818b | 200 | } |
b4b12c62 | 201 | |
9b9df25a GH |
202 | void qmp_system_wakeup(Error **errp) |
203 | { | |
204 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); | |
205 | } | |
206 | ||
57c9fafe | 207 | ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) |
b4b12c62 | 208 | { |
57c9fafe | 209 | Object *obj; |
b4b12c62 | 210 | bool ambiguous = false; |
57c9fafe AL |
211 | ObjectPropertyInfoList *props = NULL; |
212 | ObjectProperty *prop; | |
7746abd8 | 213 | ObjectPropertyIterator iter; |
b4b12c62 | 214 | |
57c9fafe AL |
215 | obj = object_resolve_path(path, &ambiguous); |
216 | if (obj == NULL) { | |
79772087 MT |
217 | if (ambiguous) { |
218 | error_setg(errp, "Path '%s' is ambiguous", path); | |
219 | } else { | |
75158ebb MA |
220 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
221 | "Device '%s' not found", path); | |
79772087 | 222 | } |
b4b12c62 AL |
223 | return NULL; |
224 | } | |
225 | ||
7746abd8 DB |
226 | object_property_iter_init(&iter, obj); |
227 | while ((prop = object_property_iter_next(&iter))) { | |
57c9fafe | 228 | ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); |
b4b12c62 | 229 | |
57c9fafe | 230 | entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); |
b4b12c62 AL |
231 | entry->next = props; |
232 | props = entry; | |
233 | ||
234 | entry->value->name = g_strdup(prop->name); | |
235 | entry->value->type = g_strdup(prop->type); | |
236 | } | |
237 | ||
238 | return props; | |
239 | } | |
eb6e8ea5 | 240 | |
6eb3937e MA |
241 | void qmp_qom_set(const char *path, const char *property, QObject *value, |
242 | Error **errp) | |
eb6e8ea5 | 243 | { |
57c9fafe | 244 | Object *obj; |
eb6e8ea5 | 245 | |
57c9fafe AL |
246 | obj = object_resolve_path(path, NULL); |
247 | if (!obj) { | |
485febc6 | 248 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
75158ebb | 249 | "Device '%s' not found", path); |
485febc6 | 250 | return; |
eb6e8ea5 AL |
251 | } |
252 | ||
485febc6 | 253 | object_property_set_qobject(obj, value, property, errp); |
eb6e8ea5 AL |
254 | } |
255 | ||
6eb3937e | 256 | QObject *qmp_qom_get(const char *path, const char *property, Error **errp) |
eb6e8ea5 | 257 | { |
57c9fafe | 258 | Object *obj; |
eb6e8ea5 | 259 | |
57c9fafe AL |
260 | obj = object_resolve_path(path, NULL); |
261 | if (!obj) { | |
485febc6 | 262 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
75158ebb | 263 | "Device '%s' not found", path); |
6eb3937e | 264 | return NULL; |
eb6e8ea5 AL |
265 | } |
266 | ||
6eb3937e | 267 | return object_property_get_qobject(obj, property, errp); |
eb6e8ea5 | 268 | } |
fbf796fd LC |
269 | |
270 | void qmp_set_password(const char *protocol, const char *password, | |
271 | bool has_connected, const char *connected, Error **errp) | |
272 | { | |
273 | int disconnect_if_connected = 0; | |
274 | int fail_if_connected = 0; | |
275 | int rc; | |
276 | ||
277 | if (has_connected) { | |
278 | if (strcmp(connected, "fail") == 0) { | |
279 | fail_if_connected = 1; | |
280 | } else if (strcmp(connected, "disconnect") == 0) { | |
281 | disconnect_if_connected = 1; | |
282 | } else if (strcmp(connected, "keep") == 0) { | |
283 | /* nothing */ | |
284 | } else { | |
c6bd8c70 | 285 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
fbf796fd LC |
286 | return; |
287 | } | |
288 | } | |
289 | ||
290 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 291 | if (!qemu_using_spice(errp)) { |
fbf796fd LC |
292 | return; |
293 | } | |
294 | rc = qemu_spice_set_passwd(password, fail_if_connected, | |
295 | disconnect_if_connected); | |
296 | if (rc != 0) { | |
c6bd8c70 | 297 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
fbf796fd LC |
298 | } |
299 | return; | |
300 | } | |
301 | ||
302 | if (strcmp(protocol, "vnc") == 0) { | |
303 | if (fail_if_connected || disconnect_if_connected) { | |
304 | /* vnc supports "connected=keep" only */ | |
c6bd8c70 | 305 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
fbf796fd LC |
306 | return; |
307 | } | |
308 | /* Note that setting an empty password will not disable login through | |
309 | * this interface. */ | |
310 | rc = vnc_display_password(NULL, password); | |
311 | if (rc < 0) { | |
c6bd8c70 | 312 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
fbf796fd LC |
313 | } |
314 | return; | |
315 | } | |
316 | ||
c6bd8c70 | 317 | error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); |
fbf796fd | 318 | } |
9ad5372d LC |
319 | |
320 | void qmp_expire_password(const char *protocol, const char *whenstr, | |
321 | Error **errp) | |
322 | { | |
323 | time_t when; | |
324 | int rc; | |
325 | ||
326 | if (strcmp(whenstr, "now") == 0) { | |
327 | when = 0; | |
328 | } else if (strcmp(whenstr, "never") == 0) { | |
329 | when = TIME_MAX; | |
330 | } else if (whenstr[0] == '+') { | |
331 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); | |
332 | } else { | |
333 | when = strtoull(whenstr, NULL, 10); | |
334 | } | |
335 | ||
336 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 337 | if (!qemu_using_spice(errp)) { |
9ad5372d LC |
338 | return; |
339 | } | |
340 | rc = qemu_spice_set_pw_expire(when); | |
341 | if (rc != 0) { | |
c6bd8c70 | 342 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
9ad5372d LC |
343 | } |
344 | return; | |
345 | } | |
346 | ||
347 | if (strcmp(protocol, "vnc") == 0) { | |
348 | rc = vnc_display_pw_expire(NULL, when); | |
349 | if (rc != 0) { | |
c6bd8c70 | 350 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
9ad5372d LC |
351 | } |
352 | return; | |
353 | } | |
354 | ||
c6bd8c70 | 355 | error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); |
9ad5372d | 356 | } |
270b243f | 357 | |
333a96ec | 358 | #ifdef CONFIG_VNC |
270b243f LC |
359 | void qmp_change_vnc_password(const char *password, Error **errp) |
360 | { | |
361 | if (vnc_display_password(NULL, password) < 0) { | |
c6bd8c70 | 362 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
270b243f LC |
363 | } |
364 | } | |
333a96ec | 365 | |
007fcd3e | 366 | static void qmp_change_vnc_listen(const char *target, Error **errp) |
333a96ec | 367 | { |
4db14629 GH |
368 | QemuOptsList *olist = qemu_find_opts("vnc"); |
369 | QemuOpts *opts; | |
370 | ||
371 | if (strstr(target, "id=")) { | |
372 | error_setg(errp, "id not supported"); | |
373 | return; | |
374 | } | |
375 | ||
376 | opts = qemu_opts_find(olist, "default"); | |
377 | if (opts) { | |
378 | qemu_opts_del(opts); | |
379 | } | |
70b94331 | 380 | opts = vnc_parse(target, errp); |
f7801c5c GA |
381 | if (!opts) { |
382 | return; | |
383 | } | |
384 | ||
4db14629 | 385 | vnc_display_open("default", errp); |
333a96ec LC |
386 | } |
387 | ||
388 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, | |
389 | Error **errp) | |
390 | { | |
391 | if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { | |
392 | if (!has_arg) { | |
c6bd8c70 | 393 | error_setg(errp, QERR_MISSING_PARAMETER, "password"); |
333a96ec LC |
394 | } else { |
395 | qmp_change_vnc_password(arg, errp); | |
396 | } | |
397 | } else { | |
398 | qmp_change_vnc_listen(target, errp); | |
399 | } | |
400 | } | |
401 | #else | |
402 | void qmp_change_vnc_password(const char *password, Error **errp) | |
403 | { | |
c6bd8c70 | 404 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
333a96ec LC |
405 | } |
406 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, | |
407 | Error **errp) | |
408 | { | |
c6bd8c70 | 409 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
333a96ec LC |
410 | } |
411 | #endif /* !CONFIG_VNC */ | |
412 | ||
413 | void qmp_change(const char *device, const char *target, | |
7daecb30 | 414 | bool has_arg, const char *arg, Error **errp) |
333a96ec LC |
415 | { |
416 | if (strcmp(device, "vnc") == 0) { | |
7daecb30 | 417 | qmp_change_vnc(target, has_arg, arg, errp); |
333a96ec | 418 | } else { |
70e2cb3b KW |
419 | qmp_blockdev_change_medium(true, device, false, NULL, target, |
420 | has_arg, arg, false, 0, errp); | |
333a96ec LC |
421 | } |
422 | } | |
5eeee3fa AL |
423 | |
424 | static void qom_list_types_tramp(ObjectClass *klass, void *data) | |
425 | { | |
426 | ObjectTypeInfoList *e, **pret = data; | |
427 | ObjectTypeInfo *info; | |
f86285c5 | 428 | ObjectClass *parent = object_class_get_parent(klass); |
5eeee3fa AL |
429 | |
430 | info = g_malloc0(sizeof(*info)); | |
431 | info->name = g_strdup(object_class_get_name(klass)); | |
87467eae | 432 | info->has_abstract = info->abstract = object_class_is_abstract(klass); |
f86285c5 EH |
433 | if (parent) { |
434 | info->has_parent = true; | |
435 | info->parent = g_strdup(object_class_get_name(parent)); | |
436 | } | |
5eeee3fa AL |
437 | |
438 | e = g_malloc0(sizeof(*e)); | |
439 | e->value = info; | |
440 | e->next = *pret; | |
441 | *pret = e; | |
442 | } | |
443 | ||
444 | ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, | |
445 | const char *implements, | |
446 | bool has_abstract, | |
447 | bool abstract, | |
448 | Error **errp) | |
449 | { | |
450 | ObjectTypeInfoList *ret = NULL; | |
451 | ||
452 | object_class_foreach(qom_list_types_tramp, implements, abstract, &ret); | |
453 | ||
454 | return ret; | |
455 | } | |
1daa31b9 | 456 | |
f4eb32b5 SH |
457 | /* Return a DevicePropertyInfo for a qdev property. |
458 | * | |
459 | * If a qdev property with the given name does not exist, use the given default | |
460 | * type. If the qdev property info should not be shown, return NULL. | |
461 | * | |
462 | * The caller must free the return value. | |
463 | */ | |
464 | static DevicePropertyInfo *make_device_property_info(ObjectClass *klass, | |
465 | const char *name, | |
07d09c58 GA |
466 | const char *default_type, |
467 | const char *description) | |
f4eb32b5 SH |
468 | { |
469 | DevicePropertyInfo *info; | |
470 | Property *prop; | |
471 | ||
472 | do { | |
473 | for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { | |
474 | if (strcmp(name, prop->name) != 0) { | |
475 | continue; | |
476 | } | |
477 | ||
478 | /* | |
479 | * TODO Properties without a parser are just for dirty hacks. | |
480 | * qdev_prop_ptr is the only such PropertyInfo. It's marked | |
481 | * for removal. This conditional should be removed along with | |
482 | * it. | |
483 | */ | |
faabdbb7 | 484 | if (!prop->info->set && !prop->info->create) { |
f4eb32b5 SH |
485 | return NULL; /* no way to set it, don't show */ |
486 | } | |
487 | ||
488 | info = g_malloc0(sizeof(*info)); | |
489 | info->name = g_strdup(prop->name); | |
75ab9053 FZ |
490 | info->type = default_type ? g_strdup(default_type) |
491 | : g_strdup(prop->info->name); | |
07d09c58 GA |
492 | info->has_description = !!prop->info->description; |
493 | info->description = g_strdup(prop->info->description); | |
f4eb32b5 SH |
494 | return info; |
495 | } | |
496 | klass = object_class_get_parent(klass); | |
497 | } while (klass != object_class_by_name(TYPE_DEVICE)); | |
498 | ||
499 | /* Not a qdev property, use the default type */ | |
500 | info = g_malloc0(sizeof(*info)); | |
501 | info->name = g_strdup(name); | |
502 | info->type = g_strdup(default_type); | |
07d09c58 GA |
503 | info->has_description = !!description; |
504 | info->description = g_strdup(description); | |
505 | ||
f4eb32b5 SH |
506 | return info; |
507 | } | |
508 | ||
1daa31b9 AL |
509 | DevicePropertyInfoList *qmp_device_list_properties(const char *typename, |
510 | Error **errp) | |
511 | { | |
512 | ObjectClass *klass; | |
f4eb32b5 SH |
513 | Object *obj; |
514 | ObjectProperty *prop; | |
7746abd8 | 515 | ObjectPropertyIterator iter; |
1daa31b9 AL |
516 | DevicePropertyInfoList *prop_list = NULL; |
517 | ||
518 | klass = object_class_by_name(typename); | |
519 | if (klass == NULL) { | |
75158ebb MA |
520 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
521 | "Device '%s' not found", typename); | |
1daa31b9 AL |
522 | return NULL; |
523 | } | |
524 | ||
525 | klass = object_class_dynamic_cast(klass, TYPE_DEVICE); | |
526 | if (klass == NULL) { | |
7a8c153f | 527 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE); |
1daa31b9 AL |
528 | return NULL; |
529 | } | |
530 | ||
edb1523d | 531 | if (object_class_is_abstract(klass)) { |
7a8c153f | 532 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", |
edb1523d MA |
533 | "non-abstract device type"); |
534 | return NULL; | |
535 | } | |
536 | ||
f4eb32b5 | 537 | obj = object_new(typename); |
1daa31b9 | 538 | |
7746abd8 DB |
539 | object_property_iter_init(&iter, obj); |
540 | while ((prop = object_property_iter_next(&iter))) { | |
f4eb32b5 SH |
541 | DevicePropertyInfo *info; |
542 | DevicePropertyInfoList *entry; | |
543 | ||
544 | /* Skip Object and DeviceState properties */ | |
545 | if (strcmp(prop->name, "type") == 0 || | |
546 | strcmp(prop->name, "realized") == 0 || | |
547 | strcmp(prop->name, "hotpluggable") == 0 || | |
4115dd65 | 548 | strcmp(prop->name, "hotplugged") == 0 || |
f4eb32b5 SH |
549 | strcmp(prop->name, "parent_bus") == 0) { |
550 | continue; | |
551 | } | |
1daa31b9 | 552 | |
f4eb32b5 SH |
553 | /* Skip legacy properties since they are just string versions of |
554 | * properties that we already list. | |
555 | */ | |
556 | if (strstart(prop->name, "legacy-", NULL)) { | |
557 | continue; | |
558 | } | |
1daa31b9 | 559 | |
07d09c58 GA |
560 | info = make_device_property_info(klass, prop->name, prop->type, |
561 | prop->description); | |
f4eb32b5 SH |
562 | if (!info) { |
563 | continue; | |
1daa31b9 | 564 | } |
f4eb32b5 SH |
565 | |
566 | entry = g_malloc0(sizeof(*entry)); | |
567 | entry->value = info; | |
568 | entry->next = prop_list; | |
569 | prop_list = entry; | |
570 | } | |
571 | ||
572 | object_unref(obj); | |
1daa31b9 AL |
573 | |
574 | return prop_list; | |
575 | } | |
e4e31c63 | 576 | |
76b64a7a AL |
577 | CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
578 | { | |
579 | return arch_query_cpu_definitions(errp); | |
580 | } | |
581 | ||
e09484ef DH |
582 | CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, |
583 | CpuModelInfo *model, | |
584 | Error **errp) | |
585 | { | |
586 | return arch_query_cpu_model_expansion(type, model, errp); | |
587 | } | |
588 | ||
0031e0d6 DH |
589 | CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela, |
590 | CpuModelInfo *modelb, | |
591 | Error **errp) | |
592 | { | |
593 | return arch_query_cpu_model_comparison(modela, modelb, errp); | |
594 | } | |
595 | ||
b18b6043 DH |
596 | CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela, |
597 | CpuModelInfo *modelb, | |
598 | Error **errp) | |
599 | { | |
600 | return arch_query_cpu_model_baseline(modela, modelb, errp); | |
601 | } | |
602 | ||
b224e5e2 LC |
603 | void qmp_add_client(const char *protocol, const char *fdname, |
604 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, | |
605 | Error **errp) | |
606 | { | |
0ec7b3e7 | 607 | Chardev *s; |
b224e5e2 LC |
608 | int fd; |
609 | ||
610 | fd = monitor_get_fd(cur_mon, fdname, errp); | |
611 | if (fd < 0) { | |
612 | return; | |
613 | } | |
614 | ||
615 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 616 | if (!qemu_using_spice(errp)) { |
b224e5e2 LC |
617 | close(fd); |
618 | return; | |
619 | } | |
620 | skipauth = has_skipauth ? skipauth : false; | |
621 | tls = has_tls ? tls : false; | |
622 | if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) { | |
623 | error_setg(errp, "spice failed to add client"); | |
624 | close(fd); | |
625 | } | |
626 | return; | |
627 | #ifdef CONFIG_VNC | |
628 | } else if (strcmp(protocol, "vnc") == 0) { | |
629 | skipauth = has_skipauth ? skipauth : false; | |
630 | vnc_display_add_client(NULL, fd, skipauth); | |
631 | return; | |
632 | #endif | |
633 | } else if ((s = qemu_chr_find(protocol)) != NULL) { | |
634 | if (qemu_chr_add_client(s, fd) < 0) { | |
635 | error_setg(errp, "failed to add client"); | |
636 | close(fd); | |
637 | return; | |
638 | } | |
639 | return; | |
640 | } | |
641 | ||
642 | error_setg(errp, "protocol '%s' is invalid", protocol); | |
643 | close(fd); | |
644 | } | |
ab2d0531 | 645 | |
cff8b2c6 | 646 | |
6eb3937e MA |
647 | void qmp_object_add(const char *type, const char *id, |
648 | bool has_props, QObject *props, Error **errp) | |
cff8b2c6 | 649 | { |
e64c75a9 | 650 | QDict *pdict; |
b70ce101 | 651 | Visitor *v; |
90998d58 | 652 | Object *obj; |
cff8b2c6 PB |
653 | |
654 | if (props) { | |
655 | pdict = qobject_to_qdict(props); | |
656 | if (!pdict) { | |
485febc6 MA |
657 | error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); |
658 | return; | |
cff8b2c6 | 659 | } |
e64c75a9 MAL |
660 | QINCREF(pdict); |
661 | } else { | |
662 | pdict = qdict_new(); | |
cff8b2c6 PB |
663 | } |
664 | ||
048abb7b | 665 | v = qobject_input_visitor_new(QOBJECT(pdict)); |
b70ce101 EB |
666 | obj = user_creatable_add_type(type, id, pdict, v, errp); |
667 | visit_free(v); | |
90998d58 DB |
668 | if (obj) { |
669 | object_unref(obj); | |
670 | } | |
e64c75a9 | 671 | QDECREF(pdict); |
cff8b2c6 PB |
672 | } |
673 | ||
ab2d0531 PB |
674 | void qmp_object_del(const char *id, Error **errp) |
675 | { | |
90998d58 | 676 | user_creatable_del(id, errp); |
ab2d0531 | 677 | } |
6f2e2730 IM |
678 | |
679 | MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) | |
680 | { | |
681 | MemoryDeviceInfoList *head = NULL; | |
682 | MemoryDeviceInfoList **prev = &head; | |
683 | ||
684 | qmp_pc_dimm_device_list(qdev_get_machine(), &prev); | |
685 | ||
686 | return head; | |
687 | } | |
02419bcb IM |
688 | |
689 | ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) | |
690 | { | |
691 | bool ambig; | |
692 | ACPIOSTInfoList *head = NULL; | |
693 | ACPIOSTInfoList **prev = &head; | |
694 | Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig); | |
695 | ||
696 | if (obj) { | |
697 | AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); | |
698 | AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj); | |
699 | ||
700 | adevc->ospm_status(adev, &prev); | |
701 | } else { | |
702 | error_setg(errp, "command is not supported, missing ACPI device"); | |
703 | } | |
704 | ||
705 | return head; | |
706 | } | |
9aa3397f VG |
707 | |
708 | MemoryInfo *qmp_query_memory_size_summary(Error **errp) | |
709 | { | |
710 | MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo)); | |
711 | ||
712 | mem_info->base_memory = ram_size; | |
713 | ||
714 | mem_info->plugged_memory = get_plugged_memory_size(); | |
715 | mem_info->has_plugged_memory = | |
716 | mem_info->plugged_memory != (uint64_t)-1; | |
717 | ||
718 | return mem_info; | |
719 | } |