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