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