Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Human Monitor Interface |
| 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 | */ |
| 13 | |
| 14 | #include "hmp.h" |
| 15 | #include "qmp-commands.h" |
| 16 | |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 17 | static void hmp_handle_error(Monitor *mon, Error **errp) |
| 18 | { |
| 19 | if (error_is_set(errp)) { |
| 20 | monitor_printf(mon, "%s\n", error_get_pretty(*errp)); |
| 21 | error_free(*errp); |
| 22 | } |
| 23 | } |
| 24 | |
Anthony Liguori | 48a32be | 2011-09-02 12:34:48 -0500 | [diff] [blame] | 25 | void hmp_info_name(Monitor *mon) |
| 26 | { |
| 27 | NameInfo *info; |
| 28 | |
| 29 | info = qmp_query_name(NULL); |
| 30 | if (info->has_name) { |
| 31 | monitor_printf(mon, "%s\n", info->name); |
| 32 | } |
| 33 | qapi_free_NameInfo(info); |
| 34 | } |
Luiz Capitulino | b9c15f1 | 2011-08-26 17:38:13 -0300 | [diff] [blame] | 35 | |
| 36 | void hmp_info_version(Monitor *mon) |
| 37 | { |
| 38 | VersionInfo *info; |
| 39 | |
| 40 | info = qmp_query_version(NULL); |
| 41 | |
| 42 | monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n", |
| 43 | info->qemu.major, info->qemu.minor, info->qemu.micro, |
| 44 | info->package); |
| 45 | |
| 46 | qapi_free_VersionInfo(info); |
| 47 | } |
Luiz Capitulino | 292a260 | 2011-09-12 15:10:53 -0300 | [diff] [blame] | 48 | |
| 49 | void hmp_info_kvm(Monitor *mon) |
| 50 | { |
| 51 | KvmInfo *info; |
| 52 | |
| 53 | info = qmp_query_kvm(NULL); |
| 54 | monitor_printf(mon, "kvm support: "); |
| 55 | if (info->present) { |
| 56 | monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled"); |
| 57 | } else { |
| 58 | monitor_printf(mon, "not compiled\n"); |
| 59 | } |
| 60 | |
| 61 | qapi_free_KvmInfo(info); |
| 62 | } |
| 63 | |
Luiz Capitulino | 1fa9a5e | 2011-09-12 17:54:20 -0300 | [diff] [blame] | 64 | void hmp_info_status(Monitor *mon) |
| 65 | { |
| 66 | StatusInfo *info; |
| 67 | |
| 68 | info = qmp_query_status(NULL); |
| 69 | |
| 70 | monitor_printf(mon, "VM status: %s%s", |
| 71 | info->running ? "running" : "paused", |
| 72 | info->singlestep ? " (single step mode)" : ""); |
| 73 | |
| 74 | if (!info->running && info->status != RUN_STATE_PAUSED) { |
| 75 | monitor_printf(mon, " (%s)", RunState_lookup[info->status]); |
| 76 | } |
| 77 | |
| 78 | monitor_printf(mon, "\n"); |
| 79 | |
| 80 | qapi_free_StatusInfo(info); |
| 81 | } |
| 82 | |
Luiz Capitulino | efab767 | 2011-09-13 17:16:25 -0300 | [diff] [blame] | 83 | void hmp_info_uuid(Monitor *mon) |
| 84 | { |
| 85 | UuidInfo *info; |
| 86 | |
| 87 | info = qmp_query_uuid(NULL); |
| 88 | monitor_printf(mon, "%s\n", info->UUID); |
| 89 | qapi_free_UuidInfo(info); |
| 90 | } |
Luiz Capitulino | c5a415a | 2011-09-14 16:05:49 -0300 | [diff] [blame] | 91 | |
| 92 | void hmp_info_chardev(Monitor *mon) |
| 93 | { |
| 94 | ChardevInfoList *char_info, *info; |
| 95 | |
| 96 | char_info = qmp_query_chardev(NULL); |
| 97 | for (info = char_info; info; info = info->next) { |
| 98 | monitor_printf(mon, "%s: filename=%s\n", info->value->label, |
| 99 | info->value->filename); |
| 100 | } |
| 101 | |
| 102 | qapi_free_ChardevInfoList(char_info); |
| 103 | } |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 104 | |
Luiz Capitulino | e235cec | 2011-09-21 15:29:55 -0300 | [diff] [blame] | 105 | void hmp_info_mice(Monitor *mon) |
| 106 | { |
| 107 | MouseInfoList *mice_list, *mouse; |
| 108 | |
| 109 | mice_list = qmp_query_mice(NULL); |
| 110 | if (!mice_list) { |
| 111 | monitor_printf(mon, "No mouse devices connected\n"); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | for (mouse = mice_list; mouse; mouse = mouse->next) { |
| 116 | monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n", |
| 117 | mouse->value->current ? '*' : ' ', |
| 118 | mouse->value->index, mouse->value->name, |
| 119 | mouse->value->absolute ? " (absolute)" : ""); |
| 120 | } |
| 121 | |
| 122 | qapi_free_MouseInfoList(mice_list); |
| 123 | } |
| 124 | |
Luiz Capitulino | 791e7c8 | 2011-09-13 17:37:16 -0300 | [diff] [blame] | 125 | void hmp_info_migrate(Monitor *mon) |
| 126 | { |
| 127 | MigrationInfo *info; |
| 128 | |
| 129 | info = qmp_query_migrate(NULL); |
| 130 | |
| 131 | if (info->has_status) { |
| 132 | monitor_printf(mon, "Migration status: %s\n", info->status); |
| 133 | } |
| 134 | |
| 135 | if (info->has_ram) { |
| 136 | monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n", |
| 137 | info->ram->transferred >> 10); |
| 138 | monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n", |
| 139 | info->ram->remaining >> 10); |
| 140 | monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n", |
| 141 | info->ram->total >> 10); |
| 142 | } |
| 143 | |
| 144 | if (info->has_disk) { |
| 145 | monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n", |
| 146 | info->disk->transferred >> 10); |
| 147 | monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n", |
| 148 | info->disk->remaining >> 10); |
| 149 | monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n", |
| 150 | info->disk->total >> 10); |
| 151 | } |
| 152 | |
| 153 | qapi_free_MigrationInfo(info); |
| 154 | } |
| 155 | |
Luiz Capitulino | de0b36b | 2011-09-21 16:38:35 -0300 | [diff] [blame] | 156 | void hmp_info_cpus(Monitor *mon) |
| 157 | { |
| 158 | CpuInfoList *cpu_list, *cpu; |
| 159 | |
| 160 | cpu_list = qmp_query_cpus(NULL); |
| 161 | |
| 162 | for (cpu = cpu_list; cpu; cpu = cpu->next) { |
| 163 | int active = ' '; |
| 164 | |
| 165 | if (cpu->value->CPU == monitor_get_cpu_index()) { |
| 166 | active = '*'; |
| 167 | } |
| 168 | |
| 169 | monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU); |
| 170 | |
| 171 | if (cpu->value->has_pc) { |
| 172 | monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc); |
| 173 | } |
| 174 | if (cpu->value->has_nip) { |
| 175 | monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip); |
| 176 | } |
| 177 | if (cpu->value->has_npc) { |
| 178 | monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc); |
| 179 | monitor_printf(mon, "npc=0x%016" PRIx64, cpu->value->npc); |
| 180 | } |
| 181 | if (cpu->value->has_PC) { |
| 182 | monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC); |
| 183 | } |
| 184 | |
| 185 | if (cpu->value->halted) { |
| 186 | monitor_printf(mon, " (halted)"); |
| 187 | } |
| 188 | |
| 189 | monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id); |
| 190 | } |
| 191 | |
| 192 | qapi_free_CpuInfoList(cpu_list); |
| 193 | } |
| 194 | |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 195 | void hmp_info_block(Monitor *mon) |
| 196 | { |
| 197 | BlockInfoList *block_list, *info; |
| 198 | |
| 199 | block_list = qmp_query_block(NULL); |
| 200 | |
| 201 | for (info = block_list; info; info = info->next) { |
| 202 | monitor_printf(mon, "%s: removable=%d", |
| 203 | info->value->device, info->value->removable); |
| 204 | |
| 205 | if (info->value->removable) { |
| 206 | monitor_printf(mon, " locked=%d", info->value->locked); |
| 207 | monitor_printf(mon, " tray-open=%d", info->value->tray_open); |
| 208 | } |
| 209 | |
| 210 | if (info->value->has_io_status) { |
| 211 | monitor_printf(mon, " io-status=%s", |
| 212 | BlockDeviceIoStatus_lookup[info->value->io_status]); |
| 213 | } |
| 214 | |
| 215 | if (info->value->has_inserted) { |
| 216 | monitor_printf(mon, " file="); |
| 217 | monitor_print_filename(mon, info->value->inserted->file); |
| 218 | |
| 219 | if (info->value->inserted->has_backing_file) { |
| 220 | monitor_printf(mon, " backing_file="); |
| 221 | monitor_print_filename(mon, info->value->inserted->backing_file); |
| 222 | } |
| 223 | monitor_printf(mon, " ro=%d drv=%s encrypted=%d", |
| 224 | info->value->inserted->ro, |
| 225 | info->value->inserted->drv, |
| 226 | info->value->inserted->encrypted); |
Zhi Yong Wu | 727f005 | 2011-11-08 13:00:31 +0800 | [diff] [blame] | 227 | |
| 228 | monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64 |
| 229 | " bps_wr=%" PRId64 " iops=%" PRId64 |
| 230 | " iops_rd=%" PRId64 " iops_wr=%" PRId64, |
| 231 | info->value->inserted->bps, |
| 232 | info->value->inserted->bps_rd, |
| 233 | info->value->inserted->bps_wr, |
| 234 | info->value->inserted->iops, |
| 235 | info->value->inserted->iops_rd, |
| 236 | info->value->inserted->iops_wr); |
Luiz Capitulino | b202381 | 2011-09-21 17:16:47 -0300 | [diff] [blame] | 237 | } else { |
| 238 | monitor_printf(mon, " [not inserted]"); |
| 239 | } |
| 240 | |
| 241 | monitor_printf(mon, "\n"); |
| 242 | } |
| 243 | |
| 244 | qapi_free_BlockInfoList(block_list); |
| 245 | } |
| 246 | |
Luiz Capitulino | f11f57e | 2011-09-22 15:56:36 -0300 | [diff] [blame] | 247 | void hmp_info_blockstats(Monitor *mon) |
| 248 | { |
| 249 | BlockStatsList *stats_list, *stats; |
| 250 | |
| 251 | stats_list = qmp_query_blockstats(NULL); |
| 252 | |
| 253 | for (stats = stats_list; stats; stats = stats->next) { |
| 254 | if (!stats->value->has_device) { |
| 255 | continue; |
| 256 | } |
| 257 | |
| 258 | monitor_printf(mon, "%s:", stats->value->device); |
| 259 | monitor_printf(mon, " rd_bytes=%" PRId64 |
| 260 | " wr_bytes=%" PRId64 |
| 261 | " rd_operations=%" PRId64 |
| 262 | " wr_operations=%" PRId64 |
| 263 | " flush_operations=%" PRId64 |
| 264 | " wr_total_time_ns=%" PRId64 |
| 265 | " rd_total_time_ns=%" PRId64 |
| 266 | " flush_total_time_ns=%" PRId64 |
| 267 | "\n", |
| 268 | stats->value->stats->rd_bytes, |
| 269 | stats->value->stats->wr_bytes, |
| 270 | stats->value->stats->rd_operations, |
| 271 | stats->value->stats->wr_operations, |
| 272 | stats->value->stats->flush_operations, |
| 273 | stats->value->stats->wr_total_time_ns, |
| 274 | stats->value->stats->rd_total_time_ns, |
| 275 | stats->value->stats->flush_total_time_ns); |
| 276 | } |
| 277 | |
| 278 | qapi_free_BlockStatsList(stats_list); |
| 279 | } |
| 280 | |
Luiz Capitulino | 2b54aa8 | 2011-10-17 16:41:22 -0200 | [diff] [blame] | 281 | void hmp_info_vnc(Monitor *mon) |
| 282 | { |
| 283 | VncInfo *info; |
| 284 | Error *err = NULL; |
| 285 | VncClientInfoList *client; |
| 286 | |
| 287 | info = qmp_query_vnc(&err); |
| 288 | if (err) { |
| 289 | monitor_printf(mon, "%s\n", error_get_pretty(err)); |
| 290 | error_free(err); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | if (!info->enabled) { |
| 295 | monitor_printf(mon, "Server: disabled\n"); |
| 296 | goto out; |
| 297 | } |
| 298 | |
| 299 | monitor_printf(mon, "Server:\n"); |
| 300 | if (info->has_host && info->has_service) { |
| 301 | monitor_printf(mon, " address: %s:%s\n", info->host, info->service); |
| 302 | } |
| 303 | if (info->has_auth) { |
| 304 | monitor_printf(mon, " auth: %s\n", info->auth); |
| 305 | } |
| 306 | |
| 307 | if (!info->has_clients || info->clients == NULL) { |
| 308 | monitor_printf(mon, "Client: none\n"); |
| 309 | } else { |
| 310 | for (client = info->clients; client; client = client->next) { |
| 311 | monitor_printf(mon, "Client:\n"); |
| 312 | monitor_printf(mon, " address: %s:%s\n", |
| 313 | client->value->host, client->value->service); |
| 314 | monitor_printf(mon, " x509_dname: %s\n", |
| 315 | client->value->x509_dname ? |
| 316 | client->value->x509_dname : "none"); |
| 317 | monitor_printf(mon, " username: %s\n", |
| 318 | client->value->has_sasl_username ? |
| 319 | client->value->sasl_username : "none"); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | out: |
| 324 | qapi_free_VncInfo(info); |
| 325 | } |
| 326 | |
Luiz Capitulino | d1f2964 | 2011-10-20 17:01:33 -0200 | [diff] [blame] | 327 | void hmp_info_spice(Monitor *mon) |
| 328 | { |
| 329 | SpiceChannelList *chan; |
| 330 | SpiceInfo *info; |
| 331 | |
| 332 | info = qmp_query_spice(NULL); |
| 333 | |
| 334 | if (!info->enabled) { |
| 335 | monitor_printf(mon, "Server: disabled\n"); |
| 336 | goto out; |
| 337 | } |
| 338 | |
| 339 | monitor_printf(mon, "Server:\n"); |
| 340 | if (info->has_port) { |
| 341 | monitor_printf(mon, " address: %s:%" PRId64 "\n", |
| 342 | info->host, info->port); |
| 343 | } |
| 344 | if (info->has_tls_port) { |
| 345 | monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n", |
| 346 | info->host, info->tls_port); |
| 347 | } |
| 348 | monitor_printf(mon, " auth: %s\n", info->auth); |
| 349 | monitor_printf(mon, " compiled: %s\n", info->compiled_version); |
| 350 | |
| 351 | if (!info->has_channels || info->channels == NULL) { |
| 352 | monitor_printf(mon, "Channels: none\n"); |
| 353 | } else { |
| 354 | for (chan = info->channels; chan; chan = chan->next) { |
| 355 | monitor_printf(mon, "Channel:\n"); |
| 356 | monitor_printf(mon, " address: %s:%s%s\n", |
| 357 | chan->value->host, chan->value->port, |
| 358 | chan->value->tls ? " [tls]" : ""); |
| 359 | monitor_printf(mon, " session: %" PRId64 "\n", |
| 360 | chan->value->connection_id); |
| 361 | monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n", |
| 362 | chan->value->channel_type, chan->value->channel_id); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | out: |
| 367 | qapi_free_SpiceInfo(info); |
| 368 | } |
| 369 | |
Luiz Capitulino | 96637bc | 2011-10-21 11:41:37 -0200 | [diff] [blame] | 370 | void hmp_info_balloon(Monitor *mon) |
| 371 | { |
| 372 | BalloonInfo *info; |
| 373 | Error *err = NULL; |
| 374 | |
| 375 | info = qmp_query_balloon(&err); |
| 376 | if (err) { |
| 377 | monitor_printf(mon, "%s\n", error_get_pretty(err)); |
| 378 | error_free(err); |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20); |
| 383 | if (info->has_mem_swapped_in) { |
| 384 | monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in); |
| 385 | } |
| 386 | if (info->has_mem_swapped_out) { |
| 387 | monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out); |
| 388 | } |
| 389 | if (info->has_major_page_faults) { |
| 390 | monitor_printf(mon, " major_page_faults=%" PRId64, |
| 391 | info->major_page_faults); |
| 392 | } |
| 393 | if (info->has_minor_page_faults) { |
| 394 | monitor_printf(mon, " minor_page_faults=%" PRId64, |
| 395 | info->minor_page_faults); |
| 396 | } |
| 397 | if (info->has_free_mem) { |
| 398 | monitor_printf(mon, " free_mem=%" PRId64, info->free_mem); |
| 399 | } |
| 400 | if (info->has_total_mem) { |
| 401 | monitor_printf(mon, " total_mem=%" PRId64, info->total_mem); |
| 402 | } |
| 403 | |
| 404 | monitor_printf(mon, "\n"); |
| 405 | |
| 406 | qapi_free_BalloonInfo(info); |
| 407 | } |
| 408 | |
Luiz Capitulino | 7962747 | 2011-10-21 14:15:33 -0200 | [diff] [blame] | 409 | static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) |
| 410 | { |
| 411 | PciMemoryRegionList *region; |
| 412 | |
| 413 | monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus); |
| 414 | monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n", |
| 415 | dev->slot, dev->function); |
| 416 | monitor_printf(mon, " "); |
| 417 | |
| 418 | if (dev->class_info.has_desc) { |
| 419 | monitor_printf(mon, "%s", dev->class_info.desc); |
| 420 | } else { |
| 421 | monitor_printf(mon, "Class %04" PRId64, dev->class_info.class); |
| 422 | } |
| 423 | |
| 424 | monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n", |
| 425 | dev->id.vendor, dev->id.device); |
| 426 | |
| 427 | if (dev->has_irq) { |
| 428 | monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq); |
| 429 | } |
| 430 | |
| 431 | if (dev->has_pci_bridge) { |
| 432 | monitor_printf(mon, " BUS %" PRId64 ".\n", |
| 433 | dev->pci_bridge->bus.number); |
| 434 | monitor_printf(mon, " secondary bus %" PRId64 ".\n", |
| 435 | dev->pci_bridge->bus.secondary); |
| 436 | monitor_printf(mon, " subordinate bus %" PRId64 ".\n", |
| 437 | dev->pci_bridge->bus.subordinate); |
| 438 | |
| 439 | monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n", |
| 440 | dev->pci_bridge->bus.io_range->base, |
| 441 | dev->pci_bridge->bus.io_range->limit); |
| 442 | |
| 443 | monitor_printf(mon, |
| 444 | " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n", |
| 445 | dev->pci_bridge->bus.memory_range->base, |
| 446 | dev->pci_bridge->bus.memory_range->limit); |
| 447 | |
| 448 | monitor_printf(mon, " prefetchable memory range " |
| 449 | "[0x%08"PRIx64", 0x%08"PRIx64"]\n", |
| 450 | dev->pci_bridge->bus.prefetchable_range->base, |
| 451 | dev->pci_bridge->bus.prefetchable_range->limit); |
| 452 | } |
| 453 | |
| 454 | for (region = dev->regions; region; region = region->next) { |
| 455 | uint64_t addr, size; |
| 456 | |
| 457 | addr = region->value->address; |
| 458 | size = region->value->size; |
| 459 | |
| 460 | monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar); |
| 461 | |
| 462 | if (!strcmp(region->value->type, "io")) { |
| 463 | monitor_printf(mon, "I/O at 0x%04" PRIx64 |
| 464 | " [0x%04" PRIx64 "].\n", |
| 465 | addr, addr + size - 1); |
| 466 | } else { |
| 467 | monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64 |
| 468 | " [0x%08" PRIx64 "].\n", |
| 469 | region->value->mem_type_64 ? 64 : 32, |
| 470 | region->value->prefetch ? " prefetchable" : "", |
| 471 | addr, addr + size - 1); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | monitor_printf(mon, " id \"%s\"\n", dev->qdev_id); |
| 476 | |
| 477 | if (dev->has_pci_bridge) { |
| 478 | if (dev->pci_bridge->has_devices) { |
| 479 | PciDeviceInfoList *cdev; |
| 480 | for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) { |
| 481 | hmp_info_pci_device(mon, cdev->value); |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | void hmp_info_pci(Monitor *mon) |
| 488 | { |
| 489 | PciInfoList *info; |
| 490 | Error *err = NULL; |
| 491 | |
| 492 | info = qmp_query_pci(&err); |
| 493 | if (err) { |
| 494 | monitor_printf(mon, "PCI devices not supported\n"); |
| 495 | error_free(err); |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | for (; info; info = info->next) { |
| 500 | PciDeviceInfoList *dev; |
| 501 | |
| 502 | for (dev = info->value->devices; dev; dev = dev->next) { |
| 503 | hmp_info_pci_device(mon, dev->value); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | qapi_free_PciInfoList(info); |
| 508 | } |
| 509 | |
Luiz Capitulino | 7a7f325 | 2011-09-15 14:20:28 -0300 | [diff] [blame] | 510 | void hmp_quit(Monitor *mon, const QDict *qdict) |
| 511 | { |
| 512 | monitor_suspend(mon); |
| 513 | qmp_quit(NULL); |
| 514 | } |
Luiz Capitulino | 5f158f2 | 2011-09-15 14:34:39 -0300 | [diff] [blame] | 515 | |
| 516 | void hmp_stop(Monitor *mon, const QDict *qdict) |
| 517 | { |
| 518 | qmp_stop(NULL); |
| 519 | } |
Luiz Capitulino | 38d2265 | 2011-09-15 14:41:46 -0300 | [diff] [blame] | 520 | |
| 521 | void hmp_system_reset(Monitor *mon, const QDict *qdict) |
| 522 | { |
| 523 | qmp_system_reset(NULL); |
| 524 | } |
Luiz Capitulino | 5bc465e | 2011-09-28 11:06:15 -0300 | [diff] [blame] | 525 | |
| 526 | void hmp_system_powerdown(Monitor *mon, const QDict *qdict) |
| 527 | { |
| 528 | qmp_system_powerdown(NULL); |
| 529 | } |
Luiz Capitulino | 755f196 | 2011-10-06 14:31:39 -0300 | [diff] [blame] | 530 | |
| 531 | void hmp_cpu(Monitor *mon, const QDict *qdict) |
| 532 | { |
| 533 | int64_t cpu_index; |
| 534 | |
| 535 | /* XXX: drop the monitor_set_cpu() usage when all HMP commands that |
| 536 | use it are converted to the QAPI */ |
| 537 | cpu_index = qdict_get_int(qdict, "index"); |
| 538 | if (monitor_set_cpu(cpu_index) < 0) { |
| 539 | monitor_printf(mon, "invalid CPU index\n"); |
| 540 | } |
| 541 | } |
Luiz Capitulino | 0cfd6a9 | 2011-11-22 16:32:37 -0200 | [diff] [blame] | 542 | |
| 543 | void hmp_memsave(Monitor *mon, const QDict *qdict) |
| 544 | { |
| 545 | uint32_t size = qdict_get_int(qdict, "size"); |
| 546 | const char *filename = qdict_get_str(qdict, "filename"); |
| 547 | uint64_t addr = qdict_get_int(qdict, "val"); |
| 548 | Error *errp = NULL; |
| 549 | |
| 550 | qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp); |
| 551 | hmp_handle_error(mon, &errp); |
| 552 | } |
Luiz Capitulino | 6d3962b | 2011-11-22 17:26:46 -0200 | [diff] [blame] | 553 | |
| 554 | void hmp_pmemsave(Monitor *mon, const QDict *qdict) |
| 555 | { |
| 556 | uint32_t size = qdict_get_int(qdict, "size"); |
| 557 | const char *filename = qdict_get_str(qdict, "filename"); |
| 558 | uint64_t addr = qdict_get_int(qdict, "val"); |
| 559 | Error *errp = NULL; |
| 560 | |
| 561 | qmp_pmemsave(addr, size, filename, &errp); |
| 562 | hmp_handle_error(mon, &errp); |
| 563 | } |
Luiz Capitulino | e42e818 | 2011-11-22 17:58:31 -0200 | [diff] [blame] | 564 | |
| 565 | static void hmp_cont_cb(void *opaque, int err) |
| 566 | { |
| 567 | Monitor *mon = opaque; |
| 568 | |
| 569 | if (!err) { |
| 570 | hmp_cont(mon, NULL); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | void hmp_cont(Monitor *mon, const QDict *qdict) |
| 575 | { |
| 576 | Error *errp = NULL; |
| 577 | |
| 578 | qmp_cont(&errp); |
| 579 | if (error_is_set(&errp)) { |
| 580 | if (error_is_type(errp, QERR_DEVICE_ENCRYPTED)) { |
| 581 | const char *device; |
| 582 | |
| 583 | /* The device is encrypted. Ask the user for the password |
| 584 | and retry */ |
| 585 | |
| 586 | device = error_get_field(errp, "device"); |
| 587 | assert(device != NULL); |
| 588 | |
| 589 | monitor_read_block_device_key(mon, device, hmp_cont_cb, mon); |
| 590 | error_free(errp); |
| 591 | return; |
| 592 | } |
| 593 | hmp_handle_error(mon, &errp); |
| 594 | } |
| 595 | } |
Luiz Capitulino | ab49ab5 | 2011-11-23 12:55:53 -0200 | [diff] [blame] | 596 | |
| 597 | void hmp_inject_nmi(Monitor *mon, const QDict *qdict) |
| 598 | { |
| 599 | Error *errp = NULL; |
| 600 | |
| 601 | qmp_inject_nmi(&errp); |
| 602 | hmp_handle_error(mon, &errp); |
| 603 | } |
Luiz Capitulino | 4b37156 | 2011-11-23 13:11:55 -0200 | [diff] [blame] | 604 | |
| 605 | void hmp_set_link(Monitor *mon, const QDict *qdict) |
| 606 | { |
| 607 | const char *name = qdict_get_str(qdict, "name"); |
| 608 | int up = qdict_get_bool(qdict, "up"); |
| 609 | Error *errp = NULL; |
| 610 | |
| 611 | qmp_set_link(name, up, &errp); |
| 612 | hmp_handle_error(mon, &errp); |
| 613 | } |
Luiz Capitulino | a4dea8a | 2011-11-23 13:28:21 -0200 | [diff] [blame] | 614 | |
| 615 | void hmp_block_passwd(Monitor *mon, const QDict *qdict) |
| 616 | { |
| 617 | const char *device = qdict_get_str(qdict, "device"); |
| 618 | const char *password = qdict_get_str(qdict, "password"); |
| 619 | Error *errp = NULL; |
| 620 | |
| 621 | qmp_block_passwd(device, password, &errp); |
| 622 | hmp_handle_error(mon, &errp); |
| 623 | } |
Luiz Capitulino | d72f326 | 2011-11-25 14:38:09 -0200 | [diff] [blame] | 624 | |
| 625 | void hmp_balloon(Monitor *mon, const QDict *qdict) |
| 626 | { |
| 627 | int64_t value = qdict_get_int(qdict, "value"); |
| 628 | Error *errp = NULL; |
| 629 | |
| 630 | qmp_balloon(value, &errp); |
| 631 | if (error_is_set(&errp)) { |
| 632 | monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp)); |
| 633 | error_free(errp); |
| 634 | } |
| 635 | } |
Luiz Capitulino | 5e7caac | 2011-11-25 14:57:10 -0200 | [diff] [blame] | 636 | |
| 637 | void hmp_block_resize(Monitor *mon, const QDict *qdict) |
| 638 | { |
| 639 | const char *device = qdict_get_str(qdict, "device"); |
| 640 | int64_t size = qdict_get_int(qdict, "size"); |
| 641 | Error *errp = NULL; |
| 642 | |
| 643 | qmp_block_resize(device, size, &errp); |
| 644 | hmp_handle_error(mon, &errp); |
| 645 | } |
Luiz Capitulino | 6106e24 | 2011-11-25 16:15:19 -0200 | [diff] [blame] | 646 | |
| 647 | void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) |
| 648 | { |
| 649 | const char *device = qdict_get_str(qdict, "device"); |
| 650 | const char *filename = qdict_get_try_str(qdict, "snapshot-file"); |
| 651 | const char *format = qdict_get_try_str(qdict, "format"); |
| 652 | Error *errp = NULL; |
| 653 | |
| 654 | if (!filename) { |
| 655 | /* In the future, if 'snapshot-file' is not specified, the snapshot |
| 656 | will be taken internally. Today it's actually required. */ |
| 657 | error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file"); |
| 658 | hmp_handle_error(mon, &errp); |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | qmp_blockdev_snapshot_sync(device, filename, !!format, format, &errp); |
| 663 | hmp_handle_error(mon, &errp); |
| 664 | } |
Luiz Capitulino | 6cdedb0 | 2011-11-27 22:54:09 -0200 | [diff] [blame] | 665 | |
| 666 | void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) |
| 667 | { |
| 668 | qmp_migrate_cancel(NULL); |
| 669 | } |
Luiz Capitulino | 4f0a993 | 2011-11-27 23:18:01 -0200 | [diff] [blame] | 670 | |
| 671 | void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict) |
| 672 | { |
| 673 | double value = qdict_get_double(qdict, "value"); |
| 674 | qmp_migrate_set_downtime(value, NULL); |
| 675 | } |
Luiz Capitulino | 3dc8538 | 2011-11-28 11:59:37 -0200 | [diff] [blame] | 676 | |
| 677 | void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict) |
| 678 | { |
| 679 | int64_t value = qdict_get_int(qdict, "value"); |
| 680 | qmp_migrate_set_speed(value, NULL); |
| 681 | } |