blob: 6bbbe1ad85d5a0f9f833e66f95bbe3d604ec5d95 [file] [log] [blame]
Anthony Liguori48a32be2011-09-02 12:34:48 -05001/*
2 * Human Monitor Interface
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
Paolo 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"
Anthony Liguori48a32be2011-09-02 12:34:48 -050017#include "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"
Juan Quintela52b26202017-04-18 11:40:56 +020022#include "sysemu/sysemu.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"
Paolo Bonzini83c90892012-12-17 18:19:49 +010027#include "monitor/monitor.h"
Markus Armbruster318660f2015-03-05 17:24:48 +010028#include "monitor/qdev.h"
Markus Armbrustere688df62018-02-01 12:18:31 +010029#include "qapi/error.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"
34#include "qapi/qapi-commands-migration.h"
35#include "qapi/qapi-commands-misc.h"
36#include "qapi/qapi-commands-net.h"
37#include "qapi/qapi-commands-rocker.h"
38#include "qapi/qapi-commands-run-state.h"
39#include "qapi/qapi-commands-tpm.h"
40#include "qapi/qapi-commands-ui.h"
Markus Armbruster452fcdb2018-02-01 12:18:39 +010041#include "qapi/qmp/qdict.h"
Markus Armbrustercc7a8ea2015-03-17 17:22:46 +010042#include "qapi/qmp/qerror.h"
Juan Quintelaf4a06d12017-05-16 11:37:45 +020043#include "qapi/string-input-visitor.h"
Hu Taoeb1539b2014-05-14 17:43:35 +080044#include "qapi/string-output-visitor.h"
Daniel P. Berrange90998d52016-02-10 18:40:59 +000045#include "qom/object_interfaces.h"
Paolo Bonzini28ecbae2012-11-28 12:06:30 +010046#include "ui/console.h"
Markus Armbrusterbd269eb2017-04-26 09:36:41 +020047#include "block/nbd.h"
Wenchao Xiabd093a32013-06-06 12:28:00 +080048#include "block/qapi.h"
Kevin Wolf587da2c2013-06-05 14:19:41 +020049#include "qemu-io.h"
Veronia Bahaaf348b6d2016-03-20 19:16:19 +020050#include "qemu/cutils.h"
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +010051#include "qemu/error-report.h"
Peter Xube9b23c2017-05-12 12:17:41 +080052#include "exec/ramlist.h"
Hervé Poussineau61b97832016-09-26 22:23:27 +020053#include "hw/intc/intc.h"
Yuval Shaiaf4b2c022019-03-11 03:29:09 -070054#include "hw/rdma/rdma.h"
Juan Quintela5e224792017-04-20 14:25:55 +020055#include "migration/snapshot.h"
Peter Xu9d18af92017-06-27 12:10:19 +080056#include "migration/misc.h"
Anthony Liguori48a32be2011-09-02 12:34:48 -050057
Cole Robinson22fa7da2015-03-01 09:29:18 -050058#ifdef CONFIG_SPICE
59#include <spice/enums.h>
60#endif
61
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020062static void hmp_handle_error(Monitor *mon, Error **errp)
63{
Markus Armbruster415168e2014-05-02 13:26:34 +020064 assert(errp);
65 if (*errp) {
Dr. David Alan Gilbert66363e92019-02-12 13:47:56 +000066 error_reportf_err(*errp, "Error: ");
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -020067 }
68}
69
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080070void hmp_info_name(Monitor *mon, const QDict *qdict)
Anthony Liguori48a32be2011-09-02 12:34:48 -050071{
72 NameInfo *info;
73
74 info = qmp_query_name(NULL);
75 if (info->has_name) {
76 monitor_printf(mon, "%s\n", info->name);
77 }
78 qapi_free_NameInfo(info);
79}
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030080
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080081void hmp_info_version(Monitor *mon, const QDict *qdict)
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030082{
83 VersionInfo *info;
84
85 info = qmp_query_version(NULL);
86
87 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
Eric Blake4752cdb2015-05-04 09:05:31 -060088 info->qemu->major, info->qemu->minor, info->qemu->micro,
Luiz Capitulinob9c15f12011-08-26 17:38:13 -030089 info->package);
90
91 qapi_free_VersionInfo(info);
92}
Luiz Capitulino292a2602011-09-12 15:10:53 -030093
Wenchao Xia84f2d0e2013-01-14 14:06:25 +080094void hmp_info_kvm(Monitor *mon, const QDict *qdict)
Luiz Capitulino292a2602011-09-12 15:10:53 -030095{
96 KvmInfo *info;
97
98 info = qmp_query_kvm(NULL);
99 monitor_printf(mon, "kvm support: ");
100 if (info->present) {
101 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
102 } else {
103 monitor_printf(mon, "not compiled\n");
104 }
105
106 qapi_free_KvmInfo(info);
107}
108
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800109void hmp_info_status(Monitor *mon, const QDict *qdict)
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300110{
111 StatusInfo *info;
112
113 info = qmp_query_status(NULL);
114
115 monitor_printf(mon, "VM status: %s%s",
116 info->running ? "running" : "paused",
117 info->singlestep ? " (single step mode)" : "");
118
119 if (!info->running && info->status != RUN_STATE_PAUSED) {
Markus Armbruster977c7362017-08-24 10:46:08 +0200120 monitor_printf(mon, " (%s)", RunState_str(info->status));
Luiz Capitulino1fa9a5e2011-09-12 17:54:20 -0300121 }
122
123 monitor_printf(mon, "\n");
124
125 qapi_free_StatusInfo(info);
126}
127
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800128void hmp_info_uuid(Monitor *mon, const QDict *qdict)
Luiz Capitulinoefab7672011-09-13 17:16:25 -0300129{
130 UuidInfo *info;
131
132 info = qmp_query_uuid(NULL);
133 monitor_printf(mon, "%s\n", info->UUID);
134 qapi_free_UuidInfo(info);
135}
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300136
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800137void hmp_info_chardev(Monitor *mon, const QDict *qdict)
Luiz Capitulinoc5a415a2011-09-14 16:05:49 -0300138{
139 ChardevInfoList *char_info, *info;
140
141 char_info = qmp_query_chardev(NULL);
142 for (info = char_info; info; info = info->next) {
143 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
144 info->value->filename);
145 }
146
147 qapi_free_ChardevInfoList(char_info);
148}
Luiz Capitulino7a7f3252011-09-15 14:20:28 -0300149
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800150void hmp_info_mice(Monitor *mon, const QDict *qdict)
Luiz Capitulinoe235cec2011-09-21 15:29:55 -0300151{
152 MouseInfoList *mice_list, *mouse;
153
154 mice_list = qmp_query_mice(NULL);
155 if (!mice_list) {
156 monitor_printf(mon, "No mouse devices connected\n");
157 return;
158 }
159
160 for (mouse = mice_list; mouse; mouse = mouse->next) {
161 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
162 mouse->value->current ? '*' : ' ',
163 mouse->value->index, mouse->value->name,
164 mouse->value->absolute ? " (absolute)" : "");
165 }
166
167 qapi_free_MouseInfoList(mice_list);
168}
169
Juan Quintela9aca82b2019-02-27 11:51:27 +0100170static char *SocketAddress_to_str(SocketAddress *addr)
171{
172 switch (addr->type) {
173 case SOCKET_ADDRESS_TYPE_INET:
174 return g_strdup_printf("tcp:%s:%s",
175 addr->u.inet.host,
176 addr->u.inet.port);
177 case SOCKET_ADDRESS_TYPE_UNIX:
178 return g_strdup_printf("unix:%s",
179 addr->u.q_unix.path);
180 case SOCKET_ADDRESS_TYPE_FD:
181 return g_strdup_printf("fd:%s", addr->u.fd.str);
182 case SOCKET_ADDRESS_TYPE_VSOCK:
183 return g_strdup_printf("tcp:%s:%s",
184 addr->u.vsock.cid,
185 addr->u.vsock.port);
186 default:
187 return g_strdup("unknown address type");
188 }
189}
190
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800191void hmp_info_migrate(Monitor *mon, const QDict *qdict)
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300192{
193 MigrationInfo *info;
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300194 MigrationCapabilityStatusList *caps, *cap;
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300195
196 info = qmp_query_migrate(NULL);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300197 caps = qmp_query_migrate_capabilities(NULL);
198
Peter Xu9d18af92017-06-27 12:10:19 +0800199 migration_global_dump(mon);
200
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300201 /* do not display parameters during setup */
202 if (info->has_status && caps) {
203 monitor_printf(mon, "capabilities: ");
204 for (cap = caps; cap; cap = cap->next) {
205 monitor_printf(mon, "%s: %s ",
Markus Armbruster977c7362017-08-24 10:46:08 +0200206 MigrationCapability_str(cap->value->capability),
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300207 cap->value->state ? "on" : "off");
208 }
209 monitor_printf(mon, "\n");
210 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300211
212 if (info->has_status) {
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +0100213 monitor_printf(mon, "Migration status: %s",
Markus Armbruster977c7362017-08-24 10:46:08 +0200214 MigrationStatus_str(info->status));
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +0100215 if (info->status == MIGRATION_STATUS_FAILED &&
216 info->has_error_desc) {
217 monitor_printf(mon, " (%s)\n", info->error_desc);
218 } else {
219 monitor_printf(mon, "\n");
220 }
221
Juan Quintela7aa939a2012-08-18 13:17:10 +0200222 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
223 info->total_time);
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200224 if (info->has_expected_downtime) {
225 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
226 info->expected_downtime);
227 }
Juan Quintela9c5a9fc2012-08-13 09:35:16 +0200228 if (info->has_downtime) {
229 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
230 info->downtime);
231 }
Michael R. Hinesed4fbd12013-07-22 10:01:58 -0400232 if (info->has_setup_time) {
233 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
234 info->setup_time);
235 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300236 }
237
238 if (info->has_ram) {
239 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
240 info->ram->transferred >> 10);
Michael R. Hines7e114f82013-06-25 21:35:30 -0400241 monitor_printf(mon, "throughput: %0.2f mbps\n",
242 info->ram->mbps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300243 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
244 info->ram->remaining >> 10);
245 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
246 info->ram->total >> 10);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300247 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
248 info->ram->duplicate);
Peter Lievenf1c72792013-03-26 10:58:37 +0100249 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
250 info->ram->skipped);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300251 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
252 info->ram->normal);
253 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
254 info->ram->normal_bytes >> 10);
ChenLiang58570ed2014-04-04 17:57:55 +0800255 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
256 info->ram->dirty_sync_count);
Chao Fan030ce1f2017-03-21 10:22:43 +0800257 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
258 info->ram->page_size >> 10);
Juan Quintelaa61c45b2018-06-26 15:20:11 +0200259 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
260 info->ram->multifd_bytes >> 10);
Xiao Guangrongaecbfe92019-01-11 14:37:30 +0800261 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
262 info->ram->pages_per_second);
Chao Fan030ce1f2017-03-21 10:22:43 +0800263
Juan Quintela8d017192012-08-13 12:31:25 +0200264 if (info->ram->dirty_pages_rate) {
265 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
266 info->ram->dirty_pages_rate);
267 }
Dr. David Alan Gilbertd3bf5412016-06-13 12:16:42 +0100268 if (info->ram->postcopy_requests) {
269 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
270 info->ram->postcopy_requests);
271 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300272 }
273
274 if (info->has_disk) {
275 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
276 info->disk->transferred >> 10);
277 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
278 info->disk->remaining >> 10);
279 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
280 info->disk->total >> 10);
281 }
282
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300283 if (info->has_xbzrle_cache) {
284 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
285 info->xbzrle_cache->cache_size);
286 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
287 info->xbzrle_cache->bytes >> 10);
288 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
289 info->xbzrle_cache->pages);
290 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
291 info->xbzrle_cache->cache_miss);
ChenLiang8bc39232014-04-04 17:57:56 +0800292 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
293 info->xbzrle_cache->cache_miss_rate);
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300294 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
295 info->xbzrle_cache->overflow);
296 }
297
Xiao Guangrong76e03002018-09-06 15:01:00 +0800298 if (info->has_compression) {
299 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
300 info->compression->pages);
301 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
302 info->compression->busy);
303 monitor_printf(mon, "compression busy rate: %0.2f\n",
304 info->compression->busy_rate);
305 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
306 info->compression->compressed_size);
307 monitor_printf(mon, "compression rate: %0.2f\n",
308 info->compression->compression_rate);
309 }
310
Jason J. Herned85a31d2016-04-21 14:07:18 -0400311 if (info->has_cpu_throttle_percentage) {
Jason J. Herne47828932015-09-08 13:12:36 -0400312 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
Jason J. Herned85a31d2016-04-21 14:07:18 -0400313 info->cpu_throttle_percentage);
Jason J. Herne47828932015-09-08 13:12:36 -0400314 }
315
Alexey Perevalov65ace062018-03-22 21:17:27 +0300316 if (info->has_postcopy_blocktime) {
317 monitor_printf(mon, "postcopy blocktime: %u\n",
318 info->postcopy_blocktime);
319 }
320
321 if (info->has_postcopy_vcpu_blocktime) {
322 Visitor *v;
323 char *str;
324 v = string_output_visitor_new(false, &str);
325 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
326 visit_complete(v, &str);
327 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
328 g_free(str);
329 visit_free(v);
330 }
Juan Quintela9aca82b2019-02-27 11:51:27 +0100331 if (info->has_socket_address) {
332 SocketAddressList *addr;
333
334 monitor_printf(mon, "socket address: [\n");
335
336 for (addr = info->socket_address; addr; addr = addr->next) {
337 char *s = SocketAddress_to_str(addr->value);
338 monitor_printf(mon, "\t%s\n", s);
339 g_free(s);
340 }
341 monitor_printf(mon, "]\n");
342 }
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300343 qapi_free_MigrationInfo(info);
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300344 qapi_free_MigrationCapabilityStatusList(caps);
345}
346
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800347void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300348{
349 MigrationCapabilityStatusList *caps, *cap;
350
351 caps = qmp_query_migrate_capabilities(NULL);
352
353 if (caps) {
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300354 for (cap = caps; cap; cap = cap->next) {
Peter Xud80a0162017-04-01 16:18:44 +0800355 monitor_printf(mon, "%s: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200356 MigrationCapability_str(cap->value->capability),
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300357 cap->value->state ? "on" : "off");
358 }
Orit Wassermanbbf6da32012-08-06 21:42:47 +0300359 }
360
361 qapi_free_MigrationCapabilityStatusList(caps);
Luiz Capitulino791e7c82011-09-13 17:37:16 -0300362}
363
Liang Li50e9a622015-03-23 16:32:29 +0800364void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
365{
366 MigrationParameters *params;
367
368 params = qmp_query_migrate_parameters(NULL);
369
370 if (params) {
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +0000371 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
372 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
373 params->announce_initial);
374 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
375 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
376 params->announce_max);
377 monitor_printf(mon, "%s: %" PRIu64 "\n",
378 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
379 params->announce_rounds);
380 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
381 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
382 params->announce_step);
Eric Blakede63ab62016-09-08 22:14:15 -0500383 assert(params->has_compress_level);
Juan Quintela741d4082017-12-01 13:08:38 +0100384 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200385 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
Liang Li50e9a622015-03-23 16:32:29 +0800386 params->compress_level);
Eric Blakede63ab62016-09-08 22:14:15 -0500387 assert(params->has_compress_threads);
Juan Quintela741d4082017-12-01 13:08:38 +0100388 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200389 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
Liang Li50e9a622015-03-23 16:32:29 +0800390 params->compress_threads);
Xiao Guangrong1d588722018-08-21 16:10:20 +0800391 assert(params->has_compress_wait_thread);
392 monitor_printf(mon, "%s: %s\n",
393 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
394 params->compress_wait_thread ? "on" : "off");
Eric Blakede63ab62016-09-08 22:14:15 -0500395 assert(params->has_decompress_threads);
Juan Quintela741d4082017-12-01 13:08:38 +0100396 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200397 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
Liang Li50e9a622015-03-23 16:32:29 +0800398 params->decompress_threads);
Eric Blakede63ab62016-09-08 22:14:15 -0500399 assert(params->has_cpu_throttle_initial);
Juan Quintela741d4082017-12-01 13:08:38 +0100400 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200401 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
Jason J. Herned85a31d2016-04-21 14:07:18 -0400402 params->cpu_throttle_initial);
Eric Blakede63ab62016-09-08 22:14:15 -0500403 assert(params->has_cpu_throttle_increment);
Juan Quintela741d4082017-12-01 13:08:38 +0100404 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200405 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
Jason J. Herned85a31d2016-04-21 14:07:18 -0400406 params->cpu_throttle_increment);
Li Qiang4cbc9c72018-08-01 06:00:20 -0700407 assert(params->has_max_cpu_throttle);
408 monitor_printf(mon, "%s: %u\n",
409 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
410 params->max_cpu_throttle);
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200411 assert(params->has_tls_creds);
Peter Xu2c024682017-04-01 16:18:45 +0800412 monitor_printf(mon, "%s: '%s'\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200413 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200414 params->tls_creds);
415 assert(params->has_tls_hostname);
Peter Xu2c024682017-04-01 16:18:45 +0800416 monitor_printf(mon, "%s: '%s'\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200417 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
Markus Armbruster8cc99dc2017-07-18 12:04:54 +0200418 params->tls_hostname);
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530419 assert(params->has_max_bandwidth);
Juan Quintela741d4082017-12-01 13:08:38 +0100420 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200421 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530422 params->max_bandwidth);
423 assert(params->has_downtime_limit);
Juan Quintela741d4082017-12-01 13:08:38 +0100424 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200425 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
Ashijeet Acharya2ff30252016-09-15 21:50:28 +0530426 params->downtime_limit);
zhanghailiangfe39a4d2016-11-02 15:42:09 +0800427 assert(params->has_x_checkpoint_delay);
Juan Quintela741d4082017-12-01 13:08:38 +0100428 monitor_printf(mon, "%s: %u\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200429 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
zhanghailiang68b53592016-10-27 14:43:01 +0800430 params->x_checkpoint_delay);
Juan Quintela2833c592017-04-05 18:32:37 +0200431 assert(params->has_block_incremental);
432 monitor_printf(mon, "%s: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200433 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
434 params->block_incremental ? "on" : "off");
Juan Quintela741d4082017-12-01 13:08:38 +0100435 monitor_printf(mon, "%s: %u\n",
Juan Quintelacbfd6c92019-02-06 13:54:06 +0100436 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
437 params->multifd_channels);
Juan Quintela741d4082017-12-01 13:08:38 +0100438 monitor_printf(mon, "%s: %" PRIu64 "\n",
Juan Quintela73af8dd2017-10-05 21:30:10 +0200439 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
440 params->xbzrle_cache_size);
Dr. David Alan Gilbert7e555c62018-06-13 11:26:40 +0100441 monitor_printf(mon, "%s: %" PRIu64 "\n",
442 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
443 params->max_postcopy_bandwidth);
Liang Li50e9a622015-03-23 16:32:29 +0800444 }
445
446 qapi_free_MigrationParameters(params);
447}
448
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800449void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300450{
451 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
452 qmp_query_migrate_cache_size(NULL) >> 10);
453}
454
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800455void hmp_info_cpus(Monitor *mon, const QDict *qdict)
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300456{
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100457 CpuInfoFastList *cpu_list, *cpu;
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300458
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100459 cpu_list = qmp_query_cpus_fast(NULL);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300460
461 for (cpu = cpu_list; cpu; cpu = cpu->next) {
462 int active = ' ';
463
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100464 if (cpu->value->cpu_index == monitor_get_cpu_index()) {
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300465 active = '*';
466 }
467
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100468 monitor_printf(mon, "%c CPU #%" PRId64 ":", active,
469 cpu->value->cpu_index);
Satheesh Rajendran0dfddbb2018-03-27 18:08:00 +0530470 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300471 }
472
Viktor Mihajlovski137b5cb2018-02-16 17:08:41 +0100473 qapi_free_CpuInfoFastList(cpu_list);
Luiz Capitulinode0b36b2011-09-21 16:38:35 -0300474}
475
Kevin Wolf289b2762014-09-15 12:06:39 +0200476static void print_block_info(Monitor *mon, BlockInfo *info,
477 BlockDeviceInfo *inserted, bool verbose)
478{
479 ImageInfo *image_info;
480
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200481 assert(!info || !info->has_inserted || info->inserted == inserted);
482
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200483 if (info && *info->device) {
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200484 monitor_printf(mon, "%s", info->device);
485 if (inserted && inserted->has_node_name) {
486 monitor_printf(mon, " (%s)", inserted->node_name);
487 }
488 } else {
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200489 assert(info || inserted);
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200490 monitor_printf(mon, "%s",
Kevin Wolfec18b0a2017-07-11 14:00:57 +0200491 inserted && inserted->has_node_name ? inserted->node_name
492 : info && info->has_qdev ? info->qdev
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200493 : "<anonymous>");
494 }
495
Kevin Wolf289b2762014-09-15 12:06:39 +0200496 if (inserted) {
497 monitor_printf(mon, ": %s (%s%s%s)\n",
498 inserted->file,
499 inserted->drv,
500 inserted->ro ? ", read-only" : "",
501 inserted->encrypted ? ", encrypted" : "");
502 } else {
503 monitor_printf(mon, ": [not inserted]\n");
504 }
505
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200506 if (info) {
Kevin Wolf46eade72017-07-11 13:27:38 +0200507 if (info->has_qdev) {
508 monitor_printf(mon, " Attached to: %s\n", info->qdev);
509 }
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200510 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
511 monitor_printf(mon, " I/O status: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200512 BlockDeviceIoStatus_str(info->io_status));
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200513 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200514
Kevin Wolf8d6adcc2014-09-15 12:12:52 +0200515 if (info->removable) {
516 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
517 info->locked ? "" : "not ",
518 info->tray_open ? "open" : "closed");
519 }
Kevin Wolf289b2762014-09-15 12:06:39 +0200520 }
521
522
523 if (!inserted) {
524 return;
525 }
526
527 monitor_printf(mon, " Cache mode: %s%s%s\n",
528 inserted->cache->writeback ? "writeback" : "writethrough",
529 inserted->cache->direct ? ", direct" : "",
530 inserted->cache->no_flush ? ", ignore flushes" : "");
531
532 if (inserted->has_backing_file) {
533 monitor_printf(mon,
534 " Backing file: %s "
535 "(chain depth: %" PRId64 ")\n",
536 inserted->backing_file,
537 inserted->backing_file_depth);
538 }
539
540 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
541 monitor_printf(mon, " Detect zeroes: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200542 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes));
Kevin Wolf289b2762014-09-15 12:06:39 +0200543 }
544
545 if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
546 inserted->iops || inserted->iops_rd || inserted->iops_wr)
547 {
548 monitor_printf(mon, " I/O throttling: bps=%" PRId64
549 " bps_rd=%" PRId64 " bps_wr=%" PRId64
550 " bps_max=%" PRId64
551 " bps_rd_max=%" PRId64
552 " bps_wr_max=%" PRId64
553 " iops=%" PRId64 " iops_rd=%" PRId64
554 " iops_wr=%" PRId64
555 " iops_max=%" PRId64
556 " iops_rd_max=%" PRId64
557 " iops_wr_max=%" PRId64
Alberto Garciab8fe1692015-06-08 18:17:46 +0200558 " iops_size=%" PRId64
559 " group=%s\n",
Kevin Wolf289b2762014-09-15 12:06:39 +0200560 inserted->bps,
561 inserted->bps_rd,
562 inserted->bps_wr,
563 inserted->bps_max,
564 inserted->bps_rd_max,
565 inserted->bps_wr_max,
566 inserted->iops,
567 inserted->iops_rd,
568 inserted->iops_wr,
569 inserted->iops_max,
570 inserted->iops_rd_max,
571 inserted->iops_wr_max,
Alberto Garciab8fe1692015-06-08 18:17:46 +0200572 inserted->iops_size,
573 inserted->group);
Kevin Wolf289b2762014-09-15 12:06:39 +0200574 }
575
Stefan Hajnoczi94198742015-04-22 11:15:10 +0100576 if (verbose) {
Kevin Wolf289b2762014-09-15 12:06:39 +0200577 monitor_printf(mon, "\nImages:\n");
578 image_info = inserted->image;
579 while (1) {
580 bdrv_image_info_dump((fprintf_function)monitor_printf,
581 mon, image_info);
582 if (image_info->has_backing_image) {
583 image_info = image_info->backing_image;
584 } else {
585 break;
586 }
587 }
588 }
589}
590
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800591void hmp_info_block(Monitor *mon, const QDict *qdict)
Luiz Capitulinob2023812011-09-21 17:16:47 -0300592{
593 BlockInfoList *block_list, *info;
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200594 BlockDeviceInfoList *blockdev_list, *blockdev;
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800595 const char *device = qdict_get_try_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -0600596 bool verbose = qdict_get_try_bool(qdict, "verbose", false);
597 bool nodes = qdict_get_try_bool(qdict, "nodes", false);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200598 bool printed = false;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300599
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200600 /* Print BlockBackend information */
601 if (!nodes) {
Stefan Weilf19e44b2015-02-08 15:40:48 +0100602 block_list = qmp_query_block(NULL);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200603 } else {
604 block_list = NULL;
605 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300606
607 for (info = block_list; info; info = info->next) {
Wenchao Xiae73fe2b2013-06-06 12:28:01 +0800608 if (device && strcmp(device, info->value->device)) {
609 continue;
610 }
Luiz Capitulinob2023812011-09-21 17:16:47 -0300611
Kevin Wolffbe2e262013-06-19 16:10:55 +0200612 if (info != block_list) {
613 monitor_printf(mon, "\n");
Luiz Capitulinob2023812011-09-21 17:16:47 -0300614 }
615
Kevin Wolf289b2762014-09-15 12:06:39 +0200616 print_block_info(mon, info->value, info->value->has_inserted
617 ? info->value->inserted : NULL,
618 verbose);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200619 printed = true;
Luiz Capitulinob2023812011-09-21 17:16:47 -0300620 }
621
622 qapi_free_BlockInfoList(block_list);
Kevin Wolfe6bb31e2014-09-15 12:19:14 +0200623
624 if ((!device && !nodes) || printed) {
625 return;
626 }
627
628 /* Print node information */
629 blockdev_list = qmp_query_named_block_nodes(NULL);
630 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
631 assert(blockdev->value->has_node_name);
632 if (device && strcmp(device, blockdev->value->node_name)) {
633 continue;
634 }
635
636 if (blockdev != blockdev_list) {
637 monitor_printf(mon, "\n");
638 }
639
640 print_block_info(mon, NULL, blockdev->value, verbose);
641 }
642 qapi_free_BlockDeviceInfoList(blockdev_list);
Luiz Capitulinob2023812011-09-21 17:16:47 -0300643}
644
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800645void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300646{
647 BlockStatsList *stats_list, *stats;
648
Fam Zhengf71eaa72014-10-31 11:32:57 +0800649 stats_list = qmp_query_blockstats(false, false, NULL);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300650
651 for (stats = stats_list; stats; stats = stats->next) {
652 if (!stats->value->has_device) {
653 continue;
654 }
655
656 monitor_printf(mon, "%s:", stats->value->device);
657 monitor_printf(mon, " rd_bytes=%" PRId64
658 " wr_bytes=%" PRId64
659 " rd_operations=%" PRId64
660 " wr_operations=%" PRId64
661 " flush_operations=%" PRId64
662 " wr_total_time_ns=%" PRId64
663 " rd_total_time_ns=%" PRId64
664 " flush_total_time_ns=%" PRId64
Peter Lievenf4564d52015-02-02 14:52:18 +0100665 " rd_merged=%" PRId64
666 " wr_merged=%" PRId64
Alberto Garciacb38fff2015-10-28 17:33:02 +0200667 " idle_time_ns=%" PRId64
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300668 "\n",
669 stats->value->stats->rd_bytes,
670 stats->value->stats->wr_bytes,
671 stats->value->stats->rd_operations,
672 stats->value->stats->wr_operations,
673 stats->value->stats->flush_operations,
674 stats->value->stats->wr_total_time_ns,
675 stats->value->stats->rd_total_time_ns,
Peter Lievenf4564d52015-02-02 14:52:18 +0100676 stats->value->stats->flush_total_time_ns,
677 stats->value->stats->rd_merged,
Alberto Garciacb38fff2015-10-28 17:33:02 +0200678 stats->value->stats->wr_merged,
679 stats->value->stats->idle_time_ns);
Luiz Capitulinof11f57e2011-09-22 15:56:36 -0300680 }
681
682 qapi_free_BlockStatsList(stats_list);
683}
684
Marc-André Lureau05eb4a22018-07-03 17:56:47 +0200685#ifdef CONFIG_VNC
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100686/* Helper for hmp_info_vnc_clients, _servers */
687static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
688 const char *name)
689{
690 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
691 name,
692 info->host,
693 info->service,
Markus Armbruster977c7362017-08-24 10:46:08 +0200694 NetworkAddressFamily_str(info->family),
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100695 info->websocket ? " (Websocket)" : "");
696}
697
698/* Helper displaying and auth and crypt info */
699static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
700 VncPrimaryAuth auth,
701 VncVencryptSubAuth *vencrypt)
702{
703 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
Markus Armbruster977c7362017-08-24 10:46:08 +0200704 VncPrimaryAuth_str(auth),
705 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100706}
707
708static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
709{
710 while (client) {
711 VncClientInfo *cinfo = client->value;
712
713 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
714 monitor_printf(mon, " x509_dname: %s\n",
715 cinfo->has_x509_dname ?
716 cinfo->x509_dname : "none");
717 monitor_printf(mon, " sasl_username: %s\n",
718 cinfo->has_sasl_username ?
719 cinfo->sasl_username : "none");
720
721 client = client->next;
722 }
723}
724
725static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
726{
727 while (server) {
728 VncServerInfo2 *sinfo = server->value;
729 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
730 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
731 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
732 server = server->next;
733 }
734}
735
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800736void hmp_info_vnc(Monitor *mon, const QDict *qdict)
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200737{
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100738 VncInfo2List *info2l;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200739 Error *err = NULL;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200740
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100741 info2l = qmp_query_vnc_servers(&err);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200742 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +0800743 hmp_handle_error(mon, &err);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200744 return;
745 }
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100746 if (!info2l) {
747 monitor_printf(mon, "None\n");
748 return;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200749 }
750
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100751 while (info2l) {
752 VncInfo2 *info = info2l->value;
753 monitor_printf(mon, "%s:\n", info->id);
754 hmp_info_vnc_servers(mon, info->server);
755 hmp_info_vnc_clients(mon, info->clients);
756 if (!info->server) {
757 /* The server entry displays its auth, we only
758 * need to display in the case of 'reverse' connections
759 * where there's no server.
760 */
761 hmp_info_vnc_authcrypt(mon, " ", info->auth,
762 info->has_vencrypt ? &info->vencrypt : NULL);
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200763 }
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100764 if (info->has_display) {
765 monitor_printf(mon, " Display: %s\n", info->display);
766 }
767 info2l = info2l->next;
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200768 }
769
Dr. David Alan Gilbert0a9667e2017-07-11 16:44:14 +0100770 qapi_free_VncInfo2List(info2l);
771
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200772}
Marc-André Lureau05eb4a22018-07-03 17:56:47 +0200773#endif
Luiz Capitulino2b54aa82011-10-17 16:41:22 -0200774
Markus Armbruster206addd2015-01-13 15:46:39 +0100775#ifdef CONFIG_SPICE
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800776void hmp_info_spice(Monitor *mon, const QDict *qdict)
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200777{
778 SpiceChannelList *chan;
779 SpiceInfo *info;
Cole Robinson22fa7da2015-03-01 09:29:18 -0500780 const char *channel_name;
781 const char * const channel_names[] = {
782 [SPICE_CHANNEL_MAIN] = "main",
783 [SPICE_CHANNEL_DISPLAY] = "display",
784 [SPICE_CHANNEL_INPUTS] = "inputs",
785 [SPICE_CHANNEL_CURSOR] = "cursor",
786 [SPICE_CHANNEL_PLAYBACK] = "playback",
787 [SPICE_CHANNEL_RECORD] = "record",
788 [SPICE_CHANNEL_TUNNEL] = "tunnel",
789 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
790 [SPICE_CHANNEL_USBREDIR] = "usbredir",
791 [SPICE_CHANNEL_PORT] = "port",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100792#if 0
793 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
794 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
795 * as quick fix for build failures with older versions. */
Cole Robinson22fa7da2015-03-01 09:29:18 -0500796 [SPICE_CHANNEL_WEBDAV] = "webdav",
Gerd Hoffmann7c6044a2015-03-03 09:27:28 +0100797#endif
Cole Robinson22fa7da2015-03-01 09:29:18 -0500798 };
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200799
800 info = qmp_query_spice(NULL);
801
802 if (!info->enabled) {
803 monitor_printf(mon, "Server: disabled\n");
804 goto out;
805 }
806
807 monitor_printf(mon, "Server:\n");
808 if (info->has_port) {
809 monitor_printf(mon, " address: %s:%" PRId64 "\n",
810 info->host, info->port);
811 }
812 if (info->has_tls_port) {
813 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
814 info->host, info->tls_port);
815 }
Yonit Halperin61c4efe2012-08-21 11:51:58 +0300816 monitor_printf(mon, " migrated: %s\n",
817 info->migrated ? "true" : "false");
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200818 monitor_printf(mon, " auth: %s\n", info->auth);
819 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
Alon Levy4efee022012-03-29 23:23:14 +0200820 monitor_printf(mon, " mouse-mode: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +0200821 SpiceQueryMouseMode_str(info->mouse_mode));
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200822
823 if (!info->has_channels || info->channels == NULL) {
824 monitor_printf(mon, "Channels: none\n");
825 } else {
826 for (chan = info->channels; chan; chan = chan->next) {
827 monitor_printf(mon, "Channel:\n");
828 monitor_printf(mon, " address: %s:%s%s\n",
Eric Blakeddf21902015-10-26 16:34:49 -0600829 chan->value->host, chan->value->port,
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200830 chan->value->tls ? " [tls]" : "");
831 monitor_printf(mon, " session: %" PRId64 "\n",
832 chan->value->connection_id);
833 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
834 chan->value->channel_type, chan->value->channel_id);
Cole Robinson22fa7da2015-03-01 09:29:18 -0500835
836 channel_name = "unknown";
837 if (chan->value->channel_type > 0 &&
838 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
839 channel_names[chan->value->channel_type]) {
840 channel_name = channel_names[chan->value->channel_type];
841 }
842
843 monitor_printf(mon, " channel name: %s\n", channel_name);
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200844 }
845 }
846
847out:
848 qapi_free_SpiceInfo(info);
849}
Markus Armbruster206addd2015-01-13 15:46:39 +0100850#endif
Luiz Capitulinod1f29642011-10-20 17:01:33 -0200851
Wenchao Xia84f2d0e2013-01-14 14:06:25 +0800852void hmp_info_balloon(Monitor *mon, const QDict *qdict)
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200853{
854 BalloonInfo *info;
855 Error *err = NULL;
856
857 info = qmp_query_balloon(&err);
858 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +0800859 hmp_handle_error(mon, &err);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200860 return;
861 }
862
Luiz Capitulino01ceb972012-12-03 15:56:41 -0200863 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
Luiz Capitulino96637bc2011-10-21 11:41:37 -0200864
865 qapi_free_BalloonInfo(info);
866}
867
Luiz Capitulino79627472011-10-21 14:15:33 -0200868static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
869{
870 PciMemoryRegionList *region;
871
872 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
873 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
874 dev->slot, dev->function);
875 monitor_printf(mon, " ");
876
Eric Blake9fa02cd2015-05-04 09:05:32 -0600877 if (dev->class_info->has_desc) {
878 monitor_printf(mon, "%s", dev->class_info->desc);
Luiz Capitulino79627472011-10-21 14:15:33 -0200879 } else {
Eric Blake9fa02cd2015-05-04 09:05:32 -0600880 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
Luiz Capitulino79627472011-10-21 14:15:33 -0200881 }
882
883 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600884 dev->id->vendor, dev->id->device);
Denis V. Lunev18613dc2018-10-02 16:55:38 +0300885 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
886 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
887 dev->id->subsystem_vendor, dev->id->subsystem);
888 }
Luiz Capitulino79627472011-10-21 14:15:33 -0200889
890 if (dev->has_irq) {
891 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
892 }
893
894 if (dev->has_pci_bridge) {
895 monitor_printf(mon, " BUS %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600896 dev->pci_bridge->bus->number);
Luiz Capitulino79627472011-10-21 14:15:33 -0200897 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600898 dev->pci_bridge->bus->secondary);
Luiz Capitulino79627472011-10-21 14:15:33 -0200899 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600900 dev->pci_bridge->bus->subordinate);
Luiz Capitulino79627472011-10-21 14:15:33 -0200901
902 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600903 dev->pci_bridge->bus->io_range->base,
904 dev->pci_bridge->bus->io_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200905
906 monitor_printf(mon,
907 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600908 dev->pci_bridge->bus->memory_range->base,
909 dev->pci_bridge->bus->memory_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200910
911 monitor_printf(mon, " prefetchable memory range "
912 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
Eric Blake9fa02cd2015-05-04 09:05:32 -0600913 dev->pci_bridge->bus->prefetchable_range->base,
914 dev->pci_bridge->bus->prefetchable_range->limit);
Luiz Capitulino79627472011-10-21 14:15:33 -0200915 }
916
917 for (region = dev->regions; region; region = region->next) {
918 uint64_t addr, size;
919
920 addr = region->value->address;
921 size = region->value->size;
922
923 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
924
925 if (!strcmp(region->value->type, "io")) {
926 monitor_printf(mon, "I/O at 0x%04" PRIx64
927 " [0x%04" PRIx64 "].\n",
928 addr, addr + size - 1);
929 } else {
930 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
931 " [0x%08" PRIx64 "].\n",
932 region->value->mem_type_64 ? 64 : 32,
933 region->value->prefetch ? " prefetchable" : "",
934 addr, addr + size - 1);
935 }
936 }
937
938 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
939
940 if (dev->has_pci_bridge) {
941 if (dev->pci_bridge->has_devices) {
942 PciDeviceInfoList *cdev;
943 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
944 hmp_info_pci_device(mon, cdev->value);
945 }
946 }
947 }
948}
949
Hervé Poussineau61b97832016-09-26 22:23:27 +0200950static int hmp_info_irq_foreach(Object *obj, void *opaque)
951{
952 InterruptStatsProvider *intc;
953 InterruptStatsProviderClass *k;
954 Monitor *mon = opaque;
955
956 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
957 intc = INTERRUPT_STATS_PROVIDER(obj);
958 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
959 uint64_t *irq_counts;
960 unsigned int nb_irqs, i;
961 if (k->get_statistics &&
962 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
963 if (nb_irqs > 0) {
964 monitor_printf(mon, "IRQ statistics for %s:\n",
965 object_get_typename(obj));
966 for (i = 0; i < nb_irqs; i++) {
967 if (irq_counts[i] > 0) {
968 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
969 irq_counts[i]);
970 }
971 }
972 }
973 } else {
974 monitor_printf(mon, "IRQ statistics not available for %s.\n",
975 object_get_typename(obj));
976 }
977 }
978
979 return 0;
980}
981
982void hmp_info_irq(Monitor *mon, const QDict *qdict)
983{
984 object_child_foreach_recursive(object_get_root(),
985 hmp_info_irq_foreach, mon);
986}
987
988static int hmp_info_pic_foreach(Object *obj, void *opaque)
989{
990 InterruptStatsProvider *intc;
991 InterruptStatsProviderClass *k;
992 Monitor *mon = opaque;
993
994 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
995 intc = INTERRUPT_STATS_PROVIDER(obj);
996 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
997 if (k->print_info) {
998 k->print_info(intc, mon);
999 } else {
1000 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
1001 object_get_typename(obj));
1002 }
1003 }
1004
1005 return 0;
1006}
1007
1008void hmp_info_pic(Monitor *mon, const QDict *qdict)
1009{
1010 object_child_foreach_recursive(object_get_root(),
1011 hmp_info_pic_foreach, mon);
1012}
1013
Yuval Shaiaf4b2c022019-03-11 03:29:09 -07001014static int hmp_info_rdma_foreach(Object *obj, void *opaque)
1015{
1016 RdmaProvider *rdma;
1017 RdmaProviderClass *k;
1018 Monitor *mon = opaque;
1019
1020 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
1021 rdma = RDMA_PROVIDER(obj);
1022 k = RDMA_PROVIDER_GET_CLASS(obj);
1023 if (k->print_statistics) {
1024 k->print_statistics(mon, rdma);
1025 } else {
1026 monitor_printf(mon, "RDMA statistics not available for %s.\n",
1027 object_get_typename(obj));
1028 }
1029 }
1030
1031 return 0;
1032}
1033
1034void hmp_info_rdma(Monitor *mon, const QDict *qdict)
1035{
1036 object_child_foreach_recursive(object_get_root(),
1037 hmp_info_rdma_foreach, mon);
1038}
1039
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001040void hmp_info_pci(Monitor *mon, const QDict *qdict)
Luiz Capitulino79627472011-10-21 14:15:33 -02001041{
Stefan Bergerf46cee32012-01-11 10:51:52 -05001042 PciInfoList *info_list, *info;
Luiz Capitulino79627472011-10-21 14:15:33 -02001043 Error *err = NULL;
1044
Stefan Bergerf46cee32012-01-11 10:51:52 -05001045 info_list = qmp_query_pci(&err);
Luiz Capitulino79627472011-10-21 14:15:33 -02001046 if (err) {
1047 monitor_printf(mon, "PCI devices not supported\n");
1048 error_free(err);
1049 return;
1050 }
1051
Stefan Bergerf46cee32012-01-11 10:51:52 -05001052 for (info = info_list; info; info = info->next) {
Luiz Capitulino79627472011-10-21 14:15:33 -02001053 PciDeviceInfoList *dev;
1054
1055 for (dev = info->value->devices; dev; dev = dev->next) {
1056 hmp_info_pci_device(mon, dev->value);
1057 }
1058 }
1059
Stefan Bergerf46cee32012-01-11 10:51:52 -05001060 qapi_free_PciInfoList(info_list);
Luiz Capitulino79627472011-10-21 14:15:33 -02001061}
1062
Wenchao Xia84f2d0e2013-01-14 14:06:25 +08001063void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +00001064{
1065 BlockJobInfoList *list;
1066 Error *err = NULL;
1067
1068 list = qmp_query_block_jobs(&err);
1069 assert(!err);
1070
1071 if (!list) {
1072 monitor_printf(mon, "No active jobs\n");
1073 return;
1074 }
1075
1076 while (list) {
1077 if (strcmp(list->value->type, "stream") == 0) {
1078 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
1079 " of %" PRId64 " bytes, speed limit %" PRId64
1080 " bytes/s\n",
1081 list->value->device,
1082 list->value->offset,
1083 list->value->len,
1084 list->value->speed);
1085 } else {
1086 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
1087 " of %" PRId64 " bytes, speed limit %" PRId64
1088 " bytes/s\n",
1089 list->value->type,
1090 list->value->device,
1091 list->value->offset,
1092 list->value->len,
1093 list->value->speed);
1094 }
1095 list = list->next;
1096 }
Gonglei93bb1312014-09-16 21:36:55 +08001097
1098 qapi_free_BlockJobInfoList(list);
Stefan Hajnoczifb5458c2012-01-18 14:40:49 +00001099}
1100
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001101void hmp_info_tpm(Monitor *mon, const QDict *qdict)
1102{
1103 TPMInfoList *info_list, *info;
1104 Error *err = NULL;
1105 unsigned int c = 0;
1106 TPMPassthroughOptions *tpo;
Amarnath Vallurif4ede812017-09-29 14:10:20 +03001107 TPMEmulatorOptions *teo;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001108
1109 info_list = qmp_query_tpm(&err);
1110 if (err) {
1111 monitor_printf(mon, "TPM device not supported\n");
1112 error_free(err);
1113 return;
1114 }
1115
1116 if (info_list) {
1117 monitor_printf(mon, "TPM device:\n");
1118 }
1119
1120 for (info = info_list; info; info = info->next) {
1121 TPMInfo *ti = info->value;
1122 monitor_printf(mon, " tpm%d: model=%s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02001123 c, TpmModel_str(ti->model));
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001124
1125 monitor_printf(mon, " \\ %s: type=%s",
Markus Armbruster977c7362017-08-24 10:46:08 +02001126 ti->id, TpmTypeOptionsKind_str(ti->options->type));
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001127
Eric Blakece211312015-10-26 16:35:00 -06001128 switch (ti->options->type) {
Corey Bryant88ca7bc2013-03-20 12:34:48 -04001129 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
Eric Blake32bafa82016-03-17 16:48:37 -06001130 tpo = ti->options->u.passthrough.data;
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001131 monitor_printf(mon, "%s%s%s%s",
1132 tpo->has_path ? ",path=" : "",
1133 tpo->has_path ? tpo->path : "",
1134 tpo->has_cancel_path ? ",cancel-path=" : "",
1135 tpo->has_cancel_path ? tpo->cancel_path : "");
1136 break;
Amarnath Vallurif4ede812017-09-29 14:10:20 +03001137 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
1138 teo = ti->options->u.emulator.data;
1139 monitor_printf(mon, ",chardev=%s", teo->chardev);
1140 break;
Eric Blake7fb1cf12015-11-18 01:52:57 -07001141 case TPM_TYPE_OPTIONS_KIND__MAX:
Stefan Bergerd1a0cf72013-02-27 12:47:49 -05001142 break;
1143 }
1144 monitor_printf(mon, "\n");
1145 c++;
1146 }
1147 qapi_free_TPMInfoList(info_list);
1148}
1149
Luiz Capitulino7a7f3252011-09-15 14:20:28 -03001150void hmp_quit(Monitor *mon, const QDict *qdict)
1151{
1152 monitor_suspend(mon);
1153 qmp_quit(NULL);
1154}
Luiz Capitulino5f158f22011-09-15 14:34:39 -03001155
1156void hmp_stop(Monitor *mon, const QDict *qdict)
1157{
1158 qmp_stop(NULL);
1159}
Luiz Capitulino38d22652011-09-15 14:41:46 -03001160
Emilio G. Cotadd12e1b2018-08-15 16:00:03 -04001161void hmp_sync_profile(Monitor *mon, const QDict *qdict)
1162{
1163 const char *op = qdict_get_try_str(qdict, "op");
1164
1165 if (op == NULL) {
1166 bool on = qsp_is_enabled();
1167
1168 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
1169 return;
1170 }
1171 if (!strcmp(op, "on")) {
1172 qsp_enable();
1173 } else if (!strcmp(op, "off")) {
1174 qsp_disable();
1175 } else if (!strcmp(op, "reset")) {
1176 qsp_reset();
1177 } else {
1178 Error *err = NULL;
1179
1180 error_setg(&err, QERR_INVALID_PARAMETER, op);
1181 hmp_handle_error(mon, &err);
1182 }
1183}
1184
Luiz Capitulino38d22652011-09-15 14:41:46 -03001185void hmp_system_reset(Monitor *mon, const QDict *qdict)
1186{
1187 qmp_system_reset(NULL);
1188}
Luiz Capitulino5bc465e2011-09-28 11:06:15 -03001189
1190void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
1191{
1192 qmp_system_powerdown(NULL);
1193}
Luiz Capitulino755f1962011-10-06 14:31:39 -03001194
Dr. David Alan Gilbert8e8581e2018-06-20 16:39:46 +01001195void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
1196{
1197 Error *err = NULL;
1198
Markus Armbruster361ac942018-07-05 11:14:02 +02001199 qmp_x_exit_preconfig(&err);
Dr. David Alan Gilbert8e8581e2018-06-20 16:39:46 +01001200 hmp_handle_error(mon, &err);
1201}
1202
Luiz Capitulino755f1962011-10-06 14:31:39 -03001203void hmp_cpu(Monitor *mon, const QDict *qdict)
1204{
1205 int64_t cpu_index;
1206
1207 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
1208 use it are converted to the QAPI */
1209 cpu_index = qdict_get_int(qdict, "index");
1210 if (monitor_set_cpu(cpu_index) < 0) {
1211 monitor_printf(mon, "invalid CPU index\n");
1212 }
1213}
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001214
1215void hmp_memsave(Monitor *mon, const QDict *qdict)
1216{
1217 uint32_t size = qdict_get_int(qdict, "size");
1218 const char *filename = qdict_get_str(qdict, "filename");
1219 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +02001220 Error *err = NULL;
Thomas Huth854e67f2017-01-13 13:12:35 +01001221 int cpu_index = monitor_get_cpu_index();
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001222
Thomas Huth854e67f2017-01-13 13:12:35 +01001223 if (cpu_index < 0) {
1224 monitor_printf(mon, "No CPU available\n");
1225 return;
1226 }
1227
1228 qmp_memsave(addr, size, filename, true, cpu_index, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001229 hmp_handle_error(mon, &err);
Luiz Capitulino0cfd6a92011-11-22 16:32:37 -02001230}
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001231
1232void hmp_pmemsave(Monitor *mon, const QDict *qdict)
1233{
1234 uint32_t size = qdict_get_int(qdict, "size");
1235 const char *filename = qdict_get_str(qdict, "filename");
1236 uint64_t addr = qdict_get_int(qdict, "val");
Markus Armbrustere940f542014-05-02 13:26:29 +02001237 Error *err = NULL;
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001238
Markus Armbrustere940f542014-05-02 13:26:29 +02001239 qmp_pmemsave(addr, size, filename, &err);
1240 hmp_handle_error(mon, &err);
Luiz Capitulino6d3962b2011-11-22 17:26:46 -02001241}
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001242
Markus Armbruster3949e592013-02-06 21:27:24 +01001243void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
Lei Li1f590cf2013-01-25 00:03:20 +08001244{
Lei Li1f590cf2013-01-25 00:03:20 +08001245 const char *chardev = qdict_get_str(qdict, "device");
1246 const char *data = qdict_get_str(qdict, "data");
Markus Armbrustere940f542014-05-02 13:26:29 +02001247 Error *err = NULL;
Lei Li1f590cf2013-01-25 00:03:20 +08001248
Markus Armbrustere940f542014-05-02 13:26:29 +02001249 qmp_ringbuf_write(chardev, data, false, 0, &err);
Lei Li1f590cf2013-01-25 00:03:20 +08001250
Markus Armbrustere940f542014-05-02 13:26:29 +02001251 hmp_handle_error(mon, &err);
Lei Li1f590cf2013-01-25 00:03:20 +08001252}
1253
Markus Armbruster3949e592013-02-06 21:27:24 +01001254void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
Lei Li49b6d722013-01-25 00:03:21 +08001255{
1256 uint32_t size = qdict_get_int(qdict, "size");
1257 const char *chardev = qdict_get_str(qdict, "device");
Markus Armbruster3ab651f2013-02-06 21:27:15 +01001258 char *data;
Markus Armbrustere940f542014-05-02 13:26:29 +02001259 Error *err = NULL;
Markus Armbruster543f3412013-02-06 21:27:26 +01001260 int i;
Lei Li49b6d722013-01-25 00:03:21 +08001261
Markus Armbrustere940f542014-05-02 13:26:29 +02001262 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1263 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001264 hmp_handle_error(mon, &err);
Lei Li49b6d722013-01-25 00:03:21 +08001265 return;
1266 }
1267
Markus Armbruster543f3412013-02-06 21:27:26 +01001268 for (i = 0; data[i]; i++) {
1269 unsigned char ch = data[i];
1270
1271 if (ch == '\\') {
1272 monitor_printf(mon, "\\\\");
1273 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1274 monitor_printf(mon, "\\u%04X", ch);
1275 } else {
1276 monitor_printf(mon, "%c", ch);
1277 }
1278
1279 }
1280 monitor_printf(mon, "\n");
Markus Armbruster3ab651f2013-02-06 21:27:15 +01001281 g_free(data);
Lei Li49b6d722013-01-25 00:03:21 +08001282}
1283
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001284void hmp_cont(Monitor *mon, const QDict *qdict)
1285{
Markus Armbrustere940f542014-05-02 13:26:29 +02001286 Error *err = NULL;
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001287
Markus Armbrustere940f542014-05-02 13:26:29 +02001288 qmp_cont(&err);
1289 hmp_handle_error(mon, &err);
Luiz Capitulinoe42e8182011-11-22 17:58:31 -02001290}
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001291
Gerd Hoffmann9b9df252012-02-23 13:45:21 +01001292void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1293{
Daniel Henrique Barbozafb064112018-12-05 17:47:01 -02001294 Error *err = NULL;
1295
1296 qmp_system_wakeup(&err);
1297 hmp_handle_error(mon, &err);
Gerd Hoffmann9b9df252012-02-23 13:45:21 +01001298}
1299
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01001300void hmp_nmi(Monitor *mon, const QDict *qdict)
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001301{
Markus Armbrustere940f542014-05-02 13:26:29 +02001302 Error *err = NULL;
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001303
Markus Armbrustere940f542014-05-02 13:26:29 +02001304 qmp_inject_nmi(&err);
1305 hmp_handle_error(mon, &err);
Luiz Capitulinoab49ab52011-11-23 12:55:53 -02001306}
Luiz Capitulino4b371562011-11-23 13:11:55 -02001307
1308void hmp_set_link(Monitor *mon, const QDict *qdict)
1309{
1310 const char *name = qdict_get_str(qdict, "name");
Eric Blake34acbc92015-05-15 16:25:00 -06001311 bool up = qdict_get_bool(qdict, "up");
Markus Armbrustere940f542014-05-02 13:26:29 +02001312 Error *err = NULL;
Luiz Capitulino4b371562011-11-23 13:11:55 -02001313
Markus Armbrustere940f542014-05-02 13:26:29 +02001314 qmp_set_link(name, up, &err);
1315 hmp_handle_error(mon, &err);
Luiz Capitulino4b371562011-11-23 13:11:55 -02001316}
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001317
1318void hmp_block_passwd(Monitor *mon, const QDict *qdict)
1319{
1320 const char *device = qdict_get_str(qdict, "device");
1321 const char *password = qdict_get_str(qdict, "password");
Markus Armbrustere940f542014-05-02 13:26:29 +02001322 Error *err = NULL;
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001323
Markus Armbrustere940f542014-05-02 13:26:29 +02001324 qmp_block_passwd(true, device, false, NULL, password, &err);
1325 hmp_handle_error(mon, &err);
Luiz Capitulinoa4dea8a2011-11-23 13:28:21 -02001326}
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001327
1328void hmp_balloon(Monitor *mon, const QDict *qdict)
1329{
1330 int64_t value = qdict_get_int(qdict, "value");
Markus Armbrustere940f542014-05-02 13:26:29 +02001331 Error *err = NULL;
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001332
Markus Armbrustere940f542014-05-02 13:26:29 +02001333 qmp_balloon(value, &err);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001334 hmp_handle_error(mon, &err);
Luiz Capitulinod72f3262011-11-25 14:38:09 -02001335}
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001336
1337void hmp_block_resize(Monitor *mon, const QDict *qdict)
1338{
1339 const char *device = qdict_get_str(qdict, "device");
1340 int64_t size = qdict_get_int(qdict, "size");
Markus Armbrustere940f542014-05-02 13:26:29 +02001341 Error *err = NULL;
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001342
Markus Armbrustere940f542014-05-02 13:26:29 +02001343 qmp_block_resize(true, device, false, NULL, size, &err);
1344 hmp_handle_error(mon, &err);
Luiz Capitulino5e7caac2011-11-25 14:57:10 -02001345}
Luiz Capitulino6106e242011-11-25 16:15:19 -02001346
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001347void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
1348{
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001349 const char *filename = qdict_get_str(qdict, "target");
1350 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001351 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1352 bool full = qdict_get_try_bool(qdict, "full", false);
Markus Armbrustere940f542014-05-02 13:26:29 +02001353 Error *err = NULL;
Eric Blakefaecd402016-07-14 16:37:58 -06001354 DriveMirror mirror = {
1355 .device = (char *)qdict_get_str(qdict, "device"),
1356 .target = (char *)filename,
1357 .has_format = !!format,
1358 .format = (char *)format,
1359 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1360 .has_mode = true,
1361 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
1362 .unmap = true,
1363 };
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001364
1365 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001366 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Markus Armbrustere940f542014-05-02 13:26:29 +02001367 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001368 return;
1369 }
Eric Blakefaecd402016-07-14 16:37:58 -06001370 qmp_drive_mirror(&mirror, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001371 hmp_handle_error(mon, &err);
Paolo Bonzinid9b902d2012-10-18 16:49:24 +02001372}
1373
Stefan Hajnoczide909302013-06-26 14:11:58 +02001374void hmp_drive_backup(Monitor *mon, const QDict *qdict)
1375{
1376 const char *device = qdict_get_str(qdict, "device");
1377 const char *filename = qdict_get_str(qdict, "target");
1378 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001379 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
1380 bool full = qdict_get_try_bool(qdict, "full", false);
Pavel Butsykin13b94142016-07-22 11:17:52 +03001381 bool compress = qdict_get_try_bool(qdict, "compress", false);
Markus Armbrustere940f542014-05-02 13:26:29 +02001382 Error *err = NULL;
Pavel Butsykin81206a82016-07-22 11:17:50 +03001383 DriveBackup backup = {
1384 .device = (char *)device,
1385 .target = (char *)filename,
1386 .has_format = !!format,
1387 .format = (char *)format,
1388 .sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
1389 .has_mode = true,
1390 .mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS,
Pavel Butsykin13b94142016-07-22 11:17:52 +03001391 .has_compress = !!compress,
1392 .compress = compress,
Pavel Butsykin81206a82016-07-22 11:17:50 +03001393 };
Stefan Hajnoczide909302013-06-26 14:11:58 +02001394
1395 if (!filename) {
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001396 error_setg(&err, QERR_MISSING_PARAMETER, "target");
Markus Armbrustere940f542014-05-02 13:26:29 +02001397 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001398 return;
1399 }
1400
Pavel Butsykin81206a82016-07-22 11:17:50 +03001401 qmp_drive_backup(&backup, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02001402 hmp_handle_error(mon, &err);
Stefan Hajnoczide909302013-06-26 14:11:58 +02001403}
1404
Luiz Capitulino6106e242011-11-25 16:15:19 -02001405void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
1406{
1407 const char *device = qdict_get_str(qdict, "device");
1408 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
1409 const char *format = qdict_get_try_str(qdict, "format");
Eric Blake34acbc92015-05-15 16:25:00 -06001410 bool reuse = qdict_get_try_bool(qdict, "reuse", false);
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001411 enum NewImageMode mode;
Markus Armbrustere940f542014-05-02 13:26:29 +02001412 Error *err = NULL;
Luiz Capitulino6106e242011-11-25 16:15:19 -02001413
1414 if (!filename) {
1415 /* In the future, if 'snapshot-file' is not specified, the snapshot
1416 will be taken internally. Today it's actually required. */
Markus Armbrusterc6bd8c72015-03-17 11:54:50 +01001417 error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
Markus Armbrustere940f542014-05-02 13:26:29 +02001418 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001419 return;
1420 }
1421
Paolo Bonzini6cc2a412012-03-06 18:55:59 +01001422 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
Benoît Canet0901f672014-01-23 21:31:38 +01001423 qmp_blockdev_snapshot_sync(true, device, false, NULL,
1424 filename, false, NULL,
1425 !!format, format,
Markus Armbrustere940f542014-05-02 13:26:29 +02001426 true, mode, &err);
1427 hmp_handle_error(mon, &err);
Luiz Capitulino6106e242011-11-25 16:15:19 -02001428}
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001429
Wenchao Xia775ca882013-09-11 14:04:37 +08001430void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
1431{
1432 const char *device = qdict_get_str(qdict, "device");
1433 const char *name = qdict_get_str(qdict, "name");
Markus Armbrustere940f542014-05-02 13:26:29 +02001434 Error *err = NULL;
Wenchao Xia775ca882013-09-11 14:04:37 +08001435
Markus Armbrustere940f542014-05-02 13:26:29 +02001436 qmp_blockdev_snapshot_internal_sync(device, name, &err);
1437 hmp_handle_error(mon, &err);
Wenchao Xia775ca882013-09-11 14:04:37 +08001438}
1439
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001440void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
1441{
1442 const char *device = qdict_get_str(qdict, "device");
1443 const char *name = qdict_get_str(qdict, "name");
1444 const char *id = qdict_get_try_str(qdict, "id");
Markus Armbrustere940f542014-05-02 13:26:29 +02001445 Error *err = NULL;
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001446
1447 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
Markus Armbrustere940f542014-05-02 13:26:29 +02001448 true, name, &err);
1449 hmp_handle_error(mon, &err);
Wenchao Xia7a4ed2e2013-09-11 14:04:38 +08001450}
1451
Juan Quintela52b26202017-04-18 11:40:56 +02001452void hmp_loadvm(Monitor *mon, const QDict *qdict)
1453{
1454 int saved_vm_running = runstate_is_running();
1455 const char *name = qdict_get_str(qdict, "name");
Juan Quintela927d6632017-04-18 18:12:35 +02001456 Error *err = NULL;
Juan Quintela52b26202017-04-18 11:40:56 +02001457
1458 vm_stop(RUN_STATE_RESTORE_VM);
1459
Juan Quintela5e224792017-04-20 14:25:55 +02001460 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
Juan Quintela52b26202017-04-18 11:40:56 +02001461 vm_start();
1462 }
Juan Quintela927d6632017-04-18 18:12:35 +02001463 hmp_handle_error(mon, &err);
Juan Quintela52b26202017-04-18 11:40:56 +02001464}
1465
Juan Quintelad9c7d132017-04-18 11:44:16 +02001466void hmp_savevm(Monitor *mon, const QDict *qdict)
1467{
Juan Quintela927d6632017-04-18 18:12:35 +02001468 Error *err = NULL;
1469
Juan Quintela5e224792017-04-20 14:25:55 +02001470 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
Juan Quintela927d6632017-04-18 18:12:35 +02001471 hmp_handle_error(mon, &err);
Juan Quintelad9c7d132017-04-18 11:44:16 +02001472}
1473
Juan Quintelad905bb72017-04-18 11:46:23 +02001474void hmp_delvm(Monitor *mon, const QDict *qdict)
1475{
1476 BlockDriverState *bs;
zhangjixiang32cd6552018-02-25 09:47:51 +08001477 Error *err = NULL;
Juan Quintelad905bb72017-04-18 11:46:23 +02001478 const char *name = qdict_get_str(qdict, "name");
1479
1480 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1481 error_reportf_err(err,
1482 "Error while deleting snapshot on device '%s': ",
1483 bdrv_get_device_name(bs));
1484 }
1485}
1486
Juan Quintela66830612017-04-18 11:51:06 +02001487void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
1488{
1489 BlockDriverState *bs, *bs1;
1490 BdrvNextIterator it1;
1491 QEMUSnapshotInfo *sn_tab, *sn;
1492 bool no_snapshot = true;
1493 int nb_sns, i;
1494 int total;
1495 int *global_snapshots;
1496 AioContext *aio_context;
1497
1498 typedef struct SnapshotEntry {
1499 QEMUSnapshotInfo sn;
1500 QTAILQ_ENTRY(SnapshotEntry) next;
1501 } SnapshotEntry;
1502
1503 typedef struct ImageEntry {
1504 const char *imagename;
1505 QTAILQ_ENTRY(ImageEntry) next;
1506 QTAILQ_HEAD(, SnapshotEntry) snapshots;
1507 } ImageEntry;
1508
1509 QTAILQ_HEAD(, ImageEntry) image_list =
1510 QTAILQ_HEAD_INITIALIZER(image_list);
1511
1512 ImageEntry *image_entry, *next_ie;
1513 SnapshotEntry *snapshot_entry;
1514
1515 bs = bdrv_all_find_vmstate_bs();
1516 if (!bs) {
1517 monitor_printf(mon, "No available block device supports snapshots\n");
1518 return;
1519 }
1520 aio_context = bdrv_get_aio_context(bs);
1521
1522 aio_context_acquire(aio_context);
1523 nb_sns = bdrv_snapshot_list(bs, &sn_tab);
1524 aio_context_release(aio_context);
1525
1526 if (nb_sns < 0) {
1527 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
1528 return;
1529 }
1530
1531 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) {
1532 int bs1_nb_sns = 0;
1533 ImageEntry *ie;
1534 SnapshotEntry *se;
1535 AioContext *ctx = bdrv_get_aio_context(bs1);
1536
1537 aio_context_acquire(ctx);
1538 if (bdrv_can_snapshot(bs1)) {
1539 sn = NULL;
1540 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn);
1541 if (bs1_nb_sns > 0) {
1542 no_snapshot = false;
1543 ie = g_new0(ImageEntry, 1);
1544 ie->imagename = bdrv_get_device_name(bs1);
1545 QTAILQ_INIT(&ie->snapshots);
1546 QTAILQ_INSERT_TAIL(&image_list, ie, next);
1547 for (i = 0; i < bs1_nb_sns; i++) {
1548 se = g_new0(SnapshotEntry, 1);
1549 se->sn = sn[i];
1550 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next);
1551 }
1552 }
1553 g_free(sn);
1554 }
1555 aio_context_release(ctx);
1556 }
1557
1558 if (no_snapshot) {
1559 monitor_printf(mon, "There is no snapshot available.\n");
1560 return;
1561 }
1562
1563 global_snapshots = g_new0(int, nb_sns);
1564 total = 0;
1565 for (i = 0; i < nb_sns; i++) {
1566 SnapshotEntry *next_sn;
1567 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) {
1568 global_snapshots[total] = i;
1569 total++;
1570 QTAILQ_FOREACH(image_entry, &image_list, next) {
1571 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots,
1572 next, next_sn) {
1573 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) {
1574 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry,
1575 next);
1576 g_free(snapshot_entry);
1577 }
1578 }
1579 }
1580 }
1581 }
1582
1583 monitor_printf(mon, "List of snapshots present on all disks:\n");
1584
1585 if (total > 0) {
1586 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1587 monitor_printf(mon, "\n");
1588 for (i = 0; i < total; i++) {
1589 sn = &sn_tab[global_snapshots[i]];
1590 /* The ID is not guaranteed to be the same on all images, so
1591 * overwrite it.
1592 */
1593 pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
1594 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, sn);
1595 monitor_printf(mon, "\n");
1596 }
1597 } else {
1598 monitor_printf(mon, "None\n");
1599 }
1600
1601 QTAILQ_FOREACH(image_entry, &image_list, next) {
1602 if (QTAILQ_EMPTY(&image_entry->snapshots)) {
1603 continue;
1604 }
1605 monitor_printf(mon,
1606 "\nList of partial (non-loadable) snapshots on '%s':\n",
1607 image_entry->imagename);
1608 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon, NULL);
1609 monitor_printf(mon, "\n");
1610 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
1611 bdrv_snapshot_dump((fprintf_function)monitor_printf, mon,
1612 &snapshot_entry->sn);
1613 monitor_printf(mon, "\n");
1614 }
1615 }
1616
1617 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) {
1618 SnapshotEntry *next_sn;
1619 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next,
1620 next_sn) {
1621 g_free(snapshot_entry);
1622 }
1623 g_free(image_entry);
1624 }
1625 g_free(sn_tab);
1626 g_free(global_snapshots);
1627
1628}
1629
Dr. David Alan Gilbert544f6ea2019-02-27 13:24:12 +00001630void hmp_announce_self(Monitor *mon, const QDict *qdict)
1631{
1632 qmp_announce_self(migrate_announce_params(), NULL);
1633}
1634
Luiz Capitulino6cdedb02011-11-27 22:54:09 -02001635void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1636{
1637 qmp_migrate_cancel(NULL);
1638}
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001639
Dr. David Alan Gilbert94ae12c2017-10-20 10:05:54 +01001640void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1641{
1642 Error *err = NULL;
1643 const char *state = qdict_get_str(qdict, "state");
1644 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1645
1646 if (val >= 0) {
1647 qmp_migrate_continue(val, &err);
1648 }
1649
1650 hmp_handle_error(mon, &err);
1651}
1652
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001653void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1654{
1655 Error *err = NULL;
1656 const char *uri = qdict_get_str(qdict, "uri");
1657
1658 qmp_migrate_incoming(uri, &err);
1659
Dr. David Alan Gilbert1fa57f52015-02-26 14:54:39 +00001660 hmp_handle_error(mon, &err);
Dr. David Alan Gilbertbf1ae1f2015-02-19 11:40:28 +00001661}
1662
Peter Xu3b563c42018-05-02 18:47:37 +08001663void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1664{
1665 Error *err = NULL;
1666 const char *uri = qdict_get_str(qdict, "uri");
1667
1668 qmp_migrate_recover(uri, &err);
1669
1670 hmp_handle_error(mon, &err);
1671}
1672
Peter Xud37297d2018-05-02 18:47:40 +08001673void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1674{
1675 Error *err = NULL;
1676
1677 qmp_migrate_pause(&err);
1678
1679 hmp_handle_error(mon, &err);
1680}
1681
Ashijeet Acharya2ff30252016-09-15 21:50:28 +05301682/* Kept for backwards compatibility */
Luiz Capitulino4f0a9932011-11-27 23:18:01 -02001683void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1684{
1685 double value = qdict_get_double(qdict, "value");
1686 qmp_migrate_set_downtime(value, NULL);
1687}
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001688
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001689void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1690{
1691 int64_t value = qdict_get_int(qdict, "value");
1692 Error *err = NULL;
1693
1694 qmp_migrate_set_cache_size(value, &err);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001695 hmp_handle_error(mon, &err);
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +03001696}
1697
Ashijeet Acharya2ff30252016-09-15 21:50:28 +05301698/* Kept for backwards compatibility */
Luiz Capitulino3dc85382011-11-28 11:59:37 -02001699void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1700{
1701 int64_t value = qdict_get_int(qdict, "value");
1702 qmp_migrate_set_speed(value, NULL);
1703}
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001704
Orit Wasserman00458432012-08-06 21:42:48 +03001705void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1706{
1707 const char *cap = qdict_get_str(qdict, "capability");
1708 bool state = qdict_get_bool(qdict, "state");
1709 Error *err = NULL;
1710 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001711 int val;
Orit Wasserman00458432012-08-06 21:42:48 +03001712
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001713 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001714 if (val < 0) {
1715 goto end;
Orit Wasserman00458432012-08-06 21:42:48 +03001716 }
1717
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001718 caps->value = g_malloc0(sizeof(*caps->value));
1719 caps->value->capability = val;
1720 caps->value->state = state;
1721 caps->next = NULL;
1722 qmp_migrate_set_capabilities(caps, &err);
Orit Wasserman00458432012-08-06 21:42:48 +03001723
Marc-André Lureau8e615e32017-08-24 10:46:00 +02001724end:
Orit Wasserman00458432012-08-06 21:42:48 +03001725 qapi_free_MigrationCapabilityStatusList(caps);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001726 hmp_handle_error(mon, &err);
Orit Wasserman00458432012-08-06 21:42:48 +03001727}
1728
Liang Li50e9a622015-03-23 16:32:29 +08001729void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1730{
1731 const char *param = qdict_get_str(qdict, "parameter");
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001732 const char *valuestr = qdict_get_str(qdict, "value");
Juan Quintelaf4a06d12017-05-16 11:37:45 +02001733 Visitor *v = string_input_visitor_new(valuestr);
Markus Armbruster1bda8b32017-07-18 13:42:11 +02001734 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
Markus Armbrusterf46bfdb2017-02-21 21:14:07 +01001735 uint64_t valuebw = 0;
Juan Quintela73af8dd2017-10-05 21:30:10 +02001736 uint64_t cache_size;
Liang Li50e9a622015-03-23 16:32:29 +08001737 Error *err = NULL;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001738 int val, ret;
Liang Li50e9a622015-03-23 16:32:29 +08001739
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001740 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
Marc-André Lureau262517b2017-08-24 10:46:01 +02001741 if (val < 0) {
1742 goto cleanup;
1743 }
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001744
Marc-André Lureau262517b2017-08-24 10:46:01 +02001745 switch (val) {
1746 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1747 p->has_compress_level = true;
1748 visit_type_int(v, param, &p->compress_level, &err);
1749 break;
1750 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1751 p->has_compress_threads = true;
1752 visit_type_int(v, param, &p->compress_threads, &err);
1753 break;
Xiao Guangrong1d588722018-08-21 16:10:20 +08001754 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1755 p->has_compress_wait_thread = true;
1756 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1757 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001758 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1759 p->has_decompress_threads = true;
1760 visit_type_int(v, param, &p->decompress_threads, &err);
1761 break;
1762 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1763 p->has_cpu_throttle_initial = true;
1764 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1765 break;
1766 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1767 p->has_cpu_throttle_increment = true;
1768 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1769 break;
Li Qiang4cbc9c72018-08-01 06:00:20 -07001770 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1771 p->has_max_cpu_throttle = true;
1772 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1773 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001774 case MIGRATION_PARAMETER_TLS_CREDS:
1775 p->has_tls_creds = true;
1776 p->tls_creds = g_new0(StrOrNull, 1);
1777 p->tls_creds->type = QTYPE_QSTRING;
1778 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1779 break;
1780 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1781 p->has_tls_hostname = true;
1782 p->tls_hostname = g_new0(StrOrNull, 1);
1783 p->tls_hostname->type = QTYPE_QSTRING;
1784 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1785 break;
1786 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1787 p->has_max_bandwidth = true;
1788 /*
1789 * Can't use visit_type_size() here, because it
1790 * defaults to Bytes rather than Mebibytes.
1791 */
1792 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1793 if (ret < 0 || valuebw > INT64_MAX
1794 || (size_t)valuebw != valuebw) {
1795 error_setg(&err, "Invalid size %s", valuestr);
Liang Li50e9a622015-03-23 16:32:29 +08001796 break;
1797 }
Marc-André Lureau262517b2017-08-24 10:46:01 +02001798 p->max_bandwidth = valuebw;
1799 break;
1800 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1801 p->has_downtime_limit = true;
1802 visit_type_int(v, param, &p->downtime_limit, &err);
1803 break;
1804 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1805 p->has_x_checkpoint_delay = true;
1806 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1807 break;
1808 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1809 p->has_block_incremental = true;
1810 visit_type_bool(v, param, &p->block_incremental, &err);
1811 break;
Juan Quintelacbfd6c92019-02-06 13:54:06 +01001812 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1813 p->has_multifd_channels = true;
1814 visit_type_int(v, param, &p->multifd_channels, &err);
Juan Quintela4075fb12016-01-15 08:56:17 +01001815 break;
Juan Quintela73af8dd2017-10-05 21:30:10 +02001816 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1817 p->has_xbzrle_cache_size = true;
1818 visit_type_size(v, param, &cache_size, &err);
1819 if (err || cache_size > INT64_MAX
1820 || (size_t)cache_size != cache_size) {
1821 error_setg(&err, "Invalid size %s", valuestr);
1822 break;
1823 }
1824 p->xbzrle_cache_size = cache_size;
1825 break;
Dr. David Alan Gilbert7e555c62018-06-13 11:26:40 +01001826 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1827 p->has_max_postcopy_bandwidth = true;
1828 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1829 break;
Dr. David Alan Gilbertee3d96b2019-02-27 13:24:06 +00001830 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1831 p->has_announce_initial = true;
1832 visit_type_size(v, param, &p->announce_initial, &err);
1833 break;
1834 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1835 p->has_announce_max = true;
1836 visit_type_size(v, param, &p->announce_max, &err);
1837 break;
1838 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1839 p->has_announce_rounds = true;
1840 visit_type_size(v, param, &p->announce_rounds, &err);
1841 break;
1842 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1843 p->has_announce_step = true;
1844 visit_type_size(v, param, &p->announce_step, &err);
1845 break;
Marc-André Lureau262517b2017-08-24 10:46:01 +02001846 default:
1847 assert(0);
Liang Li50e9a622015-03-23 16:32:29 +08001848 }
1849
Marc-André Lureau262517b2017-08-24 10:46:01 +02001850 if (err) {
1851 goto cleanup;
Liang Li50e9a622015-03-23 16:32:29 +08001852 }
1853
Marc-André Lureau262517b2017-08-24 10:46:01 +02001854 qmp_migrate_set_parameters(p, &err);
1855
Daniel P. Berrange69ef1f32016-04-27 11:05:15 +01001856 cleanup:
Markus Armbruster1bda8b32017-07-18 13:42:11 +02001857 qapi_free_MigrateSetParameters(p);
Juan Quintelaf4a06d12017-05-16 11:37:45 +02001858 visit_free(v);
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08001859 hmp_handle_error(mon, &err);
Liang Li50e9a622015-03-23 16:32:29 +08001860}
1861
Markus Armbrusterb8a185b2015-03-05 17:29:02 +01001862void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1863{
1864 Error *err = NULL;
1865 const char *protocol = qdict_get_str(qdict, "protocol");
1866 const char *hostname = qdict_get_str(qdict, "hostname");
1867 bool has_port = qdict_haskey(qdict, "port");
1868 int port = qdict_get_try_int(qdict, "port", -1);
1869 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1870 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1871 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1872
1873 qmp_client_migrate_info(protocol, hostname,
1874 has_port, port, has_tls_port, tls_port,
1875 !!cert_subject, cert_subject, &err);
1876 hmp_handle_error(mon, &err);
1877}
1878
Dr. David Alan Gilbert4886a1b2015-11-05 18:10:56 +00001879void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1880{
1881 Error *err = NULL;
1882 qmp_migrate_start_postcopy(&err);
1883 hmp_handle_error(mon, &err);
1884}
1885
zhanghailiangd89e6662016-10-27 14:43:03 +08001886void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1887{
1888 Error *err = NULL;
1889
1890 qmp_x_colo_lost_heartbeat(&err);
1891 hmp_handle_error(mon, &err);
1892}
1893
Luiz Capitulinofbf796f2011-12-07 11:17:51 -02001894void hmp_set_password(Monitor *mon, const QDict *qdict)
1895{
1896 const char *protocol = qdict_get_str(qdict, "protocol");
1897 const char *password = qdict_get_str(qdict, "password");
1898 const char *connected = qdict_get_try_str(qdict, "connected");
1899 Error *err = NULL;
1900
1901 qmp_set_password(protocol, password, !!connected, connected, &err);
1902 hmp_handle_error(mon, &err);
1903}
Luiz Capitulino9ad53722011-12-07 11:47:57 -02001904
1905void hmp_expire_password(Monitor *mon, const QDict *qdict)
1906{
1907 const char *protocol = qdict_get_str(qdict, "protocol");
1908 const char *whenstr = qdict_get_str(qdict, "time");
1909 Error *err = NULL;
1910
1911 qmp_expire_password(protocol, whenstr, &err);
1912 hmp_handle_error(mon, &err);
1913}
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001914
1915void hmp_eject(Monitor *mon, const QDict *qdict)
1916{
Eric Blake34acbc92015-05-15 16:25:00 -06001917 bool force = qdict_get_try_bool(qdict, "force", false);
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001918 const char *device = qdict_get_str(qdict, "device");
1919 Error *err = NULL;
1920
Kevin Wolffbe2d812016-09-20 13:38:46 +02001921 qmp_eject(true, device, false, NULL, true, force, &err);
Luiz Capitulinoc245b6a2011-12-07 16:02:36 -02001922 hmp_handle_error(mon, &err);
1923}
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001924
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001925#ifdef CONFIG_VNC
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001926static void hmp_change_read_arg(void *opaque, const char *password,
1927 void *readline_opaque)
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001928{
1929 qmp_change_vnc_password(password, NULL);
Stefan Hajnoczic60bf332013-11-14 11:54:14 +01001930 monitor_read_command(opaque, 1);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001931}
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001932#endif
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001933
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001934void hmp_change(Monitor *mon, const QDict *qdict)
1935{
1936 const char *device = qdict_get_str(qdict, "device");
1937 const char *target = qdict_get_str(qdict, "target");
1938 const char *arg = qdict_get_try_str(qdict, "arg");
Max Reitzbaead0a2015-10-26 21:39:18 +01001939 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1940 BlockdevChangeReadOnlyMode read_only_mode = 0;
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001941 Error *err = NULL;
1942
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001943#ifdef CONFIG_VNC
Max Reitz10686742015-10-26 21:39:16 +01001944 if (strcmp(device, "vnc") == 0) {
Max Reitzbaead0a2015-10-26 21:39:18 +01001945 if (read_only) {
1946 monitor_printf(mon,
1947 "Parameter 'read-only-mode' is invalid for VNC\n");
1948 return;
1949 }
Max Reitz10686742015-10-26 21:39:16 +01001950 if (strcmp(target, "passwd") == 0 ||
1951 strcmp(target, "password") == 0) {
1952 if (!arg) {
1953 monitor_read_password(mon, hmp_change_read_arg, NULL);
1954 return;
1955 }
1956 }
1957 qmp_change("vnc", target, !!arg, arg, &err);
Marc-André Lureau05eb4a22018-07-03 17:56:47 +02001958 } else
1959#endif
1960 {
Max Reitzbaead0a2015-10-26 21:39:18 +01001961 if (read_only) {
1962 read_only_mode =
Marc-André Lureauf7abe0e2017-08-24 10:46:10 +02001963 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
Markus Armbruster06c60b62017-08-24 10:45:57 +02001964 read_only,
Max Reitzbaead0a2015-10-26 21:39:18 +01001965 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1966 if (err) {
1967 hmp_handle_error(mon, &err);
1968 return;
1969 }
1970 }
1971
Kevin Wolf70e2cb32016-09-20 13:38:47 +02001972 qmp_blockdev_change_medium(true, device, false, NULL, target,
1973 !!arg, arg, !!read_only, read_only_mode,
1974 &err);
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001975 }
1976
Luiz Capitulino333a96e2011-12-08 11:13:50 -02001977 hmp_handle_error(mon, &err);
1978}
Luiz Capitulino80047da2011-12-14 16:49:14 -02001979
1980void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1981{
1982 Error *err = NULL;
Alberto Garcia83592182018-03-09 16:11:07 +02001983 char *device = (char *) qdict_get_str(qdict, "device");
Eric Blake4dc93972016-07-13 21:50:21 -06001984 BlockIOThrottle throttle = {
Eric Blake4dc93972016-07-13 21:50:21 -06001985 .bps = qdict_get_int(qdict, "bps"),
1986 .bps_rd = qdict_get_int(qdict, "bps_rd"),
1987 .bps_wr = qdict_get_int(qdict, "bps_wr"),
1988 .iops = qdict_get_int(qdict, "iops"),
1989 .iops_rd = qdict_get_int(qdict, "iops_rd"),
1990 .iops_wr = qdict_get_int(qdict, "iops_wr"),
1991 };
Luiz Capitulino80047da2011-12-14 16:49:14 -02001992
Alberto Garcia83592182018-03-09 16:11:07 +02001993 /* qmp_block_set_io_throttle has separate parameters for the
1994 * (deprecated) block device name and the qdev ID but the HMP
1995 * version has only one, so we must decide which one to pass. */
1996 if (blk_by_name(device)) {
1997 throttle.has_device = true;
1998 throttle.device = device;
1999 } else {
2000 throttle.has_id = true;
2001 throttle.id = device;
2002 }
2003
Eric Blake4dc93972016-07-13 21:50:21 -06002004 qmp_block_set_io_throttle(&throttle, &err);
Luiz Capitulino80047da2011-12-14 16:49:14 -02002005 hmp_handle_error(mon, &err);
2006}
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002007
2008void hmp_block_stream(Monitor *mon, const QDict *qdict)
2009{
2010 Error *error = NULL;
2011 const char *device = qdict_get_str(qdict, "device");
2012 const char *base = qdict_get_try_str(qdict, "base");
Stefan Hajnoczic83c66c2012-04-25 16:51:03 +01002013 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002014
Alberto Garcia11d6fbe2016-11-04 15:44:43 +02002015 qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
John Snow241ca1a2018-09-06 09:02:23 -04002016 false, NULL, qdict_haskey(qdict, "speed"), speed, true,
2017 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
2018 &error);
Stefan Hajnoczi12bd4512012-01-18 14:40:46 +00002019
2020 hmp_handle_error(mon, &error);
2021}
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00002022
2023void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
2024{
2025 Error *error = NULL;
2026 const char *device = qdict_get_str(qdict, "device");
Paolo Bonzinic6db2392012-05-08 16:51:56 +02002027 int64_t value = qdict_get_int(qdict, "speed");
Stefan Hajnoczi2d47c6e2012-01-18 14:40:47 +00002028
2029 qmp_block_job_set_speed(device, value, &error);
2030
2031 hmp_handle_error(mon, &error);
2032}
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002033
2034void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
2035{
2036 Error *error = NULL;
2037 const char *device = qdict_get_str(qdict, "device");
Eric Blake34acbc92015-05-15 16:25:00 -06002038 bool force = qdict_get_try_bool(qdict, "force", false);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002039
Paolo Bonzini6e37fb82012-09-28 17:22:51 +02002040 qmp_block_job_cancel(device, true, force, &error);
2041
2042 hmp_handle_error(mon, &error);
2043}
2044
2045void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
2046{
2047 Error *error = NULL;
2048 const char *device = qdict_get_str(qdict, "device");
2049
2050 qmp_block_job_pause(device, &error);
2051
2052 hmp_handle_error(mon, &error);
2053}
2054
2055void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
2056{
2057 Error *error = NULL;
2058 const char *device = qdict_get_str(qdict, "device");
2059
2060 qmp_block_job_resume(device, &error);
Stefan Hajnoczi370521a2012-01-18 14:40:48 +00002061
2062 hmp_handle_error(mon, &error);
2063}
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002064
Paolo Bonziniaeae8832012-10-18 16:49:21 +02002065void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
2066{
2067 Error *error = NULL;
2068 const char *device = qdict_get_str(qdict, "device");
2069
2070 qmp_block_job_complete(device, &error);
2071
2072 hmp_handle_error(mon, &error);
2073}
2074
zhanghailiange49f35b2015-03-13 16:08:39 +08002075typedef struct HMPMigrationStatus
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002076{
2077 QEMUTimer *timer;
2078 Monitor *mon;
2079 bool is_block_migration;
zhanghailiange49f35b2015-03-13 16:08:39 +08002080} HMPMigrationStatus;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002081
2082static void hmp_migrate_status_cb(void *opaque)
2083{
zhanghailiange49f35b2015-03-13 16:08:39 +08002084 HMPMigrationStatus *status = opaque;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002085 MigrationInfo *info;
2086
2087 info = qmp_query_migrate(NULL);
zhanghailiang24b8c392015-03-13 16:08:40 +08002088 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
2089 info->status == MIGRATION_STATUS_SETUP) {
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002090 if (info->has_disk) {
2091 int progress;
2092
2093 if (info->disk->remaining) {
2094 progress = info->disk->transferred * 100 / info->disk->total;
2095 } else {
2096 progress = 100;
2097 }
2098
2099 monitor_printf(status->mon, "Completed %d %%\r", progress);
2100 monitor_flush(status->mon);
2101 }
2102
Alex Blighbc72ad62013-08-21 16:03:08 +01002103 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002104 } else {
2105 if (status->is_block_migration) {
2106 monitor_printf(status->mon, "\n");
2107 }
Daniel P. Berranged59ce6f2016-04-27 11:05:00 +01002108 if (info->has_error_desc) {
2109 error_report("%s", info->error_desc);
2110 }
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002111 monitor_resume(status->mon);
Alex Blighbc72ad62013-08-21 16:03:08 +01002112 timer_del(status->timer);
Marc-André Lureaud34a10a2018-09-01 15:46:52 +02002113 timer_free(status->timer);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002114 g_free(status);
2115 }
2116
2117 qapi_free_MigrationInfo(info);
2118}
2119
2120void hmp_migrate(Monitor *mon, const QDict *qdict)
2121{
Eric Blake34acbc92015-05-15 16:25:00 -06002122 bool detach = qdict_get_try_bool(qdict, "detach", false);
2123 bool blk = qdict_get_try_bool(qdict, "blk", false);
2124 bool inc = qdict_get_try_bool(qdict, "inc", false);
Peter Xu7a4da282018-05-02 18:47:23 +08002125 bool resume = qdict_get_try_bool(qdict, "resume", false);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002126 const char *uri = qdict_get_str(qdict, "uri");
2127 Error *err = NULL;
2128
Peter Xu7a4da282018-05-02 18:47:23 +08002129 qmp_migrate(uri, !!blk, blk, !!inc, inc,
2130 false, false, true, resume, &err);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002131 if (err) {
ZhiPeng Lu554a39e2017-10-19 19:16:33 +08002132 hmp_handle_error(mon, &err);
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002133 return;
2134 }
2135
2136 if (!detach) {
zhanghailiange49f35b2015-03-13 16:08:39 +08002137 HMPMigrationStatus *status;
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002138
2139 if (monitor_suspend(mon) < 0) {
2140 monitor_printf(mon, "terminal does not allow synchronous "
2141 "migration, continuing detached\n");
2142 return;
2143 }
2144
2145 status = g_malloc0(sizeof(*status));
2146 status->mon = mon;
2147 status->is_block_migration = blk || inc;
Alex Blighbc72ad62013-08-21 16:03:08 +01002148 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002149 status);
Alex Blighbc72ad62013-08-21 16:03:08 +01002150 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
Luiz Capitulinoe1c37d02011-12-05 14:48:01 -02002151 }
2152}
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03002153
Markus Armbruster318660f2015-03-05 17:24:48 +01002154void hmp_device_add(Monitor *mon, const QDict *qdict)
2155{
Markus Armbruster485febc2015-03-13 17:25:50 +01002156 Error *err = NULL;
2157
2158 qmp_device_add((QDict *)qdict, NULL, &err);
2159 hmp_handle_error(mon, &err);
Markus Armbruster318660f2015-03-05 17:24:48 +01002160}
2161
Luiz Capitulinoa15fef22012-03-29 12:38:50 -03002162void hmp_device_del(Monitor *mon, const QDict *qdict)
2163{
2164 const char *id = qdict_get_str(qdict, "id");
2165 Error *err = NULL;
2166
2167 qmp_device_del(id, &err);
2168 hmp_handle_error(mon, &err);
2169}
Wen Congyang783e9b42012-05-07 12:10:47 +08002170
2171void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
2172{
Markus Armbrustere940f542014-05-02 13:26:29 +02002173 Error *err = NULL;
Viktor Prutyanov2da91b52018-05-17 19:23:39 +03002174 bool win_dmp = qdict_get_try_bool(qdict, "windmp", false);
Eric Blake34acbc92015-05-15 16:25:00 -06002175 bool paging = qdict_get_try_bool(qdict, "paging", false);
2176 bool zlib = qdict_get_try_bool(qdict, "zlib", false);
2177 bool lzo = qdict_get_try_bool(qdict, "lzo", false);
2178 bool snappy = qdict_get_try_bool(qdict, "snappy", false);
Luiz Capitulino75363762012-09-21 13:53:00 -03002179 const char *file = qdict_get_str(qdict, "filename");
Wen Congyang783e9b42012-05-07 12:10:47 +08002180 bool has_begin = qdict_haskey(qdict, "begin");
2181 bool has_length = qdict_haskey(qdict, "length");
Peter Xu228de9c2016-02-18 13:16:47 +08002182 bool has_detach = qdict_haskey(qdict, "detach");
Wen Congyang783e9b42012-05-07 12:10:47 +08002183 int64_t begin = 0;
2184 int64_t length = 0;
Peter Xu228de9c2016-02-18 13:16:47 +08002185 bool detach = false;
qiaonuohanb53ccc32014-02-18 14:11:36 +08002186 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
Luiz Capitulino75363762012-09-21 13:53:00 -03002187 char *prot;
Wen Congyang783e9b42012-05-07 12:10:47 +08002188
Viktor Prutyanov2da91b52018-05-17 19:23:39 +03002189 if (zlib + lzo + snappy + win_dmp > 1) {
2190 error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
Markus Armbrustere940f542014-05-02 13:26:29 +02002191 hmp_handle_error(mon, &err);
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08002192 return;
2193 }
2194
Viktor Prutyanov2da91b52018-05-17 19:23:39 +03002195 if (win_dmp) {
2196 dump_format = DUMP_GUEST_MEMORY_FORMAT_WIN_DMP;
2197 }
2198
Qiao Nuohan1b7a0f72014-04-17 16:15:07 +08002199 if (zlib) {
2200 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
2201 }
2202
2203 if (lzo) {
2204 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
2205 }
2206
2207 if (snappy) {
2208 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
2209 }
2210
Wen Congyang783e9b42012-05-07 12:10:47 +08002211 if (has_begin) {
2212 begin = qdict_get_int(qdict, "begin");
2213 }
2214 if (has_length) {
2215 length = qdict_get_int(qdict, "length");
2216 }
Peter Xu228de9c2016-02-18 13:16:47 +08002217 if (has_detach) {
2218 detach = qdict_get_bool(qdict, "detach");
2219 }
Wen Congyang783e9b42012-05-07 12:10:47 +08002220
Luiz Capitulino75363762012-09-21 13:53:00 -03002221 prot = g_strconcat("file:", file, NULL);
2222
Peter Xu228de9c2016-02-18 13:16:47 +08002223 qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
2224 has_length, length, true, dump_format, &err);
Markus Armbrustere940f542014-05-02 13:26:29 +02002225 hmp_handle_error(mon, &err);
Luiz Capitulino75363762012-09-21 13:53:00 -03002226 g_free(prot);
Wen Congyang783e9b42012-05-07 12:10:47 +08002227}
Luiz Capitulino928059a2012-04-18 17:34:15 -03002228
2229void hmp_netdev_add(Monitor *mon, const QDict *qdict)
2230{
2231 Error *err = NULL;
2232 QemuOpts *opts;
2233
2234 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01002235 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03002236 goto out;
2237 }
2238
2239 netdev_add(opts, &err);
Markus Armbruster84d18f02014-01-30 15:07:28 +01002240 if (err) {
Luiz Capitulino928059a2012-04-18 17:34:15 -03002241 qemu_opts_del(opts);
2242 }
2243
2244out:
2245 hmp_handle_error(mon, &err);
2246}
Luiz Capitulino5f964152012-04-16 14:36:32 -03002247
2248void hmp_netdev_del(Monitor *mon, const QDict *qdict)
2249{
2250 const char *id = qdict_get_str(qdict, "id");
2251 Error *err = NULL;
2252
2253 qmp_netdev_del(id, &err);
2254 hmp_handle_error(mon, &err);
2255}
Corey Bryant208c9d12012-06-22 14:36:09 -04002256
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002257void hmp_object_add(Monitor *mon, const QDict *qdict)
2258{
2259 Error *err = NULL;
2260 QemuOpts *opts;
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002261 Object *obj = NULL;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002262
2263 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
2264 if (err) {
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002265 hmp_handle_error(mon, &err);
2266 return;
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002267 }
2268
Igor Mammedov3a464102017-01-10 13:53:14 +01002269 obj = user_creatable_add_opts(opts, &err);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002270 qemu_opts_del(opts);
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002271
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002272 if (err) {
2273 hmp_handle_error(mon, &err);
2274 }
2275 if (obj) {
2276 object_unref(obj);
2277 }
Paolo Bonzinicff8b2c2013-12-20 23:21:10 +01002278}
2279
Corey Bryant208c9d12012-06-22 14:36:09 -04002280void hmp_getfd(Monitor *mon, const QDict *qdict)
2281{
2282 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02002283 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04002284
Markus Armbrustere940f542014-05-02 13:26:29 +02002285 qmp_getfd(fdname, &err);
2286 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04002287}
2288
2289void hmp_closefd(Monitor *mon, const QDict *qdict)
2290{
2291 const char *fdname = qdict_get_str(qdict, "fdname");
Markus Armbrustere940f542014-05-02 13:26:29 +02002292 Error *err = NULL;
Corey Bryant208c9d12012-06-22 14:36:09 -04002293
Markus Armbrustere940f542014-05-02 13:26:29 +02002294 qmp_closefd(fdname, &err);
2295 hmp_handle_error(mon, &err);
Corey Bryant208c9d12012-06-22 14:36:09 -04002296}
Amos Konge4c8f002012-08-31 10:56:26 +08002297
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01002298void hmp_sendkey(Monitor *mon, const QDict *qdict)
Amos Konge4c8f002012-08-31 10:56:26 +08002299{
2300 const char *keys = qdict_get_str(qdict, "keys");
Luiz Capitulino9f328972012-09-20 14:19:47 -03002301 KeyValueList *keylist, *head = NULL, *tmp = NULL;
Amos Konge4c8f002012-08-31 10:56:26 +08002302 int has_hold_time = qdict_haskey(qdict, "hold-time");
2303 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
2304 Error *err = NULL;
Keno Fischer5c99fa32018-06-29 12:32:10 +02002305 const char *separator;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002306 int keyname_len;
Amos Konge4c8f002012-08-31 10:56:26 +08002307
2308 while (1) {
Keno Fischer5c99fa32018-06-29 12:32:10 +02002309 separator = qemu_strchrnul(keys, '-');
2310 keyname_len = separator - keys;
Amos Konge4c8f002012-08-31 10:56:26 +08002311
2312 /* Be compatible with old interface, convert user inputted "<" */
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002313 if (keys[0] == '<' && keyname_len == 1) {
2314 keys = "less";
Amos Konge4c8f002012-08-31 10:56:26 +08002315 keyname_len = 4;
2316 }
Amos Konge4c8f002012-08-31 10:56:26 +08002317
Amos Konge4c8f002012-08-31 10:56:26 +08002318 keylist = g_malloc0(sizeof(*keylist));
Luiz Capitulino9f328972012-09-20 14:19:47 -03002319 keylist->value = g_malloc0(sizeof(*keylist->value));
Amos Konge4c8f002012-08-31 10:56:26 +08002320
2321 if (!head) {
2322 head = keylist;
2323 }
2324 if (tmp) {
2325 tmp->next = keylist;
2326 }
2327 tmp = keylist;
2328
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002329 if (strstart(keys, "0x", NULL)) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002330 char *endp;
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002331 int value = strtoul(keys, &endp, 0);
2332 assert(endp <= keys + keyname_len);
2333 if (endp != keys + keyname_len) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002334 goto err_out;
2335 }
Eric Blake568c73a2015-10-26 16:34:58 -06002336 keylist->value->type = KEY_VALUE_KIND_NUMBER;
Eric Blake32bafa82016-03-17 16:48:37 -06002337 keylist->value->u.number.data = value;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002338 } else {
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002339 int idx = index_from_key(keys, keyname_len);
Eric Blake7fb1cf12015-11-18 01:52:57 -07002340 if (idx == Q_KEY_CODE__MAX) {
Luiz Capitulino9f328972012-09-20 14:19:47 -03002341 goto err_out;
2342 }
Eric Blake568c73a2015-10-26 16:34:58 -06002343 keylist->value->type = KEY_VALUE_KIND_QCODE;
Eric Blake32bafa82016-03-17 16:48:37 -06002344 keylist->value->u.qcode.data = idx;
Luiz Capitulino9f328972012-09-20 14:19:47 -03002345 }
2346
Keno Fischer5c99fa32018-06-29 12:32:10 +02002347 if (!*separator) {
Amos Konge4c8f002012-08-31 10:56:26 +08002348 break;
2349 }
2350 keys = separator + 1;
2351 }
2352
Luiz Capitulino9f328972012-09-20 14:19:47 -03002353 qmp_send_key(head, has_hold_time, hold_time, &err);
Amos Konge4c8f002012-08-31 10:56:26 +08002354 hmp_handle_error(mon, &err);
Luiz Capitulino9f328972012-09-20 14:19:47 -03002355
2356out:
2357 qapi_free_KeyValueList(head);
2358 return;
2359
2360err_out:
Wolfgang Bumiller64ffbe02016-01-13 09:09:58 +01002361 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
Luiz Capitulino9f328972012-09-20 14:19:47 -03002362 goto out;
Amos Konge4c8f002012-08-31 10:56:26 +08002363}
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002364
Markus Armbruster3e5a50d2015-02-06 13:55:43 +01002365void hmp_screendump(Monitor *mon, const QDict *qdict)
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002366{
2367 const char *filename = qdict_get_str(qdict, "filename");
Thomas Huthf771c542018-03-05 17:37:48 +01002368 const char *id = qdict_get_try_str(qdict, "device");
2369 int64_t head = qdict_get_try_int(qdict, "head", 0);
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002370 Error *err = NULL;
2371
Thomas Huthf771c542018-03-05 17:37:48 +01002372 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
Luiz Capitulinoad39cf62012-05-24 13:48:23 -03002373 hmp_handle_error(mon, &err);
2374}
Paolo Bonzini40577252012-08-23 11:53:04 +02002375
2376void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
2377{
2378 const char *uri = qdict_get_str(qdict, "uri");
Eric Blake34acbc92015-05-15 16:25:00 -06002379 bool writable = qdict_get_try_bool(qdict, "writable", false);
2380 bool all = qdict_get_try_bool(qdict, "all", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02002381 Error *local_err = NULL;
2382 BlockInfoList *block_list, *info;
Markus Armbrusterbd269eb2017-04-26 09:36:41 +02002383 SocketAddress *addr;
Paolo Bonzini40577252012-08-23 11:53:04 +02002384
2385 if (writable && !all) {
2386 error_setg(&local_err, "-w only valid together with -a");
2387 goto exit;
2388 }
2389
2390 /* First check if the address is valid and start the server. */
2391 addr = socket_parse(uri, &local_err);
2392 if (local_err != NULL) {
2393 goto exit;
2394 }
2395
Daniel P. Berrange00019452019-02-27 16:20:34 +00002396 nbd_server_start(addr, NULL, NULL, &local_err);
Markus Armbrusterbd269eb2017-04-26 09:36:41 +02002397 qapi_free_SocketAddress(addr);
Paolo Bonzini40577252012-08-23 11:53:04 +02002398 if (local_err != NULL) {
2399 goto exit;
2400 }
2401
2402 if (!all) {
2403 return;
2404 }
2405
2406 /* Then try adding all block devices. If one fails, close all and
2407 * exit.
2408 */
2409 block_list = qmp_query_block(NULL);
2410
2411 for (info = block_list; info; info = info->next) {
2412 if (!info->value->has_inserted) {
2413 continue;
2414 }
2415
Vladimir Sementsov-Ogievskiy902a1f92018-01-19 16:57:15 +03002416 qmp_nbd_server_add(info->value->device, false, NULL,
Eric Blake5fcbeb02019-01-11 13:47:17 -06002417 true, writable, false, NULL, &local_err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002418
2419 if (local_err != NULL) {
2420 qmp_nbd_server_stop(NULL);
2421 break;
2422 }
2423 }
2424
2425 qapi_free_BlockInfoList(block_list);
2426
2427exit:
2428 hmp_handle_error(mon, &local_err);
2429}
2430
2431void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
2432{
2433 const char *device = qdict_get_str(qdict, "device");
Eric Blakedba49322018-01-09 13:28:02 -06002434 const char *name = qdict_get_try_str(qdict, "name");
Eric Blake34acbc92015-05-15 16:25:00 -06002435 bool writable = qdict_get_try_bool(qdict, "writable", false);
Paolo Bonzini40577252012-08-23 11:53:04 +02002436 Error *local_err = NULL;
2437
Eric Blake5fcbeb02019-01-11 13:47:17 -06002438 qmp_nbd_server_add(device, !!name, name, true, writable,
2439 false, NULL, &local_err);
Eric Blake08fb10a2018-01-25 08:45:57 -06002440 hmp_handle_error(mon, &local_err);
2441}
Paolo Bonzini40577252012-08-23 11:53:04 +02002442
Eric Blake08fb10a2018-01-25 08:45:57 -06002443void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
2444{
2445 const char *name = qdict_get_str(qdict, "name");
2446 bool force = qdict_get_try_bool(qdict, "force", false);
2447 Error *err = NULL;
2448
2449 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
2450 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
2451 hmp_handle_error(mon, &err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002452}
2453
2454void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
2455{
Markus Armbrustere940f542014-05-02 13:26:29 +02002456 Error *err = NULL;
Paolo Bonzini40577252012-08-23 11:53:04 +02002457
Markus Armbrustere940f542014-05-02 13:26:29 +02002458 qmp_nbd_server_stop(&err);
2459 hmp_handle_error(mon, &err);
Paolo Bonzini40577252012-08-23 11:53:04 +02002460}
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002461
Jason J. Herneabf23322013-12-11 13:24:14 -05002462void hmp_cpu_add(Monitor *mon, const QDict *qdict)
2463{
2464 int cpuid;
2465 Error *err = NULL;
2466
Kashyap Chamarthye25701b2018-10-30 13:35:25 +01002467 error_report("cpu_add is deprecated, please use device_add instead");
2468
Jason J. Herneabf23322013-12-11 13:24:14 -05002469 cpuid = qdict_get_int(qdict, "id");
2470 qmp_cpu_add(cpuid, &err);
2471 hmp_handle_error(mon, &err);
2472}
2473
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002474void hmp_chardev_add(Monitor *mon, const QDict *qdict)
2475{
2476 const char *args = qdict_get_str(qdict, "args");
2477 Error *err = NULL;
2478 QemuOpts *opts;
2479
Markus Armbruster70b94332015-02-13 12:50:26 +01002480 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002481 if (opts == NULL) {
Markus Armbruster312fd5f2013-02-08 21:22:16 +01002482 error_setg(&err, "Parsing chardev args failed");
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002483 } else {
Paolo Bonzini4ad6f6c2019-02-13 14:18:13 +01002484 qemu_chr_new_from_opts(opts, NULL, &err);
Daniel P. Berrange0a733362016-10-07 13:18:34 +01002485 qemu_opts_del(opts);
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002486 }
2487 hmp_handle_error(mon, &err);
2488}
2489
Anton Nefedov75b60162017-07-06 15:08:57 +03002490void hmp_chardev_change(Monitor *mon, const QDict *qdict)
2491{
2492 const char *args = qdict_get_str(qdict, "args");
2493 const char *id;
2494 Error *err = NULL;
2495 ChardevBackend *backend = NULL;
2496 ChardevReturn *ret = NULL;
2497 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
2498 true);
2499 if (!opts) {
2500 error_setg(&err, "Parsing chardev args failed");
2501 goto end;
2502 }
2503
2504 id = qdict_get_str(qdict, "id");
2505 if (qemu_opts_id(opts)) {
2506 error_setg(&err, "Unexpected 'id' parameter");
2507 goto end;
2508 }
2509
2510 backend = qemu_chr_parse_opts(opts, &err);
2511 if (!backend) {
2512 goto end;
2513 }
2514
2515 ret = qmp_chardev_change(id, backend, &err);
2516
2517end:
2518 qapi_free_ChardevReturn(ret);
2519 qapi_free_ChardevBackend(backend);
2520 qemu_opts_del(opts);
2521 hmp_handle_error(mon, &err);
2522}
2523
Gerd Hoffmannf1088902012-12-19 10:33:40 +01002524void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
2525{
2526 Error *local_err = NULL;
2527
2528 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
2529 hmp_handle_error(mon, &local_err);
2530}
Kevin Wolf587da2c2013-06-05 14:19:41 +02002531
Stefan Fritschbd1d5ad2017-06-11 09:48:17 +02002532void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
2533{
2534 Error *local_err = NULL;
2535
2536 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
2537 hmp_handle_error(mon, &local_err);
2538}
2539
Kevin Wolf587da2c2013-06-05 14:19:41 +02002540void hmp_qemu_io(Monitor *mon, const QDict *qdict)
2541{
Max Reitz4c7b7e92015-02-05 13:58:22 -05002542 BlockBackend *blk;
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002543 BlockBackend *local_blk = NULL;
Kevin Wolf587da2c2013-06-05 14:19:41 +02002544 const char* device = qdict_get_str(qdict, "device");
2545 const char* command = qdict_get_str(qdict, "command");
2546 Error *err = NULL;
Kevin Wolfd7086422017-01-13 19:02:32 +01002547 int ret;
Kevin Wolf587da2c2013-06-05 14:19:41 +02002548
Max Reitz4c7b7e92015-02-05 13:58:22 -05002549 blk = blk_by_name(device);
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002550 if (!blk) {
2551 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err);
2552 if (bs) {
Kevin Wolf6d0eb642017-01-20 17:07:26 +01002553 blk = local_blk = blk_new(0, BLK_PERM_ALL);
Kevin Wolfd7086422017-01-13 19:02:32 +01002554 ret = blk_insert_bs(blk, bs, &err);
2555 if (ret < 0) {
2556 goto fail;
2557 }
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002558 } else {
2559 goto fail;
2560 }
2561 }
2562
Kevin Wolf887354b2017-02-10 16:24:56 +01002563 /*
2564 * Notably absent: Proper permission management. This is sad, but it seems
2565 * almost impossible to achieve without changing the semantics and thereby
2566 * limiting the use cases of the qemu-io HMP command.
2567 *
2568 * In an ideal world we would unconditionally create a new BlockBackend for
2569 * qemuio_command(), but we have commands like 'reopen' and want them to
2570 * take effect on the exact BlockBackend whose name the user passed instead
2571 * of just on a temporary copy of it.
2572 *
2573 * Another problem is that deleting the temporary BlockBackend involves
2574 * draining all requests on it first, but some qemu-iotests cases want to
2575 * issue multiple aio_read/write requests and expect them to complete in
2576 * the background while the monitor has already returned.
2577 *
2578 * This is also what prevents us from saving the original permissions and
2579 * restoring them later: We can't revoke permissions until all requests
2580 * have completed, and we don't know when that is nor can we really let
2581 * anything else run before we have revoken them to avoid race conditions.
2582 *
2583 * What happens now is that command() in qemu-io-cmds.c can extend the
2584 * permissions if necessary for the qemu-io command. And they simply stay
2585 * extended, possibly resulting in a read-only guest device keeping write
2586 * permissions. Ugly, but it appears to be the lesser evil.
2587 */
Kevin Wolf1813d332016-09-15 17:44:16 +02002588 qemuio_command(blk, command);
Vladimir Sementsov-Ogievskiy479b5992016-06-08 12:39:17 +03002589
Kevin Wolfe7f98f22016-07-13 17:27:51 +02002590fail:
2591 blk_unref(local_blk);
Kevin Wolf587da2c2013-06-05 14:19:41 +02002592 hmp_handle_error(mon, &err);
2593}
Paolo Bonziniab2d0532013-12-20 23:21:09 +01002594
2595void hmp_object_del(Monitor *mon, const QDict *qdict)
2596{
2597 const char *id = qdict_get_str(qdict, "id");
2598 Error *err = NULL;
2599
Daniel P. Berrange90998d52016-02-10 18:40:59 +00002600 user_creatable_del(id, &err);
Paolo Bonziniab2d0532013-12-20 23:21:09 +01002601 hmp_handle_error(mon, &err);
2602}
Hu Taoeb1539b2014-05-14 17:43:35 +08002603
2604void hmp_info_memdev(Monitor *mon, const QDict *qdict)
2605{
2606 Error *err = NULL;
2607 MemdevList *memdev_list = qmp_query_memdev(&err);
2608 MemdevList *m = memdev_list;
Eric Blake3b098d52016-06-09 10:48:43 -06002609 Visitor *v;
Chen Fan976620a2014-08-18 14:46:34 +08002610 char *str;
Hu Taoeb1539b2014-05-14 17:43:35 +08002611
2612 while (m) {
Eric Blake3b098d52016-06-09 10:48:43 -06002613 v = string_output_visitor_new(false, &str);
2614 visit_type_uint16List(v, NULL, &m->value->host_nodes, NULL);
Igor Mammedove1ff3c62017-01-10 13:53:15 +01002615 monitor_printf(mon, "memory backend: %s\n", m->value->id);
Hu Taoeb1539b2014-05-14 17:43:35 +08002616 monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
2617 monitor_printf(mon, " merge: %s\n",
2618 m->value->merge ? "true" : "false");
2619 monitor_printf(mon, " dump: %s\n",
2620 m->value->dump ? "true" : "false");
2621 monitor_printf(mon, " prealloc: %s\n",
2622 m->value->prealloc ? "true" : "false");
2623 monitor_printf(mon, " policy: %s\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02002624 HostMemPolicy_str(m->value->policy));
Eric Blake3b098d52016-06-09 10:48:43 -06002625 visit_complete(v, &str);
Chen Fan976620a2014-08-18 14:46:34 +08002626 monitor_printf(mon, " host nodes: %s\n", str);
Hu Taoeb1539b2014-05-14 17:43:35 +08002627
Chen Fan976620a2014-08-18 14:46:34 +08002628 g_free(str);
Eric Blake3b098d52016-06-09 10:48:43 -06002629 visit_free(v);
Hu Taoeb1539b2014-05-14 17:43:35 +08002630 m = m->next;
Hu Taoeb1539b2014-05-14 17:43:35 +08002631 }
2632
2633 monitor_printf(mon, "\n");
Chen Fanecaf54a2014-08-18 14:46:35 +08002634
2635 qapi_free_MemdevList(memdev_list);
Dr. David Alan Gilbert40c71f62017-08-17 11:42:15 +01002636 hmp_handle_error(mon, &err);
Hu Taoeb1539b2014-05-14 17:43:35 +08002637}
Zhu Guihuaa6318922014-09-23 13:35:19 +08002638
2639void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
2640{
2641 Error *err = NULL;
2642 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
2643 MemoryDeviceInfoList *info;
2644 MemoryDeviceInfo *value;
2645 PCDIMMDeviceInfo *di;
2646
2647 for (info = info_list; info; info = info->next) {
2648 value = info->value;
2649
2650 if (value) {
Eric Blake1fd5d4f2015-10-26 16:34:59 -06002651 switch (value->type) {
Zhu Guihuaa6318922014-09-23 13:35:19 +08002652 case MEMORY_DEVICE_INFO_KIND_DIMM:
Eric Blake32bafa82016-03-17 16:48:37 -06002653 di = value->u.dimm.data;
Haozhong Zhang6388e182018-03-11 11:02:12 +08002654 break;
Zhu Guihuaa6318922014-09-23 13:35:19 +08002655
Haozhong Zhang6388e182018-03-11 11:02:12 +08002656 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
2657 di = value->u.nvdimm.data;
2658 break;
2659
2660 default:
2661 di = NULL;
2662 break;
2663 }
2664
2665 if (di) {
Zhu Guihuaa6318922014-09-23 13:35:19 +08002666 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
Markus Armbruster977c7362017-08-24 10:46:08 +02002667 MemoryDeviceInfoKind_str(value->type),
Zhu Guihuaa6318922014-09-23 13:35:19 +08002668 di->id ? di->id : "");
2669 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
2670 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
2671 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
2672 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
2673 monitor_printf(mon, " memdev: %s\n", di->memdev);
2674 monitor_printf(mon, " hotplugged: %s\n",
2675 di->hotplugged ? "true" : "false");
2676 monitor_printf(mon, " hotpluggable: %s\n",
2677 di->hotpluggable ? "true" : "false");
Zhu Guihuaa6318922014-09-23 13:35:19 +08002678 }
2679 }
2680 }
2681
2682 qapi_free_MemoryDeviceInfoList(info_list);
Dr. David Alan Gilbert40c71f62017-08-17 11:42:15 +01002683 hmp_handle_error(mon, &err);
Zhu Guihuaa6318922014-09-23 13:35:19 +08002684}
Andreas Färber89d7fa92014-05-07 18:08:29 +02002685
Ting Wang62313162015-06-26 16:07:13 +08002686void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
2687{
2688 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
2689 IOThreadInfoList *info;
Pavel Hrdina5fc00482017-02-10 10:41:17 +01002690 IOThreadInfo *value;
Ting Wang62313162015-06-26 16:07:13 +08002691
2692 for (info = info_list; info; info = info->next) {
Pavel Hrdina5fc00482017-02-10 10:41:17 +01002693 value = info->value;
2694 monitor_printf(mon, "%s:\n", value->id);
2695 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
2696 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
2697 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
2698 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
Ting Wang62313162015-06-26 16:07:13 +08002699 }
2700
2701 qapi_free_IOThreadInfoList(info_list);
2702}
2703
Andreas Färber89d7fa92014-05-07 18:08:29 +02002704void hmp_qom_list(Monitor *mon, const QDict *qdict)
2705{
2706 const char *path = qdict_get_try_str(qdict, "path");
2707 ObjectPropertyInfoList *list;
2708 Error *err = NULL;
2709
2710 if (path == NULL) {
2711 monitor_printf(mon, "/\n");
2712 return;
2713 }
2714
2715 list = qmp_qom_list(path, &err);
2716 if (err == NULL) {
2717 ObjectPropertyInfoList *start = list;
2718 while (list != NULL) {
2719 ObjectPropertyInfo *value = list->value;
2720
2721 monitor_printf(mon, "%s (%s)\n",
2722 value->name, value->type);
2723 list = list->next;
2724 }
2725 qapi_free_ObjectPropertyInfoList(start);
2726 }
2727 hmp_handle_error(mon, &err);
2728}
Andreas Färberc0e6ee92014-05-07 19:48:15 +02002729
2730void hmp_qom_set(Monitor *mon, const QDict *qdict)
2731{
2732 const char *path = qdict_get_str(qdict, "path");
2733 const char *property = qdict_get_str(qdict, "property");
2734 const char *value = qdict_get_str(qdict, "value");
2735 Error *err = NULL;
2736 bool ambiguous = false;
2737 Object *obj;
2738
2739 obj = object_resolve_path(path, &ambiguous);
2740 if (obj == NULL) {
Markus Armbruster75158eb2015-03-16 08:57:47 +01002741 error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
2742 "Device '%s' not found", path);
Andreas Färberc0e6ee92014-05-07 19:48:15 +02002743 } else {
2744 if (ambiguous) {
2745 monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
2746 }
2747 object_property_parse(obj, value, property, &err);
2748 }
2749 hmp_handle_error(mon, &err);
2750}
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002751
2752void hmp_rocker(Monitor *mon, const QDict *qdict)
2753{
2754 const char *name = qdict_get_str(qdict, "name");
2755 RockerSwitch *rocker;
Markus Armbruster533fdae2015-12-18 16:35:27 +01002756 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002757
Markus Armbruster533fdae2015-12-18 16:35:27 +01002758 rocker = qmp_query_rocker(name, &err);
2759 if (err != NULL) {
2760 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002761 return;
2762 }
2763
2764 monitor_printf(mon, "name: %s\n", rocker->name);
2765 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
2766 monitor_printf(mon, "ports: %d\n", rocker->ports);
2767
2768 qapi_free_RockerSwitch(rocker);
2769}
2770
2771void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
2772{
2773 RockerPortList *list, *port;
2774 const char *name = qdict_get_str(qdict, "name");
Markus Armbruster533fdae2015-12-18 16:35:27 +01002775 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002776
Markus Armbruster533fdae2015-12-18 16:35:27 +01002777 list = qmp_query_rocker_ports(name, &err);
2778 if (err != NULL) {
2779 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002780 return;
2781 }
2782
2783 monitor_printf(mon, " ena/ speed/ auto\n");
2784 monitor_printf(mon, " port link duplex neg?\n");
2785
2786 for (port = list; port; port = port->next) {
2787 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
2788 port->value->name,
2789 port->value->enabled ? port->value->link_up ?
2790 "up" : "down" : "!ena",
2791 port->value->speed == 10000 ? "10G" : "??",
2792 port->value->duplex ? "FD" : "HD",
2793 port->value->autoneg ? "Yes" : "No");
2794 }
2795
2796 qapi_free_RockerPortList(list);
2797}
2798
2799void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
2800{
2801 RockerOfDpaFlowList *list, *info;
2802 const char *name = qdict_get_str(qdict, "name");
2803 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
Markus Armbruster533fdae2015-12-18 16:35:27 +01002804 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002805
Markus Armbruster533fdae2015-12-18 16:35:27 +01002806 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
2807 if (err != NULL) {
2808 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002809 return;
2810 }
2811
2812 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
2813
2814 for (info = list; info; info = info->next) {
2815 RockerOfDpaFlow *flow = info->value;
2816 RockerOfDpaFlowKey *key = flow->key;
2817 RockerOfDpaFlowMask *mask = flow->mask;
2818 RockerOfDpaFlowAction *action = flow->action;
2819
2820 if (flow->hits) {
2821 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
2822 key->priority, key->tbl_id, flow->hits);
2823 } else {
2824 monitor_printf(mon, "%-4d %-3d ",
2825 key->priority, key->tbl_id);
2826 }
2827
2828 if (key->has_in_pport) {
2829 monitor_printf(mon, " pport %d", key->in_pport);
2830 if (mask->has_in_pport) {
2831 monitor_printf(mon, "(0x%x)", mask->in_pport);
2832 }
2833 }
2834
2835 if (key->has_vlan_id) {
2836 monitor_printf(mon, " vlan %d",
2837 key->vlan_id & VLAN_VID_MASK);
2838 if (mask->has_vlan_id) {
2839 monitor_printf(mon, "(0x%x)", mask->vlan_id);
2840 }
2841 }
2842
2843 if (key->has_tunnel_id) {
2844 monitor_printf(mon, " tunnel %d", key->tunnel_id);
2845 if (mask->has_tunnel_id) {
2846 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
2847 }
2848 }
2849
2850 if (key->has_eth_type) {
2851 switch (key->eth_type) {
2852 case 0x0806:
2853 monitor_printf(mon, " ARP");
2854 break;
2855 case 0x0800:
2856 monitor_printf(mon, " IP");
2857 break;
2858 case 0x86dd:
2859 monitor_printf(mon, " IPv6");
2860 break;
2861 case 0x8809:
2862 monitor_printf(mon, " LACP");
2863 break;
2864 case 0x88cc:
2865 monitor_printf(mon, " LLDP");
2866 break;
2867 default:
2868 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
2869 break;
2870 }
2871 }
2872
2873 if (key->has_eth_src) {
2874 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
2875 (mask->has_eth_src) &&
2876 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2877 monitor_printf(mon, " src <any mcast/bcast>");
2878 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
2879 (mask->has_eth_src) &&
2880 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
2881 monitor_printf(mon, " src <any ucast>");
2882 } else {
2883 monitor_printf(mon, " src %s", key->eth_src);
2884 if (mask->has_eth_src) {
2885 monitor_printf(mon, "(%s)", mask->eth_src);
2886 }
2887 }
2888 }
2889
2890 if (key->has_eth_dst) {
2891 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2892 (mask->has_eth_dst) &&
2893 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2894 monitor_printf(mon, " dst <any mcast/bcast>");
2895 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2896 (mask->has_eth_dst) &&
2897 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2898 monitor_printf(mon, " dst <any ucast>");
2899 } else {
2900 monitor_printf(mon, " dst %s", key->eth_dst);
2901 if (mask->has_eth_dst) {
2902 monitor_printf(mon, "(%s)", mask->eth_dst);
2903 }
2904 }
2905 }
2906
2907 if (key->has_ip_proto) {
2908 monitor_printf(mon, " proto %d", key->ip_proto);
2909 if (mask->has_ip_proto) {
2910 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2911 }
2912 }
2913
2914 if (key->has_ip_tos) {
2915 monitor_printf(mon, " TOS %d", key->ip_tos);
2916 if (mask->has_ip_tos) {
2917 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2918 }
2919 }
2920
2921 if (key->has_ip_dst) {
2922 monitor_printf(mon, " dst %s", key->ip_dst);
2923 }
2924
2925 if (action->has_goto_tbl || action->has_group_id ||
2926 action->has_new_vlan_id) {
2927 monitor_printf(mon, " -->");
2928 }
2929
2930 if (action->has_new_vlan_id) {
2931 monitor_printf(mon, " apply new vlan %d",
2932 ntohs(action->new_vlan_id));
2933 }
2934
2935 if (action->has_group_id) {
2936 monitor_printf(mon, " write group 0x%08x", action->group_id);
2937 }
2938
2939 if (action->has_goto_tbl) {
2940 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2941 }
2942
2943 monitor_printf(mon, "\n");
2944 }
2945
2946 qapi_free_RockerOfDpaFlowList(list);
2947}
2948
2949void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2950{
2951 RockerOfDpaGroupList *list, *g;
2952 const char *name = qdict_get_str(qdict, "name");
2953 uint8_t type = qdict_get_try_int(qdict, "type", 9);
Markus Armbruster533fdae2015-12-18 16:35:27 +01002954 Error *err = NULL;
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002955 bool set = false;
2956
Markus Armbruster533fdae2015-12-18 16:35:27 +01002957 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2958 if (err != NULL) {
2959 hmp_handle_error(mon, &err);
Scott Feldmanfafa4d52015-06-10 18:21:21 -07002960 return;
2961 }
2962
2963 monitor_printf(mon, "id (decode) --> buckets\n");
2964
2965 for (g = list; g; g = g->next) {
2966 RockerOfDpaGroup *group = g->value;
2967
2968 monitor_printf(mon, "0x%08x", group->id);
2969
2970 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2971 group->type == 1 ? "L2 rewrite" :
2972 group->type == 2 ? "L3 unicast" :
2973 group->type == 3 ? "L2 multicast" :
2974 group->type == 4 ? "L2 flood" :
2975 group->type == 5 ? "L3 interface" :
2976 group->type == 6 ? "L3 multicast" :
2977 group->type == 7 ? "L3 ECMP" :
2978 group->type == 8 ? "L2 overlay" :
2979 "unknown");
2980
2981 if (group->has_vlan_id) {
2982 monitor_printf(mon, " vlan %d", group->vlan_id);
2983 }
2984
2985 if (group->has_pport) {
2986 monitor_printf(mon, " pport %d", group->pport);
2987 }
2988
2989 if (group->has_index) {
2990 monitor_printf(mon, " index %d", group->index);
2991 }
2992
2993 monitor_printf(mon, ") -->");
2994
2995 if (group->has_set_vlan_id && group->set_vlan_id) {
2996 set = true;
2997 monitor_printf(mon, " set vlan %d",
2998 group->set_vlan_id & VLAN_VID_MASK);
2999 }
3000
3001 if (group->has_set_eth_src) {
3002 if (!set) {
3003 set = true;
3004 monitor_printf(mon, " set");
3005 }
3006 monitor_printf(mon, " src %s", group->set_eth_src);
3007 }
3008
3009 if (group->has_set_eth_dst) {
3010 if (!set) {
3011 set = true;
3012 monitor_printf(mon, " set");
3013 }
3014 monitor_printf(mon, " dst %s", group->set_eth_dst);
3015 }
3016
3017 set = false;
3018
3019 if (group->has_ttl_check && group->ttl_check) {
3020 monitor_printf(mon, " check TTL");
3021 }
3022
3023 if (group->has_group_id && group->group_id) {
3024 monitor_printf(mon, " group id 0x%08x", group->group_id);
3025 }
3026
3027 if (group->has_pop_vlan && group->pop_vlan) {
3028 monitor_printf(mon, " pop vlan");
3029 }
3030
3031 if (group->has_out_pport) {
3032 monitor_printf(mon, " out pport %d", group->out_pport);
3033 }
3034
3035 if (group->has_group_ids) {
3036 struct uint32List *id;
3037
3038 monitor_printf(mon, " groups [");
3039 for (id = group->group_ids; id; id = id->next) {
3040 monitor_printf(mon, "0x%08x", id->value);
3041 if (id->next) {
3042 monitor_printf(mon, ",");
3043 }
3044 }
3045 monitor_printf(mon, "]");
3046 }
3047
3048 monitor_printf(mon, "\n");
3049 }
3050
3051 qapi_free_RockerOfDpaGroupList(list);
3052}
Peter Xu4a6b52d2016-02-18 13:16:55 +08003053
3054void hmp_info_dump(Monitor *mon, const QDict *qdict)
3055{
3056 DumpQueryResult *result = qmp_query_dump(NULL);
3057
3058 assert(result && result->status < DUMP_STATUS__MAX);
Markus Armbruster977c7362017-08-24 10:46:08 +02003059 monitor_printf(mon, "Status: %s\n", DumpStatus_str(result->status));
Peter Xu4a6b52d2016-02-18 13:16:55 +08003060
3061 if (result->status == DUMP_STATUS_ACTIVE) {
3062 float percent = 0;
3063 assert(result->total != 0);
3064 percent = 100.0 * result->completed / result->total;
3065 monitor_printf(mon, "Finished: %.2f %%\n", percent);
3066 }
3067
3068 qapi_free_DumpQueryResult(result);
3069}
Bharata B Raod2d8d462016-06-10 06:29:07 +05303070
Peter Xube9b23c2017-05-12 12:17:41 +08003071void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
3072{
3073 ram_block_dump(mon);
3074}
3075
Bharata B Raod2d8d462016-06-10 06:29:07 +05303076void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
3077{
3078 Error *err = NULL;
3079 HotpluggableCPUList *l = qmp_query_hotpluggable_cpus(&err);
3080 HotpluggableCPUList *saved = l;
3081 CpuInstanceProperties *c;
3082
3083 if (err != NULL) {
3084 hmp_handle_error(mon, &err);
3085 return;
3086 }
3087
3088 monitor_printf(mon, "Hotpluggable CPUs:\n");
3089 while (l) {
3090 monitor_printf(mon, " type: \"%s\"\n", l->value->type);
3091 monitor_printf(mon, " vcpus_count: \"%" PRIu64 "\"\n",
3092 l->value->vcpus_count);
3093 if (l->value->has_qom_path) {
3094 monitor_printf(mon, " qom_path: \"%s\"\n", l->value->qom_path);
3095 }
3096
3097 c = l->value->props;
3098 monitor_printf(mon, " CPUInstance Properties:\n");
Peter Krempa27393c32016-06-23 23:23:34 +02003099 if (c->has_node_id) {
3100 monitor_printf(mon, " node-id: \"%" PRIu64 "\"\n", c->node_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303101 }
Peter Krempa27393c32016-06-23 23:23:34 +02003102 if (c->has_socket_id) {
3103 monitor_printf(mon, " socket-id: \"%" PRIu64 "\"\n", c->socket_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303104 }
Peter Krempa27393c32016-06-23 23:23:34 +02003105 if (c->has_core_id) {
3106 monitor_printf(mon, " core-id: \"%" PRIu64 "\"\n", c->core_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303107 }
Peter Krempa27393c32016-06-23 23:23:34 +02003108 if (c->has_thread_id) {
3109 monitor_printf(mon, " thread-id: \"%" PRIu64 "\"\n", c->thread_id);
Bharata B Raod2d8d462016-06-10 06:29:07 +05303110 }
3111
3112 l = l->next;
3113 }
3114
3115 qapi_free_HotpluggableCPUList(saved);
3116}
Igor Mammedov39164c12017-02-16 15:15:37 -08003117
3118void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
3119{
Ben Warren72d91962017-03-02 13:36:50 -08003120 Error *err = NULL;
3121 GuidInfo *info = qmp_query_vm_generation_id(&err);
Igor Mammedov39164c12017-02-16 15:15:37 -08003122 if (info) {
3123 monitor_printf(mon, "%s\n", info->guid);
3124 }
Ben Warren72d91962017-03-02 13:36:50 -08003125 hmp_handle_error(mon, &err);
Igor Mammedov39164c12017-02-16 15:15:37 -08003126 qapi_free_GuidInfo(info);
3127}
Vadim Galitsynd0f63c12017-08-29 17:30:22 +02003128
3129void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
3130{
3131 Error *err = NULL;
3132 MemoryInfo *info = qmp_query_memory_size_summary(&err);
3133 if (info) {
3134 monitor_printf(mon, "base memory: %" PRIu64 "\n",
3135 info->base_memory);
3136
3137 if (info->has_plugged_memory) {
3138 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
3139 info->plugged_memory);
3140 }
3141
3142 qapi_free_MemoryInfo(info);
3143 }
3144 hmp_handle_error(mon, &err);
3145}