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