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" |
Marc-André Lureau | 8228e35 | 2017-01-26 17:19:46 +0400 | [diff] [blame] | 24 | #include "chardev/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; |
Eric Blake | cf83f14 | 2017-05-15 16:41:13 -0500 | [diff] [blame] | 87 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP); |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 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 | { |
Eric Blake | cf83f14 | 2017-05-15 16:41:13 -0500 | [diff] [blame] | 108 | qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP); |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 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 | { |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 167 | BlockBackend *blk; |
Daniel P. Berrange | 788cf9f | 2017-06-23 17:24:15 +0100 | [diff] [blame] | 168 | Error *local_err = NULL; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 169 | |
Peter Xu | 65d64f3 | 2016-02-18 13:16:49 +0800 | [diff] [blame] | 170 | /* if there is a dump in background, we should wait until the dump |
| 171 | * finished */ |
| 172 | if (dump_in_progress()) { |
| 173 | error_setg(errp, "There is a dump in process, please wait."); |
| 174 | return; |
| 175 | } |
| 176 | |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 177 | if (runstate_needs_reset()) { |
Cole Robinson | f231b88 | 2014-03-21 19:42:26 -0400 | [diff] [blame] | 178 | error_setg(errp, "Resetting the Virtual Machine is required"); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 179 | return; |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 180 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
| 181 | return; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 182 | } |
| 183 | |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 184 | for (blk = blk_next(NULL); blk; blk = blk_next(blk)) { |
| 185 | blk_iostatus_reset(blk); |
Markus Armbruster | ab31979 | 2014-05-02 13:26:42 +0200 | [diff] [blame] | 186 | } |
Kevin Wolf | 7c8eece | 2016-03-22 18:58:50 +0100 | [diff] [blame] | 187 | |
Kevin Wolf | 76b1c7f | 2015-12-22 14:07:08 +0100 | [diff] [blame] | 188 | /* Continuing after completed migration. Images have been inactivated to |
Kevin Wolf | ace21a5 | 2017-05-04 18:52:36 +0200 | [diff] [blame] | 189 | * allow the destination to take control. Need to get control back now. |
| 190 | * |
| 191 | * If there are no inactive block nodes (e.g. because the VM was just |
| 192 | * paused rather than completing a migration), bdrv_inactivate_all() simply |
| 193 | * doesn't do anything. */ |
| 194 | bdrv_invalidate_cache_all(&local_err); |
| 195 | if (local_err) { |
| 196 | error_propagate(errp, local_err); |
| 197 | return; |
Kevin Wolf | 76b1c7f | 2015-12-22 14:07:08 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Paolo Bonzini | 1e99814 | 2012-10-23 14:54:21 +0200 | [diff] [blame] | 200 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 201 | autostart = 1; |
| 202 | } else { |
| 203 | vm_start(); |
| 204 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 205 | } |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 206 | |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 207 | void qmp_system_wakeup(Error **errp) |
| 208 | { |
| 209 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); |
| 210 | } |
| 211 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 212 | ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 213 | { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 214 | Object *obj; |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 215 | bool ambiguous = false; |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 216 | ObjectPropertyInfoList *props = NULL; |
| 217 | ObjectProperty *prop; |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 218 | ObjectPropertyIterator iter; |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 219 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 220 | obj = object_resolve_path(path, &ambiguous); |
| 221 | if (obj == NULL) { |
Michael Tokarev | 7977208 | 2014-05-04 12:23:59 +0400 | [diff] [blame] | 222 | if (ambiguous) { |
| 223 | error_setg(errp, "Path '%s' is ambiguous", path); |
| 224 | } else { |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 225 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 226 | "Device '%s' not found", path); |
Michael Tokarev | 7977208 | 2014-05-04 12:23:59 +0400 | [diff] [blame] | 227 | } |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
| 230 | |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 231 | object_property_iter_init(&iter, obj); |
| 232 | while ((prop = object_property_iter_next(&iter))) { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 233 | ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry)); |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 234 | |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 235 | entry->value = g_malloc0(sizeof(ObjectPropertyInfo)); |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 236 | entry->next = props; |
| 237 | props = entry; |
| 238 | |
| 239 | entry->value->name = g_strdup(prop->name); |
| 240 | entry->value->type = g_strdup(prop->type); |
| 241 | } |
| 242 | |
| 243 | return props; |
| 244 | } |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 245 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 246 | void qmp_qom_set(const char *path, const char *property, QObject *value, |
| 247 | Error **errp) |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 248 | { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 249 | 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) { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 253 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 254 | "Device '%s' not found", path); |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 255 | return; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 256 | } |
| 257 | |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 258 | object_property_set_qobject(obj, value, property, errp); |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 259 | } |
| 260 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 261 | QObject *qmp_qom_get(const char *path, const char *property, Error **errp) |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 262 | { |
Anthony Liguori | 57c9faf | 2012-01-30 08:55:55 -0600 | [diff] [blame] | 263 | Object *obj; |
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 | obj = object_resolve_path(path, NULL); |
| 266 | if (!obj) { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 267 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 268 | "Device '%s' not found", path); |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 269 | return NULL; |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 270 | } |
| 271 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 272 | return object_property_get_qobject(obj, property, errp); |
Anthony Liguori | eb6e8ea | 2011-12-12 14:29:35 -0600 | [diff] [blame] | 273 | } |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 274 | |
| 275 | void qmp_set_password(const char *protocol, const char *password, |
| 276 | bool has_connected, const char *connected, Error **errp) |
| 277 | { |
| 278 | int disconnect_if_connected = 0; |
| 279 | int fail_if_connected = 0; |
| 280 | int rc; |
| 281 | |
| 282 | if (has_connected) { |
| 283 | if (strcmp(connected, "fail") == 0) { |
| 284 | fail_if_connected = 1; |
| 285 | } else if (strcmp(connected, "disconnect") == 0) { |
| 286 | disconnect_if_connected = 1; |
| 287 | } else if (strcmp(connected, "keep") == 0) { |
| 288 | /* nothing */ |
| 289 | } else { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 290 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 296 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 297 | return; |
| 298 | } |
| 299 | rc = qemu_spice_set_passwd(password, fail_if_connected, |
| 300 | disconnect_if_connected); |
| 301 | if (rc != 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 302 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 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 */ |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 310 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 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) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 317 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 318 | } |
| 319 | return; |
| 320 | } |
| 321 | |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 322 | error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 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) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 342 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 343 | return; |
| 344 | } |
| 345 | rc = qemu_spice_set_pw_expire(when); |
| 346 | if (rc != 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 347 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 348 | } |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | if (strcmp(protocol, "vnc") == 0) { |
| 353 | rc = vnc_display_pw_expire(NULL, when); |
| 354 | if (rc != 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 355 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 356 | } |
| 357 | return; |
| 358 | } |
| 359 | |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 360 | error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 361 | } |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 362 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 363 | #ifdef CONFIG_VNC |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 364 | void qmp_change_vnc_password(const char *password, Error **errp) |
| 365 | { |
| 366 | if (vnc_display_password(NULL, password) < 0) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 367 | error_setg(errp, QERR_SET_PASSWD_FAILED); |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 368 | } |
| 369 | } |
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 | static void qmp_change_vnc_listen(const char *target, Error **errp) |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 372 | { |
Gerd Hoffmann | 4db1462 | 2014-09-16 12:33:03 +0200 | [diff] [blame] | 373 | QemuOptsList *olist = qemu_find_opts("vnc"); |
| 374 | QemuOpts *opts; |
| 375 | |
| 376 | if (strstr(target, "id=")) { |
| 377 | error_setg(errp, "id not supported"); |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | opts = qemu_opts_find(olist, "default"); |
| 382 | if (opts) { |
| 383 | qemu_opts_del(opts); |
| 384 | } |
Markus Armbruster | 70b9433 | 2015-02-13 12:50:26 +0100 | [diff] [blame] | 385 | opts = vnc_parse(target, errp); |
Gonglei | f7801c5 | 2015-02-05 17:43:35 +0800 | [diff] [blame] | 386 | if (!opts) { |
| 387 | return; |
| 388 | } |
| 389 | |
Gerd Hoffmann | 4db1462 | 2014-09-16 12:33:03 +0200 | [diff] [blame] | 390 | vnc_display_open("default", errp); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, |
| 394 | Error **errp) |
| 395 | { |
| 396 | if (strcmp(target, "passwd") == 0 || strcmp(target, "password") == 0) { |
| 397 | if (!has_arg) { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 398 | error_setg(errp, QERR_MISSING_PARAMETER, "password"); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 399 | } else { |
| 400 | qmp_change_vnc_password(arg, errp); |
| 401 | } |
| 402 | } else { |
| 403 | qmp_change_vnc_listen(target, errp); |
| 404 | } |
| 405 | } |
| 406 | #else |
| 407 | void qmp_change_vnc_password(const char *password, Error **errp) |
| 408 | { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 409 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 410 | } |
| 411 | static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, |
| 412 | Error **errp) |
| 413 | { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 414 | error_setg(errp, QERR_FEATURE_DISABLED, "vnc"); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 415 | } |
| 416 | #endif /* !CONFIG_VNC */ |
| 417 | |
| 418 | void qmp_change(const char *device, const char *target, |
Markus Armbruster | 7daecb3 | 2014-05-02 13:26:31 +0200 | [diff] [blame] | 419 | bool has_arg, const char *arg, Error **errp) |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 420 | { |
| 421 | if (strcmp(device, "vnc") == 0) { |
Markus Armbruster | 7daecb3 | 2014-05-02 13:26:31 +0200 | [diff] [blame] | 422 | qmp_change_vnc(target, has_arg, arg, errp); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 423 | } else { |
Kevin Wolf | 70e2cb3 | 2016-09-20 13:38:47 +0200 | [diff] [blame] | 424 | qmp_blockdev_change_medium(true, device, false, NULL, target, |
| 425 | has_arg, arg, false, 0, errp); |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 426 | } |
| 427 | } |
Anthony Liguori | 5eeee3f | 2011-12-22 14:40:54 -0600 | [diff] [blame] | 428 | |
| 429 | static void qom_list_types_tramp(ObjectClass *klass, void *data) |
| 430 | { |
| 431 | ObjectTypeInfoList *e, **pret = data; |
| 432 | ObjectTypeInfo *info; |
Eduardo Habkost | f86285c | 2017-07-07 09:22:15 -0300 | [diff] [blame] | 433 | ObjectClass *parent = object_class_get_parent(klass); |
Anthony Liguori | 5eeee3f | 2011-12-22 14:40:54 -0600 | [diff] [blame] | 434 | |
| 435 | info = g_malloc0(sizeof(*info)); |
| 436 | info->name = g_strdup(object_class_get_name(klass)); |
Eduardo Habkost | 87467ea | 2017-07-07 09:22:14 -0300 | [diff] [blame] | 437 | info->has_abstract = info->abstract = object_class_is_abstract(klass); |
Eduardo Habkost | f86285c | 2017-07-07 09:22:15 -0300 | [diff] [blame] | 438 | if (parent) { |
| 439 | info->has_parent = true; |
| 440 | info->parent = g_strdup(object_class_get_name(parent)); |
| 441 | } |
Anthony Liguori | 5eeee3f | 2011-12-22 14:40:54 -0600 | [diff] [blame] | 442 | |
| 443 | e = g_malloc0(sizeof(*e)); |
| 444 | e->value = info; |
| 445 | e->next = *pret; |
| 446 | *pret = e; |
| 447 | } |
| 448 | |
| 449 | ObjectTypeInfoList *qmp_qom_list_types(bool has_implements, |
| 450 | const char *implements, |
| 451 | bool has_abstract, |
| 452 | bool abstract, |
| 453 | Error **errp) |
| 454 | { |
| 455 | ObjectTypeInfoList *ret = NULL; |
| 456 | |
| 457 | object_class_foreach(qom_list_types_tramp, implements, abstract, &ret); |
| 458 | |
| 459 | return ret; |
| 460 | } |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 461 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 462 | /* Return a DevicePropertyInfo for a qdev property. |
| 463 | * |
| 464 | * If a qdev property with the given name does not exist, use the given default |
| 465 | * type. If the qdev property info should not be shown, return NULL. |
| 466 | * |
| 467 | * The caller must free the return value. |
| 468 | */ |
| 469 | static DevicePropertyInfo *make_device_property_info(ObjectClass *klass, |
| 470 | const char *name, |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 471 | const char *default_type, |
| 472 | const char *description) |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 473 | { |
| 474 | DevicePropertyInfo *info; |
| 475 | Property *prop; |
| 476 | |
| 477 | do { |
| 478 | for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) { |
| 479 | if (strcmp(name, prop->name) != 0) { |
| 480 | continue; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * TODO Properties without a parser are just for dirty hacks. |
| 485 | * qdev_prop_ptr is the only such PropertyInfo. It's marked |
| 486 | * for removal. This conditional should be removed along with |
| 487 | * it. |
| 488 | */ |
Fam Zheng | faabdbb | 2017-07-14 10:14:51 +0800 | [diff] [blame] | 489 | if (!prop->info->set && !prop->info->create) { |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 490 | return NULL; /* no way to set it, don't show */ |
| 491 | } |
| 492 | |
| 493 | info = g_malloc0(sizeof(*info)); |
| 494 | info->name = g_strdup(prop->name); |
Fam Zheng | 75ab905 | 2017-07-14 10:14:53 +0800 | [diff] [blame] | 495 | info->type = default_type ? g_strdup(default_type) |
| 496 | : g_strdup(prop->info->name); |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 497 | info->has_description = !!prop->info->description; |
| 498 | info->description = g_strdup(prop->info->description); |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 499 | return info; |
| 500 | } |
| 501 | klass = object_class_get_parent(klass); |
| 502 | } while (klass != object_class_by_name(TYPE_DEVICE)); |
| 503 | |
| 504 | /* Not a qdev property, use the default type */ |
| 505 | info = g_malloc0(sizeof(*info)); |
| 506 | info->name = g_strdup(name); |
| 507 | info->type = g_strdup(default_type); |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 508 | info->has_description = !!description; |
| 509 | info->description = g_strdup(description); |
| 510 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 511 | return info; |
| 512 | } |
| 513 | |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 514 | DevicePropertyInfoList *qmp_device_list_properties(const char *typename, |
| 515 | Error **errp) |
| 516 | { |
| 517 | ObjectClass *klass; |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 518 | Object *obj; |
| 519 | ObjectProperty *prop; |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 520 | ObjectPropertyIterator iter; |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 521 | DevicePropertyInfoList *prop_list = NULL; |
| 522 | |
| 523 | klass = object_class_by_name(typename); |
| 524 | if (klass == NULL) { |
Markus Armbruster | 75158eb | 2015-03-16 08:57:47 +0100 | [diff] [blame] | 525 | error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, |
| 526 | "Device '%s' not found", typename); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 527 | return NULL; |
| 528 | } |
| 529 | |
| 530 | klass = object_class_dynamic_cast(klass, TYPE_DEVICE); |
| 531 | if (klass == NULL) { |
Lin Ma | 7a8c153 | 2017-01-25 13:27:03 +0800 | [diff] [blame] | 532 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", TYPE_DEVICE); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 533 | return NULL; |
| 534 | } |
| 535 | |
Markus Armbruster | edb1523 | 2015-10-01 10:59:57 +0200 | [diff] [blame] | 536 | if (object_class_is_abstract(klass)) { |
Lin Ma | 7a8c153 | 2017-01-25 13:27:03 +0800 | [diff] [blame] | 537 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "typename", |
Markus Armbruster | edb1523 | 2015-10-01 10:59:57 +0200 | [diff] [blame] | 538 | "non-abstract device type"); |
| 539 | return NULL; |
| 540 | } |
| 541 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 542 | obj = object_new(typename); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 543 | |
Daniel P. Berrange | 7746abd | 2015-12-09 12:34:02 +0000 | [diff] [blame] | 544 | object_property_iter_init(&iter, obj); |
| 545 | while ((prop = object_property_iter_next(&iter))) { |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 546 | DevicePropertyInfo *info; |
| 547 | DevicePropertyInfoList *entry; |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 548 | |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 549 | /* Skip Object and DeviceState properties */ |
| 550 | if (strcmp(prop->name, "type") == 0 || |
| 551 | strcmp(prop->name, "realized") == 0 || |
| 552 | strcmp(prop->name, "hotpluggable") == 0 || |
Stefan Hajnoczi | 4115dd6 | 2014-07-09 14:01:31 +0200 | [diff] [blame] | 553 | strcmp(prop->name, "hotplugged") == 0 || |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 554 | strcmp(prop->name, "parent_bus") == 0) { |
| 555 | continue; |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 556 | } |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 557 | |
| 558 | /* Skip legacy properties since they are just string versions of |
| 559 | * properties that we already list. |
| 560 | */ |
| 561 | if (strstart(prop->name, "legacy-", NULL)) { |
| 562 | continue; |
| 563 | } |
| 564 | |
Gonglei | 07d09c5 | 2014-10-07 14:33:23 +0800 | [diff] [blame] | 565 | info = make_device_property_info(klass, prop->name, prop->type, |
| 566 | prop->description); |
Stefan Hajnoczi | f4eb32b | 2014-05-20 14:29:01 +0200 | [diff] [blame] | 567 | if (!info) { |
| 568 | continue; |
| 569 | } |
| 570 | |
| 571 | entry = g_malloc0(sizeof(*entry)); |
| 572 | entry->value = info; |
| 573 | entry->next = prop_list; |
| 574 | prop_list = entry; |
| 575 | } |
| 576 | |
| 577 | object_unref(obj); |
Anthony Liguori | 1daa31b | 2012-08-10 11:04:09 -0500 | [diff] [blame] | 578 | |
| 579 | return prop_list; |
| 580 | } |
Anthony Liguori | e4e31c6 | 2012-08-10 11:04:13 -0500 | [diff] [blame] | 581 | |
Anthony Liguori | 76b64a7 | 2012-08-14 22:17:36 -0500 | [diff] [blame] | 582 | CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
| 583 | { |
| 584 | return arch_query_cpu_definitions(errp); |
| 585 | } |
| 586 | |
David Hildenbrand | e09484e | 2016-09-05 10:52:39 +0200 | [diff] [blame] | 587 | CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type, |
| 588 | CpuModelInfo *model, |
| 589 | Error **errp) |
| 590 | { |
| 591 | return arch_query_cpu_model_expansion(type, model, errp); |
| 592 | } |
| 593 | |
David Hildenbrand | 0031e0d | 2016-09-05 10:52:40 +0200 | [diff] [blame] | 594 | CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela, |
| 595 | CpuModelInfo *modelb, |
| 596 | Error **errp) |
| 597 | { |
| 598 | return arch_query_cpu_model_comparison(modela, modelb, errp); |
| 599 | } |
| 600 | |
David Hildenbrand | b18b604 | 2016-09-05 10:52:41 +0200 | [diff] [blame] | 601 | CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela, |
| 602 | CpuModelInfo *modelb, |
| 603 | Error **errp) |
| 604 | { |
| 605 | return arch_query_cpu_model_baseline(modela, modelb, errp); |
| 606 | } |
| 607 | |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 608 | void qmp_add_client(const char *protocol, const char *fdname, |
| 609 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, |
| 610 | Error **errp) |
| 611 | { |
Marc-André Lureau | 0ec7b3e | 2016-12-07 16:20:22 +0300 | [diff] [blame] | 612 | Chardev *s; |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 613 | int fd; |
| 614 | |
| 615 | fd = monitor_get_fd(cur_mon, fdname, errp); |
| 616 | if (fd < 0) { |
| 617 | return; |
| 618 | } |
| 619 | |
| 620 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 621 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 622 | close(fd); |
| 623 | return; |
| 624 | } |
| 625 | skipauth = has_skipauth ? skipauth : false; |
| 626 | tls = has_tls ? tls : false; |
| 627 | if (qemu_spice_display_add_client(fd, skipauth, tls) < 0) { |
| 628 | error_setg(errp, "spice failed to add client"); |
| 629 | close(fd); |
| 630 | } |
| 631 | return; |
| 632 | #ifdef CONFIG_VNC |
| 633 | } else if (strcmp(protocol, "vnc") == 0) { |
| 634 | skipauth = has_skipauth ? skipauth : false; |
| 635 | vnc_display_add_client(NULL, fd, skipauth); |
| 636 | return; |
| 637 | #endif |
| 638 | } else if ((s = qemu_chr_find(protocol)) != NULL) { |
| 639 | if (qemu_chr_add_client(s, fd) < 0) { |
| 640 | error_setg(errp, "failed to add client"); |
| 641 | close(fd); |
| 642 | return; |
| 643 | } |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | error_setg(errp, "protocol '%s' is invalid", protocol); |
| 648 | close(fd); |
| 649 | } |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 650 | |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 651 | |
Markus Armbruster | 6eb3937 | 2015-09-16 13:06:25 +0200 | [diff] [blame] | 652 | void qmp_object_add(const char *type, const char *id, |
| 653 | bool has_props, QObject *props, Error **errp) |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 654 | { |
Marc-André Lureau | e64c75a | 2016-09-23 00:39:25 +0400 | [diff] [blame] | 655 | QDict *pdict; |
Eric Blake | b70ce10 | 2016-06-09 10:48:38 -0600 | [diff] [blame] | 656 | Visitor *v; |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 657 | Object *obj; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 658 | |
| 659 | if (props) { |
| 660 | pdict = qobject_to_qdict(props); |
| 661 | if (!pdict) { |
Markus Armbruster | 485febc | 2015-03-13 17:25:50 +0100 | [diff] [blame] | 662 | error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); |
| 663 | return; |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 664 | } |
Marc-André Lureau | e64c75a | 2016-09-23 00:39:25 +0400 | [diff] [blame] | 665 | QINCREF(pdict); |
| 666 | } else { |
| 667 | pdict = qdict_new(); |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 668 | } |
| 669 | |
Markus Armbruster | 048abb7 | 2017-03-03 13:32:39 +0100 | [diff] [blame] | 670 | v = qobject_input_visitor_new(QOBJECT(pdict)); |
Eric Blake | b70ce10 | 2016-06-09 10:48:38 -0600 | [diff] [blame] | 671 | obj = user_creatable_add_type(type, id, pdict, v, errp); |
| 672 | visit_free(v); |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 673 | if (obj) { |
| 674 | object_unref(obj); |
| 675 | } |
Marc-André Lureau | e64c75a | 2016-09-23 00:39:25 +0400 | [diff] [blame] | 676 | QDECREF(pdict); |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 679 | void qmp_object_del(const char *id, Error **errp) |
| 680 | { |
Daniel P. Berrange | 90998d5 | 2016-02-10 18:40:59 +0000 | [diff] [blame] | 681 | user_creatable_del(id, errp); |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 682 | } |
Igor Mammedov | 6f2e273 | 2014-06-16 19:12:25 +0200 | [diff] [blame] | 683 | |
| 684 | MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) |
| 685 | { |
| 686 | MemoryDeviceInfoList *head = NULL; |
| 687 | MemoryDeviceInfoList **prev = &head; |
| 688 | |
| 689 | qmp_pc_dimm_device_list(qdev_get_machine(), &prev); |
| 690 | |
| 691 | return head; |
| 692 | } |
Igor Mammedov | 02419bc | 2014-06-16 19:12:28 +0200 | [diff] [blame] | 693 | |
| 694 | ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) |
| 695 | { |
| 696 | bool ambig; |
| 697 | ACPIOSTInfoList *head = NULL; |
| 698 | ACPIOSTInfoList **prev = &head; |
| 699 | Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig); |
| 700 | |
| 701 | if (obj) { |
| 702 | AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); |
| 703 | AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj); |
| 704 | |
| 705 | adevc->ospm_status(adev, &prev); |
| 706 | } else { |
| 707 | error_setg(errp, "command is not supported, missing ACPI device"); |
| 708 | } |
| 709 | |
| 710 | return head; |
| 711 | } |
Vadim Galitsyn | 9aa3397 | 2017-08-29 17:30:21 +0200 | [diff] [blame] | 712 | |
| 713 | MemoryInfo *qmp_query_memory_size_summary(Error **errp) |
| 714 | { |
| 715 | MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo)); |
| 716 | |
| 717 | mem_info->base_memory = ram_size; |
| 718 | |
| 719 | mem_info->plugged_memory = get_plugged_memory_size(); |
| 720 | mem_info->has_plugged_memory = |
| 721 | mem_info->plugged_memory != (uint64_t)-1; |
| 722 | |
| 723 | return mem_info; |
| 724 | } |