]>
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 | }; | |
137 | #endif | |
d1f29646 LC |
138 | |
139 | #ifndef CONFIG_SPICE | |
140 | /* If SPICE support is enabled, the "true" query-spice command is | |
141 | defined in the SPICE subsystem. Also note that we use a small | |
142 | trick to maintain query-spice's original behavior, which is not | |
143 | to be available in the namespace if SPICE is not compiled in */ | |
144 | SpiceInfo *qmp_query_spice(Error **errp) | |
145 | { | |
146 | error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice"); | |
147 | return NULL; | |
148 | }; | |
149 | #endif | |
e42e818b | 150 | |
e42e818b LC |
151 | void qmp_cont(Error **errp) |
152 | { | |
ab31979a | 153 | BlockDriverState *bs; |
e42e818b | 154 | |
ede085b3 | 155 | if (runstate_needs_reset()) { |
f231b88d | 156 | error_setg(errp, "Resetting the Virtual Machine is required"); |
e42e818b | 157 | return; |
ad02b96a LC |
158 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
159 | return; | |
e42e818b LC |
160 | } |
161 | ||
ab31979a MA |
162 | for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) { |
163 | bdrv_iostatus_reset(bs); | |
164 | } | |
165 | for (bs = bdrv_next(NULL); bs; bs = bdrv_next(bs)) { | |
166 | if (bdrv_key_required(bs)) { | |
167 | error_set(errp, QERR_DEVICE_ENCRYPTED, | |
168 | bdrv_get_device_name(bs), | |
169 | bdrv_get_encrypted_filename(bs)); | |
170 | return; | |
171 | } | |
e42e818b LC |
172 | } |
173 | ||
1e998146 PB |
174 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
175 | autostart = 1; | |
176 | } else { | |
177 | vm_start(); | |
178 | } | |
e42e818b | 179 | } |
b4b12c62 | 180 | |
9b9df25a GH |
181 | void qmp_system_wakeup(Error **errp) |
182 | { | |
183 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); | |
184 | } | |
185 | ||
57c9fafe | 186 | ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) |
b4b12c62 | 187 | { |
57c9fafe | 188 | Object *obj; |
b4b12c62 | 189 | bool ambiguous = false; |
57c9fafe AL |
190 | ObjectPropertyInfoList *props = NULL; |
191 | ObjectProperty *prop; | |
b4b12c62 | 192 | |
57c9fafe AL |
193 | obj = object_resolve_path(path, &ambiguous); |
194 | if (obj == NULL) { | |
79772087 MT |
195 | if (ambiguous) { |
196 | error_setg(errp, "Path '%s' is ambiguous", path); | |
197 | } else { | |
198 | error_set(errp, QERR_DEVICE_NOT_FOUND, path); | |
199 | } | |
b4b12c62 AL |
200 | return NULL; |
201 | } | |
202 | ||
57c9fafe AL |
203 | QTAILQ_FOREACH(prop, &obj->properties, node) { |
204 | ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); | |
b4b12c62 | 205 | |
57c9fafe | 206 | entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); |
b4b12c62 AL |
207 | entry->next = props; |
208 | props = entry; | |
209 | ||
210 | entry->value->name = g_strdup(prop->name); | |
211 | entry->value->type = g_strdup(prop->type); | |
212 | } | |
213 | ||
214 | return props; | |
215 | } | |
eb6e8ea5 AL |
216 | |
217 | /* FIXME: teach qapi about how to pass through Visitors */ | |
218 | int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret) | |
219 | { | |
220 | const char *path = qdict_get_str(qdict, "path"); | |
221 | const char *property = qdict_get_str(qdict, "property"); | |
222 | QObject *value = qdict_get(qdict, "value"); | |
223 | Error *local_err = NULL; | |
57c9fafe | 224 | Object *obj; |
eb6e8ea5 | 225 | |
57c9fafe AL |
226 | obj = object_resolve_path(path, NULL); |
227 | if (!obj) { | |
eb6e8ea5 AL |
228 | error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); |
229 | goto out; | |
230 | } | |
231 | ||
9f5f1350 | 232 | object_property_set_qobject(obj, value, property, &local_err); |
eb6e8ea5 AL |
233 | |
234 | out: | |
235 | if (local_err) { | |
236 | qerror_report_err(local_err); | |
237 | error_free(local_err); | |
238 | return -1; | |
239 | } | |
240 | ||
241 | return 0; | |
242 | } | |
243 | ||
244 | int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret) | |
245 | { | |
246 | const char *path = qdict_get_str(qdict, "path"); | |
247 | const char *property = qdict_get_str(qdict, "property"); | |
248 | Error *local_err = NULL; | |
57c9fafe | 249 | Object *obj; |
eb6e8ea5 | 250 | |
57c9fafe AL |
251 | obj = object_resolve_path(path, NULL); |
252 | if (!obj) { | |
eb6e8ea5 AL |
253 | error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); |
254 | goto out; | |
255 | } | |
256 | ||
9f5f1350 | 257 | *ret = object_property_get_qobject(obj, property, &local_err); |
eb6e8ea5 AL |
258 | |
259 | out: | |
260 | if (local_err) { | |
261 | qerror_report_err(local_err); | |
262 | error_free(local_err); | |
263 | return -1; | |
264 | } | |
265 | ||
266 | return 0; | |
267 | } | |
fbf796fd LC |
268 | |
269 | void qmp_set_password(const char *protocol, const char *password, | |
270 | bool has_connected, const char *connected, Error **errp) | |
271 | { | |
272 | int disconnect_if_connected = 0; | |
273 | int fail_if_connected = 0; | |
274 | int rc; | |
275 | ||
276 | if (has_connected) { | |
277 | if (strcmp(connected, "fail") == 0) { | |
278 | fail_if_connected = 1; | |
279 | } else if (strcmp(connected, "disconnect") == 0) { | |
280 | disconnect_if_connected = 1; | |
281 | } else if (strcmp(connected, "keep") == 0) { | |
282 | /* nothing */ | |
283 | } else { | |
284 | error_set(errp, QERR_INVALID_PARAMETER, "connected"); | |
285 | return; | |
286 | } | |
287 | } | |
288 | ||
289 | if (strcmp(protocol, "spice") == 0) { | |
290 | if (!using_spice) { | |
291 | /* correct one? spice isn't a device ,,, */ | |
292 | error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice"); | |
293 | return; | |
294 | } | |
295 | rc = qemu_spice_set_passwd(password, fail_if_connected, | |
296 | disconnect_if_connected); | |
297 | if (rc != 0) { | |
298 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
299 | } | |
300 | return; | |
301 | } | |
302 | ||
303 | if (strcmp(protocol, "vnc") == 0) { | |
304 | if (fail_if_connected || disconnect_if_connected) { | |
305 | /* vnc supports "connected=keep" only */ | |
306 | error_set(errp, QERR_INVALID_PARAMETER, "connected"); | |
307 | return; | |
308 | } | |
309 | /* Note that setting an empty password will not disable login through | |
310 | * this interface. */ | |
311 | rc = vnc_display_password(NULL, password); | |
312 | if (rc < 0) { | |
313 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
314 | } | |
315 | return; | |
316 | } | |
317 | ||
318 | error_set(errp, QERR_INVALID_PARAMETER, "protocol"); | |
319 | } | |
9ad5372d LC |
320 | |
321 | void qmp_expire_password(const char *protocol, const char *whenstr, | |
322 | Error **errp) | |
323 | { | |
324 | time_t when; | |
325 | int rc; | |
326 | ||
327 | if (strcmp(whenstr, "now") == 0) { | |
328 | when = 0; | |
329 | } else if (strcmp(whenstr, "never") == 0) { | |
330 | when = TIME_MAX; | |
331 | } else if (whenstr[0] == '+') { | |
332 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); | |
333 | } else { | |
334 | when = strtoull(whenstr, NULL, 10); | |
335 | } | |
336 | ||
337 | if (strcmp(protocol, "spice") == 0) { | |
338 | if (!using_spice) { | |
339 | /* correct one? spice isn't a device ,,, */ | |
340 | error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice"); | |
341 | return; | |
342 | } | |
343 | rc = qemu_spice_set_pw_expire(when); | |
344 | if (rc != 0) { | |
345 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
346 | } | |
347 | return; | |
348 | } | |
349 | ||
350 | if (strcmp(protocol, "vnc") == 0) { | |
351 | rc = vnc_display_pw_expire(NULL, when); | |
352 | if (rc != 0) { | |
353 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
354 | } | |
355 | return; | |
356 | } | |
357 | ||
358 | error_set(errp, QERR_INVALID_PARAMETER, "protocol"); | |
359 | } | |
270b243f | 360 | |
333a96ec | 361 | #ifdef CONFIG_VNC |
270b243f LC |
362 | void qmp_change_vnc_password(const char *password, Error **errp) |
363 | { | |
364 | if (vnc_display_password(NULL, password) < 0) { | |
365 | error_set(errp, QERR_SET_PASSWD_FAILED); | |
366 | } | |
367 | } | |
333a96ec | 368 | |
007fcd3e | 369 | static void qmp_change_vnc_listen(const char *target, Error **errp) |
333a96ec | 370 | { |
007fcd3e | 371 | vnc_display_open(NULL, target, errp); |
333a96ec LC |
372 | } |
373 | ||
374 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, | |
375 | Error **errp) | |
376 | { | |
377 | if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { | |
378 | if (!has_arg) { | |
379 | error_set(errp, QERR_MISSING_PARAMETER, "password"); | |
380 | } else { | |
381 | qmp_change_vnc_password(arg, errp); | |
382 | } | |
383 | } else { | |
384 | qmp_change_vnc_listen(target, errp); | |
385 | } | |
386 | } | |
387 | #else | |
388 | void qmp_change_vnc_password(const char *password, Error **errp) | |
389 | { | |
390 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); | |
391 | } | |
392 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, | |
393 | Error **errp) | |
394 | { | |
395 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); | |
396 | } | |
397 | #endif /* !CONFIG_VNC */ | |
398 | ||
399 | void qmp_change(const char *device, const char *target, | |
7daecb30 | 400 | bool has_arg, const char *arg, Error **errp) |
333a96ec LC |
401 | { |
402 | if (strcmp(device, "vnc") == 0) { | |
7daecb30 | 403 | qmp_change_vnc(target, has_arg, arg, errp); |
333a96ec | 404 | } else { |
7daecb30 | 405 | qmp_change_blockdev(device, target, arg, errp); |
333a96ec LC |
406 | } |
407 | } | |
5eeee3fa AL |
408 | |
409 | static void qom_list_types_tramp(ObjectClass *klass, void *data) | |
410 | { | |
411 | ObjectTypeInfoList *e, **pret = data; | |
412 | ObjectTypeInfo *info; | |
413 | ||
414 | info = g_malloc0(sizeof(*info)); | |
415 | info->name = g_strdup(object_class_get_name(klass)); | |
416 | ||
417 | e = g_malloc0(sizeof(*e)); | |
418 | e->value = info; | |
419 | e->next = *pret; | |
420 | *pret = e; | |
421 | } | |
422 | ||
423 | ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, | |
424 | const char *implements, | |
425 | bool has_abstract, | |
426 | bool abstract, | |
427 | Error **errp) | |
428 | { | |
429 | ObjectTypeInfoList *ret = NULL; | |
430 | ||
431 | object_class_foreach(qom_list_types_tramp, implements, abstract, &ret); | |
432 | ||
433 | return ret; | |
434 | } | |
1daa31b9 | 435 | |
f4eb32b5 SH |
436 | /* Return a DevicePropertyInfo for a qdev property. |
437 | * | |
438 | * If a qdev property with the given name does not exist, use the given default | |
439 | * type. If the qdev property info should not be shown, return NULL. | |
440 | * | |
441 | * The caller must free the return value. | |
442 | */ | |
443 | static DevicePropertyInfo *make_device_property_info(ObjectClass *klass, | |
444 | const char *name, | |
445 | const char *default_type) | |
446 | { | |
447 | DevicePropertyInfo *info; | |
448 | Property *prop; | |
449 | ||
450 | do { | |
451 | for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { | |
452 | if (strcmp(name, prop->name) != 0) { | |
453 | continue; | |
454 | } | |
455 | ||
456 | /* | |
457 | * TODO Properties without a parser are just for dirty hacks. | |
458 | * qdev_prop_ptr is the only such PropertyInfo. It's marked | |
459 | * for removal. This conditional should be removed along with | |
460 | * it. | |
461 | */ | |
462 | if (!prop->info->set) { | |
463 | return NULL; /* no way to set it, don't show */ | |
464 | } | |
465 | ||
466 | info = g_malloc0(sizeof(*info)); | |
467 | info->name = g_strdup(prop->name); | |
468 | info->type = g_strdup(prop->info->legacy_name ?: prop->info->name); | |
469 | return info; | |
470 | } | |
471 | klass = object_class_get_parent(klass); | |
472 | } while (klass != object_class_by_name(TYPE_DEVICE)); | |
473 | ||
474 | /* Not a qdev property, use the default type */ | |
475 | info = g_malloc0(sizeof(*info)); | |
476 | info->name = g_strdup(name); | |
477 | info->type = g_strdup(default_type); | |
478 | return info; | |
479 | } | |
480 | ||
1daa31b9 AL |
481 | DevicePropertyInfoList *qmp_device_list_properties(const char *typename, |
482 | Error **errp) | |
483 | { | |
484 | ObjectClass *klass; | |
f4eb32b5 SH |
485 | Object *obj; |
486 | ObjectProperty *prop; | |
1daa31b9 AL |
487 | DevicePropertyInfoList *prop_list = NULL; |
488 | ||
489 | klass = object_class_by_name(typename); | |
490 | if (klass == NULL) { | |
491 | error_set(errp, QERR_DEVICE_NOT_FOUND, typename); | |
492 | return NULL; | |
493 | } | |
494 | ||
495 | klass = object_class_dynamic_cast(klass, TYPE_DEVICE); | |
496 | if (klass == NULL) { | |
497 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, | |
498 | "name", TYPE_DEVICE); | |
499 | return NULL; | |
500 | } | |
501 | ||
f4eb32b5 | 502 | obj = object_new(typename); |
1daa31b9 | 503 | |
f4eb32b5 SH |
504 | QTAILQ_FOREACH(prop, &obj->properties, node) { |
505 | DevicePropertyInfo *info; | |
506 | DevicePropertyInfoList *entry; | |
507 | ||
508 | /* Skip Object and DeviceState properties */ | |
509 | if (strcmp(prop->name, "type") == 0 || | |
510 | strcmp(prop->name, "realized") == 0 || | |
511 | strcmp(prop->name, "hotpluggable") == 0 || | |
4115dd65 | 512 | strcmp(prop->name, "hotplugged") == 0 || |
f4eb32b5 SH |
513 | strcmp(prop->name, "parent_bus") == 0) { |
514 | continue; | |
515 | } | |
1daa31b9 | 516 | |
f4eb32b5 SH |
517 | /* Skip legacy properties since they are just string versions of |
518 | * properties that we already list. | |
519 | */ | |
520 | if (strstart(prop->name, "legacy-", NULL)) { | |
521 | continue; | |
522 | } | |
1daa31b9 | 523 | |
f4eb32b5 SH |
524 | info = make_device_property_info(klass, prop->name, prop->type); |
525 | if (!info) { | |
526 | continue; | |
1daa31b9 | 527 | } |
f4eb32b5 SH |
528 | |
529 | entry = g_malloc0(sizeof(*entry)); | |
530 | entry->value = info; | |
531 | entry->next = prop_list; | |
532 | prop_list = entry; | |
533 | } | |
534 | ||
535 | object_unref(obj); | |
1daa31b9 AL |
536 | |
537 | return prop_list; | |
538 | } | |
e4e31c63 | 539 | |
76b64a7a AL |
540 | CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
541 | { | |
542 | return arch_query_cpu_definitions(errp); | |
543 | } | |
544 | ||
b224e5e2 LC |
545 | void qmp_add_client(const char *protocol, const char *fdname, |
546 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, | |
547 | Error **errp) | |
548 | { | |
549 | CharDriverState *s; | |
550 | int fd; | |
551 | ||
552 | fd = monitor_get_fd(cur_mon, fdname, errp); | |
553 | if (fd < 0) { | |
554 | return; | |
555 | } | |
556 | ||
557 | if (strcmp(protocol, "spice") == 0) { | |
558 | if (!using_spice) { | |
559 | error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice"); | |
560 | close(fd); | |
561 | return; | |
562 | } | |
563 | skipauth = has_skipauth ? skipauth : false; | |
564 | tls = has_tls ? tls : false; | |
565 | if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) { | |
566 | error_setg(errp, "spice failed to add client"); | |
567 | close(fd); | |
568 | } | |
569 | return; | |
570 | #ifdef CONFIG_VNC | |
571 | } else if (strcmp(protocol, "vnc") == 0) { | |
572 | skipauth = has_skipauth ? skipauth : false; | |
573 | vnc_display_add_client(NULL, fd, skipauth); | |
574 | return; | |
575 | #endif | |
576 | } else if ((s = qemu_chr_find(protocol)) != NULL) { | |
577 | if (qemu_chr_add_client(s, fd) < 0) { | |
578 | error_setg(errp, "failed to add client"); | |
579 | close(fd); | |
580 | return; | |
581 | } | |
582 | return; | |
583 | } | |
584 | ||
585 | error_setg(errp, "protocol '%s' is invalid", protocol); | |
586 | close(fd); | |
587 | } | |
ab2d0531 | 588 | |
cff8b2c6 PB |
589 | void object_add(const char *type, const char *id, const QDict *qdict, |
590 | Visitor *v, Error **errp) | |
591 | { | |
592 | Object *obj; | |
c3481247 | 593 | ObjectClass *klass; |
cff8b2c6 PB |
594 | const QDictEntry *e; |
595 | Error *local_err = NULL; | |
596 | ||
c3481247 EH |
597 | klass = object_class_by_name(type); |
598 | if (!klass) { | |
d1169464 | 599 | error_setg(errp, "invalid object type: %s", type); |
cff8b2c6 PB |
600 | return; |
601 | } | |
602 | ||
c3481247 EH |
603 | if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) { |
604 | error_setg(errp, "object type '%s' isn't supported by object-add", | |
605 | type); | |
606 | return; | |
607 | } | |
608 | ||
609 | if (object_class_is_abstract(klass)) { | |
610 | error_setg(errp, "object type '%s' is abstract", type); | |
611 | return; | |
612 | } | |
613 | ||
cff8b2c6 PB |
614 | obj = object_new(type); |
615 | if (qdict) { | |
616 | for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) { | |
617 | object_property_set(obj, v, e->key, &local_err); | |
618 | if (local_err) { | |
69252c04 | 619 | goto out; |
cff8b2c6 PB |
620 | } |
621 | } | |
622 | } | |
623 | ||
a790f4ec IM |
624 | object_property_add_child(container_get(object_get_root(), "/objects"), |
625 | id, obj, &local_err); | |
269e09f3 IM |
626 | if (local_err) { |
627 | goto out; | |
628 | } | |
629 | ||
a790f4ec IM |
630 | user_creatable_complete(obj, &local_err); |
631 | if (local_err) { | |
632 | object_property_del(container_get(object_get_root(), "/objects"), | |
633 | id, &error_abort); | |
634 | goto out; | |
635 | } | |
69252c04 IM |
636 | out: |
637 | if (local_err) { | |
638 | error_propagate(errp, local_err); | |
639 | } | |
cff8b2c6 PB |
640 | object_unref(obj); |
641 | } | |
642 | ||
643 | int qmp_object_add(Monitor *mon, const QDict *qdict, QObject **ret) | |
644 | { | |
645 | const char *type = qdict_get_str(qdict, "qom-type"); | |
646 | const char *id = qdict_get_str(qdict, "id"); | |
647 | QObject *props = qdict_get(qdict, "props"); | |
648 | const QDict *pdict = NULL; | |
649 | Error *local_err = NULL; | |
650 | QmpInputVisitor *qiv; | |
651 | ||
652 | if (props) { | |
653 | pdict = qobject_to_qdict(props); | |
654 | if (!pdict) { | |
655 | error_set(&local_err, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); | |
656 | goto out; | |
657 | } | |
658 | } | |
659 | ||
660 | qiv = qmp_input_visitor_new(props); | |
661 | object_add(type, id, pdict, qmp_input_get_visitor(qiv), &local_err); | |
662 | qmp_input_visitor_cleanup(qiv); | |
663 | ||
664 | out: | |
665 | if (local_err) { | |
666 | qerror_report_err(local_err); | |
667 | error_free(local_err); | |
668 | return -1; | |
669 | } | |
670 | ||
671 | return 0; | |
672 | } | |
673 | ||
ab2d0531 PB |
674 | void qmp_object_del(const char *id, Error **errp) |
675 | { | |
676 | Object *container; | |
677 | Object *obj; | |
678 | ||
679 | container = container_get(object_get_root(), "/objects"); | |
680 | obj = object_resolve_path_component(container, id); | |
681 | if (!obj) { | |
682 | error_setg(errp, "object id not found"); | |
683 | return; | |
684 | } | |
685 | object_unparent(obj); | |
686 | } | |
6f2e2730 IM |
687 | |
688 | MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) | |
689 | { | |
690 | MemoryDeviceInfoList *head = NULL; | |
691 | MemoryDeviceInfoList **prev = &head; | |
692 | ||
693 | qmp_pc_dimm_device_list(qdev_get_machine(), &prev); | |
694 | ||
695 | return head; | |
696 | } | |
02419bcb IM |
697 | |
698 | ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) | |
699 | { | |
700 | bool ambig; | |
701 | ACPIOSTInfoList *head = NULL; | |
702 | ACPIOSTInfoList **prev = &head; | |
703 | Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig); | |
704 | ||
705 | if (obj) { | |
706 | AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); | |
707 | AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj); | |
708 | ||
709 | adevc->ospm_status(adev, &prev); | |
710 | } else { | |
711 | error_setg(errp, "command is not supported, missing ACPI device"); | |
712 | } | |
713 | ||
714 | return head; | |
715 | } |