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