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