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