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