migration: expose the bitmap_sync_count to the end
[qemu/cris-port.git] / hmp.c
blob69a70e473bb27ef05bae73cf548ecc895208c6a8
1 /*
2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
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.
16 #include "hmp.h"
17 #include "net/net.h"
18 #include "sysemu/char.h"
19 #include "qemu/option.h"
20 #include "qemu/timer.h"
21 #include "qmp-commands.h"
22 #include "qemu/sockets.h"
23 #include "monitor/monitor.h"
24 #include "qapi/opts-visitor.h"
25 #include "ui/console.h"
26 #include "block/qapi.h"
27 #include "qemu-io.h"
29 static void hmp_handle_error(Monitor *mon, Error **errp)
31 if (error_is_set(errp)) {
32 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
33 error_free(*errp);
37 void hmp_info_name(Monitor *mon, const QDict *qdict)
39 NameInfo *info;
41 info = qmp_query_name(NULL);
42 if (info->has_name) {
43 monitor_printf(mon, "%s\n", info->name);
45 qapi_free_NameInfo(info);
48 void hmp_info_version(Monitor *mon, const QDict *qdict)
50 VersionInfo *info;
52 info = qmp_query_version(NULL);
54 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
55 info->qemu.major, info->qemu.minor, info->qemu.micro,
56 info->package);
58 qapi_free_VersionInfo(info);
61 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
63 KvmInfo *info;
65 info = qmp_query_kvm(NULL);
66 monitor_printf(mon, "kvm support: ");
67 if (info->present) {
68 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
69 } else {
70 monitor_printf(mon, "not compiled\n");
73 qapi_free_KvmInfo(info);
76 void hmp_info_status(Monitor *mon, const QDict *qdict)
78 StatusInfo *info;
80 info = qmp_query_status(NULL);
82 monitor_printf(mon, "VM status: %s%s",
83 info->running ? "running" : "paused",
84 info->singlestep ? " (single step mode)" : "");
86 if (!info->running && info->status != RUN_STATE_PAUSED) {
87 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
90 monitor_printf(mon, "\n");
92 qapi_free_StatusInfo(info);
95 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
97 UuidInfo *info;
99 info = qmp_query_uuid(NULL);
100 monitor_printf(mon, "%s\n", info->UUID);
101 qapi_free_UuidInfo(info);
104 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
106 ChardevInfoList *char_info, *info;
108 char_info = qmp_query_chardev(NULL);
109 for (info = char_info; info; info = info->next) {
110 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
111 info->value->filename);
114 qapi_free_ChardevInfoList(char_info);
117 void hmp_info_mice(Monitor *mon, const QDict *qdict)
119 MouseInfoList *mice_list, *mouse;
121 mice_list = qmp_query_mice(NULL);
122 if (!mice_list) {
123 monitor_printf(mon, "No mouse devices connected\n");
124 return;
127 for (mouse = mice_list; mouse; mouse = mouse->next) {
128 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
129 mouse->value->current ? '*' : ' ',
130 mouse->value->index, mouse->value->name,
131 mouse->value->absolute ? " (absolute)" : "");
134 qapi_free_MouseInfoList(mice_list);
137 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
139 MigrationInfo *info;
140 MigrationCapabilityStatusList *caps, *cap;
142 info = qmp_query_migrate(NULL);
143 caps = qmp_query_migrate_capabilities(NULL);
145 /* do not display parameters during setup */
146 if (info->has_status && caps) {
147 monitor_printf(mon, "capabilities: ");
148 for (cap = caps; cap; cap = cap->next) {
149 monitor_printf(mon, "%s: %s ",
150 MigrationCapability_lookup[cap->value->capability],
151 cap->value->state ? "on" : "off");
153 monitor_printf(mon, "\n");
156 if (info->has_status) {
157 monitor_printf(mon, "Migration status: %s\n", info->status);
158 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
159 info->total_time);
160 if (info->has_expected_downtime) {
161 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
162 info->expected_downtime);
164 if (info->has_downtime) {
165 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
166 info->downtime);
168 if (info->has_setup_time) {
169 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
170 info->setup_time);
174 if (info->has_ram) {
175 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
176 info->ram->transferred >> 10);
177 monitor_printf(mon, "throughput: %0.2f mbps\n",
178 info->ram->mbps);
179 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
180 info->ram->remaining >> 10);
181 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
182 info->ram->total >> 10);
183 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
184 info->ram->duplicate);
185 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
186 info->ram->skipped);
187 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
188 info->ram->normal);
189 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
190 info->ram->normal_bytes >> 10);
191 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
192 info->ram->dirty_sync_count);
193 if (info->ram->dirty_pages_rate) {
194 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
195 info->ram->dirty_pages_rate);
199 if (info->has_disk) {
200 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
201 info->disk->transferred >> 10);
202 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
203 info->disk->remaining >> 10);
204 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
205 info->disk->total >> 10);
208 if (info->has_xbzrle_cache) {
209 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
210 info->xbzrle_cache->cache_size);
211 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
212 info->xbzrle_cache->bytes >> 10);
213 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
214 info->xbzrle_cache->pages);
215 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
216 info->xbzrle_cache->cache_miss);
217 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
218 info->xbzrle_cache->overflow);
221 qapi_free_MigrationInfo(info);
222 qapi_free_MigrationCapabilityStatusList(caps);
225 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
227 MigrationCapabilityStatusList *caps, *cap;
229 caps = qmp_query_migrate_capabilities(NULL);
231 if (caps) {
232 monitor_printf(mon, "capabilities: ");
233 for (cap = caps; cap; cap = cap->next) {
234 monitor_printf(mon, "%s: %s ",
235 MigrationCapability_lookup[cap->value->capability],
236 cap->value->state ? "on" : "off");
238 monitor_printf(mon, "\n");
241 qapi_free_MigrationCapabilityStatusList(caps);
244 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
246 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
247 qmp_query_migrate_cache_size(NULL) >> 10);
250 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
252 CpuInfoList *cpu_list, *cpu;
254 cpu_list = qmp_query_cpus(NULL);
256 for (cpu = cpu_list; cpu; cpu = cpu->next) {
257 int active = ' ';
259 if (cpu->value->CPU == monitor_get_cpu_index()) {
260 active = '*';
263 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
265 if (cpu->value->has_pc) {
266 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
268 if (cpu->value->has_nip) {
269 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
271 if (cpu->value->has_npc) {
272 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
274 if (cpu->value->has_PC) {
275 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
278 if (cpu->value->halted) {
279 monitor_printf(mon, " (halted)");
282 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
285 qapi_free_CpuInfoList(cpu_list);
288 void hmp_info_block(Monitor *mon, const QDict *qdict)
290 BlockInfoList *block_list, *info;
291 ImageInfo *image_info;
292 const char *device = qdict_get_try_str(qdict, "device");
293 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
295 block_list = qmp_query_block(NULL);
297 for (info = block_list; info; info = info->next) {
298 if (device && strcmp(device, info->value->device)) {
299 continue;
302 if (info != block_list) {
303 monitor_printf(mon, "\n");
306 monitor_printf(mon, "%s", info->value->device);
307 if (info->value->has_inserted) {
308 monitor_printf(mon, ": %s (%s%s%s)\n",
309 info->value->inserted->file,
310 info->value->inserted->drv,
311 info->value->inserted->ro ? ", read-only" : "",
312 info->value->inserted->encrypted ? ", encrypted" : "");
313 } else {
314 monitor_printf(mon, ": [not inserted]\n");
317 if (info->value->has_io_status && info->value->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
318 monitor_printf(mon, " I/O status: %s\n",
319 BlockDeviceIoStatus_lookup[info->value->io_status]);
322 if (info->value->removable) {
323 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
324 info->value->locked ? "" : "not ",
325 info->value->tray_open ? "open" : "closed");
329 if (!info->value->has_inserted) {
330 continue;
333 if (info->value->inserted->has_backing_file) {
334 monitor_printf(mon,
335 " Backing file: %s "
336 "(chain depth: %" PRId64 ")\n",
337 info->value->inserted->backing_file,
338 info->value->inserted->backing_file_depth);
341 if (info->value->inserted->bps
342 || info->value->inserted->bps_rd
343 || info->value->inserted->bps_wr
344 || info->value->inserted->iops
345 || info->value->inserted->iops_rd
346 || info->value->inserted->iops_wr)
348 monitor_printf(mon, " I/O throttling: bps=%" PRId64
349 " bps_rd=%" PRId64 " bps_wr=%" PRId64
350 " bps_max=%" PRId64
351 " bps_rd_max=%" PRId64
352 " bps_wr_max=%" PRId64
353 " iops=%" PRId64 " iops_rd=%" PRId64
354 " iops_wr=%" PRId64
355 " iops_max=%" PRId64
356 " iops_rd_max=%" PRId64
357 " iops_wr_max=%" PRId64
358 " iops_size=%" PRId64 "\n",
359 info->value->inserted->bps,
360 info->value->inserted->bps_rd,
361 info->value->inserted->bps_wr,
362 info->value->inserted->bps_max,
363 info->value->inserted->bps_rd_max,
364 info->value->inserted->bps_wr_max,
365 info->value->inserted->iops,
366 info->value->inserted->iops_rd,
367 info->value->inserted->iops_wr,
368 info->value->inserted->iops_max,
369 info->value->inserted->iops_rd_max,
370 info->value->inserted->iops_wr_max,
371 info->value->inserted->iops_size);
374 if (verbose) {
375 monitor_printf(mon, "\nImages:\n");
376 image_info = info->value->inserted->image;
377 while (1) {
378 bdrv_image_info_dump((fprintf_function)monitor_printf,
379 mon, image_info);
380 if (image_info->has_backing_image) {
381 image_info = image_info->backing_image;
382 } else {
383 break;
389 qapi_free_BlockInfoList(block_list);
392 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
394 BlockStatsList *stats_list, *stats;
396 stats_list = qmp_query_blockstats(NULL);
398 for (stats = stats_list; stats; stats = stats->next) {
399 if (!stats->value->has_device) {
400 continue;
403 monitor_printf(mon, "%s:", stats->value->device);
404 monitor_printf(mon, " rd_bytes=%" PRId64
405 " wr_bytes=%" PRId64
406 " rd_operations=%" PRId64
407 " wr_operations=%" PRId64
408 " flush_operations=%" PRId64
409 " wr_total_time_ns=%" PRId64
410 " rd_total_time_ns=%" PRId64
411 " flush_total_time_ns=%" PRId64
412 "\n",
413 stats->value->stats->rd_bytes,
414 stats->value->stats->wr_bytes,
415 stats->value->stats->rd_operations,
416 stats->value->stats->wr_operations,
417 stats->value->stats->flush_operations,
418 stats->value->stats->wr_total_time_ns,
419 stats->value->stats->rd_total_time_ns,
420 stats->value->stats->flush_total_time_ns);
423 qapi_free_BlockStatsList(stats_list);
426 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
428 VncInfo *info;
429 Error *err = NULL;
430 VncClientInfoList *client;
432 info = qmp_query_vnc(&err);
433 if (err) {
434 monitor_printf(mon, "%s\n", error_get_pretty(err));
435 error_free(err);
436 return;
439 if (!info->enabled) {
440 monitor_printf(mon, "Server: disabled\n");
441 goto out;
444 monitor_printf(mon, "Server:\n");
445 if (info->has_host && info->has_service) {
446 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
448 if (info->has_auth) {
449 monitor_printf(mon, " auth: %s\n", info->auth);
452 if (!info->has_clients || info->clients == NULL) {
453 monitor_printf(mon, "Client: none\n");
454 } else {
455 for (client = info->clients; client; client = client->next) {
456 monitor_printf(mon, "Client:\n");
457 monitor_printf(mon, " address: %s:%s\n",
458 client->value->host, client->value->service);
459 monitor_printf(mon, " x509_dname: %s\n",
460 client->value->x509_dname ?
461 client->value->x509_dname : "none");
462 monitor_printf(mon, " username: %s\n",
463 client->value->has_sasl_username ?
464 client->value->sasl_username : "none");
468 out:
469 qapi_free_VncInfo(info);
472 void hmp_info_spice(Monitor *mon, const QDict *qdict)
474 SpiceChannelList *chan;
475 SpiceInfo *info;
477 info = qmp_query_spice(NULL);
479 if (!info->enabled) {
480 monitor_printf(mon, "Server: disabled\n");
481 goto out;
484 monitor_printf(mon, "Server:\n");
485 if (info->has_port) {
486 monitor_printf(mon, " address: %s:%" PRId64 "\n",
487 info->host, info->port);
489 if (info->has_tls_port) {
490 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
491 info->host, info->tls_port);
493 monitor_printf(mon, " migrated: %s\n",
494 info->migrated ? "true" : "false");
495 monitor_printf(mon, " auth: %s\n", info->auth);
496 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
497 monitor_printf(mon, " mouse-mode: %s\n",
498 SpiceQueryMouseMode_lookup[info->mouse_mode]);
500 if (!info->has_channels || info->channels == NULL) {
501 monitor_printf(mon, "Channels: none\n");
502 } else {
503 for (chan = info->channels; chan; chan = chan->next) {
504 monitor_printf(mon, "Channel:\n");
505 monitor_printf(mon, " address: %s:%s%s\n",
506 chan->value->host, chan->value->port,
507 chan->value->tls ? " [tls]" : "");
508 monitor_printf(mon, " session: %" PRId64 "\n",
509 chan->value->connection_id);
510 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
511 chan->value->channel_type, chan->value->channel_id);
515 out:
516 qapi_free_SpiceInfo(info);
519 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
521 BalloonInfo *info;
522 Error *err = NULL;
524 info = qmp_query_balloon(&err);
525 if (err) {
526 monitor_printf(mon, "%s\n", error_get_pretty(err));
527 error_free(err);
528 return;
531 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
533 qapi_free_BalloonInfo(info);
536 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
538 PciMemoryRegionList *region;
540 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
541 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
542 dev->slot, dev->function);
543 monitor_printf(mon, " ");
545 if (dev->class_info.has_desc) {
546 monitor_printf(mon, "%s", dev->class_info.desc);
547 } else {
548 monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
551 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
552 dev->id.vendor, dev->id.device);
554 if (dev->has_irq) {
555 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
558 if (dev->has_pci_bridge) {
559 monitor_printf(mon, " BUS %" PRId64 ".\n",
560 dev->pci_bridge->bus.number);
561 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
562 dev->pci_bridge->bus.secondary);
563 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
564 dev->pci_bridge->bus.subordinate);
566 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
567 dev->pci_bridge->bus.io_range->base,
568 dev->pci_bridge->bus.io_range->limit);
570 monitor_printf(mon,
571 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
572 dev->pci_bridge->bus.memory_range->base,
573 dev->pci_bridge->bus.memory_range->limit);
575 monitor_printf(mon, " prefetchable memory range "
576 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
577 dev->pci_bridge->bus.prefetchable_range->base,
578 dev->pci_bridge->bus.prefetchable_range->limit);
581 for (region = dev->regions; region; region = region->next) {
582 uint64_t addr, size;
584 addr = region->value->address;
585 size = region->value->size;
587 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
589 if (!strcmp(region->value->type, "io")) {
590 monitor_printf(mon, "I/O at 0x%04" PRIx64
591 " [0x%04" PRIx64 "].\n",
592 addr, addr + size - 1);
593 } else {
594 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
595 " [0x%08" PRIx64 "].\n",
596 region->value->mem_type_64 ? 64 : 32,
597 region->value->prefetch ? " prefetchable" : "",
598 addr, addr + size - 1);
602 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
604 if (dev->has_pci_bridge) {
605 if (dev->pci_bridge->has_devices) {
606 PciDeviceInfoList *cdev;
607 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
608 hmp_info_pci_device(mon, cdev->value);
614 void hmp_info_pci(Monitor *mon, const QDict *qdict)
616 PciInfoList *info_list, *info;
617 Error *err = NULL;
619 info_list = qmp_query_pci(&err);
620 if (err) {
621 monitor_printf(mon, "PCI devices not supported\n");
622 error_free(err);
623 return;
626 for (info = info_list; info; info = info->next) {
627 PciDeviceInfoList *dev;
629 for (dev = info->value->devices; dev; dev = dev->next) {
630 hmp_info_pci_device(mon, dev->value);
634 qapi_free_PciInfoList(info_list);
637 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
639 BlockJobInfoList *list;
640 Error *err = NULL;
642 list = qmp_query_block_jobs(&err);
643 assert(!err);
645 if (!list) {
646 monitor_printf(mon, "No active jobs\n");
647 return;
650 while (list) {
651 if (strcmp(list->value->type, "stream") == 0) {
652 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
653 " of %" PRId64 " bytes, speed limit %" PRId64
654 " bytes/s\n",
655 list->value->device,
656 list->value->offset,
657 list->value->len,
658 list->value->speed);
659 } else {
660 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
661 " of %" PRId64 " bytes, speed limit %" PRId64
662 " bytes/s\n",
663 list->value->type,
664 list->value->device,
665 list->value->offset,
666 list->value->len,
667 list->value->speed);
669 list = list->next;
673 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
675 TPMInfoList *info_list, *info;
676 Error *err = NULL;
677 unsigned int c = 0;
678 TPMPassthroughOptions *tpo;
680 info_list = qmp_query_tpm(&err);
681 if (err) {
682 monitor_printf(mon, "TPM device not supported\n");
683 error_free(err);
684 return;
687 if (info_list) {
688 monitor_printf(mon, "TPM device:\n");
691 for (info = info_list; info; info = info->next) {
692 TPMInfo *ti = info->value;
693 monitor_printf(mon, " tpm%d: model=%s\n",
694 c, TpmModel_lookup[ti->model]);
696 monitor_printf(mon, " \\ %s: type=%s",
697 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
699 switch (ti->options->kind) {
700 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
701 tpo = ti->options->passthrough;
702 monitor_printf(mon, "%s%s%s%s",
703 tpo->has_path ? ",path=" : "",
704 tpo->has_path ? tpo->path : "",
705 tpo->has_cancel_path ? ",cancel-path=" : "",
706 tpo->has_cancel_path ? tpo->cancel_path : "");
707 break;
708 case TPM_TYPE_OPTIONS_KIND_MAX:
709 break;
711 monitor_printf(mon, "\n");
712 c++;
714 qapi_free_TPMInfoList(info_list);
717 void hmp_quit(Monitor *mon, const QDict *qdict)
719 monitor_suspend(mon);
720 qmp_quit(NULL);
723 void hmp_stop(Monitor *mon, const QDict *qdict)
725 qmp_stop(NULL);
728 void hmp_system_reset(Monitor *mon, const QDict *qdict)
730 qmp_system_reset(NULL);
733 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
735 qmp_system_powerdown(NULL);
738 void hmp_cpu(Monitor *mon, const QDict *qdict)
740 int64_t cpu_index;
742 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
743 use it are converted to the QAPI */
744 cpu_index = qdict_get_int(qdict, "index");
745 if (monitor_set_cpu(cpu_index) < 0) {
746 monitor_printf(mon, "invalid CPU index\n");
750 void hmp_memsave(Monitor *mon, const QDict *qdict)
752 uint32_t size = qdict_get_int(qdict, "size");
753 const char *filename = qdict_get_str(qdict, "filename");
754 uint64_t addr = qdict_get_int(qdict, "val");
755 Error *errp = NULL;
757 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
758 hmp_handle_error(mon, &errp);
761 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
763 uint32_t size = qdict_get_int(qdict, "size");
764 const char *filename = qdict_get_str(qdict, "filename");
765 uint64_t addr = qdict_get_int(qdict, "val");
766 Error *errp = NULL;
768 qmp_pmemsave(addr, size, filename, &errp);
769 hmp_handle_error(mon, &errp);
772 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
774 const char *chardev = qdict_get_str(qdict, "device");
775 const char *data = qdict_get_str(qdict, "data");
776 Error *errp = NULL;
778 qmp_ringbuf_write(chardev, data, false, 0, &errp);
780 hmp_handle_error(mon, &errp);
783 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
785 uint32_t size = qdict_get_int(qdict, "size");
786 const char *chardev = qdict_get_str(qdict, "device");
787 char *data;
788 Error *errp = NULL;
789 int i;
791 data = qmp_ringbuf_read(chardev, size, false, 0, &errp);
792 if (errp) {
793 monitor_printf(mon, "%s\n", error_get_pretty(errp));
794 error_free(errp);
795 return;
798 for (i = 0; data[i]; i++) {
799 unsigned char ch = data[i];
801 if (ch == '\\') {
802 monitor_printf(mon, "\\\\");
803 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
804 monitor_printf(mon, "\\u%04X", ch);
805 } else {
806 monitor_printf(mon, "%c", ch);
810 monitor_printf(mon, "\n");
811 g_free(data);
814 static void hmp_cont_cb(void *opaque, int err)
816 if (!err) {
817 qmp_cont(NULL);
821 static bool key_is_missing(const BlockInfo *bdev)
823 return (bdev->inserted && bdev->inserted->encryption_key_missing);
826 void hmp_cont(Monitor *mon, const QDict *qdict)
828 BlockInfoList *bdev_list, *bdev;
829 Error *errp = NULL;
831 bdev_list = qmp_query_block(NULL);
832 for (bdev = bdev_list; bdev; bdev = bdev->next) {
833 if (key_is_missing(bdev->value)) {
834 monitor_read_block_device_key(mon, bdev->value->device,
835 hmp_cont_cb, NULL);
836 goto out;
840 qmp_cont(&errp);
841 hmp_handle_error(mon, &errp);
843 out:
844 qapi_free_BlockInfoList(bdev_list);
847 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
849 qmp_system_wakeup(NULL);
852 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
854 Error *errp = NULL;
856 qmp_inject_nmi(&errp);
857 hmp_handle_error(mon, &errp);
860 void hmp_set_link(Monitor *mon, const QDict *qdict)
862 const char *name = qdict_get_str(qdict, "name");
863 int up = qdict_get_bool(qdict, "up");
864 Error *errp = NULL;
866 qmp_set_link(name, up, &errp);
867 hmp_handle_error(mon, &errp);
870 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
872 const char *device = qdict_get_str(qdict, "device");
873 const char *password = qdict_get_str(qdict, "password");
874 Error *errp = NULL;
876 qmp_block_passwd(true, device, false, NULL, password, &errp);
877 hmp_handle_error(mon, &errp);
880 void hmp_balloon(Monitor *mon, const QDict *qdict)
882 int64_t value = qdict_get_int(qdict, "value");
883 Error *errp = NULL;
885 qmp_balloon(value, &errp);
886 if (errp) {
887 monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
888 error_free(errp);
892 void hmp_block_resize(Monitor *mon, const QDict *qdict)
894 const char *device = qdict_get_str(qdict, "device");
895 int64_t size = qdict_get_int(qdict, "size");
896 Error *errp = NULL;
898 qmp_block_resize(true, device, false, NULL, size, &errp);
899 hmp_handle_error(mon, &errp);
902 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
904 const char *device = qdict_get_str(qdict, "device");
905 const char *filename = qdict_get_str(qdict, "target");
906 const char *format = qdict_get_try_str(qdict, "format");
907 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
908 int full = qdict_get_try_bool(qdict, "full", 0);
909 enum NewImageMode mode;
910 Error *errp = NULL;
912 if (!filename) {
913 error_set(&errp, QERR_MISSING_PARAMETER, "target");
914 hmp_handle_error(mon, &errp);
915 return;
918 if (reuse) {
919 mode = NEW_IMAGE_MODE_EXISTING;
920 } else {
921 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
924 qmp_drive_mirror(device, filename, !!format, format,
925 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
926 true, mode, false, 0, false, 0, false, 0,
927 false, 0, false, 0, &errp);
928 hmp_handle_error(mon, &errp);
931 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
933 const char *device = qdict_get_str(qdict, "device");
934 const char *filename = qdict_get_str(qdict, "target");
935 const char *format = qdict_get_try_str(qdict, "format");
936 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
937 int full = qdict_get_try_bool(qdict, "full", 0);
938 enum NewImageMode mode;
939 Error *errp = NULL;
941 if (!filename) {
942 error_set(&errp, QERR_MISSING_PARAMETER, "target");
943 hmp_handle_error(mon, &errp);
944 return;
947 if (reuse) {
948 mode = NEW_IMAGE_MODE_EXISTING;
949 } else {
950 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
953 qmp_drive_backup(device, filename, !!format, format,
954 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
955 true, mode, false, 0, false, 0, false, 0, &errp);
956 hmp_handle_error(mon, &errp);
959 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
961 const char *device = qdict_get_str(qdict, "device");
962 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
963 const char *format = qdict_get_try_str(qdict, "format");
964 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
965 enum NewImageMode mode;
966 Error *errp = NULL;
968 if (!filename) {
969 /* In the future, if 'snapshot-file' is not specified, the snapshot
970 will be taken internally. Today it's actually required. */
971 error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
972 hmp_handle_error(mon, &errp);
973 return;
976 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
977 qmp_blockdev_snapshot_sync(true, device, false, NULL,
978 filename, false, NULL,
979 !!format, format,
980 true, mode, &errp);
981 hmp_handle_error(mon, &errp);
984 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
986 const char *device = qdict_get_str(qdict, "device");
987 const char *name = qdict_get_str(qdict, "name");
988 Error *errp = NULL;
990 qmp_blockdev_snapshot_internal_sync(device, name, &errp);
991 hmp_handle_error(mon, &errp);
994 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
996 const char *device = qdict_get_str(qdict, "device");
997 const char *name = qdict_get_str(qdict, "name");
998 const char *id = qdict_get_try_str(qdict, "id");
999 Error *errp = NULL;
1001 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1002 true, name, &errp);
1003 hmp_handle_error(mon, &errp);
1006 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1008 qmp_migrate_cancel(NULL);
1011 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1013 double value = qdict_get_double(qdict, "value");
1014 qmp_migrate_set_downtime(value, NULL);
1017 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1019 int64_t value = qdict_get_int(qdict, "value");
1020 Error *err = NULL;
1022 qmp_migrate_set_cache_size(value, &err);
1023 if (err) {
1024 monitor_printf(mon, "%s\n", error_get_pretty(err));
1025 error_free(err);
1026 return;
1030 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1032 int64_t value = qdict_get_int(qdict, "value");
1033 qmp_migrate_set_speed(value, NULL);
1036 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1038 const char *cap = qdict_get_str(qdict, "capability");
1039 bool state = qdict_get_bool(qdict, "state");
1040 Error *err = NULL;
1041 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1042 int i;
1044 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1045 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1046 caps->value = g_malloc0(sizeof(*caps->value));
1047 caps->value->capability = i;
1048 caps->value->state = state;
1049 caps->next = NULL;
1050 qmp_migrate_set_capabilities(caps, &err);
1051 break;
1055 if (i == MIGRATION_CAPABILITY_MAX) {
1056 error_set(&err, QERR_INVALID_PARAMETER, cap);
1059 qapi_free_MigrationCapabilityStatusList(caps);
1061 if (err) {
1062 monitor_printf(mon, "migrate_set_capability: %s\n",
1063 error_get_pretty(err));
1064 error_free(err);
1068 void hmp_set_password(Monitor *mon, const QDict *qdict)
1070 const char *protocol = qdict_get_str(qdict, "protocol");
1071 const char *password = qdict_get_str(qdict, "password");
1072 const char *connected = qdict_get_try_str(qdict, "connected");
1073 Error *err = NULL;
1075 qmp_set_password(protocol, password, !!connected, connected, &err);
1076 hmp_handle_error(mon, &err);
1079 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1081 const char *protocol = qdict_get_str(qdict, "protocol");
1082 const char *whenstr = qdict_get_str(qdict, "time");
1083 Error *err = NULL;
1085 qmp_expire_password(protocol, whenstr, &err);
1086 hmp_handle_error(mon, &err);
1089 void hmp_eject(Monitor *mon, const QDict *qdict)
1091 int force = qdict_get_try_bool(qdict, "force", 0);
1092 const char *device = qdict_get_str(qdict, "device");
1093 Error *err = NULL;
1095 qmp_eject(device, true, force, &err);
1096 hmp_handle_error(mon, &err);
1099 static void hmp_change_read_arg(void *opaque, const char *password,
1100 void *readline_opaque)
1102 qmp_change_vnc_password(password, NULL);
1103 monitor_read_command(opaque, 1);
1106 void hmp_change(Monitor *mon, const QDict *qdict)
1108 const char *device = qdict_get_str(qdict, "device");
1109 const char *target = qdict_get_str(qdict, "target");
1110 const char *arg = qdict_get_try_str(qdict, "arg");
1111 Error *err = NULL;
1113 if (strcmp(device, "vnc") == 0 &&
1114 (strcmp(target, "passwd") == 0 ||
1115 strcmp(target, "password") == 0)) {
1116 if (!arg) {
1117 monitor_read_password(mon, hmp_change_read_arg, NULL);
1118 return;
1122 qmp_change(device, target, !!arg, arg, &err);
1123 if (err &&
1124 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1125 error_free(err);
1126 monitor_read_block_device_key(mon, device, NULL, NULL);
1127 return;
1129 hmp_handle_error(mon, &err);
1132 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1134 Error *err = NULL;
1136 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1137 qdict_get_int(qdict, "bps"),
1138 qdict_get_int(qdict, "bps_rd"),
1139 qdict_get_int(qdict, "bps_wr"),
1140 qdict_get_int(qdict, "iops"),
1141 qdict_get_int(qdict, "iops_rd"),
1142 qdict_get_int(qdict, "iops_wr"),
1143 false, /* no burst max via HMP */
1145 false,
1147 false,
1149 false,
1151 false,
1153 false,
1155 false, /* No default I/O size */
1156 0, &err);
1157 hmp_handle_error(mon, &err);
1160 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1162 Error *error = NULL;
1163 const char *device = qdict_get_str(qdict, "device");
1164 const char *base = qdict_get_try_str(qdict, "base");
1165 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1167 qmp_block_stream(device, base != NULL, base,
1168 qdict_haskey(qdict, "speed"), speed,
1169 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1171 hmp_handle_error(mon, &error);
1174 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1176 Error *error = NULL;
1177 const char *device = qdict_get_str(qdict, "device");
1178 int64_t value = qdict_get_int(qdict, "speed");
1180 qmp_block_job_set_speed(device, value, &error);
1182 hmp_handle_error(mon, &error);
1185 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1187 Error *error = NULL;
1188 const char *device = qdict_get_str(qdict, "device");
1189 bool force = qdict_get_try_bool(qdict, "force", 0);
1191 qmp_block_job_cancel(device, true, force, &error);
1193 hmp_handle_error(mon, &error);
1196 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1198 Error *error = NULL;
1199 const char *device = qdict_get_str(qdict, "device");
1201 qmp_block_job_pause(device, &error);
1203 hmp_handle_error(mon, &error);
1206 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1208 Error *error = NULL;
1209 const char *device = qdict_get_str(qdict, "device");
1211 qmp_block_job_resume(device, &error);
1213 hmp_handle_error(mon, &error);
1216 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1218 Error *error = NULL;
1219 const char *device = qdict_get_str(qdict, "device");
1221 qmp_block_job_complete(device, &error);
1223 hmp_handle_error(mon, &error);
1226 typedef struct MigrationStatus
1228 QEMUTimer *timer;
1229 Monitor *mon;
1230 bool is_block_migration;
1231 } MigrationStatus;
1233 static void hmp_migrate_status_cb(void *opaque)
1235 MigrationStatus *status = opaque;
1236 MigrationInfo *info;
1238 info = qmp_query_migrate(NULL);
1239 if (!info->has_status || strcmp(info->status, "active") == 0 ||
1240 strcmp(info->status, "setup") == 0) {
1241 if (info->has_disk) {
1242 int progress;
1244 if (info->disk->remaining) {
1245 progress = info->disk->transferred * 100 / info->disk->total;
1246 } else {
1247 progress = 100;
1250 monitor_printf(status->mon, "Completed %d %%\r", progress);
1251 monitor_flush(status->mon);
1254 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1255 } else {
1256 if (status->is_block_migration) {
1257 monitor_printf(status->mon, "\n");
1259 monitor_resume(status->mon);
1260 timer_del(status->timer);
1261 g_free(status);
1264 qapi_free_MigrationInfo(info);
1267 void hmp_migrate(Monitor *mon, const QDict *qdict)
1269 int detach = qdict_get_try_bool(qdict, "detach", 0);
1270 int blk = qdict_get_try_bool(qdict, "blk", 0);
1271 int inc = qdict_get_try_bool(qdict, "inc", 0);
1272 const char *uri = qdict_get_str(qdict, "uri");
1273 Error *err = NULL;
1275 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1276 if (err) {
1277 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1278 error_free(err);
1279 return;
1282 if (!detach) {
1283 MigrationStatus *status;
1285 if (monitor_suspend(mon) < 0) {
1286 monitor_printf(mon, "terminal does not allow synchronous "
1287 "migration, continuing detached\n");
1288 return;
1291 status = g_malloc0(sizeof(*status));
1292 status->mon = mon;
1293 status->is_block_migration = blk || inc;
1294 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1295 status);
1296 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1300 void hmp_device_del(Monitor *mon, const QDict *qdict)
1302 const char *id = qdict_get_str(qdict, "id");
1303 Error *err = NULL;
1305 qmp_device_del(id, &err);
1306 hmp_handle_error(mon, &err);
1309 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1311 Error *errp = NULL;
1312 int paging = qdict_get_try_bool(qdict, "paging", 0);
1313 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1314 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1315 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
1316 const char *file = qdict_get_str(qdict, "filename");
1317 bool has_begin = qdict_haskey(qdict, "begin");
1318 bool has_length = qdict_haskey(qdict, "length");
1319 int64_t begin = 0;
1320 int64_t length = 0;
1321 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1322 char *prot;
1324 if (zlib + lzo + snappy > 1) {
1325 error_setg(&errp, "only one of '-z|-l|-s' can be set");
1326 hmp_handle_error(mon, &errp);
1327 return;
1330 if (zlib) {
1331 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1334 if (lzo) {
1335 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1338 if (snappy) {
1339 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1342 if (has_begin) {
1343 begin = qdict_get_int(qdict, "begin");
1345 if (has_length) {
1346 length = qdict_get_int(qdict, "length");
1349 prot = g_strconcat("file:", file, NULL);
1351 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1352 true, dump_format, &errp);
1353 hmp_handle_error(mon, &errp);
1354 g_free(prot);
1357 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1359 Error *err = NULL;
1360 QemuOpts *opts;
1362 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1363 if (err) {
1364 goto out;
1367 netdev_add(opts, &err);
1368 if (err) {
1369 qemu_opts_del(opts);
1372 out:
1373 hmp_handle_error(mon, &err);
1376 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1378 const char *id = qdict_get_str(qdict, "id");
1379 Error *err = NULL;
1381 qmp_netdev_del(id, &err);
1382 hmp_handle_error(mon, &err);
1385 void hmp_object_add(Monitor *mon, const QDict *qdict)
1387 Error *err = NULL;
1388 QemuOpts *opts;
1389 char *type = NULL;
1390 char *id = NULL;
1391 void *dummy = NULL;
1392 OptsVisitor *ov;
1393 QDict *pdict;
1395 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1396 if (err) {
1397 goto out;
1400 ov = opts_visitor_new(opts);
1401 pdict = qdict_clone_shallow(qdict);
1403 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1404 if (err) {
1405 goto out_clean;
1408 qdict_del(pdict, "qom-type");
1409 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1410 if (err) {
1411 goto out_clean;
1414 qdict_del(pdict, "id");
1415 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1416 if (err) {
1417 goto out_clean;
1420 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1421 if (err) {
1422 goto out_clean;
1424 visit_end_struct(opts_get_visitor(ov), &err);
1425 if (err) {
1426 qmp_object_del(id, NULL);
1429 out_clean:
1430 opts_visitor_cleanup(ov);
1432 QDECREF(pdict);
1433 qemu_opts_del(opts);
1434 g_free(id);
1435 g_free(type);
1436 g_free(dummy);
1438 out:
1439 hmp_handle_error(mon, &err);
1442 void hmp_getfd(Monitor *mon, const QDict *qdict)
1444 const char *fdname = qdict_get_str(qdict, "fdname");
1445 Error *errp = NULL;
1447 qmp_getfd(fdname, &errp);
1448 hmp_handle_error(mon, &errp);
1451 void hmp_closefd(Monitor *mon, const QDict *qdict)
1453 const char *fdname = qdict_get_str(qdict, "fdname");
1454 Error *errp = NULL;
1456 qmp_closefd(fdname, &errp);
1457 hmp_handle_error(mon, &errp);
1460 void hmp_send_key(Monitor *mon, const QDict *qdict)
1462 const char *keys = qdict_get_str(qdict, "keys");
1463 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1464 int has_hold_time = qdict_haskey(qdict, "hold-time");
1465 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1466 Error *err = NULL;
1467 char keyname_buf[16];
1468 char *separator;
1469 int keyname_len;
1471 while (1) {
1472 separator = strchr(keys, '-');
1473 keyname_len = separator ? separator - keys : strlen(keys);
1474 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1476 /* Be compatible with old interface, convert user inputted "<" */
1477 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1478 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1479 keyname_len = 4;
1481 keyname_buf[keyname_len] = 0;
1483 keylist = g_malloc0(sizeof(*keylist));
1484 keylist->value = g_malloc0(sizeof(*keylist->value));
1486 if (!head) {
1487 head = keylist;
1489 if (tmp) {
1490 tmp->next = keylist;
1492 tmp = keylist;
1494 if (strstart(keyname_buf, "0x", NULL)) {
1495 char *endp;
1496 int value = strtoul(keyname_buf, &endp, 0);
1497 if (*endp != '\0') {
1498 goto err_out;
1500 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1501 keylist->value->number = value;
1502 } else {
1503 int idx = index_from_key(keyname_buf);
1504 if (idx == Q_KEY_CODE_MAX) {
1505 goto err_out;
1507 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1508 keylist->value->qcode = idx;
1511 if (!separator) {
1512 break;
1514 keys = separator + 1;
1517 qmp_send_key(head, has_hold_time, hold_time, &err);
1518 hmp_handle_error(mon, &err);
1520 out:
1521 qapi_free_KeyValueList(head);
1522 return;
1524 err_out:
1525 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1526 goto out;
1529 void hmp_screen_dump(Monitor *mon, const QDict *qdict)
1531 const char *filename = qdict_get_str(qdict, "filename");
1532 Error *err = NULL;
1534 qmp_screendump(filename, &err);
1535 hmp_handle_error(mon, &err);
1538 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1540 const char *uri = qdict_get_str(qdict, "uri");
1541 int writable = qdict_get_try_bool(qdict, "writable", 0);
1542 int all = qdict_get_try_bool(qdict, "all", 0);
1543 Error *local_err = NULL;
1544 BlockInfoList *block_list, *info;
1545 SocketAddress *addr;
1547 if (writable && !all) {
1548 error_setg(&local_err, "-w only valid together with -a");
1549 goto exit;
1552 /* First check if the address is valid and start the server. */
1553 addr = socket_parse(uri, &local_err);
1554 if (local_err != NULL) {
1555 goto exit;
1558 qmp_nbd_server_start(addr, &local_err);
1559 qapi_free_SocketAddress(addr);
1560 if (local_err != NULL) {
1561 goto exit;
1564 if (!all) {
1565 return;
1568 /* Then try adding all block devices. If one fails, close all and
1569 * exit.
1571 block_list = qmp_query_block(NULL);
1573 for (info = block_list; info; info = info->next) {
1574 if (!info->value->has_inserted) {
1575 continue;
1578 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1580 if (local_err != NULL) {
1581 qmp_nbd_server_stop(NULL);
1582 break;
1586 qapi_free_BlockInfoList(block_list);
1588 exit:
1589 hmp_handle_error(mon, &local_err);
1592 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1594 const char *device = qdict_get_str(qdict, "device");
1595 int writable = qdict_get_try_bool(qdict, "writable", 0);
1596 Error *local_err = NULL;
1598 qmp_nbd_server_add(device, true, writable, &local_err);
1600 if (local_err != NULL) {
1601 hmp_handle_error(mon, &local_err);
1605 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1607 Error *errp = NULL;
1609 qmp_nbd_server_stop(&errp);
1610 hmp_handle_error(mon, &errp);
1613 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1615 int cpuid;
1616 Error *err = NULL;
1618 cpuid = qdict_get_int(qdict, "id");
1619 qmp_cpu_add(cpuid, &err);
1620 hmp_handle_error(mon, &err);
1623 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1625 const char *args = qdict_get_str(qdict, "args");
1626 Error *err = NULL;
1627 QemuOpts *opts;
1629 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1630 if (opts == NULL) {
1631 error_setg(&err, "Parsing chardev args failed");
1632 } else {
1633 qemu_chr_new_from_opts(opts, NULL, &err);
1635 hmp_handle_error(mon, &err);
1638 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1640 Error *local_err = NULL;
1642 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1643 hmp_handle_error(mon, &local_err);
1646 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1648 BlockDriverState *bs;
1649 const char* device = qdict_get_str(qdict, "device");
1650 const char* command = qdict_get_str(qdict, "command");
1651 Error *err = NULL;
1653 bs = bdrv_find(device);
1654 if (bs) {
1655 qemuio_command(bs, command);
1656 } else {
1657 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1660 hmp_handle_error(mon, &err);
1663 void hmp_object_del(Monitor *mon, const QDict *qdict)
1665 const char *id = qdict_get_str(qdict, "id");
1666 Error *err = NULL;
1668 qmp_object_del(id, &err);
1669 hmp_handle_error(mon, &err);