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