blob: 30313858c2ceac205b98921bddcdbd81c6ab9d20 [file] [log] [blame]
Anthony Liguori48a32be2011-09-02 12:34:48 -05001/*
Kevin Wolff1b3ccf2019-06-13 17:33:58 +02002 * Human Monitor Interface commands
Anthony Liguori48a32be2011-09-02 12:34:48 -05003 *
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 Bonzini6b620ca2012-01-13 17:44:23 +010012 * 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 Liguori48a32be2011-09-02 12:34:48 -050014 */
15
Peter Maydelld38ea872016-01-29 17:50:05 +000016#include "qemu/osdep.h"
Markus Armbruster275307a2019-06-19 22:10:36 +020017#include "monitor/hmp.h"
Paolo Bonzini1422e322012-10-24 08:43:34 +020018#include "net/net.h"
Scott Feldmanfafa4d52015-06-10 18:21:21 -070019#include "net/eth.h"
Marc-André Lureau8228e352017-01-26 17:19:46 +040020#include "chardev/char.h"
Max Reitz4c7b7e92015-02-05 13:58:22 -050021#include "sysemu/block-backend.h"
Markus Armbruster54d31232019-08-12 07:23:59 +020022#include "sysemu/runstate.h"
Marc-André Lureau213dcb02016-12-12 20:22:24 +030023#include "qemu/config-file.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010024#include "qemu/option.h"
25#include "qemu/timer.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010026#include "qemu/sockets.h"
Kevin Wolf5bce3082019-06-13 17:33:59 +020027#include "monitor/monitor-internal.h"
Markus Armbrustere688df62018-02-01 12:18:31 +010028#include "qapi/error.h"
Dr. David Alan Gilbert08528272019-06-20 19:47:03 +010029#include "qapi/clone-visitor.h"
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +010030#include "qapi/opts-visitor.h"
Markus Armbrustereb815e22018-02-11 10:36:05 +010031#include "qapi/qapi-builtin-visit.h"
Markus Armbruster112ed242018-02-26 17:13:27 -060032#include "qapi/qapi-commands-block.h"
33#include "qapi/qapi-commands-char.h"
Kevin Wolffa4dcf52020-01-29 11:22:37 +010034#include "qapi/qapi-commands-control.h"
Markus Armbruster112ed242018-02-26 17:13:27 -060035#include "qapi/qapi-commands-migration.h"
36#include "qapi/qapi-commands-misc.h"
37#include "qapi/qapi-commands-net.h"
38#include "qapi/qapi-commands-rocker.h"
39#include "qapi/qapi-commands-run-state.h"
40#include "qapi/qapi-commands-tpm.h"
41#include "qapi/qapi-commands-ui.h"
Dr. David Alan Gilbert08528272019-06-20 19:47:03 +010042#include "qapi/qapi-visit-net.h"
Juan Quintela96eef042019-01-16 10:35:55 +010043#include "qapi/qapi-visit-migration.h"
Markus Armbruster452fcdb2018-02-01 12:18:39 +010044#include "qapi/qmp/qdict.h"
Markus Armbrustercc7a8ea2015-03-17 17:22:46 +010045#include "qapi/qmp/qerror.h"
Juan Quintelaf4a06d12017-05-16 11:37:45 +020046#include "qapi/string-input-visitor.h"
Hu Taoeb1539b2014-05-14 17:43:35 +080047#include "qapi/string-output-visitor.h"
Daniel P. Berrange90998d52016-02-10 18:40:59 +000048#include "qom/object_interfaces.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010049#include "ui/console.h"
Markus Armbrusterbd269eb2017-04-26 09:36:41 +020050#include "block/nbd.h"
Wenchao Xiabd093a32013-06-06 12:28:00 +080051#include "block/qapi.h"
Kevin Wolf587da2c2013-06-05 14:19:41 +020052#include "qemu-io.h"
Veronia Bahaaf348b6d2016-03-20 19:16:19 +020053#include "qemu/cutils.h"
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +010054#include "qemu/error-report.h"
Peter Xube9b23c2017-05-12 12:17:41 +080055#include "exec/ramlist.h"
Hervé Poussineau61b97832016-09-26 22:23:27 +020056#include "hw/intc/intc.h"
Yuval Shaiaf4b2c022019-03-11 03:29:09 -070057#include "hw/rdma/rdma.h"
Juan Quintela5e224792017-04-20 14:25:55 +020058#include "migration/snapshot.h"
Peter Xu9d18af92017-06-27 12:10:19 +080059#include "migration/misc.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050060
Cole Robinson22fa7da2015-03-01 09:29:18 -050061#ifdef CONFIG_SPICE
62#include <spice/enums.h>
63#endif
64
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +030065void hmp_handle_error(Monitor *mon, Error *err)
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020066{
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +030067 if (err) {
68 error_reportf_err(err, "Error: ");
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020069 }
70}
71
Dr. David Alan Gilbert08528272019-06-20 19:47:03 +010072/*
73 * Produce a strList from a comma separated list.
74 * A NULL or empty input string return NULL.
75 */
76static strList *strList_from_comma_list(const char *in)
77{
78 strList *res = NULL;
79 strList **hook = &res;
80
81 while (in && in[0]) {
82 char *comma = strchr(in, ',');
83 *hook = g_new0(strList, 1);
84
85 if (comma) {
86 (*hook)->value = g_strndup(in, comma - in);
87 in = comma + 1; /* skip the , */
88 } else {
89 (*hook)->value = g_strdup(in);
90 in = NULL;
91 }
92 hook = &(*hook)->next;
93 }
94
95 return res;
96}
97
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080098void hmp_info_name(Monitor *mon, const QDict *qdict)
Anthony Liguori48a32be2011-09-02 12:34:48 -050099{
100 NameInfo *info;
101
102 info = qmp_query_name(NULL);
103 if (info->has_name) {
104 monitor_printf(mon, "%s\n", info->name);
105 }
106 qapi_free_NameInfo(info);
107}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -0300108
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800109void hmp_info_version(Monitor *mon, const QDict *qdict)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -0300110{
111 VersionInfo *info;
112
113 info = qmp_query_version(NULL);
114
115 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
Eric Blake4752cdb2015-05-04 09:05:31 -0600116 info->qemu->major, info->qemu->minor, info->qemu->micro,
Luiz Capitulinob9c15f12011-08-26 17:38:13 -0300117 info->package);
118
119 qapi_free_VersionInfo(info);
120}
Luiz Capitulino292a2602011-09-12 15:10:53 -0300121
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800122void hmp_info_kvm(Monitor *mon, const QDict *qdict)
Luiz Capitulino292a2602011-09-12 15:10:53 -0300123{
124 KvmInfo *info;
125
126 info = qmp_query_kvm(NULL);
127 monitor_printf(mon, "kvm support: ");
128 if (info->present) {
129 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
130 } else {
131 monitor_printf(mon, "not compiled\n");
132 }
133
134 qapi_free_KvmInfo(info);
135}
136
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800137void hmp_info_status(Monitor *mon, const QDict *qdict)
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300138{
139 StatusInfo *info;
140
141 info = qmp_query_status(NULL);
142
143 monitor_printf(mon, "VM status: %s%s",
144 info->running ? "running" : "paused",
145 info->singlestep ? " (single step mode)" : "");
146
147 if (!info->running && info->status != RUN_STATE_PAUSED) {
Markus Armbruster977c7362017-08-24 10:46:08 +0200148 monitor_printf(mon, " (%s)", RunState_str(info->status));
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300149 }
150
151 monitor_printf(mon, "\n");
152
153 qapi_free_StatusInfo(info);
154}
155
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800156void hmp_info_uuid(Monitor *mon, const QDict *qdict)
Luiz Capitulinoefab7672011-09-13 17:16:25 -0300157{
158 UuidInfo *info;
159
160 info = qmp_query_uuid(NULL);
161 monitor_printf(mon, "%s\n", info->UUID);
162 qapi_free_UuidInfo(info);
163}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300164
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800165void hmp_info_chardev(Monitor *mon, const QDict *qdict)
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300166{
167 ChardevInfoList *char_info, *info;
168
169 char_info = qmp_query_chardev(NULL);
170 for (info = char_info; info; info = info->next) {
171 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
172 info->value->filename);
173 }
174
175 qapi_free_ChardevInfoList(char_info);
176}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300177
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800178void hmp_info_mice(Monitor *mon, const QDict *qdict)
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300179{
180 MouseInfoList *mice_list, *mouse;
181
182 mice_list = qmp_query_mice(NULL);
183 if (!mice_list) {
184 monitor_printf(mon, "No mouse devices connected\n");
185 return;
186 }
187
188 for (mouse = mice_list; mouse; mouse = mouse->next) {
189 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
190 mouse->value->current ? '*' : ' ',
191 mouse->value->index, mouse->value->name,
192 mouse->value->absolute ? " (absolute)" : "");
193 }
194
195 qapi_free_MouseInfoList(mice_list);
196}
197
Juan Quintela9aca82b2019-02-27 11:51:27 +0100198static char *SocketAddress_to_str(SocketAddress *addr)
199{
200 switch (addr->type) {
201 case SOCKET_ADDRESS_TYPE_INET:
202 return g_strdup_printf("tcp:%s:%s",
203 addr->u.inet.host,
204 addr->u.inet.port);
205 case SOCKET_ADDRESS_TYPE_UNIX:
206 return g_strdup_printf("unix:%s",
207 addr->u.q_unix.path);
208 case SOCKET_ADDRESS_TYPE_FD:
209 return g_strdup_printf("fd:%s", addr->u.fd.str);
210 case SOCKET_ADDRESS_TYPE_VSOCK:
211 return g_strdup_printf("tcp:%s:%s",
212 addr->u.vsock.cid,
213 addr->u.vsock.port);
214 default:
215 return g_strdup("unknown address type");
216 }
217}
218
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800219void hmp_info_migrate(Monitor *mon, const QDict *qdict)
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300220{
221 MigrationInfo *info;
222
223 info = qmp_query_migrate(NULL);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300224
Peter Xu9d18af92017-06-27 12:10:19 +0800225 migration_global_dump(mon);
226
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300227 if (info->has_status) {
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +0100228 monitor_printf(mon, "Migration status: %s",
Markus Armbruster977c7362017-08-24 10:46:08 +0200229 MigrationStatus_str(info->status));
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +0100230 if (info->status == MIGRATION_STATUS_FAILED &&
231 info->has_error_desc) {
232 monitor_printf(mon, " (%s)\n", info->error_desc);
233 } else {
234 monitor_printf(mon, "\n");
235 }
236
Juan Quintela7aa939a2012-08-18 13:17:10 +0200237 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
238 info->total_time);
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200239 if (info->has_expected_downtime) {
240 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
241 info->expected_downtime);
242 }
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200243 if (info->has_downtime) {
244 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
245 info->downtime);
246 }
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400247 if (info->has_setup_time) {
248 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
249 info->setup_time);
250 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300251 }
252
253 if (info->has_ram) {
254 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
255 info->ram->transferred >> 10);
Michael R. Hines7e114f82013-06-25 21:35:30 -0400256 monitor_printf(mon, "throughput: %0.2f mbps\n",
257 info->ram->mbps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300258 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
259 info->ram->remaining >> 10);
260 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
261 info->ram->total >> 10);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300262 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
263 info->ram->duplicate);
Peter Lievenf1c72792013-03-26 10:58:37 +0100264 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
265 info->ram->skipped);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300266 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
267 info->ram->normal);
268 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
269 info->ram->normal_bytes >> 10);
ChenLiang58570ed2014-04-04 17:57:55 +0800270 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
271 info->ram->dirty_sync_count);
Chao Fan030ce1f2017-03-21 10:22:43 +0800272 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
273 info->ram->page_size >> 10);
Juan Quintelaa61c45b2018-06-26 15:20:11 +0200274 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
275 info->ram->multifd_bytes >> 10);
Xiao Guangrongaecbfe92019-01-11 14:37:30 +0800276 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
277 info->ram->pages_per_second);
Chao Fan030ce1f2017-03-21 10:22:43 +0800278
Juan Quintela8d017192012-08-13 12:31:25 +0200279 if (info->ram->dirty_pages_rate) {
280 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
281 info->ram->dirty_pages_rate);
282 }
Dr. David Alan Gilbertd3bf5412016-06-13 12:16:42 +0100283 if (info->ram->postcopy_requests) {
284 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
285 info->ram->postcopy_requests);
286 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300287 }
288
289 if (info->has_disk) {
290 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
291 info->disk->transferred >> 10);
292 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
293 info->disk->remaining >> 10);
294 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
295 info->disk->total >> 10);
296 }
297
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300298 if (info->has_xbzrle_cache) {
299 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
300 info->xbzrle_cache->cache_size);
301 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
302 info->xbzrle_cache->bytes >> 10);
303 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
304 info->xbzrle_cache->pages);
305 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
306 info->xbzrle_cache->cache_miss);
ChenLiang8bc39232014-04-04 17:57:56 +0800307 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
308 info->xbzrle_cache->cache_miss_rate);
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300309 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
310 info->xbzrle_cache->overflow);
311 }
312
Xiao Guangrong76e03002018-09-06 15:01:00 +0800313 if (info->has_compression) {
314 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
315 info->compression->pages);
316 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
317 info->compression->busy);
318 monitor_printf(mon, "compression busy rate: %0.2f\n",
319 info->compression->busy_rate);
320 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
321 info->compression->compressed_size);
322 monitor_printf(mon, "compression rate: %0.2f\n",
323 info->compression->compression_rate);
324 }
325
Jason J. Herned85a31d2016-04-21 14:07:18 -0400326 if (info->has_cpu_throttle_percentage) {
Jason J. Herne47828932015-09-08 13:12:36 -0400327 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
Jason J. Herned85a31d2016-04-21 14:07:18 -0400328 info->cpu_throttle_percentage);
Jason J. Herne47828932015-09-08 13:12:36 -0400329 }
330
Alexey Perevalov65ace062018-03-22 21:17:27 +0300331 if (info->has_postcopy_blocktime) {
332 monitor_printf(mon, "postcopy blocktime: %u\n",
333 info->postcopy_blocktime);
334 }
335
336 if (info->has_postcopy_vcpu_blocktime) {
337 Visitor *v;
338 char *str;
339 v = string_output_visitor_new(false, &str);
340 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
341 visit_complete(v, &str);
342 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
343 g_free(str);
344 visit_free(v);
345 }
Juan Quintela9aca82b2019-02-27 11:51:27 +0100346 if (info->has_socket_address) {
347 SocketAddressList *addr;
348
349 monitor_printf(mon, "socket address: [\n");
350
351 for (addr = info->socket_address; addr; addr = addr->next) {
352 char *s = SocketAddress_to_str(addr->value);
353 monitor_printf(mon, "\t%s\n", s);
354 g_free(s);
355 }
356 monitor_printf(mon, "]\n");
357 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300358 qapi_free_MigrationInfo(info);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300359}
360
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800361void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300362{
363 MigrationCapabilityStatusList *caps, *cap;
364
365 caps = qmp_query_migrate_capabilities(NULL);
366
367 if (caps) {
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300368 for (cap = caps; cap; cap = cap->next) {
Peter Xud80a0162017-04-01 16:18:44 +0800369 monitor_printf(mon, "%s: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200370 MigrationCapability_str(cap->value->capability),
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300371 cap->value->state ? "on" : "off");
372 }
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300373 }
374
375 qapi_free_MigrationCapabilityStatusList(caps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300376}
377
Liang Li50e9a622015-03-23 16:32:29 +0800378void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
379{
380 MigrationParameters *params;
381
382 params = qmp_query_migrate_parameters(NULL);
383
384 if (params) {
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +0000385 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
386 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
387 params->announce_initial);
388 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
389 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
390 params->announce_max);
391 monitor_printf(mon, "%s: %" PRIu64 "\n",
392 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
393 params->announce_rounds);
394 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
395 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
396 params->announce_step);
Eric Blakede63ab62016-09-08 22:14:15 -0500397 assert(params->has_compress_level);
Juan Quintela741d4082017-12-01 13:08:38 +0100398 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200399 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
Liang Li50e9a622015-03-23 16:32:29 +0800400 params->compress_level);
Eric Blakede63ab62016-09-08 22:14:15 -0500401 assert(params->has_compress_threads);
Juan Quintela741d4082017-12-01 13:08:38 +0100402 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200403 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
Liang Li50e9a622015-03-23 16:32:29 +0800404 params->compress_threads);
Xiao Guangrong1d588722018-08-21 16:10:20 +0800405 assert(params->has_compress_wait_thread);
406 monitor_printf(mon, "%s: %s\n",
407 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
408 params->compress_wait_thread ? "on" : "off");
Eric Blakede63ab62016-09-08 22:14:15 -0500409 assert(params->has_decompress_threads);
Juan Quintela741d4082017-12-01 13:08:38 +0100410 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200411 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
Liang Li50e9a622015-03-23 16:32:29 +0800412 params->decompress_threads);
Eric Blakede63ab62016-09-08 22:14:15 -0500413 assert(params->has_cpu_throttle_initial);
Juan Quintela741d4082017-12-01 13:08:38 +0100414 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200415 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
Jason J. Herned85a31d2016-04-21 14:07:18 -0400416 params->cpu_throttle_initial);
Eric Blakede63ab62016-09-08 22:14:15 -0500417 assert(params->has_cpu_throttle_increment);
Juan Quintela741d4082017-12-01 13:08:38 +0100418 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200419 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
Jason J. Herned85a31d2016-04-21 14:07:18 -0400420 params->cpu_throttle_increment);
Li Qiang4cbc9c72018-08-01 06:00:20 -0700421 assert(params->has_max_cpu_throttle);
422 monitor_printf(mon, "%s: %u\n",
423 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
424 params->max_cpu_throttle);
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200425 assert(params->has_tls_creds);
Peter Xu2c024682017-04-01 16:18:45 +0800426 monitor_printf(mon, "%s: '%s'\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200427 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200428 params->tls_creds);
429 assert(params->has_tls_hostname);
Peter Xu2c024682017-04-01 16:18:45 +0800430 monitor_printf(mon, "%s: '%s'\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200431 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200432 params->tls_hostname);
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530433 assert(params->has_max_bandwidth);
Juan Quintela741d4082017-12-01 13:08:38 +0100434 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200435 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530436 params->max_bandwidth);
437 assert(params->has_downtime_limit);
Juan Quintela741d4082017-12-01 13:08:38 +0100438 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200439 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530440 params->downtime_limit);
zhanghailiangfe39a4d2016-11-02 15:42:09 +0800441 assert(params->has_x_checkpoint_delay);
Juan Quintela741d4082017-12-01 13:08:38 +0100442 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200443 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
zhanghailiang68b53592016-10-27 14:43:01 +0800444 params->x_checkpoint_delay);
Juan Quintela2833c592017-04-05 18:32:37 +0200445 assert(params->has_block_incremental);
446 monitor_printf(mon, "%s: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200447 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
448 params->block_incremental ? "on" : "off");
Juan Quintela741d4082017-12-01 13:08:38 +0100449 monitor_printf(mon, "%s: %u\n",
Juan Quintelacbfd6c92019-02-06 13:54:06 +0100450 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
451 params->multifd_channels);
Juan Quintela96eef042019-01-16 10:35:55 +0100452 monitor_printf(mon, "%s: %s\n",
453 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
454 MultiFDCompression_str(params->multifd_compression));
Juan Quintela741d4082017-12-01 13:08:38 +0100455 monitor_printf(mon, "%s: %" PRIu64 "\n",
Juan Quintela73af8dd2017-10-05 21:30:10 +0200456 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
457 params->xbzrle_cache_size);
Dr. David Alan Gilbert7e555c62018-06-13 11:26:40 +0100458 monitor_printf(mon, "%s: %" PRIu64 "\n",
459 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
460 params->max_postcopy_bandwidth);
Daniel P. Berranged2f1d292019-02-27 14:53:24 +0000461 monitor_printf(mon, " %s: '%s'\n",
462 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
463 params->has_tls_authz ? params->tls_authz : "");
Liang Li50e9a622015-03-23 16:32:29 +0800464 }
465
466 qapi_free_MigrationParameters(params);
467}
468
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800469void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300470{
471 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
472 qmp_query_migrate_cache_size(NULL) >> 10);
473}
474
Kevin Wolf289b2762014-09-15 12:06:39 +0200475static void print_block_info(Monitor *mon, BlockInfo *info,
476 BlockDeviceInfo *inserted, bool verbose)
477{
478 ImageInfo *image_info;
479
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200480 assert(!info || !info->has_inserted || info->inserted == inserted);
481
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200482 if (info && *info->device) {
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200483 monitor_printf(mon, "%s", info->device);
484 if (inserted && inserted->has_node_name) {
485 monitor_printf(mon, " (%s)", inserted->node_name);
486 }
487 } else {
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200488 assert(info || inserted);
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200489 monitor_printf(mon, "%s",
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200490 inserted && inserted->has_node_name ? inserted->node_name
491 : info && info->has_qdev ? info->qdev
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200492 : "<anonymous>");
493 }
494
Kevin Wolf289b2762014-09-15 12:06:39 +0200495 if (inserted) {
496 monitor_printf(mon, ": %s (%s%s%s)\n",
497 inserted->file,
498 inserted->drv,
499 inserted->ro ? ", read-only" : "",
500 inserted->encrypted ? ", encrypted" : "");
501 } else {
502 monitor_printf(mon, ": [not inserted]\n");
503 }
504
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200505 if (info) {
Kevin Wolf46eade72017-07-11 13:27:38 +0200506 if (info->has_qdev) {
507 monitor_printf(mon, " Attached to: %s\n", info->qdev);
508 }
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200509 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
510 monitor_printf(mon, " I/O status: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200511 BlockDeviceIoStatus_str(info->io_status));
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200512 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200513
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200514 if (info->removable) {
515 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
516 info->locked ? "" : "not ",
517 info->tray_open ? "open" : "closed");
518 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200519 }
520
521
522 if (!inserted) {
523 return;
524 }
525
526 monitor_printf(mon, " Cache mode: %s%s%s\n",
527 inserted->cache->writeback ? "writeback" : "writethrough",
528 inserted->cache->direct ? ", direct" : "",
529 inserted->cache->no_flush ? ", ignore flushes" : "");
530
531 if (inserted->has_backing_file) {
532 monitor_printf(mon,
533 " Backing file: %s "
534 "(chain depth: %" PRId64 ")\n",
535 inserted->backing_file,
536 inserted->backing_file_depth);
537 }
538
539 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
540 monitor_printf(mon, " Detect zeroes: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200541 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
Kevin Wolf289b2762014-09-15 12:06:39 +0200542 }
543
544 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
545 inserted->iops || inserted->iops_rd || inserted->iops_wr)
546 {
547 monitor_printf(mon, " I/O throttling: bps=%" PRId64
548 " bps_rd=%" PRId64 " bps_wr=%" PRId64
549 " bps_max=%" PRId64
550 " bps_rd_max=%" PRId64
551 " bps_wr_max=%" PRId64
552 " iops=%" PRId64 " iops_rd=%" PRId64
553 " iops_wr=%" PRId64
554 " iops_max=%" PRId64
555 " iops_rd_max=%" PRId64
556 " iops_wr_max=%" PRId64
Alberto Garciab8fe1692015-06-08 18:17:46 +0200557 " iops_size=%" PRId64
558 " group=%s\n",
Kevin Wolf289b2762014-09-15 12:06:39 +0200559 inserted->bps,
560 inserted->bps_rd,
561 inserted->bps_wr,
562 inserted->bps_max,
563 inserted->bps_rd_max,
564 inserted->bps_wr_max,
565 inserted->iops,
566 inserted->iops_rd,
567 inserted->iops_wr,
568 inserted->iops_max,
569 inserted->iops_rd_max,
570 inserted->iops_wr_max,
Alberto Garciab8fe1692015-06-08 18:17:46 +0200571 inserted->iops_size,
572 inserted->group);
Kevin Wolf289b2762014-09-15 12:06:39 +0200573 }
574
Stefan Hajnoczi94198742015-04-22 11:15:10 +0100575 if (verbose) {
Kevin Wolf289b2762014-09-15 12:06:39 +0200576 monitor_printf(mon, "\nImages:\n");
577 image_info = inserted->image;
578 while (1) {
Markus Armbrustere1ce7d72019-04-17 21:17:55 +0200579 bdrv_image_info_dump(image_info);
Kevin Wolf289b2762014-09-15 12:06:39 +0200580 if (image_info->has_backing_image) {
581 image_info = image_info->backing_image;
582 } else {
583 break;
584 }
585 }
586 }
587}
588
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800589void hmp_info_block(Monitor *mon, const QDict *qdict)
Luiz Capitulinob2023812011-09-21 17:16:47 -0300590{
591 BlockInfoList *block_list, *info;
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200592 BlockDeviceInfoList *blockdev_list, *blockdev;
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800593 const char *device = qdict_get_try_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -0600594 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
595 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200596 bool printed = false;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300597
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200598 /* Print BlockBackend information */
599 if (!nodes) {
Stefan Weilf19e44b2015-02-08 15:40:48 +0100600 block_list = qmp_query_block(NULL);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200601 } else {
602 block_list = NULL;
603 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300604
605 for (info = block_list; info; info = info->next) {
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800606 if (device && strcmp(device, info->value->device)) {
607 continue;
608 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300609
Kevin Wolffbe2e262013-06-19 16:10:55 +0200610 if (info != block_list) {
611 monitor_printf(mon, "\n");
Luiz Capitulinob2023812011-09-21 17:16:47 -0300612 }
613
Kevin Wolf289b2762014-09-15 12:06:39 +0200614 print_block_info(mon, info->value, info->value->has_inserted
615 ? info->value->inserted : NULL,
616 verbose);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200617 printed = true;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300618 }
619
620 qapi_free_BlockInfoList(block_list);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200621
622 if ((!device && !nodes) || printed) {
623 return;
624 }
625
626 /* Print node information */
Peter Krempafacda542020-01-20 09:50:49 +0100627 blockdev_list = qmp_query_named_block_nodes(false, false, NULL);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200628 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
629 assert(blockdev->value->has_node_name);
630 if (device && strcmp(device, blockdev->value->node_name)) {
631 continue;
632 }
633
634 if (blockdev != blockdev_list) {
635 monitor_printf(mon, "\n");
636 }
637
638 print_block_info(mon, NULL, blockdev->value, verbose);
639 }
640 qapi_free_BlockDeviceInfoList(blockdev_list);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300641}
642
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800643void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300644{
645 BlockStatsList *stats_list, *stats;
646
Fam Zhengf71eaa72014-10-31 11:32:57 +0800647 stats_list = qmp_query_blockstats(false, false, NULL);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300648
649 for (stats = stats_list; stats; stats = stats->next) {
650 if (!stats->value->has_device) {
651 continue;
652 }
653
654 monitor_printf(mon, "%s:", stats->value->device);
655 monitor_printf(mon, " rd_bytes=%" PRId64
656 " wr_bytes=%" PRId64
657 " rd_operations=%" PRId64
658 " wr_operations=%" PRId64
659 " flush_operations=%" PRId64
660 " wr_total_time_ns=%" PRId64
661 " rd_total_time_ns=%" PRId64
662 " flush_total_time_ns=%" PRId64
Peter Lievenf4564d52015-02-02 14:52:18 +0100663 " rd_merged=%" PRId64
664 " wr_merged=%" PRId64
Alberto Garciacb38fff2015-10-28 17:33:02 +0200665 " idle_time_ns=%" PRId64
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300666 "\n",
667 stats->value->stats->rd_bytes,
668 stats->value->stats->wr_bytes,
669 stats->value->stats->rd_operations,
670 stats->value->stats->wr_operations,
671 stats->value->stats->flush_operations,
672 stats->value->stats->wr_total_time_ns,
673 stats->value->stats->rd_total_time_ns,
Peter Lievenf4564d52015-02-02 14:52:18 +0100674 stats->value->stats->flush_total_time_ns,
675 stats->value->stats->rd_merged,
Alberto Garciacb38fff2015-10-28 17:33:02 +0200676 stats->value->stats->wr_merged,
677 stats->value->stats->idle_time_ns);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300678 }
679
680 qapi_free_BlockStatsList(stats_list);
681}
682
Marc-André Lureau05eb4a22018-07-03 17:56:47 +0200683#ifdef CONFIG_VNC
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100684/* Helper for hmp_info_vnc_clients, _servers */
685static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
686 const char *name)
687{
688 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
689 name,
690 info->host,
691 info->service,
Markus Armbruster977c7362017-08-24 10:46:08 +0200692 NetworkAddressFamily_str(info->family),
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100693 info->websocket ? " (Websocket)" : "");
694}
695
696/* Helper displaying and auth and crypt info */
697static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
698 VncPrimaryAuth auth,
699 VncVencryptSubAuth *vencrypt)
700{
701 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
Markus Armbruster977c7362017-08-24 10:46:08 +0200702 VncPrimaryAuth_str(auth),
703 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100704}
705
706static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
707{
708 while (client) {
709 VncClientInfo *cinfo = client->value;
710
711 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
712 monitor_printf(mon, " x509_dname: %s\n",
713 cinfo->has_x509_dname ?
714 cinfo->x509_dname : "none");
715 monitor_printf(mon, " sasl_username: %s\n",
716 cinfo->has_sasl_username ?
717 cinfo->sasl_username : "none");
718
719 client = client->next;
720 }
721}
722
723static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
724{
725 while (server) {
726 VncServerInfo2 *sinfo = server->value;
727 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
728 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
729 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
730 server = server->next;
731 }
732}
733
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800734void hmp_info_vnc(Monitor *mon, const QDict *qdict)
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200735{
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100736 VncInfo2List *info2l;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200737 Error *err = NULL;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200738
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100739 info2l = qmp_query_vnc_servers(&err);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200740 if (err) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +0300741 hmp_handle_error(mon, err);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200742 return;
743 }
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100744 if (!info2l) {
745 monitor_printf(mon, "None\n");
746 return;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200747 }
748
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100749 while (info2l) {
750 VncInfo2 *info = info2l->value;
751 monitor_printf(mon, "%s:\n", info->id);
752 hmp_info_vnc_servers(mon, info->server);
753 hmp_info_vnc_clients(mon, info->clients);
754 if (!info->server) {
755 /* The server entry displays its auth, we only
756 * need to display in the case of 'reverse' connections
757 * where there's no server.
758 */
759 hmp_info_vnc_authcrypt(mon, " ", info->auth,
760 info->has_vencrypt ? &info->vencrypt : NULL);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200761 }
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100762 if (info->has_display) {
763 monitor_printf(mon, " Display: %s\n", info->display);
764 }
765 info2l = info2l->next;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200766 }
767
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100768 qapi_free_VncInfo2List(info2l);
769
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200770}
Marc-André Lureau05eb4a22018-07-03 17:56:47 +0200771#endif
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200772
Markus Armbruster206addd2015-01-13 15:46:39 +0100773#ifdef CONFIG_SPICE
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800774void hmp_info_spice(Monitor *mon, const QDict *qdict)
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200775{
776 SpiceChannelList *chan;
777 SpiceInfo *info;
Cole Robinson22fa7da2015-03-01 09:29:18 -0500778 const char *channel_name;
779 const char * const channel_names[] = {
780 [SPICE_CHANNEL_MAIN] = "main",
781 [SPICE_CHANNEL_DISPLAY] = "display",
782 [SPICE_CHANNEL_INPUTS] = "inputs",
783 [SPICE_CHANNEL_CURSOR] = "cursor",
784 [SPICE_CHANNEL_PLAYBACK] = "playback",
785 [SPICE_CHANNEL_RECORD] = "record",
786 [SPICE_CHANNEL_TUNNEL] = "tunnel",
787 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
788 [SPICE_CHANNEL_USBREDIR] = "usbredir",
789 [SPICE_CHANNEL_PORT] = "port",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100790#if 0
791 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
792 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
793 * as quick fix for build failures with older versions. */
Cole Robinson22fa7da2015-03-01 09:29:18 -0500794 [SPICE_CHANNEL_WEBDAV] = "webdav",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100795#endif
Cole Robinson22fa7da2015-03-01 09:29:18 -0500796 };
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200797
798 info = qmp_query_spice(NULL);
799
800 if (!info->enabled) {
801 monitor_printf(mon, "Server: disabled\n");
802 goto out;
803 }
804
805 monitor_printf(mon, "Server:\n");
806 if (info->has_port) {
807 monitor_printf(mon, " address: %s:%" PRId64 "\n",
808 info->host, info->port);
809 }
810 if (info->has_tls_port) {
811 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
812 info->host, info->tls_port);
813 }
Yonit Halperin61c4efe2012-08-21 11:51:58 +0300814 monitor_printf(mon, " migrated: %s\n",
815 info->migrated ? "true" : "false");
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200816 monitor_printf(mon, " auth: %s\n", info->auth);
817 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200818 monitor_printf(mon, " mouse-mode: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200819 SpiceQueryMouseMode_str(info->mouse_mode));
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200820
821 if (!info->has_channels || info->channels == NULL) {
822 monitor_printf(mon, "Channels: none\n");
823 } else {
824 for (chan = info->channels; chan; chan = chan->next) {
825 monitor_printf(mon, "Channel:\n");
826 monitor_printf(mon, " address: %s:%s%s\n",
Eric Blakeddf21902015-10-26 16:34:49 -0600827 chan->value->host, chan->value->port,
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200828 chan->value->tls ? " [tls]" : "");
829 monitor_printf(mon, " session: %" PRId64 "\n",
830 chan->value->connection_id);
831 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
832 chan->value->channel_type, chan->value->channel_id);
Cole Robinson22fa7da2015-03-01 09:29:18 -0500833
834 channel_name = "unknown";
835 if (chan->value->channel_type > 0 &&
836 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
837 channel_names[chan->value->channel_type]) {
838 channel_name = channel_names[chan->value->channel_type];
839 }
840
841 monitor_printf(mon, " channel name: %s\n", channel_name);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200842 }
843 }
844
845out:
846 qapi_free_SpiceInfo(info);
847}
Markus Armbruster206addd2015-01-13 15:46:39 +0100848#endif
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200849
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800850void hmp_info_balloon(Monitor *mon, const QDict *qdict)
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200851{
852 BalloonInfo *info;
853 Error *err = NULL;
854
855 info = qmp_query_balloon(&err);
856 if (err) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +0300857 hmp_handle_error(mon, err);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200858 return;
859 }
860
Luiz Capitulino01ceb972012-12-03 15:56:41 -0200861 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200862
863 qapi_free_BalloonInfo(info);
864}
865
Luiz Capitulino79627472011-10-21 14:15:33 -0200866static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
867{
868 PciMemoryRegionList *region;
869
870 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
871 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
872 dev->slot, dev->function);
873 monitor_printf(mon, " ");
874
Eric Blake9fa02cd2015-05-04 09:05:32 -0600875 if (dev->class_info->has_desc) {
876 monitor_printf(mon, "%s", dev->class_info->desc);
Luiz Capitulino79627472011-10-21 14:15:33 -0200877 } else {
Eric Blake9fa02cd2015-05-04 09:05:32 -0600878 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
Luiz Capitulino79627472011-10-21 14:15:33 -0200879 }
880
881 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600882 dev->id->vendor, dev->id->device);
Denis V. Lunev18613dc2018-10-02 16:55:38 +0300883 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
884 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
885 dev->id->subsystem_vendor, dev->id->subsystem);
886 }
Luiz Capitulino79627472011-10-21 14:15:33 -0200887
888 if (dev->has_irq) {
889 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
890 }
891
892 if (dev->has_pci_bridge) {
893 monitor_printf(mon, " BUS %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600894 dev->pci_bridge->bus->number);
Luiz Capitulino79627472011-10-21 14:15:33 -0200895 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600896 dev->pci_bridge->bus->secondary);
Luiz Capitulino79627472011-10-21 14:15:33 -0200897 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600898 dev->pci_bridge->bus->subordinate);
Luiz Capitulino79627472011-10-21 14:15:33 -0200899
900 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600901 dev->pci_bridge->bus->io_range->base,
902 dev->pci_bridge->bus->io_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200903
904 monitor_printf(mon,
905 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600906 dev->pci_bridge->bus->memory_range->base,
907 dev->pci_bridge->bus->memory_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200908
909 monitor_printf(mon, " prefetchable memory range "
910 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600911 dev->pci_bridge->bus->prefetchable_range->base,
912 dev->pci_bridge->bus->prefetchable_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200913 }
914
915 for (region = dev->regions; region; region = region->next) {
916 uint64_t addr, size;
917
918 addr = region->value->address;
919 size = region->value->size;
920
921 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
922
923 if (!strcmp(region->value->type, "io")) {
924 monitor_printf(mon, "I/O at 0x%04" PRIx64
925 " [0x%04" PRIx64 "].\n",
926 addr, addr + size - 1);
927 } else {
928 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
929 " [0x%08" PRIx64 "].\n",
930 region->value->mem_type_64 ? 64 : 32,
931 region->value->prefetch ? " prefetchable" : "",
932 addr, addr + size - 1);
933 }
934 }
935
936 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
937
938 if (dev->has_pci_bridge) {
939 if (dev->pci_bridge->has_devices) {
940 PciDeviceInfoList *cdev;
941 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
942 hmp_info_pci_device(mon, cdev->value);
943 }
944 }
945 }
946}
947
Hervé Poussineau61b97832016-09-26 22:23:27 +0200948static int hmp_info_irq_foreach(Object *obj, void *opaque)
949{
950 InterruptStatsProvider *intc;
951 InterruptStatsProviderClass *k;
952 Monitor *mon = opaque;
953
954 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
955 intc = INTERRUPT_STATS_PROVIDER(obj);
956 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
957 uint64_t *irq_counts;
958 unsigned int nb_irqs, i;
959 if (k->get_statistics &&
960 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
961 if (nb_irqs > 0) {
962 monitor_printf(mon, "IRQ statistics for %s:\n",
963 object_get_typename(obj));
964 for (i = 0; i < nb_irqs; i++) {
965 if (irq_counts[i] > 0) {
966 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
967 irq_counts[i]);
968 }
969 }
970 }
971 } else {
972 monitor_printf(mon, "IRQ statistics not available for %s.\n",
973 object_get_typename(obj));
974 }
975 }
976
977 return 0;
978}
979
980void hmp_info_irq(Monitor *mon, const QDict *qdict)
981{
982 object_child_foreach_recursive(object_get_root(),
983 hmp_info_irq_foreach, mon);
984}
985
986static int hmp_info_pic_foreach(Object *obj, void *opaque)
987{
988 InterruptStatsProvider *intc;
989 InterruptStatsProviderClass *k;
990 Monitor *mon = opaque;
991
992 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
993 intc = INTERRUPT_STATS_PROVIDER(obj);
994 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
995 if (k->print_info) {
996 k->print_info(intc, mon);
997 } else {
998 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
999 object_get_typename(obj));
1000 }
1001 }
1002
1003 return 0;
1004}
1005
1006void hmp_info_pic(Monitor *mon, const QDict *qdict)
1007{
1008 object_child_foreach_recursive(object_get_root(),
1009 hmp_info_pic_foreach, mon);
1010}
1011
Yuval Shaiaf4b2c022019-03-11 03:29:09 -07001012static int hmp_info_rdma_foreach(Object *obj, void *opaque)
1013{
1014 RdmaProvider *rdma;
1015 RdmaProviderClass *k;
1016 Monitor *mon = opaque;
1017
1018 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
1019 rdma = RDMA_PROVIDER(obj);
1020 k = RDMA_PROVIDER_GET_CLASS(obj);
1021 if (k->print_statistics) {
1022 k->print_statistics(mon, rdma);
1023 } else {
1024 monitor_printf(mon, "RDMA statistics not available for %s.\n",
1025 object_get_typename(obj));
1026 }
1027 }
1028
1029 return 0;
1030}
1031
1032void hmp_info_rdma(Monitor *mon, const QDict *qdict)
1033{
1034 object_child_foreach_recursive(object_get_root(),
1035 hmp_info_rdma_foreach, mon);
1036}
1037
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001038void hmp_info_pci(Monitor *mon, const QDict *qdict)
Luiz Capitulino79627472011-10-21 14:15:33 -02001039{
Stefan Bergerf46cee32012-01-11 10:51:52 -05001040 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -02001041 Error *err = NULL;
1042
Stefan Bergerf46cee32012-01-11 10:51:52 -05001043 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -02001044 if (err) {
1045 monitor_printf(mon, "PCI devices not supported\n");
1046 error_free(err);
1047 return;
1048 }
1049
Stefan Bergerf46cee32012-01-11 10:51:52 -05001050 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -02001051 PciDeviceInfoList *dev;
1052
1053 for (dev = info->value->devices; dev; dev = dev->next) {
1054 hmp_info_pci_device(mon, dev->value);
1055 }
1056 }
1057
Stefan Bergerf46cee32012-01-11 10:51:52 -05001058 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -02001059}
1060
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001061void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +00001062{
1063 BlockJobInfoList *list;
1064 Error *err = NULL;
1065
1066 list = qmp_query_block_jobs(&err);
1067 assert(!err);
1068
1069 if (!list) {
1070 monitor_printf(mon, "No active jobs\n");
1071 return;
1072 }
1073
1074 while (list) {
1075 if (strcmp(list->value->type, "stream") == 0) {
1076 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1077 " of %" PRId64 " bytes, speed limit %" PRId64
1078 " bytes/s\n",
1079 list->value->device,
1080 list->value->offset,
1081 list->value->len,
1082 list->value->speed);
1083 } else {
1084 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1085 " of %" PRId64 " bytes, speed limit %" PRId64
1086 " bytes/s\n",
1087 list->value->type,
1088 list->value->device,
1089 list->value->offset,
1090 list->value->len,
1091 list->value->speed);
1092 }
1093 list = list->next;
1094 }
Gonglei93bb1312014-09-16 21:36:55 +08001095
1096 qapi_free_BlockJobInfoList(list);
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +00001097}
1098
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001099void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1100{
1101 TPMInfoList *info_list, *info;
1102 Error *err = NULL;
1103 unsigned int c = 0;
1104 TPMPassthroughOptions *tpo;
Amarnath Vallurif4ede812017-09-29 14:10:20 +03001105 TPMEmulatorOptions *teo;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001106
1107 info_list = qmp_query_tpm(&err);
1108 if (err) {
1109 monitor_printf(mon, "TPM device not supported\n");
1110 error_free(err);
1111 return;
1112 }
1113
1114 if (info_list) {
1115 monitor_printf(mon, "TPM device:\n");
1116 }
1117
1118 for (info = info_list; info; info = info->next) {
1119 TPMInfo *ti = info->value;
1120 monitor_printf(mon, " tpm%d: model=%s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02001121 c, TpmModel_str(ti->model));
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001122
1123 monitor_printf(mon, " \\ %s: type=%s",
Markus Armbruster977c7362017-08-24 10:46:08 +02001124 ti->id, TpmTypeOptionsKind_str(ti->options->type));
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001125
Eric Blakece211312015-10-26 16:35:00 -06001126 switch (ti->options->type) {
Corey Bryant88ca7bc2013-03-20 12:34:48 -04001127 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
Eric Blake32bafa82016-03-17 16:48:37 -06001128 tpo = ti->options->u.passthrough.data;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001129 monitor_printf(mon, "%s%s%s%s",
1130 tpo->has_path ? ",path=" : "",
1131 tpo->has_path ? tpo->path : "",
1132 tpo->has_cancel_path ? ",cancel-path=" : "",
1133 tpo->has_cancel_path ? tpo->cancel_path : "");
1134 break;
Amarnath Vallurif4ede812017-09-29 14:10:20 +03001135 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1136 teo = ti->options->u.emulator.data;
1137 monitor_printf(mon, ",chardev=%s", teo->chardev);
1138 break;
Eric Blake7fb1cf12015-11-18 01:52:57 -07001139 case TPM_TYPE_OPTIONS_KIND__MAX:
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001140 break;
1141 }
1142 monitor_printf(mon, "\n");
1143 c++;
1144 }
1145 qapi_free_TPMInfoList(info_list);
1146}
1147
Luiz Capitulino7a7f3252011-09-15 14:20:28 -03001148void hmp_quit(Monitor *mon, const QDict *qdict)
1149{
1150 monitor_suspend(mon);
1151 qmp_quit(NULL);
1152}
Luiz Capitulino5f158f22011-09-15 14:34:39 -03001153
1154void hmp_stop(Monitor *mon, const QDict *qdict)
1155{
1156 qmp_stop(NULL);
1157}
Luiz Capitulino38d22652011-09-15 14:41:46 -03001158
Emilio G. Cotadd12e1b2018-08-15 16:00:03 -04001159void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1160{
1161 const char *op = qdict_get_try_str(qdict, "op");
1162
1163 if (op == NULL) {
1164 bool on = qsp_is_enabled();
1165
1166 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1167 return;
1168 }
1169 if (!strcmp(op, "on")) {
1170 qsp_enable();
1171 } else if (!strcmp(op, "off")) {
1172 qsp_disable();
1173 } else if (!strcmp(op, "reset")) {
1174 qsp_reset();
1175 } else {
1176 Error *err = NULL;
1177
1178 error_setg(&err, QERR_INVALID_PARAMETER, op);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001179 hmp_handle_error(mon, err);
Emilio G. Cotadd12e1b2018-08-15 16:00:03 -04001180 }
1181}
1182
Luiz Capitulino38d22652011-09-15 14:41:46 -03001183void hmp_system_reset(Monitor *mon, const QDict *qdict)
1184{
1185 qmp_system_reset(NULL);
1186}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -03001187
1188void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1189{
1190 qmp_system_powerdown(NULL);
1191}
Luiz Capitulino755f1962011-10-06 14:31:39 -03001192
Dr. David Alan Gilbert8e8581e2018-06-20 16:39:46 +01001193void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1194{
1195 Error *err = NULL;
1196
Markus Armbruster361ac942018-07-05 11:14:02 +02001197 qmp_x_exit_preconfig(&err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001198 hmp_handle_error(mon, err);
Dr. David Alan Gilbert8e8581e2018-06-20 16:39:46 +01001199}
1200
Luiz Capitulino755f1962011-10-06 14:31:39 -03001201void hmp_cpu(Monitor *mon, const QDict *qdict)
1202{
1203 int64_t cpu_index;
1204
1205 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1206 use it are converted to the QAPI */
1207 cpu_index = qdict_get_int(qdict, "index");
1208 if (monitor_set_cpu(cpu_index) < 0) {
1209 monitor_printf(mon, "invalid CPU index\n");
1210 }
1211}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001212
1213void hmp_memsave(Monitor *mon, const QDict *qdict)
1214{
1215 uint32_t size = qdict_get_int(qdict, "size");
1216 const char *filename = qdict_get_str(qdict, "filename");
1217 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +02001218 Error *err = NULL;
Thomas Huth854e67f2017-01-13 13:12:35 +01001219 int cpu_index = monitor_get_cpu_index();
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001220
Thomas Huth854e67f2017-01-13 13:12:35 +01001221 if (cpu_index < 0) {
1222 monitor_printf(mon, "No CPU available\n");
1223 return;
1224 }
1225
1226 qmp_memsave(addr, size, filename, true, cpu_index, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001227 hmp_handle_error(mon, err);
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001228}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001229
1230void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1231{
1232 uint32_t size = qdict_get_int(qdict, "size");
1233 const char *filename = qdict_get_str(qdict, "filename");
1234 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +02001235 Error *err = NULL;
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001236
Markus Armbrustere940f542014-05-02 13:26:29 +02001237 qmp_pmemsave(addr, size, filename, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001238 hmp_handle_error(mon, err);
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001239}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001240
Markus Armbruster3949e592013-02-06 21:27:24 +01001241void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
Lei Li1f590cf2013-01-25 00:03:20 +08001242{
Lei Li1f590cf2013-01-25 00:03:20 +08001243 const char *chardev = qdict_get_str(qdict, "device");
1244 const char *data = qdict_get_str(qdict, "data");
Markus Armbrustere940f542014-05-02 13:26:29 +02001245 Error *err = NULL;
Lei Li1f590cf2013-01-25 00:03:20 +08001246
Markus Armbrustere940f542014-05-02 13:26:29 +02001247 qmp_ringbuf_write(chardev, data, false, 0, &err);
Lei Li1f590cf2013-01-25 00:03:20 +08001248
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001249 hmp_handle_error(mon, err);
Lei Li1f590cf2013-01-25 00:03:20 +08001250}
1251
Markus Armbruster3949e592013-02-06 21:27:24 +01001252void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
Lei Li49b6d722013-01-25 00:03:21 +08001253{
1254 uint32_t size = qdict_get_int(qdict, "size");
1255 const char *chardev = qdict_get_str(qdict, "device");
Markus Armbruster3ab651f2013-02-06 21:27:15 +01001256 char *data;
Markus Armbrustere940f542014-05-02 13:26:29 +02001257 Error *err = NULL;
Markus Armbruster543f3412013-02-06 21:27:26 +01001258 int i;
Lei Li49b6d722013-01-25 00:03:21 +08001259
Markus Armbrustere940f542014-05-02 13:26:29 +02001260 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1261 if (err) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001262 hmp_handle_error(mon, err);
Lei Li49b6d722013-01-25 00:03:21 +08001263 return;
1264 }
1265
Markus Armbruster543f3412013-02-06 21:27:26 +01001266 for (i = 0; data[i]; i++) {
1267 unsigned char ch = data[i];
1268
1269 if (ch == '\\') {
1270 monitor_printf(mon, "\\\\");
1271 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1272 monitor_printf(mon, "\\u%04X", ch);
1273 } else {
1274 monitor_printf(mon, "%c", ch);
1275 }
1276
1277 }
1278 monitor_printf(mon, "\n");
Markus Armbruster3ab651f2013-02-06 21:27:15 +01001279 g_free(data);
Lei Li49b6d722013-01-25 00:03:21 +08001280}
1281
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001282void hmp_cont(Monitor *mon, const QDict *qdict)
1283{
Markus Armbrustere940f542014-05-02 13:26:29 +02001284 Error *err = NULL;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001285
Markus Armbrustere940f542014-05-02 13:26:29 +02001286 qmp_cont(&err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001287 hmp_handle_error(mon, err);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001288}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001289
Gerd Hoffmann9b9df252012-02-23 13:45:21 +01001290void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1291{
Daniel Henrique Barbozafb064112018-12-05 17:47:01 -02001292 Error *err = NULL;
1293
1294 qmp_system_wakeup(&err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001295 hmp_handle_error(mon, err);
Gerd Hoffmann9b9df252012-02-23 13:45:21 +01001296}
1297
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01001298void hmp_nmi(Monitor *mon, const QDict *qdict)
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001299{
Markus Armbrustere940f542014-05-02 13:26:29 +02001300 Error *err = NULL;
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001301
Markus Armbrustere940f542014-05-02 13:26:29 +02001302 qmp_inject_nmi(&err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001303 hmp_handle_error(mon, err);
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001304}
Luiz Capitulino4b371562011-11-23 13:11:55 -02001305
1306void hmp_set_link(Monitor *mon, const QDict *qdict)
1307{
1308 const char *name = qdict_get_str(qdict, "name");
Eric Blake34acbc92015-05-15 16:25:00 -06001309 bool up = qdict_get_bool(qdict, "up");
Markus Armbrustere940f542014-05-02 13:26:29 +02001310 Error *err = NULL;
Luiz Capitulino4b371562011-11-23 13:11:55 -02001311
Markus Armbrustere940f542014-05-02 13:26:29 +02001312 qmp_set_link(name, up, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001313 hmp_handle_error(mon, err);
Luiz Capitulino4b371562011-11-23 13:11:55 -02001314}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001315
1316void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1317{
1318 const char *device = qdict_get_str(qdict, "device");
1319 const char *password = qdict_get_str(qdict, "password");
Markus Armbrustere940f542014-05-02 13:26:29 +02001320 Error *err = NULL;
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001321
Markus Armbrustere940f542014-05-02 13:26:29 +02001322 qmp_block_passwd(true, device, false, NULL, password, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001323 hmp_handle_error(mon, err);
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001324}
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001325
1326void hmp_balloon(Monitor *mon, const QDict *qdict)
1327{
1328 int64_t value = qdict_get_int(qdict, "value");
Markus Armbrustere940f542014-05-02 13:26:29 +02001329 Error *err = NULL;
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001330
Markus Armbrustere940f542014-05-02 13:26:29 +02001331 qmp_balloon(value, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001332 hmp_handle_error(mon, err);
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001333}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001334
1335void hmp_block_resize(Monitor *mon, const QDict *qdict)
1336{
1337 const char *device = qdict_get_str(qdict, "device");
1338 int64_t size = qdict_get_int(qdict, "size");
Markus Armbrustere940f542014-05-02 13:26:29 +02001339 Error *err = NULL;
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001340
Markus Armbrustere940f542014-05-02 13:26:29 +02001341 qmp_block_resize(true, device, false, NULL, size, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001342 hmp_handle_error(mon, err);
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001343}
Luiz Capitulino6106e242011-11-25 16:15:19 -02001344
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001345void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1346{
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001347 const char *filename = qdict_get_str(qdict, "target");
1348 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001349 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1350 bool full = qdict_get_try_bool(qdict, "full", false);
Markus Armbrustere940f542014-05-02 13:26:29 +02001351 Error *err = NULL;
Eric Blakefaecd402016-07-14 16:37:58 -06001352 DriveMirror mirror = {
1353 .device = (char *)qdict_get_str(qdict, "device"),
1354 .target = (char *)filename,
1355 .has_format = !!format,
1356 .format = (char *)format,
1357 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1358 .has_mode = true,
1359 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1360 .unmap = true,
1361 };
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001362
1363 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001364 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001365 hmp_handle_error(mon, err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001366 return;
1367 }
Eric Blakefaecd402016-07-14 16:37:58 -06001368 qmp_drive_mirror(&mirror, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001369 hmp_handle_error(mon, err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001370}
1371
Stefan Hajnoczide909302013-06-26 14:11:58 +02001372void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1373{
1374 const char *device = qdict_get_str(qdict, "device");
1375 const char *filename = qdict_get_str(qdict, "target");
1376 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001377 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1378 bool full = qdict_get_try_bool(qdict, "full", false);
Pavel Butsykin13b94142016-07-22 11:17:52 +03001379 bool compress = qdict_get_try_bool(qdict, "compress", false);
Markus Armbrustere940f542014-05-02 13:26:29 +02001380 Error *err = NULL;
Pavel Butsykin81206a82016-07-22 11:17:50 +03001381 DriveBackup backup = {
1382 .device = (char *)device,
1383 .target = (char *)filename,
1384 .has_format = !!format,
1385 .format = (char *)format,
1386 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1387 .has_mode = true,
1388 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
Pavel Butsykin13b94142016-07-22 11:17:52 +03001389 .has_compress = !!compress,
1390 .compress = compress,
Pavel Butsykin81206a82016-07-22 11:17:50 +03001391 };
Stefan Hajnoczide909302013-06-26 14:11:58 +02001392
1393 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001394 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001395 hmp_handle_error(mon, err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001396 return;
1397 }
1398
Pavel Butsykin81206a82016-07-22 11:17:50 +03001399 qmp_drive_backup(&backup, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001400 hmp_handle_error(mon, err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001401}
1402
Luiz Capitulino6106e242011-11-25 16:15:19 -02001403void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1404{
1405 const char *device = qdict_get_str(qdict, "device");
1406 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1407 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001408 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001409 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001410 Error *err = NULL;
Luiz Capitulino6106e242011-11-25 16:15:19 -02001411
1412 if (!filename) {
1413 /* In the future, if 'snapshot-file' is not specified, the snapshot
1414 will be taken internally. Today it's actually required. */
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001415 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001416 hmp_handle_error(mon, err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001417 return;
1418 }
1419
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001420 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
Benoît Canet0901f672014-01-23 21:31:38 +01001421 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1422 filename, false, NULL,
1423 !!format, format,
Markus Armbrustere940f542014-05-02 13:26:29 +02001424 true, mode, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001425 hmp_handle_error(mon, err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001426}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001427
Wenchao Xia775ca882013-09-11 14:04:37 +08001428void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1429{
1430 const char *device = qdict_get_str(qdict, "device");
1431 const char *name = qdict_get_str(qdict, "name");
Markus Armbrustere940f542014-05-02 13:26:29 +02001432 Error *err = NULL;
Wenchao Xia775ca882013-09-11 14:04:37 +08001433
Markus Armbrustere940f542014-05-02 13:26:29 +02001434 qmp_blockdev_snapshot_internal_sync(device, name, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001435 hmp_handle_error(mon, err);
Wenchao Xia775ca882013-09-11 14:04:37 +08001436}
1437
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001438void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1439{
1440 const char *device = qdict_get_str(qdict, "device");
1441 const char *name = qdict_get_str(qdict, "name");
1442 const char *id = qdict_get_try_str(qdict, "id");
Markus Armbrustere940f542014-05-02 13:26:29 +02001443 Error *err = NULL;
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001444
1445 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
Markus Armbrustere940f542014-05-02 13:26:29 +02001446 true, name, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001447 hmp_handle_error(mon, err);
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001448}
1449
Juan Quintela52b26202017-04-18 11:40:56 +02001450void hmp_loadvm(Monitor *mon, const QDict *qdict)
1451{
1452 int saved_vm_running = runstate_is_running();
1453 const char *name = qdict_get_str(qdict, "name");
Juan Quintela927d6632017-04-18 18:12:35 +02001454 Error *err = NULL;
Juan Quintela52b26202017-04-18 11:40:56 +02001455
1456 vm_stop(RUN_STATE_RESTORE_VM);
1457
Juan Quintela5e224792017-04-20 14:25:55 +02001458 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
Juan Quintela52b26202017-04-18 11:40:56 +02001459 vm_start();
1460 }
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001461 hmp_handle_error(mon, err);
Juan Quintela52b26202017-04-18 11:40:56 +02001462}
1463
Juan Quintelad9c7d132017-04-18 11:44:16 +02001464void hmp_savevm(Monitor *mon, const QDict *qdict)
1465{
Juan Quintela927d6632017-04-18 18:12:35 +02001466 Error *err = NULL;
1467
Juan Quintela5e224792017-04-20 14:25:55 +02001468 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001469 hmp_handle_error(mon, err);
Juan Quintelad9c7d132017-04-18 11:44:16 +02001470}
1471
Juan Quintelad905bb72017-04-18 11:46:23 +02001472void hmp_delvm(Monitor *mon, const QDict *qdict)
1473{
1474 BlockDriverState *bs;
zhangjixiang32cd6552018-02-25 09:47:51 +08001475 Error *err = NULL;
Juan Quintelad905bb72017-04-18 11:46:23 +02001476 const char *name = qdict_get_str(qdict, "name");
1477
1478 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
Cole Robinsonb4e492d2019-04-24 17:49:08 -04001479 error_prepend(&err,
1480 "deleting snapshot on device '%s': ",
1481 bdrv_get_device_name(bs));
Juan Quintelad905bb72017-04-18 11:46:23 +02001482 }
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001483 hmp_handle_error(mon, err);
Juan Quintelad905bb72017-04-18 11:46:23 +02001484}
1485
Juan Quintela66830612017-04-18 11:51:06 +02001486void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1487{
1488 BlockDriverState *bs, *bs1;
1489 BdrvNextIterator it1;
1490 QEMUSnapshotInfo *sn_tab, *sn;
1491 bool no_snapshot = true;
1492 int nb_sns, i;
1493 int total;
1494 int *global_snapshots;
1495 AioContext *aio_context;
1496
1497 typedef struct SnapshotEntry {
1498 QEMUSnapshotInfo sn;
1499 QTAILQ_ENTRY(SnapshotEntry) next;
1500 } SnapshotEntry;
1501
1502 typedef struct ImageEntry {
1503 const char *imagename;
1504 QTAILQ_ENTRY(ImageEntry) next;
1505 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1506 } ImageEntry;
1507
1508 QTAILQ_HEAD(, ImageEntry) image_list =
1509 QTAILQ_HEAD_INITIALIZER(image_list);
1510
1511 ImageEntry *image_entry, *next_ie;
1512 SnapshotEntry *snapshot_entry;
1513
1514 bs = bdrv_all_find_vmstate_bs();
1515 if (!bs) {
1516 monitor_printf(mon, "No available block device supports snapshots\n");
1517 return;
1518 }
1519 aio_context = bdrv_get_aio_context(bs);
1520
1521 aio_context_acquire(aio_context);
1522 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1523 aio_context_release(aio_context);
1524
1525 if (nb_sns < 0) {
1526 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1527 return;
1528 }
1529
1530 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1531 int bs1_nb_sns = 0;
1532 ImageEntry *ie;
1533 SnapshotEntry *se;
1534 AioContext *ctx = bdrv_get_aio_context(bs1);
1535
1536 aio_context_acquire(ctx);
1537 if (bdrv_can_snapshot(bs1)) {
1538 sn = NULL;
1539 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1540 if (bs1_nb_sns > 0) {
1541 no_snapshot = false;
1542 ie = g_new0(ImageEntry, 1);
1543 ie->imagename = bdrv_get_device_name(bs1);
1544 QTAILQ_INIT(&ie->snapshots);
1545 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1546 for (i = 0; i < bs1_nb_sns; i++) {
1547 se = g_new0(SnapshotEntry, 1);
1548 se->sn = sn[i];
1549 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1550 }
1551 }
1552 g_free(sn);
1553 }
1554 aio_context_release(ctx);
1555 }
1556
1557 if (no_snapshot) {
1558 monitor_printf(mon, "There is no snapshot available.\n");
1559 return;
1560 }
1561
1562 global_snapshots = g_new0(int, nb_sns);
1563 total = 0;
1564 for (i = 0; i < nb_sns; i++) {
1565 SnapshotEntry *next_sn;
1566 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1567 global_snapshots[total] = i;
1568 total++;
1569 QTAILQ_FOREACH(image_entry, &image_list, next) {
1570 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1571 next, next_sn) {
1572 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1573 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1574 next);
1575 g_free(snapshot_entry);
1576 }
1577 }
1578 }
1579 }
1580 }
1581
1582 monitor_printf(mon, "List of snapshots present on all disks:\n");
1583
1584 if (total > 0) {
Markus Armbrustere1ce7d72019-04-17 21:17:55 +02001585 bdrv_snapshot_dump(NULL);
Juan Quintela66830612017-04-18 11:51:06 +02001586 monitor_printf(mon, "\n");
1587 for (i = 0; i < total; i++) {
1588 sn = &sn_tab[global_snapshots[i]];
1589 /* The ID is not guaranteed to be the same on all images, so
1590 * overwrite it.
1591 */
1592 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
Markus Armbrustere1ce7d72019-04-17 21:17:55 +02001593 bdrv_snapshot_dump(sn);
Juan Quintela66830612017-04-18 11:51:06 +02001594 monitor_printf(mon, "\n");
1595 }
1596 } else {
1597 monitor_printf(mon, "None\n");
1598 }
1599
1600 QTAILQ_FOREACH(image_entry, &image_list, next) {
1601 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1602 continue;
1603 }
1604 monitor_printf(mon,
1605 "\nList of partial (non-loadable) snapshots on '%s':\n",
1606 image_entry->imagename);
Markus Armbrustere1ce7d72019-04-17 21:17:55 +02001607 bdrv_snapshot_dump(NULL);
Juan Quintela66830612017-04-18 11:51:06 +02001608 monitor_printf(mon, "\n");
1609 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
Markus Armbrustere1ce7d72019-04-17 21:17:55 +02001610 bdrv_snapshot_dump(&snapshot_entry->sn);
Juan Quintela66830612017-04-18 11:51:06 +02001611 monitor_printf(mon, "\n");
1612 }
1613 }
1614
1615 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1616 SnapshotEntry *next_sn;
1617 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1618 next_sn) {
1619 g_free(snapshot_entry);
1620 }
1621 g_free(image_entry);
1622 }
1623 g_free(sn_tab);
1624 g_free(global_snapshots);
1625
1626}
1627
Dr. David Alan Gilbert544f6ea2019-02-27 13:24:12 +00001628void hmp_announce_self(Monitor *mon, const QDict *qdict)
1629{
Dr. David Alan Gilbert08528272019-06-20 19:47:03 +01001630 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
Dr. David Alan Gilbertc6644542019-06-20 19:47:05 +01001631 const char *id = qdict_get_try_str(qdict, "id");
Dr. David Alan Gilbert08528272019-06-20 19:47:03 +01001632 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1633 migrate_announce_params());
1634
1635 qapi_free_strList(params->interfaces);
1636 params->interfaces = strList_from_comma_list(interfaces_str);
1637 params->has_interfaces = params->interfaces != NULL;
Dr. David Alan Gilbertc6644542019-06-20 19:47:05 +01001638 params->id = g_strdup(id);
1639 params->has_id = !!params->id;
Dr. David Alan Gilbert08528272019-06-20 19:47:03 +01001640 qmp_announce_self(params, NULL);
1641 qapi_free_AnnounceParameters(params);
Dr. David Alan Gilbert544f6ea2019-02-27 13:24:12 +00001642}
1643
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001644void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1645{
1646 qmp_migrate_cancel(NULL);
1647}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001648
Dr. David Alan Gilbert94ae12c2017-10-20 10:05:54 +01001649void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1650{
1651 Error *err = NULL;
1652 const char *state = qdict_get_str(qdict, "state");
1653 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1654
1655 if (val >= 0) {
1656 qmp_migrate_continue(val, &err);
1657 }
1658
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001659 hmp_handle_error(mon, err);
Dr. David Alan Gilbert94ae12c2017-10-20 10:05:54 +01001660}
1661
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001662void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1663{
1664 Error *err = NULL;
1665 const char *uri = qdict_get_str(qdict, "uri");
1666
1667 qmp_migrate_incoming(uri, &err);
1668
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001669 hmp_handle_error(mon, err);
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001670}
1671
Peter Xu3b563c42018-05-02 18:47:37 +08001672void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1673{
1674 Error *err = NULL;
1675 const char *uri = qdict_get_str(qdict, "uri");
1676
1677 qmp_migrate_recover(uri, &err);
1678
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001679 hmp_handle_error(mon, err);
Peter Xu3b563c42018-05-02 18:47:37 +08001680}
1681
Peter Xud37297d2018-05-02 18:47:40 +08001682void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1683{
1684 Error *err = NULL;
1685
1686 qmp_migrate_pause(&err);
1687
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001688 hmp_handle_error(mon, err);
Peter Xud37297d2018-05-02 18:47:40 +08001689}
1690
Ashijeet Acharya2ff30252016-09-15 21:50:28 +05301691/* Kept for backwards compatibility */
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001692void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1693{
1694 double value = qdict_get_double(qdict, "value");
1695 qmp_migrate_set_downtime(value, NULL);
1696}
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001697
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001698void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1699{
1700 int64_t value = qdict_get_int(qdict, "value");
1701 Error *err = NULL;
1702
1703 qmp_migrate_set_cache_size(value, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001704 hmp_handle_error(mon, err);
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001705}
1706
Ashijeet Acharya2ff30252016-09-15 21:50:28 +05301707/* Kept for backwards compatibility */
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001708void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1709{
1710 int64_t value = qdict_get_int(qdict, "value");
1711 qmp_migrate_set_speed(value, NULL);
1712}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001713
Orit Wasserman00458432012-08-06 21:42:48 +03001714void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1715{
1716 const char *cap = qdict_get_str(qdict, "capability");
1717 bool state = qdict_get_bool(qdict, "state");
1718 Error *err = NULL;
1719 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001720 int val;
Orit Wasserman00458432012-08-06 21:42:48 +03001721
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001722 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001723 if (val < 0) {
1724 goto end;
Orit Wasserman00458432012-08-06 21:42:48 +03001725 }
1726
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001727 caps->value = g_malloc0(sizeof(*caps->value));
1728 caps->value->capability = val;
1729 caps->value->state = state;
1730 caps->next = NULL;
1731 qmp_migrate_set_capabilities(caps, &err);
Orit Wasserman00458432012-08-06 21:42:48 +03001732
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001733end:
Orit Wasserman00458432012-08-06 21:42:48 +03001734 qapi_free_MigrationCapabilityStatusList(caps);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001735 hmp_handle_error(mon, err);
Orit Wasserman00458432012-08-06 21:42:48 +03001736}
1737
Liang Li50e9a622015-03-23 16:32:29 +08001738void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1739{
1740 const char *param = qdict_get_str(qdict, "parameter");
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001741 const char *valuestr = qdict_get_str(qdict, "value");
Juan Quintelaf4a06d12017-05-16 11:37:45 +02001742 Visitor *v = string_input_visitor_new(valuestr);
Markus Armbruster1bda8b32017-07-18 13:42:11 +02001743 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
Markus Armbrusterf46bfdb2017-02-21 21:14:07 +01001744 uint64_t valuebw = 0;
Juan Quintela73af8dd2017-10-05 21:30:10 +02001745 uint64_t cache_size;
Juan Quintela96eef042019-01-16 10:35:55 +01001746 MultiFDCompression compress_type;
Liang Li50e9a622015-03-23 16:32:29 +08001747 Error *err = NULL;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001748 int val, ret;
Liang Li50e9a622015-03-23 16:32:29 +08001749
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001750 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
Marc-André Lureau262517b2017-08-24 10:46:01 +02001751 if (val < 0) {
1752 goto cleanup;
1753 }
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001754
Marc-André Lureau262517b2017-08-24 10:46:01 +02001755 switch (val) {
1756 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1757 p->has_compress_level = true;
1758 visit_type_int(v, param, &p->compress_level, &err);
1759 break;
1760 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1761 p->has_compress_threads = true;
1762 visit_type_int(v, param, &p->compress_threads, &err);
1763 break;
Xiao Guangrong1d588722018-08-21 16:10:20 +08001764 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1765 p->has_compress_wait_thread = true;
1766 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1767 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001768 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1769 p->has_decompress_threads = true;
1770 visit_type_int(v, param, &p->decompress_threads, &err);
1771 break;
1772 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1773 p->has_cpu_throttle_initial = true;
1774 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1775 break;
1776 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1777 p->has_cpu_throttle_increment = true;
1778 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1779 break;
Li Qiang4cbc9c72018-08-01 06:00:20 -07001780 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1781 p->has_max_cpu_throttle = true;
1782 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1783 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001784 case MIGRATION_PARAMETER_TLS_CREDS:
1785 p->has_tls_creds = true;
1786 p->tls_creds = g_new0(StrOrNull, 1);
1787 p->tls_creds->type = QTYPE_QSTRING;
1788 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1789 break;
1790 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1791 p->has_tls_hostname = true;
1792 p->tls_hostname = g_new0(StrOrNull, 1);
1793 p->tls_hostname->type = QTYPE_QSTRING;
1794 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1795 break;
Daniel P. Berranged2f1d292019-02-27 14:53:24 +00001796 case MIGRATION_PARAMETER_TLS_AUTHZ:
1797 p->has_tls_authz = true;
1798 p->tls_authz = g_new0(StrOrNull, 1);
1799 p->tls_authz->type = QTYPE_QSTRING;
1800 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1801 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001802 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1803 p->has_max_bandwidth = true;
1804 /*
1805 * Can't use visit_type_size() here, because it
1806 * defaults to Bytes rather than Mebibytes.
1807 */
1808 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1809 if (ret < 0 || valuebw > INT64_MAX
1810 || (size_t)valuebw != valuebw) {
1811 error_setg(&err, "Invalid size %s", valuestr);
Liang Li50e9a622015-03-23 16:32:29 +08001812 break;
1813 }
Marc-André Lureau262517b2017-08-24 10:46:01 +02001814 p->max_bandwidth = valuebw;
1815 break;
1816 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1817 p->has_downtime_limit = true;
1818 visit_type_int(v, param, &p->downtime_limit, &err);
1819 break;
1820 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1821 p->has_x_checkpoint_delay = true;
1822 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1823 break;
1824 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1825 p->has_block_incremental = true;
1826 visit_type_bool(v, param, &p->block_incremental, &err);
1827 break;
Juan Quintelacbfd6c92019-02-06 13:54:06 +01001828 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1829 p->has_multifd_channels = true;
1830 visit_type_int(v, param, &p->multifd_channels, &err);
Juan Quintela4075fb12016-01-15 08:56:17 +01001831 break;
Juan Quintela96eef042019-01-16 10:35:55 +01001832 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1833 p->has_multifd_compression = true;
1834 visit_type_MultiFDCompression(v, param, &compress_type, &err);
1835 if (err) {
1836 break;
1837 }
1838 p->multifd_compression = compress_type;
1839 break;
Juan Quintela9004db42020-01-23 17:08:52 +01001840 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1841 p->has_multifd_zlib_level = true;
1842 visit_type_int(v, param, &p->multifd_zlib_level, &err);
1843 break;
Juan Quintela6a9ad152020-01-23 17:41:36 +01001844 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1845 p->has_multifd_zstd_level = true;
1846 visit_type_int(v, param, &p->multifd_zstd_level, &err);
1847 break;
Juan Quintela73af8dd2017-10-05 21:30:10 +02001848 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1849 p->has_xbzrle_cache_size = true;
1850 visit_type_size(v, param, &cache_size, &err);
Juan Quintelad0132832019-04-03 13:49:51 +02001851 if (err) {
1852 break;
1853 }
1854 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
Juan Quintela73af8dd2017-10-05 21:30:10 +02001855 error_setg(&err, "Invalid size %s", valuestr);
1856 break;
1857 }
1858 p->xbzrle_cache_size = cache_size;
1859 break;
Dr. David Alan Gilbert7e555c62018-06-13 11:26:40 +01001860 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1861 p->has_max_postcopy_bandwidth = true;
1862 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1863 break;
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +00001864 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1865 p->has_announce_initial = true;
1866 visit_type_size(v, param, &p->announce_initial, &err);
1867 break;
1868 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1869 p->has_announce_max = true;
1870 visit_type_size(v, param, &p->announce_max, &err);
1871 break;
1872 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1873 p->has_announce_rounds = true;
1874 visit_type_size(v, param, &p->announce_rounds, &err);
1875 break;
1876 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1877 p->has_announce_step = true;
1878 visit_type_size(v, param, &p->announce_step, &err);
1879 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001880 default:
1881 assert(0);
Liang Li50e9a622015-03-23 16:32:29 +08001882 }
1883
Marc-André Lureau262517b2017-08-24 10:46:01 +02001884 if (err) {
1885 goto cleanup;
Liang Li50e9a622015-03-23 16:32:29 +08001886 }
1887
Marc-André Lureau262517b2017-08-24 10:46:01 +02001888 qmp_migrate_set_parameters(p, &err);
1889
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001890 cleanup:
Markus Armbruster1bda8b32017-07-18 13:42:11 +02001891 qapi_free_MigrateSetParameters(p);
Juan Quintelaf4a06d12017-05-16 11:37:45 +02001892 visit_free(v);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001893 hmp_handle_error(mon, err);
Liang Li50e9a622015-03-23 16:32:29 +08001894}
1895
Markus Armbrusterb8a185b2015-03-05 17:29:02 +01001896void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1897{
1898 Error *err = NULL;
1899 const char *protocol = qdict_get_str(qdict, "protocol");
1900 const char *hostname = qdict_get_str(qdict, "hostname");
1901 bool has_port = qdict_haskey(qdict, "port");
1902 int port = qdict_get_try_int(qdict, "port", -1);
1903 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1904 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1905 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1906
1907 qmp_client_migrate_info(protocol, hostname,
1908 has_port, port, has_tls_port, tls_port,
1909 !!cert_subject, cert_subject, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001910 hmp_handle_error(mon, err);
Markus Armbrusterb8a185b2015-03-05 17:29:02 +01001911}
1912
Dr. David Alan Gilbert4886a1b2015-11-05 18:10:56 +00001913void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1914{
1915 Error *err = NULL;
1916 qmp_migrate_start_postcopy(&err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001917 hmp_handle_error(mon, err);
Dr. David Alan Gilbert4886a1b2015-11-05 18:10:56 +00001918}
1919
zhanghailiangd89e6662016-10-27 14:43:03 +08001920void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1921{
1922 Error *err = NULL;
1923
1924 qmp_x_colo_lost_heartbeat(&err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001925 hmp_handle_error(mon, err);
zhanghailiangd89e6662016-10-27 14:43:03 +08001926}
1927
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001928void hmp_set_password(Monitor *mon, const QDict *qdict)
1929{
1930 const char *protocol = qdict_get_str(qdict, "protocol");
1931 const char *password = qdict_get_str(qdict, "password");
1932 const char *connected = qdict_get_try_str(qdict, "connected");
1933 Error *err = NULL;
1934
1935 qmp_set_password(protocol, password, !!connected, connected, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001936 hmp_handle_error(mon, err);
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001937}
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001938
1939void hmp_expire_password(Monitor *mon, const QDict *qdict)
1940{
1941 const char *protocol = qdict_get_str(qdict, "protocol");
1942 const char *whenstr = qdict_get_str(qdict, "time");
1943 Error *err = NULL;
1944
1945 qmp_expire_password(protocol, whenstr, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001946 hmp_handle_error(mon, err);
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001947}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001948
1949void hmp_eject(Monitor *mon, const QDict *qdict)
1950{
Eric Blake34acbc92015-05-15 16:25:00 -06001951 bool force = qdict_get_try_bool(qdict, "force", false);
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001952 const char *device = qdict_get_str(qdict, "device");
1953 Error *err = NULL;
1954
Kevin Wolffbe2d812016-09-20 13:38:46 +02001955 qmp_eject(true, device, false, NULL, true, force, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03001956 hmp_handle_error(mon, err);
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001957}
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001958
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001959#ifdef CONFIG_VNC
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001960static void hmp_change_read_arg(void *opaque, const char *password,
1961 void *readline_opaque)
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001962{
1963 qmp_change_vnc_password(password, NULL);
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001964 monitor_read_command(opaque, 1);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001965}
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001966#endif
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001967
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001968void hmp_change(Monitor *mon, const QDict *qdict)
1969{
1970 const char *device = qdict_get_str(qdict, "device");
1971 const char *target = qdict_get_str(qdict, "target");
1972 const char *arg = qdict_get_try_str(qdict, "arg");
Max Reitzbaead0a2015-10-26 21:39:18 +01001973 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1974 BlockdevChangeReadOnlyMode read_only_mode = 0;
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001975 Error *err = NULL;
1976
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001977#ifdef CONFIG_VNC
Max Reitz10686742015-10-26 21:39:16 +01001978 if (strcmp(device, "vnc") == 0) {
Max Reitzbaead0a2015-10-26 21:39:18 +01001979 if (read_only) {
1980 monitor_printf(mon,
1981 "Parameter 'read-only-mode' is invalid for VNC\n");
1982 return;
1983 }
Max Reitz10686742015-10-26 21:39:16 +01001984 if (strcmp(target, "passwd") == 0 ||
1985 strcmp(target, "password") == 0) {
1986 if (!arg) {
Christophe de Dinechinea73f372019-06-25 14:39:05 +02001987 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
Kevin Wolf5f9dba12019-06-13 17:33:54 +02001988 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
Max Reitz10686742015-10-26 21:39:16 +01001989 return;
1990 }
1991 }
1992 qmp_change("vnc", target, !!arg, arg, &err);
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001993 } else
1994#endif
1995 {
Max Reitzbaead0a2015-10-26 21:39:18 +01001996 if (read_only) {
1997 read_only_mode =
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001998 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
Markus Armbruster06c60b62017-08-24 10:45:57 +02001999 read_only,
Max Reitzbaead0a2015-10-26 21:39:18 +01002000 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
2001 if (err) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002002 hmp_handle_error(mon, err);
Max Reitzbaead0a2015-10-26 21:39:18 +01002003 return;
2004 }
2005 }
2006
Kevin Wolf70e2cb32016-09-20 13:38:47 +02002007 qmp_blockdev_change_medium(true, device, false, NULL, target,
2008 !!arg, arg, !!read_only, read_only_mode,
2009 &err);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02002010 }
2011
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002012 hmp_handle_error(mon, err);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02002013}
Luiz Capitulino80047da2011-12-14 16:49:14 -02002014
2015void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
2016{
2017 Error *err = NULL;
Alberto Garcia83592182018-03-09 16:11:07 +02002018 char *device = (char *) qdict_get_str(qdict, "device");
Eric Blake4dc93972016-07-13 21:50:21 -06002019 BlockIOThrottle throttle = {
Eric Blake4dc93972016-07-13 21:50:21 -06002020 .bps = qdict_get_int(qdict, "bps"),
2021 .bps_rd = qdict_get_int(qdict, "bps_rd"),
2022 .bps_wr = qdict_get_int(qdict, "bps_wr"),
2023 .iops = qdict_get_int(qdict, "iops"),
2024 .iops_rd = qdict_get_int(qdict, "iops_rd"),
2025 .iops_wr = qdict_get_int(qdict, "iops_wr"),
2026 };
Luiz Capitulino80047da2011-12-14 16:49:14 -02002027
Alberto Garcia83592182018-03-09 16:11:07 +02002028 /* qmp_block_set_io_throttle has separate parameters for the
2029 * (deprecated) block device name and the qdev ID but the HMP
2030 * version has only one, so we must decide which one to pass. */
2031 if (blk_by_name(device)) {
2032 throttle.has_device = true;
2033 throttle.device = device;
2034 } else {
2035 throttle.has_id = true;
2036 throttle.id = device;
2037 }
2038
Eric Blake4dc93972016-07-13 21:50:21 -06002039 qmp_block_set_io_throttle(&throttle, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002040 hmp_handle_error(mon, err);
Luiz Capitulino80047da2011-12-14 16:49:14 -02002041}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002042
2043void hmp_block_stream(Monitor *mon, const QDict *qdict)
2044{
2045 Error *error = NULL;
2046 const char *device = qdict_get_str(qdict, "device");
2047 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01002048 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002049
Alberto Garcia11d6fbe2016-11-04 15:44:43 +02002050 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
John Snow241ca1a2018-09-06 09:02:23 -04002051 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
2052 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
2053 &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002054
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002055 hmp_handle_error(mon, error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002056}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00002057
2058void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
2059{
2060 Error *error = NULL;
2061 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +02002062 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00002063
2064 qmp_block_job_set_speed(device, value, &error);
2065
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002066 hmp_handle_error(mon, error);
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00002067}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002068
2069void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
2070{
2071 Error *error = NULL;
2072 const char *device = qdict_get_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -06002073 bool force = qdict_get_try_bool(qdict, "force", false);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002074
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02002075 qmp_block_job_cancel(device, true, force, &error);
2076
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002077 hmp_handle_error(mon, error);
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02002078}
2079
2080void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
2081{
2082 Error *error = NULL;
2083 const char *device = qdict_get_str(qdict, "device");
2084
2085 qmp_block_job_pause(device, &error);
2086
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002087 hmp_handle_error(mon, error);
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02002088}
2089
2090void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
2091{
2092 Error *error = NULL;
2093 const char *device = qdict_get_str(qdict, "device");
2094
2095 qmp_block_job_resume(device, &error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002096
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002097 hmp_handle_error(mon, error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002098}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002099
Paolo Bonziniaeae8832012-10-18 16:49:21 +02002100void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2101{
2102 Error *error = NULL;
2103 const char *device = qdict_get_str(qdict, "device");
2104
2105 qmp_block_job_complete(device, &error);
2106
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002107 hmp_handle_error(mon, error);
Paolo Bonziniaeae8832012-10-18 16:49:21 +02002108}
2109
zhanghailiange49f35b2015-03-13 16:08:39 +08002110typedef struct HMPMigrationStatus
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002111{
2112 QEMUTimer *timer;
2113 Monitor *mon;
2114 bool is_block_migration;
zhanghailiange49f35b2015-03-13 16:08:39 +08002115} HMPMigrationStatus;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002116
2117static void hmp_migrate_status_cb(void *opaque)
2118{
zhanghailiange49f35b2015-03-13 16:08:39 +08002119 HMPMigrationStatus *status = opaque;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002120 MigrationInfo *info;
2121
2122 info = qmp_query_migrate(NULL);
zhanghailiang24b8c392015-03-13 16:08:40 +08002123 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2124 info->status == MIGRATION_STATUS_SETUP) {
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002125 if (info->has_disk) {
2126 int progress;
2127
2128 if (info->disk->remaining) {
2129 progress = info->disk->transferred * 100 / info->disk->total;
2130 } else {
2131 progress = 100;
2132 }
2133
2134 monitor_printf(status->mon, "Completed %d %%\r", progress);
2135 monitor_flush(status->mon);
2136 }
2137
Alex Blighbc72ad62013-08-21 16:03:08 +01002138 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002139 } else {
2140 if (status->is_block_migration) {
2141 monitor_printf(status->mon, "\n");
2142 }
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +01002143 if (info->has_error_desc) {
2144 error_report("%s", info->error_desc);
2145 }
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002146 monitor_resume(status->mon);
Alex Blighbc72ad62013-08-21 16:03:08 +01002147 timer_del(status->timer);
Marc-André Lureaud34a10a2018-09-01 15:46:52 +02002148 timer_free(status->timer);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002149 g_free(status);
2150 }
2151
2152 qapi_free_MigrationInfo(info);
2153}
2154
2155void hmp_migrate(Monitor *mon, const QDict *qdict)
2156{
Eric Blake34acbc92015-05-15 16:25:00 -06002157 bool detach = qdict_get_try_bool(qdict, "detach", false);
2158 bool blk = qdict_get_try_bool(qdict, "blk", false);
2159 bool inc = qdict_get_try_bool(qdict, "inc", false);
Peter Xu7a4da282018-05-02 18:47:23 +08002160 bool resume = qdict_get_try_bool(qdict, "resume", false);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002161 const char *uri = qdict_get_str(qdict, "uri");
2162 Error *err = NULL;
2163
Peter Xu7a4da282018-05-02 18:47:23 +08002164 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2165 false, false, true, resume, &err);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002166 if (err) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002167 hmp_handle_error(mon, err);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002168 return;
2169 }
2170
2171 if (!detach) {
zhanghailiange49f35b2015-03-13 16:08:39 +08002172 HMPMigrationStatus *status;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002173
2174 if (monitor_suspend(mon) < 0) {
2175 monitor_printf(mon, "terminal does not allow synchronous "
2176 "migration, continuing detached\n");
2177 return;
2178 }
2179
2180 status = g_malloc0(sizeof(*status));
2181 status->mon = mon;
2182 status->is_block_migration = blk || inc;
Alex Blighbc72ad62013-08-21 16:03:08 +01002183 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002184 status);
Alex Blighbc72ad62013-08-21 16:03:08 +01002185 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002186 }
2187}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03002188
Luiz Capitulino928059a2012-04-18 17:34:15 -03002189void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2190{
2191 Error *err = NULL;
2192 QemuOpts *opts;
2193
2194 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01002195 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03002196 goto out;
2197 }
2198
2199 netdev_add(opts, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01002200 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03002201 qemu_opts_del(opts);
2202 }
2203
2204out:
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002205 hmp_handle_error(mon, err);
Luiz Capitulino928059a2012-04-18 17:34:15 -03002206}
Luiz Capitulino5f964152012-04-16 14:36:32 -03002207
2208void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2209{
2210 const char *id = qdict_get_str(qdict, "id");
2211 Error *err = NULL;
2212
2213 qmp_netdev_del(id, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002214 hmp_handle_error(mon, err);
Luiz Capitulino5f964152012-04-16 14:36:32 -03002215}
Corey Bryant208c9d12012-06-22 14:36:09 -04002216
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002217void hmp_object_add(Monitor *mon, const QDict *qdict)
2218{
2219 Error *err = NULL;
2220 QemuOpts *opts;
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002221 Object *obj = NULL;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002222
2223 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2224 if (err) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002225 hmp_handle_error(mon, err);
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002226 return;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002227 }
2228
Igor Mammedov3a464102017-01-10 13:53:14 +01002229 obj = user_creatable_add_opts(opts, &err);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002230 qemu_opts_del(opts);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002231
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002232 if (err) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002233 hmp_handle_error(mon, err);
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002234 }
2235 if (obj) {
2236 object_unref(obj);
2237 }
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002238}
2239
Corey Bryant208c9d12012-06-22 14:36:09 -04002240void hmp_getfd(Monitor *mon, const QDict *qdict)
2241{
2242 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02002243 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04002244
Markus Armbrustere940f542014-05-02 13:26:29 +02002245 qmp_getfd(fdname, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002246 hmp_handle_error(mon, err);
Corey Bryant208c9d12012-06-22 14:36:09 -04002247}
2248
2249void hmp_closefd(Monitor *mon, const QDict *qdict)
2250{
2251 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02002252 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04002253
Markus Armbrustere940f542014-05-02 13:26:29 +02002254 qmp_closefd(fdname, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002255 hmp_handle_error(mon, err);
Corey Bryant208c9d12012-06-22 14:36:09 -04002256}
Amos Konge4c8f002012-08-31 10:56:26 +08002257
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01002258void hmp_sendkey(Monitor *mon, const QDict *qdict)
Amos Konge4c8f002012-08-31 10:56:26 +08002259{
2260 const char *keys = qdict_get_str(qdict, "keys");
Luiz Capitulino9f328972012-09-20 14:19:47 -03002261 KeyValueList *keylist, *head = NULL, *tmp = NULL;
Amos Konge4c8f002012-08-31 10:56:26 +08002262 int has_hold_time = qdict_haskey(qdict, "hold-time");
2263 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2264 Error *err = NULL;
Keno Fischer5c99fa32018-06-29 12:32:10 +02002265 const char *separator;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002266 int keyname_len;
Amos Konge4c8f002012-08-31 10:56:26 +08002267
2268 while (1) {
Keno Fischer5c99fa32018-06-29 12:32:10 +02002269 separator = qemu_strchrnul(keys, '-');
2270 keyname_len = separator - keys;
Amos Konge4c8f002012-08-31 10:56:26 +08002271
2272 /* Be compatible with old interface, convert user inputted "<" */
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002273 if (keys[0] == '<' && keyname_len == 1) {
2274 keys = "less";
Amos Konge4c8f002012-08-31 10:56:26 +08002275 keyname_len = 4;
2276 }
Amos Konge4c8f002012-08-31 10:56:26 +08002277
Amos Konge4c8f002012-08-31 10:56:26 +08002278 keylist = g_malloc0(sizeof(*keylist));
Luiz Capitulino9f328972012-09-20 14:19:47 -03002279 keylist->value = g_malloc0(sizeof(*keylist->value));
Amos Konge4c8f002012-08-31 10:56:26 +08002280
2281 if (!head) {
2282 head = keylist;
2283 }
2284 if (tmp) {
2285 tmp->next = keylist;
2286 }
2287 tmp = keylist;
2288
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002289 if (strstart(keys, "0x", NULL)) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002290 char *endp;
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002291 int value = strtoul(keys, &endp, 0);
2292 assert(endp <= keys + keyname_len);
2293 if (endp != keys + keyname_len) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002294 goto err_out;
2295 }
Eric Blake568c73a2015-10-26 16:34:58 -06002296 keylist->value->type = KEY_VALUE_KIND_NUMBER;
Eric Blake32bafa82016-03-17 16:48:37 -06002297 keylist->value->u.number.data = value;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002298 } else {
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002299 int idx = index_from_key(keys, keyname_len);
Eric Blake7fb1cf12015-11-18 01:52:57 -07002300 if (idx == Q_KEY_CODE__MAX) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002301 goto err_out;
2302 }
Eric Blake568c73a2015-10-26 16:34:58 -06002303 keylist->value->type = KEY_VALUE_KIND_QCODE;
Eric Blake32bafa82016-03-17 16:48:37 -06002304 keylist->value->u.qcode.data = idx;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002305 }
2306
Keno Fischer5c99fa32018-06-29 12:32:10 +02002307 if (!*separator) {
Amos Konge4c8f002012-08-31 10:56:26 +08002308 break;
2309 }
2310 keys = separator + 1;
2311 }
2312
Luiz Capitulino9f328972012-09-20 14:19:47 -03002313 qmp_send_key(head, has_hold_time, hold_time, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002314 hmp_handle_error(mon, err);
Luiz Capitulino9f328972012-09-20 14:19:47 -03002315
2316out:
2317 qapi_free_KeyValueList(head);
2318 return;
2319
2320err_out:
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002321 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
Luiz Capitulino9f328972012-09-20 14:19:47 -03002322 goto out;
Amos Konge4c8f002012-08-31 10:56:26 +08002323}
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002324
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01002325void hmp_screendump(Monitor *mon, const QDict *qdict)
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002326{
2327 const char *filename = qdict_get_str(qdict, "filename");
Thomas Huthf771c542018-03-05 17:37:48 +01002328 const char *id = qdict_get_try_str(qdict, "device");
2329 int64_t head = qdict_get_try_int(qdict, "head", 0);
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002330 Error *err = NULL;
2331
Thomas Huthf771c542018-03-05 17:37:48 +01002332 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002333 hmp_handle_error(mon, err);
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002334}
Paolo Bonzini40577252012-08-23 11:53:04 +02002335
2336void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2337{
2338 const char *uri = qdict_get_str(qdict, "uri");
Eric Blake34acbc92015-05-15 16:25:00 -06002339 bool writable = qdict_get_try_bool(qdict, "writable", false);
2340 bool all = qdict_get_try_bool(qdict, "all", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02002341 Error *local_err = NULL;
2342 BlockInfoList *block_list, *info;
Markus Armbrusterbd269eb2017-04-26 09:36:41 +02002343 SocketAddress *addr;
Paolo Bonzini40577252012-08-23 11:53:04 +02002344
2345 if (writable && !all) {
2346 error_setg(&local_err, "-w only valid together with -a");
2347 goto exit;
2348 }
2349
2350 /* First check if the address is valid and start the server. */
2351 addr = socket_parse(uri, &local_err);
2352 if (local_err != NULL) {
2353 goto exit;
2354 }
2355
Daniel P. Berrange00019452019-02-27 16:20:34 +00002356 nbd_server_start(addr, NULL, NULL, &local_err);
Markus Armbrusterbd269eb2017-04-26 09:36:41 +02002357 qapi_free_SocketAddress(addr);
Paolo Bonzini40577252012-08-23 11:53:04 +02002358 if (local_err != NULL) {
2359 goto exit;
2360 }
2361
2362 if (!all) {
2363 return;
2364 }
2365
2366 /* Then try adding all block devices. If one fails, close all and
2367 * exit.
2368 */
2369 block_list = qmp_query_block(NULL);
2370
2371 for (info = block_list; info; info = info->next) {
2372 if (!info->value->has_inserted) {
2373 continue;
2374 }
2375
Eric Blakedeb6ccb2019-11-13 20:46:35 -06002376 qmp_nbd_server_add(info->value->device, false, NULL, false, NULL,
Eric Blake5fcbeb02019-01-11 13:47:17 -06002377 true, writable, false, NULL, &local_err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002378
2379 if (local_err != NULL) {
2380 qmp_nbd_server_stop(NULL);
2381 break;
2382 }
2383 }
2384
2385 qapi_free_BlockInfoList(block_list);
2386
2387exit:
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002388 hmp_handle_error(mon, local_err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002389}
2390
2391void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2392{
2393 const char *device = qdict_get_str(qdict, "device");
Eric Blakedba49322018-01-09 13:28:02 -06002394 const char *name = qdict_get_try_str(qdict, "name");
Eric Blake34acbc92015-05-15 16:25:00 -06002395 bool writable = qdict_get_try_bool(qdict, "writable", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02002396 Error *local_err = NULL;
2397
Eric Blakedeb6ccb2019-11-13 20:46:35 -06002398 qmp_nbd_server_add(device, !!name, name, false, NULL, true, writable,
Eric Blake5fcbeb02019-01-11 13:47:17 -06002399 false, NULL, &local_err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002400 hmp_handle_error(mon, local_err);
Eric Blake08fb10a2018-01-25 08:45:57 -06002401}
Paolo Bonzini40577252012-08-23 11:53:04 +02002402
Eric Blake08fb10a2018-01-25 08:45:57 -06002403void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2404{
2405 const char *name = qdict_get_str(qdict, "name");
2406 bool force = qdict_get_try_bool(qdict, "force", false);
2407 Error *err = NULL;
2408
2409 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2410 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002411 hmp_handle_error(mon, err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002412}
2413
2414void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2415{
Markus Armbrustere940f542014-05-02 13:26:29 +02002416 Error *err = NULL;
Paolo Bonzini40577252012-08-23 11:53:04 +02002417
Markus Armbrustere940f542014-05-02 13:26:29 +02002418 qmp_nbd_server_stop(&err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002419 hmp_handle_error(mon, err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002420}
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002421
2422void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2423{
2424 const char *args = qdict_get_str(qdict, "args");
2425 Error *err = NULL;
2426 QemuOpts *opts;
2427
Markus Armbruster70b94332015-02-13 12:50:26 +01002428 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002429 if (opts == NULL) {
Markus Armbruster312fd5f2013-02-08 21:22:16 +01002430 error_setg(&err, "Parsing chardev args failed");
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002431 } else {
Paolo Bonzini4ad6f6c2019-02-13 14:18:13 +01002432 qemu_chr_new_from_opts(opts, NULL, &err);
Daniel P. Berrange0a733362016-10-07 13:18:34 +01002433 qemu_opts_del(opts);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002434 }
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002435 hmp_handle_error(mon, err);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002436}
2437
Anton Nefedov75b60162017-07-06 15:08:57 +03002438void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2439{
2440 const char *args = qdict_get_str(qdict, "args");
2441 const char *id;
2442 Error *err = NULL;
2443 ChardevBackend *backend = NULL;
2444 ChardevReturn *ret = NULL;
2445 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2446 true);
2447 if (!opts) {
2448 error_setg(&err, "Parsing chardev args failed");
2449 goto end;
2450 }
2451
2452 id = qdict_get_str(qdict, "id");
2453 if (qemu_opts_id(opts)) {
2454 error_setg(&err, "Unexpected 'id' parameter");
2455 goto end;
2456 }
2457
2458 backend = qemu_chr_parse_opts(opts, &err);
2459 if (!backend) {
2460 goto end;
2461 }
2462
2463 ret = qmp_chardev_change(id, backend, &err);
2464
2465end:
2466 qapi_free_ChardevReturn(ret);
2467 qapi_free_ChardevBackend(backend);
2468 qemu_opts_del(opts);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002469 hmp_handle_error(mon, err);
Anton Nefedov75b60162017-07-06 15:08:57 +03002470}
2471
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002472void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2473{
2474 Error *local_err = NULL;
2475
2476 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002477 hmp_handle_error(mon, local_err);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002478}
Kevin Wolf587da2c2013-06-05 14:19:41 +02002479
Stefan Fritschbd1d5ad2017-06-11 09:48:17 +02002480void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2481{
2482 Error *local_err = NULL;
2483
2484 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002485 hmp_handle_error(mon, local_err);
Stefan Fritschbd1d5ad2017-06-11 09:48:17 +02002486}
2487
Kevin Wolf587da2c2013-06-05 14:19:41 +02002488void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2489{
Max Reitz4c7b7e92015-02-05 13:58:22 -05002490 BlockBackend *blk;
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002491 BlockBackend *local_blk = NULL;
Kevin Wolf89b6fc42019-12-17 15:13:34 +01002492 bool qdev = qdict_get_try_bool(qdict, "qdev", false);
Kevin Wolf587da2c2013-06-05 14:19:41 +02002493 const char* device = qdict_get_str(qdict, "device");
2494 const char* command = qdict_get_str(qdict, "command");
2495 Error *err = NULL;
Kevin Wolfd7086422017-01-13 19:02:32 +01002496 int ret;
Kevin Wolf587da2c2013-06-05 14:19:41 +02002497
Kevin Wolf89b6fc42019-12-17 15:13:34 +01002498 if (qdev) {
2499 blk = blk_by_qdev_id(device, &err);
2500 if (!blk) {
2501 goto fail;
2502 }
2503 } else {
2504 blk = blk_by_name(device);
2505 if (!blk) {
2506 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2507 if (bs) {
2508 blk = local_blk = blk_new(bdrv_get_aio_context(bs),
2509 0, BLK_PERM_ALL);
2510 ret = blk_insert_bs(blk, bs, &err);
2511 if (ret < 0) {
2512 goto fail;
2513 }
2514 } else {
Kevin Wolfd7086422017-01-13 19:02:32 +01002515 goto fail;
2516 }
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002517 }
2518 }
2519
Kevin Wolf887354b2017-02-10 16:24:56 +01002520 /*
2521 * Notably absent: Proper permission management. This is sad, but it seems
2522 * almost impossible to achieve without changing the semantics and thereby
2523 * limiting the use cases of the qemu-io HMP command.
2524 *
2525 * In an ideal world we would unconditionally create a new BlockBackend for
2526 * qemuio_command(), but we have commands like 'reopen' and want them to
2527 * take effect on the exact BlockBackend whose name the user passed instead
2528 * of just on a temporary copy of it.
2529 *
2530 * Another problem is that deleting the temporary BlockBackend involves
2531 * draining all requests on it first, but some qemu-iotests cases want to
2532 * issue multiple aio_read/write requests and expect them to complete in
2533 * the background while the monitor has already returned.
2534 *
2535 * This is also what prevents us from saving the original permissions and
2536 * restoring them later: We can't revoke permissions until all requests
2537 * have completed, and we don't know when that is nor can we really let
2538 * anything else run before we have revoken them to avoid race conditions.
2539 *
2540 * What happens now is that command() in qemu-io-cmds.c can extend the
2541 * permissions if necessary for the qemu-io command. And they simply stay
2542 * extended, possibly resulting in a read-only guest device keeping write
2543 * permissions. Ugly, but it appears to be the lesser evil.
2544 */
Kevin Wolf1813d332016-09-15 17:44:16 +02002545 qemuio_command(blk, command);
Vladimir Sementsov-Ogievskiy479b5992016-06-08 12:39:17 +03002546
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002547fail:
2548 blk_unref(local_blk);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002549 hmp_handle_error(mon, err);
Kevin Wolf587da2c2013-06-05 14:19:41 +02002550}
Paolo Bonziniab2d0532013-12-20 23:21:09 +01002551
2552void hmp_object_del(Monitor *mon, const QDict *qdict)
2553{
2554 const char *id = qdict_get_str(qdict, "id");
2555 Error *err = NULL;
2556
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002557 user_creatable_del(id, &err);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002558 hmp_handle_error(mon, err);
Paolo Bonziniab2d0532013-12-20 23:21:09 +01002559}
Hu Taoeb1539b2014-05-14 17:43:35 +08002560
Zhu Guihuaa6318922014-09-23 13:35:19 +08002561void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2562{
2563 Error *err = NULL;
2564 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2565 MemoryDeviceInfoList *info;
David Hildenbrandd766b222019-06-19 15:19:05 +05302566 VirtioPMEMDeviceInfo *vpi;
Zhu Guihuaa6318922014-09-23 13:35:19 +08002567 MemoryDeviceInfo *value;
2568 PCDIMMDeviceInfo *di;
2569
2570 for (info = info_list; info; info = info->next) {
2571 value = info->value;
2572
2573 if (value) {
Eric Blake1fd5d4f2015-10-26 16:34:59 -06002574 switch (value->type) {
Zhu Guihuaa6318922014-09-23 13:35:19 +08002575 case MEMORY_DEVICE_INFO_KIND_DIMM:
Haozhong Zhang6388e182018-03-11 11:02:12 +08002576 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
David Hildenbrandd766b222019-06-19 15:19:05 +05302577 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
2578 value->u.dimm.data : value->u.nvdimm.data;
Zhu Guihuaa6318922014-09-23 13:35:19 +08002579 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02002580 MemoryDeviceInfoKind_str(value->type),
Zhu Guihuaa6318922014-09-23 13:35:19 +08002581 di->id ? di->id : "");
2582 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2583 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2584 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2585 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2586 monitor_printf(mon, " memdev: %s\n", di->memdev);
2587 monitor_printf(mon, " hotplugged: %s\n",
2588 di->hotplugged ? "true" : "false");
2589 monitor_printf(mon, " hotpluggable: %s\n",
2590 di->hotpluggable ? "true" : "false");
David Hildenbrandd766b222019-06-19 15:19:05 +05302591 break;
2592 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
2593 vpi = value->u.virtio_pmem.data;
2594 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
2595 MemoryDeviceInfoKind_str(value->type),
2596 vpi->id ? vpi->id : "");
2597 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
2598 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
2599 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
2600 break;
2601 default:
2602 g_assert_not_reached();
Zhu Guihuaa6318922014-09-23 13:35:19 +08002603 }
2604 }
2605 }
2606
2607 qapi_free_MemoryDeviceInfoList(info_list);
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002608 hmp_handle_error(mon, err);
Zhu Guihuaa6318922014-09-23 13:35:19 +08002609}
Andreas Färber89d7fa92014-05-07 18:08:29 +02002610
Ting Wang62313162015-06-26 16:07:13 +08002611void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2612{
2613 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2614 IOThreadInfoList *info;
Pavel Hrdina5fc00482017-02-10 10:41:17 +01002615 IOThreadInfo *value;
Ting Wang62313162015-06-26 16:07:13 +08002616
2617 for (info = info_list; info; info = info->next) {
Pavel Hrdina5fc00482017-02-10 10:41:17 +01002618 value = info->value;
2619 monitor_printf(mon, "%s:\n", value->id);
2620 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2621 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2622 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2623 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
Ting Wang62313162015-06-26 16:07:13 +08002624 }
2625
2626 qapi_free_IOThreadInfoList(info_list);
2627}
2628
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002629void hmp_rocker(Monitor *mon, const QDict *qdict)
2630{
2631 const char *name = qdict_get_str(qdict, "name");
2632 RockerSwitch *rocker;
Markus Armbruster533fdae2015-12-18 16:35:27 +01002633 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002634
Markus Armbruster533fdae2015-12-18 16:35:27 +01002635 rocker = qmp_query_rocker(name, &err);
2636 if (err != NULL) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002637 hmp_handle_error(mon, err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002638 return;
2639 }
2640
2641 monitor_printf(mon, "name: %s\n", rocker->name);
2642 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2643 monitor_printf(mon, "ports: %d\n", rocker->ports);
2644
2645 qapi_free_RockerSwitch(rocker);
2646}
2647
2648void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2649{
2650 RockerPortList *list, *port;
2651 const char *name = qdict_get_str(qdict, "name");
Markus Armbruster533fdae2015-12-18 16:35:27 +01002652 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002653
Markus Armbruster533fdae2015-12-18 16:35:27 +01002654 list = qmp_query_rocker_ports(name, &err);
2655 if (err != NULL) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002656 hmp_handle_error(mon, err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002657 return;
2658 }
2659
2660 monitor_printf(mon, " ena/ speed/ auto\n");
2661 monitor_printf(mon, " port link duplex neg?\n");
2662
2663 for (port = list; port; port = port->next) {
2664 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2665 port->value->name,
2666 port->value->enabled ? port->value->link_up ?
2667 "up" : "down" : "!ena",
2668 port->value->speed == 10000 ? "10G" : "??",
2669 port->value->duplex ? "FD" : "HD",
2670 port->value->autoneg ? "Yes" : "No");
2671 }
2672
2673 qapi_free_RockerPortList(list);
2674}
2675
2676void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2677{
2678 RockerOfDpaFlowList *list, *info;
2679 const char *name = qdict_get_str(qdict, "name");
2680 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
Markus Armbruster533fdae2015-12-18 16:35:27 +01002681 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002682
Markus Armbruster533fdae2015-12-18 16:35:27 +01002683 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2684 if (err != NULL) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002685 hmp_handle_error(mon, err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002686 return;
2687 }
2688
2689 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2690
2691 for (info = list; info; info = info->next) {
2692 RockerOfDpaFlow *flow = info->value;
2693 RockerOfDpaFlowKey *key = flow->key;
2694 RockerOfDpaFlowMask *mask = flow->mask;
2695 RockerOfDpaFlowAction *action = flow->action;
2696
2697 if (flow->hits) {
2698 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2699 key->priority, key->tbl_id, flow->hits);
2700 } else {
2701 monitor_printf(mon, "%-4d %-3d ",
2702 key->priority, key->tbl_id);
2703 }
2704
2705 if (key->has_in_pport) {
2706 monitor_printf(mon, " pport %d", key->in_pport);
2707 if (mask->has_in_pport) {
2708 monitor_printf(mon, "(0x%x)", mask->in_pport);
2709 }
2710 }
2711
2712 if (key->has_vlan_id) {
2713 monitor_printf(mon, " vlan %d",
2714 key->vlan_id & VLAN_VID_MASK);
2715 if (mask->has_vlan_id) {
2716 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2717 }
2718 }
2719
2720 if (key->has_tunnel_id) {
2721 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2722 if (mask->has_tunnel_id) {
2723 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2724 }
2725 }
2726
2727 if (key->has_eth_type) {
2728 switch (key->eth_type) {
2729 case 0x0806:
2730 monitor_printf(mon, " ARP");
2731 break;
2732 case 0x0800:
2733 monitor_printf(mon, " IP");
2734 break;
2735 case 0x86dd:
2736 monitor_printf(mon, " IPv6");
2737 break;
2738 case 0x8809:
2739 monitor_printf(mon, " LACP");
2740 break;
2741 case 0x88cc:
2742 monitor_printf(mon, " LLDP");
2743 break;
2744 default:
2745 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2746 break;
2747 }
2748 }
2749
2750 if (key->has_eth_src) {
2751 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2752 (mask->has_eth_src) &&
2753 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2754 monitor_printf(mon, " src <any mcast/bcast>");
2755 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2756 (mask->has_eth_src) &&
2757 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2758 monitor_printf(mon, " src <any ucast>");
2759 } else {
2760 monitor_printf(mon, " src %s", key->eth_src);
2761 if (mask->has_eth_src) {
2762 monitor_printf(mon, "(%s)", mask->eth_src);
2763 }
2764 }
2765 }
2766
2767 if (key->has_eth_dst) {
2768 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2769 (mask->has_eth_dst) &&
2770 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2771 monitor_printf(mon, " dst <any mcast/bcast>");
2772 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2773 (mask->has_eth_dst) &&
2774 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2775 monitor_printf(mon, " dst <any ucast>");
2776 } else {
2777 monitor_printf(mon, " dst %s", key->eth_dst);
2778 if (mask->has_eth_dst) {
2779 monitor_printf(mon, "(%s)", mask->eth_dst);
2780 }
2781 }
2782 }
2783
2784 if (key->has_ip_proto) {
2785 monitor_printf(mon, " proto %d", key->ip_proto);
2786 if (mask->has_ip_proto) {
2787 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2788 }
2789 }
2790
2791 if (key->has_ip_tos) {
2792 monitor_printf(mon, " TOS %d", key->ip_tos);
2793 if (mask->has_ip_tos) {
2794 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2795 }
2796 }
2797
2798 if (key->has_ip_dst) {
2799 monitor_printf(mon, " dst %s", key->ip_dst);
2800 }
2801
2802 if (action->has_goto_tbl || action->has_group_id ||
2803 action->has_new_vlan_id) {
2804 monitor_printf(mon, " -->");
2805 }
2806
2807 if (action->has_new_vlan_id) {
2808 monitor_printf(mon, " apply new vlan %d",
2809 ntohs(action->new_vlan_id));
2810 }
2811
2812 if (action->has_group_id) {
2813 monitor_printf(mon, " write group 0x%08x", action->group_id);
2814 }
2815
2816 if (action->has_goto_tbl) {
2817 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2818 }
2819
2820 monitor_printf(mon, "\n");
2821 }
2822
2823 qapi_free_RockerOfDpaFlowList(list);
2824}
2825
2826void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2827{
2828 RockerOfDpaGroupList *list, *g;
2829 const char *name = qdict_get_str(qdict, "name");
2830 uint8_t type = qdict_get_try_int(qdict, "type", 9);
Markus Armbruster533fdae2015-12-18 16:35:27 +01002831 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002832 bool set = false;
2833
Markus Armbruster533fdae2015-12-18 16:35:27 +01002834 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2835 if (err != NULL) {
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002836 hmp_handle_error(mon, err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002837 return;
2838 }
2839
2840 monitor_printf(mon, "id (decode) --> buckets\n");
2841
2842 for (g = list; g; g = g->next) {
2843 RockerOfDpaGroup *group = g->value;
2844
2845 monitor_printf(mon, "0x%08x", group->id);
2846
2847 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2848 group->type == 1 ? "L2 rewrite" :
2849 group->type == 2 ? "L3 unicast" :
2850 group->type == 3 ? "L2 multicast" :
2851 group->type == 4 ? "L2 flood" :
2852 group->type == 5 ? "L3 interface" :
2853 group->type == 6 ? "L3 multicast" :
2854 group->type == 7 ? "L3 ECMP" :
2855 group->type == 8 ? "L2 overlay" :
2856 "unknown");
2857
2858 if (group->has_vlan_id) {
2859 monitor_printf(mon, " vlan %d", group->vlan_id);
2860 }
2861
2862 if (group->has_pport) {
2863 monitor_printf(mon, " pport %d", group->pport);
2864 }
2865
2866 if (group->has_index) {
2867 monitor_printf(mon, " index %d", group->index);
2868 }
2869
2870 monitor_printf(mon, ") -->");
2871
2872 if (group->has_set_vlan_id && group->set_vlan_id) {
2873 set = true;
2874 monitor_printf(mon, " set vlan %d",
2875 group->set_vlan_id & VLAN_VID_MASK);
2876 }
2877
2878 if (group->has_set_eth_src) {
2879 if (!set) {
2880 set = true;
2881 monitor_printf(mon, " set");
2882 }
2883 monitor_printf(mon, " src %s", group->set_eth_src);
2884 }
2885
2886 if (group->has_set_eth_dst) {
2887 if (!set) {
2888 set = true;
2889 monitor_printf(mon, " set");
2890 }
2891 monitor_printf(mon, " dst %s", group->set_eth_dst);
2892 }
2893
2894 set = false;
2895
2896 if (group->has_ttl_check && group->ttl_check) {
2897 monitor_printf(mon, " check TTL");
2898 }
2899
2900 if (group->has_group_id && group->group_id) {
2901 monitor_printf(mon, " group id 0x%08x", group->group_id);
2902 }
2903
2904 if (group->has_pop_vlan && group->pop_vlan) {
2905 monitor_printf(mon, " pop vlan");
2906 }
2907
2908 if (group->has_out_pport) {
2909 monitor_printf(mon, " out pport %d", group->out_pport);
2910 }
2911
2912 if (group->has_group_ids) {
2913 struct uint32List *id;
2914
2915 monitor_printf(mon, " groups [");
2916 for (id = group->group_ids; id; id = id->next) {
2917 monitor_printf(mon, "0x%08x", id->value);
2918 if (id->next) {
2919 monitor_printf(mon, ",");
2920 }
2921 }
2922 monitor_printf(mon, "]");
2923 }
2924
2925 monitor_printf(mon, "\n");
2926 }
2927
2928 qapi_free_RockerOfDpaGroupList(list);
2929}
Peter Xu4a6b52d2016-02-18 13:16:55 +08002930
Peter Xube9b23c2017-05-12 12:17:41 +08002931void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2932{
2933 ram_block_dump(mon);
2934}
2935
Igor Mammedov39164c12017-02-16 15:15:37 -08002936void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2937{
Ben Warren72d91962017-03-02 13:36:50 -08002938 Error *err = NULL;
2939 GuidInfo *info = qmp_query_vm_generation_id(&err);
Igor Mammedov39164c12017-02-16 15:15:37 -08002940 if (info) {
2941 monitor_printf(mon, "%s\n", info->guid);
2942 }
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002943 hmp_handle_error(mon, err);
Igor Mammedov39164c12017-02-16 15:15:37 -08002944 qapi_free_GuidInfo(info);
2945}
Vadim Galitsynd0f63c12017-08-29 17:30:22 +02002946
2947void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2948{
2949 Error *err = NULL;
2950 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2951 if (info) {
2952 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2953 info->base_memory);
2954
2955 if (info->has_plugged_memory) {
2956 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2957 info->plugged_memory);
2958 }
2959
2960 qapi_free_MemoryInfo(info);
2961 }
Vladimir Sementsov-Ogievskiy187c6142019-12-05 20:46:18 +03002962 hmp_handle_error(mon, err);
Vadim Galitsynd0f63c12017-08-29 17:30:22 +02002963}