]>
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 | ||
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 LC |
47 | { |
48 | VersionInfo *info = g_malloc0(sizeof(*info)); | |
49 | const char *version = QEMU_VERSION; | |
50 | char *tmp; | |
51 | ||
52 | info->qemu.major = strtol(version, &tmp, 10); | |
53 | tmp++; | |
54 | info->qemu.minor = strtol(tmp, &tmp, 10); | |
55 | tmp++; | |
56 | info->qemu.micro = strtol(tmp, &tmp, 10); | |
57 | info->package = g_strdup(QEMU_PKGVERSION); | |
58 | ||
59 | return info; | |
60 | } | |
292a2602 LC |
61 | |
62 | KvmInfo *qmp_query_kvm(Error **errp) | |
63 | { | |
64 | KvmInfo *info = g_malloc0(sizeof(*info)); | |
65 | ||
66 | info->enabled = kvm_enabled(); | |
67 | info->present = kvm_available(); | |
68 | ||
69 | return info; | |
70 | } | |
71 | ||
efab767e LC |
72 | UuidInfo *qmp_query_uuid(Error **errp) |
73 | { | |
74 | UuidInfo *info = g_malloc0(sizeof(*info)); | |
75 | char uuid[64]; | |
76 | ||
77 | snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1], | |
78 | qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], | |
79 | qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], | |
80 | qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], | |
81 | qemu_uuid[14], qemu_uuid[15]); | |
82 | ||
83 | info->UUID = g_strdup(uuid); | |
84 | return info; | |
85 | } | |
86 | ||
7daecb30 | 87 | void qmp_quit(Error **errp) |
7a7f325e LC |
88 | { |
89 | no_shutdown = 0; | |
90 | qemu_system_shutdown_request(); | |
91 | } | |
92 | ||
5f158f21 LC |
93 | void qmp_stop(Error **errp) |
94 | { | |
1e998146 PB |
95 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
96 | autostart = 0; | |
97 | } else { | |
98 | vm_stop(RUN_STATE_PAUSED); | |
99 | } | |
5f158f21 LC |
100 | } |
101 | ||
38d22653 LC |
102 | void qmp_system_reset(Error **errp) |
103 | { | |
104 | qemu_system_reset_request(); | |
105 | } | |
5bc465e4 LC |
106 | |
107 | void qmp_system_powerdown(Error **erp) | |
108 | { | |
109 | qemu_system_powerdown_request(); | |
110 | } | |
755f1968 LC |
111 | |
112 | void qmp_cpu(int64_t index, Error **errp) | |
113 | { | |
114 | /* Just do nothing */ | |
115 | } | |
2b54aa87 | 116 | |
69ca3ea5 IM |
117 | void qmp_cpu_add(int64_t id, Error **errp) |
118 | { | |
0056ae24 MA |
119 | MachineClass *mc; |
120 | ||
121 | mc = MACHINE_GET_CLASS(current_machine); | |
958db90c MA |
122 | if (mc->hot_add_cpu) { |
123 | mc->hot_add_cpu(id, errp); | |
69ca3ea5 IM |
124 | } else { |
125 | error_setg(errp, "Not supported"); | |
126 | } | |
127 | } | |
128 | ||
2b54aa87 LC |
129 | #ifndef CONFIG_VNC |
130 | /* If VNC support is enabled, the "true" query-vnc command is | |
131 | defined in the VNC subsystem */ | |
132 | VncInfo *qmp_query_vnc(Error **errp) | |
133 | { | |
134 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); | |
135 | return NULL; | |
136 | }; | |
89db2177 LY |
137 | |
138 | VncInfo2List *qmp_query_vnc_servers(Error **errp) | |
139 | { | |
140 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); | |
141 | return NULL; | |
142 | }; | |
2b54aa87 | 143 | #endif |
d1f29646 LC |
144 | |
145 | #ifndef CONFIG_SPICE | |
ad0ec14b MA |
146 | /* |
147 | * qmp-commands.hx ensures that QMP command query-spice exists only | |
148 | * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands | |
149 | * result. However, the QAPI schema is blissfully unaware of that, | |
150 | * and the QAPI code generator happily generates a dead | |
151 | * qmp_marshal_input_query_spice() that calls qmp_query_spice(). | |
152 | * Provide it one, or else linking fails. | |
153 | * FIXME Educate the QAPI schema on CONFIG_SPICE. | |
154 | */ | |
d1f29646 LC |
155 | SpiceInfo *qmp_query_spice(Error **errp) |
156 | { | |
ad0ec14b | 157 | abort(); |
d1f29646 LC |
158 | }; |
159 | #endif | |
e42e818b | 160 | |
e42e818b LC |
161 | void qmp_cont(Error **errp) |
162 | { | |
4d2855a3 | 163 | Error *local_err = NULL; |
ab31979a | 164 | BlockDriverState *bs; |
e42e818b | 165 | |
ede085b3 | 166 | if (runstate_needs_reset()) { |
f231b88d | 167 | error_setg(errp, "Resetting the Virtual Machine is required"); |
e42e818b | 168 | return; |
ad02b96a LC |
169 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
170 | return; | |
e42e818b LC |
171 | } |
172 | ||
ab31979a MA |
173 | for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) { |
174 | bdrv_iostatus_reset(bs); | |
175 | } | |
176 | for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) { | |
4d2855a3 MA |
177 | bdrv_add_key(bs, NULL, &local_err); |
178 | if (local_err) { | |
179 | error_propagate(errp, local_err); | |
ab31979a MA |
180 | return; |
181 | } | |
e42e818b LC |
182 | } |
183 | ||
1e998146 PB |
184 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
185 | autostart = 1; | |
186 | } else { | |
187 | vm_start(); | |
188 | } | |
e42e818b | 189 | } |
b4b12c62 | 190 | |
9b9df25a GH |
191 | void qmp_system_wakeup(Error **errp) |
192 | { | |
193 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); | |
194 | } | |
195 | ||
57c9fafe | 196 | ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) |
b4b12c62 | 197 | { |
57c9fafe | 198 | Object *obj; |
b4b12c62 | 199 | bool ambiguous = false; |
57c9fafe AL |
200 | ObjectPropertyInfoList *props = NULL; |
201 | ObjectProperty *prop; | |
b4b12c62 | 202 | |
57c9fafe AL |
203 | obj = object_resolve_path(path, &ambiguous); |
204 | if (obj == NULL) { | |
79772087 MT |
205 | if (ambiguous) { |
206 | error_setg(errp, "Path '%s' is ambiguous", path); | |
207 | } else { | |
208 | error_set(errp, QERR_DEVICE_NOT_FOUND, path); | |
209 | } | |
b4b12c62 AL |
210 | return NULL; |
211 | } | |
212 | ||
57c9fafe AL |
213 | QTAILQ_FOREACH(prop, &obj->properties, node) { |
214 | ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); | |
b4b12c62 | 215 | |
57c9fafe | 216 | entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); |
b4b12c62 AL |
217 | entry->next = props; |
218 | props = entry; | |
219 | ||
220 | entry->value->name = g_strdup(prop->name); | |
221 | entry->value->type = g_strdup(prop->type); | |
222 | } | |
223 | ||
224 | return props; | |
225 | } | |
eb6e8ea5 AL |
226 | |
227 | /* FIXME: teach qapi about how to pass through Visitors */ | |
228 | int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret) | |
229 | { | |
230 | const char *path = qdict_get_str(qdict, "path"); | |
231 | const char *property = qdict_get_str(qdict, "property"); | |
232 | QObject *value = qdict_get(qdict, "value"); | |
233 | Error *local_err = NULL; | |
57c9fafe | 234 | Object *obj; |
eb6e8ea5 | 235 | |
57c9fafe AL |
236 | obj = object_resolve_path(path, NULL); |
237 | if (!obj) { | |
eb6e8ea5 AL |
238 | error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); |
239 | goto out; | |
240 | } | |
241 | ||
9f5f1350 | 242 | object_property_set_qobject(obj, value, property, &local_err); |
eb6e8ea5 AL |
243 | |
244 | out: | |
245 | if (local_err) { | |
246 | qerror_report_err(local_err); | |
247 | error_free(local_err); | |
248 | return -1; | |
249 | } | |
250 | ||
251 | return 0; | |
252 | } | |
253 | ||
254 | int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret) | |
255 | { | |
256 | const char *path = qdict_get_str(qdict, "path"); | |
257 | const char *property = qdict_get_str(qdict, "property"); | |
258 | Error *local_err = NULL; | |
57c9fafe | 259 | Object *obj; |
eb6e8ea5 | 260 | |
57c9fafe AL |
261 | obj = object_resolve_path(path, NULL); |
262 | if (!obj) { | |
eb6e8ea5 AL |
263 | error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); |
264 | goto out; | |
265 | } | |
266 | ||
9f5f1350 | 267 | *ret = object_property_get_qobject(obj, property, &local_err); |
eb6e8ea5 AL |
268 | |
269 | out: | |
270 | if (local_err) { | |
271 | qerror_report_err(local_err); | |
272 | error_free(local_err); | |
273 | return -1; | |
274 | } | |
275 | ||
276 | return 0; | |
277 | } | |
fbf796fd LC |
278 | |
279 | void qmp_set_password(const char *protocol, const char *password, | |
280 | bool has_connected, const char *connected, Error **errp) | |
281 | { | |
282 | int disconnect_if_connected = 0; | |
283 | int fail_if_connected = 0; | |
284 | int rc; | |
285 | ||
286 | if (has_connected) { | |
287 | if (strcmp(connected, "fail") == 0) { | |
288 | fail_if_connected = 1; | |
289 | } else if (strcmp(connected, "disconnect") == 0) { | |
290 | disconnect_if_connected = 1; | |
291 | } else if (strcmp(connected, "keep") == 0) { | |
292 | /* nothing */ | |
293 | } else { | |
294 | error_set(errp, QERR_INVALID_PARAMETER, "connected"); | |
295 | return; | |
296 | } | |
297 | } | |
298 | ||
299 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 300 | if (!qemu_using_spice(errp)) { |
fbf796fd LC |
301 | return; |
302 | } | |
303 | rc = qemu_spice_set_passwd(password, fail_if_connected, | |
304 | disconnect_if_connected); | |
305 | if (rc != 0) { | |
306 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
307 | } | |
308 | return; | |
309 | } | |
310 | ||
311 | if (strcmp(protocol, "vnc") == 0) { | |
312 | if (fail_if_connected || disconnect_if_connected) { | |
313 | /* vnc supports "connected=keep" only */ | |
314 | error_set(errp, QERR_INVALID_PARAMETER, "connected"); | |
315 | return; | |
316 | } | |
317 | /* Note that setting an empty password will not disable login through | |
318 | * this interface. */ | |
319 | rc = vnc_display_password(NULL, password); | |
320 | if (rc < 0) { | |
321 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
322 | } | |
323 | return; | |
324 | } | |
325 | ||
326 | error_set(errp, QERR_INVALID_PARAMETER, "protocol"); | |
327 | } | |
9ad5372d LC |
328 | |
329 | void qmp_expire_password(const char *protocol, const char *whenstr, | |
330 | Error **errp) | |
331 | { | |
332 | time_t when; | |
333 | int rc; | |
334 | ||
335 | if (strcmp(whenstr, "now") == 0) { | |
336 | when = 0; | |
337 | } else if (strcmp(whenstr, "never") == 0) { | |
338 | when = TIME_MAX; | |
339 | } else if (whenstr[0] == '+') { | |
340 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); | |
341 | } else { | |
342 | when = strtoull(whenstr, NULL, 10); | |
343 | } | |
344 | ||
345 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 346 | if (!qemu_using_spice(errp)) { |
9ad5372d LC |
347 | return; |
348 | } | |
349 | rc = qemu_spice_set_pw_expire(when); | |
350 | if (rc != 0) { | |
351 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
352 | } | |
353 | return; | |
354 | } | |
355 | ||
356 | if (strcmp(protocol, "vnc") == 0) { | |
357 | rc = vnc_display_pw_expire(NULL, when); | |
358 | if (rc != 0) { | |
359 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
360 | } | |
361 | return; | |
362 | } | |
363 | ||
364 | error_set(errp, QERR_INVALID_PARAMETER, "protocol"); | |
365 | } | |
270b243f | 366 | |
333a96ec | 367 | #ifdef CONFIG_VNC |
270b243f LC |
368 | void qmp_change_vnc_password(const char *password, Error **errp) |
369 | { | |
370 | if (vnc_display_password(NULL, password) < 0) { | |
371 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
372 | } | |
373 | } | |
333a96ec | 374 | |
007fcd3e | 375 | static void qmp_change_vnc_listen(const char *target, Error **errp) |
333a96ec | 376 | { |
4db14629 GH |
377 | QemuOptsList *olist = qemu_find_opts("vnc"); |
378 | QemuOpts *opts; | |
379 | ||
380 | if (strstr(target, "id=")) { | |
381 | error_setg(errp, "id not supported"); | |
382 | return; | |
383 | } | |
384 | ||
385 | opts = qemu_opts_find(olist, "default"); | |
386 | if (opts) { | |
387 | qemu_opts_del(opts); | |
388 | } | |
389 | opts = vnc_parse_func(target); | |
f7801c5c GA |
390 | if (!opts) { |
391 | return; | |
392 | } | |
393 | ||
4db14629 | 394 | vnc_display_open("default", errp); |
333a96ec LC |
395 | } |
396 | ||
397 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, | |
398 | Error **errp) | |
399 | { | |
400 | if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { | |
401 | if (!has_arg) { | |
402 | error_set(errp, QERR_MISSING_PARAMETER, "password"); | |
403 | } else { | |
404 | qmp_change_vnc_password(arg, errp); | |
405 | } | |
406 | } else { | |
407 | qmp_change_vnc_listen(target, errp); | |
408 | } | |
409 | } | |
410 | #else | |
411 | void qmp_change_vnc_password(const char *password, Error **errp) | |
412 | { | |
413 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); | |
414 | } | |
415 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, | |
416 | Error **errp) | |
417 | { | |
418 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); | |
419 | } | |
420 | #endif /* !CONFIG_VNC */ | |
421 | ||
422 | void qmp_change(const char *device, const char *target, | |
7daecb30 | 423 | bool has_arg, const char *arg, Error **errp) |
333a96ec LC |
424 | { |
425 | if (strcmp(device, "vnc") == 0) { | |
7daecb30 | 426 | qmp_change_vnc(target, has_arg, arg, errp); |
333a96ec | 427 | } else { |
7daecb30 | 428 | qmp_change_blockdev(device, target, arg, errp); |
333a96ec LC |
429 | } |
430 | } | |
5eeee3fa AL |
431 | |
432 | static void qom_list_types_tramp(ObjectClass *klass, void *data) | |
433 | { | |
434 | ObjectTypeInfoList *e, **pret = data; | |
435 | ObjectTypeInfo *info; | |
436 | ||
437 | info = g_malloc0(sizeof(*info)); | |
438 | info->name = g_strdup(object_class_get_name(klass)); | |
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 | */ | |
486 | if (!prop->info->set) { | |
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); | |
07d09c58 GA |
492 | info->type = g_strdup(prop->info->name); |
493 | info->has_description = !!prop->info->description; | |
494 | info->description = g_strdup(prop->info->description); | |
f4eb32b5 SH |
495 | return info; |
496 | } | |
497 | klass = object_class_get_parent(klass); | |
498 | } while (klass != object_class_by_name(TYPE_DEVICE)); | |
499 | ||
500 | /* Not a qdev property, use the default type */ | |
501 | info = g_malloc0(sizeof(*info)); | |
502 | info->name = g_strdup(name); | |
503 | info->type = g_strdup(default_type); | |
07d09c58 GA |
504 | info->has_description = !!description; |
505 | info->description = g_strdup(description); | |
506 | ||
f4eb32b5 SH |
507 | return info; |
508 | } | |
509 | ||
1daa31b9 AL |
510 | DevicePropertyInfoList *qmp_device_list_properties(const char *typename, |
511 | Error **errp) | |
512 | { | |
513 | ObjectClass *klass; | |
f4eb32b5 SH |
514 | Object *obj; |
515 | ObjectProperty *prop; | |
1daa31b9 AL |
516 | DevicePropertyInfoList *prop_list = NULL; |
517 | ||
518 | klass = object_class_by_name(typename); | |
519 | if (klass == NULL) { | |
520 | error_set(errp, QERR_DEVICE_NOT_FOUND, typename); | |
521 | return NULL; | |
522 | } | |
523 | ||
524 | klass = object_class_dynamic_cast(klass, TYPE_DEVICE); | |
525 | if (klass == NULL) { | |
526 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, | |
527 | "name", TYPE_DEVICE); | |
528 | return NULL; | |
529 | } | |
530 | ||
f4eb32b5 | 531 | obj = object_new(typename); |
1daa31b9 | 532 | |
f4eb32b5 SH |
533 | QTAILQ_FOREACH(prop, &obj->properties, node) { |
534 | DevicePropertyInfo *info; | |
535 | DevicePropertyInfoList *entry; | |
536 | ||
537 | /* Skip Object and DeviceState properties */ | |
538 | if (strcmp(prop->name, "type") == 0 || | |
539 | strcmp(prop->name, "realized") == 0 || | |
540 | strcmp(prop->name, "hotpluggable") == 0 || | |
4115dd65 | 541 | strcmp(prop->name, "hotplugged") == 0 || |
f4eb32b5 SH |
542 | strcmp(prop->name, "parent_bus") == 0) { |
543 | continue; | |
544 | } | |
1daa31b9 | 545 | |
f4eb32b5 SH |
546 | /* Skip legacy properties since they are just string versions of |
547 | * properties that we already list. | |
548 | */ | |
549 | if (strstart(prop->name, "legacy-", NULL)) { | |
550 | continue; | |
551 | } | |
1daa31b9 | 552 | |
07d09c58 GA |
553 | info = make_device_property_info(klass, prop->name, prop->type, |
554 | prop->description); | |
f4eb32b5 SH |
555 | if (!info) { |
556 | continue; | |
1daa31b9 | 557 | } |
f4eb32b5 SH |
558 | |
559 | entry = g_malloc0(sizeof(*entry)); | |
560 | entry->value = info; | |
561 | entry->next = prop_list; | |
562 | prop_list = entry; | |
563 | } | |
564 | ||
565 | object_unref(obj); | |
1daa31b9 AL |
566 | |
567 | return prop_list; | |
568 | } | |
e4e31c63 | 569 | |
76b64a7a AL |
570 | CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
571 | { | |
572 | return arch_query_cpu_definitions(errp); | |
573 | } | |
574 | ||
b224e5e2 LC |
575 | void qmp_add_client(const char *protocol, const char *fdname, |
576 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, | |
577 | Error **errp) | |
578 | { | |
579 | CharDriverState *s; | |
580 | int fd; | |
581 | ||
582 | fd = monitor_get_fd(cur_mon, fdname, errp); | |
583 | if (fd < 0) { | |
584 | return; | |
585 | } | |
586 | ||
587 | if (strcmp(protocol, "spice") == 0) { | |
b25d81ba | 588 | if (!qemu_using_spice(errp)) { |
b224e5e2 LC |
589 | close(fd); |
590 | return; | |
591 | } | |
592 | skipauth = has_skipauth ? skipauth : false; | |
593 | tls = has_tls ? tls : false; | |
594 | if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) { | |
595 | error_setg(errp, "spice failed to add client"); | |
596 | close(fd); | |
597 | } | |
598 | return; | |
599 | #ifdef CONFIG_VNC | |
600 | } else if (strcmp(protocol, "vnc") == 0) { | |
601 | skipauth = has_skipauth ? skipauth : false; | |
602 | vnc_display_add_client(NULL, fd, skipauth); | |
603 | return; | |
604 | #endif | |
605 | } else if ((s = qemu_chr_find(protocol)) != NULL) { | |
606 | if (qemu_chr_add_client(s, fd) < 0) { | |
607 | error_setg(errp, "failed to add client"); | |
608 | close(fd); | |
609 | return; | |
610 | } | |
611 | return; | |
612 | } | |
613 | ||
614 | error_setg(errp, "protocol '%s' is invalid", protocol); | |
615 | close(fd); | |
616 | } | |
ab2d0531 | 617 | |
cff8b2c6 PB |
618 | void object_add(const char *type, const char *id, const QDict *qdict, |
619 | Visitor *v, Error **errp) | |
620 | { | |
621 | Object *obj; | |
c3481247 | 622 | ObjectClass *klass; |
cff8b2c6 PB |
623 | const QDictEntry *e; |
624 | Error *local_err = NULL; | |
625 | ||
c3481247 EH |
626 | klass = object_class_by_name(type); |
627 | if (!klass) { | |
d1169464 | 628 | error_setg(errp, "invalid object type: %s", type); |
cff8b2c6 PB |
629 | return; |
630 | } | |
631 | ||
c3481247 EH |
632 | if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) { |
633 | error_setg(errp, "object type '%s' isn't supported by object-add", | |
634 | type); | |
635 | return; | |
636 | } | |
637 | ||
638 | if (object_class_is_abstract(klass)) { | |
639 | error_setg(errp, "object type '%s' is abstract", type); | |
640 | return; | |
641 | } | |
642 | ||
cff8b2c6 PB |
643 | obj = object_new(type); |
644 | if (qdict) { | |
645 | for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { | |
646 | object_property_set(obj, v, e->key, &local_err); | |
647 | if (local_err) { | |
69252c04 | 648 | goto out; |
cff8b2c6 PB |
649 | } |
650 | } | |
651 | } | |
652 | ||
a790f4ec IM |
653 | object_property_add_child(container_get(object_get_root(), "/objects"), |
654 | id, obj, &local_err); | |
269e09f3 IM |
655 | if (local_err) { |
656 | goto out; | |
657 | } | |
658 | ||
a790f4ec IM |
659 | user_creatable_complete(obj, &local_err); |
660 | if (local_err) { | |
661 | object_property_del(container_get(object_get_root(), "/objects"), | |
662 | id, &error_abort); | |
663 | goto out; | |
664 | } | |
69252c04 IM |
665 | out: |
666 | if (local_err) { | |
667 | error_propagate(errp, local_err); | |
668 | } | |
cff8b2c6 PB |
669 | object_unref(obj); |
670 | } | |
671 | ||
672 | int qmp_object_add(Monitor *mon, const QDict *qdict, QObject **ret) | |
673 | { | |
674 | const char *type = qdict_get_str(qdict, "qom-type"); | |
675 | const char *id = qdict_get_str(qdict, "id"); | |
676 | QObject *props = qdict_get(qdict, "props"); | |
677 | const QDict *pdict = NULL; | |
678 | Error *local_err = NULL; | |
679 | QmpInputVisitor *qiv; | |
680 | ||
681 | if (props) { | |
682 | pdict = qobject_to_qdict(props); | |
683 | if (!pdict) { | |
684 | error_set(&local_err, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); | |
685 | goto out; | |
686 | } | |
687 | } | |
688 | ||
689 | qiv = qmp_input_visitor_new(props); | |
690 | object_add(type, id, pdict, qmp_input_get_visitor(qiv), &local_err); | |
691 | qmp_input_visitor_cleanup(qiv); | |
692 | ||
693 | out: | |
694 | if (local_err) { | |
695 | qerror_report_err(local_err); | |
696 | error_free(local_err); | |
697 | return -1; | |
698 | } | |
699 | ||
700 | return 0; | |
701 | } | |
702 | ||
ab2d0531 PB |
703 | void qmp_object_del(const char *id, Error **errp) |
704 | { | |
705 | Object *container; | |
706 | Object *obj; | |
707 | ||
708 | container = container_get(object_get_root(), "/objects"); | |
709 | obj = object_resolve_path_component(container, id); | |
710 | if (!obj) { | |
711 | error_setg(errp, "object id not found"); | |
712 | return; | |
713 | } | |
714 | object_unparent(obj); | |
715 | } | |
6f2e2730 IM |
716 | |
717 | MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) | |
718 | { | |
719 | MemoryDeviceInfoList *head = NULL; | |
720 | MemoryDeviceInfoList **prev = &head; | |
721 | ||
722 | qmp_pc_dimm_device_list(qdev_get_machine(), &prev); | |
723 | ||
724 | return head; | |
725 | } | |
02419bcb IM |
726 | |
727 | ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) | |
728 | { | |
729 | bool ambig; | |
730 | ACPIOSTInfoList *head = NULL; | |
731 | ACPIOSTInfoList **prev = &head; | |
732 | Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig); | |
733 | ||
734 | if (obj) { | |
735 | AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); | |
736 | AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj); | |
737 | ||
738 | adevc->ospm_status(adev, &prev); | |
739 | } else { | |
740 | error_setg(errp, "command is not supported, missing ACPI device"); | |
741 | } | |
742 | ||
743 | return head; | |
744 | } |