MAINTAINERS: add simplebench
[qemu.git] / monitor / hmp-cmds.c
1 /*
2 * Human Monitor Interface commands
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 *
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.
14 */
15
16 #include "qemu/osdep.h"
17 #include "monitor/hmp.h"
18 #include "net/net.h"
19 #include "net/eth.h"
20 #include "chardev/char.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/runstate.h"
23 #include "qemu/config-file.h"
24 #include "qemu/option.h"
25 #include "qemu/timer.h"
26 #include "qemu/sockets.h"
27 #include "monitor/monitor-internal.h"
28 #include "qapi/error.h"
29 #include "qapi/clone-visitor.h"
30 #include "qapi/opts-visitor.h"
31 #include "qapi/qapi-builtin-visit.h"
32 #include "qapi/qapi-commands-block.h"
33 #include "qapi/qapi-commands-char.h"
34 #include "qapi/qapi-commands-control.h"
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"
42 #include "qapi/qapi-visit-net.h"
43 #include "qapi/qapi-visit-migration.h"
44 #include "qapi/qmp/qdict.h"
45 #include "qapi/qmp/qerror.h"
46 #include "qapi/string-input-visitor.h"
47 #include "qapi/string-output-visitor.h"
48 #include "qom/object_interfaces.h"
49 #include "ui/console.h"
50 #include "qemu/cutils.h"
51 #include "qemu/error-report.h"
52 #include "exec/ramlist.h"
53 #include "hw/intc/intc.h"
54 #include "hw/rdma/rdma.h"
55 #include "migration/snapshot.h"
56 #include "migration/misc.h"
57
58 #ifdef CONFIG_SPICE
59 #include <spice/enums.h>
60 #endif
61
62 void hmp_handle_error(Monitor *mon, Error *err)
63 {
64 if (err) {
65 error_reportf_err(err, "Error: ");
66 }
67 }
68
69 /*
70 * Produce a strList from a comma separated list.
71 * A NULL or empty input string return NULL.
72 */
73 static 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
95 void hmp_info_name(Monitor *mon, const QDict *qdict)
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 }
105
106 void hmp_info_version(Monitor *mon, const QDict *qdict)
107 {
108 VersionInfo *info;
109
110 info = qmp_query_version(NULL);
111
112 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
113 info->qemu->major, info->qemu->minor, info->qemu->micro,
114 info->package);
115
116 qapi_free_VersionInfo(info);
117 }
118
119 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
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
134 void hmp_info_status(Monitor *mon, const QDict *qdict)
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) {
145 monitor_printf(mon, " (%s)", RunState_str(info->status));
146 }
147
148 monitor_printf(mon, "\n");
149
150 qapi_free_StatusInfo(info);
151 }
152
153 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
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 }
161
162 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
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 }
174
175 void hmp_info_mice(Monitor *mon, const QDict *qdict)
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
195 static 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
216 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
217 {
218 MigrationInfo *info;
219
220 info = qmp_query_migrate(NULL);
221
222 migration_global_dump(mon);
223
224 if (info->has_status) {
225 monitor_printf(mon, "Migration status: %s",
226 MigrationStatus_str(info->status));
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
234 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
235 info->total_time);
236 if (info->has_expected_downtime) {
237 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
238 info->expected_downtime);
239 }
240 if (info->has_downtime) {
241 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
242 info->downtime);
243 }
244 if (info->has_setup_time) {
245 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
246 info->setup_time);
247 }
248 }
249
250 if (info->has_ram) {
251 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
252 info->ram->transferred >> 10);
253 monitor_printf(mon, "throughput: %0.2f mbps\n",
254 info->ram->mbps);
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);
259 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
260 info->ram->duplicate);
261 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
262 info->ram->skipped);
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);
267 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
268 info->ram->dirty_sync_count);
269 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n",
270 info->ram->page_size >> 10);
271 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n",
272 info->ram->multifd_bytes >> 10);
273 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n",
274 info->ram->pages_per_second);
275
276 if (info->ram->dirty_pages_rate) {
277 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
278 info->ram->dirty_pages_rate);
279 }
280 if (info->ram->postcopy_requests) {
281 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
282 info->ram->postcopy_requests);
283 }
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
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);
304 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
305 info->xbzrle_cache->cache_miss_rate);
306 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
307 info->xbzrle_cache->overflow);
308 }
309
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
323 if (info->has_cpu_throttle_percentage) {
324 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n",
325 info->cpu_throttle_percentage);
326 }
327
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 }
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 }
355 qapi_free_MigrationInfo(info);
356 }
357
358 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
359 {
360 MigrationCapabilityStatusList *caps, *cap;
361
362 caps = qmp_query_migrate_capabilities(NULL);
363
364 if (caps) {
365 for (cap = caps; cap; cap = cap->next) {
366 monitor_printf(mon, "%s: %s\n",
367 MigrationCapability_str(cap->value->capability),
368 cap->value->state ? "on" : "off");
369 }
370 }
371
372 qapi_free_MigrationCapabilityStatusList(caps);
373 }
374
375 void 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) {
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);
394 assert(params->has_compress_level);
395 monitor_printf(mon, "%s: %u\n",
396 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
397 params->compress_level);
398 assert(params->has_compress_threads);
399 monitor_printf(mon, "%s: %u\n",
400 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
401 params->compress_threads);
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");
406 assert(params->has_decompress_threads);
407 monitor_printf(mon, "%s: %u\n",
408 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
409 params->decompress_threads);
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);
414 assert(params->has_cpu_throttle_initial);
415 monitor_printf(mon, "%s: %u\n",
416 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
417 params->cpu_throttle_initial);
418 assert(params->has_cpu_throttle_increment);
419 monitor_printf(mon, "%s: %u\n",
420 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
421 params->cpu_throttle_increment);
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);
426 assert(params->has_tls_creds);
427 monitor_printf(mon, "%s: '%s'\n",
428 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
429 params->tls_creds);
430 assert(params->has_tls_hostname);
431 monitor_printf(mon, "%s: '%s'\n",
432 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
433 params->tls_hostname);
434 assert(params->has_max_bandwidth);
435 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
436 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
437 params->max_bandwidth);
438 assert(params->has_downtime_limit);
439 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
440 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
441 params->downtime_limit);
442 assert(params->has_x_checkpoint_delay);
443 monitor_printf(mon, "%s: %u\n",
444 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
445 params->x_checkpoint_delay);
446 assert(params->has_block_incremental);
447 monitor_printf(mon, "%s: %s\n",
448 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
449 params->block_incremental ? "on" : "off");
450 monitor_printf(mon, "%s: %u\n",
451 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
452 params->multifd_channels);
453 monitor_printf(mon, "%s: %s\n",
454 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
455 MultiFDCompression_str(params->multifd_compression));
456 monitor_printf(mon, "%s: %" PRIu64 "\n",
457 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
458 params->xbzrle_cache_size);
459 monitor_printf(mon, "%s: %" PRIu64 "\n",
460 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
461 params->max_postcopy_bandwidth);
462 monitor_printf(mon, " %s: '%s'\n",
463 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
464 params->has_tls_authz ? params->tls_authz : "");
465 }
466
467 qapi_free_MigrationParameters(params);
468 }
469
470 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
471 {
472 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
473 qmp_query_migrate_cache_size(NULL) >> 10);
474 }
475
476
477 #ifdef CONFIG_VNC
478 /* Helper for hmp_info_vnc_clients, _servers */
479 static 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,
486 NetworkAddressFamily_str(info->family),
487 info->websocket ? " (Websocket)" : "");
488 }
489
490 /* Helper displaying and auth and crypt info */
491 static 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,
496 VncPrimaryAuth_str(auth),
497 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none");
498 }
499
500 static 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
517 static 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
528 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
529 {
530 VncInfo2List *info2l;
531 Error *err = NULL;
532
533 info2l = qmp_query_vnc_servers(&err);
534 if (err) {
535 hmp_handle_error(mon, err);
536 return;
537 }
538 if (!info2l) {
539 monitor_printf(mon, "None\n");
540 return;
541 }
542
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);
558 }
559 info2l = info2l->next;
560 }
561
562 qapi_free_VncInfo2List(info2l);
563
564 }
565 #endif
566
567 #ifdef CONFIG_SPICE
568 void hmp_info_spice(Monitor *mon, const QDict *qdict)
569 {
570 SpiceChannelList *chan;
571 SpiceInfo *info;
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",
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. */
588 [SPICE_CHANNEL_WEBDAV] = "webdav",
589 #endif
590 };
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 }
608 monitor_printf(mon, " migrated: %s\n",
609 info->migrated ? "true" : "false");
610 monitor_printf(mon, " auth: %s\n", info->auth);
611 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
612 monitor_printf(mon, " mouse-mode: %s\n",
613 SpiceQueryMouseMode_str(info->mouse_mode));
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",
621 chan->value->host, chan->value->port,
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);
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);
636 }
637 }
638
639 out:
640 qapi_free_SpiceInfo(info);
641 }
642 #endif
643
644 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
645 {
646 BalloonInfo *info;
647 Error *err = NULL;
648
649 info = qmp_query_balloon(&err);
650 if (err) {
651 hmp_handle_error(mon, err);
652 return;
653 }
654
655 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
656
657 qapi_free_BalloonInfo(info);
658 }
659
660 static 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
669 if (dev->class_info->has_desc) {
670 monitor_printf(mon, "%s", dev->class_info->desc);
671 } else {
672 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
673 }
674
675 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
676 dev->id->vendor, dev->id->device);
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 }
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",
688 dev->pci_bridge->bus->number);
689 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
690 dev->pci_bridge->bus->secondary);
691 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
692 dev->pci_bridge->bus->subordinate);
693
694 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
695 dev->pci_bridge->bus->io_range->base,
696 dev->pci_bridge->bus->io_range->limit);
697
698 monitor_printf(mon,
699 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
700 dev->pci_bridge->bus->memory_range->base,
701 dev->pci_bridge->bus->memory_range->limit);
702
703 monitor_printf(mon, " prefetchable memory range "
704 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
705 dev->pci_bridge->bus->prefetchable_range->base,
706 dev->pci_bridge->bus->prefetchable_range->limit);
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
742 static 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
774 void 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
780 static 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
800 void 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
806 static 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
826 void 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
832 void hmp_info_pci(Monitor *mon, const QDict *qdict)
833 {
834 PciInfoList *info_list, *info;
835 Error *err = NULL;
836
837 info_list = qmp_query_pci(&err);
838 if (err) {
839 monitor_printf(mon, "PCI devices not supported\n");
840 error_free(err);
841 return;
842 }
843
844 for (info = info_list; info; info = info->next) {
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
852 qapi_free_PciInfoList(info_list);
853 }
854
855 void 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;
861 TPMEmulatorOptions *teo;
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",
877 c, TpmModel_str(ti->model));
878
879 monitor_printf(mon, " \\ %s: type=%s",
880 ti->id, TpmTypeOptionsKind_str(ti->options->type));
881
882 switch (ti->options->type) {
883 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
884 tpo = ti->options->u.passthrough.data;
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;
891 case TPM_TYPE_OPTIONS_KIND_EMULATOR:
892 teo = ti->options->u.emulator.data;
893 monitor_printf(mon, ",chardev=%s", teo->chardev);
894 break;
895 case TPM_TYPE_OPTIONS_KIND__MAX:
896 break;
897 }
898 monitor_printf(mon, "\n");
899 c++;
900 }
901 qapi_free_TPMInfoList(info_list);
902 }
903
904 void hmp_quit(Monitor *mon, const QDict *qdict)
905 {
906 monitor_suspend(mon);
907 qmp_quit(NULL);
908 }
909
910 void hmp_stop(Monitor *mon, const QDict *qdict)
911 {
912 qmp_stop(NULL);
913 }
914
915 void 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);
935 hmp_handle_error(mon, err);
936 }
937 }
938
939 void hmp_system_reset(Monitor *mon, const QDict *qdict)
940 {
941 qmp_system_reset(NULL);
942 }
943
944 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
945 {
946 qmp_system_powerdown(NULL);
947 }
948
949 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
950 {
951 Error *err = NULL;
952
953 qmp_x_exit_preconfig(&err);
954 hmp_handle_error(mon, err);
955 }
956
957 void 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 }
968
969 void 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");
974 Error *err = NULL;
975 int cpu_index = monitor_get_cpu_index();
976
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);
983 hmp_handle_error(mon, err);
984 }
985
986 void 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");
991 Error *err = NULL;
992
993 qmp_pmemsave(addr, size, filename, &err);
994 hmp_handle_error(mon, err);
995 }
996
997 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
998 {
999 const char *chardev = qdict_get_str(qdict, "device");
1000 const char *data = qdict_get_str(qdict, "data");
1001 Error *err = NULL;
1002
1003 qmp_ringbuf_write(chardev, data, false, 0, &err);
1004
1005 hmp_handle_error(mon, err);
1006 }
1007
1008 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
1009 {
1010 uint32_t size = qdict_get_int(qdict, "size");
1011 const char *chardev = qdict_get_str(qdict, "device");
1012 char *data;
1013 Error *err = NULL;
1014 int i;
1015
1016 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
1017 if (err) {
1018 hmp_handle_error(mon, err);
1019 return;
1020 }
1021
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");
1035 g_free(data);
1036 }
1037
1038 void hmp_cont(Monitor *mon, const QDict *qdict)
1039 {
1040 Error *err = NULL;
1041
1042 qmp_cont(&err);
1043 hmp_handle_error(mon, err);
1044 }
1045
1046 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
1047 {
1048 Error *err = NULL;
1049
1050 qmp_system_wakeup(&err);
1051 hmp_handle_error(mon, err);
1052 }
1053
1054 void hmp_nmi(Monitor *mon, const QDict *qdict)
1055 {
1056 Error *err = NULL;
1057
1058 qmp_inject_nmi(&err);
1059 hmp_handle_error(mon, err);
1060 }
1061
1062 void hmp_set_link(Monitor *mon, const QDict *qdict)
1063 {
1064 const char *name = qdict_get_str(qdict, "name");
1065 bool up = qdict_get_bool(qdict, "up");
1066 Error *err = NULL;
1067
1068 qmp_set_link(name, up, &err);
1069 hmp_handle_error(mon, err);
1070 }
1071
1072 void hmp_balloon(Monitor *mon, const QDict *qdict)
1073 {
1074 int64_t value = qdict_get_int(qdict, "value");
1075 Error *err = NULL;
1076
1077 qmp_balloon(value, &err);
1078 hmp_handle_error(mon, err);
1079 }
1080
1081 void 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");
1085 Error *err = NULL;
1086
1087 vm_stop(RUN_STATE_RESTORE_VM);
1088
1089 if (load_snapshot(name, &err) == 0 && saved_vm_running) {
1090 vm_start();
1091 }
1092 hmp_handle_error(mon, err);
1093 }
1094
1095 void hmp_savevm(Monitor *mon, const QDict *qdict)
1096 {
1097 Error *err = NULL;
1098
1099 save_snapshot(qdict_get_try_str(qdict, "name"), &err);
1100 hmp_handle_error(mon, err);
1101 }
1102
1103 void hmp_delvm(Monitor *mon, const QDict *qdict)
1104 {
1105 BlockDriverState *bs;
1106 Error *err = NULL;
1107 const char *name = qdict_get_str(qdict, "name");
1108
1109 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) {
1110 error_prepend(&err,
1111 "deleting snapshot on device '%s': ",
1112 bdrv_get_device_name(bs));
1113 }
1114 hmp_handle_error(mon, err);
1115 }
1116
1117 void hmp_announce_self(Monitor *mon, const QDict *qdict)
1118 {
1119 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
1120 const char *id = qdict_get_try_str(qdict, "id");
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;
1127 params->id = g_strdup(id);
1128 params->has_id = !!params->id;
1129 qmp_announce_self(params, NULL);
1130 qapi_free_AnnounceParameters(params);
1131 }
1132
1133 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1134 {
1135 qmp_migrate_cancel(NULL);
1136 }
1137
1138 void 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
1148 hmp_handle_error(mon, err);
1149 }
1150
1151 void 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
1158 hmp_handle_error(mon, err);
1159 }
1160
1161 void 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
1168 hmp_handle_error(mon, err);
1169 }
1170
1171 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
1172 {
1173 Error *err = NULL;
1174
1175 qmp_migrate_pause(&err);
1176
1177 hmp_handle_error(mon, err);
1178 }
1179
1180 /* Kept for backwards compatibility */
1181 void 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 }
1186
1187 void 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);
1193 hmp_handle_error(mon, err);
1194 }
1195
1196 /* Kept for backwards compatibility */
1197 void 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 }
1202
1203 void 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));
1209 int val;
1210
1211 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
1212 if (val < 0) {
1213 goto end;
1214 }
1215
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);
1221
1222 end:
1223 qapi_free_MigrationCapabilityStatusList(caps);
1224 hmp_handle_error(mon, err);
1225 }
1226
1227 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
1228 {
1229 const char *param = qdict_get_str(qdict, "parameter");
1230 const char *valuestr = qdict_get_str(qdict, "value");
1231 Visitor *v = string_input_visitor_new(valuestr);
1232 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
1233 uint64_t valuebw = 0;
1234 uint64_t cache_size;
1235 MultiFDCompression compress_type;
1236 Error *err = NULL;
1237 int val, ret;
1238
1239 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
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;
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;
1257 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
1258 p->has_decompress_threads = true;
1259 visit_type_int(v, param, &p->decompress_threads, &err);
1260 break;
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);
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;
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;
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;
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;
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);
1304 break;
1305 }
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;
1320 case MIGRATION_PARAMETER_MULTIFD_CHANNELS:
1321 p->has_multifd_channels = true;
1322 visit_type_int(v, param, &p->multifd_channels, &err);
1323 break;
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;
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;
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;
1340 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE:
1341 p->has_xbzrle_cache_size = true;
1342 visit_type_size(v, param, &cache_size, &err);
1343 if (err) {
1344 break;
1345 }
1346 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) {
1347 error_setg(&err, "Invalid size %s", valuestr);
1348 break;
1349 }
1350 p->xbzrle_cache_size = cache_size;
1351 break;
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;
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;
1372 default:
1373 assert(0);
1374 }
1375
1376 if (err) {
1377 goto cleanup;
1378 }
1379
1380 qmp_migrate_set_parameters(p, &err);
1381
1382 cleanup:
1383 qapi_free_MigrateSetParameters(p);
1384 visit_free(v);
1385 hmp_handle_error(mon, err);
1386 }
1387
1388 void 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);
1402 hmp_handle_error(mon, err);
1403 }
1404
1405 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
1406 {
1407 Error *err = NULL;
1408 qmp_migrate_start_postcopy(&err);
1409 hmp_handle_error(mon, err);
1410 }
1411
1412 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
1413 {
1414 Error *err = NULL;
1415
1416 qmp_x_colo_lost_heartbeat(&err);
1417 hmp_handle_error(mon, err);
1418 }
1419
1420 void 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);
1428 hmp_handle_error(mon, err);
1429 }
1430
1431 void 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);
1438 hmp_handle_error(mon, err);
1439 }
1440
1441
1442 #ifdef CONFIG_VNC
1443 static void hmp_change_read_arg(void *opaque, const char *password,
1444 void *readline_opaque)
1445 {
1446 qmp_change_vnc_password(password, NULL);
1447 monitor_read_command(opaque, 1);
1448 }
1449 #endif
1450
1451 void 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");
1456 const char *read_only = qdict_get_try_str(qdict, "read-only-mode");
1457 BlockdevChangeReadOnlyMode read_only_mode = 0;
1458 Error *err = NULL;
1459
1460 #ifdef CONFIG_VNC
1461 if (strcmp(device, "vnc") == 0) {
1462 if (read_only) {
1463 monitor_printf(mon,
1464 "Parameter 'read-only-mode' is invalid for VNC\n");
1465 return;
1466 }
1467 if (strcmp(target, "passwd") == 0 ||
1468 strcmp(target, "password") == 0) {
1469 if (!arg) {
1470 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common);
1471 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL);
1472 return;
1473 }
1474 }
1475 qmp_change("vnc", target, !!arg, arg, &err);
1476 } else
1477 #endif
1478 {
1479 if (read_only) {
1480 read_only_mode =
1481 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
1482 read_only,
1483 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
1484 if (err) {
1485 hmp_handle_error(mon, err);
1486 return;
1487 }
1488 }
1489
1490 qmp_blockdev_change_medium(true, device, false, NULL, target,
1491 !!arg, arg, !!read_only, read_only_mode,
1492 &err);
1493 }
1494
1495 hmp_handle_error(mon, err);
1496 }
1497
1498 typedef struct HMPMigrationStatus
1499 {
1500 QEMUTimer *timer;
1501 Monitor *mon;
1502 bool is_block_migration;
1503 } HMPMigrationStatus;
1504
1505 static void hmp_migrate_status_cb(void *opaque)
1506 {
1507 HMPMigrationStatus *status = opaque;
1508 MigrationInfo *info;
1509
1510 info = qmp_query_migrate(NULL);
1511 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE ||
1512 info->status == MIGRATION_STATUS_SETUP) {
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
1526 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1527 } else {
1528 if (status->is_block_migration) {
1529 monitor_printf(status->mon, "\n");
1530 }
1531 if (info->has_error_desc) {
1532 error_report("%s", info->error_desc);
1533 }
1534 monitor_resume(status->mon);
1535 timer_del(status->timer);
1536 timer_free(status->timer);
1537 g_free(status);
1538 }
1539
1540 qapi_free_MigrationInfo(info);
1541 }
1542
1543 void hmp_migrate(Monitor *mon, const QDict *qdict)
1544 {
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);
1548 bool resume = qdict_get_try_bool(qdict, "resume", false);
1549 const char *uri = qdict_get_str(qdict, "uri");
1550 Error *err = NULL;
1551
1552 qmp_migrate(uri, !!blk, blk, !!inc, inc,
1553 false, false, true, resume, &err);
1554 if (err) {
1555 hmp_handle_error(mon, err);
1556 return;
1557 }
1558
1559 if (!detach) {
1560 HMPMigrationStatus *status;
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;
1571 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1572 status);
1573 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1574 }
1575 }
1576
1577 void 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);
1583 if (err) {
1584 goto out;
1585 }
1586
1587 netdev_add(opts, &err);
1588 if (err) {
1589 qemu_opts_del(opts);
1590 }
1591
1592 out:
1593 hmp_handle_error(mon, err);
1594 }
1595
1596 void 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);
1602 hmp_handle_error(mon, err);
1603 }
1604
1605 void hmp_object_add(Monitor *mon, const QDict *qdict)
1606 {
1607 Error *err = NULL;
1608 QemuOpts *opts;
1609 Object *obj = NULL;
1610
1611 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1612 if (err) {
1613 hmp_handle_error(mon, err);
1614 return;
1615 }
1616
1617 obj = user_creatable_add_opts(opts, &err);
1618 qemu_opts_del(opts);
1619
1620 if (err) {
1621 hmp_handle_error(mon, err);
1622 }
1623 if (obj) {
1624 object_unref(obj);
1625 }
1626 }
1627
1628 void hmp_getfd(Monitor *mon, const QDict *qdict)
1629 {
1630 const char *fdname = qdict_get_str(qdict, "fdname");
1631 Error *err = NULL;
1632
1633 qmp_getfd(fdname, &err);
1634 hmp_handle_error(mon, err);
1635 }
1636
1637 void hmp_closefd(Monitor *mon, const QDict *qdict)
1638 {
1639 const char *fdname = qdict_get_str(qdict, "fdname");
1640 Error *err = NULL;
1641
1642 qmp_closefd(fdname, &err);
1643 hmp_handle_error(mon, err);
1644 }
1645
1646 void hmp_sendkey(Monitor *mon, const QDict *qdict)
1647 {
1648 const char *keys = qdict_get_str(qdict, "keys");
1649 KeyValueList *keylist, *head = NULL, *tmp = NULL;
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;
1653 const char *separator;
1654 int keyname_len;
1655
1656 while (1) {
1657 separator = qemu_strchrnul(keys, '-');
1658 keyname_len = separator - keys;
1659
1660 /* Be compatible with old interface, convert user inputted "<" */
1661 if (keys[0] == '<' && keyname_len == 1) {
1662 keys = "less";
1663 keyname_len = 4;
1664 }
1665
1666 keylist = g_malloc0(sizeof(*keylist));
1667 keylist->value = g_malloc0(sizeof(*keylist->value));
1668
1669 if (!head) {
1670 head = keylist;
1671 }
1672 if (tmp) {
1673 tmp->next = keylist;
1674 }
1675 tmp = keylist;
1676
1677 if (strstart(keys, "0x", NULL)) {
1678 char *endp;
1679 int value = strtoul(keys, &endp, 0);
1680 assert(endp <= keys + keyname_len);
1681 if (endp != keys + keyname_len) {
1682 goto err_out;
1683 }
1684 keylist->value->type = KEY_VALUE_KIND_NUMBER;
1685 keylist->value->u.number.data = value;
1686 } else {
1687 int idx = index_from_key(keys, keyname_len);
1688 if (idx == Q_KEY_CODE__MAX) {
1689 goto err_out;
1690 }
1691 keylist->value->type = KEY_VALUE_KIND_QCODE;
1692 keylist->value->u.qcode.data = idx;
1693 }
1694
1695 if (!*separator) {
1696 break;
1697 }
1698 keys = separator + 1;
1699 }
1700
1701 qmp_send_key(head, has_hold_time, hold_time, &err);
1702 hmp_handle_error(mon, err);
1703
1704 out:
1705 qapi_free_KeyValueList(head);
1706 return;
1707
1708 err_out:
1709 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys);
1710 goto out;
1711 }
1712
1713 void hmp_screendump(Monitor *mon, const QDict *qdict)
1714 {
1715 const char *filename = qdict_get_str(qdict, "filename");
1716 const char *id = qdict_get_try_str(qdict, "device");
1717 int64_t head = qdict_get_try_int(qdict, "head", 0);
1718 Error *err = NULL;
1719
1720 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
1721 hmp_handle_error(mon, err);
1722 }
1723
1724 void 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
1730 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true);
1731 if (opts == NULL) {
1732 error_setg(&err, "Parsing chardev args failed");
1733 } else {
1734 qemu_chr_new_from_opts(opts, NULL, &err);
1735 qemu_opts_del(opts);
1736 }
1737 hmp_handle_error(mon, err);
1738 }
1739
1740 void 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
1767 end:
1768 qapi_free_ChardevReturn(ret);
1769 qapi_free_ChardevBackend(backend);
1770 qemu_opts_del(opts);
1771 hmp_handle_error(mon, err);
1772 }
1773
1774 void 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);
1779 hmp_handle_error(mon, local_err);
1780 }
1781
1782 void 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);
1787 hmp_handle_error(mon, local_err);
1788 }
1789
1790 void hmp_object_del(Monitor *mon, const QDict *qdict)
1791 {
1792 const char *id = qdict_get_str(qdict, "id");
1793 Error *err = NULL;
1794
1795 user_creatable_del(id, &err);
1796 hmp_handle_error(mon, err);
1797 }
1798
1799 void 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;
1804 VirtioPMEMDeviceInfo *vpi;
1805 MemoryDeviceInfo *value;
1806 PCDIMMDeviceInfo *di;
1807
1808 for (info = info_list; info; info = info->next) {
1809 value = info->value;
1810
1811 if (value) {
1812 switch (value->type) {
1813 case MEMORY_DEVICE_INFO_KIND_DIMM:
1814 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
1815 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ?
1816 value->u.dimm.data : value->u.nvdimm.data;
1817 monitor_printf(mon, "Memory device [%s]: \"%s\"\n",
1818 MemoryDeviceInfoKind_str(value->type),
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");
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();
1841 }
1842 }
1843 }
1844
1845 qapi_free_MemoryDeviceInfoList(info_list);
1846 hmp_handle_error(mon, err);
1847 }
1848
1849 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
1850 {
1851 IOThreadInfoList *info_list = qmp_query_iothreads(NULL);
1852 IOThreadInfoList *info;
1853 IOThreadInfo *value;
1854
1855 for (info = info_list; info; info = info->next) {
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);
1862 }
1863
1864 qapi_free_IOThreadInfoList(info_list);
1865 }
1866
1867 void hmp_rocker(Monitor *mon, const QDict *qdict)
1868 {
1869 const char *name = qdict_get_str(qdict, "name");
1870 RockerSwitch *rocker;
1871 Error *err = NULL;
1872
1873 rocker = qmp_query_rocker(name, &err);
1874 if (err != NULL) {
1875 hmp_handle_error(mon, err);
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
1886 void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
1887 {
1888 RockerPortList *list, *port;
1889 const char *name = qdict_get_str(qdict, "name");
1890 Error *err = NULL;
1891
1892 list = qmp_query_rocker_ports(name, &err);
1893 if (err != NULL) {
1894 hmp_handle_error(mon, err);
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
1914 void 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);
1919 Error *err = NULL;
1920
1921 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
1922 if (err != NULL) {
1923 hmp_handle_error(mon, err);
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
2064 void 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);
2069 Error *err = NULL;
2070
2071 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
2072 if (err != NULL) {
2073 hmp_handle_error(mon, err);
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;
2081 bool set = false;
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) {
2126 monitor_printf(mon, " set");
2127 }
2128 monitor_printf(mon, " dst %s", group->set_eth_dst);
2129 }
2130
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 }
2165
2166 void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
2167 {
2168 ram_block_dump(mon);
2169 }
2170
2171 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
2172 {
2173 Error *err = NULL;
2174 GuidInfo *info = qmp_query_vm_generation_id(&err);
2175 if (info) {
2176 monitor_printf(mon, "%s\n", info->guid);
2177 }
2178 hmp_handle_error(mon, err);
2179 qapi_free_GuidInfo(info);
2180 }
2181
2182 void 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 }
2197 hmp_handle_error(mon, err);
2198 }