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-tpm.h" 44 #include "qapi/qapi-commands-ui.h" 45 #include "qapi/qapi-visit-net.h" 46 #include "qapi/qapi-visit-migration.h" 47 #include "qapi/qmp/qdict.h" 48 #include "qapi/qmp/qerror.h" 49 #include "qapi/string-input-visitor.h" 50 #include "qapi/string-output-visitor.h" 51 #include "qom/object_interfaces.h" 52 #include "ui/console.h" 53 #include "qemu/cutils.h" 54 #include "qemu/error-report.h" 55 #include "exec/ramlist.h" 56 #include "hw/intc/intc.h" 57 #include "hw/rdma/rdma.h" 58 #include "migration/snapshot.h" 59 #include "migration/misc.h" 60 61 #ifdef CONFIG_SPICE 62 #include <spice/enums.h> 63 #endif 64 65 void hmp_handle_error(Monitor *mon, Error *err) 66 { 67 if (err) { 68 error_reportf_err(err, "Error: "); 69 } 70 } 71 72 /* 73 * Produce a strList from a comma separated list. 74 * A NULL or empty input string return NULL. 75 */ 76 static strList *strList_from_comma_list(const char *in) 77 { 78 strList *res = NULL; 79 strList **tail = &res; 80 81 while (in && in[0]) { 82 char *comma = strchr(in, ','); 83 char *value; 84 85 if (comma) { 86 value = g_strndup(in, comma - in); 87 in = comma + 1; /* skip the , */ 88 } else { 89 value = g_strdup(in); 90 in = NULL; 91 } 92 QAPI_LIST_APPEND(tail, value); 93 } 94 95 return res; 96 } 97 98 void hmp_info_name(Monitor *mon, const QDict *qdict) 99 { 100 NameInfo *info; 101 102 info = qmp_query_name(NULL); 103 if (info->has_name) { 104 monitor_printf(mon, "%s\n", info->name); 105 } 106 qapi_free_NameInfo(info); 107 } 108 109 void hmp_info_version(Monitor *mon, const QDict *qdict) 110 { 111 VersionInfo *info; 112 113 info = qmp_query_version(NULL); 114 115 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", 116 info->qemu->major, info->qemu->minor, info->qemu->micro, 117 info->package); 118 119 qapi_free_VersionInfo(info); 120 } 121 122 void hmp_info_kvm(Monitor *mon, const QDict *qdict) 123 { 124 KvmInfo *info; 125 126 info = qmp_query_kvm(NULL); 127 monitor_printf(mon, "kvm support: "); 128 if (info->present) { 129 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); 130 } else { 131 monitor_printf(mon, "not compiled\n"); 132 } 133 134 qapi_free_KvmInfo(info); 135 } 136 137 void hmp_info_status(Monitor *mon, const QDict *qdict) 138 { 139 StatusInfo *info; 140 141 info = qmp_query_status(NULL); 142 143 monitor_printf(mon, "VM status: %s%s", 144 info->running ? "running" : "paused", 145 info->singlestep ? " (single step mode)" : ""); 146 147 if (!info->running && info->status != RUN_STATE_PAUSED) { 148 monitor_printf(mon, " (%s)", RunState_str(info->status)); 149 } 150 151 monitor_printf(mon, "\n"); 152 153 qapi_free_StatusInfo(info); 154 } 155 156 void hmp_info_uuid(Monitor *mon, const QDict *qdict) 157 { 158 UuidInfo *info; 159 160 info = qmp_query_uuid(NULL); 161 monitor_printf(mon, "%s\n", info->UUID); 162 qapi_free_UuidInfo(info); 163 } 164 165 void hmp_info_chardev(Monitor *mon, const QDict *qdict) 166 { 167 ChardevInfoList *char_info, *info; 168 169 char_info = qmp_query_chardev(NULL); 170 for (info = char_info; info; info = info->next) { 171 monitor_printf(mon, "%s: filename=%s\n", info->value->label, 172 info->value->filename); 173 } 174 175 qapi_free_ChardevInfoList(char_info); 176 } 177 178 void hmp_info_mice(Monitor *mon, const QDict *qdict) 179 { 180 MouseInfoList *mice_list, *mouse; 181 182 mice_list = qmp_query_mice(NULL); 183 if (!mice_list) { 184 monitor_printf(mon, "No mouse devices connected\n"); 185 return; 186 } 187 188 for (mouse = mice_list; mouse; mouse = mouse->next) { 189 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", 190 mouse->value->current ? '*' : ' ', 191 mouse->value->index, mouse->value->name, 192 mouse->value->absolute ? " (absolute)" : ""); 193 } 194 195 qapi_free_MouseInfoList(mice_list); 196 } 197 198 static char *SocketAddress_to_str(SocketAddress *addr) 199 { 200 switch (addr->type) { 201 case SOCKET_ADDRESS_TYPE_INET: 202 return g_strdup_printf("tcp:%s:%s", 203 addr->u.inet.host, 204 addr->u.inet.port); 205 case SOCKET_ADDRESS_TYPE_UNIX: 206 return g_strdup_printf("unix:%s", 207 addr->u.q_unix.path); 208 case SOCKET_ADDRESS_TYPE_FD: 209 return g_strdup_printf("fd:%s", addr->u.fd.str); 210 case SOCKET_ADDRESS_TYPE_VSOCK: 211 return g_strdup_printf("tcp:%s:%s", 212 addr->u.vsock.cid, 213 addr->u.vsock.port); 214 default: 215 return g_strdup("unknown address type"); 216 } 217 } 218 219 void hmp_info_migrate(Monitor *mon, const QDict *qdict) 220 { 221 MigrationInfo *info; 222 223 info = qmp_query_migrate(NULL); 224 225 migration_global_dump(mon); 226 227 if (info->has_status) { 228 monitor_printf(mon, "Migration status: %s", 229 MigrationStatus_str(info->status)); 230 if (info->status == MIGRATION_STATUS_FAILED && 231 info->has_error_desc) { 232 monitor_printf(mon, " (%s)\n", info->error_desc); 233 } else { 234 monitor_printf(mon, "\n"); 235 } 236 237 monitor_printf(mon, "total time: %" PRIu64 " ms\n", 238 info->total_time); 239 if (info->has_expected_downtime) { 240 monitor_printf(mon, "expected downtime: %" PRIu64 " ms\n", 241 info->expected_downtime); 242 } 243 if (info->has_downtime) { 244 monitor_printf(mon, "downtime: %" PRIu64 " ms\n", 245 info->downtime); 246 } 247 if (info->has_setup_time) { 248 monitor_printf(mon, "setup: %" PRIu64 " ms\n", 249 info->setup_time); 250 } 251 } 252 253 if (info->has_ram) { 254 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", 255 info->ram->transferred >> 10); 256 monitor_printf(mon, "throughput: %0.2f mbps\n", 257 info->ram->mbps); 258 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", 259 info->ram->remaining >> 10); 260 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", 261 info->ram->total >> 10); 262 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n", 263 info->ram->duplicate); 264 monitor_printf(mon, "skipped: %" PRIu64 " pages\n", 265 info->ram->skipped); 266 monitor_printf(mon, "normal: %" PRIu64 " pages\n", 267 info->ram->normal); 268 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n", 269 info->ram->normal_bytes >> 10); 270 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n", 271 info->ram->dirty_sync_count); 272 monitor_printf(mon, "page size: %" PRIu64 " kbytes\n", 273 info->ram->page_size >> 10); 274 monitor_printf(mon, "multifd bytes: %" PRIu64 " kbytes\n", 275 info->ram->multifd_bytes >> 10); 276 monitor_printf(mon, "pages-per-second: %" PRIu64 "\n", 277 info->ram->pages_per_second); 278 279 if (info->ram->dirty_pages_rate) { 280 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n", 281 info->ram->dirty_pages_rate); 282 } 283 if (info->ram->postcopy_requests) { 284 monitor_printf(mon, "postcopy request count: %" PRIu64 "\n", 285 info->ram->postcopy_requests); 286 } 287 } 288 289 if (info->has_disk) { 290 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", 291 info->disk->transferred >> 10); 292 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", 293 info->disk->remaining >> 10); 294 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", 295 info->disk->total >> 10); 296 } 297 298 if (info->has_xbzrle_cache) { 299 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n", 300 info->xbzrle_cache->cache_size); 301 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n", 302 info->xbzrle_cache->bytes >> 10); 303 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n", 304 info->xbzrle_cache->pages); 305 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 " pages\n", 306 info->xbzrle_cache->cache_miss); 307 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n", 308 info->xbzrle_cache->cache_miss_rate); 309 monitor_printf(mon, "xbzrle encoding rate: %0.2f\n", 310 info->xbzrle_cache->encoding_rate); 311 monitor_printf(mon, "xbzrle overflow: %" PRIu64 "\n", 312 info->xbzrle_cache->overflow); 313 } 314 315 if (info->has_compression) { 316 monitor_printf(mon, "compression pages: %" PRIu64 " pages\n", 317 info->compression->pages); 318 monitor_printf(mon, "compression busy: %" PRIu64 "\n", 319 info->compression->busy); 320 monitor_printf(mon, "compression busy rate: %0.2f\n", 321 info->compression->busy_rate); 322 monitor_printf(mon, "compressed size: %" PRIu64 " kbytes\n", 323 info->compression->compressed_size >> 10); 324 monitor_printf(mon, "compression rate: %0.2f\n", 325 info->compression->compression_rate); 326 } 327 328 if (info->has_cpu_throttle_percentage) { 329 monitor_printf(mon, "cpu throttle percentage: %" PRIu64 "\n", 330 info->cpu_throttle_percentage); 331 } 332 333 if (info->has_postcopy_blocktime) { 334 monitor_printf(mon, "postcopy blocktime: %u\n", 335 info->postcopy_blocktime); 336 } 337 338 if (info->has_postcopy_vcpu_blocktime) { 339 Visitor *v; 340 char *str; 341 v = string_output_visitor_new(false, &str); 342 visit_type_uint32List(v, NULL, &info->postcopy_vcpu_blocktime, 343 &error_abort); 344 visit_complete(v, &str); 345 monitor_printf(mon, "postcopy vcpu blocktime: %s\n", str); 346 g_free(str); 347 visit_free(v); 348 } 349 if (info->has_socket_address) { 350 SocketAddressList *addr; 351 352 monitor_printf(mon, "socket address: [\n"); 353 354 for (addr = info->socket_address; addr; addr = addr->next) { 355 char *s = SocketAddress_to_str(addr->value); 356 monitor_printf(mon, "\t%s\n", s); 357 g_free(s); 358 } 359 monitor_printf(mon, "]\n"); 360 } 361 362 if (info->has_vfio) { 363 monitor_printf(mon, "vfio device transferred: %" PRIu64 " kbytes\n", 364 info->vfio->transferred >> 10); 365 } 366 367 qapi_free_MigrationInfo(info); 368 } 369 370 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict) 371 { 372 MigrationCapabilityStatusList *caps, *cap; 373 374 caps = qmp_query_migrate_capabilities(NULL); 375 376 if (caps) { 377 for (cap = caps; cap; cap = cap->next) { 378 monitor_printf(mon, "%s: %s\n", 379 MigrationCapability_str(cap->value->capability), 380 cap->value->state ? "on" : "off"); 381 } 382 } 383 384 qapi_free_MigrationCapabilityStatusList(caps); 385 } 386 387 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) 388 { 389 MigrationParameters *params; 390 391 params = qmp_query_migrate_parameters(NULL); 392 393 if (params) { 394 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 395 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), 396 params->announce_initial); 397 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 398 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), 399 params->announce_max); 400 monitor_printf(mon, "%s: %" PRIu64 "\n", 401 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), 402 params->announce_rounds); 403 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 404 MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), 405 params->announce_step); 406 assert(params->has_compress_level); 407 monitor_printf(mon, "%s: %u\n", 408 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), 409 params->compress_level); 410 assert(params->has_compress_threads); 411 monitor_printf(mon, "%s: %u\n", 412 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS), 413 params->compress_threads); 414 assert(params->has_compress_wait_thread); 415 monitor_printf(mon, "%s: %s\n", 416 MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD), 417 params->compress_wait_thread ? "on" : "off"); 418 assert(params->has_decompress_threads); 419 monitor_printf(mon, "%s: %u\n", 420 MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS), 421 params->decompress_threads); 422 assert(params->has_throttle_trigger_threshold); 423 monitor_printf(mon, "%s: %u\n", 424 MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD), 425 params->throttle_trigger_threshold); 426 assert(params->has_cpu_throttle_initial); 427 monitor_printf(mon, "%s: %u\n", 428 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL), 429 params->cpu_throttle_initial); 430 assert(params->has_cpu_throttle_increment); 431 monitor_printf(mon, "%s: %u\n", 432 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT), 433 params->cpu_throttle_increment); 434 assert(params->has_cpu_throttle_tailslow); 435 monitor_printf(mon, "%s: %s\n", 436 MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW), 437 params->cpu_throttle_tailslow ? "on" : "off"); 438 assert(params->has_max_cpu_throttle); 439 monitor_printf(mon, "%s: %u\n", 440 MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE), 441 params->max_cpu_throttle); 442 assert(params->has_tls_creds); 443 monitor_printf(mon, "%s: '%s'\n", 444 MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS), 445 params->tls_creds); 446 assert(params->has_tls_hostname); 447 monitor_printf(mon, "%s: '%s'\n", 448 MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME), 449 params->tls_hostname); 450 assert(params->has_max_bandwidth); 451 monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n", 452 MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH), 453 params->max_bandwidth); 454 assert(params->has_downtime_limit); 455 monitor_printf(mon, "%s: %" PRIu64 " ms\n", 456 MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT), 457 params->downtime_limit); 458 assert(params->has_x_checkpoint_delay); 459 monitor_printf(mon, "%s: %u ms\n", 460 MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY), 461 params->x_checkpoint_delay); 462 assert(params->has_block_incremental); 463 monitor_printf(mon, "%s: %s\n", 464 MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL), 465 params->block_incremental ? "on" : "off"); 466 monitor_printf(mon, "%s: %u\n", 467 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS), 468 params->multifd_channels); 469 monitor_printf(mon, "%s: %s\n", 470 MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION), 471 MultiFDCompression_str(params->multifd_compression)); 472 monitor_printf(mon, "%s: %" PRIu64 " bytes\n", 473 MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE), 474 params->xbzrle_cache_size); 475 monitor_printf(mon, "%s: %" PRIu64 "\n", 476 MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH), 477 params->max_postcopy_bandwidth); 478 monitor_printf(mon, "%s: '%s'\n", 479 MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ), 480 params->tls_authz); 481 482 if (params->has_block_bitmap_mapping) { 483 const BitmapMigrationNodeAliasList *bmnal; 484 485 monitor_printf(mon, "%s:\n", 486 MigrationParameter_str( 487 MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING)); 488 489 for (bmnal = params->block_bitmap_mapping; 490 bmnal; 491 bmnal = bmnal->next) 492 { 493 const BitmapMigrationNodeAlias *bmna = bmnal->value; 494 const BitmapMigrationBitmapAliasList *bmbal; 495 496 monitor_printf(mon, " '%s' -> '%s'\n", 497 bmna->node_name, bmna->alias); 498 499 for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) { 500 const BitmapMigrationBitmapAlias *bmba = bmbal->value; 501 502 monitor_printf(mon, " '%s' -> '%s'\n", 503 bmba->name, bmba->alias); 504 } 505 } 506 } 507 } 508 509 qapi_free_MigrationParameters(params); 510 } 511 512 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict) 513 { 514 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n", 515 qmp_query_migrate_cache_size(NULL) >> 10); 516 } 517 518 519 #ifdef CONFIG_VNC 520 /* Helper for hmp_info_vnc_clients, _servers */ 521 static void hmp_info_VncBasicInfo(Monitor *mon, VncBasicInfo *info, 522 const char *name) 523 { 524 monitor_printf(mon, " %s: %s:%s (%s%s)\n", 525 name, 526 info->host, 527 info->service, 528 NetworkAddressFamily_str(info->family), 529 info->websocket ? " (Websocket)" : ""); 530 } 531 532 /* Helper displaying and auth and crypt info */ 533 static void hmp_info_vnc_authcrypt(Monitor *mon, const char *indent, 534 VncPrimaryAuth auth, 535 VncVencryptSubAuth *vencrypt) 536 { 537 monitor_printf(mon, "%sAuth: %s (Sub: %s)\n", indent, 538 VncPrimaryAuth_str(auth), 539 vencrypt ? VncVencryptSubAuth_str(*vencrypt) : "none"); 540 } 541 542 static void hmp_info_vnc_clients(Monitor *mon, VncClientInfoList *client) 543 { 544 while (client) { 545 VncClientInfo *cinfo = client->value; 546 547 hmp_info_VncBasicInfo(mon, qapi_VncClientInfo_base(cinfo), "Client"); 548 monitor_printf(mon, " x509_dname: %s\n", 549 cinfo->has_x509_dname ? 550 cinfo->x509_dname : "none"); 551 monitor_printf(mon, " sasl_username: %s\n", 552 cinfo->has_sasl_username ? 553 cinfo->sasl_username : "none"); 554 555 client = client->next; 556 } 557 } 558 559 static void hmp_info_vnc_servers(Monitor *mon, VncServerInfo2List *server) 560 { 561 while (server) { 562 VncServerInfo2 *sinfo = server->value; 563 hmp_info_VncBasicInfo(mon, qapi_VncServerInfo2_base(sinfo), "Server"); 564 hmp_info_vnc_authcrypt(mon, " ", sinfo->auth, 565 sinfo->has_vencrypt ? &sinfo->vencrypt : NULL); 566 server = server->next; 567 } 568 } 569 570 void hmp_info_vnc(Monitor *mon, const QDict *qdict) 571 { 572 VncInfo2List *info2l, *info2l_head; 573 Error *err = NULL; 574 575 info2l = qmp_query_vnc_servers(&err); 576 info2l_head = info2l; 577 if (err) { 578 hmp_handle_error(mon, err); 579 return; 580 } 581 if (!info2l) { 582 monitor_printf(mon, "None\n"); 583 return; 584 } 585 586 while (info2l) { 587 VncInfo2 *info = info2l->value; 588 monitor_printf(mon, "%s:\n", info->id); 589 hmp_info_vnc_servers(mon, info->server); 590 hmp_info_vnc_clients(mon, info->clients); 591 if (!info->server) { 592 /* The server entry displays its auth, we only 593 * need to display in the case of 'reverse' connections 594 * where there's no server. 595 */ 596 hmp_info_vnc_authcrypt(mon, " ", info->auth, 597 info->has_vencrypt ? &info->vencrypt : NULL); 598 } 599 if (info->has_display) { 600 monitor_printf(mon, " Display: %s\n", info->display); 601 } 602 info2l = info2l->next; 603 } 604 605 qapi_free_VncInfo2List(info2l_head); 606 607 } 608 #endif 609 610 #ifdef CONFIG_SPICE 611 void hmp_info_spice(Monitor *mon, const QDict *qdict) 612 { 613 SpiceChannelList *chan; 614 SpiceInfo *info; 615 const char *channel_name; 616 const char * const channel_names[] = { 617 [SPICE_CHANNEL_MAIN] = "main", 618 [SPICE_CHANNEL_DISPLAY] = "display", 619 [SPICE_CHANNEL_INPUTS] = "inputs", 620 [SPICE_CHANNEL_CURSOR] = "cursor", 621 [SPICE_CHANNEL_PLAYBACK] = "playback", 622 [SPICE_CHANNEL_RECORD] = "record", 623 [SPICE_CHANNEL_TUNNEL] = "tunnel", 624 [SPICE_CHANNEL_SMARTCARD] = "smartcard", 625 [SPICE_CHANNEL_USBREDIR] = "usbredir", 626 [SPICE_CHANNEL_PORT] = "port", 627 #if 0 628 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7, 629 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable 630 * as quick fix for build failures with older versions. */ 631 [SPICE_CHANNEL_WEBDAV] = "webdav", 632 #endif 633 }; 634 635 info = qmp_query_spice(NULL); 636 637 if (!info->enabled) { 638 monitor_printf(mon, "Server: disabled\n"); 639 goto out; 640 } 641 642 monitor_printf(mon, "Server:\n"); 643 if (info->has_port) { 644 monitor_printf(mon, " address: %s:%" PRId64 "\n", 645 info->host, info->port); 646 } 647 if (info->has_tls_port) { 648 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", 649 info->host, info->tls_port); 650 } 651 monitor_printf(mon, " migrated: %s\n", 652 info->migrated ? "true" : "false"); 653 monitor_printf(mon, " auth: %s\n", info->auth); 654 monitor_printf(mon, " compiled: %s\n", info->compiled_version); 655 monitor_printf(mon, " mouse-mode: %s\n", 656 SpiceQueryMouseMode_str(info->mouse_mode)); 657 658 if (!info->has_channels || info->channels == NULL) { 659 monitor_printf(mon, "Channels: none\n"); 660 } else { 661 for (chan = info->channels; chan; chan = chan->next) { 662 monitor_printf(mon, "Channel:\n"); 663 monitor_printf(mon, " address: %s:%s%s\n", 664 chan->value->host, chan->value->port, 665 chan->value->tls ? " [tls]" : ""); 666 monitor_printf(mon, " session: %" PRId64 "\n", 667 chan->value->connection_id); 668 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", 669 chan->value->channel_type, chan->value->channel_id); 670 671 channel_name = "unknown"; 672 if (chan->value->channel_type > 0 && 673 chan->value->channel_type < ARRAY_SIZE(channel_names) && 674 channel_names[chan->value->channel_type]) { 675 channel_name = channel_names[chan->value->channel_type]; 676 } 677 678 monitor_printf(mon, " channel name: %s\n", channel_name); 679 } 680 } 681 682 out: 683 qapi_free_SpiceInfo(info); 684 } 685 #endif 686 687 void hmp_info_balloon(Monitor *mon, const QDict *qdict) 688 { 689 BalloonInfo *info; 690 Error *err = NULL; 691 692 info = qmp_query_balloon(&err); 693 if (err) { 694 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_printf(mon, "%s", 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_irq_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 uint64_t *irq_counts; 796 unsigned int nb_irqs, i; 797 if (k->get_statistics && 798 k->get_statistics(intc, &irq_counts, &nb_irqs)) { 799 if (nb_irqs > 0) { 800 monitor_printf(mon, "IRQ statistics for %s:\n", 801 object_get_typename(obj)); 802 for (i = 0; i < nb_irqs; i++) { 803 if (irq_counts[i] > 0) { 804 monitor_printf(mon, "%2d: %" PRId64 "\n", i, 805 irq_counts[i]); 806 } 807 } 808 } 809 } else { 810 monitor_printf(mon, "IRQ statistics not available for %s.\n", 811 object_get_typename(obj)); 812 } 813 } 814 815 return 0; 816 } 817 818 void hmp_info_irq(Monitor *mon, const QDict *qdict) 819 { 820 object_child_foreach_recursive(object_get_root(), 821 hmp_info_irq_foreach, mon); 822 } 823 824 static int hmp_info_pic_foreach(Object *obj, void *opaque) 825 { 826 InterruptStatsProvider *intc; 827 InterruptStatsProviderClass *k; 828 Monitor *mon = opaque; 829 830 if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) { 831 intc = INTERRUPT_STATS_PROVIDER(obj); 832 k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj); 833 if (k->print_info) { 834 k->print_info(intc, mon); 835 } else { 836 monitor_printf(mon, "Interrupt controller information not available for %s.\n", 837 object_get_typename(obj)); 838 } 839 } 840 841 return 0; 842 } 843 844 void hmp_info_pic(Monitor *mon, const QDict *qdict) 845 { 846 object_child_foreach_recursive(object_get_root(), 847 hmp_info_pic_foreach, mon); 848 } 849 850 static int hmp_info_rdma_foreach(Object *obj, void *opaque) 851 { 852 RdmaProvider *rdma; 853 RdmaProviderClass *k; 854 Monitor *mon = opaque; 855 856 if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) { 857 rdma = RDMA_PROVIDER(obj); 858 k = RDMA_PROVIDER_GET_CLASS(obj); 859 if (k->print_statistics) { 860 k->print_statistics(mon, rdma); 861 } else { 862 monitor_printf(mon, "RDMA statistics not available for %s.\n", 863 object_get_typename(obj)); 864 } 865 } 866 867 return 0; 868 } 869 870 void hmp_info_rdma(Monitor *mon, const QDict *qdict) 871 { 872 object_child_foreach_recursive(object_get_root(), 873 hmp_info_rdma_foreach, mon); 874 } 875 876 void hmp_info_pci(Monitor *mon, const QDict *qdict) 877 { 878 PciInfoList *info_list, *info; 879 Error *err = NULL; 880 881 info_list = qmp_query_pci(&err); 882 if (err) { 883 monitor_printf(mon, "PCI devices not supported\n"); 884 error_free(err); 885 return; 886 } 887 888 for (info = info_list; info; info = info->next) { 889 PciDeviceInfoList *dev; 890 891 for (dev = info->value->devices; dev; dev = dev->next) { 892 hmp_info_pci_device(mon, dev->value); 893 } 894 } 895 896 qapi_free_PciInfoList(info_list); 897 } 898 899 void hmp_info_tpm(Monitor *mon, const QDict *qdict) 900 { 901 TPMInfoList *info_list, *info; 902 Error *err = NULL; 903 unsigned int c = 0; 904 TPMPassthroughOptions *tpo; 905 TPMEmulatorOptions *teo; 906 907 info_list = qmp_query_tpm(&err); 908 if (err) { 909 monitor_printf(mon, "TPM device not supported\n"); 910 error_free(err); 911 return; 912 } 913 914 if (info_list) { 915 monitor_printf(mon, "TPM device:\n"); 916 } 917 918 for (info = info_list; info; info = info->next) { 919 TPMInfo *ti = info->value; 920 monitor_printf(mon, " tpm%d: model=%s\n", 921 c, TpmModel_str(ti->model)); 922 923 monitor_printf(mon, " \\ %s: type=%s", 924 ti->id, TpmTypeOptionsKind_str(ti->options->type)); 925 926 switch (ti->options->type) { 927 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: 928 tpo = ti->options->u.passthrough.data; 929 monitor_printf(mon, "%s%s%s%s", 930 tpo->has_path ? ",path=" : "", 931 tpo->has_path ? tpo->path : "", 932 tpo->has_cancel_path ? ",cancel-path=" : "", 933 tpo->has_cancel_path ? tpo->cancel_path : ""); 934 break; 935 case TPM_TYPE_OPTIONS_KIND_EMULATOR: 936 teo = ti->options->u.emulator.data; 937 monitor_printf(mon, ",chardev=%s", teo->chardev); 938 break; 939 case TPM_TYPE_OPTIONS_KIND__MAX: 940 break; 941 } 942 monitor_printf(mon, "\n"); 943 c++; 944 } 945 qapi_free_TPMInfoList(info_list); 946 } 947 948 void hmp_quit(Monitor *mon, const QDict *qdict) 949 { 950 monitor_suspend(mon); 951 qmp_quit(NULL); 952 } 953 954 void hmp_stop(Monitor *mon, const QDict *qdict) 955 { 956 qmp_stop(NULL); 957 } 958 959 void hmp_sync_profile(Monitor *mon, const QDict *qdict) 960 { 961 const char *op = qdict_get_try_str(qdict, "op"); 962 963 if (op == NULL) { 964 bool on = qsp_is_enabled(); 965 966 monitor_printf(mon, "sync-profile is %s\n", on ? "on" : "off"); 967 return; 968 } 969 if (!strcmp(op, "on")) { 970 qsp_enable(); 971 } else if (!strcmp(op, "off")) { 972 qsp_disable(); 973 } else if (!strcmp(op, "reset")) { 974 qsp_reset(); 975 } else { 976 Error *err = NULL; 977 978 error_setg(&err, QERR_INVALID_PARAMETER, op); 979 hmp_handle_error(mon, err); 980 } 981 } 982 983 void hmp_system_reset(Monitor *mon, const QDict *qdict) 984 { 985 qmp_system_reset(NULL); 986 } 987 988 void hmp_system_powerdown(Monitor *mon, const QDict *qdict) 989 { 990 qmp_system_powerdown(NULL); 991 } 992 993 void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) 994 { 995 Error *err = NULL; 996 997 qmp_x_exit_preconfig(&err); 998 hmp_handle_error(mon, err); 999 } 1000 1001 void hmp_cpu(Monitor *mon, const QDict *qdict) 1002 { 1003 int64_t cpu_index; 1004 1005 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that 1006 use it are converted to the QAPI */ 1007 cpu_index = qdict_get_int(qdict, "index"); 1008 if (monitor_set_cpu(mon, cpu_index) < 0) { 1009 monitor_printf(mon, "invalid CPU index\n"); 1010 } 1011 } 1012 1013 void hmp_memsave(Monitor *mon, const QDict *qdict) 1014 { 1015 uint32_t size = qdict_get_int(qdict, "size"); 1016 const char *filename = qdict_get_str(qdict, "filename"); 1017 uint64_t addr = qdict_get_int(qdict, "val"); 1018 Error *err = NULL; 1019 int cpu_index = monitor_get_cpu_index(mon); 1020 1021 if (cpu_index < 0) { 1022 monitor_printf(mon, "No CPU available\n"); 1023 return; 1024 } 1025 1026 qmp_memsave(addr, size, filename, true, cpu_index, &err); 1027 hmp_handle_error(mon, err); 1028 } 1029 1030 void hmp_pmemsave(Monitor *mon, const QDict *qdict) 1031 { 1032 uint32_t size = qdict_get_int(qdict, "size"); 1033 const char *filename = qdict_get_str(qdict, "filename"); 1034 uint64_t addr = qdict_get_int(qdict, "val"); 1035 Error *err = NULL; 1036 1037 qmp_pmemsave(addr, size, filename, &err); 1038 hmp_handle_error(mon, err); 1039 } 1040 1041 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) 1042 { 1043 const char *chardev = qdict_get_str(qdict, "device"); 1044 const char *data = qdict_get_str(qdict, "data"); 1045 Error *err = NULL; 1046 1047 qmp_ringbuf_write(chardev, data, false, 0, &err); 1048 1049 hmp_handle_error(mon, err); 1050 } 1051 1052 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) 1053 { 1054 uint32_t size = qdict_get_int(qdict, "size"); 1055 const char *chardev = qdict_get_str(qdict, "device"); 1056 char *data; 1057 Error *err = NULL; 1058 int i; 1059 1060 data = qmp_ringbuf_read(chardev, size, false, 0, &err); 1061 if (err) { 1062 hmp_handle_error(mon, err); 1063 return; 1064 } 1065 1066 for (i = 0; data[i]; i++) { 1067 unsigned char ch = data[i]; 1068 1069 if (ch == '\\') { 1070 monitor_printf(mon, "\\\\"); 1071 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { 1072 monitor_printf(mon, "\\u%04X", ch); 1073 } else { 1074 monitor_printf(mon, "%c", ch); 1075 } 1076 1077 } 1078 monitor_printf(mon, "\n"); 1079 g_free(data); 1080 } 1081 1082 void hmp_cont(Monitor *mon, const QDict *qdict) 1083 { 1084 Error *err = NULL; 1085 1086 qmp_cont(&err); 1087 hmp_handle_error(mon, err); 1088 } 1089 1090 void hmp_system_wakeup(Monitor *mon, const QDict *qdict) 1091 { 1092 Error *err = NULL; 1093 1094 qmp_system_wakeup(&err); 1095 hmp_handle_error(mon, err); 1096 } 1097 1098 void hmp_nmi(Monitor *mon, const QDict *qdict) 1099 { 1100 Error *err = NULL; 1101 1102 qmp_inject_nmi(&err); 1103 hmp_handle_error(mon, err); 1104 } 1105 1106 void hmp_set_link(Monitor *mon, const QDict *qdict) 1107 { 1108 const char *name = qdict_get_str(qdict, "name"); 1109 bool up = qdict_get_bool(qdict, "up"); 1110 Error *err = NULL; 1111 1112 qmp_set_link(name, up, &err); 1113 hmp_handle_error(mon, err); 1114 } 1115 1116 void hmp_balloon(Monitor *mon, const QDict *qdict) 1117 { 1118 int64_t value = qdict_get_int(qdict, "value"); 1119 Error *err = NULL; 1120 1121 qmp_balloon(value, &err); 1122 hmp_handle_error(mon, err); 1123 } 1124 1125 void hmp_loadvm(Monitor *mon, const QDict *qdict) 1126 { 1127 int saved_vm_running = runstate_is_running(); 1128 const char *name = qdict_get_str(qdict, "name"); 1129 Error *err = NULL; 1130 1131 vm_stop(RUN_STATE_RESTORE_VM); 1132 1133 if (load_snapshot(name, &err) == 0 && saved_vm_running) { 1134 vm_start(); 1135 } 1136 hmp_handle_error(mon, err); 1137 } 1138 1139 void hmp_savevm(Monitor *mon, const QDict *qdict) 1140 { 1141 Error *err = NULL; 1142 1143 save_snapshot(qdict_get_try_str(qdict, "name"), &err); 1144 hmp_handle_error(mon, err); 1145 } 1146 1147 void hmp_delvm(Monitor *mon, const QDict *qdict) 1148 { 1149 BlockDriverState *bs; 1150 Error *err = NULL; 1151 const char *name = qdict_get_str(qdict, "name"); 1152 1153 if (bdrv_all_delete_snapshot(name, &bs, &err) < 0) { 1154 error_prepend(&err, 1155 "deleting snapshot on device '%s': ", 1156 bdrv_get_device_name(bs)); 1157 } 1158 hmp_handle_error(mon, err); 1159 } 1160 1161 void hmp_announce_self(Monitor *mon, const QDict *qdict) 1162 { 1163 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces"); 1164 const char *id = qdict_get_try_str(qdict, "id"); 1165 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters, 1166 migrate_announce_params()); 1167 1168 qapi_free_strList(params->interfaces); 1169 params->interfaces = strList_from_comma_list(interfaces_str); 1170 params->has_interfaces = params->interfaces != NULL; 1171 params->id = g_strdup(id); 1172 params->has_id = !!params->id; 1173 qmp_announce_self(params, NULL); 1174 qapi_free_AnnounceParameters(params); 1175 } 1176 1177 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) 1178 { 1179 qmp_migrate_cancel(NULL); 1180 } 1181 1182 void hmp_migrate_continue(Monitor *mon, const QDict *qdict) 1183 { 1184 Error *err = NULL; 1185 const char *state = qdict_get_str(qdict, "state"); 1186 int val = qapi_enum_parse(&MigrationStatus_lookup, state, -1, &err); 1187 1188 if (val >= 0) { 1189 qmp_migrate_continue(val, &err); 1190 } 1191 1192 hmp_handle_error(mon, err); 1193 } 1194 1195 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) 1196 { 1197 Error *err = NULL; 1198 const char *uri = qdict_get_str(qdict, "uri"); 1199 1200 qmp_migrate_incoming(uri, &err); 1201 1202 hmp_handle_error(mon, err); 1203 } 1204 1205 void hmp_migrate_recover(Monitor *mon, const QDict *qdict) 1206 { 1207 Error *err = NULL; 1208 const char *uri = qdict_get_str(qdict, "uri"); 1209 1210 qmp_migrate_recover(uri, &err); 1211 1212 hmp_handle_error(mon, err); 1213 } 1214 1215 void hmp_migrate_pause(Monitor *mon, const QDict *qdict) 1216 { 1217 Error *err = NULL; 1218 1219 qmp_migrate_pause(&err); 1220 1221 hmp_handle_error(mon, err); 1222 } 1223 1224 /* Kept for backwards compatibility */ 1225 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) 1226 { 1227 Error *err = NULL; 1228 1229 double value = qdict_get_double(qdict, "value"); 1230 qmp_migrate_set_downtime(value, &err); 1231 hmp_handle_error(mon, err); 1232 } 1233 1234 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) 1235 { 1236 int64_t value = qdict_get_int(qdict, "value"); 1237 Error *err = NULL; 1238 1239 qmp_migrate_set_cache_size(value, &err); 1240 hmp_handle_error(mon, err); 1241 } 1242 1243 /* Kept for backwards compatibility */ 1244 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) 1245 { 1246 Error *err = NULL; 1247 1248 int64_t value = qdict_get_int(qdict, "value"); 1249 qmp_migrate_set_speed(value, &err); 1250 hmp_handle_error(mon, err); 1251 } 1252 1253 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) 1254 { 1255 const char *cap = qdict_get_str(qdict, "capability"); 1256 bool state = qdict_get_bool(qdict, "state"); 1257 Error *err = NULL; 1258 MigrationCapabilityStatusList *caps = NULL; 1259 MigrationCapabilityStatus *value; 1260 int val; 1261 1262 val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err); 1263 if (val < 0) { 1264 goto end; 1265 } 1266 1267 value = g_malloc0(sizeof(*value)); 1268 value->capability = val; 1269 value->state = state; 1270 QAPI_LIST_PREPEND(caps, value); 1271 qmp_migrate_set_capabilities(caps, &err); 1272 qapi_free_MigrationCapabilityStatusList(caps); 1273 1274 end: 1275 hmp_handle_error(mon, err); 1276 } 1277 1278 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) 1279 { 1280 const char *param = qdict_get_str(qdict, "parameter"); 1281 const char *valuestr = qdict_get_str(qdict, "value"); 1282 Visitor *v = string_input_visitor_new(valuestr); 1283 MigrateSetParameters *p = g_new0(MigrateSetParameters, 1); 1284 uint64_t valuebw = 0; 1285 uint64_t cache_size; 1286 Error *err = NULL; 1287 int val, ret; 1288 1289 val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err); 1290 if (val < 0) { 1291 goto cleanup; 1292 } 1293 1294 switch (val) { 1295 case MIGRATION_PARAMETER_COMPRESS_LEVEL: 1296 p->has_compress_level = true; 1297 visit_type_int(v, param, &p->compress_level, &err); 1298 break; 1299 case MIGRATION_PARAMETER_COMPRESS_THREADS: 1300 p->has_compress_threads = true; 1301 visit_type_int(v, param, &p->compress_threads, &err); 1302 break; 1303 case MIGRATION_PARAMETER_COMPRESS_WAIT_THREAD: 1304 p->has_compress_wait_thread = true; 1305 visit_type_bool(v, param, &p->compress_wait_thread, &err); 1306 break; 1307 case MIGRATION_PARAMETER_DECOMPRESS_THREADS: 1308 p->has_decompress_threads = true; 1309 visit_type_int(v, param, &p->decompress_threads, &err); 1310 break; 1311 case MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD: 1312 p->has_throttle_trigger_threshold = true; 1313 visit_type_int(v, param, &p->throttle_trigger_threshold, &err); 1314 break; 1315 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL: 1316 p->has_cpu_throttle_initial = true; 1317 visit_type_int(v, param, &p->cpu_throttle_initial, &err); 1318 break; 1319 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT: 1320 p->has_cpu_throttle_increment = true; 1321 visit_type_int(v, param, &p->cpu_throttle_increment, &err); 1322 break; 1323 case MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW: 1324 p->has_cpu_throttle_tailslow = true; 1325 visit_type_bool(v, param, &p->cpu_throttle_tailslow, &err); 1326 break; 1327 case MIGRATION_PARAMETER_MAX_CPU_THROTTLE: 1328 p->has_max_cpu_throttle = true; 1329 visit_type_int(v, param, &p->max_cpu_throttle, &err); 1330 break; 1331 case MIGRATION_PARAMETER_TLS_CREDS: 1332 p->has_tls_creds = true; 1333 p->tls_creds = g_new0(StrOrNull, 1); 1334 p->tls_creds->type = QTYPE_QSTRING; 1335 visit_type_str(v, param, &p->tls_creds->u.s, &err); 1336 break; 1337 case MIGRATION_PARAMETER_TLS_HOSTNAME: 1338 p->has_tls_hostname = true; 1339 p->tls_hostname = g_new0(StrOrNull, 1); 1340 p->tls_hostname->type = QTYPE_QSTRING; 1341 visit_type_str(v, param, &p->tls_hostname->u.s, &err); 1342 break; 1343 case MIGRATION_PARAMETER_TLS_AUTHZ: 1344 p->has_tls_authz = true; 1345 p->tls_authz = g_new0(StrOrNull, 1); 1346 p->tls_authz->type = QTYPE_QSTRING; 1347 visit_type_str(v, param, &p->tls_authz->u.s, &err); 1348 break; 1349 case MIGRATION_PARAMETER_MAX_BANDWIDTH: 1350 p->has_max_bandwidth = true; 1351 /* 1352 * Can't use visit_type_size() here, because it 1353 * defaults to Bytes rather than Mebibytes. 1354 */ 1355 ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw); 1356 if (ret < 0 || valuebw > INT64_MAX 1357 || (size_t)valuebw != valuebw) { 1358 error_setg(&err, "Invalid size %s", valuestr); 1359 break; 1360 } 1361 p->max_bandwidth = valuebw; 1362 break; 1363 case MIGRATION_PARAMETER_DOWNTIME_LIMIT: 1364 p->has_downtime_limit = true; 1365 visit_type_int(v, param, &p->downtime_limit, &err); 1366 break; 1367 case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY: 1368 p->has_x_checkpoint_delay = true; 1369 visit_type_int(v, param, &p->x_checkpoint_delay, &err); 1370 break; 1371 case MIGRATION_PARAMETER_BLOCK_INCREMENTAL: 1372 p->has_block_incremental = true; 1373 visit_type_bool(v, param, &p->block_incremental, &err); 1374 break; 1375 case MIGRATION_PARAMETER_MULTIFD_CHANNELS: 1376 p->has_multifd_channels = true; 1377 visit_type_int(v, param, &p->multifd_channels, &err); 1378 break; 1379 case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: 1380 p->has_multifd_compression = true; 1381 visit_type_MultiFDCompression(v, param, &p->multifd_compression, 1382 &err); 1383 break; 1384 case MIGRATION_PARAMETER_MULTIFD_ZLIB_LEVEL: 1385 p->has_multifd_zlib_level = true; 1386 visit_type_int(v, param, &p->multifd_zlib_level, &err); 1387 break; 1388 case MIGRATION_PARAMETER_MULTIFD_ZSTD_LEVEL: 1389 p->has_multifd_zstd_level = true; 1390 visit_type_int(v, param, &p->multifd_zstd_level, &err); 1391 break; 1392 case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: 1393 p->has_xbzrle_cache_size = true; 1394 if (!visit_type_size(v, param, &cache_size, &err)) { 1395 break; 1396 } 1397 if (cache_size > INT64_MAX || (size_t)cache_size != cache_size) { 1398 error_setg(&err, "Invalid size %s", valuestr); 1399 break; 1400 } 1401 p->xbzrle_cache_size = cache_size; 1402 break; 1403 case MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH: 1404 p->has_max_postcopy_bandwidth = true; 1405 visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); 1406 break; 1407 case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: 1408 p->has_announce_initial = true; 1409 visit_type_size(v, param, &p->announce_initial, &err); 1410 break; 1411 case MIGRATION_PARAMETER_ANNOUNCE_MAX: 1412 p->has_announce_max = true; 1413 visit_type_size(v, param, &p->announce_max, &err); 1414 break; 1415 case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: 1416 p->has_announce_rounds = true; 1417 visit_type_size(v, param, &p->announce_rounds, &err); 1418 break; 1419 case MIGRATION_PARAMETER_ANNOUNCE_STEP: 1420 p->has_announce_step = true; 1421 visit_type_size(v, param, &p->announce_step, &err); 1422 break; 1423 case MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING: 1424 error_setg(&err, "The block-bitmap-mapping parameter can only be set " 1425 "through QMP"); 1426 break; 1427 default: 1428 assert(0); 1429 } 1430 1431 if (err) { 1432 goto cleanup; 1433 } 1434 1435 qmp_migrate_set_parameters(p, &err); 1436 1437 cleanup: 1438 qapi_free_MigrateSetParameters(p); 1439 visit_free(v); 1440 hmp_handle_error(mon, err); 1441 } 1442 1443 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) 1444 { 1445 Error *err = NULL; 1446 const char *protocol = qdict_get_str(qdict, "protocol"); 1447 const char *hostname = qdict_get_str(qdict, "hostname"); 1448 bool has_port = qdict_haskey(qdict, "port"); 1449 int port = qdict_get_try_int(qdict, "port", -1); 1450 bool has_tls_port = qdict_haskey(qdict, "tls-port"); 1451 int tls_port = qdict_get_try_int(qdict, "tls-port", -1); 1452 const char *cert_subject = qdict_get_try_str(qdict, "cert-subject"); 1453 1454 qmp_client_migrate_info(protocol, hostname, 1455 has_port, port, has_tls_port, tls_port, 1456 !!cert_subject, cert_subject, &err); 1457 hmp_handle_error(mon, err); 1458 } 1459 1460 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) 1461 { 1462 Error *err = NULL; 1463 qmp_migrate_start_postcopy(&err); 1464 hmp_handle_error(mon, err); 1465 } 1466 1467 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) 1468 { 1469 Error *err = NULL; 1470 1471 qmp_x_colo_lost_heartbeat(&err); 1472 hmp_handle_error(mon, err); 1473 } 1474 1475 void hmp_set_password(Monitor *mon, const QDict *qdict) 1476 { 1477 const char *protocol = qdict_get_str(qdict, "protocol"); 1478 const char *password = qdict_get_str(qdict, "password"); 1479 const char *connected = qdict_get_try_str(qdict, "connected"); 1480 Error *err = NULL; 1481 1482 qmp_set_password(protocol, password, !!connected, connected, &err); 1483 hmp_handle_error(mon, err); 1484 } 1485 1486 void hmp_expire_password(Monitor *mon, const QDict *qdict) 1487 { 1488 const char *protocol = qdict_get_str(qdict, "protocol"); 1489 const char *whenstr = qdict_get_str(qdict, "time"); 1490 Error *err = NULL; 1491 1492 qmp_expire_password(protocol, whenstr, &err); 1493 hmp_handle_error(mon, err); 1494 } 1495 1496 1497 #ifdef CONFIG_VNC 1498 static void hmp_change_read_arg(void *opaque, const char *password, 1499 void *readline_opaque) 1500 { 1501 qmp_change_vnc_password(password, NULL); 1502 monitor_read_command(opaque, 1); 1503 } 1504 #endif 1505 1506 void hmp_change(Monitor *mon, const QDict *qdict) 1507 { 1508 const char *device = qdict_get_str(qdict, "device"); 1509 const char *target = qdict_get_str(qdict, "target"); 1510 const char *arg = qdict_get_try_str(qdict, "arg"); 1511 const char *read_only = qdict_get_try_str(qdict, "read-only-mode"); 1512 BlockdevChangeReadOnlyMode read_only_mode = 0; 1513 Error *err = NULL; 1514 1515 #ifdef CONFIG_VNC 1516 if (strcmp(device, "vnc") == 0) { 1517 if (read_only) { 1518 monitor_printf(mon, 1519 "Parameter 'read-only-mode' is invalid for VNC\n"); 1520 return; 1521 } 1522 if (strcmp(target, "passwd") == 0 || 1523 strcmp(target, "password") == 0) { 1524 if (arg) { 1525 MonitorHMP *hmp_mon = container_of(mon, MonitorHMP, common); 1526 monitor_read_password(hmp_mon, hmp_change_read_arg, NULL); 1527 return; 1528 } else { 1529 qmp_change_vnc_password(arg, &err); 1530 } 1531 } else { 1532 monitor_printf(mon, "Expected 'password' after 'vnc'\n"); 1533 } 1534 } else 1535 #endif 1536 { 1537 if (read_only) { 1538 read_only_mode = 1539 qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup, 1540 read_only, 1541 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); 1542 if (err) { 1543 goto end; 1544 } 1545 } 1546 1547 qmp_blockdev_change_medium(true, device, false, NULL, target, 1548 !!arg, arg, !!read_only, read_only_mode, 1549 &err); 1550 } 1551 1552 end: 1553 hmp_handle_error(mon, err); 1554 } 1555 1556 typedef struct HMPMigrationStatus { 1557 QEMUTimer *timer; 1558 Monitor *mon; 1559 bool is_block_migration; 1560 } HMPMigrationStatus; 1561 1562 static void hmp_migrate_status_cb(void *opaque) 1563 { 1564 HMPMigrationStatus *status = opaque; 1565 MigrationInfo *info; 1566 1567 info = qmp_query_migrate(NULL); 1568 if (!info->has_status || info->status == MIGRATION_STATUS_ACTIVE || 1569 info->status == MIGRATION_STATUS_SETUP) { 1570 if (info->has_disk) { 1571 int progress; 1572 1573 if (info->disk->remaining) { 1574 progress = info->disk->transferred * 100 / info->disk->total; 1575 } else { 1576 progress = 100; 1577 } 1578 1579 monitor_printf(status->mon, "Completed %d %%\r", progress); 1580 monitor_flush(status->mon); 1581 } 1582 1583 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000); 1584 } else { 1585 if (status->is_block_migration) { 1586 monitor_printf(status->mon, "\n"); 1587 } 1588 if (info->has_error_desc) { 1589 error_report("%s", info->error_desc); 1590 } 1591 monitor_resume(status->mon); 1592 timer_free(status->timer); 1593 g_free(status); 1594 } 1595 1596 qapi_free_MigrationInfo(info); 1597 } 1598 1599 void hmp_migrate(Monitor *mon, const QDict *qdict) 1600 { 1601 bool detach = qdict_get_try_bool(qdict, "detach", false); 1602 bool blk = qdict_get_try_bool(qdict, "blk", false); 1603 bool inc = qdict_get_try_bool(qdict, "inc", false); 1604 bool resume = qdict_get_try_bool(qdict, "resume", false); 1605 const char *uri = qdict_get_str(qdict, "uri"); 1606 Error *err = NULL; 1607 1608 qmp_migrate(uri, !!blk, blk, !!inc, inc, 1609 false, false, true, resume, &err); 1610 if (err) { 1611 hmp_handle_error(mon, err); 1612 return; 1613 } 1614 1615 if (!detach) { 1616 HMPMigrationStatus *status; 1617 1618 if (monitor_suspend(mon) < 0) { 1619 monitor_printf(mon, "terminal does not allow synchronous " 1620 "migration, continuing detached\n"); 1621 return; 1622 } 1623 1624 status = g_malloc0(sizeof(*status)); 1625 status->mon = mon; 1626 status->is_block_migration = blk || inc; 1627 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb, 1628 status); 1629 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); 1630 } 1631 } 1632 1633 void hmp_netdev_add(Monitor *mon, const QDict *qdict) 1634 { 1635 Error *err = NULL; 1636 QemuOpts *opts; 1637 const char *type = qdict_get_try_str(qdict, "type"); 1638 1639 if (type && is_help_option(type)) { 1640 show_netdevs(); 1641 return; 1642 } 1643 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); 1644 if (err) { 1645 goto out; 1646 } 1647 1648 netdev_add(opts, &err); 1649 if (err) { 1650 qemu_opts_del(opts); 1651 } 1652 1653 out: 1654 hmp_handle_error(mon, err); 1655 } 1656 1657 void hmp_netdev_del(Monitor *mon, const QDict *qdict) 1658 { 1659 const char *id = qdict_get_str(qdict, "id"); 1660 Error *err = NULL; 1661 1662 qmp_netdev_del(id, &err); 1663 hmp_handle_error(mon, err); 1664 } 1665 1666 void hmp_object_add(Monitor *mon, const QDict *qdict) 1667 { 1668 Error *err = NULL; 1669 QemuOpts *opts; 1670 Object *obj = NULL; 1671 1672 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); 1673 if (err) { 1674 goto end; 1675 } 1676 1677 obj = user_creatable_add_opts(opts, &err); 1678 qemu_opts_del(opts); 1679 1680 end: 1681 hmp_handle_error(mon, err); 1682 1683 if (obj) { 1684 object_unref(obj); 1685 } 1686 } 1687 1688 void hmp_getfd(Monitor *mon, const QDict *qdict) 1689 { 1690 const char *fdname = qdict_get_str(qdict, "fdname"); 1691 Error *err = NULL; 1692 1693 qmp_getfd(fdname, &err); 1694 hmp_handle_error(mon, err); 1695 } 1696 1697 void hmp_closefd(Monitor *mon, const QDict *qdict) 1698 { 1699 const char *fdname = qdict_get_str(qdict, "fdname"); 1700 Error *err = NULL; 1701 1702 qmp_closefd(fdname, &err); 1703 hmp_handle_error(mon, err); 1704 } 1705 1706 void hmp_sendkey(Monitor *mon, const QDict *qdict) 1707 { 1708 const char *keys = qdict_get_str(qdict, "keys"); 1709 KeyValue *v = NULL; 1710 KeyValueList *head = NULL, **tail = &head; 1711 int has_hold_time = qdict_haskey(qdict, "hold-time"); 1712 int hold_time = qdict_get_try_int(qdict, "hold-time", -1); 1713 Error *err = NULL; 1714 const char *separator; 1715 int keyname_len; 1716 1717 while (1) { 1718 separator = qemu_strchrnul(keys, '-'); 1719 keyname_len = separator - keys; 1720 1721 /* Be compatible with old interface, convert user inputted "<" */ 1722 if (keys[0] == '<' && keyname_len == 1) { 1723 keys = "less"; 1724 keyname_len = 4; 1725 } 1726 1727 v = g_malloc0(sizeof(*v)); 1728 1729 if (strstart(keys, "0x", NULL)) { 1730 char *endp; 1731 int value = strtoul(keys, &endp, 0); 1732 assert(endp <= keys + keyname_len); 1733 if (endp != keys + keyname_len) { 1734 goto err_out; 1735 } 1736 v->type = KEY_VALUE_KIND_NUMBER; 1737 v->u.number.data = value; 1738 } else { 1739 int idx = index_from_key(keys, keyname_len); 1740 if (idx == Q_KEY_CODE__MAX) { 1741 goto err_out; 1742 } 1743 v->type = KEY_VALUE_KIND_QCODE; 1744 v->u.qcode.data = idx; 1745 } 1746 QAPI_LIST_APPEND(tail, v); 1747 v = NULL; 1748 1749 if (!*separator) { 1750 break; 1751 } 1752 keys = separator + 1; 1753 } 1754 1755 qmp_send_key(head, has_hold_time, hold_time, &err); 1756 hmp_handle_error(mon, err); 1757 1758 out: 1759 qapi_free_KeyValue(v); 1760 qapi_free_KeyValueList(head); 1761 return; 1762 1763 err_out: 1764 monitor_printf(mon, "invalid parameter: %.*s\n", keyname_len, keys); 1765 goto out; 1766 } 1767 1768 void coroutine_fn 1769 hmp_screendump(Monitor *mon, const QDict *qdict) 1770 { 1771 const char *filename = qdict_get_str(qdict, "filename"); 1772 const char *id = qdict_get_try_str(qdict, "device"); 1773 int64_t head = qdict_get_try_int(qdict, "head", 0); 1774 Error *err = NULL; 1775 1776 qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); 1777 hmp_handle_error(mon, err); 1778 } 1779 1780 void hmp_chardev_add(Monitor *mon, const QDict *qdict) 1781 { 1782 const char *args = qdict_get_str(qdict, "args"); 1783 Error *err = NULL; 1784 QemuOpts *opts; 1785 1786 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, true); 1787 if (opts == NULL) { 1788 error_setg(&err, "Parsing chardev args failed"); 1789 } else { 1790 qemu_chr_new_from_opts(opts, NULL, &err); 1791 qemu_opts_del(opts); 1792 } 1793 hmp_handle_error(mon, err); 1794 } 1795 1796 void hmp_chardev_change(Monitor *mon, const QDict *qdict) 1797 { 1798 const char *args = qdict_get_str(qdict, "args"); 1799 const char *id; 1800 Error *err = NULL; 1801 ChardevBackend *backend = NULL; 1802 ChardevReturn *ret = NULL; 1803 QemuOpts *opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"), args, 1804 true); 1805 if (!opts) { 1806 error_setg(&err, "Parsing chardev args failed"); 1807 goto end; 1808 } 1809 1810 id = qdict_get_str(qdict, "id"); 1811 if (qemu_opts_id(opts)) { 1812 error_setg(&err, "Unexpected 'id' parameter"); 1813 goto end; 1814 } 1815 1816 backend = qemu_chr_parse_opts(opts, &err); 1817 if (!backend) { 1818 goto end; 1819 } 1820 1821 ret = qmp_chardev_change(id, backend, &err); 1822 1823 end: 1824 qapi_free_ChardevReturn(ret); 1825 qapi_free_ChardevBackend(backend); 1826 qemu_opts_del(opts); 1827 hmp_handle_error(mon, err); 1828 } 1829 1830 void hmp_chardev_remove(Monitor *mon, const QDict *qdict) 1831 { 1832 Error *local_err = NULL; 1833 1834 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); 1835 hmp_handle_error(mon, local_err); 1836 } 1837 1838 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) 1839 { 1840 Error *local_err = NULL; 1841 1842 qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); 1843 hmp_handle_error(mon, local_err); 1844 } 1845 1846 void hmp_object_del(Monitor *mon, const QDict *qdict) 1847 { 1848 const char *id = qdict_get_str(qdict, "id"); 1849 Error *err = NULL; 1850 1851 user_creatable_del(id, &err); 1852 hmp_handle_error(mon, err); 1853 } 1854 1855 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) 1856 { 1857 Error *err = NULL; 1858 MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); 1859 MemoryDeviceInfoList *info; 1860 VirtioPMEMDeviceInfo *vpi; 1861 VirtioMEMDeviceInfo *vmi; 1862 MemoryDeviceInfo *value; 1863 PCDIMMDeviceInfo *di; 1864 1865 for (info = info_list; info; info = info->next) { 1866 value = info->value; 1867 1868 if (value) { 1869 switch (value->type) { 1870 case MEMORY_DEVICE_INFO_KIND_DIMM: 1871 case MEMORY_DEVICE_INFO_KIND_NVDIMM: 1872 di = value->type == MEMORY_DEVICE_INFO_KIND_DIMM ? 1873 value->u.dimm.data : value->u.nvdimm.data; 1874 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1875 MemoryDeviceInfoKind_str(value->type), 1876 di->id ? di->id : ""); 1877 monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); 1878 monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); 1879 monitor_printf(mon, " node: %" PRId64 "\n", di->node); 1880 monitor_printf(mon, " size: %" PRIu64 "\n", di->size); 1881 monitor_printf(mon, " memdev: %s\n", di->memdev); 1882 monitor_printf(mon, " hotplugged: %s\n", 1883 di->hotplugged ? "true" : "false"); 1884 monitor_printf(mon, " hotpluggable: %s\n", 1885 di->hotpluggable ? "true" : "false"); 1886 break; 1887 case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: 1888 vpi = value->u.virtio_pmem.data; 1889 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1890 MemoryDeviceInfoKind_str(value->type), 1891 vpi->id ? vpi->id : ""); 1892 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr); 1893 monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); 1894 monitor_printf(mon, " memdev: %s\n", vpi->memdev); 1895 break; 1896 case MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM: 1897 vmi = value->u.virtio_mem.data; 1898 monitor_printf(mon, "Memory device [%s]: \"%s\"\n", 1899 MemoryDeviceInfoKind_str(value->type), 1900 vmi->id ? vmi->id : ""); 1901 monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vmi->memaddr); 1902 monitor_printf(mon, " node: %" PRId64 "\n", vmi->node); 1903 monitor_printf(mon, " requested-size: %" PRIu64 "\n", 1904 vmi->requested_size); 1905 monitor_printf(mon, " size: %" PRIu64 "\n", vmi->size); 1906 monitor_printf(mon, " max-size: %" PRIu64 "\n", vmi->max_size); 1907 monitor_printf(mon, " block-size: %" PRIu64 "\n", 1908 vmi->block_size); 1909 monitor_printf(mon, " memdev: %s\n", vmi->memdev); 1910 break; 1911 default: 1912 g_assert_not_reached(); 1913 } 1914 } 1915 } 1916 1917 qapi_free_MemoryDeviceInfoList(info_list); 1918 hmp_handle_error(mon, err); 1919 } 1920 1921 void hmp_info_iothreads(Monitor *mon, const QDict *qdict) 1922 { 1923 IOThreadInfoList *info_list = qmp_query_iothreads(NULL); 1924 IOThreadInfoList *info; 1925 IOThreadInfo *value; 1926 1927 for (info = info_list; info; info = info->next) { 1928 value = info->value; 1929 monitor_printf(mon, "%s:\n", value->id); 1930 monitor_printf(mon, " thread_id=%" PRId64 "\n", value->thread_id); 1931 monitor_printf(mon, " poll-max-ns=%" PRId64 "\n", value->poll_max_ns); 1932 monitor_printf(mon, " poll-grow=%" PRId64 "\n", value->poll_grow); 1933 monitor_printf(mon, " poll-shrink=%" PRId64 "\n", value->poll_shrink); 1934 } 1935 1936 qapi_free_IOThreadInfoList(info_list); 1937 } 1938 1939 void hmp_rocker(Monitor *mon, const QDict *qdict) 1940 { 1941 const char *name = qdict_get_str(qdict, "name"); 1942 RockerSwitch *rocker; 1943 Error *err = NULL; 1944 1945 rocker = qmp_query_rocker(name, &err); 1946 if (err != NULL) { 1947 hmp_handle_error(mon, err); 1948 return; 1949 } 1950 1951 monitor_printf(mon, "name: %s\n", rocker->name); 1952 monitor_printf(mon, "id: 0x%" PRIx64 "\n", rocker->id); 1953 monitor_printf(mon, "ports: %d\n", rocker->ports); 1954 1955 qapi_free_RockerSwitch(rocker); 1956 } 1957 1958 void hmp_rocker_ports(Monitor *mon, const QDict *qdict) 1959 { 1960 RockerPortList *list, *port; 1961 const char *name = qdict_get_str(qdict, "name"); 1962 Error *err = NULL; 1963 1964 list = qmp_query_rocker_ports(name, &err); 1965 if (err != NULL) { 1966 hmp_handle_error(mon, err); 1967 return; 1968 } 1969 1970 monitor_printf(mon, " ena/ speed/ auto\n"); 1971 monitor_printf(mon, " port link duplex neg?\n"); 1972 1973 for (port = list; port; port = port->next) { 1974 monitor_printf(mon, "%10s %-4s %-3s %2s %-3s\n", 1975 port->value->name, 1976 port->value->enabled ? port->value->link_up ? 1977 "up" : "down" : "!ena", 1978 port->value->speed == 10000 ? "10G" : "??", 1979 port->value->duplex ? "FD" : "HD", 1980 port->value->autoneg ? "Yes" : "No"); 1981 } 1982 1983 qapi_free_RockerPortList(list); 1984 } 1985 1986 void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) 1987 { 1988 RockerOfDpaFlowList *list, *info; 1989 const char *name = qdict_get_str(qdict, "name"); 1990 uint32_t tbl_id = qdict_get_try_int(qdict, "tbl_id", -1); 1991 Error *err = NULL; 1992 1993 list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); 1994 if (err != NULL) { 1995 hmp_handle_error(mon, err); 1996 return; 1997 } 1998 1999 monitor_printf(mon, "prio tbl hits key(mask) --> actions\n"); 2000 2001 for (info = list; info; info = info->next) { 2002 RockerOfDpaFlow *flow = info->value; 2003 RockerOfDpaFlowKey *key = flow->key; 2004 RockerOfDpaFlowMask *mask = flow->mask; 2005 RockerOfDpaFlowAction *action = flow->action; 2006 2007 if (flow->hits) { 2008 monitor_printf(mon, "%-4d %-3d %-4" PRIu64, 2009 key->priority, key->tbl_id, flow->hits); 2010 } else { 2011 monitor_printf(mon, "%-4d %-3d ", 2012 key->priority, key->tbl_id); 2013 } 2014 2015 if (key->has_in_pport) { 2016 monitor_printf(mon, " pport %d", key->in_pport); 2017 if (mask->has_in_pport) { 2018 monitor_printf(mon, "(0x%x)", mask->in_pport); 2019 } 2020 } 2021 2022 if (key->has_vlan_id) { 2023 monitor_printf(mon, " vlan %d", 2024 key->vlan_id & VLAN_VID_MASK); 2025 if (mask->has_vlan_id) { 2026 monitor_printf(mon, "(0x%x)", mask->vlan_id); 2027 } 2028 } 2029 2030 if (key->has_tunnel_id) { 2031 monitor_printf(mon, " tunnel %d", key->tunnel_id); 2032 if (mask->has_tunnel_id) { 2033 monitor_printf(mon, "(0x%x)", mask->tunnel_id); 2034 } 2035 } 2036 2037 if (key->has_eth_type) { 2038 switch (key->eth_type) { 2039 case 0x0806: 2040 monitor_printf(mon, " ARP"); 2041 break; 2042 case 0x0800: 2043 monitor_printf(mon, " IP"); 2044 break; 2045 case 0x86dd: 2046 monitor_printf(mon, " IPv6"); 2047 break; 2048 case 0x8809: 2049 monitor_printf(mon, " LACP"); 2050 break; 2051 case 0x88cc: 2052 monitor_printf(mon, " LLDP"); 2053 break; 2054 default: 2055 monitor_printf(mon, " eth type 0x%04x", key->eth_type); 2056 break; 2057 } 2058 } 2059 2060 if (key->has_eth_src) { 2061 if ((strcmp(key->eth_src, "01:00:00:00:00:00") == 0) && 2062 (mask->has_eth_src) && 2063 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 2064 monitor_printf(mon, " src <any mcast/bcast>"); 2065 } else if ((strcmp(key->eth_src, "00:00:00:00:00:00") == 0) && 2066 (mask->has_eth_src) && 2067 (strcmp(mask->eth_src, "01:00:00:00:00:00") == 0)) { 2068 monitor_printf(mon, " src <any ucast>"); 2069 } else { 2070 monitor_printf(mon, " src %s", key->eth_src); 2071 if (mask->has_eth_src) { 2072 monitor_printf(mon, "(%s)", mask->eth_src); 2073 } 2074 } 2075 } 2076 2077 if (key->has_eth_dst) { 2078 if ((strcmp(key->eth_dst, "01:00:00:00:00:00") == 0) && 2079 (mask->has_eth_dst) && 2080 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 2081 monitor_printf(mon, " dst <any mcast/bcast>"); 2082 } else if ((strcmp(key->eth_dst, "00:00:00:00:00:00") == 0) && 2083 (mask->has_eth_dst) && 2084 (strcmp(mask->eth_dst, "01:00:00:00:00:00") == 0)) { 2085 monitor_printf(mon, " dst <any ucast>"); 2086 } else { 2087 monitor_printf(mon, " dst %s", key->eth_dst); 2088 if (mask->has_eth_dst) { 2089 monitor_printf(mon, "(%s)", mask->eth_dst); 2090 } 2091 } 2092 } 2093 2094 if (key->has_ip_proto) { 2095 monitor_printf(mon, " proto %d", key->ip_proto); 2096 if (mask->has_ip_proto) { 2097 monitor_printf(mon, "(0x%x)", mask->ip_proto); 2098 } 2099 } 2100 2101 if (key->has_ip_tos) { 2102 monitor_printf(mon, " TOS %d", key->ip_tos); 2103 if (mask->has_ip_tos) { 2104 monitor_printf(mon, "(0x%x)", mask->ip_tos); 2105 } 2106 } 2107 2108 if (key->has_ip_dst) { 2109 monitor_printf(mon, " dst %s", key->ip_dst); 2110 } 2111 2112 if (action->has_goto_tbl || action->has_group_id || 2113 action->has_new_vlan_id) { 2114 monitor_printf(mon, " -->"); 2115 } 2116 2117 if (action->has_new_vlan_id) { 2118 monitor_printf(mon, " apply new vlan %d", 2119 ntohs(action->new_vlan_id)); 2120 } 2121 2122 if (action->has_group_id) { 2123 monitor_printf(mon, " write group 0x%08x", action->group_id); 2124 } 2125 2126 if (action->has_goto_tbl) { 2127 monitor_printf(mon, " goto tbl %d", action->goto_tbl); 2128 } 2129 2130 monitor_printf(mon, "\n"); 2131 } 2132 2133 qapi_free_RockerOfDpaFlowList(list); 2134 } 2135 2136 void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) 2137 { 2138 RockerOfDpaGroupList *list, *g; 2139 const char *name = qdict_get_str(qdict, "name"); 2140 uint8_t type = qdict_get_try_int(qdict, "type", 9); 2141 Error *err = NULL; 2142 2143 list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); 2144 if (err != NULL) { 2145 hmp_handle_error(mon, err); 2146 return; 2147 } 2148 2149 monitor_printf(mon, "id (decode) --> buckets\n"); 2150 2151 for (g = list; g; g = g->next) { 2152 RockerOfDpaGroup *group = g->value; 2153 bool set = false; 2154 2155 monitor_printf(mon, "0x%08x", group->id); 2156 2157 monitor_printf(mon, " (type %s", group->type == 0 ? "L2 interface" : 2158 group->type == 1 ? "L2 rewrite" : 2159 group->type == 2 ? "L3 unicast" : 2160 group->type == 3 ? "L2 multicast" : 2161 group->type == 4 ? "L2 flood" : 2162 group->type == 5 ? "L3 interface" : 2163 group->type == 6 ? "L3 multicast" : 2164 group->type == 7 ? "L3 ECMP" : 2165 group->type == 8 ? "L2 overlay" : 2166 "unknown"); 2167 2168 if (group->has_vlan_id) { 2169 monitor_printf(mon, " vlan %d", group->vlan_id); 2170 } 2171 2172 if (group->has_pport) { 2173 monitor_printf(mon, " pport %d", group->pport); 2174 } 2175 2176 if (group->has_index) { 2177 monitor_printf(mon, " index %d", group->index); 2178 } 2179 2180 monitor_printf(mon, ") -->"); 2181 2182 if (group->has_set_vlan_id && group->set_vlan_id) { 2183 set = true; 2184 monitor_printf(mon, " set vlan %d", 2185 group->set_vlan_id & VLAN_VID_MASK); 2186 } 2187 2188 if (group->has_set_eth_src) { 2189 if (!set) { 2190 set = true; 2191 monitor_printf(mon, " set"); 2192 } 2193 monitor_printf(mon, " src %s", group->set_eth_src); 2194 } 2195 2196 if (group->has_set_eth_dst) { 2197 if (!set) { 2198 monitor_printf(mon, " set"); 2199 } 2200 monitor_printf(mon, " dst %s", group->set_eth_dst); 2201 } 2202 2203 if (group->has_ttl_check && group->ttl_check) { 2204 monitor_printf(mon, " check TTL"); 2205 } 2206 2207 if (group->has_group_id && group->group_id) { 2208 monitor_printf(mon, " group id 0x%08x", group->group_id); 2209 } 2210 2211 if (group->has_pop_vlan && group->pop_vlan) { 2212 monitor_printf(mon, " pop vlan"); 2213 } 2214 2215 if (group->has_out_pport) { 2216 monitor_printf(mon, " out pport %d", group->out_pport); 2217 } 2218 2219 if (group->has_group_ids) { 2220 struct uint32List *id; 2221 2222 monitor_printf(mon, " groups ["); 2223 for (id = group->group_ids; id; id = id->next) { 2224 monitor_printf(mon, "0x%08x", id->value); 2225 if (id->next) { 2226 monitor_printf(mon, ","); 2227 } 2228 } 2229 monitor_printf(mon, "]"); 2230 } 2231 2232 monitor_printf(mon, "\n"); 2233 } 2234 2235 qapi_free_RockerOfDpaGroupList(list); 2236 } 2237 2238 void hmp_info_ramblock(Monitor *mon, const QDict *qdict) 2239 { 2240 ram_block_dump(mon); 2241 } 2242 2243 void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) 2244 { 2245 Error *err = NULL; 2246 GuidInfo *info = qmp_query_vm_generation_id(&err); 2247 if (info) { 2248 monitor_printf(mon, "%s\n", info->guid); 2249 } 2250 hmp_handle_error(mon, err); 2251 qapi_free_GuidInfo(info); 2252 } 2253 2254 void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) 2255 { 2256 Error *err = NULL; 2257 MemoryInfo *info = qmp_query_memory_size_summary(&err); 2258 if (info) { 2259 monitor_printf(mon, "base memory: %" PRIu64 "\n", 2260 info->base_memory); 2261 2262 if (info->has_plugged_memory) { 2263 monitor_printf(mon, "plugged memory: %" PRIu64 "\n", 2264 info->plugged_memory); 2265 } 2266 2267 qapi_free_MemoryInfo(info); 2268 } 2269 hmp_handle_error(mon, err); 2270 } 2271