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 "block/nbd.h" 51 #include "block/qapi.h" 52 #include "qemu-io.h" 53 #include "qemu/cutils.h" 54 #include "qemu/error-report.h" 55 #include "exec/ramlist.h" 56 #include "hw/intc/intc.h" 57 #include "hw/rdma/rdma.h" 58 #include "migration/snapshot.h" 59 #include "migration/misc.h" 60 61 #ifdef CONFIG_SPICE 62 #include <spice/enums.h> 63 #endif 64 65 void hmp_handle_error(Monitor *mon, Error *err) 66 { 67 if (err) { 68 error_reportf_err(err, "Error: "); 69 } 70 } 71 72 /* 73 * Produce a strList from a comma separated list. 74 * A NULL or empty input string return NULL. 75 */ 76 static strList *strList_from_comma_list(const char *in) 77 { 78 strList *res = NULL; 79 strList **hook = &res; 80 81 while (in && in[0]) { 82 char *comma = strchr(in, ','); 83 *hook = g_new0(strList, 1); 84 85 if (comma) { 86 (*hook)->value = g_strndup(in, comma - in); 87 in = comma + 1; /* skip the , */ 88 } else { 89 (*hook)->value = g_strdup(in); 90 in = NULL; 91 } 92 hook = &(*hook)->next; 93 } 94 95 return res; 96 } 97 98 void hmp_info_name(Monitor *mon, const QDict *qdict) 99 { 100 NameInfo *info; 101 102 info = qmp_query_name(NULL); 103 if (info->has_name) { 104 monitor_printf(mon, "%s\n", info->name); 105 } 106 qapi_free_NameInfo(info); 107 } 108 109 void hmp_info_version(Monitor *mon, const QDict *qdict) 110 { 111 VersionInfo *info; 112 113 info = qmp_query_version(NULL); 114 115 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", 116 info->qemu->major, info->qemu->minor, info->qemu->micro, 117 info->package); 118 119 qapi_free_VersionInfo(info); 120 } 121 122 void hmp_info_kvm(Monitor *mon, const QDict *qdict) 123 { 124 KvmInfo *info; 125 126 info = qmp_query_kvm(NULL); 127 monitor_printf(mon, "kvm support: "); 128 if (info->present) { 129 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); 130 } else { 131 monitor_printf(mon, "not compiled\n"); 132 } 133 134 qapi_free_KvmInfo(info); 135 } 136 137 void hmp_info_status(Monitor *mon, const QDict *qdict) 138 { 139 StatusInfo *info; 140 141 info = qmp_query_status(NULL); 142 143 monitor_printf(mon, "VM status: %s%s", 144 info->running ? "running" : "paused", 145 info->singlestep ? " (single step mode)" : ""); 146 147 if (!info->running && info->status != RUN_STATE_PAUSED) { 148 monitor_printf(mon, " (%s)", RunState_str(info->status)); 149 } 150 151 monitor_printf(mon, "\n"); 152 153 qapi_free_StatusInfo(info); 154 } 155 156 void hmp_info_uuid(Monitor *mon, const QDict *qdict) 157 { 158 UuidInfo *info; 159 160 info = qmp_query_uuid(NULL); 161 monitor_printf(mon, "%s\n", info->UUID); 162 qapi_free_UuidInfo(info); 163 } 164 165 void hmp_info_chardev(Monitor *mon, const QDict *qdict) 166 { 167 ChardevInfoList *char_info, *info; 168 169 char_info = qmp_query_chardev(NULL); 170 for (info = char_info; info; info = info->next) { 171 monitor_printf(mon, "%s: filename=%s\n", info->value->label, 172 info->value->filename); 173 } 174 175 qapi_free_ChardevInfoList(char_info); 176 } 177 178 void hmp_info_mice(Monitor *mon, const QDict *qdict) 179 { 180 MouseInfoList *mice_list, *mouse; 181 182 mice_list = qmp_query_mice(NULL); 183 if (!mice_list) { 184 monitor_printf(mon, "No mouse devices connected\n"); 185 return; 186 } 187 188 for (mouse = mice_list; mouse; mouse = mouse->next) { 189 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", 190 mouse->value->current ? '*' : ' ', 191 mouse->value->index, mouse->value->name, 192 mouse->value->absolute ? " (absolute)" : ""); 193 } 194 195 qapi_free_MouseInfoList(mice_list); 196 } 197 198 static char *SocketAddress_to_str(SocketAddress *addr) 199 { 200 switch (addr->type) { 201 case SOCKET_ADDRESS_TYPE_INET: 202 return g_strdup_printf("tcp:%s:%s", 203 addr->u.inet.host, 204 addr->u.inet.port); 205 case SOCKET_ADDRESS_TYPE_UNIX: 206 return g_strdup_printf("unix:%s", 207 addr->u.q_unix.path); 208 case SOCKET_ADDRESS_TYPE_FD: 209 return g_strdup_printf("fd:%s", addr->u.fd.str); 210 case SOCKET_ADDRESS_TYPE_VSOCK: 211 return g_strdup_printf("tcp:%s:%s", 212 addr->u.vsock.cid, 213 addr->u.vsock.port); 214 default: 215 return g_strdup("unknown address type"); 216 } 217 } 218 219 void hmp_info_migrate(Monitor *mon, const QDict *qdict) 220 { 221 MigrationInfo *info; 222 223 info = qmp_query_migrate(NULL); 224 225 migration_global_dump(mon); 226 227 if (info->has_status) { 228 monitor_printf(mon, "Migration status: %s", 229 MigrationStatus_str(info->status)); 230 if (info->status == MIGRATION_STATUS_FAILED && 231 info->has_error_desc) { 232 monitor_printf(mon, " (%s)\n", info->error_desc); 233 } else { 234 monitor_printf(mon, "\n"); 235 } 236 237 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n", 238 info->total_time); 239 if (info->has_expected_downtime) { 240 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n", 241 info->expected_downtime); 242 } 243 if (info->has_downtime) { 244 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n", 245 info->downtime); 246 } 247 if (info->has_setup_time) { 248 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n", 249 info->setup_time); 250 } 251 } 252 253 if (info->has_ram) { 254 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", 255 info->ram->transferred >> 10); 256 monitor_printf(mon, "throughput: %0.2f mbps\n", 257 info->ram->mbps); 258 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", 259 info->ram->remaining >> 10); 260 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", 261 info->ram->total >> 10); 262 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", 263 info->ram->duplicate); 264 monitor_printf(mon, "skipped: %" PRIu64 " pages\n", 265 info->ram->skipped); 266 monitor_printf(mon, "normal: %" PRIu64 " pages\n", 267 info->ram->normal); 268 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", 269 info->ram->normal_bytes >> 10); 270 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", 271 info->ram->dirty_sync_count); 272 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", 273 info->ram->page_size >> 10); 274 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", 275 info->ram->multifd_bytes >> 10); 276 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", 277 info->ram->pages_per_second); 278 279 if (info->ram->dirty_pages_rate) { 280 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", 281 info->ram->dirty_pages_rate); 282 } 283 if (info->ram->postcopy_requests) { 284 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", 285 info->ram->postcopy_requests); 286 } 287 } 288 289 if (info->has_disk) { 290 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", 291 info->disk->transferred >> 10); 292 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", 293 info->disk->remaining >> 10); 294 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", 295 info->disk->total >> 10); 296 } 297 298 if (info->has_xbzrle_cache) { 299 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", 300 info->xbzrle_cache->cache_size); 301 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", 302 info->xbzrle_cache->bytes >> 10); 303 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", 304 info->xbzrle_cache->pages); 305 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n", 306 info->xbzrle_cache->cache_miss); 307 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", 308 info->xbzrle_cache->cache_miss_rate); 309 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n", 310 info->xbzrle_cache->overflow); 311 } 312 313 if (info->has_compression) { 314 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", 315 info->compression->pages); 316 monitor_printf(mon, "compression busy: %" PRIu64 "\n", 317 info->compression->busy); 318 monitor_printf(mon, "compression busy rate: %0.2f\n", 319 info->compression->busy_rate); 320 monitor_printf(mon, "compressed size: %" PRIu64 "\n", 321 info->compression->compressed_size); 322 monitor_printf(mon, "compression rate: %0.2f\n", 323 info->compression->compression_rate); 324 } 325 326 if (info->has_cpu_throttle_percentage) { 327 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", 328 info->cpu_throttle_percentage); 329 } 330 331 if (info->has_postcopy_blocktime) { 332 monitor_printf(mon, "postcopy blocktime: %u\n", 333 info->postcopy_blocktime); 334 } 335 336 if (info->has_postcopy_vcpu_blocktime) { 337 Visitor *v; 338 char *str; 339 v = string_output_visitor_new(false, &str); 340 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, NULL); 341 visit_complete(v, &str); 342 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); 343 g_free(str); 344 visit_free(v); 345 } 346 if (info->has_socket_address) { 347 SocketAddressList *addr; 348 349 monitor_printf(mon, "socket address: [\n"); 350 351 for (addr = info->socket_address; addr; addr = addr->next) { 352 char *s = SocketAddress_to_str(addr->value); 353 monitor_printf(mon, "\t%s\n", s); 354 g_free(s); 355 } 356 monitor_printf(mon, "]\n"); 357 } 358 qapi_free_MigrationInfo(info); 359 } 360 361 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) 362 { 363 MigrationCapabilityStatusList *caps, *cap; 364 365 caps = qmp_query_migrate_capabilities(NULL); 366 367 if (caps) { 368 for (cap = caps; cap; cap = cap->next) { 369 monitor_printf(mon, "%s: %s\n", 370 MigrationCapability_str(cap->value->capability), 371 cap->value->state ? "on" : "off"); 372 } 373 } 374 375 qapi_free_MigrationCapabilityStatusList(caps); 376 } 377 378 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) 379 { 380 MigrationParameters *params; 381 382 params = qmp_query_migrate_parameters(NULL); 383 384 if (params) { 385 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 386 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), 387 params->announce_initial); 388 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 389 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), 390 params->announce_max); 391 monitor_printf(mon, "%s: %" PRIu64 "\n", 392 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), 393 params->announce_rounds); 394 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 395 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), 396 params->announce_step); 397 assert(params->has_compress_level); 398 monitor_printf(mon, "%s: %u\n", 399 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), 400 params->compress_level); 401 assert(params->has_compress_threads); 402 monitor_printf(mon, "%s: %u\n", 403 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), 404 params->compress_threads); 405 assert(params->has_compress_wait_thread); 406 monitor_printf(mon, "%s: %s\n", 407 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), 408 params->compress_wait_thread ? "on" : "off"); 409 assert(params->has_decompress_threads); 410 monitor_printf(mon, "%s: %u\n", 411 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), 412 params->decompress_threads); 413 assert(params->has_cpu_throttle_initial); 414 monitor_printf(mon, "%s: %u\n", 415 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), 416 params->cpu_throttle_initial); 417 assert(params->has_cpu_throttle_increment); 418 monitor_printf(mon, "%s: %u\n", 419 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), 420 params->cpu_throttle_increment); 421 assert(params->has_max_cpu_throttle); 422 monitor_printf(mon, "%s: %u\n", 423 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), 424 params->max_cpu_throttle); 425 assert(params->has_tls_creds); 426 monitor_printf(mon, "%s: '%s'\n", 427 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), 428 params->tls_creds); 429 assert(params->has_tls_hostname); 430 monitor_printf(mon, "%s: '%s'\n", 431 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), 432 params->tls_hostname); 433 assert(params->has_max_bandwidth); 434 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", 435 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), 436 params->max_bandwidth); 437 assert(params->has_downtime_limit); 438 monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n", 439 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), 440 params->downtime_limit); 441 assert(params->has_x_checkpoint_delay); 442 monitor_printf(mon, "%s: %u\n", 443 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), 444 params->x_checkpoint_delay); 445 assert(params->has_block_incremental); 446 monitor_printf(mon, "%s: %s\n", 447 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), 448 params->block_incremental ? "on" : "off"); 449 monitor_printf(mon, "%s: %u\n", 450 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), 451 params->multifd_channels); 452 monitor_printf(mon, "%s: %s\n", 453 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION), 454 MultiFDCompression_str(params->multifd_compression)); 455 monitor_printf(mon, "%s: %" PRIu64 "\n", 456 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), 457 params->xbzrle_cache_size); 458 monitor_printf(mon, "%s: %" PRIu64 "\n", 459 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), 460 params->max_postcopy_bandwidth); 461 monitor_printf(mon, " %s: '%s'\n", 462 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), 463 params->has_tls_authz ? params->tls_authz : ""); 464 } 465 466 qapi_free_MigrationParameters(params); 467 } 468 469 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) 470 { 471 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", 472 qmp_query_migrate_cache_size(NULL) >> 10); 473 } 474 475 static void print_block_info(Monitor *mon, BlockInfo *info, 476 BlockDeviceInfo *inserted, bool verbose) 477 { 478 ImageInfo *image_info; 479 480 assert(!info || !info->has_inserted || info->inserted == inserted); 481 482 if (info && *info->device) { 483 monitor_printf(mon, "%s", info->device); 484 if (inserted && inserted->has_node_name) { 485 monitor_printf(mon, " (%s)", inserted->node_name); 486 } 487 } else { 488 assert(info || inserted); 489 monitor_printf(mon, "%s", 490 inserted && inserted->has_node_name ? inserted->node_name 491 : info && info->has_qdev ? info->qdev 492 : "<anonymous>"); 493 } 494 495 if (inserted) { 496 monitor_printf(mon, ": %s (%s%s%s)\n", 497 inserted->file, 498 inserted->drv, 499 inserted->ro ? ", read-only" : "", 500 inserted->encrypted ? ", encrypted" : ""); 501 } else { 502 monitor_printf(mon, ": [not inserted]\n"); 503 } 504 505 if (info) { 506 if (info->has_qdev) { 507 monitor_printf(mon, " Attached to: %s\n", info->qdev); 508 } 509 if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) { 510 monitor_printf(mon, " I/O status: %s\n", 511 BlockDeviceIoStatus_str(info->io_status)); 512 } 513 514 if (info->removable) { 515 monitor_printf(mon, " Removable device: %slocked, tray %s\n", 516 info->locked ? "" : "not ", 517 info->tray_open ? "open" : "closed"); 518 } 519 } 520 521 522 if (!inserted) { 523 return; 524 } 525 526 monitor_printf(mon, " Cache mode: %s%s%s\n", 527 inserted->cache->writeback ? "writeback" : "writethrough", 528 inserted->cache->direct ? ", direct" : "", 529 inserted->cache->no_flush ? ", ignore flushes" : ""); 530 531 if (inserted->has_backing_file) { 532 monitor_printf(mon, 533 " Backing file: %s " 534 "(chain depth: %" PRId64 ")\n", 535 inserted->backing_file, 536 inserted->backing_file_depth); 537 } 538 539 if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { 540 monitor_printf(mon, " Detect zeroes: %s\n", 541 BlockdevDetectZeroesOptions_str(inserted->detect_zeroes)); 542 } 543 544 if (inserted->bps || inserted->bps_rd || inserted->bps_wr || 545 inserted->iops || inserted->iops_rd || inserted->iops_wr) 546 { 547 monitor_printf(mon, " I/O throttling: bps=%" PRId64 548 " bps_rd=%" PRId64 " bps_wr=%" PRId64 549 " bps_max=%" PRId64 550 " bps_rd_max=%" PRId64 551 " bps_wr_max=%" PRId64 552 " iops=%" PRId64 " iops_rd=%" PRId64 553 " iops_wr=%" PRId64 554 " iops_max=%" PRId64 555 " iops_rd_max=%" PRId64 556 " iops_wr_max=%" PRId64 557 " iops_size=%" PRId64 558 " group=%s\n", 559 inserted->bps, 560 inserted->bps_rd, 561 inserted->bps_wr, 562 inserted->bps_max, 563 inserted->bps_rd_max, 564 inserted->bps_wr_max, 565 inserted->iops, 566 inserted->iops_rd, 567 inserted->iops_wr, 568 inserted->iops_max, 569 inserted->iops_rd_max, 570 inserted->iops_wr_max, 571 inserted->iops_size, 572 inserted->group); 573 } 574 575 if (verbose) { 576 monitor_printf(mon, "\nImages:\n"); 577 image_info = inserted->image; 578 while (1) { 579 bdrv_image_info_dump(image_info); 580 if (image_info->has_backing_image) { 581 image_info = image_info->backing_image; 582 } else { 583 break; 584 } 585 } 586 } 587 } 588 589 void hmp_info_block(Monitor *mon, const QDict *qdict) 590 { 591 BlockInfoList *block_list, *info; 592 BlockDeviceInfoList *blockdev_list, *blockdev; 593 const char *device = qdict_get_try_str(qdict, "device"); 594 bool verbose = qdict_get_try_bool(qdict, "verbose", false); 595 bool nodes = qdict_get_try_bool(qdict, "nodes", false); 596 bool printed = false; 597 598 /* Print BlockBackend information */ 599 if (!nodes) { 600 block_list = qmp_query_block(NULL); 601 } else { 602 block_list = NULL; 603 } 604 605 for (info = block_list; info; info = info->next) { 606 if (device && strcmp(device, info->value->device)) { 607 continue; 608 } 609 610 if (info != block_list) { 611 monitor_printf(mon, "\n"); 612 } 613 614 print_block_info(mon, info->value, info->value->has_inserted 615 ? info->value->inserted : NULL, 616 verbose); 617 printed = true; 618 } 619 620 qapi_free_BlockInfoList(block_list); 621 622 if ((!device && !nodes) || printed) { 623 return; 624 } 625 626 /* Print node information */ 627 blockdev_list = qmp_query_named_block_nodes(false, false, NULL); 628 for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { 629 assert(blockdev->value->has_node_name); 630 if (device && strcmp(device, blockdev->value->node_name)) { 631 continue; 632 } 633 634 if (blockdev != blockdev_list) { 635 monitor_printf(mon, "\n"); 636 } 637 638 print_block_info(mon, NULL, blockdev->value, verbose); 639 } 640 qapi_free_BlockDeviceInfoList(blockdev_list); 641 } 642 643 void hmp_info_blockstats(Monitor *mon, const QDict *qdict) 644 { 645 BlockStatsList *stats_list, *stats; 646 647 stats_list = qmp_query_blockstats(false, false, NULL); 648 649 for (stats = stats_list; stats; stats = stats->next) { 650 if (!stats->value->has_device) { 651 continue; 652 } 653 654 monitor_printf(mon, "%s:", stats->value->device); 655 monitor_printf(mon, " rd_bytes=%" PRId64 656 " wr_bytes=%" PRId64 657 " rd_operations=%" PRId64 658 " wr_operations=%" PRId64 659 " flush_operations=%" PRId64 660 " wr_total_time_ns=%" PRId64 661 " rd_total_time_ns=%" PRId64 662 " flush_total_time_ns=%" PRId64 663 " rd_merged=%" PRId64 664 " wr_merged=%" PRId64 665 " idle_time_ns=%" PRId64 666 "\n", 667 stats->value->stats->rd_bytes, 668 stats->value->stats->wr_bytes, 669 stats->value->stats->rd_operations, 670 stats->value->stats->wr_operations, 671 stats->value->stats->flush_operations, 672 stats->value->stats->wr_total_time_ns, 673 stats->value->stats->rd_total_time_ns, 674 stats->value->stats->flush_total_time_ns, 675 stats->value->stats->rd_merged, 676 stats->value->stats->wr_merged, 677 stats->value->stats->idle_time_ns); 678 } 679 680 qapi_free_BlockStatsList(stats_list); 681 } 682 683 #ifdef CONFIG_VNC 684 /* Helper for hmp_info_vnc_clients, _servers */ 685 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, 686 const char *name) 687 { 688 monitor_printf(mon, " %s: %s:%s (%s%s)\n", 689 name, 690 info->host, 691 info->service, 692 NetworkAddressFamily_str(info->family), 693 info->websocket ? " (Websocket)" : ""); 694 } 695 696 /* Helper displaying and auth and crypt info */ 697 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, 698 VncPrimaryAuth auth, 699 VncVencryptSubAuth *vencrypt) 700 { 701 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, 702 VncPrimaryAuth_str(auth), 703 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none"); 704 } 705 706 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) 707 { 708 while (client) { 709 VncClientInfo *cinfo = client->value; 710 711 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); 712 monitor_printf(mon, " x509_dname: %s\n", 713 cinfo->has_x509_dname ? 714 cinfo->x509_dname : "none"); 715 monitor_printf(mon, " sasl_username: %s\n", 716 cinfo->has_sasl_username ? 717 cinfo->sasl_username : "none"); 718 719 client = client->next; 720 } 721 } 722 723 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) 724 { 725 while (server) { 726 VncServerInfo2 *sinfo = server->value; 727 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); 728 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, 729 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); 730 server = server->next; 731 } 732 } 733 734 void hmp_info_vnc(Monitor *mon, const QDict *qdict) 735 { 736 VncInfo2List *info2l; 737 Error *err = NULL; 738 739 info2l = qmp_query_vnc_servers(&err); 740 if (err) { 741 hmp_handle_error(mon, err); 742 return; 743 } 744 if (!info2l) { 745 monitor_printf(mon, "None\n"); 746 return; 747 } 748 749 while (info2l) { 750 VncInfo2 *info = info2l->value; 751 monitor_printf(mon, "%s:\n", info->id); 752 hmp_info_vnc_servers(mon, info->server); 753 hmp_info_vnc_clients(mon, info->clients); 754 if (!info->server) { 755 /* The server entry displays its auth, we only 756 * need to display in the case of 'reverse' connections 757 * where there's no server. 758 */ 759 hmp_info_vnc_authcrypt(mon, " ", info->auth, 760 info->has_vencrypt ? &info->vencrypt : NULL); 761 } 762 if (info->has_display) { 763 monitor_printf(mon, " Display: %s\n", info->display); 764 } 765 info2l = info2l->next; 766 } 767 768 qapi_free_VncInfo2List(info2l); 769 770 } 771 #endif 772 773 #ifdef CONFIG_SPICE 774 void hmp_info_spice(Monitor *mon, const QDict *qdict) 775 { 776 SpiceChannelList *chan; 777 SpiceInfo *info; 778 const char *channel_name; 779 const char * const channel_names[] = { 780 [SPICE_CHANNEL_MAIN] = "main", 781 [SPICE_CHANNEL_DISPLAY] = "display", 782 [SPICE_CHANNEL_INPUTS] = "inputs", 783 [SPICE_CHANNEL_CURSOR] = "cursor", 784 [SPICE_CHANNEL_PLAYBACK] = "playback", 785 [SPICE_CHANNEL_RECORD] = "record", 786 [SPICE_CHANNEL_TUNNEL] = "tunnel", 787 [SPICE_CHANNEL_SMARTCARD] = "smartcard", 788 [SPICE_CHANNEL_USBREDIR] = "usbredir", 789 [SPICE_CHANNEL_PORT] = "port", 790 #if 0 791 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, 792 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable 793 * as quick fix for build failures with older versions. */ 794 [SPICE_CHANNEL_WEBDAV] = "webdav", 795 #endif 796 }; 797 798 info = qmp_query_spice(NULL); 799 800 if (!info->enabled) { 801 monitor_printf(mon, "Server: disabled\n"); 802 goto out; 803 } 804 805 monitor_printf(mon, "Server:\n"); 806 if (info->has_port) { 807 monitor_printf(mon, " address: %s:%" PRId64 "\n", 808 info->host, info->port); 809 } 810 if (info->has_tls_port) { 811 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", 812 info->host, info->tls_port); 813 } 814 monitor_printf(mon, " migrated: %s\n", 815 info->migrated ? "true" : "false"); 816 monitor_printf(mon, " auth: %s\n", info->auth); 817 monitor_printf(mon, " compiled: %s\n", info->compiled_version); 818 monitor_printf(mon, " mouse-mode: %s\n", 819 SpiceQueryMouseMode_str(info->mouse_mode)); 820 821 if (!info->has_channels || info->channels == NULL) { 822 monitor_printf(mon, "Channels: none\n"); 823 } else { 824 for (chan = info->channels; chan; chan = chan->next) { 825 monitor_printf(mon, "Channel:\n"); 826 monitor_printf(mon, " address: %s:%s%s\n", 827 chan->value->host, chan->value->port, 828 chan->value->tls ? " [tls]" : ""); 829 monitor_printf(mon, " session: %" PRId64 "\n", 830 chan->value->connection_id); 831 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", 832 chan->value->channel_type, chan->value->channel_id); 833 834 channel_name = "unknown"; 835 if (chan->value->channel_type > 0 && 836 chan->value->channel_type < ARRAY_SIZE(channel_names) && 837 channel_names[chan->value->channel_type]) { 838 channel_name = channel_names[chan->value->channel_type]; 839 } 840 841 monitor_printf(mon, " channel name: %s\n", channel_name); 842 } 843 } 844 845 out: 846 qapi_free_SpiceInfo(info); 847 } 848 #endif 849 850 void hmp_info_balloon(Monitor *mon, const QDict *qdict) 851 { 852 BalloonInfo *info; 853 Error *err = NULL; 854 855 info = qmp_query_balloon(&err); 856 if (err) { 857 hmp_handle_error(mon, err); 858 return; 859 } 860 861 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); 862 863 qapi_free_BalloonInfo(info); 864 } 865 866 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) 867 { 868 PciMemoryRegionList *region; 869 870 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); 871 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", 872 dev->slot, dev->function); 873 monitor_printf(mon, " "); 874 875 if (dev->class_info->has_desc) { 876 monitor_printf(mon, "%s", dev->class_info->desc); 877 } else { 878 monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class); 879 } 880 881 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", 882 dev->id->vendor, dev->id->device); 883 if (dev->id->has_subsystem_vendor && dev->id->has_subsystem) { 884 monitor_printf(mon, " PCI subsystem %04" PRIx64 ":%04" PRIx64 "\n", 885 dev->id->subsystem_vendor, dev->id->subsystem); 886 } 887 888 if (dev->has_irq) { 889 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); 890 } 891 892 if (dev->has_pci_bridge) { 893 monitor_printf(mon, " BUS %" PRId64 ".\n", 894 dev->pci_bridge->bus->number); 895 monitor_printf(mon, " secondary bus %" PRId64 ".\n", 896 dev->pci_bridge->bus->secondary); 897 monitor_printf(mon, " subordinate bus %" PRId64 ".\n", 898 dev->pci_bridge->bus->subordinate); 899 900 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", 901 dev->pci_bridge->bus->io_range->base, 902 dev->pci_bridge->bus->io_range->limit); 903 904 monitor_printf(mon, 905 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", 906 dev->pci_bridge->bus->memory_range->base, 907 dev->pci_bridge->bus->memory_range->limit); 908 909 monitor_printf(mon, " prefetchable memory range " 910 "[0x%08"PRIx64", 0x%08"PRIx64"]\n", 911 dev->pci_bridge->bus->prefetchable_range->base, 912 dev->pci_bridge->bus->prefetchable_range->limit); 913 } 914 915 for (region = dev->regions; region; region = region->next) { 916 uint64_t addr, size; 917 918 addr = region->value->address; 919 size = region->value->size; 920 921 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); 922 923 if (!strcmp(region->value->type, "io")) { 924 monitor_printf(mon, "I/O at 0x%04" PRIx64 925 " [0x%04" PRIx64 "].\n", 926 addr, addr + size - 1); 927 } else { 928 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 929 " [0x%08" PRIx64 "].\n", 930 region->value->mem_type_64 ? 64 : 32, 931 region->value->prefetch ? " prefetchable" : "", 932 addr, addr + size - 1); 933 } 934 } 935 936 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); 937 938 if (dev->has_pci_bridge) { 939 if (dev->pci_bridge->has_devices) { 940 PciDeviceInfoList *cdev; 941 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { 942 hmp_info_pci_device(mon, cdev->value); 943 } 944 } 945 } 946 } 947 948 static int hmp_info_irq_foreach(Object *obj, void *opaque) 949 { 950 InterruptStatsProvider *intc; 951 InterruptStatsProviderClass *k; 952 Monitor *mon = opaque; 953 954 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { 955 intc = INTERRUPT_STATS_PROVIDER(obj); 956 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); 957 uint64_t *irq_counts; 958 unsigned int nb_irqs, i; 959 if (k->get_statistics && 960 k->get_statistics(intc, &irq_counts, &nb_irqs)) { 961 if (nb_irqs > 0) { 962 monitor_printf(mon, "IRQ statistics for %s:\n", 963 object_get_typename(obj)); 964 for (i = 0; i < nb_irqs; i++) { 965 if (irq_counts[i] > 0) { 966 monitor_printf(mon, "%2d: %" PRId64 "\n", i, 967 irq_counts[i]); 968 } 969 } 970 } 971 } else { 972 monitor_printf(mon, "IRQ statistics not available for %s.\n", 973 object_get_typename(obj)); 974 } 975 } 976 977 return 0; 978 } 979 980 void hmp_info_irq(Monitor *mon, const QDict *qdict) 981 { 982 object_child_foreach_recursive(object_get_root(), 983 hmp_info_irq_foreach, mon); 984 } 985 986 static int hmp_info_pic_foreach(Object *obj, void *opaque) 987 { 988 InterruptStatsProvider *intc; 989 InterruptStatsProviderClass *k; 990 Monitor *mon = opaque; 991 992 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { 993 intc = INTERRUPT_STATS_PROVIDER(obj); 994 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); 995 if (k->print_info) { 996 k->print_info(intc, mon); 997 } else { 998 monitor_printf(mon, "Interrupt controller information not available for %s.\n", 999 object_get_typename(obj)); 1000 } 1001 } 1002 1003 return 0; 1004 } 1005 1006 void hmp_info_pic(Monitor *mon, const QDict *qdict) 1007 { 1008 object_child_foreach_recursive(object_get_root(), 1009 hmp_info_pic_foreach, mon); 1010 } 1011 1012 static int hmp_info_rdma_foreach(Object *obj, void *opaque) 1013 { 1014 RdmaProvider *rdma; 1015 RdmaProviderClass *k; 1016 Monitor *mon = opaque; 1017 1018 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) { 1019 rdma = RDMA_PROVIDER(obj); 1020 k = RDMA_PROVIDER_GET_CLASS(obj); 1021 if (k->print_statistics) { 1022 k->print_statistics(mon, rdma); 1023 } else { 1024 monitor_printf(mon, "RDMA statistics not available for %s.\n", 1025 object_get_typename(obj)); 1026 } 1027 } 1028 1029 return 0; 1030 } 1031 1032 void hmp_info_rdma(Monitor *mon, const QDict *qdict) 1033 { 1034 object_child_foreach_recursive(object_get_root(), 1035 hmp_info_rdma_foreach, mon); 1036 } 1037 1038 void hmp_info_pci(Monitor *mon, const QDict *qdict) 1039 { 1040 PciInfoList *info_list, *info; 1041 Error *err = NULL; 1042 1043 info_list = qmp_query_pci(&err); 1044 if (err) { 1045 monitor_printf(mon, "PCI devices not supported\n"); 1046 error_free(err); 1047 return; 1048 } 1049 1050 for (info = info_list; info; info = info->next) { 1051 PciDeviceInfoList *dev; 1052 1053 for (dev = info->value->devices; dev; dev = dev->next) { 1054 hmp_info_pci_device(mon, dev->value); 1055 } 1056 } 1057 1058 qapi_free_PciInfoList(info_list); 1059 } 1060 1061 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict) 1062 { 1063 BlockJobInfoList *list; 1064 Error *err = NULL; 1065 1066 list = qmp_query_block_jobs(&err); 1067 assert(!err); 1068 1069 if (!list) { 1070 monitor_printf(mon, "No active jobs\n"); 1071 return; 1072 } 1073 1074 while (list) { 1075 if (strcmp(list->value->type, "stream") == 0) { 1076 monitor_printf(mon, "Streaming device %s: Completed %" PRId64 1077 " of %" PRId64 " bytes, speed limit %" PRId64 1078 " bytes/s\n", 1079 list->value->device, 1080 list->value->offset, 1081 list->value->len, 1082 list->value->speed); 1083 } else { 1084 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64 1085 " of %" PRId64 " bytes, speed limit %" PRId64 1086 " bytes/s\n", 1087 list->value->type, 1088 list->value->device, 1089 list->value->offset, 1090 list->value->len, 1091 list->value->speed); 1092 } 1093 list = list->next; 1094 } 1095 1096 qapi_free_BlockJobInfoList(list); 1097 } 1098 1099 void hmp_info_tpm(Monitor *mon, const QDict *qdict) 1100 { 1101 TPMInfoList *info_list, *info; 1102 Error *err = NULL; 1103 unsigned int c = 0; 1104 TPMPassthroughOptions *tpo; 1105 TPMEmulatorOptions *teo; 1106 1107 info_list = qmp_query_tpm(&err); 1108 if (err) { 1109 monitor_printf(mon, "TPM device not supported\n"); 1110 error_free(err); 1111 return; 1112 } 1113 1114 if (info_list) { 1115 monitor_printf(mon, "TPM device:\n"); 1116 } 1117 1118 for (info = info_list; info; info = info->next) { 1119 TPMInfo *ti = info->value; 1120 monitor_printf(mon, " tpm%d: model=%s\n", 1121 c, TpmModel_str(ti->model)); 1122 1123 monitor_printf(mon, " \\ %s: type=%s", 1124 ti->id, TpmTypeOptionsKind_str(ti->options->type)); 1125 1126 switch (ti->options->type) { 1127 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: 1128 tpo = ti->options->u.passthrough.data; 1129 monitor_printf(mon, "%s%s%s%s", 1130 tpo->has_path ? ",path=" : "", 1131 tpo->has_path ? tpo->path : "", 1132 tpo->has_cancel_path ? ",cancel-path=" : "", 1133 tpo->has_cancel_path ? tpo->cancel_path : ""); 1134 break; 1135 case TPM_TYPE_OPTIONS_KIND_EMULATOR: 1136 teo = ti->options->u.emulator.data; 1137 monitor_printf(mon, ",chardev=%s", teo->chardev); 1138 break; 1139 case TPM_TYPE_OPTIONS_KIND__MAX: 1140 break; 1141 } 1142 monitor_printf(mon, "\n"); 1143 c++; 1144 } 1145 qapi_free_TPMInfoList(info_list); 1146 } 1147 1148 void hmp_quit(Monitor *mon, const QDict *qdict) 1149 { 1150 monitor_suspend(mon); 1151 qmp_quit(NULL); 1152 } 1153 1154 void hmp_stop(Monitor *mon, const QDict *qdict) 1155 { 1156 qmp_stop(NULL); 1157 } 1158 1159 void hmp_sync_profile(Monitor *mon, const QDict *qdict) 1160 { 1161 const char *op = qdict_get_try_str(qdict, "op"); 1162 1163 if (op == NULL) { 1164 bool on = qsp_is_enabled(); 1165 1166 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); 1167 return; 1168 } 1169 if (!strcmp(op, "on")) { 1170 qsp_enable(); 1171 } else if (!strcmp(op, "off")) { 1172 qsp_disable(); 1173 } else if (!strcmp(op, "reset")) { 1174 qsp_reset(); 1175 } else { 1176 Error *err = NULL; 1177 1178 error_setg(&err, QERR_INVALID_PARAMETER, op); 1179 hmp_handle_error(mon, err); 1180 } 1181 } 1182 1183 void hmp_system_reset(Monitor *mon, const QDict *qdict) 1184 { 1185 qmp_system_reset(NULL); 1186 } 1187 1188 void hmp_system_powerdown(Monitor *mon, const QDict *qdict) 1189 { 1190 qmp_system_powerdown(NULL); 1191 } 1192 1193 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) 1194 { 1195 Error *err = NULL; 1196 1197 qmp_x_exit_preconfig(&err); 1198 hmp_handle_error(mon, err); 1199 } 1200 1201 void hmp_cpu(Monitor *mon, const QDict *qdict) 1202 { 1203 int64_t cpu_index; 1204 1205 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that 1206 use it are converted to the QAPI */ 1207 cpu_index = qdict_get_int(qdict, "index"); 1208 if (monitor_set_cpu(cpu_index) < 0) { 1209 monitor_printf(mon, "invalid CPU index\n"); 1210 } 1211 } 1212 1213 void hmp_memsave(Monitor *mon, const QDict *qdict) 1214 { 1215 uint32_t size = qdict_get_int(qdict, "size"); 1216 const char *filename = qdict_get_str(qdict, "filename"); 1217 uint64_t addr = qdict_get_int(qdict, "val"); 1218 Error *err = NULL; 1219 int cpu_index = monitor_get_cpu_index(); 1220 1221 if (cpu_index < 0) { 1222 monitor_printf(mon, "No CPU available\n"); 1223 return; 1224 } 1225 1226 qmp_memsave(addr, size, filename, true, cpu_index, &err); 1227 hmp_handle_error(mon, err); 1228 } 1229 1230 void hmp_pmemsave(Monitor *mon, const QDict *qdict) 1231 { 1232 uint32_t size = qdict_get_int(qdict, "size"); 1233 const char *filename = qdict_get_str(qdict, "filename"); 1234 uint64_t addr = qdict_get_int(qdict, "val"); 1235 Error *err = NULL; 1236 1237 qmp_pmemsave(addr, size, filename, &err); 1238 hmp_handle_error(mon, err); 1239 } 1240 1241 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) 1242 { 1243 const char *chardev = qdict_get_str(qdict, "device"); 1244 const char *data = qdict_get_str(qdict, "data"); 1245 Error *err = NULL; 1246 1247 qmp_ringbuf_write(chardev, data, false, 0, &err); 1248 1249 hmp_handle_error(mon, err); 1250 } 1251 1252 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) 1253 { 1254 uint32_t size = qdict_get_int(qdict, "size"); 1255 const char *chardev = qdict_get_str(qdict, "device"); 1256 char *data; 1257 Error *err = NULL; 1258 int i; 1259 1260 data = qmp_ringbuf_read(chardev, size, false, 0, &err); 1261 if (err) { 1262 hmp_handle_error(mon, err); 1263 return; 1264 } 1265 1266 for (i = 0; data[i]; i++) { 1267 unsigned char ch = data[i]; 1268 1269 if (ch == '\\') { 1270 monitor_printf(mon, "\\\\"); 1271 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { 1272 monitor_printf(mon, "\\u%04X", ch); 1273 } else { 1274 monitor_printf(mon, "%c", ch); 1275 } 1276 1277 } 1278 monitor_printf(mon, "\n"); 1279 g_free(data); 1280 } 1281 1282 void hmp_cont(Monitor *mon, const QDict *qdict) 1283 { 1284 Error *err = NULL; 1285 1286 qmp_cont(&err); 1287 hmp_handle_error(mon, err); 1288 } 1289 1290 void hmp_system_wakeup(Monitor *mon, const QDict *qdict) 1291 { 1292 Error *err = NULL; 1293 1294 qmp_system_wakeup(&err); 1295 hmp_handle_error(mon, err); 1296 } 1297 1298 void hmp_nmi(Monitor *mon, const QDict *qdict) 1299 { 1300 Error *err = NULL; 1301 1302 qmp_inject_nmi(&err); 1303 hmp_handle_error(mon, err); 1304 } 1305 1306 void hmp_set_link(Monitor *mon, const QDict *qdict) 1307 { 1308 const char *name = qdict_get_str(qdict, "name"); 1309 bool up = qdict_get_bool(qdict, "up"); 1310 Error *err = NULL; 1311 1312 qmp_set_link(name, up, &err); 1313 hmp_handle_error(mon, err); 1314 } 1315 1316 void hmp_block_passwd(Monitor *mon, const QDict *qdict) 1317 { 1318 const char *device = qdict_get_str(qdict, "device"); 1319 const char *password = qdict_get_str(qdict, "password"); 1320 Error *err = NULL; 1321 1322 qmp_block_passwd(true, device, false, NULL, password, &err); 1323 hmp_handle_error(mon, err); 1324 } 1325 1326 void hmp_balloon(Monitor *mon, const QDict *qdict) 1327 { 1328 int64_t value = qdict_get_int(qdict, "value"); 1329 Error *err = NULL; 1330 1331 qmp_balloon(value, &err); 1332 hmp_handle_error(mon, err); 1333 } 1334 1335 void hmp_block_resize(Monitor *mon, const QDict *qdict) 1336 { 1337 const char *device = qdict_get_str(qdict, "device"); 1338 int64_t size = qdict_get_int(qdict, "size"); 1339 Error *err = NULL; 1340 1341 qmp_block_resize(true, device, false, NULL, size, &err); 1342 hmp_handle_error(mon, err); 1343 } 1344 1345 void hmp_loadvm(Monitor *mon, const QDict *qdict) 1346 { 1347 int saved_vm_running = runstate_is_running(); 1348 const char *name = qdict_get_str(qdict, "name"); 1349 Error *err = NULL; 1350 1351 vm_stop(RUN_STATE_RESTORE_VM); 1352 1353 if (load_snapshot(name, &err) == 0 && saved_vm_running) { 1354 vm_start(); 1355 } 1356 hmp_handle_error(mon, err); 1357 } 1358 1359 void hmp_savevm(Monitor *mon, const QDict *qdict) 1360 { 1361 Error *err = NULL; 1362 1363 save_snapshot(qdict_get_try_str(qdict, "name"), &err); 1364 hmp_handle_error(mon, err); 1365 } 1366 1367 void hmp_delvm(Monitor *mon, const QDict *qdict) 1368 { 1369 BlockDriverState *bs; 1370 Error *err = NULL; 1371 const char *name = qdict_get_str(qdict, "name"); 1372 1373 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { 1374 error_prepend(&err, 1375 "deleting snapshot on device '%s': ", 1376 bdrv_get_device_name(bs)); 1377 } 1378 hmp_handle_error(mon, err); 1379 } 1380 1381 void hmp_info_snapshots(Monitor *mon, const QDict *qdict) 1382 { 1383 BlockDriverState *bs, *bs1; 1384 BdrvNextIterator it1; 1385 QEMUSnapshotInfo *sn_tab, *sn; 1386 bool no_snapshot = true; 1387 int nb_sns, i; 1388 int total; 1389 int *global_snapshots; 1390 AioContext *aio_context; 1391 1392 typedef struct SnapshotEntry { 1393 QEMUSnapshotInfo sn; 1394 QTAILQ_ENTRY(SnapshotEntry) next; 1395 } SnapshotEntry; 1396 1397 typedef struct ImageEntry { 1398 const char *imagename; 1399 QTAILQ_ENTRY(ImageEntry) next; 1400 QTAILQ_HEAD(, SnapshotEntry) snapshots; 1401 } ImageEntry; 1402 1403 QTAILQ_HEAD(, ImageEntry) image_list = 1404 QTAILQ_HEAD_INITIALIZER(image_list); 1405 1406 ImageEntry *image_entry, *next_ie; 1407 SnapshotEntry *snapshot_entry; 1408 1409 bs = bdrv_all_find_vmstate_bs(); 1410 if (!bs) { 1411 monitor_printf(mon, "No available block device supports snapshots\n"); 1412 return; 1413 } 1414 aio_context = bdrv_get_aio_context(bs); 1415 1416 aio_context_acquire(aio_context); 1417 nb_sns = bdrv_snapshot_list(bs, &sn_tab); 1418 aio_context_release(aio_context); 1419 1420 if (nb_sns < 0) { 1421 monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); 1422 return; 1423 } 1424 1425 for (bs1 = bdrv_first(&it1); bs1; bs1 = bdrv_next(&it1)) { 1426 int bs1_nb_sns = 0; 1427 ImageEntry *ie; 1428 SnapshotEntry *se; 1429 AioContext *ctx = bdrv_get_aio_context(bs1); 1430 1431 aio_context_acquire(ctx); 1432 if (bdrv_can_snapshot(bs1)) { 1433 sn = NULL; 1434 bs1_nb_sns = bdrv_snapshot_list(bs1, &sn); 1435 if (bs1_nb_sns > 0) { 1436 no_snapshot = false; 1437 ie = g_new0(ImageEntry, 1); 1438 ie->imagename = bdrv_get_device_name(bs1); 1439 QTAILQ_INIT(&ie->snapshots); 1440 QTAILQ_INSERT_TAIL(&image_list, ie, next); 1441 for (i = 0; i < bs1_nb_sns; i++) { 1442 se = g_new0(SnapshotEntry, 1); 1443 se->sn = sn[i]; 1444 QTAILQ_INSERT_TAIL(&ie->snapshots, se, next); 1445 } 1446 } 1447 g_free(sn); 1448 } 1449 aio_context_release(ctx); 1450 } 1451 1452 if (no_snapshot) { 1453 monitor_printf(mon, "There is no snapshot available.\n"); 1454 return; 1455 } 1456 1457 global_snapshots = g_new0(int, nb_sns); 1458 total = 0; 1459 for (i = 0; i < nb_sns; i++) { 1460 SnapshotEntry *next_sn; 1461 if (bdrv_all_find_snapshot(sn_tab[i].name, &bs1) == 0) { 1462 global_snapshots[total] = i; 1463 total++; 1464 QTAILQ_FOREACH(image_entry, &image_list, next) { 1465 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, 1466 next, next_sn) { 1467 if (!strcmp(sn_tab[i].name, snapshot_entry->sn.name)) { 1468 QTAILQ_REMOVE(&image_entry->snapshots, snapshot_entry, 1469 next); 1470 g_free(snapshot_entry); 1471 } 1472 } 1473 } 1474 } 1475 } 1476 1477 monitor_printf(mon, "List of snapshots present on all disks:\n"); 1478 1479 if (total > 0) { 1480 bdrv_snapshot_dump(NULL); 1481 monitor_printf(mon, "\n"); 1482 for (i = 0; i < total; i++) { 1483 sn = &sn_tab[global_snapshots[i]]; 1484 /* The ID is not guaranteed to be the same on all images, so 1485 * overwrite it. 1486 */ 1487 pstrcpy(sn->id_str, sizeof(sn->id_str), "--"); 1488 bdrv_snapshot_dump(sn); 1489 monitor_printf(mon, "\n"); 1490 } 1491 } else { 1492 monitor_printf(mon, "None\n"); 1493 } 1494 1495 QTAILQ_FOREACH(image_entry, &image_list, next) { 1496 if (QTAILQ_EMPTY(&image_entry->snapshots)) { 1497 continue; 1498 } 1499 monitor_printf(mon, 1500 "\nList of partial (non-loadable) snapshots on '%s':\n", 1501 image_entry->imagename); 1502 bdrv_snapshot_dump(NULL); 1503 monitor_printf(mon, "\n"); 1504 QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) { 1505 bdrv_snapshot_dump(&snapshot_entry->sn); 1506 monitor_printf(mon, "\n"); 1507 } 1508 } 1509 1510 QTAILQ_FOREACH_SAFE(image_entry, &image_list, next, next_ie) { 1511 SnapshotEntry *next_sn; 1512 QTAILQ_FOREACH_SAFE(snapshot_entry, &image_entry->snapshots, next, 1513 next_sn) { 1514 g_free(snapshot_entry); 1515 } 1516 g_free(image_entry); 1517 } 1518 g_free(sn_tab); 1519 g_free(global_snapshots); 1520 1521 } 1522 1523 void hmp_announce_self(Monitor *mon, const QDict *qdict) 1524 { 1525 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces"); 1526 const char *id = qdict_get_try_str(qdict, "id"); 1527 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters, 1528 migrate_announce_params()); 1529 1530 qapi_free_strList(params->interfaces); 1531 params->interfaces = strList_from_comma_list(interfaces_str); 1532 params->has_interfaces = params->interfaces != NULL; 1533 params->id = g_strdup(id); 1534 params->has_id = !!params->id; 1535 qmp_announce_self(params, NULL); 1536 qapi_free_AnnounceParameters(params); 1537 } 1538 1539 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) 1540 { 1541 qmp_migrate_cancel(NULL); 1542 } 1543 1544 void hmp_migrate_continue(Monitor *mon, const QDict *qdict) 1545 { 1546 Error *err = NULL; 1547 const char *state = qdict_get_str(qdict, "state"); 1548 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); 1549 1550 if (val >= 0) { 1551 qmp_migrate_continue(val, &err); 1552 } 1553 1554 hmp_handle_error(mon, err); 1555 } 1556 1557 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) 1558 { 1559 Error *err = NULL; 1560 const char *uri = qdict_get_str(qdict, "uri"); 1561 1562 qmp_migrate_incoming(uri, &err); 1563 1564 hmp_handle_error(mon, err); 1565 } 1566 1567 void hmp_migrate_recover(Monitor *mon, const QDict *qdict) 1568 { 1569 Error *err = NULL; 1570 const char *uri = qdict_get_str(qdict, "uri"); 1571 1572 qmp_migrate_recover(uri, &err); 1573 1574 hmp_handle_error(mon, err); 1575 } 1576 1577 void hmp_migrate_pause(Monitor *mon, const QDict *qdict) 1578 { 1579 Error *err = NULL; 1580 1581 qmp_migrate_pause(&err); 1582 1583 hmp_handle_error(mon, err); 1584 } 1585 1586 /* Kept for backwards compatibility */ 1587 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) 1588 { 1589 double value = qdict_get_double(qdict, "value"); 1590 qmp_migrate_set_downtime(value, NULL); 1591 } 1592 1593 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) 1594 { 1595 int64_t value = qdict_get_int(qdict, "value"); 1596 Error *err = NULL; 1597 1598 qmp_migrate_set_cache_size(value, &err); 1599 hmp_handle_error(mon, err); 1600 } 1601 1602 /* Kept for backwards compatibility */ 1603 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) 1604 { 1605 int64_t value = qdict_get_int(qdict, "value"); 1606 qmp_migrate_set_speed(value, NULL); 1607 } 1608 1609 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) 1610 { 1611 const char *cap = qdict_get_str(qdict, "capability"); 1612 bool state = qdict_get_bool(qdict, "state"); 1613 Error *err = NULL; 1614 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps)); 1615 int val; 1616 1617 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); 1618 if (val < 0) { 1619 goto end; 1620 } 1621 1622 caps->value = g_malloc0(sizeof(*caps->value)); 1623 caps->value->capability = val; 1624 caps->value->state = state; 1625 caps->next = NULL; 1626 qmp_migrate_set_capabilities(caps, &err); 1627 1628 end: 1629 qapi_free_MigrationCapabilityStatusList(caps); 1630 hmp_handle_error(mon, err); 1631 } 1632 1633 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) 1634 { 1635 const char *param = qdict_get_str(qdict, "parameter"); 1636 const char *valuestr = qdict_get_str(qdict, "value"); 1637 Visitor *v = string_input_visitor_new(valuestr); 1638 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); 1639 uint64_t valuebw = 0; 1640 uint64_t cache_size; 1641 MultiFDCompression compress_type; 1642 Error *err = NULL; 1643 int val, ret; 1644 1645 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); 1646 if (val < 0) { 1647 goto cleanup; 1648 } 1649 1650 switch (val) { 1651 case MIGRATION_PARAMETER_COMPRESS_LEVEL: 1652 p->has_compress_level = true; 1653 visit_type_int(v, param, &p->compress_level, &err); 1654 break; 1655 case MIGRATION_PARAMETER_COMPRESS_THREADS: 1656 p->has_compress_threads = true; 1657 visit_type_int(v, param, &p->compress_threads, &err); 1658 break; 1659 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: 1660 p->has_compress_wait_thread = true; 1661 visit_type_bool(v, param, &p->compress_wait_thread, &err); 1662 break; 1663 case MIGRATION_PARAMETER_DECOMPRESS_THREADS: 1664 p->has_decompress_threads = true; 1665 visit_type_int(v, param, &p->decompress_threads, &err); 1666 break; 1667 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: 1668 p->has_cpu_throttle_initial = true; 1669 visit_type_int(v, param, &p->cpu_throttle_initial, &err); 1670 break; 1671 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: 1672 p->has_cpu_throttle_increment = true; 1673 visit_type_int(v, param, &p->cpu_throttle_increment, &err); 1674 break; 1675 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: 1676 p->has_max_cpu_throttle = true; 1677 visit_type_int(v, param, &p->max_cpu_throttle, &err); 1678 break; 1679 case MIGRATION_PARAMETER_TLS_CREDS: 1680 p->has_tls_creds = true; 1681 p->tls_creds = g_new0(StrOrNull, 1); 1682 p->tls_creds->type = QTYPE_QSTRING; 1683 visit_type_str(v, param, &p->tls_creds->u.s, &err); 1684 break; 1685 case MIGRATION_PARAMETER_TLS_HOSTNAME: 1686 p->has_tls_hostname = true; 1687 p->tls_hostname = g_new0(StrOrNull, 1); 1688 p->tls_hostname->type = QTYPE_QSTRING; 1689 visit_type_str(v, param, &p->tls_hostname->u.s, &err); 1690 break; 1691 case MIGRATION_PARAMETER_TLS_AUTHZ: 1692 p->has_tls_authz = true; 1693 p->tls_authz = g_new0(StrOrNull, 1); 1694 p->tls_authz->type = QTYPE_QSTRING; 1695 visit_type_str(v, param, &p->tls_authz->u.s, &err); 1696 break; 1697 case MIGRATION_PARAMETER_MAX_BANDWIDTH: 1698 p->has_max_bandwidth = true; 1699 /* 1700 * Can't use visit_type_size() here, because it 1701 * defaults to Bytes rather than Mebibytes. 1702 */ 1703 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); 1704 if (ret < 0 || valuebw > INT64_MAX 1705 || (size_t)valuebw != valuebw) { 1706 error_setg(&err, "Invalid size %s", valuestr); 1707 break; 1708 } 1709 p->max_bandwidth = valuebw; 1710 break; 1711 case MIGRATION_PARAMETER_DOWNTIME_LIMIT: 1712 p->has_downtime_limit = true; 1713 visit_type_int(v, param, &p->downtime_limit, &err); 1714 break; 1715 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: 1716 p->has_x_checkpoint_delay = true; 1717 visit_type_int(v, param, &p->x_checkpoint_delay, &err); 1718 break; 1719 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: 1720 p->has_block_incremental = true; 1721 visit_type_bool(v, param, &p->block_incremental, &err); 1722 break; 1723 case MIGRATION_PARAMETER_MULTIFD_CHANNELS: 1724 p->has_multifd_channels = true; 1725 visit_type_int(v, param, &p->multifd_channels, &err); 1726 break; 1727 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: 1728 p->has_multifd_compression = true; 1729 visit_type_MultiFDCompression(v, param, &compress_type, &err); 1730 if (err) { 1731 break; 1732 } 1733 p->multifd_compression = compress_type; 1734 break; 1735 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: 1736 p->has_multifd_zlib_level = true; 1737 visit_type_int(v, param, &p->multifd_zlib_level, &err); 1738 break; 1739 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: 1740 p->has_multifd_zstd_level = true; 1741 visit_type_int(v, param, &p->multifd_zstd_level, &err); 1742 break; 1743 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: 1744 p->has_xbzrle_cache_size = true; 1745 visit_type_size(v, param, &cache_size, &err); 1746 if (err) { 1747 break; 1748 } 1749 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) { 1750 error_setg(&err, "Invalid size %s", valuestr); 1751 break; 1752 } 1753 p->xbzrle_cache_size = cache_size; 1754 break; 1755 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: 1756 p->has_max_postcopy_bandwidth = true; 1757 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); 1758 break; 1759 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: 1760 p->has_announce_initial = true; 1761 visit_type_size(v, param, &p->announce_initial, &err); 1762 break; 1763 case MIGRATION_PARAMETER_ANNOUNCE_MAX: 1764 p->has_announce_max = true; 1765 visit_type_size(v, param, &p->announce_max, &err); 1766 break; 1767 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: 1768 p->has_announce_rounds = true; 1769 visit_type_size(v, param, &p->announce_rounds, &err); 1770 break; 1771 case MIGRATION_PARAMETER_ANNOUNCE_STEP: 1772 p->has_announce_step = true; 1773 visit_type_size(v, param, &p->announce_step, &err); 1774 break; 1775 default: 1776 assert(0); 1777 } 1778 1779 if (err) { 1780 goto cleanup; 1781 } 1782 1783 qmp_migrate_set_parameters(p, &err); 1784 1785 cleanup: 1786 qapi_free_MigrateSetParameters(p); 1787 visit_free(v); 1788 hmp_handle_error(mon, err); 1789 } 1790 1791 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) 1792 { 1793 Error *err = NULL; 1794 const char *protocol = qdict_get_str(qdict, "protocol"); 1795 const char *hostname = qdict_get_str(qdict, "hostname"); 1796 bool has_port = qdict_haskey(qdict, "port"); 1797 int port = qdict_get_try_int(qdict, "port", -1); 1798 bool has_tls_port = qdict_haskey(qdict, "tls-port"); 1799 int tls_port = qdict_get_try_int(qdict, "tls-port", -1); 1800 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); 1801 1802 qmp_client_migrate_info(protocol, hostname, 1803 has_port, port, has_tls_port, tls_port, 1804 !!cert_subject, cert_subject, &err); 1805 hmp_handle_error(mon, err); 1806 } 1807 1808 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) 1809 { 1810 Error *err = NULL; 1811 qmp_migrate_start_postcopy(&err); 1812 hmp_handle_error(mon, err); 1813 } 1814 1815 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) 1816 { 1817 Error *err = NULL; 1818 1819 qmp_x_colo_lost_heartbeat(&err); 1820 hmp_handle_error(mon, err); 1821 } 1822 1823 void hmp_set_password(Monitor *mon, const QDict *qdict) 1824 { 1825 const char *protocol = qdict_get_str(qdict, "protocol"); 1826 const char *password = qdict_get_str(qdict, "password"); 1827 const char *connected = qdict_get_try_str(qdict, "connected"); 1828 Error *err = NULL; 1829 1830 qmp_set_password(protocol, password, !!connected, connected, &err); 1831 hmp_handle_error(mon, err); 1832 } 1833 1834 void hmp_expire_password(Monitor *mon, const QDict *qdict) 1835 { 1836 const char *protocol = qdict_get_str(qdict, "protocol"); 1837 const char *whenstr = qdict_get_str(qdict, "time"); 1838 Error *err = NULL; 1839 1840 qmp_expire_password(protocol, whenstr, &err); 1841 hmp_handle_error(mon, err); 1842 } 1843 1844 void hmp_eject(Monitor *mon, const QDict *qdict) 1845 { 1846 bool force = qdict_get_try_bool(qdict, "force", false); 1847 const char *device = qdict_get_str(qdict, "device"); 1848 Error *err = NULL; 1849 1850 qmp_eject(true, device, false, NULL, true, force, &err); 1851 hmp_handle_error(mon, err); 1852 } 1853 1854 #ifdef CONFIG_VNC 1855 static void hmp_change_read_arg(void *opaque, const char *password, 1856 void *readline_opaque) 1857 { 1858 qmp_change_vnc_password(password, NULL); 1859 monitor_read_command(opaque, 1); 1860 } 1861 #endif 1862 1863 void hmp_change(Monitor *mon, const QDict *qdict) 1864 { 1865 const char *device = qdict_get_str(qdict, "device"); 1866 const char *target = qdict_get_str(qdict, "target"); 1867 const char *arg = qdict_get_try_str(qdict, "arg"); 1868 const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); 1869 BlockdevChangeReadOnlyMode read_only_mode = 0; 1870 Error *err = NULL; 1871 1872 #ifdef CONFIG_VNC 1873 if (strcmp(device, "vnc") == 0) { 1874 if (read_only) { 1875 monitor_printf(mon, 1876 "Parameter 'read-only-mode' is invalid for VNC\n"); 1877 return; 1878 } 1879 if (strcmp(target, "passwd") == 0 || 1880 strcmp(target, "password") == 0) { 1881 if (!arg) { 1882 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common); 1883 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL); 1884 return; 1885 } 1886 } 1887 qmp_change("vnc", target, !!arg, arg, &err); 1888 } else 1889 #endif 1890 { 1891 if (read_only) { 1892 read_only_mode = 1893 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, 1894 read_only, 1895 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); 1896 if (err) { 1897 hmp_handle_error(mon, err); 1898 return; 1899 } 1900 } 1901 1902 qmp_blockdev_change_medium(true, device, false, NULL, target, 1903 !!arg, arg, !!read_only, read_only_mode, 1904 &err); 1905 } 1906 1907 hmp_handle_error(mon, err); 1908 } 1909 1910 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) 1911 { 1912 Error *err = NULL; 1913 char *device = (char *) qdict_get_str(qdict, "device"); 1914 BlockIOThrottle throttle = { 1915 .bps = qdict_get_int(qdict, "bps"), 1916 .bps_rd = qdict_get_int(qdict, "bps_rd"), 1917 .bps_wr = qdict_get_int(qdict, "bps_wr"), 1918 .iops = qdict_get_int(qdict, "iops"), 1919 .iops_rd = qdict_get_int(qdict, "iops_rd"), 1920 .iops_wr = qdict_get_int(qdict, "iops_wr"), 1921 }; 1922 1923 /* qmp_block_set_io_throttle has separate parameters for the 1924 * (deprecated) block device name and the qdev ID but the HMP 1925 * version has only one, so we must decide which one to pass. */ 1926 if (blk_by_name(device)) { 1927 throttle.has_device = true; 1928 throttle.device = device; 1929 } else { 1930 throttle.has_id = true; 1931 throttle.id = device; 1932 } 1933 1934 qmp_block_set_io_throttle(&throttle, &err); 1935 hmp_handle_error(mon, err); 1936 } 1937 1938 void hmp_block_stream(Monitor *mon, const QDict *qdict) 1939 { 1940 Error *error = NULL; 1941 const char *device = qdict_get_str(qdict, "device"); 1942 const char *base = qdict_get_try_str(qdict, "base"); 1943 int64_t speed = qdict_get_try_int(qdict, "speed", 0); 1944 1945 qmp_block_stream(true, device, device, base != NULL, base, false, NULL, 1946 false, NULL, qdict_haskey(qdict, "speed"), speed, true, 1947 BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, 1948 &error); 1949 1950 hmp_handle_error(mon, error); 1951 } 1952 1953 typedef struct HMPMigrationStatus 1954 { 1955 QEMUTimer *timer; 1956 Monitor *mon; 1957 bool is_block_migration; 1958 } HMPMigrationStatus; 1959 1960 static void hmp_migrate_status_cb(void *opaque) 1961 { 1962 HMPMigrationStatus *status = opaque; 1963 MigrationInfo *info; 1964 1965 info = qmp_query_migrate(NULL); 1966 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || 1967 info->status == MIGRATION_STATUS_SETUP) { 1968 if (info->has_disk) { 1969 int progress; 1970 1971 if (info->disk->remaining) { 1972 progress = info->disk->transferred * 100 / info->disk->total; 1973 } else { 1974 progress = 100; 1975 } 1976 1977 monitor_printf(status->mon, "Completed %d %%\r", progress); 1978 monitor_flush(status->mon); 1979 } 1980 1981 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); 1982 } else { 1983 if (status->is_block_migration) { 1984 monitor_printf(status->mon, "\n"); 1985 } 1986 if (info->has_error_desc) { 1987 error_report("%s", info->error_desc); 1988 } 1989 monitor_resume(status->mon); 1990 timer_del(status->timer); 1991 timer_free(status->timer); 1992 g_free(status); 1993 } 1994 1995 qapi_free_MigrationInfo(info); 1996 } 1997 1998 void hmp_migrate(Monitor *mon, const QDict *qdict) 1999 { 2000 bool detach = qdict_get_try_bool(qdict, "detach", false); 2001 bool blk = qdict_get_try_bool(qdict, "blk", false); 2002 bool inc = qdict_get_try_bool(qdict, "inc", false); 2003 bool resume = qdict_get_try_bool(qdict, "resume", false); 2004 const char *uri = qdict_get_str(qdict, "uri"); 2005 Error *err = NULL; 2006 2007 qmp_migrate(uri, !!blk, blk, !!inc, inc, 2008 false, false, true, resume, &err); 2009 if (err) { 2010 hmp_handle_error(mon, err); 2011 return; 2012 } 2013 2014 if (!detach) { 2015 HMPMigrationStatus *status; 2016 2017 if (monitor_suspend(mon) < 0) { 2018 monitor_printf(mon, "terminal does not allow synchronous " 2019 "migration, continuing detached\n"); 2020 return; 2021 } 2022 2023 status = g_malloc0(sizeof(*status)); 2024 status->mon = mon; 2025 status->is_block_migration = blk || inc; 2026 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, 2027 status); 2028 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); 2029 } 2030 } 2031 2032 void hmp_netdev_add(Monitor *mon, const QDict *qdict) 2033 { 2034 Error *err = NULL; 2035 QemuOpts *opts; 2036 2037 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); 2038 if (err) { 2039 goto out; 2040 } 2041 2042 netdev_add(opts, &err); 2043 if (err) { 2044 qemu_opts_del(opts); 2045 } 2046 2047 out: 2048 hmp_handle_error(mon, err); 2049 } 2050 2051 void hmp_netdev_del(Monitor *mon, const QDict *qdict) 2052 { 2053 const char *id = qdict_get_str(qdict, "id"); 2054 Error *err = NULL; 2055 2056 qmp_netdev_del(id, &err); 2057 hmp_handle_error(mon, err); 2058 } 2059 2060 void hmp_object_add(Monitor *mon, const QDict *qdict) 2061 { 2062 Error *err = NULL; 2063 QemuOpts *opts; 2064 Object *obj = NULL; 2065 2066 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); 2067 if (err) { 2068 hmp_handle_error(mon, err); 2069 return; 2070 } 2071 2072 obj = user_creatable_add_opts(opts, &err); 2073 qemu_opts_del(opts); 2074 2075 if (err) { 2076 hmp_handle_error(mon, err); 2077 } 2078 if (obj) { 2079 object_unref(obj); 2080 } 2081 } 2082 2083 void hmp_getfd(Monitor *mon, const QDict *qdict) 2084 { 2085 const char *fdname = qdict_get_str(qdict, "fdname"); 2086 Error *err = NULL; 2087 2088 qmp_getfd(fdname, &err); 2089 hmp_handle_error(mon, err); 2090 } 2091 2092 void hmp_closefd(Monitor *mon, const QDict *qdict) 2093 { 2094 const char *fdname = qdict_get_str(qdict, "fdname"); 2095 Error *err = NULL; 2096 2097 qmp_closefd(fdname, &err); 2098 hmp_handle_error(mon, err); 2099 } 2100 2101 void hmp_sendkey(Monitor *mon, const QDict *qdict) 2102 { 2103 const char *keys = qdict_get_str(qdict, "keys"); 2104 KeyValueList *keylist, *head = NULL, *tmp = NULL; 2105 int has_hold_time = qdict_haskey(qdict, "hold-time"); 2106 int hold_time = qdict_get_try_int(qdict, "hold-time", -1); 2107 Error *err = NULL; 2108 const char *separator; 2109 int keyname_len; 2110 2111 while (1) { 2112 separator = qemu_strchrnul(keys, '-'); 2113 keyname_len = separator - keys; 2114 2115 /* Be compatible with old interface, convert user inputted "<" */ 2116 if (keys[0] == '<' && keyname_len == 1) { 2117 keys = "less"; 2118 keyname_len = 4; 2119 } 2120 2121 keylist = g_malloc0(sizeof(*keylist)); 2122 keylist->value = g_malloc0(sizeof(*keylist->value)); 2123 2124 if (!head) { 2125 head = keylist; 2126 } 2127 if (tmp) { 2128 tmp->next = keylist; 2129 } 2130 tmp = keylist; 2131 2132 if (strstart(keys, "0x", NULL)) { 2133 char *endp; 2134 int value = strtoul(keys, &endp, 0); 2135 assert(endp <= keys + keyname_len); 2136 if (endp != keys + keyname_len) { 2137 goto err_out; 2138 } 2139 keylist->value->type = KEY_VALUE_KIND_NUMBER; 2140 keylist->value->u.number.data = value; 2141 } else { 2142 int idx = index_from_key(keys, keyname_len); 2143 if (idx == Q_KEY_CODE__MAX) { 2144 goto err_out; 2145 } 2146 keylist->value->type = KEY_VALUE_KIND_QCODE; 2147 keylist->value->u.qcode.data = idx; 2148 } 2149 2150 if (!*separator) { 2151 break; 2152 } 2153 keys = separator + 1; 2154 } 2155 2156 qmp_send_key(head, has_hold_time, hold_time, &err); 2157 hmp_handle_error(mon, err); 2158 2159 out: 2160 qapi_free_KeyValueList(head); 2161 return; 2162 2163 err_out: 2164 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); 2165 goto out; 2166 } 2167 2168 void hmp_screendump(Monitor *mon, const QDict *qdict) 2169 { 2170 const char *filename = qdict_get_str(qdict, "filename"); 2171 const char *id = qdict_get_try_str(qdict, "device"); 2172 int64_t head = qdict_get_try_int(qdict, "head", 0); 2173 Error *err = NULL; 2174 2175 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); 2176 hmp_handle_error(mon, err); 2177 } 2178 2179 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) 2180 { 2181 const char *uri = qdict_get_str(qdict, "uri"); 2182 bool writable = qdict_get_try_bool(qdict, "writable", false); 2183 bool all = qdict_get_try_bool(qdict, "all", false); 2184 Error *local_err = NULL; 2185 BlockInfoList *block_list, *info; 2186 SocketAddress *addr; 2187 BlockExportNbd export; 2188 2189 if (writable && !all) { 2190 error_setg(&local_err, "-w only valid together with -a"); 2191 goto exit; 2192 } 2193 2194 /* First check if the address is valid and start the server. */ 2195 addr = socket_parse(uri, &local_err); 2196 if (local_err != NULL) { 2197 goto exit; 2198 } 2199 2200 nbd_server_start(addr, NULL, NULL, &local_err); 2201 qapi_free_SocketAddress(addr); 2202 if (local_err != NULL) { 2203 goto exit; 2204 } 2205 2206 if (!all) { 2207 return; 2208 } 2209 2210 /* Then try adding all block devices. If one fails, close all and 2211 * exit. 2212 */ 2213 block_list = qmp_query_block(NULL); 2214 2215 for (info = block_list; info; info = info->next) { 2216 if (!info->value->has_inserted) { 2217 continue; 2218 } 2219 2220 export = (BlockExportNbd) { 2221 .device = info->value->device, 2222 .has_writable = true, 2223 .writable = writable, 2224 }; 2225 2226 qmp_nbd_server_add(&export, &local_err); 2227 2228 if (local_err != NULL) { 2229 qmp_nbd_server_stop(NULL); 2230 break; 2231 } 2232 } 2233 2234 qapi_free_BlockInfoList(block_list); 2235 2236 exit: 2237 hmp_handle_error(mon, local_err); 2238 } 2239 2240 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) 2241 { 2242 const char *device = qdict_get_str(qdict, "device"); 2243 const char *name = qdict_get_try_str(qdict, "name"); 2244 bool writable = qdict_get_try_bool(qdict, "writable", false); 2245 Error *local_err = NULL; 2246 2247 BlockExportNbd export = { 2248 .device = (char *) device, 2249 .has_name = !!name, 2250 .name = (char *) name, 2251 .has_writable = true, 2252 .writable = writable, 2253 }; 2254 2255 qmp_nbd_server_add(&export, &local_err); 2256 hmp_handle_error(mon, local_err); 2257 } 2258 2259 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) 2260 { 2261 const char *name = qdict_get_str(qdict, "name"); 2262 bool force = qdict_get_try_bool(qdict, "force", false); 2263 Error *err = NULL; 2264 2265 /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ 2266 qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); 2267 hmp_handle_error(mon, err); 2268 } 2269 2270 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) 2271 { 2272 Error *err = NULL; 2273 2274 qmp_nbd_server_stop(&err); 2275 hmp_handle_error(mon, err); 2276 } 2277 2278 void hmp_chardev_add(Monitor *mon, const QDict *qdict) 2279 { 2280 const char *args = qdict_get_str(qdict, "args"); 2281 Error *err = NULL; 2282 QemuOpts *opts; 2283 2284 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); 2285 if (opts == NULL) { 2286 error_setg(&err, "Parsing chardev args failed"); 2287 } else { 2288 qemu_chr_new_from_opts(opts, NULL, &err); 2289 qemu_opts_del(opts); 2290 } 2291 hmp_handle_error(mon, err); 2292 } 2293 2294 void hmp_chardev_change(Monitor *mon, const QDict *qdict) 2295 { 2296 const char *args = qdict_get_str(qdict, "args"); 2297 const char *id; 2298 Error *err = NULL; 2299 ChardevBackend *backend = NULL; 2300 ChardevReturn *ret = NULL; 2301 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, 2302 true); 2303 if (!opts) { 2304 error_setg(&err, "Parsing chardev args failed"); 2305 goto end; 2306 } 2307 2308 id = qdict_get_str(qdict, "id"); 2309 if (qemu_opts_id(opts)) { 2310 error_setg(&err, "Unexpected 'id' parameter"); 2311 goto end; 2312 } 2313 2314 backend = qemu_chr_parse_opts(opts, &err); 2315 if (!backend) { 2316 goto end; 2317 } 2318 2319 ret = qmp_chardev_change(id, backend, &err); 2320 2321 end: 2322 qapi_free_ChardevReturn(ret); 2323 qapi_free_ChardevBackend(backend); 2324 qemu_opts_del(opts); 2325 hmp_handle_error(mon, err); 2326 } 2327 2328 void hmp_chardev_remove(Monitor *mon, const QDict *qdict) 2329 { 2330 Error *local_err = NULL; 2331 2332 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); 2333 hmp_handle_error(mon, local_err); 2334 } 2335 2336 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) 2337 { 2338 Error *local_err = NULL; 2339 2340 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); 2341 hmp_handle_error(mon, local_err); 2342 } 2343 2344 void hmp_qemu_io(Monitor *mon, const QDict *qdict) 2345 { 2346 BlockBackend *blk; 2347 BlockBackend *local_blk = NULL; 2348 bool qdev = qdict_get_try_bool(qdict, "qdev", false); 2349 const char* device = qdict_get_str(qdict, "device"); 2350 const char* command = qdict_get_str(qdict, "command"); 2351 Error *err = NULL; 2352 int ret; 2353 2354 if (qdev) { 2355 blk = blk_by_qdev_id(device, &err); 2356 if (!blk) { 2357 goto fail; 2358 } 2359 } else { 2360 blk = blk_by_name(device); 2361 if (!blk) { 2362 BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err); 2363 if (bs) { 2364 blk = local_blk = blk_new(bdrv_get_aio_context(bs), 2365 0, BLK_PERM_ALL); 2366 ret = blk_insert_bs(blk, bs, &err); 2367 if (ret < 0) { 2368 goto fail; 2369 } 2370 } else { 2371 goto fail; 2372 } 2373 } 2374 } 2375 2376 /* 2377 * Notably absent: Proper permission management. This is sad, but it seems 2378 * almost impossible to achieve without changing the semantics and thereby 2379 * limiting the use cases of the qemu-io HMP command. 2380 * 2381 * In an ideal world we would unconditionally create a new BlockBackend for 2382 * qemuio_command(), but we have commands like 'reopen' and want them to 2383 * take effect on the exact BlockBackend whose name the user passed instead 2384 * of just on a temporary copy of it. 2385 * 2386 * Another problem is that deleting the temporary BlockBackend involves 2387 * draining all requests on it first, but some qemu-iotests cases want to 2388 * issue multiple aio_read/write requests and expect them to complete in 2389 * the background while the monitor has already returned. 2390 * 2391 * This is also what prevents us from saving the original permissions and 2392 * restoring them later: We can't revoke permissions until all requests 2393 * have completed, and we don't know when that is nor can we really let 2394 * anything else run before we have revoken them to avoid race conditions. 2395 * 2396 * What happens now is that command() in qemu-io-cmds.c can extend the 2397 * permissions if necessary for the qemu-io command. And they simply stay 2398 * extended, possibly resulting in a read-only guest device keeping write 2399 * permissions. Ugly, but it appears to be the lesser evil. 2400 */ 2401 qemuio_command(blk, command); 2402 2403 fail: 2404 blk_unref(local_blk); 2405 hmp_handle_error(mon, err); 2406 } 2407 2408 void hmp_object_del(Monitor *mon, const QDict *qdict) 2409 { 2410 const char *id = qdict_get_str(qdict, "id"); 2411 Error *err = NULL; 2412 2413 user_creatable_del(id, &err); 2414 hmp_handle_error(mon, err); 2415 } 2416 2417 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) 2418 { 2419 Error *err = NULL; 2420 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); 2421 MemoryDeviceInfoList *info; 2422 VirtioPMEMDeviceInfo *vpi; 2423 MemoryDeviceInfo *value; 2424 PCDIMMDeviceInfo *di; 2425 2426 for (info = info_list; info; info = info->next) { 2427 value = info->value; 2428 2429 if (value) { 2430 switch (value->type) { 2431 case MEMORY_DEVICE_INFO_KIND_DIMM: 2432 case MEMORY_DEVICE_INFO_KIND_NVDIMM: 2433 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ? 2434 value->u.dimm.data : value->u.nvdimm.data; 2435 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 2436 MemoryDeviceInfoKind_str(value->type), 2437 di->id ? di->id : ""); 2438 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); 2439 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); 2440 monitor_printf(mon, " node: %" PRId64 "\n", di->node); 2441 monitor_printf(mon, " size: %" PRIu64 "\n", di->size); 2442 monitor_printf(mon, " memdev: %s\n", di->memdev); 2443 monitor_printf(mon, " hotplugged: %s\n", 2444 di->hotplugged ? "true" : "false"); 2445 monitor_printf(mon, " hotpluggable: %s\n", 2446 di->hotpluggable ? "true" : "false"); 2447 break; 2448 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: 2449 vpi = value->u.virtio_pmem.data; 2450 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 2451 MemoryDeviceInfoKind_str(value->type), 2452 vpi->id ? vpi->id : ""); 2453 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr); 2454 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); 2455 monitor_printf(mon, " memdev: %s\n", vpi->memdev); 2456 break; 2457 default: 2458 g_assert_not_reached(); 2459 } 2460 } 2461 } 2462 2463 qapi_free_MemoryDeviceInfoList(info_list); 2464 hmp_handle_error(mon, err); 2465 } 2466 2467 void hmp_info_iothreads(Monitor *mon, const QDict *qdict) 2468 { 2469 IOThreadInfoList *info_list = qmp_query_iothreads(NULL); 2470 IOThreadInfoList *info; 2471 IOThreadInfo *value; 2472 2473 for (info = info_list; info; info = info->next) { 2474 value = info->value; 2475 monitor_printf(mon, "%s:\n", value->id); 2476 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); 2477 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); 2478 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); 2479 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); 2480 } 2481 2482 qapi_free_IOThreadInfoList(info_list); 2483 } 2484 2485 void hmp_rocker(Monitor *mon, const QDict *qdict) 2486 { 2487 const char *name = qdict_get_str(qdict, "name"); 2488 RockerSwitch *rocker; 2489 Error *err = NULL; 2490 2491 rocker = qmp_query_rocker(name, &err); 2492 if (err != NULL) { 2493 hmp_handle_error(mon, err); 2494 return; 2495 } 2496 2497 monitor_printf(mon, "name: %s\n", rocker->name); 2498 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); 2499 monitor_printf(mon, "ports: %d\n", rocker->ports); 2500 2501 qapi_free_RockerSwitch(rocker); 2502 } 2503 2504 void hmp_rocker_ports(Monitor *mon, const QDict *qdict) 2505 { 2506 RockerPortList *list, *port; 2507 const char *name = qdict_get_str(qdict, "name"); 2508 Error *err = NULL; 2509 2510 list = qmp_query_rocker_ports(name, &err); 2511 if (err != NULL) { 2512 hmp_handle_error(mon, err); 2513 return; 2514 } 2515 2516 monitor_printf(mon, " ena/ speed/ auto\n"); 2517 monitor_printf(mon, " port link duplex neg?\n"); 2518 2519 for (port = list; port; port = port->next) { 2520 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", 2521 port->value->name, 2522 port->value->enabled ? port->value->link_up ? 2523 "up" : "down" : "!ena", 2524 port->value->speed == 10000 ? "10G" : "??", 2525 port->value->duplex ? "FD" : "HD", 2526 port->value->autoneg ? "Yes" : "No"); 2527 } 2528 2529 qapi_free_RockerPortList(list); 2530 } 2531 2532 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) 2533 { 2534 RockerOfDpaFlowList *list, *info; 2535 const char *name = qdict_get_str(qdict, "name"); 2536 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); 2537 Error *err = NULL; 2538 2539 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); 2540 if (err != NULL) { 2541 hmp_handle_error(mon, err); 2542 return; 2543 } 2544 2545 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); 2546 2547 for (info = list; info; info = info->next) { 2548 RockerOfDpaFlow *flow = info->value; 2549 RockerOfDpaFlowKey *key = flow->key; 2550 RockerOfDpaFlowMask *mask = flow->mask; 2551 RockerOfDpaFlowAction *action = flow->action; 2552 2553 if (flow->hits) { 2554 monitor_printf(mon, "%-4d %-3d %-4" PRIu64, 2555 key->priority, key->tbl_id, flow->hits); 2556 } else { 2557 monitor_printf(mon, "%-4d %-3d ", 2558 key->priority, key->tbl_id); 2559 } 2560 2561 if (key->has_in_pport) { 2562 monitor_printf(mon, " pport %d", key->in_pport); 2563 if (mask->has_in_pport) { 2564 monitor_printf(mon, "(0x%x)", mask->in_pport); 2565 } 2566 } 2567 2568 if (key->has_vlan_id) { 2569 monitor_printf(mon, " vlan %d", 2570 key->vlan_id & VLAN_VID_MASK); 2571 if (mask->has_vlan_id) { 2572 monitor_printf(mon, "(0x%x)", mask->vlan_id); 2573 } 2574 } 2575 2576 if (key->has_tunnel_id) { 2577 monitor_printf(mon, " tunnel %d", key->tunnel_id); 2578 if (mask->has_tunnel_id) { 2579 monitor_printf(mon, "(0x%x)", mask->tunnel_id); 2580 } 2581 } 2582 2583 if (key->has_eth_type) { 2584 switch (key->eth_type) { 2585 case 0x0806: 2586 monitor_printf(mon, " ARP"); 2587 break; 2588 case 0x0800: 2589 monitor_printf(mon, " IP"); 2590 break; 2591 case 0x86dd: 2592 monitor_printf(mon, " IPv6"); 2593 break; 2594 case 0x8809: 2595 monitor_printf(mon, " LACP"); 2596 break; 2597 case 0x88cc: 2598 monitor_printf(mon, " LLDP"); 2599 break; 2600 default: 2601 monitor_printf(mon, " eth type 0x%04x", key->eth_type); 2602 break; 2603 } 2604 } 2605 2606 if (key->has_eth_src) { 2607 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && 2608 (mask->has_eth_src) && 2609 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 2610 monitor_printf(mon, " src <any mcast/bcast>"); 2611 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && 2612 (mask->has_eth_src) && 2613 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 2614 monitor_printf(mon, " src <any ucast>"); 2615 } else { 2616 monitor_printf(mon, " src %s", key->eth_src); 2617 if (mask->has_eth_src) { 2618 monitor_printf(mon, "(%s)", mask->eth_src); 2619 } 2620 } 2621 } 2622 2623 if (key->has_eth_dst) { 2624 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && 2625 (mask->has_eth_dst) && 2626 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 2627 monitor_printf(mon, " dst <any mcast/bcast>"); 2628 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && 2629 (mask->has_eth_dst) && 2630 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 2631 monitor_printf(mon, " dst <any ucast>"); 2632 } else { 2633 monitor_printf(mon, " dst %s", key->eth_dst); 2634 if (mask->has_eth_dst) { 2635 monitor_printf(mon, "(%s)", mask->eth_dst); 2636 } 2637 } 2638 } 2639 2640 if (key->has_ip_proto) { 2641 monitor_printf(mon, " proto %d", key->ip_proto); 2642 if (mask->has_ip_proto) { 2643 monitor_printf(mon, "(0x%x)", mask->ip_proto); 2644 } 2645 } 2646 2647 if (key->has_ip_tos) { 2648 monitor_printf(mon, " TOS %d", key->ip_tos); 2649 if (mask->has_ip_tos) { 2650 monitor_printf(mon, "(0x%x)", mask->ip_tos); 2651 } 2652 } 2653 2654 if (key->has_ip_dst) { 2655 monitor_printf(mon, " dst %s", key->ip_dst); 2656 } 2657 2658 if (action->has_goto_tbl || action->has_group_id || 2659 action->has_new_vlan_id) { 2660 monitor_printf(mon, " -->"); 2661 } 2662 2663 if (action->has_new_vlan_id) { 2664 monitor_printf(mon, " apply new vlan %d", 2665 ntohs(action->new_vlan_id)); 2666 } 2667 2668 if (action->has_group_id) { 2669 monitor_printf(mon, " write group 0x%08x", action->group_id); 2670 } 2671 2672 if (action->has_goto_tbl) { 2673 monitor_printf(mon, " goto tbl %d", action->goto_tbl); 2674 } 2675 2676 monitor_printf(mon, "\n"); 2677 } 2678 2679 qapi_free_RockerOfDpaFlowList(list); 2680 } 2681 2682 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) 2683 { 2684 RockerOfDpaGroupList *list, *g; 2685 const char *name = qdict_get_str(qdict, "name"); 2686 uint8_t type = qdict_get_try_int(qdict, "type", 9); 2687 Error *err = NULL; 2688 2689 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); 2690 if (err != NULL) { 2691 hmp_handle_error(mon, err); 2692 return; 2693 } 2694 2695 monitor_printf(mon, "id (decode) --> buckets\n"); 2696 2697 for (g = list; g; g = g->next) { 2698 RockerOfDpaGroup *group = g->value; 2699 bool set = false; 2700 2701 monitor_printf(mon, "0x%08x", group->id); 2702 2703 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : 2704 group->type == 1 ? "L2 rewrite" : 2705 group->type == 2 ? "L3 unicast" : 2706 group->type == 3 ? "L2 multicast" : 2707 group->type == 4 ? "L2 flood" : 2708 group->type == 5 ? "L3 interface" : 2709 group->type == 6 ? "L3 multicast" : 2710 group->type == 7 ? "L3 ECMP" : 2711 group->type == 8 ? "L2 overlay" : 2712 "unknown"); 2713 2714 if (group->has_vlan_id) { 2715 monitor_printf(mon, " vlan %d", group->vlan_id); 2716 } 2717 2718 if (group->has_pport) { 2719 monitor_printf(mon, " pport %d", group->pport); 2720 } 2721 2722 if (group->has_index) { 2723 monitor_printf(mon, " index %d", group->index); 2724 } 2725 2726 monitor_printf(mon, ") -->"); 2727 2728 if (group->has_set_vlan_id && group->set_vlan_id) { 2729 set = true; 2730 monitor_printf(mon, " set vlan %d", 2731 group->set_vlan_id & VLAN_VID_MASK); 2732 } 2733 2734 if (group->has_set_eth_src) { 2735 if (!set) { 2736 set = true; 2737 monitor_printf(mon, " set"); 2738 } 2739 monitor_printf(mon, " src %s", group->set_eth_src); 2740 } 2741 2742 if (group->has_set_eth_dst) { 2743 if (!set) { 2744 monitor_printf(mon, " set"); 2745 } 2746 monitor_printf(mon, " dst %s", group->set_eth_dst); 2747 } 2748 2749 if (group->has_ttl_check && group->ttl_check) { 2750 monitor_printf(mon, " check TTL"); 2751 } 2752 2753 if (group->has_group_id && group->group_id) { 2754 monitor_printf(mon, " group id 0x%08x", group->group_id); 2755 } 2756 2757 if (group->has_pop_vlan && group->pop_vlan) { 2758 monitor_printf(mon, " pop vlan"); 2759 } 2760 2761 if (group->has_out_pport) { 2762 monitor_printf(mon, " out pport %d", group->out_pport); 2763 } 2764 2765 if (group->has_group_ids) { 2766 struct uint32List *id; 2767 2768 monitor_printf(mon, " groups ["); 2769 for (id = group->group_ids; id; id = id->next) { 2770 monitor_printf(mon, "0x%08x", id->value); 2771 if (id->next) { 2772 monitor_printf(mon, ","); 2773 } 2774 } 2775 monitor_printf(mon, "]"); 2776 } 2777 2778 monitor_printf(mon, "\n"); 2779 } 2780 2781 qapi_free_RockerOfDpaGroupList(list); 2782 } 2783 2784 void hmp_info_ramblock(Monitor *mon, const QDict *qdict) 2785 { 2786 ram_block_dump(mon); 2787 } 2788 2789 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) 2790 { 2791 Error *err = NULL; 2792 GuidInfo *info = qmp_query_vm_generation_id(&err); 2793 if (info) { 2794 monitor_printf(mon, "%s\n", info->guid); 2795 } 2796 hmp_handle_error(mon, err); 2797 qapi_free_GuidInfo(info); 2798 } 2799 2800 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) 2801 { 2802 Error *err = NULL; 2803 MemoryInfo *info = qmp_query_memory_size_summary(&err); 2804 if (info) { 2805 monitor_printf(mon, "base memory: %" PRIu64 "\n", 2806 info->base_memory); 2807 2808 if (info->has_plugged_memory) { 2809 monitor_printf(mon, "plugged memory: %" PRIu64 "\n", 2810 info->plugged_memory); 2811 } 2812 2813 qapi_free_MemoryInfo(info); 2814 } 2815 hmp_handle_error(mon, err); 2816 } 2817