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