Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 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 | * |
Paolo Bonzini | 6b620ca | 2012-01-13 17:44:23 +0100 | [diff] [blame] | 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. |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "qemu-common.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 17 | #include "sysemu/sysemu.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 18 | #include "qmp-commands.h" |
Paolo Bonzini | dccfcd0 | 2013-04-08 16:55:25 +0200 | [diff] [blame] | 19 | #include "sysemu/char.h" |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 20 | #include "ui/qemu-spice.h" |
| 21 | #include "ui/vnc.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 22 | #include "sysemu/kvm.h" |
| 23 | #include "sysemu/arch_init.h" |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 24 | #include "hw/qdev.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 25 | #include "sysemu/blockdev.h" |
Paolo Bonzini | 14cccb6 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 26 | #include "qom/qom-qobject.h" |
Igor Mammedov | 69ca3ea | 2013-04-30 15:41:25 +0200 | [diff] [blame] | 27 | #include "hw/boards.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 28 | |
| 29 | NameInfo *qmp_query_name(Error **errp) |
| 30 | { |
| 31 | NameInfo *info = g_malloc0(sizeof(*info)); |
| 32 | |
| 33 | if (qemu_name) { |
| 34 | info->has_name = true; |
| 35 | info->name = g_strdup(qemu_name); |
| 36 | } |
| 37 | |
| 38 | return info; |
| 39 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 40 | |
| 41 | VersionInfo *qmp_query_version(Error **err) |
| 42 | { |
| 43 | VersionInfo *info = g_malloc0(sizeof(*info)); |
| 44 | const char *version = QEMU_VERSION; |
| 45 | char *tmp; |
| 46 | |
| 47 | info->qemu.major = strtol(version, &tmp, 10); |
| 48 | tmp++; |
| 49 | info->qemu.minor = strtol(tmp, &tmp, 10); |
| 50 | tmp++; |
| 51 | info->qemu.micro = strtol(tmp, &tmp, 10); |
| 52 | info->package = g_strdup(QEMU_PKGVERSION); |
| 53 | |
| 54 | return info; |
| 55 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 56 | |
| 57 | KvmInfo *qmp_query_kvm(Error **errp) |
| 58 | { |
| 59 | KvmInfo *info = g_malloc0(sizeof(*info)); |
| 60 | |
| 61 | info->enabled = kvm_enabled(); |
| 62 | info->present = kvm_available(); |
| 63 | |
| 64 | return info; |
| 65 | } |
| 66 | |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 67 | UuidInfo *qmp_query_uuid(Error **errp) |
| 68 | { |
| 69 | UuidInfo *info = g_malloc0(sizeof(*info)); |
| 70 | char uuid[64]; |
| 71 | |
| 72 | snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1], |
| 73 | qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], |
| 74 | qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], |
| 75 | qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], |
| 76 | qemu_uuid[14], qemu_uuid[15]); |
| 77 | |
| 78 | info->UUID = g_strdup(uuid); |
| 79 | return info; |
| 80 | } |
| 81 | |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 82 | void qmp_quit(Error **err) |
| 83 | { |
| 84 | no_shutdown = 0; |
| 85 | qemu_system_shutdown_request(); |
| 86 | } |
| 87 | |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 88 | void qmp_stop(Error **errp) |
| 89 | { |
Paolo Bonzini | 1e99814 | 2012-10-23 14:54:21 +0200 | [diff] [blame] | 90 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 91 | autostart = 0; |
| 92 | } else { |
| 93 | vm_stop(RUN_STATE_PAUSED); |
| 94 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 95 | } |
| 96 | |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 97 | void qmp_system_reset(Error **errp) |
| 98 | { |
| 99 | qemu_system_reset_request(); |
| 100 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 101 | |
| 102 | void qmp_system_powerdown(Error **erp) |
| 103 | { |
| 104 | qemu_system_powerdown_request(); |
| 105 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 106 | |
| 107 | void qmp_cpu(int64_t index, Error **errp) |
| 108 | { |
| 109 | /* Just do nothing */ |
| 110 | } |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 111 | |
Igor Mammedov | 69ca3ea | 2013-04-30 15:41:25 +0200 | [diff] [blame] | 112 | void qmp_cpu_add(int64_t id, Error **errp) |
| 113 | { |
| 114 | if (current_machine->hot_add_cpu) { |
| 115 | current_machine->hot_add_cpu(id, errp); |
| 116 | } else { |
| 117 | error_setg(errp, "Not supported"); |
| 118 | } |
| 119 | } |
| 120 | |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 121 | #ifndef CONFIG_VNC |
| 122 | /* If VNC support is enabled, the "true" query-vnc command is |
| 123 | defined in the VNC subsystem */ |
| 124 | VncInfo *qmp_query_vnc(Error **errp) |
| 125 | { |
| 126 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); |
| 127 | return NULL; |
| 128 | }; |
| 129 | #endif |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 130 | |
| 131 | #ifndef CONFIG_SPICE |
| 132 | /* If SPICE support is enabled, the "true" query-spice command is |
| 133 | defined in the SPICE subsystem. Also note that we use a small |
| 134 | trick to maintain query-spice's original behavior, which is not |
| 135 | to be available in the namespace if SPICE is not compiled in */ |
| 136 | SpiceInfo *qmp_query_spice(Error **errp) |
| 137 | { |
| 138 | error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice"); |
| 139 | return NULL; |
| 140 | }; |
| 141 | #endif |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 142 | |
| 143 | static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs) |
| 144 | { |
| 145 | bdrv_iostatus_reset(bs); |
| 146 | } |
| 147 | |
| 148 | static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs) |
| 149 | { |
| 150 | Error **err = opaque; |
| 151 | |
| 152 | if (!error_is_set(err) && bdrv_key_required(bs)) { |
Luiz Capitulino | 903a881 | 2011-12-13 17:18:30 -0200 | [diff] [blame] | 153 | error_set(err, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs), |
| 154 | bdrv_get_encrypted_filename(bs)); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
| 158 | void qmp_cont(Error **errp) |
| 159 | { |
| 160 | Error *local_err = NULL; |
| 161 | |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 162 | if (runstate_needs_reset()) { |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 163 | error_set(errp, QERR_RESET_REQUIRED); |
| 164 | return; |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 165 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
| 166 | return; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | bdrv_iterate(iostatus_bdrv_it, NULL); |
| 170 | bdrv_iterate(encrypted_bdrv_it, &local_err); |
| 171 | if (local_err) { |
| 172 | error_propagate(errp, local_err); |
| 173 | return; |
| 174 | } |
| 175 | |
Paolo Bonzini | 1e99814 | 2012-10-23 14:54:21 +0200 | [diff] [blame] | 176 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 177 | autostart = 1; |
| 178 | } else { |
| 179 | vm_start(); |
| 180 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 181 | } |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 182 | |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 183 | void qmp_system_wakeup(Error **errp) |
| 184 | { |
| 185 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); |
| 186 | } |
| 187 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 188 | ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 189 | { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 190 | Object *obj; |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 191 | bool ambiguous = false; |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 192 | ObjectPropertyInfoList *props = NULL; |
| 193 | ObjectProperty *prop; |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 194 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 195 | obj = object_resolve_path(path, &ambiguous); |
| 196 | if (obj == NULL) { |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 197 | error_set(errp, QERR_DEVICE_NOT_FOUND, path); |
| 198 | return NULL; |
| 199 | } |
| 200 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 201 | QTAILQ_FOREACH(prop, &obj->properties, node) { |
| 202 | ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 203 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 204 | entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 205 | entry->next = props; |
| 206 | props = entry; |
| 207 | |
| 208 | entry->value->name = g_strdup(prop->name); |
| 209 | entry->value->type = g_strdup(prop->type); |
| 210 | } |
| 211 | |
| 212 | return props; |
| 213 | } |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 214 | |
| 215 | /* FIXME: teach qapi about how to pass through Visitors */ |
| 216 | int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret) |
| 217 | { |
| 218 | const char *path = qdict_get_str(qdict, "path"); |
| 219 | const char *property = qdict_get_str(qdict, "property"); |
| 220 | QObject *value = qdict_get(qdict, "value"); |
| 221 | Error *local_err = NULL; |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 222 | Object *obj; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 223 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 224 | obj = object_resolve_path(path, NULL); |
| 225 | if (!obj) { |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 226 | error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); |
| 227 | goto out; |
| 228 | } |
| 229 | |
Paolo Bonzini | 9f5f135 | 2012-02-01 16:58:47 +0100 | [diff] [blame] | 230 | object_property_set_qobject(obj, value, property, &local_err); |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 231 | |
| 232 | out: |
| 233 | if (local_err) { |
| 234 | qerror_report_err(local_err); |
| 235 | error_free(local_err); |
| 236 | return -1; |
| 237 | } |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret) |
| 243 | { |
| 244 | const char *path = qdict_get_str(qdict, "path"); |
| 245 | const char *property = qdict_get_str(qdict, "property"); |
| 246 | Error *local_err = NULL; |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 247 | Object *obj; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 248 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 249 | obj = object_resolve_path(path, NULL); |
| 250 | if (!obj) { |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 251 | error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); |
| 252 | goto out; |
| 253 | } |
| 254 | |
Paolo Bonzini | 9f5f135 | 2012-02-01 16:58:47 +0100 | [diff] [blame] | 255 | *ret = object_property_get_qobject(obj, property, &local_err); |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 256 | |
| 257 | out: |
| 258 | if (local_err) { |
| 259 | qerror_report_err(local_err); |
| 260 | error_free(local_err); |
| 261 | return -1; |
| 262 | } |
| 263 | |
| 264 | return 0; |
| 265 | } |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 266 | |
| 267 | void qmp_set_password(const char *protocol, const char *password, |
| 268 | bool has_connected, const char *connected, Error **errp) |
| 269 | { |
| 270 | int disconnect_if_connected = 0; |
| 271 | int fail_if_connected = 0; |
| 272 | int rc; |
| 273 | |
| 274 | if (has_connected) { |
| 275 | if (strcmp(connected, "fail") == 0) { |
| 276 | fail_if_connected = 1; |
| 277 | } else if (strcmp(connected, "disconnect") == 0) { |
| 278 | disconnect_if_connected = 1; |
| 279 | } else if (strcmp(connected, "keep") == 0) { |
| 280 | /* nothing */ |
| 281 | } else { |
| 282 | error_set(errp, QERR_INVALID_PARAMETER, "connected"); |
| 283 | return; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | if (strcmp(protocol, "spice") == 0) { |
| 288 | if (!using_spice) { |
| 289 | /* correct one? spice isn't a device ,,, */ |
| 290 | error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice"); |
| 291 | return; |
| 292 | } |
| 293 | rc = qemu_spice_set_passwd(password, fail_if_connected, |
| 294 | disconnect_if_connected); |
| 295 | if (rc != 0) { |
| 296 | error_set(errp, QERR_SET_PASSWD_FAILED); |
| 297 | } |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | if (strcmp(protocol, "vnc") == 0) { |
| 302 | if (fail_if_connected || disconnect_if_connected) { |
| 303 | /* vnc supports "connected=keep" only */ |
| 304 | error_set(errp, QERR_INVALID_PARAMETER, "connected"); |
| 305 | return; |
| 306 | } |
| 307 | /* Note that setting an empty password will not disable login through |
| 308 | * this interface. */ |
| 309 | rc = vnc_display_password(NULL, password); |
| 310 | if (rc < 0) { |
| 311 | error_set(errp, QERR_SET_PASSWD_FAILED); |
| 312 | } |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | error_set(errp, QERR_INVALID_PARAMETER, "protocol"); |
| 317 | } |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 318 | |
| 319 | void qmp_expire_password(const char *protocol, const char *whenstr, |
| 320 | Error **errp) |
| 321 | { |
| 322 | time_t when; |
| 323 | int rc; |
| 324 | |
| 325 | if (strcmp(whenstr, "now") == 0) { |
| 326 | when = 0; |
| 327 | } else if (strcmp(whenstr, "never") == 0) { |
| 328 | when = TIME_MAX; |
| 329 | } else if (whenstr[0] == '+') { |
| 330 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); |
| 331 | } else { |
| 332 | when = strtoull(whenstr, NULL, 10); |
| 333 | } |
| 334 | |
| 335 | if (strcmp(protocol, "spice") == 0) { |
| 336 | if (!using_spice) { |
| 337 | /* correct one? spice isn't a device ,,, */ |
| 338 | error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice"); |
| 339 | return; |
| 340 | } |
| 341 | rc = qemu_spice_set_pw_expire(when); |
| 342 | if (rc != 0) { |
| 343 | error_set(errp, QERR_SET_PASSWD_FAILED); |
| 344 | } |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | if (strcmp(protocol, "vnc") == 0) { |
| 349 | rc = vnc_display_pw_expire(NULL, when); |
| 350 | if (rc != 0) { |
| 351 | error_set(errp, QERR_SET_PASSWD_FAILED); |
| 352 | } |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | error_set(errp, QERR_INVALID_PARAMETER, "protocol"); |
| 357 | } |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 358 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 359 | #ifdef CONFIG_VNC |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 360 | void qmp_change_vnc_password(const char *password, Error **errp) |
| 361 | { |
| 362 | if (vnc_display_password(NULL, password) < 0) { |
| 363 | error_set(errp, QERR_SET_PASSWD_FAILED); |
| 364 | } |
| 365 | } |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 366 | |
Paolo Bonzini | 007fcd3e | 2012-10-18 09:01:01 +0200 | [diff] [blame] | 367 | static void qmp_change_vnc_listen(const char *target, Error **errp) |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 368 | { |
Paolo Bonzini | 007fcd3e | 2012-10-18 09:01:01 +0200 | [diff] [blame] | 369 | vnc_display_open(NULL, target, errp); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, |
| 373 | Error **errp) |
| 374 | { |
| 375 | if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { |
| 376 | if (!has_arg) { |
| 377 | error_set(errp, QERR_MISSING_PARAMETER, "password"); |
| 378 | } else { |
| 379 | qmp_change_vnc_password(arg, errp); |
| 380 | } |
| 381 | } else { |
| 382 | qmp_change_vnc_listen(target, errp); |
| 383 | } |
| 384 | } |
| 385 | #else |
| 386 | void qmp_change_vnc_password(const char *password, Error **errp) |
| 387 | { |
| 388 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); |
| 389 | } |
| 390 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, |
| 391 | Error **errp) |
| 392 | { |
| 393 | error_set(errp, QERR_FEATURE_DISABLED, "vnc"); |
| 394 | } |
| 395 | #endif /* !CONFIG_VNC */ |
| 396 | |
| 397 | void qmp_change(const char *device, const char *target, |
| 398 | bool has_arg, const char *arg, Error **err) |
| 399 | { |
| 400 | if (strcmp(device, "vnc") == 0) { |
| 401 | qmp_change_vnc(target, has_arg, arg, err); |
| 402 | } else { |
| 403 | qmp_change_blockdev(device, target, has_arg, arg, err); |
| 404 | } |
| 405 | } |
Anthony Liguori | 5eeee3f | 2011-12-22 14:40:54 -0600 | [diff] [blame] | 406 | |
| 407 | static void qom_list_types_tramp(ObjectClass *klass, void *data) |
| 408 | { |
| 409 | ObjectTypeInfoList *e, **pret = data; |
| 410 | ObjectTypeInfo *info; |
| 411 | |
| 412 | info = g_malloc0(sizeof(*info)); |
| 413 | info->name = g_strdup(object_class_get_name(klass)); |
| 414 | |
| 415 | e = g_malloc0(sizeof(*e)); |
| 416 | e->value = info; |
| 417 | e->next = *pret; |
| 418 | *pret = e; |
| 419 | } |
| 420 | |
| 421 | ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, |
| 422 | const char *implements, |
| 423 | bool has_abstract, |
| 424 | bool abstract, |
| 425 | Error **errp) |
| 426 | { |
| 427 | ObjectTypeInfoList *ret = NULL; |
| 428 | |
| 429 | object_class_foreach(qom_list_types_tramp, implements, abstract, &ret); |
| 430 | |
| 431 | return ret; |
| 432 | } |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 433 | |
| 434 | DevicePropertyInfoList *qmp_device_list_properties(const char *typename, |
| 435 | Error **errp) |
| 436 | { |
| 437 | ObjectClass *klass; |
| 438 | Property *prop; |
| 439 | DevicePropertyInfoList *prop_list = NULL; |
| 440 | |
| 441 | klass = object_class_by_name(typename); |
| 442 | if (klass == NULL) { |
| 443 | error_set(errp, QERR_DEVICE_NOT_FOUND, typename); |
| 444 | return NULL; |
| 445 | } |
| 446 | |
| 447 | klass = object_class_dynamic_cast(klass, TYPE_DEVICE); |
| 448 | if (klass == NULL) { |
| 449 | error_set(errp, QERR_INVALID_PARAMETER_VALUE, |
| 450 | "name", TYPE_DEVICE); |
| 451 | return NULL; |
| 452 | } |
| 453 | |
| 454 | do { |
| 455 | for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { |
| 456 | DevicePropertyInfoList *entry; |
| 457 | DevicePropertyInfo *info; |
| 458 | |
| 459 | /* |
| 460 | * TODO Properties without a parser are just for dirty hacks. |
| 461 | * qdev_prop_ptr is the only such PropertyInfo. It's marked |
| 462 | * for removal. This conditional should be removed along with |
| 463 | * it. |
| 464 | */ |
| 465 | if (!prop->info->set) { |
| 466 | continue; /* no way to set it, don't show */ |
| 467 | } |
| 468 | |
| 469 | info = g_malloc0(sizeof(*info)); |
| 470 | info->name = g_strdup(prop->name); |
| 471 | info->type = g_strdup(prop->info->legacy_name ?: prop->info->name); |
| 472 | |
| 473 | entry = g_malloc0(sizeof(*entry)); |
| 474 | entry->value = info; |
| 475 | entry->next = prop_list; |
| 476 | prop_list = entry; |
| 477 | } |
| 478 | klass = object_class_get_parent(klass); |
| 479 | } while (klass != object_class_by_name(TYPE_DEVICE)); |
| 480 | |
| 481 | return prop_list; |
| 482 | } |
Anthony Liguori | e4e31c6 | 2012-08-10 11:04:13 -0500 | [diff] [blame] | 483 | |
Anthony Liguori | 76b64a7 | 2012-08-14 22:17:36 -0500 | [diff] [blame] | 484 | CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
| 485 | { |
| 486 | return arch_query_cpu_definitions(errp); |
| 487 | } |
| 488 | |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 489 | void qmp_add_client(const char *protocol, const char *fdname, |
| 490 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, |
| 491 | Error **errp) |
| 492 | { |
| 493 | CharDriverState *s; |
| 494 | int fd; |
| 495 | |
| 496 | fd = monitor_get_fd(cur_mon, fdname, errp); |
| 497 | if (fd < 0) { |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | if (strcmp(protocol, "spice") == 0) { |
| 502 | if (!using_spice) { |
| 503 | error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice"); |
| 504 | close(fd); |
| 505 | return; |
| 506 | } |
| 507 | skipauth = has_skipauth ? skipauth : false; |
| 508 | tls = has_tls ? tls : false; |
| 509 | if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) { |
| 510 | error_setg(errp, "spice failed to add client"); |
| 511 | close(fd); |
| 512 | } |
| 513 | return; |
| 514 | #ifdef CONFIG_VNC |
| 515 | } else if (strcmp(protocol, "vnc") == 0) { |
| 516 | skipauth = has_skipauth ? skipauth : false; |
| 517 | vnc_display_add_client(NULL, fd, skipauth); |
| 518 | return; |
| 519 | #endif |
| 520 | } else if ((s = qemu_chr_find(protocol)) != NULL) { |
| 521 | if (qemu_chr_add_client(s, fd) < 0) { |
| 522 | error_setg(errp, "failed to add client"); |
| 523 | close(fd); |
| 524 | return; |
| 525 | } |
| 526 | return; |
| 527 | } |
| 528 | |
| 529 | error_setg(errp, "protocol '%s' is invalid", protocol); |
| 530 | close(fd); |
| 531 | } |