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 | |
Peter Maydell | d38ea87 | 2016-01-29 17:50:05 +0000 | [diff] [blame] | 16 | #include "qemu/osdep.h" |
Fam Zheng | 67a1de0 | 2016-06-01 17:44:21 +0800 | [diff] [blame] | 17 | #include "qemu-version.h" |
Veronia Bahaa | f348b6d | 2016-03-20 19:16:19 +0200 | [diff] [blame] | 18 | #include "qemu/cutils.h" |
Markus Armbruster | a0b1a66 | 2015-03-17 18:16:21 +0100 | [diff] [blame] | 19 | #include "monitor/monitor.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 20 | #include "sysemu/sysemu.h" |
Marc-André Lureau | 213dcb0 | 2016-12-12 20:22:24 +0300 | [diff] [blame] | 21 | #include "qemu/config-file.h" |
Fam Zheng | cea2527 | 2016-09-21 12:27:14 +0800 | [diff] [blame] | 22 | #include "qemu/uuid.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 23 | #include "qmp-commands.h" |
Paolo Bonzini | dccfcd0 | 2013-04-08 16:55:25 +0200 | [diff] [blame] | 24 | #include "sysemu/char.h" |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 25 | #include "ui/qemu-spice.h" |
| 26 | #include "ui/vnc.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 27 | #include "sysemu/kvm.h" |
| 28 | #include "sysemu/arch_init.h" |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 29 | #include "hw/qdev.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 30 | #include "sysemu/blockdev.h" |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 31 | #include "sysemu/block-backend.h" |
Paolo Bonzini | 14cccb6 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 32 | #include "qom/qom-qobject.h" |
Markus Armbruster | cc7a8ea | 2015-03-17 17:22:46 +0100 | [diff] [blame] | 33 | #include "qapi/qmp/qerror.h" |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 34 | #include "qapi/qmp/qobject.h" |
Daniel P. Berrange | b3db211 | 2016-09-30 15:45:27 +0100 | [diff] [blame] | 35 | #include "qapi/qobject-input-visitor.h" |
Igor Mammedov | 69ca3ea | 2013-04-30 15:41:25 +0200 | [diff] [blame] | 36 | #include "hw/boards.h" |
Igor Mammedov | 269e09f | 2014-01-16 17:34:38 +0100 | [diff] [blame] | 37 | #include "qom/object_interfaces.h" |
Igor Mammedov | 6f2e273 | 2014-06-16 19:12:25 +0200 | [diff] [blame] | 38 | #include "hw/mem/pc-dimm.h" |
Igor Mammedov | 02419bc | 2014-06-16 19:12:28 +0200 | [diff] [blame] | 39 | #include "hw/acpi/acpi_dev_interface.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 40 | |
| 41 | NameInfo *qmp_query_name(Error **errp) |
| 42 | { |
| 43 | NameInfo *info = g_malloc0(sizeof(*info)); |
| 44 | |
| 45 | if (qemu_name) { |
| 46 | info->has_name = true; |
| 47 | info->name = g_strdup(qemu_name); |
| 48 | } |
| 49 | |
| 50 | return info; |
| 51 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 52 | |
Markus Armbruster | 7daecb3 | 2014-05-02 13:26:31 +0200 | [diff] [blame] | 53 | VersionInfo *qmp_query_version(Error **errp) |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 54 | { |
Eric Blake | 4752cdb | 2015-05-04 09:05:31 -0600 | [diff] [blame] | 55 | VersionInfo *info = g_new0(VersionInfo, 1); |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 56 | |
Eric Blake | 4752cdb | 2015-05-04 09:05:31 -0600 | [diff] [blame] | 57 | info->qemu = g_new0(VersionTriple, 1); |
Marc-André Lureau | 3688d8c | 2016-09-12 13:18:56 +0400 | [diff] [blame] | 58 | info->qemu->major = QEMU_VERSION_MAJOR; |
| 59 | info->qemu->minor = QEMU_VERSION_MINOR; |
| 60 | info->qemu->micro = QEMU_VERSION_MICRO; |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 61 | info->package = g_strdup(QEMU_PKGVERSION); |
| 62 | |
| 63 | return info; |
| 64 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 65 | |
| 66 | KvmInfo *qmp_query_kvm(Error **errp) |
| 67 | { |
| 68 | KvmInfo *info = g_malloc0(sizeof(*info)); |
| 69 | |
| 70 | info->enabled = kvm_enabled(); |
| 71 | info->present = kvm_available(); |
| 72 | |
| 73 | return info; |
| 74 | } |
| 75 | |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 76 | UuidInfo *qmp_query_uuid(Error **errp) |
| 77 | { |
| 78 | UuidInfo *info = g_malloc0(sizeof(*info)); |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 79 | |
Fam Zheng | 9c5ce8d | 2016-09-21 12:27:22 +0800 | [diff] [blame] | 80 | info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid); |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 81 | return info; |
| 82 | } |
| 83 | |
Markus Armbruster | 7daecb3 | 2014-05-02 13:26:31 +0200 | [diff] [blame] | 84 | void qmp_quit(Error **errp) |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 85 | { |
| 86 | no_shutdown = 0; |
| 87 | qemu_system_shutdown_request(); |
| 88 | } |
| 89 | |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 90 | void qmp_stop(Error **errp) |
| 91 | { |
Peter Xu | 65d64f3 | 2016-02-18 13:16:49 +0800 | [diff] [blame] | 92 | /* if there is a dump in background, we should wait until the dump |
| 93 | * finished */ |
| 94 | if (dump_in_progress()) { |
| 95 | error_setg(errp, "There is a dump in process, please wait."); |
| 96 | return; |
| 97 | } |
| 98 | |
Paolo Bonzini | 1e99814 | 2012-10-23 14:54:21 +0200 | [diff] [blame] | 99 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 100 | autostart = 0; |
| 101 | } else { |
| 102 | vm_stop(RUN_STATE_PAUSED); |
| 103 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 104 | } |
| 105 | |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 106 | void qmp_system_reset(Error **errp) |
| 107 | { |
| 108 | qemu_system_reset_request(); |
| 109 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 110 | |
| 111 | void qmp_system_powerdown(Error **erp) |
| 112 | { |
| 113 | qemu_system_powerdown_request(); |
| 114 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 115 | |
| 116 | void qmp_cpu(int64_t index, Error **errp) |
| 117 | { |
| 118 | /* Just do nothing */ |
| 119 | } |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 120 | |
Igor Mammedov | 69ca3ea | 2013-04-30 15:41:25 +0200 | [diff] [blame] | 121 | void qmp_cpu_add(int64_t id, Error **errp) |
| 122 | { |
Marcel Apfelbaum | 0056ae2 | 2014-03-05 19:30:47 +0200 | [diff] [blame] | 123 | MachineClass *mc; |
| 124 | |
| 125 | mc = MACHINE_GET_CLASS(current_machine); |
Marcel Apfelbaum | 958db90 | 2014-04-09 20:34:53 +0300 | [diff] [blame] | 126 | if (mc->hot_add_cpu) { |
| 127 | mc->hot_add_cpu(id, errp); |
Igor Mammedov | 69ca3ea | 2013-04-30 15:41:25 +0200 | [diff] [blame] | 128 | } else { |
| 129 | error_setg(errp, "Not supported"); |
| 130 | } |
| 131 | } |
| 132 | |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 133 | #ifndef CONFIG_VNC |
| 134 | /* If VNC support is enabled, the "true" query-vnc command is |
| 135 | defined in the VNC subsystem */ |
| 136 | VncInfo *qmp_query_vnc(Error **errp) |
| 137 | { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 138 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 139 | return NULL; |
| 140 | }; |
Leon Yu | 89db2177 | 2015-02-02 05:08:51 +0000 | [diff] [blame] | 141 | |
| 142 | VncInfo2List *qmp_query_vnc_servers(Error **errp) |
| 143 | { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 144 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
Leon Yu | 89db2177 | 2015-02-02 05:08:51 +0000 | [diff] [blame] | 145 | return NULL; |
| 146 | }; |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 147 | #endif |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 148 | |
| 149 | #ifndef CONFIG_SPICE |
Markus Armbruster | ad0ec14 | 2015-01-13 15:56:11 +0100 | [diff] [blame] | 150 | /* |
| 151 | * qmp-commands.hx ensures that QMP command query-spice exists only |
| 152 | * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands |
| 153 | * result. However, the QAPI schema is blissfully unaware of that, |
| 154 | * and the QAPI code generator happily generates a dead |
Markus Armbruster | 7fad30f | 2015-09-16 13:06:19 +0200 | [diff] [blame] | 155 | * qmp_marshal_query_spice() that calls qmp_query_spice(). Provide it |
| 156 | * one, or else linking fails. FIXME Educate the QAPI schema on |
| 157 | * CONFIG_SPICE. |
Markus Armbruster | ad0ec14 | 2015-01-13 15:56:11 +0100 | [diff] [blame] | 158 | */ |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 159 | SpiceInfo *qmp_query_spice(Error **errp) |
| 160 | { |
Markus Armbruster | ad0ec14 | 2015-01-13 15:56:11 +0100 | [diff] [blame] | 161 | abort(); |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 162 | }; |
| 163 | #endif |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 164 | |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 165 | void qmp_cont(Error **errp) |
| 166 | { |
Markus Armbruster | 4d2855a | 2015-01-29 10:37:00 +0100 | [diff] [blame] | 167 | Error *local_err = NULL; |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 168 | BlockBackend *blk; |
Markus Armbruster | ab31979 | 2014-05-02 13:26:42 +0200 | [diff] [blame] | 169 | BlockDriverState *bs; |
Kevin Wolf | 88be7b4 | 2016-05-20 18:49:07 +0200 | [diff] [blame] | 170 | BdrvNextIterator it; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 171 | |
Peter Xu | 65d64f3 | 2016-02-18 13:16:49 +0800 | [diff] [blame] | 172 | /* if there is a dump in background, we should wait until the dump |
| 173 | * finished */ |
| 174 | if (dump_in_progress()) { |
| 175 | error_setg(errp, "There is a dump in process, please wait."); |
| 176 | return; |
| 177 | } |
| 178 | |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 179 | if (runstate_needs_reset()) { |
Cole Robinson | f231b88 | 2014-03-21 19:42:26 -0400 | [diff] [blame] | 180 | error_setg(errp, "Resetting the Virtual Machine is required"); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 181 | return; |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 182 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
| 183 | return; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 184 | } |
| 185 | |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 186 | for (blk = blk_next(NULL); blk; blk = blk_next(blk)) { |
| 187 | blk_iostatus_reset(blk); |
Markus Armbruster | ab31979 | 2014-05-02 13:26:42 +0200 | [diff] [blame] | 188 | } |
Kevin Wolf | 7c8eece | 2016-03-22 18:58:50 +0100 | [diff] [blame] | 189 | |
Kevin Wolf | 88be7b4 | 2016-05-20 18:49:07 +0200 | [diff] [blame] | 190 | for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { |
Markus Armbruster | 4d2855a | 2015-01-29 10:37:00 +0100 | [diff] [blame] | 191 | bdrv_add_key(bs, NULL, &local_err); |
| 192 | if (local_err) { |
| 193 | error_propagate(errp, local_err); |
Markus Armbruster | ab31979 | 2014-05-02 13:26:42 +0200 | [diff] [blame] | 194 | return; |
| 195 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 196 | } |
| 197 | |
Kevin Wolf | 76b1c7f | 2015-12-22 14:07:08 +0100 | [diff] [blame] | 198 | /* Continuing after completed migration. Images have been inactivated to |
| 199 | * allow the destination to take control. Need to get control back now. */ |
| 200 | if (runstate_check(RUN_STATE_FINISH_MIGRATE) || |
| 201 | runstate_check(RUN_STATE_POSTMIGRATE)) |
| 202 | { |
| 203 | bdrv_invalidate_cache_all(&local_err); |
| 204 | if (local_err) { |
| 205 | error_propagate(errp, local_err); |
| 206 | return; |
| 207 | } |
| 208 | } |
| 209 | |
Kevin Wolf | d35ff5e | 2017-04-04 17:29:03 +0200 | [diff] [blame] | 210 | blk_resume_after_migration(&local_err); |
| 211 | if (local_err) { |
| 212 | error_propagate(errp, local_err); |
| 213 | return; |
| 214 | } |
| 215 | |
Paolo Bonzini | 1e99814 | 2012-10-23 14:54:21 +0200 | [diff] [blame] | 216 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 217 | autostart = 1; |
| 218 | } else { |
| 219 | vm_start(); |
| 220 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 221 | } |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 222 | |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 223 | void qmp_system_wakeup(Error **errp) |
| 224 | { |
| 225 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); |
| 226 | } |
| 227 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 228 | ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 229 | { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 230 | Object *obj; |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 231 | bool ambiguous = false; |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 232 | ObjectPropertyInfoList *props = NULL; |
| 233 | ObjectProperty *prop; |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 234 | ObjectPropertyIterator iter; |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 235 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 236 | obj = object_resolve_path(path, &ambiguous); |
| 237 | if (obj == NULL) { |
Michael Tokarev | 7977208 | 2014-05-04 12:23:59 +0400 | [diff] [blame] | 238 | if (ambiguous) { |
| 239 | error_setg(errp, "Path '%s' is ambiguous", path); |
| 240 | } else { |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 241 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 242 | "Device '%s' not found", path); |
Michael Tokarev | 7977208 | 2014-05-04 12:23:59 +0400 | [diff] [blame] | 243 | } |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 244 | return NULL; |
| 245 | } |
| 246 | |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 247 | object_property_iter_init(&iter, obj); |
| 248 | while ((prop = object_property_iter_next(&iter))) { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 249 | ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 250 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 251 | entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 252 | entry->next = props; |
| 253 | props = entry; |
| 254 | |
| 255 | entry->value->name = g_strdup(prop->name); |
| 256 | entry->value->type = g_strdup(prop->type); |
| 257 | } |
| 258 | |
| 259 | return props; |
| 260 | } |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 261 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 262 | void qmp_qom_set(const char *path, const char *property, QObject *value, |
| 263 | Error **errp) |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 264 | { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 265 | Object *obj; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 266 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 267 | obj = object_resolve_path(path, NULL); |
| 268 | if (!obj) { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 269 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 270 | "Device '%s' not found", path); |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 271 | return; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 272 | } |
| 273 | |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 274 | object_property_set_qobject(obj, value, property, errp); |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 275 | } |
| 276 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 277 | QObject *qmp_qom_get(const char *path, const char *property, Error **errp) |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 278 | { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 279 | Object *obj; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 280 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 281 | obj = object_resolve_path(path, NULL); |
| 282 | if (!obj) { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 283 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 284 | "Device '%s' not found", path); |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 285 | return NULL; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 286 | } |
| 287 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 288 | return object_property_get_qobject(obj, property, errp); |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 289 | } |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 290 | |
| 291 | void qmp_set_password(const char *protocol, const char *password, |
| 292 | bool has_connected, const char *connected, Error **errp) |
| 293 | { |
| 294 | int disconnect_if_connected = 0; |
| 295 | int fail_if_connected = 0; |
| 296 | int rc; |
| 297 | |
| 298 | if (has_connected) { |
| 299 | if (strcmp(connected, "fail") == 0) { |
| 300 | fail_if_connected = 1; |
| 301 | } else if (strcmp(connected, "disconnect") == 0) { |
| 302 | disconnect_if_connected = 1; |
| 303 | } else if (strcmp(connected, "keep") == 0) { |
| 304 | /* nothing */ |
| 305 | } else { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 306 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 307 | return; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 312 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 313 | return; |
| 314 | } |
| 315 | rc = qemu_spice_set_passwd(password, fail_if_connected, |
| 316 | disconnect_if_connected); |
| 317 | if (rc != 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 318 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 319 | } |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | if (strcmp(protocol, "vnc") == 0) { |
| 324 | if (fail_if_connected || disconnect_if_connected) { |
| 325 | /* vnc supports "connected=keep" only */ |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 326 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 327 | return; |
| 328 | } |
| 329 | /* Note that setting an empty password will not disable login through |
| 330 | * this interface. */ |
| 331 | rc = vnc_display_password(NULL, password); |
| 332 | if (rc < 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 333 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 334 | } |
| 335 | return; |
| 336 | } |
| 337 | |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 338 | error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 339 | } |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 340 | |
| 341 | void qmp_expire_password(const char *protocol, const char *whenstr, |
| 342 | Error **errp) |
| 343 | { |
| 344 | time_t when; |
| 345 | int rc; |
| 346 | |
| 347 | if (strcmp(whenstr, "now") == 0) { |
| 348 | when = 0; |
| 349 | } else if (strcmp(whenstr, "never") == 0) { |
| 350 | when = TIME_MAX; |
| 351 | } else if (whenstr[0] == '+') { |
| 352 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); |
| 353 | } else { |
| 354 | when = strtoull(whenstr, NULL, 10); |
| 355 | } |
| 356 | |
| 357 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 358 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | rc = qemu_spice_set_pw_expire(when); |
| 362 | if (rc != 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 363 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 364 | } |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | if (strcmp(protocol, "vnc") == 0) { |
| 369 | rc = vnc_display_pw_expire(NULL, when); |
| 370 | if (rc != 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 371 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 372 | } |
| 373 | return; |
| 374 | } |
| 375 | |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 376 | error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 377 | } |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 378 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 379 | #ifdef CONFIG_VNC |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 380 | void qmp_change_vnc_password(const char *password, Error **errp) |
| 381 | { |
| 382 | if (vnc_display_password(NULL, password) < 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 383 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 384 | } |
| 385 | } |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 386 | |
Paolo Bonzini | 007fcd3e | 2012-10-18 09:01:01 +0200 | [diff] [blame] | 387 | static void qmp_change_vnc_listen(const char *target, Error **errp) |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 388 | { |
Gerd Hoffmann | 4db1462 | 2014-09-16 12:33:03 +0200 | [diff] [blame] | 389 | QemuOptsList *olist = qemu_find_opts("vnc"); |
| 390 | QemuOpts *opts; |
| 391 | |
| 392 | if (strstr(target, "id=")) { |
| 393 | error_setg(errp, "id not supported"); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | opts = qemu_opts_find(olist, "default"); |
| 398 | if (opts) { |
| 399 | qemu_opts_del(opts); |
| 400 | } |
Markus Armbruster | 70b9433 | 2015-02-13 12:50:26 +0100 | [diff] [blame] | 401 | opts = vnc_parse(target, errp); |
Gonglei | f7801c5 | 2015-02-05 17:43:35 +0800 | [diff] [blame] | 402 | if (!opts) { |
| 403 | return; |
| 404 | } |
| 405 | |
Gerd Hoffmann | 4db1462 | 2014-09-16 12:33:03 +0200 | [diff] [blame] | 406 | vnc_display_open("default", errp); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, |
| 410 | Error **errp) |
| 411 | { |
| 412 | if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { |
| 413 | if (!has_arg) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 414 | error_setg(errp, QERR_MISSING_PARAMETER, "password"); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 415 | } else { |
| 416 | qmp_change_vnc_password(arg, errp); |
| 417 | } |
| 418 | } else { |
| 419 | qmp_change_vnc_listen(target, errp); |
| 420 | } |
| 421 | } |
| 422 | #else |
| 423 | void qmp_change_vnc_password(const char *password, Error **errp) |
| 424 | { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 425 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 426 | } |
| 427 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, |
| 428 | Error **errp) |
| 429 | { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 430 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 431 | } |
| 432 | #endif /* !CONFIG_VNC */ |
| 433 | |
| 434 | void qmp_change(const char *device, const char *target, |
Markus Armbruster | 7daecb3 | 2014-05-02 13:26:31 +0200 | [diff] [blame] | 435 | bool has_arg, const char *arg, Error **errp) |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 436 | { |
| 437 | if (strcmp(device, "vnc") == 0) { |
Markus Armbruster | 7daecb3 | 2014-05-02 13:26:31 +0200 | [diff] [blame] | 438 | qmp_change_vnc(target, has_arg, arg, errp); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 439 | } else { |
Kevin Wolf | 70e2cb3 | 2016-09-20 13:38:47 +0200 | [diff] [blame] | 440 | qmp_blockdev_change_medium(true, device, false, NULL, target, |
| 441 | has_arg, arg, false, 0, errp); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 442 | } |
| 443 | } |
Anthony Liguori | 5eeee3f | 2011-12-22 14:40:54 -0600 | [diff] [blame] | 444 | |
| 445 | static void qom_list_types_tramp(ObjectClass *klass, void *data) |
| 446 | { |
| 447 | ObjectTypeInfoList *e, **pret = data; |
| 448 | ObjectTypeInfo *info; |
| 449 | |
| 450 | info = g_malloc0(sizeof(*info)); |
| 451 | info->name = g_strdup(object_class_get_name(klass)); |
| 452 | |
| 453 | e = g_malloc0(sizeof(*e)); |
| 454 | e->value = info; |
| 455 | e->next = *pret; |
| 456 | *pret = e; |
| 457 | } |
| 458 | |
| 459 | ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, |
| 460 | const char *implements, |
| 461 | bool has_abstract, |
| 462 | bool abstract, |
| 463 | Error **errp) |
| 464 | { |
| 465 | ObjectTypeInfoList *ret = NULL; |
| 466 | |
| 467 | object_class_foreach(qom_list_types_tramp, implements, abstract, &ret); |
| 468 | |
| 469 | return ret; |
| 470 | } |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 471 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 472 | /* Return a DevicePropertyInfo for a qdev property. |
| 473 | * |
| 474 | * If a qdev property with the given name does not exist, use the given default |
| 475 | * type. If the qdev property info should not be shown, return NULL. |
| 476 | * |
| 477 | * The caller must free the return value. |
| 478 | */ |
| 479 | static DevicePropertyInfo *make_device_property_info(ObjectClass *klass, |
| 480 | const char *name, |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 481 | const char *default_type, |
| 482 | const char *description) |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 483 | { |
| 484 | DevicePropertyInfo *info; |
| 485 | Property *prop; |
| 486 | |
| 487 | do { |
| 488 | for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { |
| 489 | if (strcmp(name, prop->name) != 0) { |
| 490 | continue; |
| 491 | } |
| 492 | |
| 493 | /* |
| 494 | * TODO Properties without a parser are just for dirty hacks. |
| 495 | * qdev_prop_ptr is the only such PropertyInfo. It's marked |
| 496 | * for removal. This conditional should be removed along with |
| 497 | * it. |
| 498 | */ |
| 499 | if (!prop->info->set) { |
| 500 | return NULL; /* no way to set it, don't show */ |
| 501 | } |
| 502 | |
| 503 | info = g_malloc0(sizeof(*info)); |
| 504 | info->name = g_strdup(prop->name); |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 505 | info->type = g_strdup(prop->info->name); |
| 506 | info->has_description = !!prop->info->description; |
| 507 | info->description = g_strdup(prop->info->description); |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 508 | return info; |
| 509 | } |
| 510 | klass = object_class_get_parent(klass); |
| 511 | } while (klass != object_class_by_name(TYPE_DEVICE)); |
| 512 | |
| 513 | /* Not a qdev property, use the default type */ |
| 514 | info = g_malloc0(sizeof(*info)); |
| 515 | info->name = g_strdup(name); |
| 516 | info->type = g_strdup(default_type); |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 517 | info->has_description = !!description; |
| 518 | info->description = g_strdup(description); |
| 519 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 520 | return info; |
| 521 | } |
| 522 | |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 523 | DevicePropertyInfoList *qmp_device_list_properties(const char *typename, |
| 524 | Error **errp) |
| 525 | { |
| 526 | ObjectClass *klass; |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 527 | Object *obj; |
| 528 | ObjectProperty *prop; |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 529 | ObjectPropertyIterator iter; |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 530 | DevicePropertyInfoList *prop_list = NULL; |
| 531 | |
| 532 | klass = object_class_by_name(typename); |
| 533 | if (klass == NULL) { |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 534 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 535 | "Device '%s' not found", typename); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 536 | return NULL; |
| 537 | } |
| 538 | |
| 539 | klass = object_class_dynamic_cast(klass, TYPE_DEVICE); |
| 540 | if (klass == NULL) { |
Lin Ma | 7a8c153 | 2017-01-25 13:27:03 +0800 | [diff] [blame] | 541 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 542 | return NULL; |
| 543 | } |
| 544 | |
Markus Armbruster | edb1523 | 2015-10-01 10:59:57 +0200 | [diff] [blame] | 545 | if (object_class_is_abstract(klass)) { |
Lin Ma | 7a8c153 | 2017-01-25 13:27:03 +0800 | [diff] [blame] | 546 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", |
Markus Armbruster | edb1523 | 2015-10-01 10:59:57 +0200 | [diff] [blame] | 547 | "non-abstract device type"); |
| 548 | return NULL; |
| 549 | } |
| 550 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 551 | obj = object_new(typename); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 552 | |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 553 | object_property_iter_init(&iter, obj); |
| 554 | while ((prop = object_property_iter_next(&iter))) { |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 555 | DevicePropertyInfo *info; |
| 556 | DevicePropertyInfoList *entry; |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 557 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 558 | /* Skip Object and DeviceState properties */ |
| 559 | if (strcmp(prop->name, "type") == 0 || |
| 560 | strcmp(prop->name, "realized") == 0 || |
| 561 | strcmp(prop->name, "hotpluggable") == 0 || |
Stefan Hajnoczi | 4115dd6 | 2014-07-09 14:01:31 +0200 | [diff] [blame] | 562 | strcmp(prop->name, "hotplugged") == 0 || |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 563 | strcmp(prop->name, "parent_bus") == 0) { |
| 564 | continue; |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 565 | } |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 566 | |
| 567 | /* Skip legacy properties since they are just string versions of |
| 568 | * properties that we already list. |
| 569 | */ |
| 570 | if (strstart(prop->name, "legacy-", NULL)) { |
| 571 | continue; |
| 572 | } |
| 573 | |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 574 | info = make_device_property_info(klass, prop->name, prop->type, |
| 575 | prop->description); |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 576 | if (!info) { |
| 577 | continue; |
| 578 | } |
| 579 | |
| 580 | entry = g_malloc0(sizeof(*entry)); |
| 581 | entry->value = info; |
| 582 | entry->next = prop_list; |
| 583 | prop_list = entry; |
| 584 | } |
| 585 | |
| 586 | object_unref(obj); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 587 | |
| 588 | return prop_list; |
| 589 | } |
Anthony Liguori | e4e31c6 | 2012-08-10 11:04:13 -0500 | [diff] [blame] | 590 | |
Anthony Liguori | 76b64a7 | 2012-08-14 22:17:36 -0500 | [diff] [blame] | 591 | CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
| 592 | { |
| 593 | return arch_query_cpu_definitions(errp); |
| 594 | } |
| 595 | |
David Hildenbrand | e09484e | 2016-09-05 10:52:39 +0200 | [diff] [blame] | 596 | CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, |
| 597 | CpuModelInfo *model, |
| 598 | Error **errp) |
| 599 | { |
| 600 | return arch_query_cpu_model_expansion(type, model, errp); |
| 601 | } |
| 602 | |
David Hildenbrand | 0031e0d | 2016-09-05 10:52:40 +0200 | [diff] [blame] | 603 | CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela, |
| 604 | CpuModelInfo *modelb, |
| 605 | Error **errp) |
| 606 | { |
| 607 | return arch_query_cpu_model_comparison(modela, modelb, errp); |
| 608 | } |
| 609 | |
David Hildenbrand | b18b604 | 2016-09-05 10:52:41 +0200 | [diff] [blame] | 610 | CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela, |
| 611 | CpuModelInfo *modelb, |
| 612 | Error **errp) |
| 613 | { |
| 614 | return arch_query_cpu_model_baseline(modela, modelb, errp); |
| 615 | } |
| 616 | |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 617 | void qmp_add_client(const char *protocol, const char *fdname, |
| 618 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, |
| 619 | Error **errp) |
| 620 | { |
Marc-André Lureau | 0ec7b3e | 2016-12-07 16:20:22 +0300 | [diff] [blame] | 621 | Chardev *s; |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 622 | int fd; |
| 623 | |
| 624 | fd = monitor_get_fd(cur_mon, fdname, errp); |
| 625 | if (fd < 0) { |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 630 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 631 | close(fd); |
| 632 | return; |
| 633 | } |
| 634 | skipauth = has_skipauth ? skipauth : false; |
| 635 | tls = has_tls ? tls : false; |
| 636 | if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) { |
| 637 | error_setg(errp, "spice failed to add client"); |
| 638 | close(fd); |
| 639 | } |
| 640 | return; |
| 641 | #ifdef CONFIG_VNC |
| 642 | } else if (strcmp(protocol, "vnc") == 0) { |
| 643 | skipauth = has_skipauth ? skipauth : false; |
| 644 | vnc_display_add_client(NULL, fd, skipauth); |
| 645 | return; |
| 646 | #endif |
| 647 | } else if ((s = qemu_chr_find(protocol)) != NULL) { |
| 648 | if (qemu_chr_add_client(s, fd) < 0) { |
| 649 | error_setg(errp, "failed to add client"); |
| 650 | close(fd); |
| 651 | return; |
| 652 | } |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | error_setg(errp, "protocol '%s' is invalid", protocol); |
| 657 | close(fd); |
| 658 | } |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 659 | |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 660 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 661 | void qmp_object_add(const char *type, const char *id, |
| 662 | bool has_props, QObject *props, Error **errp) |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 663 | { |
Marc-André Lureau | e64c75a | 2016-09-23 00:39:25 +0400 | [diff] [blame] | 664 | QDict *pdict; |
Eric Blake | b70ce10 | 2016-06-09 10:48:38 -0600 | [diff] [blame] | 665 | Visitor *v; |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 666 | Object *obj; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 667 | |
| 668 | if (props) { |
| 669 | pdict = qobject_to_qdict(props); |
| 670 | if (!pdict) { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 671 | error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); |
| 672 | return; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 673 | } |
Marc-André Lureau | e64c75a | 2016-09-23 00:39:25 +0400 | [diff] [blame] | 674 | QINCREF(pdict); |
| 675 | } else { |
| 676 | pdict = qdict_new(); |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Markus Armbruster | 048abb7 | 2017-03-03 13:32:39 +0100 | [diff] [blame] | 679 | v = qobject_input_visitor_new(QOBJECT(pdict)); |
Eric Blake | b70ce10 | 2016-06-09 10:48:38 -0600 | [diff] [blame] | 680 | obj = user_creatable_add_type(type, id, pdict, v, errp); |
| 681 | visit_free(v); |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 682 | if (obj) { |
| 683 | object_unref(obj); |
| 684 | } |
Marc-André Lureau | e64c75a | 2016-09-23 00:39:25 +0400 | [diff] [blame] | 685 | QDECREF(pdict); |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 686 | } |
| 687 | |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 688 | void qmp_object_del(const char *id, Error **errp) |
| 689 | { |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 690 | user_creatable_del(id, errp); |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 691 | } |
Igor Mammedov | 6f2e273 | 2014-06-16 19:12:25 +0200 | [diff] [blame] | 692 | |
| 693 | MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) |
| 694 | { |
| 695 | MemoryDeviceInfoList *head = NULL; |
| 696 | MemoryDeviceInfoList **prev = &head; |
| 697 | |
| 698 | qmp_pc_dimm_device_list(qdev_get_machine(), &prev); |
| 699 | |
| 700 | return head; |
| 701 | } |
Igor Mammedov | 02419bc | 2014-06-16 19:12:28 +0200 | [diff] [blame] | 702 | |
| 703 | ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) |
| 704 | { |
| 705 | bool ambig; |
| 706 | ACPIOSTInfoList *head = NULL; |
| 707 | ACPIOSTInfoList **prev = &head; |
| 708 | Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig); |
| 709 | |
| 710 | if (obj) { |
| 711 | AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); |
| 712 | AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj); |
| 713 | |
| 714 | adevc->ospm_status(adev, &prev); |
| 715 | } else { |
| 716 | error_setg(errp, "command is not supported, missing ACPI device"); |
| 717 | } |
| 718 | |
| 719 | return head; |
| 720 | } |