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 "sysemu/runstate.h" 21 #include "qemu/sockets.h" 22 #include "qemu/help_option.h" 23 #include "monitor/monitor.h" 24 #include "qapi/error.h" 25 #include "qapi/clone-visitor.h" 26 #include "qapi/qapi-builtin-visit.h" 27 #include "qapi/qapi-commands-block.h" 28 #include "qapi/qapi-commands-control.h" 29 #include "qapi/qapi-commands-machine.h" 30 #include "qapi/qapi-commands-migration.h" 31 #include "qapi/qapi-commands-misc.h" 32 #include "qapi/qapi-commands-net.h" 33 #include "qapi/qapi-commands-rocker.h" 34 #include "qapi/qapi-commands-run-state.h" 35 #include "qapi/qapi-commands-stats.h" 36 #include "qapi/qapi-commands-tpm.h" 37 #include "qapi/qapi-commands-virtio.h" 38 #include "qapi/qapi-visit-net.h" 39 #include "qapi/qapi-visit-migration.h" 40 #include "qapi/qmp/qdict.h" 41 #include "qapi/qmp/qerror.h" 42 #include "qapi/string-input-visitor.h" 43 #include "qapi/string-output-visitor.h" 44 #include "qom/object_interfaces.h" 45 #include "qemu/cutils.h" 46 #include "qemu/error-report.h" 47 #include "hw/core/cpu.h" 48 #include "hw/intc/intc.h" 49 #include "migration/snapshot.h" 50 #include "migration/misc.h" 51 52 bool hmp_handle_error(Monitor *mon, Error *err) 53 { 54 if (err) { 55 error_reportf_err(err, "Error: "); 56 return true; 57 } 58 return false; 59 } 60 61 /* 62 * Produce a strList from a comma separated list. 63 * A NULL or empty input string return NULL. 64 */ 65 static strList *strList_from_comma_list(const char *in) 66 { 67 strList *res = NULL; 68 strList **tail = &res; 69 70 while (in && in[0]) { 71 char *comma = strchr(in, ','); 72 char *value; 73 74 if (comma) { 75 value = g_strndup(in, comma - in); 76 in = comma + 1; /* skip the , */ 77 } else { 78 value = g_strdup(in); 79 in = NULL; 80 } 81 QAPI_LIST_APPEND(tail, value); 82 } 83 84 return res; 85 } 86 87 void hmp_info_name(Monitor *mon, const QDict *qdict) 88 { 89 NameInfo *info; 90 91 info = qmp_query_name(NULL); 92 if (info->name) { 93 monitor_printf(mon, "%s\n", info->name); 94 } 95 qapi_free_NameInfo(info); 96 } 97 98 void hmp_info_version(Monitor *mon, const QDict *qdict) 99 { 100 VersionInfo *info; 101 102 info = qmp_query_version(NULL); 103 104 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", 105 info->qemu->major, info->qemu->minor, info->qemu->micro, 106 info->package); 107 108 qapi_free_VersionInfo(info); 109 } 110 111 void hmp_info_kvm(Monitor *mon, const QDict *qdict) 112 { 113 KvmInfo *info; 114 115 info = qmp_query_kvm(NULL); 116 monitor_printf(mon, "kvm support: "); 117 if (info->present) { 118 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); 119 } else { 120 monitor_printf(mon, "not compiled\n"); 121 } 122 123 qapi_free_KvmInfo(info); 124 } 125 126 void hmp_info_status(Monitor *mon, const QDict *qdict) 127 { 128 StatusInfo *info; 129 130 info = qmp_query_status(NULL); 131 132 monitor_printf(mon, "VM status: %s%s", 133 info->running ? "running" : "paused", 134 info->singlestep ? " (single step mode)" : ""); 135 136 if (!info->running && info->status != RUN_STATE_PAUSED) { 137 monitor_printf(mon, " (%s)", RunState_str(info->status)); 138 } 139 140 monitor_printf(mon, "\n"); 141 142 qapi_free_StatusInfo(info); 143 } 144 145 void hmp_info_uuid(Monitor *mon, const QDict *qdict) 146 { 147 UuidInfo *info; 148 149 info = qmp_query_uuid(NULL); 150 monitor_printf(mon, "%s\n", info->UUID); 151 qapi_free_UuidInfo(info); 152 } 153 154 void hmp_info_migrate(Monitor *mon, const QDict *qdict) 155 { 156 MigrationInfo *info; 157 158 info = qmp_query_migrate(NULL); 159 160 migration_global_dump(mon); 161 162 if (info->blocked_reasons) { 163 strList *reasons = info->blocked_reasons; 164 monitor_printf(mon, "Outgoing migration blocked:\n"); 165 while (reasons) { 166 monitor_printf(mon, " %s\n", reasons->value); 167 reasons = reasons->next; 168 } 169 } 170 171 if (info->has_status) { 172 monitor_printf(mon, "Migration status: %s", 173 MigrationStatus_str(info->status)); 174 if (info->status == MIGRATION_STATUS_FAILED && info->error_desc) { 175 monitor_printf(mon, " (%s)\n", info->error_desc); 176 } else { 177 monitor_printf(mon, "\n"); 178 } 179 180 monitor_printf(mon, "total time: %" PRIu64 " ms\n", 181 info->total_time); 182 if (info->has_expected_downtime) { 183 monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n", 184 info->expected_downtime); 185 } 186 if (info->has_downtime) { 187 monitor_printf(mon, "downtime: %" PRIu64 " ms\n", 188 info->downtime); 189 } 190 if (info->has_setup_time) { 191 monitor_printf(mon, "setup: %" PRIu64 " ms\n", 192 info->setup_time); 193 } 194 } 195 196 if (info->ram) { 197 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", 198 info->ram->transferred >> 10); 199 monitor_printf(mon, "throughput: %0.2f mbps\n", 200 info->ram->mbps); 201 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", 202 info->ram->remaining >> 10); 203 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", 204 info->ram->total >> 10); 205 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", 206 info->ram->duplicate); 207 monitor_printf(mon, "skipped: %" PRIu64 " pages\n", 208 info->ram->skipped); 209 monitor_printf(mon, "normal: %" PRIu64 " pages\n", 210 info->ram->normal); 211 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", 212 info->ram->normal_bytes >> 10); 213 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", 214 info->ram->dirty_sync_count); 215 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", 216 info->ram->page_size >> 10); 217 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", 218 info->ram->multifd_bytes >> 10); 219 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", 220 info->ram->pages_per_second); 221 222 if (info->ram->dirty_pages_rate) { 223 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", 224 info->ram->dirty_pages_rate); 225 } 226 if (info->ram->postcopy_requests) { 227 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", 228 info->ram->postcopy_requests); 229 } 230 if (info->ram->precopy_bytes) { 231 monitor_printf(mon, "precopy ram: %" PRIu64 " kbytes\n", 232 info->ram->precopy_bytes >> 10); 233 } 234 if (info->ram->downtime_bytes) { 235 monitor_printf(mon, "downtime ram: %" PRIu64 " kbytes\n", 236 info->ram->downtime_bytes >> 10); 237 } 238 if (info->ram->postcopy_bytes) { 239 monitor_printf(mon, "postcopy ram: %" PRIu64 " kbytes\n", 240 info->ram->postcopy_bytes >> 10); 241 } 242 if (info->ram->dirty_sync_missed_zero_copy) { 243 monitor_printf(mon, 244 "Zero-copy-send fallbacks happened: %" PRIu64 " times\n", 245 info->ram->dirty_sync_missed_zero_copy); 246 } 247 } 248 249 if (info->disk) { 250 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", 251 info->disk->transferred >> 10); 252 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", 253 info->disk->remaining >> 10); 254 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", 255 info->disk->total >> 10); 256 } 257 258 if (info->xbzrle_cache) { 259 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", 260 info->xbzrle_cache->cache_size); 261 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", 262 info->xbzrle_cache->bytes >> 10); 263 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", 264 info->xbzrle_cache->pages); 265 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n", 266 info->xbzrle_cache->cache_miss); 267 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", 268 info->xbzrle_cache->cache_miss_rate); 269 monitor_printf(mon, "xbzrle encoding rate: %0.2f\n", 270 info->xbzrle_cache->encoding_rate); 271 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n", 272 info->xbzrle_cache->overflow); 273 } 274 275 if (info->compression) { 276 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", 277 info->compression->pages); 278 monitor_printf(mon, "compression busy: %" PRIu64 "\n", 279 info->compression->busy); 280 monitor_printf(mon, "compression busy rate: %0.2f\n", 281 info->compression->busy_rate); 282 monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n", 283 info->compression->compressed_size >> 10); 284 monitor_printf(mon, "compression rate: %0.2f\n", 285 info->compression->compression_rate); 286 } 287 288 if (info->has_cpu_throttle_percentage) { 289 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", 290 info->cpu_throttle_percentage); 291 } 292 293 if (info->has_postcopy_blocktime) { 294 monitor_printf(mon, "postcopy blocktime: %u\n", 295 info->postcopy_blocktime); 296 } 297 298 if (info->has_postcopy_vcpu_blocktime) { 299 Visitor *v; 300 char *str; 301 v = string_output_visitor_new(false, &str); 302 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, 303 &error_abort); 304 visit_complete(v, &str); 305 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); 306 g_free(str); 307 visit_free(v); 308 } 309 if (info->has_socket_address) { 310 SocketAddressList *addr; 311 312 monitor_printf(mon, "socket address: [\n"); 313 314 for (addr = info->socket_address; addr; addr = addr->next) { 315 char *s = socket_uri(addr->value); 316 monitor_printf(mon, "\t%s\n", s); 317 g_free(s); 318 } 319 monitor_printf(mon, "]\n"); 320 } 321 322 if (info->vfio) { 323 monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n", 324 info->vfio->transferred >> 10); 325 } 326 327 qapi_free_MigrationInfo(info); 328 } 329 330 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) 331 { 332 MigrationCapabilityStatusList *caps, *cap; 333 334 caps = qmp_query_migrate_capabilities(NULL); 335 336 if (caps) { 337 for (cap = caps; cap; cap = cap->next) { 338 monitor_printf(mon, "%s: %s\n", 339 MigrationCapability_str(cap->value->capability), 340 cap->value->state ? "on" : "off"); 341 } 342 } 343 344 qapi_free_MigrationCapabilityStatusList(caps); 345 } 346 347 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) 348 { 349 MigrationParameters *params; 350 351 params = qmp_query_migrate_parameters(NULL); 352 353 if (params) { 354 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 355 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), 356 params->announce_initial); 357 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 358 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), 359 params->announce_max); 360 monitor_printf(mon, "%s: %" PRIu64 "\n", 361 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), 362 params->announce_rounds); 363 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 364 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), 365 params->announce_step); 366 assert(params->has_compress_level); 367 monitor_printf(mon, "%s: %u\n", 368 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), 369 params->compress_level); 370 assert(params->has_compress_threads); 371 monitor_printf(mon, "%s: %u\n", 372 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), 373 params->compress_threads); 374 assert(params->has_compress_wait_thread); 375 monitor_printf(mon, "%s: %s\n", 376 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), 377 params->compress_wait_thread ? "on" : "off"); 378 assert(params->has_decompress_threads); 379 monitor_printf(mon, "%s: %u\n", 380 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), 381 params->decompress_threads); 382 assert(params->has_throttle_trigger_threshold); 383 monitor_printf(mon, "%s: %u\n", 384 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD), 385 params->throttle_trigger_threshold); 386 assert(params->has_cpu_throttle_initial); 387 monitor_printf(mon, "%s: %u\n", 388 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), 389 params->cpu_throttle_initial); 390 assert(params->has_cpu_throttle_increment); 391 monitor_printf(mon, "%s: %u\n", 392 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), 393 params->cpu_throttle_increment); 394 assert(params->has_cpu_throttle_tailslow); 395 monitor_printf(mon, "%s: %s\n", 396 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW), 397 params->cpu_throttle_tailslow ? "on" : "off"); 398 assert(params->has_max_cpu_throttle); 399 monitor_printf(mon, "%s: %u\n", 400 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), 401 params->max_cpu_throttle); 402 assert(params->tls_creds); 403 monitor_printf(mon, "%s: '%s'\n", 404 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), 405 params->tls_creds); 406 assert(params->tls_hostname); 407 monitor_printf(mon, "%s: '%s'\n", 408 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), 409 params->tls_hostname); 410 assert(params->has_max_bandwidth); 411 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", 412 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), 413 params->max_bandwidth); 414 assert(params->has_downtime_limit); 415 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 416 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), 417 params->downtime_limit); 418 assert(params->has_x_checkpoint_delay); 419 monitor_printf(mon, "%s: %u ms\n", 420 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), 421 params->x_checkpoint_delay); 422 assert(params->has_block_incremental); 423 monitor_printf(mon, "%s: %s\n", 424 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), 425 params->block_incremental ? "on" : "off"); 426 monitor_printf(mon, "%s: %u\n", 427 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), 428 params->multifd_channels); 429 monitor_printf(mon, "%s: %s\n", 430 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION), 431 MultiFDCompression_str(params->multifd_compression)); 432 monitor_printf(mon, "%s: %" PRIu64 " bytes\n", 433 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), 434 params->xbzrle_cache_size); 435 monitor_printf(mon, "%s: %" PRIu64 "\n", 436 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), 437 params->max_postcopy_bandwidth); 438 monitor_printf(mon, "%s: '%s'\n", 439 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), 440 params->tls_authz); 441 442 if (params->has_block_bitmap_mapping) { 443 const BitmapMigrationNodeAliasList *bmnal; 444 445 monitor_printf(mon, "%s:\n", 446 MigrationParameter_str( 447 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING)); 448 449 for (bmnal = params->block_bitmap_mapping; 450 bmnal; 451 bmnal = bmnal->next) 452 { 453 const BitmapMigrationNodeAlias *bmna = bmnal->value; 454 const BitmapMigrationBitmapAliasList *bmbal; 455 456 monitor_printf(mon, " '%s' -> '%s'\n", 457 bmna->node_name, bmna->alias); 458 459 for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) { 460 const BitmapMigrationBitmapAlias *bmba = bmbal->value; 461 462 monitor_printf(mon, " '%s' -> '%s'\n", 463 bmba->name, bmba->alias); 464 } 465 } 466 } 467 } 468 469 qapi_free_MigrationParameters(params); 470 } 471 472 void hmp_info_balloon(Monitor *mon, const QDict *qdict) 473 { 474 BalloonInfo *info; 475 Error *err = NULL; 476 477 info = qmp_query_balloon(&err); 478 if (hmp_handle_error(mon, err)) { 479 return; 480 } 481 482 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); 483 484 qapi_free_BalloonInfo(info); 485 } 486 487 static int hmp_info_pic_foreach(Object *obj, void *opaque) 488 { 489 InterruptStatsProvider *intc; 490 InterruptStatsProviderClass *k; 491 Monitor *mon = opaque; 492 493 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { 494 intc = INTERRUPT_STATS_PROVIDER(obj); 495 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); 496 if (k->print_info) { 497 k->print_info(intc, mon); 498 } else { 499 monitor_printf(mon, "Interrupt controller information not available for %s.\n", 500 object_get_typename(obj)); 501 } 502 } 503 504 return 0; 505 } 506 507 void hmp_info_pic(Monitor *mon, const QDict *qdict) 508 { 509 object_child_foreach_recursive(object_get_root(), 510 hmp_info_pic_foreach, mon); 511 } 512 513 void hmp_info_tpm(Monitor *mon, const QDict *qdict) 514 { 515 #ifdef CONFIG_TPM 516 TPMInfoList *info_list, *info; 517 Error *err = NULL; 518 unsigned int c = 0; 519 TPMPassthroughOptions *tpo; 520 TPMEmulatorOptions *teo; 521 522 info_list = qmp_query_tpm(&err); 523 if (err) { 524 monitor_printf(mon, "TPM device not supported\n"); 525 error_free(err); 526 return; 527 } 528 529 if (info_list) { 530 monitor_printf(mon, "TPM device:\n"); 531 } 532 533 for (info = info_list; info; info = info->next) { 534 TPMInfo *ti = info->value; 535 monitor_printf(mon, " tpm%d: model=%s\n", 536 c, TpmModel_str(ti->model)); 537 538 monitor_printf(mon, " \\ %s: type=%s", 539 ti->id, TpmType_str(ti->options->type)); 540 541 switch (ti->options->type) { 542 case TPM_TYPE_PASSTHROUGH: 543 tpo = ti->options->u.passthrough.data; 544 monitor_printf(mon, "%s%s%s%s", 545 tpo->path ? ",path=" : "", 546 tpo->path ?: "", 547 tpo->cancel_path ? ",cancel-path=" : "", 548 tpo->cancel_path ?: ""); 549 break; 550 case TPM_TYPE_EMULATOR: 551 teo = ti->options->u.emulator.data; 552 monitor_printf(mon, ",chardev=%s", teo->chardev); 553 break; 554 case TPM_TYPE__MAX: 555 break; 556 } 557 monitor_printf(mon, "\n"); 558 c++; 559 } 560 qapi_free_TPMInfoList(info_list); 561 #else 562 monitor_printf(mon, "TPM device not supported\n"); 563 #endif /* CONFIG_TPM */ 564 } 565 566 void hmp_quit(Monitor *mon, const QDict *qdict) 567 { 568 monitor_suspend(mon); 569 qmp_quit(NULL); 570 } 571 572 void hmp_stop(Monitor *mon, const QDict *qdict) 573 { 574 qmp_stop(NULL); 575 } 576 577 void hmp_sync_profile(Monitor *mon, const QDict *qdict) 578 { 579 const char *op = qdict_get_try_str(qdict, "op"); 580 581 if (op == NULL) { 582 bool on = qsp_is_enabled(); 583 584 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); 585 return; 586 } 587 if (!strcmp(op, "on")) { 588 qsp_enable(); 589 } else if (!strcmp(op, "off")) { 590 qsp_disable(); 591 } else if (!strcmp(op, "reset")) { 592 qsp_reset(); 593 } else { 594 Error *err = NULL; 595 596 error_setg(&err, QERR_INVALID_PARAMETER, op); 597 hmp_handle_error(mon, err); 598 } 599 } 600 601 void hmp_system_reset(Monitor *mon, const QDict *qdict) 602 { 603 qmp_system_reset(NULL); 604 } 605 606 void hmp_system_powerdown(Monitor *mon, const QDict *qdict) 607 { 608 qmp_system_powerdown(NULL); 609 } 610 611 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) 612 { 613 Error *err = NULL; 614 615 qmp_x_exit_preconfig(&err); 616 hmp_handle_error(mon, err); 617 } 618 619 void hmp_cpu(Monitor *mon, const QDict *qdict) 620 { 621 int64_t cpu_index; 622 623 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that 624 use it are converted to the QAPI */ 625 cpu_index = qdict_get_int(qdict, "index"); 626 if (monitor_set_cpu(mon, cpu_index) < 0) { 627 monitor_printf(mon, "invalid CPU index\n"); 628 } 629 } 630 631 void hmp_memsave(Monitor *mon, const QDict *qdict) 632 { 633 uint32_t size = qdict_get_int(qdict, "size"); 634 const char *filename = qdict_get_str(qdict, "filename"); 635 uint64_t addr = qdict_get_int(qdict, "val"); 636 Error *err = NULL; 637 int cpu_index = monitor_get_cpu_index(mon); 638 639 if (cpu_index < 0) { 640 monitor_printf(mon, "No CPU available\n"); 641 return; 642 } 643 644 qmp_memsave(addr, size, filename, true, cpu_index, &err); 645 hmp_handle_error(mon, err); 646 } 647 648 void hmp_pmemsave(Monitor *mon, const QDict *qdict) 649 { 650 uint32_t size = qdict_get_int(qdict, "size"); 651 const char *filename = qdict_get_str(qdict, "filename"); 652 uint64_t addr = qdict_get_int(qdict, "val"); 653 Error *err = NULL; 654 655 qmp_pmemsave(addr, size, filename, &err); 656 hmp_handle_error(mon, err); 657 } 658 659 void hmp_cont(Monitor *mon, const QDict *qdict) 660 { 661 Error *err = NULL; 662 663 qmp_cont(&err); 664 hmp_handle_error(mon, err); 665 } 666 667 void hmp_system_wakeup(Monitor *mon, const QDict *qdict) 668 { 669 Error *err = NULL; 670 671 qmp_system_wakeup(&err); 672 hmp_handle_error(mon, err); 673 } 674 675 void hmp_nmi(Monitor *mon, const QDict *qdict) 676 { 677 Error *err = NULL; 678 679 qmp_inject_nmi(&err); 680 hmp_handle_error(mon, err); 681 } 682 683 void hmp_set_link(Monitor *mon, const QDict *qdict) 684 { 685 const char *name = qdict_get_str(qdict, "name"); 686 bool up = qdict_get_bool(qdict, "up"); 687 Error *err = NULL; 688 689 qmp_set_link(name, up, &err); 690 hmp_handle_error(mon, err); 691 } 692 693 void hmp_balloon(Monitor *mon, const QDict *qdict) 694 { 695 int64_t value = qdict_get_int(qdict, "value"); 696 Error *err = NULL; 697 698 qmp_balloon(value, &err); 699 hmp_handle_error(mon, err); 700 } 701 702 void hmp_loadvm(Monitor *mon, const QDict *qdict) 703 { 704 int saved_vm_running = runstate_is_running(); 705 const char *name = qdict_get_str(qdict, "name"); 706 Error *err = NULL; 707 708 vm_stop(RUN_STATE_RESTORE_VM); 709 710 if (load_snapshot(name, NULL, false, NULL, &err) && saved_vm_running) { 711 vm_start(); 712 } 713 hmp_handle_error(mon, err); 714 } 715 716 void hmp_savevm(Monitor *mon, const QDict *qdict) 717 { 718 Error *err = NULL; 719 720 save_snapshot(qdict_get_try_str(qdict, "name"), 721 true, NULL, false, NULL, &err); 722 hmp_handle_error(mon, err); 723 } 724 725 void hmp_delvm(Monitor *mon, const QDict *qdict) 726 { 727 Error *err = NULL; 728 const char *name = qdict_get_str(qdict, "name"); 729 730 delete_snapshot(name, false, NULL, &err); 731 hmp_handle_error(mon, err); 732 } 733 734 void hmp_announce_self(Monitor *mon, const QDict *qdict) 735 { 736 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces"); 737 const char *id = qdict_get_try_str(qdict, "id"); 738 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters, 739 migrate_announce_params()); 740 741 qapi_free_strList(params->interfaces); 742 params->interfaces = strList_from_comma_list(interfaces_str); 743 params->has_interfaces = params->interfaces != NULL; 744 params->id = g_strdup(id); 745 qmp_announce_self(params, NULL); 746 qapi_free_AnnounceParameters(params); 747 } 748 749 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) 750 { 751 qmp_migrate_cancel(NULL); 752 } 753 754 void hmp_migrate_continue(Monitor *mon, const QDict *qdict) 755 { 756 Error *err = NULL; 757 const char *state = qdict_get_str(qdict, "state"); 758 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); 759 760 if (val >= 0) { 761 qmp_migrate_continue(val, &err); 762 } 763 764 hmp_handle_error(mon, err); 765 } 766 767 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) 768 { 769 Error *err = NULL; 770 const char *uri = qdict_get_str(qdict, "uri"); 771 772 qmp_migrate_incoming(uri, &err); 773 774 hmp_handle_error(mon, err); 775 } 776 777 void hmp_migrate_recover(Monitor *mon, const QDict *qdict) 778 { 779 Error *err = NULL; 780 const char *uri = qdict_get_str(qdict, "uri"); 781 782 qmp_migrate_recover(uri, &err); 783 784 hmp_handle_error(mon, err); 785 } 786 787 void hmp_migrate_pause(Monitor *mon, const QDict *qdict) 788 { 789 Error *err = NULL; 790 791 qmp_migrate_pause(&err); 792 793 hmp_handle_error(mon, err); 794 } 795 796 797 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) 798 { 799 const char *cap = qdict_get_str(qdict, "capability"); 800 bool state = qdict_get_bool(qdict, "state"); 801 Error *err = NULL; 802 MigrationCapabilityStatusList *caps = NULL; 803 MigrationCapabilityStatus *value; 804 int val; 805 806 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); 807 if (val < 0) { 808 goto end; 809 } 810 811 value = g_malloc0(sizeof(*value)); 812 value->capability = val; 813 value->state = state; 814 QAPI_LIST_PREPEND(caps, value); 815 qmp_migrate_set_capabilities(caps, &err); 816 qapi_free_MigrationCapabilityStatusList(caps); 817 818 end: 819 hmp_handle_error(mon, err); 820 } 821 822 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) 823 { 824 const char *param = qdict_get_str(qdict, "parameter"); 825 const char *valuestr = qdict_get_str(qdict, "value"); 826 Visitor *v = string_input_visitor_new(valuestr); 827 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); 828 uint64_t valuebw = 0; 829 uint64_t cache_size; 830 Error *err = NULL; 831 int val, ret; 832 833 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); 834 if (val < 0) { 835 goto cleanup; 836 } 837 838 switch (val) { 839 case MIGRATION_PARAMETER_COMPRESS_LEVEL: 840 p->has_compress_level = true; 841 visit_type_uint8(v, param, &p->compress_level, &err); 842 break; 843 case MIGRATION_PARAMETER_COMPRESS_THREADS: 844 p->has_compress_threads = true; 845 visit_type_uint8(v, param, &p->compress_threads, &err); 846 break; 847 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: 848 p->has_compress_wait_thread = true; 849 visit_type_bool(v, param, &p->compress_wait_thread, &err); 850 break; 851 case MIGRATION_PARAMETER_DECOMPRESS_THREADS: 852 p->has_decompress_threads = true; 853 visit_type_uint8(v, param, &p->decompress_threads, &err); 854 break; 855 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: 856 p->has_throttle_trigger_threshold = true; 857 visit_type_uint8(v, param, &p->throttle_trigger_threshold, &err); 858 break; 859 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: 860 p->has_cpu_throttle_initial = true; 861 visit_type_uint8(v, param, &p->cpu_throttle_initial, &err); 862 break; 863 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: 864 p->has_cpu_throttle_increment = true; 865 visit_type_uint8(v, param, &p->cpu_throttle_increment, &err); 866 break; 867 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW: 868 p->has_cpu_throttle_tailslow = true; 869 visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err); 870 break; 871 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: 872 p->has_max_cpu_throttle = true; 873 visit_type_uint8(v, param, &p->max_cpu_throttle, &err); 874 break; 875 case MIGRATION_PARAMETER_TLS_CREDS: 876 p->tls_creds = g_new0(StrOrNull, 1); 877 p->tls_creds->type = QTYPE_QSTRING; 878 visit_type_str(v, param, &p->tls_creds->u.s, &err); 879 break; 880 case MIGRATION_PARAMETER_TLS_HOSTNAME: 881 p->tls_hostname = g_new0(StrOrNull, 1); 882 p->tls_hostname->type = QTYPE_QSTRING; 883 visit_type_str(v, param, &p->tls_hostname->u.s, &err); 884 break; 885 case MIGRATION_PARAMETER_TLS_AUTHZ: 886 p->tls_authz = g_new0(StrOrNull, 1); 887 p->tls_authz->type = QTYPE_QSTRING; 888 visit_type_str(v, param, &p->tls_authz->u.s, &err); 889 break; 890 case MIGRATION_PARAMETER_MAX_BANDWIDTH: 891 p->has_max_bandwidth = true; 892 /* 893 * Can't use visit_type_size() here, because it 894 * defaults to Bytes rather than Mebibytes. 895 */ 896 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); 897 if (ret < 0 || valuebw > INT64_MAX 898 || (size_t)valuebw != valuebw) { 899 error_setg(&err, "Invalid size %s", valuestr); 900 break; 901 } 902 p->max_bandwidth = valuebw; 903 break; 904 case MIGRATION_PARAMETER_DOWNTIME_LIMIT: 905 p->has_downtime_limit = true; 906 visit_type_size(v, param, &p->downtime_limit, &err); 907 break; 908 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: 909 p->has_x_checkpoint_delay = true; 910 visit_type_uint32(v, param, &p->x_checkpoint_delay, &err); 911 break; 912 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: 913 p->has_block_incremental = true; 914 visit_type_bool(v, param, &p->block_incremental, &err); 915 break; 916 case MIGRATION_PARAMETER_MULTIFD_CHANNELS: 917 p->has_multifd_channels = true; 918 visit_type_uint8(v, param, &p->multifd_channels, &err); 919 break; 920 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: 921 p->has_multifd_compression = true; 922 visit_type_MultiFDCompression(v, param, &p->multifd_compression, 923 &err); 924 break; 925 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: 926 p->has_multifd_zlib_level = true; 927 visit_type_uint8(v, param, &p->multifd_zlib_level, &err); 928 break; 929 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: 930 p->has_multifd_zstd_level = true; 931 visit_type_uint8(v, param, &p->multifd_zstd_level, &err); 932 break; 933 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: 934 p->has_xbzrle_cache_size = true; 935 if (!visit_type_size(v, param, &cache_size, &err)) { 936 break; 937 } 938 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) { 939 error_setg(&err, "Invalid size %s", valuestr); 940 break; 941 } 942 p->xbzrle_cache_size = cache_size; 943 break; 944 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: 945 p->has_max_postcopy_bandwidth = true; 946 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); 947 break; 948 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: 949 p->has_announce_initial = true; 950 visit_type_size(v, param, &p->announce_initial, &err); 951 break; 952 case MIGRATION_PARAMETER_ANNOUNCE_MAX: 953 p->has_announce_max = true; 954 visit_type_size(v, param, &p->announce_max, &err); 955 break; 956 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: 957 p->has_announce_rounds = true; 958 visit_type_size(v, param, &p->announce_rounds, &err); 959 break; 960 case MIGRATION_PARAMETER_ANNOUNCE_STEP: 961 p->has_announce_step = true; 962 visit_type_size(v, param, &p->announce_step, &err); 963 break; 964 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING: 965 error_setg(&err, "The block-bitmap-mapping parameter can only be set " 966 "through QMP"); 967 break; 968 default: 969 assert(0); 970 } 971 972 if (err) { 973 goto cleanup; 974 } 975 976 qmp_migrate_set_parameters(p, &err); 977 978 cleanup: 979 qapi_free_MigrateSetParameters(p); 980 visit_free(v); 981 hmp_handle_error(mon, err); 982 } 983 984 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) 985 { 986 Error *err = NULL; 987 const char *protocol = qdict_get_str(qdict, "protocol"); 988 const char *hostname = qdict_get_str(qdict, "hostname"); 989 bool has_port = qdict_haskey(qdict, "port"); 990 int port = qdict_get_try_int(qdict, "port", -1); 991 bool has_tls_port = qdict_haskey(qdict, "tls-port"); 992 int tls_port = qdict_get_try_int(qdict, "tls-port", -1); 993 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); 994 995 qmp_client_migrate_info(protocol, hostname, 996 has_port, port, has_tls_port, tls_port, 997 cert_subject, &err); 998 hmp_handle_error(mon, err); 999 } 1000 1001 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) 1002 { 1003 Error *err = NULL; 1004 qmp_migrate_start_postcopy(&err); 1005 hmp_handle_error(mon, err); 1006 } 1007 1008 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) 1009 { 1010 Error *err = NULL; 1011 1012 qmp_x_colo_lost_heartbeat(&err); 1013 hmp_handle_error(mon, err); 1014 } 1015 1016 void hmp_change(Monitor *mon, const QDict *qdict) 1017 { 1018 const char *device = qdict_get_str(qdict, "device"); 1019 const char *target = qdict_get_str(qdict, "target"); 1020 const char *arg = qdict_get_try_str(qdict, "arg"); 1021 const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); 1022 bool force = qdict_get_try_bool(qdict, "force", false); 1023 BlockdevChangeReadOnlyMode read_only_mode = 0; 1024 Error *err = NULL; 1025 1026 #ifdef CONFIG_VNC 1027 if (strcmp(device, "vnc") == 0) { 1028 hmp_change_vnc(mon, device, target, arg, read_only, force, &err); 1029 } else 1030 #endif 1031 { 1032 if (read_only) { 1033 read_only_mode = 1034 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, 1035 read_only, 1036 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); 1037 if (err) { 1038 goto end; 1039 } 1040 } 1041 1042 qmp_blockdev_change_medium(device, NULL, target, arg, true, force, 1043 !!read_only, read_only_mode, 1044 &err); 1045 } 1046 1047 end: 1048 hmp_handle_error(mon, err); 1049 } 1050 1051 typedef struct HMPMigrationStatus { 1052 QEMUTimer *timer; 1053 Monitor *mon; 1054 bool is_block_migration; 1055 } HMPMigrationStatus; 1056 1057 static void hmp_migrate_status_cb(void *opaque) 1058 { 1059 HMPMigrationStatus *status = opaque; 1060 MigrationInfo *info; 1061 1062 info = qmp_query_migrate(NULL); 1063 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || 1064 info->status == MIGRATION_STATUS_SETUP) { 1065 if (info->disk) { 1066 int progress; 1067 1068 if (info->disk->remaining) { 1069 progress = info->disk->transferred * 100 / info->disk->total; 1070 } else { 1071 progress = 100; 1072 } 1073 1074 monitor_printf(status->mon, "Completed %d %%\r", progress); 1075 monitor_flush(status->mon); 1076 } 1077 1078 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); 1079 } else { 1080 if (status->is_block_migration) { 1081 monitor_printf(status->mon, "\n"); 1082 } 1083 if (info->error_desc) { 1084 error_report("%s", info->error_desc); 1085 } 1086 monitor_resume(status->mon); 1087 timer_free(status->timer); 1088 g_free(status); 1089 } 1090 1091 qapi_free_MigrationInfo(info); 1092 } 1093 1094 void hmp_migrate(Monitor *mon, const QDict *qdict) 1095 { 1096 bool detach = qdict_get_try_bool(qdict, "detach", false); 1097 bool blk = qdict_get_try_bool(qdict, "blk", false); 1098 bool inc = qdict_get_try_bool(qdict, "inc", false); 1099 bool resume = qdict_get_try_bool(qdict, "resume", false); 1100 const char *uri = qdict_get_str(qdict, "uri"); 1101 Error *err = NULL; 1102 1103 qmp_migrate(uri, !!blk, blk, !!inc, inc, 1104 false, false, true, resume, &err); 1105 if (hmp_handle_error(mon, err)) { 1106 return; 1107 } 1108 1109 if (!detach) { 1110 HMPMigrationStatus *status; 1111 1112 if (monitor_suspend(mon) < 0) { 1113 monitor_printf(mon, "terminal does not allow synchronous " 1114 "migration, continuing detached\n"); 1115 return; 1116 } 1117 1118 status = g_malloc0(sizeof(*status)); 1119 status->mon = mon; 1120 status->is_block_migration = blk || inc; 1121 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, 1122 status); 1123 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); 1124 } 1125 } 1126 1127 void hmp_netdev_add(Monitor *mon, const QDict *qdict) 1128 { 1129 Error *err = NULL; 1130 QemuOpts *opts; 1131 const char *type = qdict_get_try_str(qdict, "type"); 1132 1133 if (type && is_help_option(type)) { 1134 show_netdevs(); 1135 return; 1136 } 1137 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); 1138 if (err) { 1139 goto out; 1140 } 1141 1142 netdev_add(opts, &err); 1143 if (err) { 1144 qemu_opts_del(opts); 1145 } 1146 1147 out: 1148 hmp_handle_error(mon, err); 1149 } 1150 1151 void hmp_netdev_del(Monitor *mon, const QDict *qdict) 1152 { 1153 const char *id = qdict_get_str(qdict, "id"); 1154 Error *err = NULL; 1155 1156 qmp_netdev_del(id, &err); 1157 hmp_handle_error(mon, err); 1158 } 1159 1160 void hmp_object_add(Monitor *mon, const QDict *qdict) 1161 { 1162 const char *options = qdict_get_str(qdict, "object"); 1163 Error *err = NULL; 1164 1165 user_creatable_add_from_str(options, &err); 1166 hmp_handle_error(mon, err); 1167 } 1168 1169 void hmp_getfd(Monitor *mon, const QDict *qdict) 1170 { 1171 const char *fdname = qdict_get_str(qdict, "fdname"); 1172 Error *err = NULL; 1173 1174 qmp_getfd(fdname, &err); 1175 hmp_handle_error(mon, err); 1176 } 1177 1178 void hmp_closefd(Monitor *mon, const QDict *qdict) 1179 { 1180 const char *fdname = qdict_get_str(qdict, "fdname"); 1181 Error *err = NULL; 1182 1183 qmp_closefd(fdname, &err); 1184 hmp_handle_error(mon, err); 1185 } 1186 1187 void hmp_object_del(Monitor *mon, const QDict *qdict) 1188 { 1189 const char *id = qdict_get_str(qdict, "id"); 1190 Error *err = NULL; 1191 1192 user_creatable_del(id, &err); 1193 hmp_handle_error(mon, err); 1194 } 1195 1196 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) 1197 { 1198 Error *err = NULL; 1199 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); 1200 MemoryDeviceInfoList *info; 1201 VirtioPMEMDeviceInfo *vpi; 1202 VirtioMEMDeviceInfo *vmi; 1203 MemoryDeviceInfo *value; 1204 PCDIMMDeviceInfo *di; 1205 SgxEPCDeviceInfo *se; 1206 1207 for (info = info_list; info; info = info->next) { 1208 value = info->value; 1209 1210 if (value) { 1211 switch (value->type) { 1212 case MEMORY_DEVICE_INFO_KIND_DIMM: 1213 case MEMORY_DEVICE_INFO_KIND_NVDIMM: 1214 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ? 1215 value->u.dimm.data : value->u.nvdimm.data; 1216 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1217 MemoryDeviceInfoKind_str(value->type), 1218 di->id ? di->id : ""); 1219 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); 1220 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); 1221 monitor_printf(mon, " node: %" PRId64 "\n", di->node); 1222 monitor_printf(mon, " size: %" PRIu64 "\n", di->size); 1223 monitor_printf(mon, " memdev: %s\n", di->memdev); 1224 monitor_printf(mon, " hotplugged: %s\n", 1225 di->hotplugged ? "true" : "false"); 1226 monitor_printf(mon, " hotpluggable: %s\n", 1227 di->hotpluggable ? "true" : "false"); 1228 break; 1229 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: 1230 vpi = value->u.virtio_pmem.data; 1231 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1232 MemoryDeviceInfoKind_str(value->type), 1233 vpi->id ? vpi->id : ""); 1234 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr); 1235 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); 1236 monitor_printf(mon, " memdev: %s\n", vpi->memdev); 1237 break; 1238 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM: 1239 vmi = value->u.virtio_mem.data; 1240 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1241 MemoryDeviceInfoKind_str(value->type), 1242 vmi->id ? vmi->id : ""); 1243 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr); 1244 monitor_printf(mon, " node: %" PRId64 "\n", vmi->node); 1245 monitor_printf(mon, " requested-size: %" PRIu64 "\n", 1246 vmi->requested_size); 1247 monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size); 1248 monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size); 1249 monitor_printf(mon, " block-size: %" PRIu64 "\n", 1250 vmi->block_size); 1251 monitor_printf(mon, " memdev: %s\n", vmi->memdev); 1252 break; 1253 case MEMORY_DEVICE_INFO_KIND_SGX_EPC: 1254 se = value->u.sgx_epc.data; 1255 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1256 MemoryDeviceInfoKind_str(value->type), 1257 se->id ? se->id : ""); 1258 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", se->memaddr); 1259 monitor_printf(mon, " size: %" PRIu64 "\n", se->size); 1260 monitor_printf(mon, " node: %" PRId64 "\n", se->node); 1261 monitor_printf(mon, " memdev: %s\n", se->memdev); 1262 break; 1263 default: 1264 g_assert_not_reached(); 1265 } 1266 } 1267 } 1268 1269 qapi_free_MemoryDeviceInfoList(info_list); 1270 hmp_handle_error(mon, err); 1271 } 1272 1273 void hmp_info_iothreads(Monitor *mon, const QDict *qdict) 1274 { 1275 IOThreadInfoList *info_list = qmp_query_iothreads(NULL); 1276 IOThreadInfoList *info; 1277 IOThreadInfo *value; 1278 1279 for (info = info_list; info; info = info->next) { 1280 value = info->value; 1281 monitor_printf(mon, "%s:\n", value->id); 1282 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); 1283 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); 1284 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); 1285 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); 1286 monitor_printf(mon, " aio-max-batch=%" PRId64 "\n", 1287 value->aio_max_batch); 1288 } 1289 1290 qapi_free_IOThreadInfoList(info_list); 1291 } 1292 1293 void hmp_rocker(Monitor *mon, const QDict *qdict) 1294 { 1295 const char *name = qdict_get_str(qdict, "name"); 1296 RockerSwitch *rocker; 1297 Error *err = NULL; 1298 1299 rocker = qmp_query_rocker(name, &err); 1300 if (hmp_handle_error(mon, err)) { 1301 return; 1302 } 1303 1304 monitor_printf(mon, "name: %s\n", rocker->name); 1305 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); 1306 monitor_printf(mon, "ports: %d\n", rocker->ports); 1307 1308 qapi_free_RockerSwitch(rocker); 1309 } 1310 1311 void hmp_rocker_ports(Monitor *mon, const QDict *qdict) 1312 { 1313 RockerPortList *list, *port; 1314 const char *name = qdict_get_str(qdict, "name"); 1315 Error *err = NULL; 1316 1317 list = qmp_query_rocker_ports(name, &err); 1318 if (hmp_handle_error(mon, err)) { 1319 return; 1320 } 1321 1322 monitor_printf(mon, " ena/ speed/ auto\n"); 1323 monitor_printf(mon, " port link duplex neg?\n"); 1324 1325 for (port = list; port; port = port->next) { 1326 monitor_printf(mon, "%10s %-4s %-3s %2s %s\n", 1327 port->value->name, 1328 port->value->enabled ? port->value->link_up ? 1329 "up" : "down" : "!ena", 1330 port->value->speed == 10000 ? "10G" : "??", 1331 port->value->duplex ? "FD" : "HD", 1332 port->value->autoneg ? "Yes" : "No"); 1333 } 1334 1335 qapi_free_RockerPortList(list); 1336 } 1337 1338 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) 1339 { 1340 RockerOfDpaFlowList *list, *info; 1341 const char *name = qdict_get_str(qdict, "name"); 1342 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); 1343 Error *err = NULL; 1344 1345 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); 1346 if (hmp_handle_error(mon, err)) { 1347 return; 1348 } 1349 1350 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); 1351 1352 for (info = list; info; info = info->next) { 1353 RockerOfDpaFlow *flow = info->value; 1354 RockerOfDpaFlowKey *key = flow->key; 1355 RockerOfDpaFlowMask *mask = flow->mask; 1356 RockerOfDpaFlowAction *action = flow->action; 1357 1358 if (flow->hits) { 1359 monitor_printf(mon, "%-4d %-3d %-4" PRIu64, 1360 key->priority, key->tbl_id, flow->hits); 1361 } else { 1362 monitor_printf(mon, "%-4d %-3d ", 1363 key->priority, key->tbl_id); 1364 } 1365 1366 if (key->has_in_pport) { 1367 monitor_printf(mon, " pport %d", key->in_pport); 1368 if (mask->has_in_pport) { 1369 monitor_printf(mon, "(0x%x)", mask->in_pport); 1370 } 1371 } 1372 1373 if (key->has_vlan_id) { 1374 monitor_printf(mon, " vlan %d", 1375 key->vlan_id & VLAN_VID_MASK); 1376 if (mask->has_vlan_id) { 1377 monitor_printf(mon, "(0x%x)", mask->vlan_id); 1378 } 1379 } 1380 1381 if (key->has_tunnel_id) { 1382 monitor_printf(mon, " tunnel %d", key->tunnel_id); 1383 if (mask->has_tunnel_id) { 1384 monitor_printf(mon, "(0x%x)", mask->tunnel_id); 1385 } 1386 } 1387 1388 if (key->has_eth_type) { 1389 switch (key->eth_type) { 1390 case 0x0806: 1391 monitor_printf(mon, " ARP"); 1392 break; 1393 case 0x0800: 1394 monitor_printf(mon, " IP"); 1395 break; 1396 case 0x86dd: 1397 monitor_printf(mon, " IPv6"); 1398 break; 1399 case 0x8809: 1400 monitor_printf(mon, " LACP"); 1401 break; 1402 case 0x88cc: 1403 monitor_printf(mon, " LLDP"); 1404 break; 1405 default: 1406 monitor_printf(mon, " eth type 0x%04x", key->eth_type); 1407 break; 1408 } 1409 } 1410 1411 if (key->eth_src) { 1412 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && 1413 mask->eth_src && 1414 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 1415 monitor_printf(mon, " src <any mcast/bcast>"); 1416 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && 1417 mask->eth_src && 1418 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 1419 monitor_printf(mon, " src <any ucast>"); 1420 } else { 1421 monitor_printf(mon, " src %s", key->eth_src); 1422 if (mask->eth_src) { 1423 monitor_printf(mon, "(%s)", mask->eth_src); 1424 } 1425 } 1426 } 1427 1428 if (key->eth_dst) { 1429 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && 1430 mask->eth_dst && 1431 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 1432 monitor_printf(mon, " dst <any mcast/bcast>"); 1433 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && 1434 mask->eth_dst && 1435 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 1436 monitor_printf(mon, " dst <any ucast>"); 1437 } else { 1438 monitor_printf(mon, " dst %s", key->eth_dst); 1439 if (mask->eth_dst) { 1440 monitor_printf(mon, "(%s)", mask->eth_dst); 1441 } 1442 } 1443 } 1444 1445 if (key->has_ip_proto) { 1446 monitor_printf(mon, " proto %d", key->ip_proto); 1447 if (mask->has_ip_proto) { 1448 monitor_printf(mon, "(0x%x)", mask->ip_proto); 1449 } 1450 } 1451 1452 if (key->has_ip_tos) { 1453 monitor_printf(mon, " TOS %d", key->ip_tos); 1454 if (mask->has_ip_tos) { 1455 monitor_printf(mon, "(0x%x)", mask->ip_tos); 1456 } 1457 } 1458 1459 if (key->ip_dst) { 1460 monitor_printf(mon, " dst %s", key->ip_dst); 1461 } 1462 1463 if (action->has_goto_tbl || action->has_group_id || 1464 action->has_new_vlan_id) { 1465 monitor_printf(mon, " -->"); 1466 } 1467 1468 if (action->has_new_vlan_id) { 1469 monitor_printf(mon, " apply new vlan %d", 1470 ntohs(action->new_vlan_id)); 1471 } 1472 1473 if (action->has_group_id) { 1474 monitor_printf(mon, " write group 0x%08x", action->group_id); 1475 } 1476 1477 if (action->has_goto_tbl) { 1478 monitor_printf(mon, " goto tbl %d", action->goto_tbl); 1479 } 1480 1481 monitor_printf(mon, "\n"); 1482 } 1483 1484 qapi_free_RockerOfDpaFlowList(list); 1485 } 1486 1487 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) 1488 { 1489 RockerOfDpaGroupList *list, *g; 1490 const char *name = qdict_get_str(qdict, "name"); 1491 uint8_t type = qdict_get_try_int(qdict, "type", 9); 1492 Error *err = NULL; 1493 1494 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); 1495 if (hmp_handle_error(mon, err)) { 1496 return; 1497 } 1498 1499 monitor_printf(mon, "id (decode) --> buckets\n"); 1500 1501 for (g = list; g; g = g->next) { 1502 RockerOfDpaGroup *group = g->value; 1503 bool set = false; 1504 1505 monitor_printf(mon, "0x%08x", group->id); 1506 1507 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : 1508 group->type == 1 ? "L2 rewrite" : 1509 group->type == 2 ? "L3 unicast" : 1510 group->type == 3 ? "L2 multicast" : 1511 group->type == 4 ? "L2 flood" : 1512 group->type == 5 ? "L3 interface" : 1513 group->type == 6 ? "L3 multicast" : 1514 group->type == 7 ? "L3 ECMP" : 1515 group->type == 8 ? "L2 overlay" : 1516 "unknown"); 1517 1518 if (group->has_vlan_id) { 1519 monitor_printf(mon, " vlan %d", group->vlan_id); 1520 } 1521 1522 if (group->has_pport) { 1523 monitor_printf(mon, " pport %d", group->pport); 1524 } 1525 1526 if (group->has_index) { 1527 monitor_printf(mon, " index %d", group->index); 1528 } 1529 1530 monitor_printf(mon, ") -->"); 1531 1532 if (group->has_set_vlan_id && group->set_vlan_id) { 1533 set = true; 1534 monitor_printf(mon, " set vlan %d", 1535 group->set_vlan_id & VLAN_VID_MASK); 1536 } 1537 1538 if (group->set_eth_src) { 1539 if (!set) { 1540 set = true; 1541 monitor_printf(mon, " set"); 1542 } 1543 monitor_printf(mon, " src %s", group->set_eth_src); 1544 } 1545 1546 if (group->set_eth_dst) { 1547 if (!set) { 1548 monitor_printf(mon, " set"); 1549 } 1550 monitor_printf(mon, " dst %s", group->set_eth_dst); 1551 } 1552 1553 if (group->has_ttl_check && group->ttl_check) { 1554 monitor_printf(mon, " check TTL"); 1555 } 1556 1557 if (group->has_group_id && group->group_id) { 1558 monitor_printf(mon, " group id 0x%08x", group->group_id); 1559 } 1560 1561 if (group->has_pop_vlan && group->pop_vlan) { 1562 monitor_printf(mon, " pop vlan"); 1563 } 1564 1565 if (group->has_out_pport) { 1566 monitor_printf(mon, " out pport %d", group->out_pport); 1567 } 1568 1569 if (group->has_group_ids) { 1570 struct uint32List *id; 1571 1572 monitor_printf(mon, " groups ["); 1573 for (id = group->group_ids; id; id = id->next) { 1574 monitor_printf(mon, "0x%08x", id->value); 1575 if (id->next) { 1576 monitor_printf(mon, ","); 1577 } 1578 } 1579 monitor_printf(mon, "]"); 1580 } 1581 1582 monitor_printf(mon, "\n"); 1583 } 1584 1585 qapi_free_RockerOfDpaGroupList(list); 1586 } 1587 1588 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) 1589 { 1590 Error *err = NULL; 1591 GuidInfo *info = qmp_query_vm_generation_id(&err); 1592 if (info) { 1593 monitor_printf(mon, "%s\n", info->guid); 1594 } 1595 hmp_handle_error(mon, err); 1596 qapi_free_GuidInfo(info); 1597 } 1598 1599 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) 1600 { 1601 Error *err = NULL; 1602 MemoryInfo *info = qmp_query_memory_size_summary(&err); 1603 if (info) { 1604 monitor_printf(mon, "base memory: %" PRIu64 "\n", 1605 info->base_memory); 1606 1607 if (info->has_plugged_memory) { 1608 monitor_printf(mon, "plugged memory: %" PRIu64 "\n", 1609 info->plugged_memory); 1610 } 1611 1612 qapi_free_MemoryInfo(info); 1613 } 1614 hmp_handle_error(mon, err); 1615 } 1616 1617 static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value) 1618 { 1619 const char *unit = NULL; 1620 monitor_printf(mon, " %s (%s%s", value->name, StatsType_str(value->type), 1621 value->has_unit || value->exponent ? ", " : ""); 1622 1623 if (value->has_unit) { 1624 if (value->unit == STATS_UNIT_SECONDS) { 1625 unit = "s"; 1626 } else if (value->unit == STATS_UNIT_BYTES) { 1627 unit = "B"; 1628 } 1629 } 1630 1631 if (unit && value->base == 10 && 1632 value->exponent >= -18 && value->exponent <= 18 && 1633 value->exponent % 3 == 0) { 1634 monitor_puts(mon, si_prefix(value->exponent)); 1635 } else if (unit && value->base == 2 && 1636 value->exponent >= 0 && value->exponent <= 60 && 1637 value->exponent % 10 == 0) { 1638 1639 monitor_puts(mon, iec_binary_prefix(value->exponent)); 1640 } else if (value->exponent) { 1641 /* Use exponential notation and write the unit's English name */ 1642 monitor_printf(mon, "* %d^%d%s", 1643 value->base, value->exponent, 1644 value->has_unit ? " " : ""); 1645 unit = NULL; 1646 } 1647 1648 if (value->has_unit) { 1649 monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit)); 1650 } 1651 1652 /* Print bucket size for linear histograms */ 1653 if (value->type == STATS_TYPE_LINEAR_HISTOGRAM && value->has_bucket_size) { 1654 monitor_printf(mon, ", bucket size=%d", value->bucket_size); 1655 } 1656 monitor_printf(mon, ")"); 1657 } 1658 1659 static StatsSchemaValueList *find_schema_value_list( 1660 StatsSchemaList *list, StatsProvider provider, 1661 StatsTarget target) 1662 { 1663 StatsSchemaList *node; 1664 1665 for (node = list; node; node = node->next) { 1666 if (node->value->provider == provider && 1667 node->value->target == target) { 1668 return node->value->stats; 1669 } 1670 } 1671 return NULL; 1672 } 1673 1674 static void print_stats_results(Monitor *mon, StatsTarget target, 1675 bool show_provider, 1676 StatsResult *result, 1677 StatsSchemaList *schema) 1678 { 1679 /* Find provider schema */ 1680 StatsSchemaValueList *schema_value_list = 1681 find_schema_value_list(schema, result->provider, target); 1682 StatsList *stats_list; 1683 1684 if (!schema_value_list) { 1685 monitor_printf(mon, "failed to find schema list for %s\n", 1686 StatsProvider_str(result->provider)); 1687 return; 1688 } 1689 1690 if (show_provider) { 1691 monitor_printf(mon, "provider: %s\n", 1692 StatsProvider_str(result->provider)); 1693 } 1694 1695 for (stats_list = result->stats; stats_list; 1696 stats_list = stats_list->next, 1697 schema_value_list = schema_value_list->next) { 1698 1699 Stats *stats = stats_list->value; 1700 StatsValue *stats_value = stats->value; 1701 StatsSchemaValue *schema_value = schema_value_list->value; 1702 1703 /* Find schema entry */ 1704 while (!g_str_equal(stats->name, schema_value->name)) { 1705 if (!schema_value_list->next) { 1706 monitor_printf(mon, "failed to find schema entry for %s\n", 1707 stats->name); 1708 return; 1709 } 1710 schema_value_list = schema_value_list->next; 1711 schema_value = schema_value_list->value; 1712 } 1713 1714 print_stats_schema_value(mon, schema_value); 1715 1716 if (stats_value->type == QTYPE_QNUM) { 1717 monitor_printf(mon, ": %" PRId64 "\n", stats_value->u.scalar); 1718 } else if (stats_value->type == QTYPE_QBOOL) { 1719 monitor_printf(mon, ": %s\n", stats_value->u.boolean ? "yes" : "no"); 1720 } else if (stats_value->type == QTYPE_QLIST) { 1721 uint64List *list; 1722 int i; 1723 1724 monitor_printf(mon, ": "); 1725 for (list = stats_value->u.list, i = 1; 1726 list; 1727 list = list->next, i++) { 1728 monitor_printf(mon, "[%d]=%" PRId64 " ", i, list->value); 1729 } 1730 monitor_printf(mon, "\n"); 1731 } 1732 } 1733 } 1734 1735 /* Create the StatsFilter that is needed for an "info stats" invocation. */ 1736 static StatsFilter *stats_filter(StatsTarget target, const char *names, 1737 int cpu_index, StatsProvider provider) 1738 { 1739 StatsFilter *filter = g_malloc0(sizeof(*filter)); 1740 StatsProvider provider_idx; 1741 StatsRequestList *request_list = NULL; 1742 1743 filter->target = target; 1744 switch (target) { 1745 case STATS_TARGET_VM: 1746 break; 1747 case STATS_TARGET_VCPU: 1748 { 1749 strList *vcpu_list = NULL; 1750 CPUState *cpu = qemu_get_cpu(cpu_index); 1751 char *canonical_path = object_get_canonical_path(OBJECT(cpu)); 1752 1753 QAPI_LIST_PREPEND(vcpu_list, canonical_path); 1754 filter->u.vcpu.has_vcpus = true; 1755 filter->u.vcpu.vcpus = vcpu_list; 1756 break; 1757 } 1758 default: 1759 break; 1760 } 1761 1762 if (!names && provider == STATS_PROVIDER__MAX) { 1763 return filter; 1764 } 1765 1766 /* 1767 * "info stats" can only query either one or all the providers. Querying 1768 * by name, but not by provider, requires the creation of one filter per 1769 * provider. 1770 */ 1771 for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++) { 1772 if (provider == STATS_PROVIDER__MAX || provider == provider_idx) { 1773 StatsRequest *request = g_new0(StatsRequest, 1); 1774 request->provider = provider_idx; 1775 if (names && !g_str_equal(names, "*")) { 1776 request->has_names = true; 1777 request->names = strList_from_comma_list(names); 1778 } 1779 QAPI_LIST_PREPEND(request_list, request); 1780 } 1781 } 1782 1783 filter->has_providers = true; 1784 filter->providers = request_list; 1785 return filter; 1786 } 1787 1788 void hmp_info_stats(Monitor *mon, const QDict *qdict) 1789 { 1790 const char *target_str = qdict_get_str(qdict, "target"); 1791 const char *provider_str = qdict_get_try_str(qdict, "provider"); 1792 const char *names = qdict_get_try_str(qdict, "names"); 1793 1794 StatsProvider provider = STATS_PROVIDER__MAX; 1795 StatsTarget target; 1796 Error *err = NULL; 1797 g_autoptr(StatsSchemaList) schema = NULL; 1798 g_autoptr(StatsResultList) stats = NULL; 1799 g_autoptr(StatsFilter) filter = NULL; 1800 StatsResultList *entry; 1801 1802 target = qapi_enum_parse(&StatsTarget_lookup, target_str, -1, &err); 1803 if (err) { 1804 monitor_printf(mon, "invalid stats target %s\n", target_str); 1805 goto exit_no_print; 1806 } 1807 if (provider_str) { 1808 provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err); 1809 if (err) { 1810 monitor_printf(mon, "invalid stats provider %s\n", provider_str); 1811 goto exit_no_print; 1812 } 1813 } 1814 1815 schema = qmp_query_stats_schemas(provider_str ? true : false, 1816 provider, &err); 1817 if (err) { 1818 goto exit; 1819 } 1820 1821 switch (target) { 1822 case STATS_TARGET_VM: 1823 filter = stats_filter(target, names, -1, provider); 1824 break; 1825 case STATS_TARGET_VCPU: {} 1826 int cpu_index = monitor_get_cpu_index(mon); 1827 filter = stats_filter(target, names, cpu_index, provider); 1828 break; 1829 default: 1830 abort(); 1831 } 1832 1833 stats = qmp_query_stats(filter, &err); 1834 if (err) { 1835 goto exit; 1836 } 1837 for (entry = stats; entry; entry = entry->next) { 1838 print_stats_results(mon, target, provider_str == NULL, entry->value, schema); 1839 } 1840 1841 exit: 1842 if (err) { 1843 monitor_printf(mon, "%s\n", error_get_pretty(err)); 1844 } 1845 exit_no_print: 1846 error_free(err); 1847 } 1848 1849 static void hmp_virtio_dump_protocols(Monitor *mon, 1850 VhostDeviceProtocols *pcol) 1851 { 1852 strList *pcol_list = pcol->protocols; 1853 while (pcol_list) { 1854 monitor_printf(mon, "\t%s", pcol_list->value); 1855 pcol_list = pcol_list->next; 1856 if (pcol_list != NULL) { 1857 monitor_printf(mon, ",\n"); 1858 } 1859 } 1860 monitor_printf(mon, "\n"); 1861 if (pcol->has_unknown_protocols) { 1862 monitor_printf(mon, " unknown-protocols(0x%016"PRIx64")\n", 1863 pcol->unknown_protocols); 1864 } 1865 } 1866 1867 static void hmp_virtio_dump_status(Monitor *mon, 1868 VirtioDeviceStatus *status) 1869 { 1870 strList *status_list = status->statuses; 1871 while (status_list) { 1872 monitor_printf(mon, "\t%s", status_list->value); 1873 status_list = status_list->next; 1874 if (status_list != NULL) { 1875 monitor_printf(mon, ",\n"); 1876 } 1877 } 1878 monitor_printf(mon, "\n"); 1879 if (status->has_unknown_statuses) { 1880 monitor_printf(mon, " unknown-statuses(0x%016"PRIx32")\n", 1881 status->unknown_statuses); 1882 } 1883 } 1884 1885 static void hmp_virtio_dump_features(Monitor *mon, 1886 VirtioDeviceFeatures *features) 1887 { 1888 strList *transport_list = features->transports; 1889 while (transport_list) { 1890 monitor_printf(mon, "\t%s", transport_list->value); 1891 transport_list = transport_list->next; 1892 if (transport_list != NULL) { 1893 monitor_printf(mon, ",\n"); 1894 } 1895 } 1896 1897 monitor_printf(mon, "\n"); 1898 strList *list = features->dev_features; 1899 if (list) { 1900 while (list) { 1901 monitor_printf(mon, "\t%s", list->value); 1902 list = list->next; 1903 if (list != NULL) { 1904 monitor_printf(mon, ",\n"); 1905 } 1906 } 1907 monitor_printf(mon, "\n"); 1908 } 1909 1910 if (features->has_unknown_dev_features) { 1911 monitor_printf(mon, " unknown-features(0x%016"PRIx64")\n", 1912 features->unknown_dev_features); 1913 } 1914 } 1915 1916 void hmp_virtio_query(Monitor *mon, const QDict *qdict) 1917 { 1918 Error *err = NULL; 1919 VirtioInfoList *list = qmp_x_query_virtio(&err); 1920 VirtioInfoList *node; 1921 1922 if (err != NULL) { 1923 hmp_handle_error(mon, err); 1924 return; 1925 } 1926 1927 if (list == NULL) { 1928 monitor_printf(mon, "No VirtIO devices\n"); 1929 return; 1930 } 1931 1932 node = list; 1933 while (node) { 1934 monitor_printf(mon, "%s [%s]\n", node->value->path, 1935 node->value->name); 1936 node = node->next; 1937 } 1938 qapi_free_VirtioInfoList(list); 1939 } 1940 1941 void hmp_virtio_status(Monitor *mon, const QDict *qdict) 1942 { 1943 Error *err = NULL; 1944 const char *path = qdict_get_try_str(qdict, "path"); 1945 VirtioStatus *s = qmp_x_query_virtio_status(path, &err); 1946 1947 if (err != NULL) { 1948 hmp_handle_error(mon, err); 1949 return; 1950 } 1951 1952 monitor_printf(mon, "%s:\n", path); 1953 monitor_printf(mon, " device_name: %s %s\n", 1954 s->name, s->vhost_dev ? "(vhost)" : ""); 1955 monitor_printf(mon, " device_id: %d\n", s->device_id); 1956 monitor_printf(mon, " vhost_started: %s\n", 1957 s->vhost_started ? "true" : "false"); 1958 monitor_printf(mon, " bus_name: %s\n", s->bus_name); 1959 monitor_printf(mon, " broken: %s\n", 1960 s->broken ? "true" : "false"); 1961 monitor_printf(mon, " disabled: %s\n", 1962 s->disabled ? "true" : "false"); 1963 monitor_printf(mon, " disable_legacy_check: %s\n", 1964 s->disable_legacy_check ? "true" : "false"); 1965 monitor_printf(mon, " started: %s\n", 1966 s->started ? "true" : "false"); 1967 monitor_printf(mon, " use_started: %s\n", 1968 s->use_started ? "true" : "false"); 1969 monitor_printf(mon, " start_on_kick: %s\n", 1970 s->start_on_kick ? "true" : "false"); 1971 monitor_printf(mon, " use_guest_notifier_mask: %s\n", 1972 s->use_guest_notifier_mask ? "true" : "false"); 1973 monitor_printf(mon, " vm_running: %s\n", 1974 s->vm_running ? "true" : "false"); 1975 monitor_printf(mon, " num_vqs: %"PRId64"\n", s->num_vqs); 1976 monitor_printf(mon, " queue_sel: %d\n", 1977 s->queue_sel); 1978 monitor_printf(mon, " isr: %d\n", s->isr); 1979 monitor_printf(mon, " endianness: %s\n", 1980 s->device_endian); 1981 monitor_printf(mon, " status:\n"); 1982 hmp_virtio_dump_status(mon, s->status); 1983 monitor_printf(mon, " Guest features:\n"); 1984 hmp_virtio_dump_features(mon, s->guest_features); 1985 monitor_printf(mon, " Host features:\n"); 1986 hmp_virtio_dump_features(mon, s->host_features); 1987 monitor_printf(mon, " Backend features:\n"); 1988 hmp_virtio_dump_features(mon, s->backend_features); 1989 1990 if (s->vhost_dev) { 1991 monitor_printf(mon, " VHost:\n"); 1992 monitor_printf(mon, " nvqs: %d\n", 1993 s->vhost_dev->nvqs); 1994 monitor_printf(mon, " vq_index: %"PRId64"\n", 1995 s->vhost_dev->vq_index); 1996 monitor_printf(mon, " max_queues: %"PRId64"\n", 1997 s->vhost_dev->max_queues); 1998 monitor_printf(mon, " n_mem_sections: %"PRId64"\n", 1999 s->vhost_dev->n_mem_sections); 2000 monitor_printf(mon, " n_tmp_sections: %"PRId64"\n", 2001 s->vhost_dev->n_tmp_sections); 2002 monitor_printf(mon, " backend_cap: %"PRId64"\n", 2003 s->vhost_dev->backend_cap); 2004 monitor_printf(mon, " log_enabled: %s\n", 2005 s->vhost_dev->log_enabled ? "true" : "false"); 2006 monitor_printf(mon, " log_size: %"PRId64"\n", 2007 s->vhost_dev->log_size); 2008 monitor_printf(mon, " Features:\n"); 2009 hmp_virtio_dump_features(mon, s->vhost_dev->features); 2010 monitor_printf(mon, " Acked features:\n"); 2011 hmp_virtio_dump_features(mon, s->vhost_dev->acked_features); 2012 monitor_printf(mon, " Backend features:\n"); 2013 hmp_virtio_dump_features(mon, s->vhost_dev->backend_features); 2014 monitor_printf(mon, " Protocol features:\n"); 2015 hmp_virtio_dump_protocols(mon, s->vhost_dev->protocol_features); 2016 } 2017 2018 qapi_free_VirtioStatus(s); 2019 } 2020 2021 void hmp_vhost_queue_status(Monitor *mon, const QDict *qdict) 2022 { 2023 Error *err = NULL; 2024 const char *path = qdict_get_try_str(qdict, "path"); 2025 int queue = qdict_get_int(qdict, "queue"); 2026 VirtVhostQueueStatus *s = 2027 qmp_x_query_virtio_vhost_queue_status(path, queue, &err); 2028 2029 if (err != NULL) { 2030 hmp_handle_error(mon, err); 2031 return; 2032 } 2033 2034 monitor_printf(mon, "%s:\n", path); 2035 monitor_printf(mon, " device_name: %s (vhost)\n", 2036 s->name); 2037 monitor_printf(mon, " kick: %"PRId64"\n", s->kick); 2038 monitor_printf(mon, " call: %"PRId64"\n", s->call); 2039 monitor_printf(mon, " VRing:\n"); 2040 monitor_printf(mon, " num: %"PRId64"\n", s->num); 2041 monitor_printf(mon, " desc: 0x%016"PRIx64"\n", s->desc); 2042 monitor_printf(mon, " desc_phys: 0x%016"PRIx64"\n", 2043 s->desc_phys); 2044 monitor_printf(mon, " desc_size: %"PRId32"\n", s->desc_size); 2045 monitor_printf(mon, " avail: 0x%016"PRIx64"\n", s->avail); 2046 monitor_printf(mon, " avail_phys: 0x%016"PRIx64"\n", 2047 s->avail_phys); 2048 monitor_printf(mon, " avail_size: %"PRId32"\n", s->avail_size); 2049 monitor_printf(mon, " used: 0x%016"PRIx64"\n", s->used); 2050 monitor_printf(mon, " used_phys: 0x%016"PRIx64"\n", 2051 s->used_phys); 2052 monitor_printf(mon, " used_size: %"PRId32"\n", s->used_size); 2053 2054 qapi_free_VirtVhostQueueStatus(s); 2055 } 2056 2057 void hmp_virtio_queue_status(Monitor *mon, const QDict *qdict) 2058 { 2059 Error *err = NULL; 2060 const char *path = qdict_get_try_str(qdict, "path"); 2061 int queue = qdict_get_int(qdict, "queue"); 2062 VirtQueueStatus *s = qmp_x_query_virtio_queue_status(path, queue, &err); 2063 2064 if (err != NULL) { 2065 hmp_handle_error(mon, err); 2066 return; 2067 } 2068 2069 monitor_printf(mon, "%s:\n", path); 2070 monitor_printf(mon, " device_name: %s\n", s->name); 2071 monitor_printf(mon, " queue_index: %d\n", s->queue_index); 2072 monitor_printf(mon, " inuse: %d\n", s->inuse); 2073 monitor_printf(mon, " used_idx: %d\n", s->used_idx); 2074 monitor_printf(mon, " signalled_used: %d\n", 2075 s->signalled_used); 2076 monitor_printf(mon, " signalled_used_valid: %s\n", 2077 s->signalled_used_valid ? "true" : "false"); 2078 if (s->has_last_avail_idx) { 2079 monitor_printf(mon, " last_avail_idx: %d\n", 2080 s->last_avail_idx); 2081 } 2082 if (s->has_shadow_avail_idx) { 2083 monitor_printf(mon, " shadow_avail_idx: %d\n", 2084 s->shadow_avail_idx); 2085 } 2086 monitor_printf(mon, " VRing:\n"); 2087 monitor_printf(mon, " num: %"PRId32"\n", s->vring_num); 2088 monitor_printf(mon, " num_default: %"PRId32"\n", 2089 s->vring_num_default); 2090 monitor_printf(mon, " align: %"PRId32"\n", 2091 s->vring_align); 2092 monitor_printf(mon, " desc: 0x%016"PRIx64"\n", 2093 s->vring_desc); 2094 monitor_printf(mon, " avail: 0x%016"PRIx64"\n", 2095 s->vring_avail); 2096 monitor_printf(mon, " used: 0x%016"PRIx64"\n", 2097 s->vring_used); 2098 2099 qapi_free_VirtQueueStatus(s); 2100 } 2101 2102 void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict) 2103 { 2104 Error *err = NULL; 2105 const char *path = qdict_get_try_str(qdict, "path"); 2106 int queue = qdict_get_int(qdict, "queue"); 2107 int index = qdict_get_try_int(qdict, "index", -1); 2108 VirtioQueueElement *e; 2109 VirtioRingDescList *list; 2110 2111 e = qmp_x_query_virtio_queue_element(path, queue, index != -1, 2112 index, &err); 2113 if (err != NULL) { 2114 hmp_handle_error(mon, err); 2115 return; 2116 } 2117 2118 monitor_printf(mon, "%s:\n", path); 2119 monitor_printf(mon, " device_name: %s\n", e->name); 2120 monitor_printf(mon, " index: %d\n", e->index); 2121 monitor_printf(mon, " desc:\n"); 2122 monitor_printf(mon, " descs:\n"); 2123 2124 list = e->descs; 2125 while (list) { 2126 monitor_printf(mon, " addr 0x%"PRIx64" len %d", 2127 list->value->addr, list->value->len); 2128 if (list->value->flags) { 2129 strList *flag = list->value->flags; 2130 monitor_printf(mon, " ("); 2131 while (flag) { 2132 monitor_printf(mon, "%s", flag->value); 2133 flag = flag->next; 2134 if (flag) { 2135 monitor_printf(mon, ", "); 2136 } 2137 } 2138 monitor_printf(mon, ")"); 2139 } 2140 list = list->next; 2141 if (list) { 2142 monitor_printf(mon, ",\n"); 2143 } 2144 } 2145 monitor_printf(mon, "\n"); 2146 monitor_printf(mon, " avail:\n"); 2147 monitor_printf(mon, " flags: %d\n", e->avail->flags); 2148 monitor_printf(mon, " idx: %d\n", e->avail->idx); 2149 monitor_printf(mon, " ring: %d\n", e->avail->ring); 2150 monitor_printf(mon, " used:\n"); 2151 monitor_printf(mon, " flags: %d\n", e->used->flags); 2152 monitor_printf(mon, " idx: %d\n", e->used->idx); 2153 2154 qapi_free_VirtioQueueElement(e); 2155 } 2156