Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 1 | /* |
Kevin Wolf | f1b3ccf | 2019-06-13 17:33:58 +0200 | [diff] [blame] | 2 | * QEMU Management Protocol commands |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 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" |
Markus Armbruster | a8d2532 | 2019-05-23 16:35:08 +0200 | [diff] [blame] | 17 | #include "qemu-common.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" |
Peter Maydell | fb246f0 | 2021-01-04 16:12:00 +0000 | [diff] [blame] | 26 | #include "ui/console.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 27 | #include "sysemu/kvm.h" |
Markus Armbruster | 54d3123 | 2019-08-12 07:23:59 +0200 | [diff] [blame] | 28 | #include "sysemu/runstate.h" |
Alejandro Jimenez | e6dba04 | 2020-12-11 11:52:43 -0500 | [diff] [blame] | 29 | #include "sysemu/runstate-action.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 30 | #include "sysemu/arch_init.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 31 | #include "sysemu/blockdev.h" |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 32 | #include "sysemu/block-backend.h" |
Markus Armbruster | e688df6 | 2018-02-01 12:18:31 +0100 | [diff] [blame] | 33 | #include "qapi/error.h" |
Philippe Mathieu-Daudé | 27c9188 | 2020-09-13 21:53:47 +0200 | [diff] [blame] | 34 | #include "qapi/qapi-commands-acpi.h" |
Kevin Wolf | 5a16818 | 2020-02-24 15:29:53 +0100 | [diff] [blame] | 35 | #include "qapi/qapi-commands-block.h" |
Kevin Wolf | fa4dcf5 | 2020-01-29 11:22:37 +0100 | [diff] [blame] | 36 | #include "qapi/qapi-commands-control.h" |
Markus Armbruster | 8ac25c8 | 2019-06-19 22:10:41 +0200 | [diff] [blame] | 37 | #include "qapi/qapi-commands-machine.h" |
Markus Armbruster | 112ed24 | 2018-02-26 17:13:27 -0600 | [diff] [blame] | 38 | #include "qapi/qapi-commands-misc.h" |
| 39 | #include "qapi/qapi-commands-ui.h" |
Markus Armbruster | cc7a8ea | 2015-03-17 17:22:46 +0100 | [diff] [blame] | 40 | #include "qapi/qmp/qerror.h" |
David Hildenbrand | 2cc0e2e | 2018-04-23 18:51:16 +0200 | [diff] [blame] | 41 | #include "hw/mem/memory-device.h" |
Igor Mammedov | 02419bc | 2014-06-16 19:12:28 +0200 | [diff] [blame] | 42 | #include "hw/acpi/acpi_dev_interface.h" |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 43 | |
| 44 | NameInfo *qmp_query_name(Error **errp) |
| 45 | { |
| 46 | NameInfo *info = g_malloc0(sizeof(*info)); |
| 47 | |
| 48 | if (qemu_name) { |
| 49 | info->has_name = true; |
| 50 | info->name = g_strdup(qemu_name); |
| 51 | } |
| 52 | |
| 53 | return info; |
| 54 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 55 | |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 56 | KvmInfo *qmp_query_kvm(Error **errp) |
| 57 | { |
| 58 | KvmInfo *info = g_malloc0(sizeof(*info)); |
| 59 | |
| 60 | info->enabled = kvm_enabled(); |
| 61 | info->present = kvm_available(); |
| 62 | |
| 63 | return info; |
| 64 | } |
| 65 | |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 66 | UuidInfo *qmp_query_uuid(Error **errp) |
| 67 | { |
| 68 | UuidInfo *info = g_malloc0(sizeof(*info)); |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 69 | |
Fam Zheng | 9c5ce8d | 2016-09-21 12:27:22 +0800 | [diff] [blame] | 70 | info->UUID = qemu_uuid_unparse_strdup(&qemu_uuid); |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 71 | return info; |
| 72 | } |
| 73 | |
Markus Armbruster | 7daecb3 | 2014-05-02 13:26:31 +0200 | [diff] [blame] | 74 | void qmp_quit(Error **errp) |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 75 | { |
Alejandro Jimenez | e6dba04 | 2020-12-11 11:52:43 -0500 | [diff] [blame] | 76 | shutdown_action = SHUTDOWN_ACTION_POWEROFF; |
Dominik Csapak | 9254893 | 2018-12-05 12:01:31 +0100 | [diff] [blame] | 77 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT); |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 78 | } |
| 79 | |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 80 | void qmp_stop(Error **errp) |
| 81 | { |
Peter Xu | 65d64f3 | 2016-02-18 13:16:49 +0800 | [diff] [blame] | 82 | /* if there is a dump in background, we should wait until the dump |
| 83 | * finished */ |
| 84 | if (dump_in_progress()) { |
| 85 | error_setg(errp, "There is a dump in process, please wait."); |
| 86 | return; |
| 87 | } |
| 88 | |
Paolo Bonzini | 1e99814 | 2012-10-23 14:54:21 +0200 | [diff] [blame] | 89 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 90 | autostart = 0; |
| 91 | } else { |
| 92 | vm_stop(RUN_STATE_PAUSED); |
| 93 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 94 | } |
| 95 | |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 96 | void qmp_system_reset(Error **errp) |
| 97 | { |
Dominik Csapak | 9254893 | 2018-12-05 12:01:31 +0100 | [diff] [blame] | 98 | qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET); |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 99 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 100 | |
Vladimir Sementsov-Ogievskiy | ec48595 | 2019-12-05 20:46:27 +0300 | [diff] [blame] | 101 | void qmp_system_powerdown(Error **errp) |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 102 | { |
| 103 | qemu_system_powerdown_request(); |
| 104 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 105 | |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 106 | void qmp_cont(Error **errp) |
| 107 | { |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 108 | BlockBackend *blk; |
Vladimir Sementsov-Ogievskiy | 68d00e4 | 2019-06-06 18:41:30 +0300 | [diff] [blame] | 109 | BlockJob *job; |
Daniel P. Berrange | 788cf9f | 2017-06-23 17:24:15 +0100 | [diff] [blame] | 110 | Error *local_err = NULL; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 111 | |
Peter Xu | 65d64f3 | 2016-02-18 13:16:49 +0800 | [diff] [blame] | 112 | /* if there is a dump in background, we should wait until the dump |
| 113 | * finished */ |
| 114 | if (dump_in_progress()) { |
| 115 | error_setg(errp, "There is a dump in process, please wait."); |
| 116 | return; |
| 117 | } |
| 118 | |
Hu Tao | ede085b | 2013-04-26 11:24:40 +0800 | [diff] [blame] | 119 | if (runstate_needs_reset()) { |
Cole Robinson | f231b88 | 2014-03-21 19:42:26 -0400 | [diff] [blame] | 120 | error_setg(errp, "Resetting the Virtual Machine is required"); |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 121 | return; |
Luiz Capitulino | ad02b96 | 2012-04-27 13:33:36 -0300 | [diff] [blame] | 122 | } else if (runstate_check(RUN_STATE_SUSPENDED)) { |
| 123 | return; |
Vladimir Sementsov-Ogievskiy | 9183dd1 | 2019-01-24 15:25:24 +0300 | [diff] [blame] | 124 | } else if (runstate_check(RUN_STATE_FINISH_MIGRATE)) { |
| 125 | error_setg(errp, "Migration is not finalized yet"); |
| 126 | return; |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 127 | } |
| 128 | |
Max Reitz | 373340b | 2015-10-19 17:53:22 +0200 | [diff] [blame] | 129 | for (blk = blk_next(NULL); blk; blk = blk_next(blk)) { |
| 130 | blk_iostatus_reset(blk); |
Markus Armbruster | ab31979 | 2014-05-02 13:26:42 +0200 | [diff] [blame] | 131 | } |
Kevin Wolf | 7c8eece | 2016-03-22 18:58:50 +0100 | [diff] [blame] | 132 | |
Vladimir Sementsov-Ogievskiy | 68d00e4 | 2019-06-06 18:41:30 +0300 | [diff] [blame] | 133 | for (job = block_job_next(NULL); job; job = block_job_next(job)) { |
| 134 | block_job_iostatus_reset(job); |
| 135 | } |
| 136 | |
Kevin Wolf | 76b1c7f | 2015-12-22 14:07:08 +0100 | [diff] [blame] | 137 | /* Continuing after completed migration. Images have been inactivated to |
Kevin Wolf | ace21a5 | 2017-05-04 18:52:36 +0200 | [diff] [blame] | 138 | * allow the destination to take control. Need to get control back now. |
| 139 | * |
| 140 | * If there are no inactive block nodes (e.g. because the VM was just |
| 141 | * paused rather than completing a migration), bdrv_inactivate_all() simply |
| 142 | * doesn't do anything. */ |
| 143 | bdrv_invalidate_cache_all(&local_err); |
| 144 | if (local_err) { |
| 145 | error_propagate(errp, local_err); |
| 146 | return; |
Kevin Wolf | 76b1c7f | 2015-12-22 14:07:08 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Paolo Bonzini | 1e99814 | 2012-10-23 14:54:21 +0200 | [diff] [blame] | 149 | if (runstate_check(RUN_STATE_INMIGRATE)) { |
| 150 | autostart = 1; |
| 151 | } else { |
| 152 | vm_start(); |
| 153 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 154 | } |
Anthony Liguori | b4b12c6 | 2011-12-12 14:29:34 -0600 | [diff] [blame] | 155 | |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 156 | void qmp_system_wakeup(Error **errp) |
| 157 | { |
Daniel Henrique Barboza | fb06411 | 2018-12-05 17:47:01 -0200 | [diff] [blame] | 158 | if (!qemu_wakeup_suspend_enabled()) { |
| 159 | error_setg(errp, |
| 160 | "wake-up from suspend is not supported by this guest"); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER, errp); |
Gerd Hoffmann | 9b9df25 | 2012-02-23 13:45:21 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 167 | void qmp_set_password(const char *protocol, const char *password, |
| 168 | bool has_connected, const char *connected, Error **errp) |
| 169 | { |
| 170 | int disconnect_if_connected = 0; |
| 171 | int fail_if_connected = 0; |
| 172 | int rc; |
| 173 | |
| 174 | if (has_connected) { |
| 175 | if (strcmp(connected, "fail") == 0) { |
| 176 | fail_if_connected = 1; |
| 177 | } else if (strcmp(connected, "disconnect") == 0) { |
| 178 | disconnect_if_connected = 1; |
| 179 | } else if (strcmp(connected, "keep") == 0) { |
| 180 | /* nothing */ |
| 181 | } else { |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 182 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 183 | return; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 188 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 189 | return; |
| 190 | } |
Gerd Hoffmann | 08ad262 | 2020-10-19 09:52:16 +0200 | [diff] [blame] | 191 | rc = qemu_spice.set_passwd(password, fail_if_connected, |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 192 | disconnect_if_connected); |
Markus Armbruster | 9272186 | 2020-11-13 09:26:20 +0100 | [diff] [blame] | 193 | } else if (strcmp(protocol, "vnc") == 0) { |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 194 | if (fail_if_connected || disconnect_if_connected) { |
| 195 | /* vnc supports "connected=keep" only */ |
Markus Armbruster | c6bd8c7 | 2015-03-17 11:54:50 +0100 | [diff] [blame] | 196 | error_setg(errp, QERR_INVALID_PARAMETER, "connected"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 197 | return; |
| 198 | } |
| 199 | /* Note that setting an empty password will not disable login through |
| 200 | * this interface. */ |
| 201 | rc = vnc_display_password(NULL, password); |
Markus Armbruster | 9272186 | 2020-11-13 09:26:20 +0100 | [diff] [blame] | 202 | } else { |
| 203 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", |
| 204 | "'vnc' or 'spice'"); |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 205 | return; |
| 206 | } |
| 207 | |
Markus Armbruster | 9272186 | 2020-11-13 09:26:20 +0100 | [diff] [blame] | 208 | if (rc != 0) { |
| 209 | error_setg(errp, "Could not set password"); |
| 210 | } |
Luiz Capitulino | fbf796f | 2011-12-07 11:17:51 -0200 | [diff] [blame] | 211 | } |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 212 | |
| 213 | void qmp_expire_password(const char *protocol, const char *whenstr, |
| 214 | Error **errp) |
| 215 | { |
| 216 | time_t when; |
| 217 | int rc; |
| 218 | |
| 219 | if (strcmp(whenstr, "now") == 0) { |
| 220 | when = 0; |
| 221 | } else if (strcmp(whenstr, "never") == 0) { |
| 222 | when = TIME_MAX; |
| 223 | } else if (whenstr[0] == '+') { |
| 224 | when = time(NULL) + strtoull(whenstr+1, NULL, 10); |
| 225 | } else { |
| 226 | when = strtoull(whenstr, NULL, 10); |
| 227 | } |
| 228 | |
| 229 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 230 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 231 | return; |
| 232 | } |
Gerd Hoffmann | 08ad262 | 2020-10-19 09:52:16 +0200 | [diff] [blame] | 233 | rc = qemu_spice.set_pw_expire(when); |
Markus Armbruster | 9272186 | 2020-11-13 09:26:20 +0100 | [diff] [blame] | 234 | } else if (strcmp(protocol, "vnc") == 0) { |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 235 | rc = vnc_display_pw_expire(NULL, when); |
Markus Armbruster | 9272186 | 2020-11-13 09:26:20 +0100 | [diff] [blame] | 236 | } else { |
| 237 | error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol", |
| 238 | "'vnc' or 'spice'"); |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 239 | return; |
| 240 | } |
| 241 | |
Markus Armbruster | 9272186 | 2020-11-13 09:26:20 +0100 | [diff] [blame] | 242 | if (rc != 0) { |
| 243 | error_setg(errp, "Could not set password expire time"); |
| 244 | } |
Luiz Capitulino | 9ad5372 | 2011-12-07 11:47:57 -0200 | [diff] [blame] | 245 | } |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 246 | |
Luiz Capitulino | 333a96e | 2011-12-08 11:13:50 -0200 | [diff] [blame] | 247 | #ifdef CONFIG_VNC |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 248 | void qmp_change_vnc_password(const char *password, Error **errp) |
| 249 | { |
| 250 | if (vnc_display_password(NULL, password) < 0) { |
Markus Armbruster | 9272186 | 2020-11-13 09:26:20 +0100 | [diff] [blame] | 251 | error_setg(errp, "Could not set password"); |
Luiz Capitulino | 270b243 | 2011-12-08 11:45:55 -0200 | [diff] [blame] | 252 | } |
| 253 | } |
Marc-André Lureau | 05eb4a2 | 2018-07-03 17:56:47 +0200 | [diff] [blame] | 254 | #endif |
Anthony Liguori | 5eeee3f | 2011-12-22 14:40:54 -0600 | [diff] [blame] | 255 | |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 256 | void qmp_add_client(const char *protocol, const char *fdname, |
| 257 | bool has_skipauth, bool skipauth, bool has_tls, bool tls, |
| 258 | Error **errp) |
| 259 | { |
Marc-André Lureau | 0ec7b3e | 2016-12-07 16:20:22 +0300 | [diff] [blame] | 260 | Chardev *s; |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 261 | int fd; |
| 262 | |
Kevin Wolf | 947e474 | 2020-10-05 17:58:44 +0200 | [diff] [blame] | 263 | fd = monitor_get_fd(monitor_cur(), fdname, errp); |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 264 | if (fd < 0) { |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | if (strcmp(protocol, "spice") == 0) { |
Markus Armbruster | b25d81b | 2015-01-13 17:07:15 +0100 | [diff] [blame] | 269 | if (!qemu_using_spice(errp)) { |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 270 | close(fd); |
| 271 | return; |
| 272 | } |
| 273 | skipauth = has_skipauth ? skipauth : false; |
| 274 | tls = has_tls ? tls : false; |
Gerd Hoffmann | 864a024 | 2020-10-19 09:52:17 +0200 | [diff] [blame] | 275 | if (qemu_spice.display_add_client(fd, skipauth, tls) < 0) { |
Luiz Capitulino | b224e5e | 2012-09-13 16:52:20 -0300 | [diff] [blame] | 276 | error_setg(errp, "spice failed to add client"); |
| 277 | close(fd); |
| 278 | } |
| 279 | return; |
| 280 | #ifdef CONFIG_VNC |
| 281 | } else if (strcmp(protocol, "vnc") == 0) { |
| 282 | skipauth = has_skipauth ? skipauth : false; |
| 283 | vnc_display_add_client(NULL, fd, skipauth); |
| 284 | return; |
| 285 | #endif |
| 286 | } else if ((s = qemu_chr_find(protocol)) != NULL) { |
| 287 | if (qemu_chr_add_client(s, fd) < 0) { |
| 288 | error_setg(errp, "failed to add client"); |
| 289 | close(fd); |
| 290 | return; |
| 291 | } |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | error_setg(errp, "protocol '%s' is invalid", protocol); |
| 296 | close(fd); |
| 297 | } |
Paolo Bonzini | ab2d053 | 2013-12-20 23:21:09 +0100 | [diff] [blame] | 298 | |
Paolo Bonzini | cff8b2c | 2013-12-20 23:21:10 +0100 | [diff] [blame] | 299 | |
Igor Mammedov | 6f2e273 | 2014-06-16 19:12:25 +0200 | [diff] [blame] | 300 | MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp) |
| 301 | { |
David Hildenbrand | 2cc0e2e | 2018-04-23 18:51:16 +0200 | [diff] [blame] | 302 | return qmp_memory_device_list(); |
Igor Mammedov | 6f2e273 | 2014-06-16 19:12:25 +0200 | [diff] [blame] | 303 | } |
Igor Mammedov | 02419bc | 2014-06-16 19:12:28 +0200 | [diff] [blame] | 304 | |
| 305 | ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) |
| 306 | { |
| 307 | bool ambig; |
| 308 | ACPIOSTInfoList *head = NULL; |
| 309 | ACPIOSTInfoList **prev = &head; |
| 310 | Object *obj = object_resolve_path_type("", TYPE_ACPI_DEVICE_IF, &ambig); |
| 311 | |
| 312 | if (obj) { |
| 313 | AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj); |
| 314 | AcpiDeviceIf *adev = ACPI_DEVICE_IF(obj); |
| 315 | |
| 316 | adevc->ospm_status(adev, &prev); |
| 317 | } else { |
| 318 | error_setg(errp, "command is not supported, missing ACPI device"); |
| 319 | } |
| 320 | |
| 321 | return head; |
| 322 | } |
Vadim Galitsyn | 9aa3397 | 2017-08-29 17:30:21 +0200 | [diff] [blame] | 323 | |
| 324 | MemoryInfo *qmp_query_memory_size_summary(Error **errp) |
| 325 | { |
| 326 | MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo)); |
Paolo Bonzini | b326b6e | 2020-10-28 06:24:22 -0400 | [diff] [blame] | 327 | MachineState *ms = MACHINE(qdev_get_machine()); |
Vadim Galitsyn | 9aa3397 | 2017-08-29 17:30:21 +0200 | [diff] [blame] | 328 | |
Paolo Bonzini | b326b6e | 2020-10-28 06:24:22 -0400 | [diff] [blame] | 329 | mem_info->base_memory = ms->ram_size; |
Vadim Galitsyn | 9aa3397 | 2017-08-29 17:30:21 +0200 | [diff] [blame] | 330 | |
| 331 | mem_info->plugged_memory = get_plugged_memory_size(); |
| 332 | mem_info->has_plugged_memory = |
| 333 | mem_info->plugged_memory != (uint64_t)-1; |
| 334 | |
| 335 | return mem_info; |
| 336 | } |