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