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