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