]> git.ipfire.org Git - thirdparty/qemu.git/blame - monitor/hmp-cmds.c
device_tree: Add info message when dumping dtb to file
[thirdparty/qemu.git] / monitor / hmp-cmds.c
CommitLineData
48a32bed 1/*
f1b3ccfa 2 * Human Monitor Interface commands
48a32bed
AL
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 *
6b620ca3
PB
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
48a32bed
AL
14 */
15
d38ea87a 16#include "qemu/osdep.h"
275307aa 17#include "monitor/hmp.h"
1422e32d 18#include "net/net.h"
fafa4d50 19#include "net/eth.h"
8228e353 20#include "chardev/char.h"
4c7b7e9b 21#include "sysemu/block-backend.h"
54d31236 22#include "sysemu/runstate.h"
213dcb06 23#include "qemu/config-file.h"
1de7afc9
PB
24#include "qemu/option.h"
25#include "qemu/timer.h"
1de7afc9 26#include "qemu/sockets.h"
5bce308a 27#include "monitor/monitor-internal.h"
e688df6b 28#include "qapi/error.h"
08528271 29#include "qapi/clone-visitor.h"
cff8b2c6 30#include "qapi/opts-visitor.h"
eb815e24 31#include "qapi/qapi-builtin-visit.h"
112ed241
MA
32#include "qapi/qapi-commands-block.h"
33#include "qapi/qapi-commands-char.h"
fa4dcf57 34#include "qapi/qapi-commands-control.h"
112ed241
MA
35#include "qapi/qapi-commands-migration.h"
36#include "qapi/qapi-commands-misc.h"
37#include "qapi/qapi-commands-net.h"
38#include "qapi/qapi-commands-rocker.h"
39#include "qapi/qapi-commands-run-state.h"
40#include "qapi/qapi-commands-tpm.h"
41#include "qapi/qapi-commands-ui.h"
08528271 42#include "qapi/qapi-visit-net.h"
96eef042 43#include "qapi/qapi-visit-migration.h"
452fcdbc 44#include "qapi/qmp/qdict.h"
cc7a8ea7 45#include "qapi/qmp/qerror.h"
f4a06d13 46#include "qapi/string-input-visitor.h"
eb1539b2 47#include "qapi/string-output-visitor.h"
90998d58 48#include "qom/object_interfaces.h"
28ecbaee 49#include "ui/console.h"
f348b6d1 50#include "qemu/cutils.h"
d59ce6f3 51#include "qemu/error-report.h"
be9b23c4 52#include "exec/ramlist.h"
61b97833 53#include "hw/intc/intc.h"
f4b2c02a 54#include "hw/rdma/rdma.h"
5e22479a 55#include "migration/snapshot.h"
9d18af93 56#include "migration/misc.h"
48a32bed 57
22fa7da0
CR
58#ifdef CONFIG_SPICE
59#include <spice/enums.h>
60#endif
61
187c6147 62void hmp_handle_error(Monitor *mon, Error *err)
0cfd6a9a 63{
187c6147
VSO
64 if (err) {
65 error_reportf_err(err, "Error: ");
0cfd6a9a
LC
66 }
67}
68
08528271
DDAG
69/*
70 * Produce a strList from a comma separated list.
71 * A NULL or empty input string return NULL.
72 */
73static strList *strList_from_comma_list(const char *in)
74{
75 strList *res = NULL;
76 strList **hook = &res;
77
78 while (in && in[0]) {
79 char *comma = strchr(in, ',');
80 *hook = g_new0(strList, 1);
81
82 if (comma) {
83 (*hook)->value = g_strndup(in, comma - in);
84 in = comma + 1; /* skip the , */
85 } else {
86 (*hook)->value = g_strdup(in);
87 in = NULL;
88 }
89 hook = &(*hook)->next;
90 }
91
92 return res;
93}
94
84f2d0ea 95void hmp_info_name(Monitor *mon, const QDict *qdict)
48a32bed
AL
96{
97 NameInfo *info;
98
99 info = qmp_query_name(NULL);
100 if (info->has_name) {
101 monitor_printf(mon, "%s\n", info->name);
102 }
103 qapi_free_NameInfo(info);
104}
b9c15f16 105
84f2d0ea 106void hmp_info_version(Monitor *mon, const QDict *qdict)
b9c15f16
LC
107{
108 VersionInfo *info;
109
110 info = qmp_query_version(NULL);
111
112 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
4752cdbb 113 info->qemu->major, info->qemu->minor, info->qemu->micro,
b9c15f16
LC
114 info->package);
115
116 qapi_free_VersionInfo(info);
117}
292a2602 118
84f2d0ea 119void hmp_info_kvm(Monitor *mon, const QDict *qdict)
292a2602
LC
120{
121 KvmInfo *info;
122
123 info = qmp_query_kvm(NULL);
124 monitor_printf(mon, "kvm support: ");
125 if (info->present) {
126 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
127 } else {
128 monitor_printf(mon, "not compiled\n");
129 }
130
131 qapi_free_KvmInfo(info);
132}
133
84f2d0ea 134void hmp_info_status(Monitor *mon, const QDict *qdict)
1fa9a5e4
LC
135{
136 StatusInfo *info;
137
138 info = qmp_query_status(NULL);
139
140 monitor_printf(mon, "VM status: %s%s",
141 info->running ? "running" : "paused",
142 info->singlestep ? " (single step mode)" : "");
143
144 if (!info->running && info->status != RUN_STATE_PAUSED) {
977c736f 145 monitor_printf(mon, " (%s)", RunState_str(info->status));
1fa9a5e4
LC
146 }
147
148 monitor_printf(mon, "\n");
149
150 qapi_free_StatusInfo(info);
151}
152
84f2d0ea 153void hmp_info_uuid(Monitor *mon, const QDict *qdict)
efab767e
LC
154{
155 UuidInfo *info;
156
157 info = qmp_query_uuid(NULL);
158 monitor_printf(mon, "%s\n", info->UUID);
159 qapi_free_UuidInfo(info);
160}
c5a415a0 161
84f2d0ea 162void hmp_info_chardev(Monitor *mon, const QDict *qdict)
c5a415a0
LC
163{
164 ChardevInfoList *char_info, *info;
165
166 char_info = qmp_query_chardev(NULL);
167 for (info = char_info; info; info = info->next) {
168 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
169 info->value->filename);
170 }
171
172 qapi_free_ChardevInfoList(char_info);
173}
7a7f325e 174
84f2d0ea 175void hmp_info_mice(Monitor *mon, const QDict *qdict)
e235cec3
LC
176{
177 MouseInfoList *mice_list, *mouse;
178
179 mice_list = qmp_query_mice(NULL);
180 if (!mice_list) {
181 monitor_printf(mon, "No mouse devices connected\n");
182 return;
183 }
184
185 for (mouse = mice_list; mouse; mouse = mouse->next) {
186 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
187 mouse->value->current ? '*' : ' ',
188 mouse->value->index, mouse->value->name,
189 mouse->value->absolute ? " (absolute)" : "");
190 }
191
192 qapi_free_MouseInfoList(mice_list);
193}
194
9aca82ba
JQ
195static char *SocketAddress_to_str(SocketAddress *addr)
196{
197 switch (addr->type) {
198 case SOCKET_ADDRESS_TYPE_INET:
199 return g_strdup_printf("tcp:%s:%s",
200 addr->u.inet.host,
201 addr->u.inet.port);
202 case SOCKET_ADDRESS_TYPE_UNIX:
203 return g_strdup_printf("unix:%s",
204 addr->u.q_unix.path);
205 case SOCKET_ADDRESS_TYPE_FD:
206 return g_strdup_printf("fd:%s", addr->u.fd.str);
207 case SOCKET_ADDRESS_TYPE_VSOCK:
208 return g_strdup_printf("tcp:%s:%s",
209 addr->u.vsock.cid,
210 addr->u.vsock.port);
211 default:
212 return g_strdup("unknown address type");
213 }
214}
215
84f2d0ea 216void hmp_info_migrate(Monitor *mon, const QDict *qdict)
791e7c82
LC
217{
218 MigrationInfo *info;
219
220 info = qmp_query_migrate(NULL);
bbf6da32 221
9d18af93
PX
222 migration_global_dump(mon);
223
791e7c82 224 if (info->has_status) {
d59ce6f3 225 monitor_printf(mon, "Migration status: %s",
977c736f 226 MigrationStatus_str(info->status));
d59ce6f3
DB
227 if (info->status == MIGRATION_STATUS_FAILED &&
228 info->has_error_desc) {
229 monitor_printf(mon, " (%s)\n", info->error_desc);
230 } else {
231 monitor_printf(mon, "\n");
232 }
233
7aa939af
JQ
234 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
235 info->total_time);
2c52ddf1
JQ
236 if (info->has_expected_downtime) {
237 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
238 info->expected_downtime);
239 }
9c5a9fcf
JQ
240 if (info->has_downtime) {
241 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
242 info->downtime);
243 }
ed4fbd10
MH
244 if (info->has_setup_time) {
245 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
246 info->setup_time);
247 }
791e7c82
LC
248 }
249
250 if (info->has_ram) {
251 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
252 info->ram->transferred >> 10);
7e114f8c
MH
253 monitor_printf(mon, "throughput: %0.2f mbps\n",
254 info->ram->mbps);
791e7c82
LC
255 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
256 info->ram->remaining >> 10);
257 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
258 info->ram->total >> 10);
004d4c10
OW
259 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
260 info->ram->duplicate);
f1c72795
PL
261 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
262 info->ram->skipped);
004d4c10
OW
263 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
264 info->ram->normal);
265 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
266 info->ram->normal_bytes >> 10);
58570ed8
C
267 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
268 info->ram->dirty_sync_count);
030ce1f8
CF
269 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
270 info->ram->page_size >> 10);
a61c45bd
JQ
271 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
272 info->ram->multifd_bytes >> 10);
aecbfe9c
XG
273 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
274 info->ram->pages_per_second);
030ce1f8 275
8d017193
JQ
276 if (info->ram->dirty_pages_rate) {
277 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
278 info->ram->dirty_pages_rate);
279 }
d3bf5418
DDAG
280 if (info->ram->postcopy_requests) {
281 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
282 info->ram->postcopy_requests);
283 }
791e7c82
LC
284 }
285
286 if (info->has_disk) {
287 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
288 info->disk->transferred >> 10);
289 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
290 info->disk->remaining >> 10);
291 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
292 info->disk->total >> 10);
293 }
294
f36d55af
OW
295 if (info->has_xbzrle_cache) {
296 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
297 info->xbzrle_cache->cache_size);
298 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
299 info->xbzrle_cache->bytes >> 10);
300 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
301 info->xbzrle_cache->pages);
302 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
303 info->xbzrle_cache->cache_miss);
8bc39233
C
304 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
305 info->xbzrle_cache->cache_miss_rate);
f36d55af
OW
306 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
307 info->xbzrle_cache->overflow);
308 }
309
76e03000
XG
310 if (info->has_compression) {
311 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n",
312 info->compression->pages);
313 monitor_printf(mon, "compression busy: %" PRIu64 "\n",
314 info->compression->busy);
315 monitor_printf(mon, "compression busy rate: %0.2f\n",
316 info->compression->busy_rate);
317 monitor_printf(mon, "compressed size: %" PRIu64 "\n",
318 info->compression->compressed_size);
319 monitor_printf(mon, "compression rate: %0.2f\n",
320 info->compression->compression_rate);
321 }
322
d85a31d1 323 if (info->has_cpu_throttle_percentage) {
4782893e 324 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
d85a31d1 325 info->cpu_throttle_percentage);
4782893e
JH
326 }
327
65ace060
AP
328 if (info->has_postcopy_blocktime) {
329 monitor_printf(mon, "postcopy blocktime: %u\n",
330 info->postcopy_blocktime);
331 }
332
333 if (info->has_postcopy_vcpu_blocktime) {
334 Visitor *v;
335 char *str;
336 v = string_output_visitor_new(false, &str);
337 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL);
338 visit_complete(v, &str);
339 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str);
340 g_free(str);
341 visit_free(v);
342 }
9aca82ba
JQ
343 if (info->has_socket_address) {
344 SocketAddressList *addr;
345
346 monitor_printf(mon, "socket address: [\n");
347
348 for (addr = info->socket_address; addr; addr = addr->next) {
349 char *s = SocketAddress_to_str(addr->value);
350 monitor_printf(mon, "\t%s\n", s);
351 g_free(s);
352 }
353 monitor_printf(mon, "]\n");
354 }
791e7c82 355 qapi_free_MigrationInfo(info);
bbf6da32
OW
356}
357
84f2d0ea 358void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
bbf6da32
OW
359{
360 MigrationCapabilityStatusList *caps, *cap;
361
362 caps = qmp_query_migrate_capabilities(NULL);
363
364 if (caps) {
bbf6da32 365 for (cap = caps; cap; cap = cap->next) {
d80a0169 366 monitor_printf(mon, "%s: %s\n",
977c736f 367 MigrationCapability_str(cap->value->capability),
bbf6da32
OW
368 cap->value->state ? "on" : "off");
369 }
bbf6da32
OW
370 }
371
372 qapi_free_MigrationCapabilityStatusList(caps);
791e7c82
LC
373}
374
50e9a629
LL
375void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
376{
377 MigrationParameters *params;
378
379 params = qmp_query_migrate_parameters(NULL);
380
381 if (params) {
ee3d96ba
DDAG
382 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
383 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
384 params->announce_initial);
385 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
386 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
387 params->announce_max);
388 monitor_printf(mon, "%s: %" PRIu64 "\n",
389 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
390 params->announce_rounds);
391 monitor_printf(mon, "%s: %" PRIu64 " ms\n",
392 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
393 params->announce_step);
de63ab61 394 assert(params->has_compress_level);
741d4086 395 monitor_printf(mon, "%s: %u\n",
977c736f 396 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
50e9a629 397 params->compress_level);
de63ab61 398 assert(params->has_compress_threads);
741d4086 399 monitor_printf(mon, "%s: %u\n",
977c736f 400 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
50e9a629 401 params->compress_threads);
1d58872a
XG
402 assert(params->has_compress_wait_thread);
403 monitor_printf(mon, "%s: %s\n",
404 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD),
405 params->compress_wait_thread ? "on" : "off");
de63ab61 406 assert(params->has_decompress_threads);
741d4086 407 monitor_printf(mon, "%s: %u\n",
977c736f 408 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
50e9a629 409 params->decompress_threads);
dc14a470
KZ
410 assert(params->has_throttle_trigger_threshold);
411 monitor_printf(mon, "%s: %u\n",
412 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
413 params->throttle_trigger_threshold);
de63ab61 414 assert(params->has_cpu_throttle_initial);
741d4086 415 monitor_printf(mon, "%s: %u\n",
977c736f 416 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
d85a31d1 417 params->cpu_throttle_initial);
de63ab61 418 assert(params->has_cpu_throttle_increment);
741d4086 419 monitor_printf(mon, "%s: %u\n",
977c736f 420 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
d85a31d1 421 params->cpu_throttle_increment);
4cbc9c7f
LQ
422 assert(params->has_max_cpu_throttle);
423 monitor_printf(mon, "%s: %u\n",
424 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
425 params->max_cpu_throttle);
8cc99dcd 426 assert(params->has_tls_creds);
2c02468c 427 monitor_printf(mon, "%s: '%s'\n",
977c736f 428 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
8cc99dcd
MA
429 params->tls_creds);
430 assert(params->has_tls_hostname);
2c02468c 431 monitor_printf(mon, "%s: '%s'\n",
977c736f 432 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
8cc99dcd 433 params->tls_hostname);
2ff30257 434 assert(params->has_max_bandwidth);
741d4086 435 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
977c736f 436 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
2ff30257
AA
437 params->max_bandwidth);
438 assert(params->has_downtime_limit);
741d4086 439 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
977c736f 440 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
2ff30257 441 params->downtime_limit);
fe39a4d4 442 assert(params->has_x_checkpoint_delay);
741d4086 443 monitor_printf(mon, "%s: %u\n",
977c736f 444 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
68b53591 445 params->x_checkpoint_delay);
2833c59b
JQ
446 assert(params->has_block_incremental);
447 monitor_printf(mon, "%s: %s\n",
977c736f
MA
448 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
449 params->block_incremental ? "on" : "off");
741d4086 450 monitor_printf(mon, "%s: %u\n",
cbfd6c95
JQ
451 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
452 params->multifd_channels);
96eef042
JQ
453 monitor_printf(mon, "%s: %s\n",
454 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
455 MultiFDCompression_str(params->multifd_compression));
741d4086 456 monitor_printf(mon, "%s: %" PRIu64 "\n",
73af8dd8
JQ
457 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
458 params->xbzrle_cache_size);
7e555c6c
DDAG
459 monitor_printf(mon, "%s: %" PRIu64 "\n",
460 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
461 params->max_postcopy_bandwidth);
d2f1d29b
DB
462 monitor_printf(mon, " %s: '%s'\n",
463 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
464 params->has_tls_authz ? params->tls_authz : "");
50e9a629
LL
465 }
466
467 qapi_free_MigrationParameters(params);
468}
469
84f2d0ea 470void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
9e1ba4cc
OW
471{
472 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
473 qmp_query_migrate_cache_size(NULL) >> 10);
474}
475
f11f57e4 476
05eb4a25 477#ifdef CONFIG_VNC
0a9667ec
DDAG
478/* Helper for hmp_info_vnc_clients, _servers */
479static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info,
480 const char *name)
481{
482 monitor_printf(mon, " %s: %s:%s (%s%s)\n",
483 name,
484 info->host,
485 info->service,
977c736f 486 NetworkAddressFamily_str(info->family),
0a9667ec
DDAG
487 info->websocket ? " (Websocket)" : "");
488}
489
490/* Helper displaying and auth and crypt info */
491static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent,
492 VncPrimaryAuth auth,
493 VncVencryptSubAuth *vencrypt)
494{
495 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent,
977c736f
MA
496 VncPrimaryAuth_str(auth),
497 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
0a9667ec
DDAG
498}
499
500static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client)
501{
502 while (client) {
503 VncClientInfo *cinfo = client->value;
504
505 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client");
506 monitor_printf(mon, " x509_dname: %s\n",
507 cinfo->has_x509_dname ?
508 cinfo->x509_dname : "none");
509 monitor_printf(mon, " sasl_username: %s\n",
510 cinfo->has_sasl_username ?
511 cinfo->sasl_username : "none");
512
513 client = client->next;
514 }
515}
516
517static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server)
518{
519 while (server) {
520 VncServerInfo2 *sinfo = server->value;
521 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server");
522 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth,
523 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL);
524 server = server->next;
525 }
526}
527
84f2d0ea 528void hmp_info_vnc(Monitor *mon, const QDict *qdict)
2b54aa87 529{
0a9667ec 530 VncInfo2List *info2l;
2b54aa87 531 Error *err = NULL;
2b54aa87 532
0a9667ec 533 info2l = qmp_query_vnc_servers(&err);
2b54aa87 534 if (err) {
187c6147 535 hmp_handle_error(mon, err);
2b54aa87
LC
536 return;
537 }
0a9667ec
DDAG
538 if (!info2l) {
539 monitor_printf(mon, "None\n");
540 return;
2b54aa87
LC
541 }
542
0a9667ec
DDAG
543 while (info2l) {
544 VncInfo2 *info = info2l->value;
545 monitor_printf(mon, "%s:\n", info->id);
546 hmp_info_vnc_servers(mon, info->server);
547 hmp_info_vnc_clients(mon, info->clients);
548 if (!info->server) {
549 /* The server entry displays its auth, we only
550 * need to display in the case of 'reverse' connections
551 * where there's no server.
552 */
553 hmp_info_vnc_authcrypt(mon, " ", info->auth,
554 info->has_vencrypt ? &info->vencrypt : NULL);
555 }
556 if (info->has_display) {
557 monitor_printf(mon, " Display: %s\n", info->display);
2b54aa87 558 }
0a9667ec 559 info2l = info2l->next;
2b54aa87
LC
560 }
561
0a9667ec
DDAG
562 qapi_free_VncInfo2List(info2l);
563
2b54aa87 564}
05eb4a25 565#endif
2b54aa87 566
206addd5 567#ifdef CONFIG_SPICE
84f2d0ea 568void hmp_info_spice(Monitor *mon, const QDict *qdict)
d1f29646
LC
569{
570 SpiceChannelList *chan;
571 SpiceInfo *info;
22fa7da0
CR
572 const char *channel_name;
573 const char * const channel_names[] = {
574 [SPICE_CHANNEL_MAIN] = "main",
575 [SPICE_CHANNEL_DISPLAY] = "display",
576 [SPICE_CHANNEL_INPUTS] = "inputs",
577 [SPICE_CHANNEL_CURSOR] = "cursor",
578 [SPICE_CHANNEL_PLAYBACK] = "playback",
579 [SPICE_CHANNEL_RECORD] = "record",
580 [SPICE_CHANNEL_TUNNEL] = "tunnel",
581 [SPICE_CHANNEL_SMARTCARD] = "smartcard",
582 [SPICE_CHANNEL_USBREDIR] = "usbredir",
583 [SPICE_CHANNEL_PORT] = "port",
7c6044a9
GH
584#if 0
585 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
586 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
587 * as quick fix for build failures with older versions. */
22fa7da0 588 [SPICE_CHANNEL_WEBDAV] = "webdav",
7c6044a9 589#endif
22fa7da0 590 };
d1f29646
LC
591
592 info = qmp_query_spice(NULL);
593
594 if (!info->enabled) {
595 monitor_printf(mon, "Server: disabled\n");
596 goto out;
597 }
598
599 monitor_printf(mon, "Server:\n");
600 if (info->has_port) {
601 monitor_printf(mon, " address: %s:%" PRId64 "\n",
602 info->host, info->port);
603 }
604 if (info->has_tls_port) {
605 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
606 info->host, info->tls_port);
607 }
61c4efe2
YH
608 monitor_printf(mon, " migrated: %s\n",
609 info->migrated ? "true" : "false");
d1f29646
LC
610 monitor_printf(mon, " auth: %s\n", info->auth);
611 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
4efee029 612 monitor_printf(mon, " mouse-mode: %s\n",
977c736f 613 SpiceQueryMouseMode_str(info->mouse_mode));
d1f29646
LC
614
615 if (!info->has_channels || info->channels == NULL) {
616 monitor_printf(mon, "Channels: none\n");
617 } else {
618 for (chan = info->channels; chan; chan = chan->next) {
619 monitor_printf(mon, "Channel:\n");
620 monitor_printf(mon, " address: %s:%s%s\n",
ddf21908 621 chan->value->host, chan->value->port,
d1f29646
LC
622 chan->value->tls ? " [tls]" : "");
623 monitor_printf(mon, " session: %" PRId64 "\n",
624 chan->value->connection_id);
625 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
626 chan->value->channel_type, chan->value->channel_id);
22fa7da0
CR
627
628 channel_name = "unknown";
629 if (chan->value->channel_type > 0 &&
630 chan->value->channel_type < ARRAY_SIZE(channel_names) &&
631 channel_names[chan->value->channel_type]) {
632 channel_name = channel_names[chan->value->channel_type];
633 }
634
635 monitor_printf(mon, " channel name: %s\n", channel_name);
d1f29646
LC
636 }
637 }
638
639out:
640 qapi_free_SpiceInfo(info);
641}
206addd5 642#endif
d1f29646 643
84f2d0ea 644void hmp_info_balloon(Monitor *mon, const QDict *qdict)
96637bcd
LC
645{
646 BalloonInfo *info;
647 Error *err = NULL;
648
649 info = qmp_query_balloon(&err);
650 if (err) {
187c6147 651 hmp_handle_error(mon, err);
96637bcd
LC
652 return;
653 }
654
01ceb97e 655 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
96637bcd
LC
656
657 qapi_free_BalloonInfo(info);
658}
659
79627472
LC
660static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
661{
662 PciMemoryRegionList *region;
663
664 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
665 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
666 dev->slot, dev->function);
667 monitor_printf(mon, " ");
668
9fa02cd1
EB
669 if (dev->class_info->has_desc) {
670 monitor_printf(mon, "%s", dev->class_info->desc);
79627472 671 } else {
9fa02cd1 672 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
79627472
LC
673 }
674
675 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
9fa02cd1 676 dev->id->vendor, dev->id->device);
18613dc6
DL
677 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) {
678 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n",
679 dev->id->subsystem_vendor, dev->id->subsystem);
680 }
79627472
LC
681
682 if (dev->has_irq) {
683 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
684 }
685
686 if (dev->has_pci_bridge) {
687 monitor_printf(mon, " BUS %" PRId64 ".\n",
9fa02cd1 688 dev->pci_bridge->bus->number);
79627472 689 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
9fa02cd1 690 dev->pci_bridge->bus->secondary);
79627472 691 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
9fa02cd1 692 dev->pci_bridge->bus->subordinate);
79627472
LC
693
694 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
9fa02cd1
EB
695 dev->pci_bridge->bus->io_range->base,
696 dev->pci_bridge->bus->io_range->limit);
79627472
LC
697
698 monitor_printf(mon,
699 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
700 dev->pci_bridge->bus->memory_range->base,
701 dev->pci_bridge->bus->memory_range->limit);
79627472
LC
702
703 monitor_printf(mon, " prefetchable memory range "
704 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
9fa02cd1
EB
705 dev->pci_bridge->bus->prefetchable_range->base,
706 dev->pci_bridge->bus->prefetchable_range->limit);
79627472
LC
707 }
708
709 for (region = dev->regions; region; region = region->next) {
710 uint64_t addr, size;
711
712 addr = region->value->address;
713 size = region->value->size;
714
715 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
716
717 if (!strcmp(region->value->type, "io")) {
718 monitor_printf(mon, "I/O at 0x%04" PRIx64
719 " [0x%04" PRIx64 "].\n",
720 addr, addr + size - 1);
721 } else {
722 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
723 " [0x%08" PRIx64 "].\n",
724 region->value->mem_type_64 ? 64 : 32,
725 region->value->prefetch ? " prefetchable" : "",
726 addr, addr + size - 1);
727 }
728 }
729
730 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
731
732 if (dev->has_pci_bridge) {
733 if (dev->pci_bridge->has_devices) {
734 PciDeviceInfoList *cdev;
735 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
736 hmp_info_pci_device(mon, cdev->value);
737 }
738 }
739 }
740}
741
61b97833
HP
742static int hmp_info_irq_foreach(Object *obj, void *opaque)
743{
744 InterruptStatsProvider *intc;
745 InterruptStatsProviderClass *k;
746 Monitor *mon = opaque;
747
748 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
749 intc = INTERRUPT_STATS_PROVIDER(obj);
750 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
751 uint64_t *irq_counts;
752 unsigned int nb_irqs, i;
753 if (k->get_statistics &&
754 k->get_statistics(intc, &irq_counts, &nb_irqs)) {
755 if (nb_irqs > 0) {
756 monitor_printf(mon, "IRQ statistics for %s:\n",
757 object_get_typename(obj));
758 for (i = 0; i < nb_irqs; i++) {
759 if (irq_counts[i] > 0) {
760 monitor_printf(mon, "%2d: %" PRId64 "\n", i,
761 irq_counts[i]);
762 }
763 }
764 }
765 } else {
766 monitor_printf(mon, "IRQ statistics not available for %s.\n",
767 object_get_typename(obj));
768 }
769 }
770
771 return 0;
772}
773
774void hmp_info_irq(Monitor *mon, const QDict *qdict)
775{
776 object_child_foreach_recursive(object_get_root(),
777 hmp_info_irq_foreach, mon);
778}
779
780static int hmp_info_pic_foreach(Object *obj, void *opaque)
781{
782 InterruptStatsProvider *intc;
783 InterruptStatsProviderClass *k;
784 Monitor *mon = opaque;
785
786 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
787 intc = INTERRUPT_STATS_PROVIDER(obj);
788 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
789 if (k->print_info) {
790 k->print_info(intc, mon);
791 } else {
792 monitor_printf(mon, "Interrupt controller information not available for %s.\n",
793 object_get_typename(obj));
794 }
795 }
796
797 return 0;
798}
799
800void hmp_info_pic(Monitor *mon, const QDict *qdict)
801{
802 object_child_foreach_recursive(object_get_root(),
803 hmp_info_pic_foreach, mon);
804}
805
f4b2c02a
YS
806static int hmp_info_rdma_foreach(Object *obj, void *opaque)
807{
808 RdmaProvider *rdma;
809 RdmaProviderClass *k;
810 Monitor *mon = opaque;
811
812 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
813 rdma = RDMA_PROVIDER(obj);
814 k = RDMA_PROVIDER_GET_CLASS(obj);
815 if (k->print_statistics) {
816 k->print_statistics(mon, rdma);
817 } else {
818 monitor_printf(mon, "RDMA statistics not available for %s.\n",
819 object_get_typename(obj));
820 }
821 }
822
823 return 0;
824}
825
826void hmp_info_rdma(Monitor *mon, const QDict *qdict)
827{
828 object_child_foreach_recursive(object_get_root(),
829 hmp_info_rdma_foreach, mon);
830}
831
84f2d0ea 832void hmp_info_pci(Monitor *mon, const QDict *qdict)
79627472 833{
f46cee37 834 PciInfoList *info_list, *info;
79627472
LC
835 Error *err = NULL;
836
f46cee37 837 info_list = qmp_query_pci(&err);
79627472
LC
838 if (err) {
839 monitor_printf(mon, "PCI devices not supported\n");
840 error_free(err);
841 return;
842 }
843
f46cee37 844 for (info = info_list; info; info = info->next) {
79627472
LC
845 PciDeviceInfoList *dev;
846
847 for (dev = info->value->devices; dev; dev = dev->next) {
848 hmp_info_pci_device(mon, dev->value);
849 }
850 }
851
f46cee37 852 qapi_free_PciInfoList(info_list);
79627472
LC
853}
854
d1a0cf73
SB
855void hmp_info_tpm(Monitor *mon, const QDict *qdict)
856{
857 TPMInfoList *info_list, *info;
858 Error *err = NULL;
859 unsigned int c = 0;
860 TPMPassthroughOptions *tpo;
f4ede81e 861 TPMEmulatorOptions *teo;
d1a0cf73
SB
862
863 info_list = qmp_query_tpm(&err);
864 if (err) {
865 monitor_printf(mon, "TPM device not supported\n");
866 error_free(err);
867 return;
868 }
869
870 if (info_list) {
871 monitor_printf(mon, "TPM device:\n");
872 }
873
874 for (info = info_list; info; info = info->next) {
875 TPMInfo *ti = info->value;
876 monitor_printf(mon, " tpm%d: model=%s\n",
977c736f 877 c, TpmModel_str(ti->model));
d1a0cf73
SB
878
879 monitor_printf(mon, " \\ %s: type=%s",
977c736f 880 ti->id, TpmTypeOptionsKind_str(ti->options->type));
d1a0cf73 881
ce21131a 882 switch (ti->options->type) {
88ca7bcf 883 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
32bafa8f 884 tpo = ti->options->u.passthrough.data;
d1a0cf73
SB
885 monitor_printf(mon, "%s%s%s%s",
886 tpo->has_path ? ",path=" : "",
887 tpo->has_path ? tpo->path : "",
888 tpo->has_cancel_path ? ",cancel-path=" : "",
889 tpo->has_cancel_path ? tpo->cancel_path : "");
890 break;
f4ede81e
AV
891 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
892 teo = ti->options->u.emulator.data;
893 monitor_printf(mon, ",chardev=%s", teo->chardev);
894 break;
7fb1cf16 895 case TPM_TYPE_OPTIONS_KIND__MAX:
d1a0cf73
SB
896 break;
897 }
898 monitor_printf(mon, "\n");
899 c++;
900 }
901 qapi_free_TPMInfoList(info_list);
902}
903
7a7f325e
LC
904void hmp_quit(Monitor *mon, const QDict *qdict)
905{
906 monitor_suspend(mon);
907 qmp_quit(NULL);
908}
5f158f21
LC
909
910void hmp_stop(Monitor *mon, const QDict *qdict)
911{
912 qmp_stop(NULL);
913}
38d22653 914
dd12e1bb
EC
915void hmp_sync_profile(Monitor *mon, const QDict *qdict)
916{
917 const char *op = qdict_get_try_str(qdict, "op");
918
919 if (op == NULL) {
920 bool on = qsp_is_enabled();
921
922 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off");
923 return;
924 }
925 if (!strcmp(op, "on")) {
926 qsp_enable();
927 } else if (!strcmp(op, "off")) {
928 qsp_disable();
929 } else if (!strcmp(op, "reset")) {
930 qsp_reset();
931 } else {
932 Error *err = NULL;
933
934 error_setg(&err, QERR_INVALID_PARAMETER, op);
187c6147 935 hmp_handle_error(mon, err);
dd12e1bb
EC
936 }
937}
938
38d22653
LC
939void hmp_system_reset(Monitor *mon, const QDict *qdict)
940{
941 qmp_system_reset(NULL);
942}
5bc465e4
LC
943
944void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
945{
946 qmp_system_powerdown(NULL);
947}
755f1968 948
8e8581e6
DDAG
949void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
950{
951 Error *err = NULL;
952
361ac948 953 qmp_x_exit_preconfig(&err);
187c6147 954 hmp_handle_error(mon, err);
8e8581e6
DDAG
955}
956
755f1968
LC
957void hmp_cpu(Monitor *mon, const QDict *qdict)
958{
959 int64_t cpu_index;
960
961 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
962 use it are converted to the QAPI */
963 cpu_index = qdict_get_int(qdict, "index");
964 if (monitor_set_cpu(cpu_index) < 0) {
965 monitor_printf(mon, "invalid CPU index\n");
966 }
967}
0cfd6a9a
LC
968
969void hmp_memsave(Monitor *mon, const QDict *qdict)
970{
971 uint32_t size = qdict_get_int(qdict, "size");
972 const char *filename = qdict_get_str(qdict, "filename");
973 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 974 Error *err = NULL;
854e67fe 975 int cpu_index = monitor_get_cpu_index();
0cfd6a9a 976
854e67fe
TH
977 if (cpu_index < 0) {
978 monitor_printf(mon, "No CPU available\n");
979 return;
980 }
981
982 qmp_memsave(addr, size, filename, true, cpu_index, &err);
187c6147 983 hmp_handle_error(mon, err);
0cfd6a9a 984}
6d3962bf
LC
985
986void hmp_pmemsave(Monitor *mon, const QDict *qdict)
987{
988 uint32_t size = qdict_get_int(qdict, "size");
989 const char *filename = qdict_get_str(qdict, "filename");
990 uint64_t addr = qdict_get_int(qdict, "val");
e940f543 991 Error *err = NULL;
6d3962bf 992
e940f543 993 qmp_pmemsave(addr, size, filename, &err);
187c6147 994 hmp_handle_error(mon, err);
1f590cf9
LL
995}
996
3949e594 997void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
1f590cf9 998{
1f590cf9
LL
999 const char *chardev = qdict_get_str(qdict, "device");
1000 const char *data = qdict_get_str(qdict, "data");
e940f543 1001 Error *err = NULL;
1f590cf9 1002
e940f543 1003 qmp_ringbuf_write(chardev, data, false, 0, &err);
1f590cf9 1004
187c6147 1005 hmp_handle_error(mon, err);
6d3962bf 1006}
e42e818b 1007
3949e594 1008void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
49b6d722
LL
1009{
1010 uint32_t size = qdict_get_int(qdict, "size");
1011 const char *chardev = qdict_get_str(qdict, "device");
3ab651fc 1012 char *data;
e940f543 1013 Error *err = NULL;
543f3412 1014 int i;
49b6d722 1015
e940f543
MA
1016 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1017 if (err) {
187c6147 1018 hmp_handle_error(mon, err);
49b6d722
LL
1019 return;
1020 }
1021
543f3412
MA
1022 for (i = 0; data[i]; i++) {
1023 unsigned char ch = data[i];
1024
1025 if (ch == '\\') {
1026 monitor_printf(mon, "\\\\");
1027 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
1028 monitor_printf(mon, "\\u%04X", ch);
1029 } else {
1030 monitor_printf(mon, "%c", ch);
1031 }
1032
1033 }
1034 monitor_printf(mon, "\n");
3ab651fc 1035 g_free(data);
49b6d722
LL
1036}
1037
e42e818b
LC
1038void hmp_cont(Monitor *mon, const QDict *qdict)
1039{
e940f543 1040 Error *err = NULL;
e42e818b 1041
e940f543 1042 qmp_cont(&err);
187c6147 1043 hmp_handle_error(mon, err);
e42e818b 1044}
ab49ab5c 1045
9b9df25a
GH
1046void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1047{
fb064112
DHB
1048 Error *err = NULL;
1049
1050 qmp_system_wakeup(&err);
187c6147 1051 hmp_handle_error(mon, err);
9b9df25a
GH
1052}
1053
3e5a50d6 1054void hmp_nmi(Monitor *mon, const QDict *qdict)
ab49ab5c 1055{
e940f543 1056 Error *err = NULL;
ab49ab5c 1057
e940f543 1058 qmp_inject_nmi(&err);
187c6147 1059 hmp_handle_error(mon, err);
ab49ab5c 1060}
4b37156c
LC
1061
1062void hmp_set_link(Monitor *mon, const QDict *qdict)
1063{
1064 const char *name = qdict_get_str(qdict, "name");
34acbc95 1065 bool up = qdict_get_bool(qdict, "up");
e940f543 1066 Error *err = NULL;
4b37156c 1067
e940f543 1068 qmp_set_link(name, up, &err);
187c6147 1069 hmp_handle_error(mon, err);
4b37156c 1070}
a4dea8a9 1071
d72f3264
LC
1072void hmp_balloon(Monitor *mon, const QDict *qdict)
1073{
1074 int64_t value = qdict_get_int(qdict, "value");
e940f543 1075 Error *err = NULL;
d72f3264 1076
e940f543 1077 qmp_balloon(value, &err);
187c6147 1078 hmp_handle_error(mon, err);
d72f3264 1079}
5e7caacb 1080
52b26205
JQ
1081void hmp_loadvm(Monitor *mon, const QDict *qdict)
1082{
1083 int saved_vm_running = runstate_is_running();
1084 const char *name = qdict_get_str(qdict, "name");
927d6638 1085 Error *err = NULL;
52b26205
JQ
1086
1087 vm_stop(RUN_STATE_RESTORE_VM);
1088
5e22479a 1089 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
52b26205
JQ
1090 vm_start();
1091 }
187c6147 1092 hmp_handle_error(mon, err);
52b26205
JQ
1093}
1094
d9c7d137
JQ
1095void hmp_savevm(Monitor *mon, const QDict *qdict)
1096{
927d6638
JQ
1097 Error *err = NULL;
1098
5e22479a 1099 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
187c6147 1100 hmp_handle_error(mon, err);
d9c7d137
JQ
1101}
1102
d905bb7b
JQ
1103void hmp_delvm(Monitor *mon, const QDict *qdict)
1104{
1105 BlockDriverState *bs;
32cd6550 1106 Error *err = NULL;
d905bb7b
JQ
1107 const char *name = qdict_get_str(qdict, "name");
1108
1109 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
b4e492db
CR
1110 error_prepend(&err,
1111 "deleting snapshot on device '%s': ",
1112 bdrv_get_device_name(bs));
d905bb7b 1113 }
187c6147 1114 hmp_handle_error(mon, err);
d905bb7b
JQ
1115}
1116
544f6ea3
DDAG
1117void hmp_announce_self(Monitor *mon, const QDict *qdict)
1118{
08528271 1119 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
c6644548 1120 const char *id = qdict_get_try_str(qdict, "id");
08528271
DDAG
1121 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
1122 migrate_announce_params());
1123
1124 qapi_free_strList(params->interfaces);
1125 params->interfaces = strList_from_comma_list(interfaces_str);
1126 params->has_interfaces = params->interfaces != NULL;
c6644548
DDAG
1127 params->id = g_strdup(id);
1128 params->has_id = !!params->id;
08528271
DDAG
1129 qmp_announce_self(params, NULL);
1130 qapi_free_AnnounceParameters(params);
544f6ea3
DDAG
1131}
1132
6cdedb07
LC
1133void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1134{
1135 qmp_migrate_cancel(NULL);
1136}
4f0a993b 1137
94ae12cb
DDAG
1138void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
1139{
1140 Error *err = NULL;
1141 const char *state = qdict_get_str(qdict, "state");
1142 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err);
1143
1144 if (val >= 0) {
1145 qmp_migrate_continue(val, &err);
1146 }
1147
187c6147 1148 hmp_handle_error(mon, err);
94ae12cb
DDAG
1149}
1150
bf1ae1f4
DDAG
1151void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
1152{
1153 Error *err = NULL;
1154 const char *uri = qdict_get_str(qdict, "uri");
1155
1156 qmp_migrate_incoming(uri, &err);
1157
187c6147 1158 hmp_handle_error(mon, err);
bf1ae1f4
DDAG
1159}
1160
3b563c4b
PX
1161void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
1162{
1163 Error *err = NULL;
1164 const char *uri = qdict_get_str(qdict, "uri");
1165
1166 qmp_migrate_recover(uri, &err);
1167
187c6147 1168 hmp_handle_error(mon, err);
3b563c4b
PX
1169}
1170
d37297dc
PX
1171void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1172{
1173 Error *err = NULL;
1174
1175 qmp_migrate_pause(&err);
1176
187c6147 1177 hmp_handle_error(mon, err);
d37297dc
PX
1178}
1179
2ff30257 1180/* Kept for backwards compatibility */
4f0a993b
LC
1181void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1182{
1183 double value = qdict_get_double(qdict, "value");
1184 qmp_migrate_set_downtime(value, NULL);
1185}
3dc85383 1186
9e1ba4cc
OW
1187void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1188{
1189 int64_t value = qdict_get_int(qdict, "value");
1190 Error *err = NULL;
1191
1192 qmp_migrate_set_cache_size(value, &err);
187c6147 1193 hmp_handle_error(mon, err);
9e1ba4cc
OW
1194}
1195
2ff30257 1196/* Kept for backwards compatibility */
3dc85383
LC
1197void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1198{
1199 int64_t value = qdict_get_int(qdict, "value");
1200 qmp_migrate_set_speed(value, NULL);
1201}
fbf796fd 1202
00458433
OW
1203void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1204{
1205 const char *cap = qdict_get_str(qdict, "capability");
1206 bool state = qdict_get_bool(qdict, "state");
1207 Error *err = NULL;
1208 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
8e615e34 1209 int val;
00458433 1210
f7abe0ec 1211 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
8e615e34
MAL
1212 if (val < 0) {
1213 goto end;
00458433
OW
1214 }
1215
8e615e34
MAL
1216 caps->value = g_malloc0(sizeof(*caps->value));
1217 caps->value->capability = val;
1218 caps->value->state = state;
1219 caps->next = NULL;
1220 qmp_migrate_set_capabilities(caps, &err);
00458433 1221
8e615e34 1222end:
00458433 1223 qapi_free_MigrationCapabilityStatusList(caps);
187c6147 1224 hmp_handle_error(mon, err);
00458433
OW
1225}
1226
50e9a629
LL
1227void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1228{
1229 const char *param = qdict_get_str(qdict, "parameter");
69ef1f36 1230 const char *valuestr = qdict_get_str(qdict, "value");
f4a06d13 1231 Visitor *v = string_input_visitor_new(valuestr);
1bda8b3c 1232 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
f46bfdbf 1233 uint64_t valuebw = 0;
73af8dd8 1234 uint64_t cache_size;
96eef042 1235 MultiFDCompression compress_type;
50e9a629 1236 Error *err = NULL;
262517b7 1237 int val, ret;
69ef1f36 1238
f7abe0ec 1239 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
262517b7
MAL
1240 if (val < 0) {
1241 goto cleanup;
1242 }
1243
1244 switch (val) {
1245 case MIGRATION_PARAMETER_COMPRESS_LEVEL:
1246 p->has_compress_level = true;
1247 visit_type_int(v, param, &p->compress_level, &err);
1248 break;
1249 case MIGRATION_PARAMETER_COMPRESS_THREADS:
1250 p->has_compress_threads = true;
1251 visit_type_int(v, param, &p->compress_threads, &err);
1252 break;
1d58872a
XG
1253 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD:
1254 p->has_compress_wait_thread = true;
1255 visit_type_bool(v, param, &p->compress_wait_thread, &err);
1256 break;
262517b7
MAL
1257 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1258 p->has_decompress_threads = true;
1259 visit_type_int(v, param, &p->decompress_threads, &err);
1260 break;
dc14a470
KZ
1261 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD:
1262 p->has_throttle_trigger_threshold = true;
1263 visit_type_int(v, param, &p->throttle_trigger_threshold, &err);
262517b7
MAL
1264 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
1265 p->has_cpu_throttle_initial = true;
1266 visit_type_int(v, param, &p->cpu_throttle_initial, &err);
1267 break;
1268 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
1269 p->has_cpu_throttle_increment = true;
1270 visit_type_int(v, param, &p->cpu_throttle_increment, &err);
1271 break;
4cbc9c7f
LQ
1272 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE:
1273 p->has_max_cpu_throttle = true;
1274 visit_type_int(v, param, &p->max_cpu_throttle, &err);
1275 break;
262517b7
MAL
1276 case MIGRATION_PARAMETER_TLS_CREDS:
1277 p->has_tls_creds = true;
1278 p->tls_creds = g_new0(StrOrNull, 1);
1279 p->tls_creds->type = QTYPE_QSTRING;
1280 visit_type_str(v, param, &p->tls_creds->u.s, &err);
1281 break;
1282 case MIGRATION_PARAMETER_TLS_HOSTNAME:
1283 p->has_tls_hostname = true;
1284 p->tls_hostname = g_new0(StrOrNull, 1);
1285 p->tls_hostname->type = QTYPE_QSTRING;
1286 visit_type_str(v, param, &p->tls_hostname->u.s, &err);
1287 break;
d2f1d29b
DB
1288 case MIGRATION_PARAMETER_TLS_AUTHZ:
1289 p->has_tls_authz = true;
1290 p->tls_authz = g_new0(StrOrNull, 1);
1291 p->tls_authz->type = QTYPE_QSTRING;
1292 visit_type_str(v, param, &p->tls_authz->u.s, &err);
1293 break;
262517b7
MAL
1294 case MIGRATION_PARAMETER_MAX_BANDWIDTH:
1295 p->has_max_bandwidth = true;
1296 /*
1297 * Can't use visit_type_size() here, because it
1298 * defaults to Bytes rather than Mebibytes.
1299 */
1300 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
1301 if (ret < 0 || valuebw > INT64_MAX
1302 || (size_t)valuebw != valuebw) {
1303 error_setg(&err, "Invalid size %s", valuestr);
50e9a629
LL
1304 break;
1305 }
262517b7
MAL
1306 p->max_bandwidth = valuebw;
1307 break;
1308 case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
1309 p->has_downtime_limit = true;
1310 visit_type_int(v, param, &p->downtime_limit, &err);
1311 break;
1312 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
1313 p->has_x_checkpoint_delay = true;
1314 visit_type_int(v, param, &p->x_checkpoint_delay, &err);
1315 break;
1316 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
1317 p->has_block_incremental = true;
1318 visit_type_bool(v, param, &p->block_incremental, &err);
1319 break;
cbfd6c95
JQ
1320 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1321 p->has_multifd_channels = true;
1322 visit_type_int(v, param, &p->multifd_channels, &err);
4075fb1c 1323 break;
96eef042
JQ
1324 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION:
1325 p->has_multifd_compression = true;
1326 visit_type_MultiFDCompression(v, param, &compress_type, &err);
1327 if (err) {
1328 break;
1329 }
1330 p->multifd_compression = compress_type;
1331 break;
9004db48
JQ
1332 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL:
1333 p->has_multifd_zlib_level = true;
1334 visit_type_int(v, param, &p->multifd_zlib_level, &err);
1335 break;
6a9ad154
JQ
1336 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL:
1337 p->has_multifd_zstd_level = true;
1338 visit_type_int(v, param, &p->multifd_zstd_level, &err);
1339 break;
73af8dd8
JQ
1340 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1341 p->has_xbzrle_cache_size = true;
1342 visit_type_size(v, param, &cache_size, &err);
d013283a
JQ
1343 if (err) {
1344 break;
1345 }
1346 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
73af8dd8
JQ
1347 error_setg(&err, "Invalid size %s", valuestr);
1348 break;
1349 }
1350 p->xbzrle_cache_size = cache_size;
1351 break;
7e555c6c
DDAG
1352 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH:
1353 p->has_max_postcopy_bandwidth = true;
1354 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err);
1355 break;
ee3d96ba
DDAG
1356 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL:
1357 p->has_announce_initial = true;
1358 visit_type_size(v, param, &p->announce_initial, &err);
1359 break;
1360 case MIGRATION_PARAMETER_ANNOUNCE_MAX:
1361 p->has_announce_max = true;
1362 visit_type_size(v, param, &p->announce_max, &err);
1363 break;
1364 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS:
1365 p->has_announce_rounds = true;
1366 visit_type_size(v, param, &p->announce_rounds, &err);
1367 break;
1368 case MIGRATION_PARAMETER_ANNOUNCE_STEP:
1369 p->has_announce_step = true;
1370 visit_type_size(v, param, &p->announce_step, &err);
1371 break;
262517b7
MAL
1372 default:
1373 assert(0);
50e9a629
LL
1374 }
1375
262517b7
MAL
1376 if (err) {
1377 goto cleanup;
50e9a629
LL
1378 }
1379
262517b7
MAL
1380 qmp_migrate_set_parameters(p, &err);
1381
69ef1f36 1382 cleanup:
1bda8b3c 1383 qapi_free_MigrateSetParameters(p);
f4a06d13 1384 visit_free(v);
187c6147 1385 hmp_handle_error(mon, err);
50e9a629
LL
1386}
1387
b8a185bc
MA
1388void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
1389{
1390 Error *err = NULL;
1391 const char *protocol = qdict_get_str(qdict, "protocol");
1392 const char *hostname = qdict_get_str(qdict, "hostname");
1393 bool has_port = qdict_haskey(qdict, "port");
1394 int port = qdict_get_try_int(qdict, "port", -1);
1395 bool has_tls_port = qdict_haskey(qdict, "tls-port");
1396 int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
1397 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject");
1398
1399 qmp_client_migrate_info(protocol, hostname,
1400 has_port, port, has_tls_port, tls_port,
1401 !!cert_subject, cert_subject, &err);
187c6147 1402 hmp_handle_error(mon, err);
b8a185bc
MA
1403}
1404
4886a1bc
DDAG
1405void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1406{
1407 Error *err = NULL;
1408 qmp_migrate_start_postcopy(&err);
187c6147 1409 hmp_handle_error(mon, err);
4886a1bc
DDAG
1410}
1411
d89e666e
HZ
1412void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1413{
1414 Error *err = NULL;
1415
1416 qmp_x_colo_lost_heartbeat(&err);
187c6147 1417 hmp_handle_error(mon, err);
d89e666e
HZ
1418}
1419
fbf796fd
LC
1420void hmp_set_password(Monitor *mon, const QDict *qdict)
1421{
1422 const char *protocol = qdict_get_str(qdict, "protocol");
1423 const char *password = qdict_get_str(qdict, "password");
1424 const char *connected = qdict_get_try_str(qdict, "connected");
1425 Error *err = NULL;
1426
1427 qmp_set_password(protocol, password, !!connected, connected, &err);
187c6147 1428 hmp_handle_error(mon, err);
fbf796fd 1429}
9ad5372d
LC
1430
1431void hmp_expire_password(Monitor *mon, const QDict *qdict)
1432{
1433 const char *protocol = qdict_get_str(qdict, "protocol");
1434 const char *whenstr = qdict_get_str(qdict, "time");
1435 Error *err = NULL;
1436
1437 qmp_expire_password(protocol, whenstr, &err);
187c6147 1438 hmp_handle_error(mon, err);
9ad5372d 1439}
c245b6a3 1440
333a96ec 1441
05eb4a25 1442#ifdef CONFIG_VNC
c60bf339
SH
1443static void hmp_change_read_arg(void *opaque, const char *password,
1444 void *readline_opaque)
333a96ec
LC
1445{
1446 qmp_change_vnc_password(password, NULL);
c60bf339 1447 monitor_read_command(opaque, 1);
333a96ec 1448}
05eb4a25 1449#endif
333a96ec 1450
333a96ec
LC
1451void hmp_change(Monitor *mon, const QDict *qdict)
1452{
1453 const char *device = qdict_get_str(qdict, "device");
1454 const char *target = qdict_get_str(qdict, "target");
1455 const char *arg = qdict_get_try_str(qdict, "arg");
baead0ab
HR
1456 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1457 BlockdevChangeReadOnlyMode read_only_mode = 0;
333a96ec
LC
1458 Error *err = NULL;
1459
05eb4a25 1460#ifdef CONFIG_VNC
10686749 1461 if (strcmp(device, "vnc") == 0) {
baead0ab
HR
1462 if (read_only) {
1463 monitor_printf(mon,
1464 "Parameter 'read-only-mode' is invalid for VNC\n");
1465 return;
1466 }
10686749
HR
1467 if (strcmp(target, "passwd") == 0 ||
1468 strcmp(target, "password") == 0) {
1469 if (!arg) {
ea73f370 1470 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
5f9dba16 1471 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
10686749
HR
1472 return;
1473 }
1474 }
1475 qmp_change("vnc", target, !!arg, arg, &err);
05eb4a25
MAL
1476 } else
1477#endif
1478 {
baead0ab
HR
1479 if (read_only) {
1480 read_only_mode =
f7abe0ec 1481 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
06c60b6c 1482 read_only,
baead0ab
HR
1483 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1484 if (err) {
187c6147 1485 hmp_handle_error(mon, err);
baead0ab
HR
1486 return;
1487 }
1488 }
1489
70e2cb3b
KW
1490 qmp_blockdev_change_medium(true, device, false, NULL, target,
1491 !!arg, arg, !!read_only, read_only_mode,
1492 &err);
333a96ec
LC
1493 }
1494
187c6147 1495 hmp_handle_error(mon, err);
333a96ec 1496}
80047da5 1497
e49f35bd 1498typedef struct HMPMigrationStatus
e1c37d0e
LC
1499{
1500 QEMUTimer *timer;
1501 Monitor *mon;
1502 bool is_block_migration;
e49f35bd 1503} HMPMigrationStatus;
e1c37d0e
LC
1504
1505static void hmp_migrate_status_cb(void *opaque)
1506{
e49f35bd 1507 HMPMigrationStatus *status = opaque;
e1c37d0e
LC
1508 MigrationInfo *info;
1509
1510 info = qmp_query_migrate(NULL);
24b8c39b
HZ
1511 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1512 info->status == MIGRATION_STATUS_SETUP) {
e1c37d0e
LC
1513 if (info->has_disk) {
1514 int progress;
1515
1516 if (info->disk->remaining) {
1517 progress = info->disk->transferred * 100 / info->disk->total;
1518 } else {
1519 progress = 100;
1520 }
1521
1522 monitor_printf(status->mon, "Completed %d %%\r", progress);
1523 monitor_flush(status->mon);
1524 }
1525
bc72ad67 1526 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
e1c37d0e
LC
1527 } else {
1528 if (status->is_block_migration) {
1529 monitor_printf(status->mon, "\n");
1530 }
d59ce6f3
DB
1531 if (info->has_error_desc) {
1532 error_report("%s", info->error_desc);
1533 }
e1c37d0e 1534 monitor_resume(status->mon);
bc72ad67 1535 timer_del(status->timer);
d34a10af 1536 timer_free(status->timer);
e1c37d0e
LC
1537 g_free(status);
1538 }
1539
1540 qapi_free_MigrationInfo(info);
1541}
1542
1543void hmp_migrate(Monitor *mon, const QDict *qdict)
1544{
34acbc95
EB
1545 bool detach = qdict_get_try_bool(qdict, "detach", false);
1546 bool blk = qdict_get_try_bool(qdict, "blk", false);
1547 bool inc = qdict_get_try_bool(qdict, "inc", false);
7a4da28b 1548 bool resume = qdict_get_try_bool(qdict, "resume", false);
e1c37d0e
LC
1549 const char *uri = qdict_get_str(qdict, "uri");
1550 Error *err = NULL;
1551
7a4da28b
PX
1552 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1553 false, false, true, resume, &err);
e1c37d0e 1554 if (err) {
187c6147 1555 hmp_handle_error(mon, err);
e1c37d0e
LC
1556 return;
1557 }
1558
1559 if (!detach) {
e49f35bd 1560 HMPMigrationStatus *status;
e1c37d0e
LC
1561
1562 if (monitor_suspend(mon) < 0) {
1563 monitor_printf(mon, "terminal does not allow synchronous "
1564 "migration, continuing detached\n");
1565 return;
1566 }
1567
1568 status = g_malloc0(sizeof(*status));
1569 status->mon = mon;
1570 status->is_block_migration = blk || inc;
bc72ad67 1571 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
e1c37d0e 1572 status);
bc72ad67 1573 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
e1c37d0e
LC
1574 }
1575}
a15fef21 1576
928059a3
LC
1577void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1578{
1579 Error *err = NULL;
1580 QemuOpts *opts;
1581
1582 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
84d18f06 1583 if (err) {
928059a3
LC
1584 goto out;
1585 }
1586
1587 netdev_add(opts, &err);
84d18f06 1588 if (err) {
928059a3
LC
1589 qemu_opts_del(opts);
1590 }
1591
1592out:
187c6147 1593 hmp_handle_error(mon, err);
928059a3 1594}
5f964155
LC
1595
1596void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1597{
1598 const char *id = qdict_get_str(qdict, "id");
1599 Error *err = NULL;
1600
1601 qmp_netdev_del(id, &err);
187c6147 1602 hmp_handle_error(mon, err);
5f964155 1603}
208c9d1b 1604
cff8b2c6
PB
1605void hmp_object_add(Monitor *mon, const QDict *qdict)
1606{
1607 Error *err = NULL;
1608 QemuOpts *opts;
90998d58 1609 Object *obj = NULL;
cff8b2c6
PB
1610
1611 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1612 if (err) {
187c6147 1613 hmp_handle_error(mon, err);
90998d58 1614 return;
cff8b2c6
PB
1615 }
1616
3a464105 1617 obj = user_creatable_add_opts(opts, &err);
90998d58 1618 qemu_opts_del(opts);
cff8b2c6 1619
cff8b2c6 1620 if (err) {
187c6147 1621 hmp_handle_error(mon, err);
cff8b2c6 1622 }
90998d58
DB
1623 if (obj) {
1624 object_unref(obj);
cff8b2c6 1625 }
cff8b2c6
PB
1626}
1627
208c9d1b
CB
1628void hmp_getfd(Monitor *mon, const QDict *qdict)
1629{
1630 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1631 Error *err = NULL;
208c9d1b 1632
e940f543 1633 qmp_getfd(fdname, &err);
187c6147 1634 hmp_handle_error(mon, err);
208c9d1b
CB
1635}
1636
1637void hmp_closefd(Monitor *mon, const QDict *qdict)
1638{
1639 const char *fdname = qdict_get_str(qdict, "fdname");
e940f543 1640 Error *err = NULL;
208c9d1b 1641
e940f543 1642 qmp_closefd(fdname, &err);
187c6147 1643 hmp_handle_error(mon, err);
208c9d1b 1644}
e4c8f004 1645
3e5a50d6 1646void hmp_sendkey(Monitor *mon, const QDict *qdict)
e4c8f004
AK
1647{
1648 const char *keys = qdict_get_str(qdict, "keys");
9f328977 1649 KeyValueList *keylist, *head = NULL, *tmp = NULL;
e4c8f004
AK
1650 int has_hold_time = qdict_haskey(qdict, "hold-time");
1651 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1652 Error *err = NULL;
5c99fa37 1653 const char *separator;
9f328977 1654 int keyname_len;
e4c8f004
AK
1655
1656 while (1) {
5c99fa37
KF
1657 separator = qemu_strchrnul(keys, '-');
1658 keyname_len = separator - keys;
e4c8f004
AK
1659
1660 /* Be compatible with old interface, convert user inputted "<" */
64ffbe04
WB
1661 if (keys[0] == '<' && keyname_len == 1) {
1662 keys = "less";
e4c8f004
AK
1663 keyname_len = 4;
1664 }
e4c8f004 1665
e4c8f004 1666 keylist = g_malloc0(sizeof(*keylist));
9f328977 1667 keylist->value = g_malloc0(sizeof(*keylist->value));
e4c8f004
AK
1668
1669 if (!head) {
1670 head = keylist;
1671 }
1672 if (tmp) {
1673 tmp->next = keylist;
1674 }
1675 tmp = keylist;
1676
64ffbe04 1677 if (strstart(keys, "0x", NULL)) {
9f328977 1678 char *endp;
64ffbe04
WB
1679 int value = strtoul(keys, &endp, 0);
1680 assert(endp <= keys + keyname_len);
1681 if (endp != keys + keyname_len) {
9f328977
LC
1682 goto err_out;
1683 }
568c73a4 1684 keylist->value->type = KEY_VALUE_KIND_NUMBER;
32bafa8f 1685 keylist->value->u.number.data = value;
9f328977 1686 } else {
64ffbe04 1687 int idx = index_from_key(keys, keyname_len);
7fb1cf16 1688 if (idx == Q_KEY_CODE__MAX) {
9f328977
LC
1689 goto err_out;
1690 }
568c73a4 1691 keylist->value->type = KEY_VALUE_KIND_QCODE;
32bafa8f 1692 keylist->value->u.qcode.data = idx;
9f328977
LC
1693 }
1694
5c99fa37 1695 if (!*separator) {
e4c8f004
AK
1696 break;
1697 }
1698 keys = separator + 1;
1699 }
1700
9f328977 1701 qmp_send_key(head, has_hold_time, hold_time, &err);
187c6147 1702 hmp_handle_error(mon, err);
9f328977
LC
1703
1704out:
1705 qapi_free_KeyValueList(head);
1706 return;
1707
1708err_out:
64ffbe04 1709 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
9f328977 1710 goto out;
e4c8f004 1711}
ad39cf6d 1712
3e5a50d6 1713void hmp_screendump(Monitor *mon, const QDict *qdict)
ad39cf6d
LC
1714{
1715 const char *filename = qdict_get_str(qdict, "filename");
f771c544
TH
1716 const char *id = qdict_get_try_str(qdict, "device");
1717 int64_t head = qdict_get_try_int(qdict, "head", 0);
ad39cf6d
LC
1718 Error *err = NULL;
1719
f771c544 1720 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
187c6147 1721 hmp_handle_error(mon, err);
ad39cf6d 1722}
4057725f 1723
f1088908
GH
1724void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1725{
1726 const char *args = qdict_get_str(qdict, "args");
1727 Error *err = NULL;
1728 QemuOpts *opts;
1729
70b94331 1730 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
f1088908 1731 if (opts == NULL) {
312fd5f2 1732 error_setg(&err, "Parsing chardev args failed");
f1088908 1733 } else {
4ad6f6cb 1734 qemu_chr_new_from_opts(opts, NULL, &err);
0a73336d 1735 qemu_opts_del(opts);
f1088908 1736 }
187c6147 1737 hmp_handle_error(mon, err);
f1088908
GH
1738}
1739
75b60160
AN
1740void hmp_chardev_change(Monitor *mon, const QDict *qdict)
1741{
1742 const char *args = qdict_get_str(qdict, "args");
1743 const char *id;
1744 Error *err = NULL;
1745 ChardevBackend *backend = NULL;
1746 ChardevReturn *ret = NULL;
1747 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args,
1748 true);
1749 if (!opts) {
1750 error_setg(&err, "Parsing chardev args failed");
1751 goto end;
1752 }
1753
1754 id = qdict_get_str(qdict, "id");
1755 if (qemu_opts_id(opts)) {
1756 error_setg(&err, "Unexpected 'id' parameter");
1757 goto end;
1758 }
1759
1760 backend = qemu_chr_parse_opts(opts, &err);
1761 if (!backend) {
1762 goto end;
1763 }
1764
1765 ret = qmp_chardev_change(id, backend, &err);
1766
1767end:
1768 qapi_free_ChardevReturn(ret);
1769 qapi_free_ChardevBackend(backend);
1770 qemu_opts_del(opts);
187c6147 1771 hmp_handle_error(mon, err);
75b60160
AN
1772}
1773
f1088908
GH
1774void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1775{
1776 Error *local_err = NULL;
1777
1778 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
187c6147 1779 hmp_handle_error(mon, local_err);
f1088908 1780}
587da2c3 1781
bd1d5ad9
SF
1782void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
1783{
1784 Error *local_err = NULL;
1785
1786 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
187c6147 1787 hmp_handle_error(mon, local_err);
bd1d5ad9
SF
1788}
1789
ab2d0531
PB
1790void hmp_object_del(Monitor *mon, const QDict *qdict)
1791{
1792 const char *id = qdict_get_str(qdict, "id");
1793 Error *err = NULL;
1794
90998d58 1795 user_creatable_del(id, &err);
187c6147 1796 hmp_handle_error(mon, err);
ab2d0531 1797}
eb1539b2 1798
a631892f
ZG
1799void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
1800{
1801 Error *err = NULL;
1802 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
1803 MemoryDeviceInfoList *info;
d766b22b 1804 VirtioPMEMDeviceInfo *vpi;
a631892f
ZG
1805 MemoryDeviceInfo *value;
1806 PCDIMMDeviceInfo *di;
1807
1808 for (info = info_list; info; info = info->next) {
1809 value = info->value;
1810
1811 if (value) {
1fd5d4fe 1812 switch (value->type) {
a631892f 1813 case MEMORY_DEVICE_INFO_KIND_DIMM:
6388e18d 1814 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
d766b22b
DH
1815 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
1816 value->u.dimm.data : value->u.nvdimm.data;
a631892f 1817 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
977c736f 1818 MemoryDeviceInfoKind_str(value->type),
a631892f
ZG
1819 di->id ? di->id : "");
1820 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr);
1821 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot);
1822 monitor_printf(mon, " node: %" PRId64 "\n", di->node);
1823 monitor_printf(mon, " size: %" PRIu64 "\n", di->size);
1824 monitor_printf(mon, " memdev: %s\n", di->memdev);
1825 monitor_printf(mon, " hotplugged: %s\n",
1826 di->hotplugged ? "true" : "false");
1827 monitor_printf(mon, " hotpluggable: %s\n",
1828 di->hotpluggable ? "true" : "false");
d766b22b
DH
1829 break;
1830 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM:
1831 vpi = value->u.virtio_pmem.data;
1832 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1833 MemoryDeviceInfoKind_str(value->type),
1834 vpi->id ? vpi->id : "");
1835 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr);
1836 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size);
1837 monitor_printf(mon, " memdev: %s\n", vpi->memdev);
1838 break;
1839 default:
1840 g_assert_not_reached();
a631892f
ZG
1841 }
1842 }
1843 }
1844
1845 qapi_free_MemoryDeviceInfoList(info_list);
187c6147 1846 hmp_handle_error(mon, err);
a631892f 1847}
89d7fa9e 1848
62313160
TW
1849void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1850{
1851 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1852 IOThreadInfoList *info;
5fc00480 1853 IOThreadInfo *value;
62313160
TW
1854
1855 for (info = info_list; info; info = info->next) {
5fc00480
PH
1856 value = info->value;
1857 monitor_printf(mon, "%s:\n", value->id);
1858 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id);
1859 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns);
1860 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow);
1861 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink);
62313160
TW
1862 }
1863
1864 qapi_free_IOThreadInfoList(info_list);
1865}
1866
fafa4d50
SF
1867void hmp_rocker(Monitor *mon, const QDict *qdict)
1868{
1869 const char *name = qdict_get_str(qdict, "name");
1870 RockerSwitch *rocker;
533fdaed 1871 Error *err = NULL;
fafa4d50 1872
533fdaed
MA
1873 rocker = qmp_query_rocker(name, &err);
1874 if (err != NULL) {
187c6147 1875 hmp_handle_error(mon, err);
fafa4d50
SF
1876 return;
1877 }
1878
1879 monitor_printf(mon, "name: %s\n", rocker->name);
1880 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id);
1881 monitor_printf(mon, "ports: %d\n", rocker->ports);
1882
1883 qapi_free_RockerSwitch(rocker);
1884}
1885
1886void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
1887{
1888 RockerPortList *list, *port;
1889 const char *name = qdict_get_str(qdict, "name");
533fdaed 1890 Error *err = NULL;
fafa4d50 1891
533fdaed
MA
1892 list = qmp_query_rocker_ports(name, &err);
1893 if (err != NULL) {
187c6147 1894 hmp_handle_error(mon, err);
fafa4d50
SF
1895 return;
1896 }
1897
1898 monitor_printf(mon, " ena/ speed/ auto\n");
1899 monitor_printf(mon, " port link duplex neg?\n");
1900
1901 for (port = list; port; port = port->next) {
1902 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n",
1903 port->value->name,
1904 port->value->enabled ? port->value->link_up ?
1905 "up" : "down" : "!ena",
1906 port->value->speed == 10000 ? "10G" : "??",
1907 port->value->duplex ? "FD" : "HD",
1908 port->value->autoneg ? "Yes" : "No");
1909 }
1910
1911 qapi_free_RockerPortList(list);
1912}
1913
1914void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
1915{
1916 RockerOfDpaFlowList *list, *info;
1917 const char *name = qdict_get_str(qdict, "name");
1918 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1);
533fdaed 1919 Error *err = NULL;
fafa4d50 1920
533fdaed
MA
1921 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1922 if (err != NULL) {
187c6147 1923 hmp_handle_error(mon, err);
fafa4d50
SF
1924 return;
1925 }
1926
1927 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n");
1928
1929 for (info = list; info; info = info->next) {
1930 RockerOfDpaFlow *flow = info->value;
1931 RockerOfDpaFlowKey *key = flow->key;
1932 RockerOfDpaFlowMask *mask = flow->mask;
1933 RockerOfDpaFlowAction *action = flow->action;
1934
1935 if (flow->hits) {
1936 monitor_printf(mon, "%-4d %-3d %-4" PRIu64,
1937 key->priority, key->tbl_id, flow->hits);
1938 } else {
1939 monitor_printf(mon, "%-4d %-3d ",
1940 key->priority, key->tbl_id);
1941 }
1942
1943 if (key->has_in_pport) {
1944 monitor_printf(mon, " pport %d", key->in_pport);
1945 if (mask->has_in_pport) {
1946 monitor_printf(mon, "(0x%x)", mask->in_pport);
1947 }
1948 }
1949
1950 if (key->has_vlan_id) {
1951 monitor_printf(mon, " vlan %d",
1952 key->vlan_id & VLAN_VID_MASK);
1953 if (mask->has_vlan_id) {
1954 monitor_printf(mon, "(0x%x)", mask->vlan_id);
1955 }
1956 }
1957
1958 if (key->has_tunnel_id) {
1959 monitor_printf(mon, " tunnel %d", key->tunnel_id);
1960 if (mask->has_tunnel_id) {
1961 monitor_printf(mon, "(0x%x)", mask->tunnel_id);
1962 }
1963 }
1964
1965 if (key->has_eth_type) {
1966 switch (key->eth_type) {
1967 case 0x0806:
1968 monitor_printf(mon, " ARP");
1969 break;
1970 case 0x0800:
1971 monitor_printf(mon, " IP");
1972 break;
1973 case 0x86dd:
1974 monitor_printf(mon, " IPv6");
1975 break;
1976 case 0x8809:
1977 monitor_printf(mon, " LACP");
1978 break;
1979 case 0x88cc:
1980 monitor_printf(mon, " LLDP");
1981 break;
1982 default:
1983 monitor_printf(mon, " eth type 0x%04x", key->eth_type);
1984 break;
1985 }
1986 }
1987
1988 if (key->has_eth_src) {
1989 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) &&
1990 (mask->has_eth_src) &&
1991 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
1992 monitor_printf(mon, " src <any mcast/bcast>");
1993 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) &&
1994 (mask->has_eth_src) &&
1995 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) {
1996 monitor_printf(mon, " src <any ucast>");
1997 } else {
1998 monitor_printf(mon, " src %s", key->eth_src);
1999 if (mask->has_eth_src) {
2000 monitor_printf(mon, "(%s)", mask->eth_src);
2001 }
2002 }
2003 }
2004
2005 if (key->has_eth_dst) {
2006 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) &&
2007 (mask->has_eth_dst) &&
2008 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2009 monitor_printf(mon, " dst <any mcast/bcast>");
2010 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) &&
2011 (mask->has_eth_dst) &&
2012 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) {
2013 monitor_printf(mon, " dst <any ucast>");
2014 } else {
2015 monitor_printf(mon, " dst %s", key->eth_dst);
2016 if (mask->has_eth_dst) {
2017 monitor_printf(mon, "(%s)", mask->eth_dst);
2018 }
2019 }
2020 }
2021
2022 if (key->has_ip_proto) {
2023 monitor_printf(mon, " proto %d", key->ip_proto);
2024 if (mask->has_ip_proto) {
2025 monitor_printf(mon, "(0x%x)", mask->ip_proto);
2026 }
2027 }
2028
2029 if (key->has_ip_tos) {
2030 monitor_printf(mon, " TOS %d", key->ip_tos);
2031 if (mask->has_ip_tos) {
2032 monitor_printf(mon, "(0x%x)", mask->ip_tos);
2033 }
2034 }
2035
2036 if (key->has_ip_dst) {
2037 monitor_printf(mon, " dst %s", key->ip_dst);
2038 }
2039
2040 if (action->has_goto_tbl || action->has_group_id ||
2041 action->has_new_vlan_id) {
2042 monitor_printf(mon, " -->");
2043 }
2044
2045 if (action->has_new_vlan_id) {
2046 monitor_printf(mon, " apply new vlan %d",
2047 ntohs(action->new_vlan_id));
2048 }
2049
2050 if (action->has_group_id) {
2051 monitor_printf(mon, " write group 0x%08x", action->group_id);
2052 }
2053
2054 if (action->has_goto_tbl) {
2055 monitor_printf(mon, " goto tbl %d", action->goto_tbl);
2056 }
2057
2058 monitor_printf(mon, "\n");
2059 }
2060
2061 qapi_free_RockerOfDpaFlowList(list);
2062}
2063
2064void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
2065{
2066 RockerOfDpaGroupList *list, *g;
2067 const char *name = qdict_get_str(qdict, "name");
2068 uint8_t type = qdict_get_try_int(qdict, "type", 9);
533fdaed 2069 Error *err = NULL;
fafa4d50 2070
533fdaed
MA
2071 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2072 if (err != NULL) {
187c6147 2073 hmp_handle_error(mon, err);
fafa4d50
SF
2074 return;
2075 }
2076
2077 monitor_printf(mon, "id (decode) --> buckets\n");
2078
2079 for (g = list; g; g = g->next) {
2080 RockerOfDpaGroup *group = g->value;
916c9250 2081 bool set = false;
fafa4d50
SF
2082
2083 monitor_printf(mon, "0x%08x", group->id);
2084
2085 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" :
2086 group->type == 1 ? "L2 rewrite" :
2087 group->type == 2 ? "L3 unicast" :
2088 group->type == 3 ? "L2 multicast" :
2089 group->type == 4 ? "L2 flood" :
2090 group->type == 5 ? "L3 interface" :
2091 group->type == 6 ? "L3 multicast" :
2092 group->type == 7 ? "L3 ECMP" :
2093 group->type == 8 ? "L2 overlay" :
2094 "unknown");
2095
2096 if (group->has_vlan_id) {
2097 monitor_printf(mon, " vlan %d", group->vlan_id);
2098 }
2099
2100 if (group->has_pport) {
2101 monitor_printf(mon, " pport %d", group->pport);
2102 }
2103
2104 if (group->has_index) {
2105 monitor_printf(mon, " index %d", group->index);
2106 }
2107
2108 monitor_printf(mon, ") -->");
2109
2110 if (group->has_set_vlan_id && group->set_vlan_id) {
2111 set = true;
2112 monitor_printf(mon, " set vlan %d",
2113 group->set_vlan_id & VLAN_VID_MASK);
2114 }
2115
2116 if (group->has_set_eth_src) {
2117 if (!set) {
2118 set = true;
2119 monitor_printf(mon, " set");
2120 }
2121 monitor_printf(mon, " src %s", group->set_eth_src);
2122 }
2123
2124 if (group->has_set_eth_dst) {
2125 if (!set) {
fafa4d50
SF
2126 monitor_printf(mon, " set");
2127 }
2128 monitor_printf(mon, " dst %s", group->set_eth_dst);
2129 }
2130
fafa4d50
SF
2131 if (group->has_ttl_check && group->ttl_check) {
2132 monitor_printf(mon, " check TTL");
2133 }
2134
2135 if (group->has_group_id && group->group_id) {
2136 monitor_printf(mon, " group id 0x%08x", group->group_id);
2137 }
2138
2139 if (group->has_pop_vlan && group->pop_vlan) {
2140 monitor_printf(mon, " pop vlan");
2141 }
2142
2143 if (group->has_out_pport) {
2144 monitor_printf(mon, " out pport %d", group->out_pport);
2145 }
2146
2147 if (group->has_group_ids) {
2148 struct uint32List *id;
2149
2150 monitor_printf(mon, " groups [");
2151 for (id = group->group_ids; id; id = id->next) {
2152 monitor_printf(mon, "0x%08x", id->value);
2153 if (id->next) {
2154 monitor_printf(mon, ",");
2155 }
2156 }
2157 monitor_printf(mon, "]");
2158 }
2159
2160 monitor_printf(mon, "\n");
2161 }
2162
2163 qapi_free_RockerOfDpaGroupList(list);
2164}
4a6b52d6 2165
be9b23c4
PX
2166void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2167{
2168 ram_block_dump(mon);
2169}
2170
39164c13
IM
2171void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2172{
72d9196f
BW
2173 Error *err = NULL;
2174 GuidInfo *info = qmp_query_vm_generation_id(&err);
39164c13
IM
2175 if (info) {
2176 monitor_printf(mon, "%s\n", info->guid);
2177 }
187c6147 2178 hmp_handle_error(mon, err);
39164c13
IM
2179 qapi_free_GuidInfo(info);
2180}
d0f63c1e
VG
2181
2182void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
2183{
2184 Error *err = NULL;
2185 MemoryInfo *info = qmp_query_memory_size_summary(&err);
2186 if (info) {
2187 monitor_printf(mon, "base memory: %" PRIu64 "\n",
2188 info->base_memory);
2189
2190 if (info->has_plugged_memory) {
2191 monitor_printf(mon, "plugged memory: %" PRIu64 "\n",
2192 info->plugged_memory);
2193 }
2194
2195 qapi_free_MemoryInfo(info);
2196 }
187c6147 2197 hmp_handle_error(mon, err);
d0f63c1e 2198}