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