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