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