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