microblaze: Support loading of u-boot initrd images
[qemu/ar7.git] / hmp.c
blob5c4d6122944e0762709fc69207032914772e8017
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 assert(errp);
32 if (*errp) {
33 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
34 error_free(*errp);
38 void hmp_info_name(Monitor *mon, const QDict *qdict)
40 NameInfo *info;
42 info = qmp_query_name(NULL);
43 if (info->has_name) {
44 monitor_printf(mon, "%s\n", info->name);
46 qapi_free_NameInfo(info);
49 void hmp_info_version(Monitor *mon, const QDict *qdict)
51 VersionInfo *info;
53 info = qmp_query_version(NULL);
55 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
56 info->qemu.major, info->qemu.minor, info->qemu.micro,
57 info->package);
59 qapi_free_VersionInfo(info);
62 void hmp_info_kvm(Monitor *mon, const QDict *qdict)
64 KvmInfo *info;
66 info = qmp_query_kvm(NULL);
67 monitor_printf(mon, "kvm support: ");
68 if (info->present) {
69 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
70 } else {
71 monitor_printf(mon, "not compiled\n");
74 qapi_free_KvmInfo(info);
77 void hmp_info_status(Monitor *mon, const QDict *qdict)
79 StatusInfo *info;
81 info = qmp_query_status(NULL);
83 monitor_printf(mon, "VM status: %s%s",
84 info->running ? "running" : "paused",
85 info->singlestep ? " (single step mode)" : "");
87 if (!info->running && info->status != RUN_STATE_PAUSED) {
88 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
91 monitor_printf(mon, "\n");
93 qapi_free_StatusInfo(info);
96 void hmp_info_uuid(Monitor *mon, const QDict *qdict)
98 UuidInfo *info;
100 info = qmp_query_uuid(NULL);
101 monitor_printf(mon, "%s\n", info->UUID);
102 qapi_free_UuidInfo(info);
105 void hmp_info_chardev(Monitor *mon, const QDict *qdict)
107 ChardevInfoList *char_info, *info;
109 char_info = qmp_query_chardev(NULL);
110 for (info = char_info; info; info = info->next) {
111 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
112 info->value->filename);
115 qapi_free_ChardevInfoList(char_info);
118 void hmp_info_mice(Monitor *mon, const QDict *qdict)
120 MouseInfoList *mice_list, *mouse;
122 mice_list = qmp_query_mice(NULL);
123 if (!mice_list) {
124 monitor_printf(mon, "No mouse devices connected\n");
125 return;
128 for (mouse = mice_list; mouse; mouse = mouse->next) {
129 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
130 mouse->value->current ? '*' : ' ',
131 mouse->value->index, mouse->value->name,
132 mouse->value->absolute ? " (absolute)" : "");
135 qapi_free_MouseInfoList(mice_list);
138 void hmp_info_migrate(Monitor *mon, const QDict *qdict)
140 MigrationInfo *info;
141 MigrationCapabilityStatusList *caps, *cap;
143 info = qmp_query_migrate(NULL);
144 caps = qmp_query_migrate_capabilities(NULL);
146 /* do not display parameters during setup */
147 if (info->has_status && caps) {
148 monitor_printf(mon, "capabilities: ");
149 for (cap = caps; cap; cap = cap->next) {
150 monitor_printf(mon, "%s: %s ",
151 MigrationCapability_lookup[cap->value->capability],
152 cap->value->state ? "on" : "off");
154 monitor_printf(mon, "\n");
157 if (info->has_status) {
158 monitor_printf(mon, "Migration status: %s\n", info->status);
159 monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
160 info->total_time);
161 if (info->has_expected_downtime) {
162 monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
163 info->expected_downtime);
165 if (info->has_downtime) {
166 monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
167 info->downtime);
169 if (info->has_setup_time) {
170 monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
171 info->setup_time);
175 if (info->has_ram) {
176 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
177 info->ram->transferred >> 10);
178 monitor_printf(mon, "throughput: %0.2f mbps\n",
179 info->ram->mbps);
180 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
181 info->ram->remaining >> 10);
182 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
183 info->ram->total >> 10);
184 monitor_printf(mon, "duplicate: %" PRIu64 " pages\n",
185 info->ram->duplicate);
186 monitor_printf(mon, "skipped: %" PRIu64 " pages\n",
187 info->ram->skipped);
188 monitor_printf(mon, "normal: %" PRIu64 " pages\n",
189 info->ram->normal);
190 monitor_printf(mon, "normal bytes: %" PRIu64 " kbytes\n",
191 info->ram->normal_bytes >> 10);
192 monitor_printf(mon, "dirty sync count: %" PRIu64 "\n",
193 info->ram->dirty_sync_count);
194 if (info->ram->dirty_pages_rate) {
195 monitor_printf(mon, "dirty pages rate: %" PRIu64 " pages\n",
196 info->ram->dirty_pages_rate);
200 if (info->has_disk) {
201 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
202 info->disk->transferred >> 10);
203 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
204 info->disk->remaining >> 10);
205 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
206 info->disk->total >> 10);
209 if (info->has_xbzrle_cache) {
210 monitor_printf(mon, "cache size: %" PRIu64 " bytes\n",
211 info->xbzrle_cache->cache_size);
212 monitor_printf(mon, "xbzrle transferred: %" PRIu64 " kbytes\n",
213 info->xbzrle_cache->bytes >> 10);
214 monitor_printf(mon, "xbzrle pages: %" PRIu64 " pages\n",
215 info->xbzrle_cache->pages);
216 monitor_printf(mon, "xbzrle cache miss: %" PRIu64 "\n",
217 info->xbzrle_cache->cache_miss);
218 monitor_printf(mon, "xbzrle cache miss rate: %0.2f\n",
219 info->xbzrle_cache->cache_miss_rate);
220 monitor_printf(mon, "xbzrle overflow : %" PRIu64 "\n",
221 info->xbzrle_cache->overflow);
224 qapi_free_MigrationInfo(info);
225 qapi_free_MigrationCapabilityStatusList(caps);
228 void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
230 MigrationCapabilityStatusList *caps, *cap;
232 caps = qmp_query_migrate_capabilities(NULL);
234 if (caps) {
235 monitor_printf(mon, "capabilities: ");
236 for (cap = caps; cap; cap = cap->next) {
237 monitor_printf(mon, "%s: %s ",
238 MigrationCapability_lookup[cap->value->capability],
239 cap->value->state ? "on" : "off");
241 monitor_printf(mon, "\n");
244 qapi_free_MigrationCapabilityStatusList(caps);
247 void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
249 monitor_printf(mon, "xbzrel cache size: %" PRId64 " kbytes\n",
250 qmp_query_migrate_cache_size(NULL) >> 10);
253 void hmp_info_cpus(Monitor *mon, const QDict *qdict)
255 CpuInfoList *cpu_list, *cpu;
257 cpu_list = qmp_query_cpus(NULL);
259 for (cpu = cpu_list; cpu; cpu = cpu->next) {
260 int active = ' ';
262 if (cpu->value->CPU == monitor_get_cpu_index()) {
263 active = '*';
266 monitor_printf(mon, "%c CPU #%" PRId64 ":", active, cpu->value->CPU);
268 if (cpu->value->has_pc) {
269 monitor_printf(mon, " pc=0x%016" PRIx64, cpu->value->pc);
271 if (cpu->value->has_nip) {
272 monitor_printf(mon, " nip=0x%016" PRIx64, cpu->value->nip);
274 if (cpu->value->has_npc) {
275 monitor_printf(mon, " npc=0x%016" PRIx64, cpu->value->npc);
277 if (cpu->value->has_PC) {
278 monitor_printf(mon, " PC=0x%016" PRIx64, cpu->value->PC);
281 if (cpu->value->halted) {
282 monitor_printf(mon, " (halted)");
285 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
288 qapi_free_CpuInfoList(cpu_list);
291 void hmp_info_block(Monitor *mon, const QDict *qdict)
293 BlockInfoList *block_list, *info;
294 ImageInfo *image_info;
295 const char *device = qdict_get_try_str(qdict, "device");
296 bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
298 block_list = qmp_query_block(NULL);
300 for (info = block_list; info; info = info->next) {
301 if (device && strcmp(device, info->value->device)) {
302 continue;
305 if (info != block_list) {
306 monitor_printf(mon, "\n");
309 monitor_printf(mon, "%s", info->value->device);
310 if (info->value->has_inserted) {
311 monitor_printf(mon, ": %s (%s%s%s)\n",
312 info->value->inserted->file,
313 info->value->inserted->drv,
314 info->value->inserted->ro ? ", read-only" : "",
315 info->value->inserted->encrypted ? ", encrypted" : "");
316 } else {
317 monitor_printf(mon, ": [not inserted]\n");
320 if (info->value->has_io_status && info->value->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
321 monitor_printf(mon, " I/O status: %s\n",
322 BlockDeviceIoStatus_lookup[info->value->io_status]);
325 if (info->value->removable) {
326 monitor_printf(mon, " Removable device: %slocked, tray %s\n",
327 info->value->locked ? "" : "not ",
328 info->value->tray_open ? "open" : "closed");
332 if (!info->value->has_inserted) {
333 continue;
336 if (info->value->inserted->has_backing_file) {
337 monitor_printf(mon,
338 " Backing file: %s "
339 "(chain depth: %" PRId64 ")\n",
340 info->value->inserted->backing_file,
341 info->value->inserted->backing_file_depth);
344 if (info->value->inserted->bps
345 || info->value->inserted->bps_rd
346 || info->value->inserted->bps_wr
347 || info->value->inserted->iops
348 || info->value->inserted->iops_rd
349 || info->value->inserted->iops_wr)
351 monitor_printf(mon, " I/O throttling: bps=%" PRId64
352 " bps_rd=%" PRId64 " bps_wr=%" PRId64
353 " bps_max=%" PRId64
354 " bps_rd_max=%" PRId64
355 " bps_wr_max=%" PRId64
356 " iops=%" PRId64 " iops_rd=%" PRId64
357 " iops_wr=%" PRId64
358 " iops_max=%" PRId64
359 " iops_rd_max=%" PRId64
360 " iops_wr_max=%" PRId64
361 " iops_size=%" PRId64 "\n",
362 info->value->inserted->bps,
363 info->value->inserted->bps_rd,
364 info->value->inserted->bps_wr,
365 info->value->inserted->bps_max,
366 info->value->inserted->bps_rd_max,
367 info->value->inserted->bps_wr_max,
368 info->value->inserted->iops,
369 info->value->inserted->iops_rd,
370 info->value->inserted->iops_wr,
371 info->value->inserted->iops_max,
372 info->value->inserted->iops_rd_max,
373 info->value->inserted->iops_wr_max,
374 info->value->inserted->iops_size);
377 if (verbose) {
378 monitor_printf(mon, "\nImages:\n");
379 image_info = info->value->inserted->image;
380 while (1) {
381 bdrv_image_info_dump((fprintf_function)monitor_printf,
382 mon, image_info);
383 if (image_info->has_backing_image) {
384 image_info = image_info->backing_image;
385 } else {
386 break;
392 qapi_free_BlockInfoList(block_list);
395 void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
397 BlockStatsList *stats_list, *stats;
399 stats_list = qmp_query_blockstats(NULL);
401 for (stats = stats_list; stats; stats = stats->next) {
402 if (!stats->value->has_device) {
403 continue;
406 monitor_printf(mon, "%s:", stats->value->device);
407 monitor_printf(mon, " rd_bytes=%" PRId64
408 " wr_bytes=%" PRId64
409 " rd_operations=%" PRId64
410 " wr_operations=%" PRId64
411 " flush_operations=%" PRId64
412 " wr_total_time_ns=%" PRId64
413 " rd_total_time_ns=%" PRId64
414 " flush_total_time_ns=%" PRId64
415 "\n",
416 stats->value->stats->rd_bytes,
417 stats->value->stats->wr_bytes,
418 stats->value->stats->rd_operations,
419 stats->value->stats->wr_operations,
420 stats->value->stats->flush_operations,
421 stats->value->stats->wr_total_time_ns,
422 stats->value->stats->rd_total_time_ns,
423 stats->value->stats->flush_total_time_ns);
426 qapi_free_BlockStatsList(stats_list);
429 void hmp_info_vnc(Monitor *mon, const QDict *qdict)
431 VncInfo *info;
432 Error *err = NULL;
433 VncClientInfoList *client;
435 info = qmp_query_vnc(&err);
436 if (err) {
437 monitor_printf(mon, "%s\n", error_get_pretty(err));
438 error_free(err);
439 return;
442 if (!info->enabled) {
443 monitor_printf(mon, "Server: disabled\n");
444 goto out;
447 monitor_printf(mon, "Server:\n");
448 if (info->has_host && info->has_service) {
449 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
451 if (info->has_auth) {
452 monitor_printf(mon, " auth: %s\n", info->auth);
455 if (!info->has_clients || info->clients == NULL) {
456 monitor_printf(mon, "Client: none\n");
457 } else {
458 for (client = info->clients; client; client = client->next) {
459 monitor_printf(mon, "Client:\n");
460 monitor_printf(mon, " address: %s:%s\n",
461 client->value->host, client->value->service);
462 monitor_printf(mon, " x509_dname: %s\n",
463 client->value->x509_dname ?
464 client->value->x509_dname : "none");
465 monitor_printf(mon, " username: %s\n",
466 client->value->has_sasl_username ?
467 client->value->sasl_username : "none");
471 out:
472 qapi_free_VncInfo(info);
475 void hmp_info_spice(Monitor *mon, const QDict *qdict)
477 SpiceChannelList *chan;
478 SpiceInfo *info;
480 info = qmp_query_spice(NULL);
482 if (!info->enabled) {
483 monitor_printf(mon, "Server: disabled\n");
484 goto out;
487 monitor_printf(mon, "Server:\n");
488 if (info->has_port) {
489 monitor_printf(mon, " address: %s:%" PRId64 "\n",
490 info->host, info->port);
492 if (info->has_tls_port) {
493 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
494 info->host, info->tls_port);
496 monitor_printf(mon, " migrated: %s\n",
497 info->migrated ? "true" : "false");
498 monitor_printf(mon, " auth: %s\n", info->auth);
499 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
500 monitor_printf(mon, " mouse-mode: %s\n",
501 SpiceQueryMouseMode_lookup[info->mouse_mode]);
503 if (!info->has_channels || info->channels == NULL) {
504 monitor_printf(mon, "Channels: none\n");
505 } else {
506 for (chan = info->channels; chan; chan = chan->next) {
507 monitor_printf(mon, "Channel:\n");
508 monitor_printf(mon, " address: %s:%s%s\n",
509 chan->value->host, chan->value->port,
510 chan->value->tls ? " [tls]" : "");
511 monitor_printf(mon, " session: %" PRId64 "\n",
512 chan->value->connection_id);
513 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
514 chan->value->channel_type, chan->value->channel_id);
518 out:
519 qapi_free_SpiceInfo(info);
522 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
524 BalloonInfo *info;
525 Error *err = NULL;
527 info = qmp_query_balloon(&err);
528 if (err) {
529 monitor_printf(mon, "%s\n", error_get_pretty(err));
530 error_free(err);
531 return;
534 monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
536 qapi_free_BalloonInfo(info);
539 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
541 PciMemoryRegionList *region;
543 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
544 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
545 dev->slot, dev->function);
546 monitor_printf(mon, " ");
548 if (dev->class_info.has_desc) {
549 monitor_printf(mon, "%s", dev->class_info.desc);
550 } else {
551 monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
554 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
555 dev->id.vendor, dev->id.device);
557 if (dev->has_irq) {
558 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
561 if (dev->has_pci_bridge) {
562 monitor_printf(mon, " BUS %" PRId64 ".\n",
563 dev->pci_bridge->bus.number);
564 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
565 dev->pci_bridge->bus.secondary);
566 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
567 dev->pci_bridge->bus.subordinate);
569 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
570 dev->pci_bridge->bus.io_range->base,
571 dev->pci_bridge->bus.io_range->limit);
573 monitor_printf(mon,
574 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
575 dev->pci_bridge->bus.memory_range->base,
576 dev->pci_bridge->bus.memory_range->limit);
578 monitor_printf(mon, " prefetchable memory range "
579 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
580 dev->pci_bridge->bus.prefetchable_range->base,
581 dev->pci_bridge->bus.prefetchable_range->limit);
584 for (region = dev->regions; region; region = region->next) {
585 uint64_t addr, size;
587 addr = region->value->address;
588 size = region->value->size;
590 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
592 if (!strcmp(region->value->type, "io")) {
593 monitor_printf(mon, "I/O at 0x%04" PRIx64
594 " [0x%04" PRIx64 "].\n",
595 addr, addr + size - 1);
596 } else {
597 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
598 " [0x%08" PRIx64 "].\n",
599 region->value->mem_type_64 ? 64 : 32,
600 region->value->prefetch ? " prefetchable" : "",
601 addr, addr + size - 1);
605 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
607 if (dev->has_pci_bridge) {
608 if (dev->pci_bridge->has_devices) {
609 PciDeviceInfoList *cdev;
610 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
611 hmp_info_pci_device(mon, cdev->value);
617 void hmp_info_pci(Monitor *mon, const QDict *qdict)
619 PciInfoList *info_list, *info;
620 Error *err = NULL;
622 info_list = qmp_query_pci(&err);
623 if (err) {
624 monitor_printf(mon, "PCI devices not supported\n");
625 error_free(err);
626 return;
629 for (info = info_list; info; info = info->next) {
630 PciDeviceInfoList *dev;
632 for (dev = info->value->devices; dev; dev = dev->next) {
633 hmp_info_pci_device(mon, dev->value);
637 qapi_free_PciInfoList(info_list);
640 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
642 BlockJobInfoList *list;
643 Error *err = NULL;
645 list = qmp_query_block_jobs(&err);
646 assert(!err);
648 if (!list) {
649 monitor_printf(mon, "No active jobs\n");
650 return;
653 while (list) {
654 if (strcmp(list->value->type, "stream") == 0) {
655 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
656 " of %" PRId64 " bytes, speed limit %" PRId64
657 " bytes/s\n",
658 list->value->device,
659 list->value->offset,
660 list->value->len,
661 list->value->speed);
662 } else {
663 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
664 " of %" PRId64 " bytes, speed limit %" PRId64
665 " bytes/s\n",
666 list->value->type,
667 list->value->device,
668 list->value->offset,
669 list->value->len,
670 list->value->speed);
672 list = list->next;
676 void hmp_info_tpm(Monitor *mon, const QDict *qdict)
678 TPMInfoList *info_list, *info;
679 Error *err = NULL;
680 unsigned int c = 0;
681 TPMPassthroughOptions *tpo;
683 info_list = qmp_query_tpm(&err);
684 if (err) {
685 monitor_printf(mon, "TPM device not supported\n");
686 error_free(err);
687 return;
690 if (info_list) {
691 monitor_printf(mon, "TPM device:\n");
694 for (info = info_list; info; info = info->next) {
695 TPMInfo *ti = info->value;
696 monitor_printf(mon, " tpm%d: model=%s\n",
697 c, TpmModel_lookup[ti->model]);
699 monitor_printf(mon, " \\ %s: type=%s",
700 ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]);
702 switch (ti->options->kind) {
703 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH:
704 tpo = ti->options->passthrough;
705 monitor_printf(mon, "%s%s%s%s",
706 tpo->has_path ? ",path=" : "",
707 tpo->has_path ? tpo->path : "",
708 tpo->has_cancel_path ? ",cancel-path=" : "",
709 tpo->has_cancel_path ? tpo->cancel_path : "");
710 break;
711 case TPM_TYPE_OPTIONS_KIND_MAX:
712 break;
714 monitor_printf(mon, "\n");
715 c++;
717 qapi_free_TPMInfoList(info_list);
720 void hmp_quit(Monitor *mon, const QDict *qdict)
722 monitor_suspend(mon);
723 qmp_quit(NULL);
726 void hmp_stop(Monitor *mon, const QDict *qdict)
728 qmp_stop(NULL);
731 void hmp_system_reset(Monitor *mon, const QDict *qdict)
733 qmp_system_reset(NULL);
736 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
738 qmp_system_powerdown(NULL);
741 void hmp_cpu(Monitor *mon, const QDict *qdict)
743 int64_t cpu_index;
745 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
746 use it are converted to the QAPI */
747 cpu_index = qdict_get_int(qdict, "index");
748 if (monitor_set_cpu(cpu_index) < 0) {
749 monitor_printf(mon, "invalid CPU index\n");
753 void hmp_memsave(Monitor *mon, const QDict *qdict)
755 uint32_t size = qdict_get_int(qdict, "size");
756 const char *filename = qdict_get_str(qdict, "filename");
757 uint64_t addr = qdict_get_int(qdict, "val");
758 Error *err = NULL;
760 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
761 hmp_handle_error(mon, &err);
764 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
766 uint32_t size = qdict_get_int(qdict, "size");
767 const char *filename = qdict_get_str(qdict, "filename");
768 uint64_t addr = qdict_get_int(qdict, "val");
769 Error *err = NULL;
771 qmp_pmemsave(addr, size, filename, &err);
772 hmp_handle_error(mon, &err);
775 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
777 const char *chardev = qdict_get_str(qdict, "device");
778 const char *data = qdict_get_str(qdict, "data");
779 Error *err = NULL;
781 qmp_ringbuf_write(chardev, data, false, 0, &err);
783 hmp_handle_error(mon, &err);
786 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
788 uint32_t size = qdict_get_int(qdict, "size");
789 const char *chardev = qdict_get_str(qdict, "device");
790 char *data;
791 Error *err = NULL;
792 int i;
794 data = qmp_ringbuf_read(chardev, size, false, 0, &err);
795 if (err) {
796 monitor_printf(mon, "%s\n", error_get_pretty(err));
797 error_free(err);
798 return;
801 for (i = 0; data[i]; i++) {
802 unsigned char ch = data[i];
804 if (ch == '\\') {
805 monitor_printf(mon, "\\\\");
806 } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) {
807 monitor_printf(mon, "\\u%04X", ch);
808 } else {
809 monitor_printf(mon, "%c", ch);
813 monitor_printf(mon, "\n");
814 g_free(data);
817 static void hmp_cont_cb(void *opaque, int err)
819 if (!err) {
820 qmp_cont(NULL);
824 static bool key_is_missing(const BlockInfo *bdev)
826 return (bdev->inserted && bdev->inserted->encryption_key_missing);
829 void hmp_cont(Monitor *mon, const QDict *qdict)
831 BlockInfoList *bdev_list, *bdev;
832 Error *err = NULL;
834 bdev_list = qmp_query_block(NULL);
835 for (bdev = bdev_list; bdev; bdev = bdev->next) {
836 if (key_is_missing(bdev->value)) {
837 monitor_read_block_device_key(mon, bdev->value->device,
838 hmp_cont_cb, NULL);
839 goto out;
843 qmp_cont(&err);
844 hmp_handle_error(mon, &err);
846 out:
847 qapi_free_BlockInfoList(bdev_list);
850 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
852 qmp_system_wakeup(NULL);
855 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
857 Error *err = NULL;
859 qmp_inject_nmi(&err);
860 hmp_handle_error(mon, &err);
863 void hmp_set_link(Monitor *mon, const QDict *qdict)
865 const char *name = qdict_get_str(qdict, "name");
866 int up = qdict_get_bool(qdict, "up");
867 Error *err = NULL;
869 qmp_set_link(name, up, &err);
870 hmp_handle_error(mon, &err);
873 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
875 const char *device = qdict_get_str(qdict, "device");
876 const char *password = qdict_get_str(qdict, "password");
877 Error *err = NULL;
879 qmp_block_passwd(true, device, false, NULL, password, &err);
880 hmp_handle_error(mon, &err);
883 void hmp_balloon(Monitor *mon, const QDict *qdict)
885 int64_t value = qdict_get_int(qdict, "value");
886 Error *err = NULL;
888 qmp_balloon(value, &err);
889 if (err) {
890 monitor_printf(mon, "balloon: %s\n", error_get_pretty(err));
891 error_free(err);
895 void hmp_block_resize(Monitor *mon, const QDict *qdict)
897 const char *device = qdict_get_str(qdict, "device");
898 int64_t size = qdict_get_int(qdict, "size");
899 Error *err = NULL;
901 qmp_block_resize(true, device, false, NULL, size, &err);
902 hmp_handle_error(mon, &err);
905 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
907 const char *device = qdict_get_str(qdict, "device");
908 const char *filename = qdict_get_str(qdict, "target");
909 const char *format = qdict_get_try_str(qdict, "format");
910 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
911 int full = qdict_get_try_bool(qdict, "full", 0);
912 enum NewImageMode mode;
913 Error *err = NULL;
915 if (!filename) {
916 error_set(&err, QERR_MISSING_PARAMETER, "target");
917 hmp_handle_error(mon, &err);
918 return;
921 if (reuse) {
922 mode = NEW_IMAGE_MODE_EXISTING;
923 } else {
924 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
927 qmp_drive_mirror(device, filename, !!format, format,
928 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
929 true, mode, false, 0, false, 0, false, 0,
930 false, 0, false, 0, &err);
931 hmp_handle_error(mon, &err);
934 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
936 const char *device = qdict_get_str(qdict, "device");
937 const char *filename = qdict_get_str(qdict, "target");
938 const char *format = qdict_get_try_str(qdict, "format");
939 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
940 int full = qdict_get_try_bool(qdict, "full", 0);
941 enum NewImageMode mode;
942 Error *err = NULL;
944 if (!filename) {
945 error_set(&err, QERR_MISSING_PARAMETER, "target");
946 hmp_handle_error(mon, &err);
947 return;
950 if (reuse) {
951 mode = NEW_IMAGE_MODE_EXISTING;
952 } else {
953 mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS;
956 qmp_drive_backup(device, filename, !!format, format,
957 full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
958 true, mode, false, 0, false, 0, false, 0, &err);
959 hmp_handle_error(mon, &err);
962 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
964 const char *device = qdict_get_str(qdict, "device");
965 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
966 const char *format = qdict_get_try_str(qdict, "format");
967 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
968 enum NewImageMode mode;
969 Error *err = NULL;
971 if (!filename) {
972 /* In the future, if 'snapshot-file' is not specified, the snapshot
973 will be taken internally. Today it's actually required. */
974 error_set(&err, QERR_MISSING_PARAMETER, "snapshot-file");
975 hmp_handle_error(mon, &err);
976 return;
979 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
980 qmp_blockdev_snapshot_sync(true, device, false, NULL,
981 filename, false, NULL,
982 !!format, format,
983 true, mode, &err);
984 hmp_handle_error(mon, &err);
987 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
989 const char *device = qdict_get_str(qdict, "device");
990 const char *name = qdict_get_str(qdict, "name");
991 Error *err = NULL;
993 qmp_blockdev_snapshot_internal_sync(device, name, &err);
994 hmp_handle_error(mon, &err);
997 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
999 const char *device = qdict_get_str(qdict, "device");
1000 const char *name = qdict_get_str(qdict, "name");
1001 const char *id = qdict_get_try_str(qdict, "id");
1002 Error *err = NULL;
1004 qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
1005 true, name, &err);
1006 hmp_handle_error(mon, &err);
1009 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
1011 qmp_migrate_cancel(NULL);
1014 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
1016 double value = qdict_get_double(qdict, "value");
1017 qmp_migrate_set_downtime(value, NULL);
1020 void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
1022 int64_t value = qdict_get_int(qdict, "value");
1023 Error *err = NULL;
1025 qmp_migrate_set_cache_size(value, &err);
1026 if (err) {
1027 monitor_printf(mon, "%s\n", error_get_pretty(err));
1028 error_free(err);
1029 return;
1033 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
1035 int64_t value = qdict_get_int(qdict, "value");
1036 qmp_migrate_set_speed(value, NULL);
1039 void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
1041 const char *cap = qdict_get_str(qdict, "capability");
1042 bool state = qdict_get_bool(qdict, "state");
1043 Error *err = NULL;
1044 MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
1045 int i;
1047 for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
1048 if (strcmp(cap, MigrationCapability_lookup[i]) == 0) {
1049 caps->value = g_malloc0(sizeof(*caps->value));
1050 caps->value->capability = i;
1051 caps->value->state = state;
1052 caps->next = NULL;
1053 qmp_migrate_set_capabilities(caps, &err);
1054 break;
1058 if (i == MIGRATION_CAPABILITY_MAX) {
1059 error_set(&err, QERR_INVALID_PARAMETER, cap);
1062 qapi_free_MigrationCapabilityStatusList(caps);
1064 if (err) {
1065 monitor_printf(mon, "migrate_set_capability: %s\n",
1066 error_get_pretty(err));
1067 error_free(err);
1071 void hmp_set_password(Monitor *mon, const QDict *qdict)
1073 const char *protocol = qdict_get_str(qdict, "protocol");
1074 const char *password = qdict_get_str(qdict, "password");
1075 const char *connected = qdict_get_try_str(qdict, "connected");
1076 Error *err = NULL;
1078 qmp_set_password(protocol, password, !!connected, connected, &err);
1079 hmp_handle_error(mon, &err);
1082 void hmp_expire_password(Monitor *mon, const QDict *qdict)
1084 const char *protocol = qdict_get_str(qdict, "protocol");
1085 const char *whenstr = qdict_get_str(qdict, "time");
1086 Error *err = NULL;
1088 qmp_expire_password(protocol, whenstr, &err);
1089 hmp_handle_error(mon, &err);
1092 void hmp_eject(Monitor *mon, const QDict *qdict)
1094 int force = qdict_get_try_bool(qdict, "force", 0);
1095 const char *device = qdict_get_str(qdict, "device");
1096 Error *err = NULL;
1098 qmp_eject(device, true, force, &err);
1099 hmp_handle_error(mon, &err);
1102 static void hmp_change_read_arg(void *opaque, const char *password,
1103 void *readline_opaque)
1105 qmp_change_vnc_password(password, NULL);
1106 monitor_read_command(opaque, 1);
1109 void hmp_change(Monitor *mon, const QDict *qdict)
1111 const char *device = qdict_get_str(qdict, "device");
1112 const char *target = qdict_get_str(qdict, "target");
1113 const char *arg = qdict_get_try_str(qdict, "arg");
1114 Error *err = NULL;
1116 if (strcmp(device, "vnc") == 0 &&
1117 (strcmp(target, "passwd") == 0 ||
1118 strcmp(target, "password") == 0)) {
1119 if (!arg) {
1120 monitor_read_password(mon, hmp_change_read_arg, NULL);
1121 return;
1125 qmp_change(device, target, !!arg, arg, &err);
1126 if (err &&
1127 error_get_class(err) == ERROR_CLASS_DEVICE_ENCRYPTED) {
1128 error_free(err);
1129 monitor_read_block_device_key(mon, device, NULL, NULL);
1130 return;
1132 hmp_handle_error(mon, &err);
1135 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
1137 Error *err = NULL;
1139 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
1140 qdict_get_int(qdict, "bps"),
1141 qdict_get_int(qdict, "bps_rd"),
1142 qdict_get_int(qdict, "bps_wr"),
1143 qdict_get_int(qdict, "iops"),
1144 qdict_get_int(qdict, "iops_rd"),
1145 qdict_get_int(qdict, "iops_wr"),
1146 false, /* no burst max via HMP */
1148 false,
1150 false,
1152 false,
1154 false,
1156 false,
1158 false, /* No default I/O size */
1159 0, &err);
1160 hmp_handle_error(mon, &err);
1163 void hmp_block_stream(Monitor *mon, const QDict *qdict)
1165 Error *error = NULL;
1166 const char *device = qdict_get_str(qdict, "device");
1167 const char *base = qdict_get_try_str(qdict, "base");
1168 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
1170 qmp_block_stream(device, base != NULL, base,
1171 qdict_haskey(qdict, "speed"), speed,
1172 true, BLOCKDEV_ON_ERROR_REPORT, &error);
1174 hmp_handle_error(mon, &error);
1177 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
1179 Error *error = NULL;
1180 const char *device = qdict_get_str(qdict, "device");
1181 int64_t value = qdict_get_int(qdict, "speed");
1183 qmp_block_job_set_speed(device, value, &error);
1185 hmp_handle_error(mon, &error);
1188 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
1190 Error *error = NULL;
1191 const char *device = qdict_get_str(qdict, "device");
1192 bool force = qdict_get_try_bool(qdict, "force", 0);
1194 qmp_block_job_cancel(device, true, force, &error);
1196 hmp_handle_error(mon, &error);
1199 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
1201 Error *error = NULL;
1202 const char *device = qdict_get_str(qdict, "device");
1204 qmp_block_job_pause(device, &error);
1206 hmp_handle_error(mon, &error);
1209 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
1211 Error *error = NULL;
1212 const char *device = qdict_get_str(qdict, "device");
1214 qmp_block_job_resume(device, &error);
1216 hmp_handle_error(mon, &error);
1219 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
1221 Error *error = NULL;
1222 const char *device = qdict_get_str(qdict, "device");
1224 qmp_block_job_complete(device, &error);
1226 hmp_handle_error(mon, &error);
1229 typedef struct MigrationStatus
1231 QEMUTimer *timer;
1232 Monitor *mon;
1233 bool is_block_migration;
1234 } MigrationStatus;
1236 static void hmp_migrate_status_cb(void *opaque)
1238 MigrationStatus *status = opaque;
1239 MigrationInfo *info;
1241 info = qmp_query_migrate(NULL);
1242 if (!info->has_status || strcmp(info->status, "active") == 0 ||
1243 strcmp(info->status, "setup") == 0) {
1244 if (info->has_disk) {
1245 int progress;
1247 if (info->disk->remaining) {
1248 progress = info->disk->transferred * 100 / info->disk->total;
1249 } else {
1250 progress = 100;
1253 monitor_printf(status->mon, "Completed %d %%\r", progress);
1254 monitor_flush(status->mon);
1257 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
1258 } else {
1259 if (status->is_block_migration) {
1260 monitor_printf(status->mon, "\n");
1262 monitor_resume(status->mon);
1263 timer_del(status->timer);
1264 g_free(status);
1267 qapi_free_MigrationInfo(info);
1270 void hmp_migrate(Monitor *mon, const QDict *qdict)
1272 int detach = qdict_get_try_bool(qdict, "detach", 0);
1273 int blk = qdict_get_try_bool(qdict, "blk", 0);
1274 int inc = qdict_get_try_bool(qdict, "inc", 0);
1275 const char *uri = qdict_get_str(qdict, "uri");
1276 Error *err = NULL;
1278 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
1279 if (err) {
1280 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
1281 error_free(err);
1282 return;
1285 if (!detach) {
1286 MigrationStatus *status;
1288 if (monitor_suspend(mon) < 0) {
1289 monitor_printf(mon, "terminal does not allow synchronous "
1290 "migration, continuing detached\n");
1291 return;
1294 status = g_malloc0(sizeof(*status));
1295 status->mon = mon;
1296 status->is_block_migration = blk || inc;
1297 status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
1298 status);
1299 timer_mod(status->timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
1303 void hmp_device_del(Monitor *mon, const QDict *qdict)
1305 const char *id = qdict_get_str(qdict, "id");
1306 Error *err = NULL;
1308 qmp_device_del(id, &err);
1309 hmp_handle_error(mon, &err);
1312 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
1314 Error *err = NULL;
1315 int paging = qdict_get_try_bool(qdict, "paging", 0);
1316 int zlib = qdict_get_try_bool(qdict, "zlib", 0);
1317 int lzo = qdict_get_try_bool(qdict, "lzo", 0);
1318 int snappy = qdict_get_try_bool(qdict, "snappy", 0);
1319 const char *file = qdict_get_str(qdict, "filename");
1320 bool has_begin = qdict_haskey(qdict, "begin");
1321 bool has_length = qdict_haskey(qdict, "length");
1322 int64_t begin = 0;
1323 int64_t length = 0;
1324 enum DumpGuestMemoryFormat dump_format = DUMP_GUEST_MEMORY_FORMAT_ELF;
1325 char *prot;
1327 if (zlib + lzo + snappy > 1) {
1328 error_setg(&err, "only one of '-z|-l|-s' can be set");
1329 hmp_handle_error(mon, &err);
1330 return;
1333 if (zlib) {
1334 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
1337 if (lzo) {
1338 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
1341 if (snappy) {
1342 dump_format = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
1345 if (has_begin) {
1346 begin = qdict_get_int(qdict, "begin");
1348 if (has_length) {
1349 length = qdict_get_int(qdict, "length");
1352 prot = g_strconcat("file:", file, NULL);
1354 qmp_dump_guest_memory(paging, prot, has_begin, begin, has_length, length,
1355 true, dump_format, &err);
1356 hmp_handle_error(mon, &err);
1357 g_free(prot);
1360 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
1362 Error *err = NULL;
1363 QemuOpts *opts;
1365 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
1366 if (err) {
1367 goto out;
1370 netdev_add(opts, &err);
1371 if (err) {
1372 qemu_opts_del(opts);
1375 out:
1376 hmp_handle_error(mon, &err);
1379 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
1381 const char *id = qdict_get_str(qdict, "id");
1382 Error *err = NULL;
1384 qmp_netdev_del(id, &err);
1385 hmp_handle_error(mon, &err);
1388 void hmp_object_add(Monitor *mon, const QDict *qdict)
1390 Error *err = NULL;
1391 QemuOpts *opts;
1392 char *type = NULL;
1393 char *id = NULL;
1394 void *dummy = NULL;
1395 OptsVisitor *ov;
1396 QDict *pdict;
1398 opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
1399 if (err) {
1400 goto out;
1403 ov = opts_visitor_new(opts);
1404 pdict = qdict_clone_shallow(qdict);
1406 visit_start_struct(opts_get_visitor(ov), &dummy, NULL, NULL, 0, &err);
1407 if (err) {
1408 goto out_clean;
1411 qdict_del(pdict, "qom-type");
1412 visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
1413 if (err) {
1414 goto out_clean;
1417 qdict_del(pdict, "id");
1418 visit_type_str(opts_get_visitor(ov), &id, "id", &err);
1419 if (err) {
1420 goto out_clean;
1423 object_add(type, id, pdict, opts_get_visitor(ov), &err);
1424 if (err) {
1425 goto out_clean;
1427 visit_end_struct(opts_get_visitor(ov), &err);
1428 if (err) {
1429 qmp_object_del(id, NULL);
1432 out_clean:
1433 opts_visitor_cleanup(ov);
1435 QDECREF(pdict);
1436 qemu_opts_del(opts);
1437 g_free(id);
1438 g_free(type);
1439 g_free(dummy);
1441 out:
1442 hmp_handle_error(mon, &err);
1445 void hmp_getfd(Monitor *mon, const QDict *qdict)
1447 const char *fdname = qdict_get_str(qdict, "fdname");
1448 Error *err = NULL;
1450 qmp_getfd(fdname, &err);
1451 hmp_handle_error(mon, &err);
1454 void hmp_closefd(Monitor *mon, const QDict *qdict)
1456 const char *fdname = qdict_get_str(qdict, "fdname");
1457 Error *err = NULL;
1459 qmp_closefd(fdname, &err);
1460 hmp_handle_error(mon, &err);
1463 void hmp_send_key(Monitor *mon, const QDict *qdict)
1465 const char *keys = qdict_get_str(qdict, "keys");
1466 KeyValueList *keylist, *head = NULL, *tmp = NULL;
1467 int has_hold_time = qdict_haskey(qdict, "hold-time");
1468 int hold_time = qdict_get_try_int(qdict, "hold-time", -1);
1469 Error *err = NULL;
1470 char keyname_buf[16];
1471 char *separator;
1472 int keyname_len;
1474 while (1) {
1475 separator = strchr(keys, '-');
1476 keyname_len = separator ? separator - keys : strlen(keys);
1477 pstrcpy(keyname_buf, sizeof(keyname_buf), keys);
1479 /* Be compatible with old interface, convert user inputted "<" */
1480 if (!strncmp(keyname_buf, "<", 1) && keyname_len == 1) {
1481 pstrcpy(keyname_buf, sizeof(keyname_buf), "less");
1482 keyname_len = 4;
1484 keyname_buf[keyname_len] = 0;
1486 keylist = g_malloc0(sizeof(*keylist));
1487 keylist->value = g_malloc0(sizeof(*keylist->value));
1489 if (!head) {
1490 head = keylist;
1492 if (tmp) {
1493 tmp->next = keylist;
1495 tmp = keylist;
1497 if (strstart(keyname_buf, "0x", NULL)) {
1498 char *endp;
1499 int value = strtoul(keyname_buf, &endp, 0);
1500 if (*endp != '\0') {
1501 goto err_out;
1503 keylist->value->kind = KEY_VALUE_KIND_NUMBER;
1504 keylist->value->number = value;
1505 } else {
1506 int idx = index_from_key(keyname_buf);
1507 if (idx == Q_KEY_CODE_MAX) {
1508 goto err_out;
1510 keylist->value->kind = KEY_VALUE_KIND_QCODE;
1511 keylist->value->qcode = idx;
1514 if (!separator) {
1515 break;
1517 keys = separator + 1;
1520 qmp_send_key(head, has_hold_time, hold_time, &err);
1521 hmp_handle_error(mon, &err);
1523 out:
1524 qapi_free_KeyValueList(head);
1525 return;
1527 err_out:
1528 monitor_printf(mon, "invalid parameter: %s\n", keyname_buf);
1529 goto out;
1532 void hmp_screen_dump(Monitor *mon, const QDict *qdict)
1534 const char *filename = qdict_get_str(qdict, "filename");
1535 Error *err = NULL;
1537 qmp_screendump(filename, &err);
1538 hmp_handle_error(mon, &err);
1541 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
1543 const char *uri = qdict_get_str(qdict, "uri");
1544 int writable = qdict_get_try_bool(qdict, "writable", 0);
1545 int all = qdict_get_try_bool(qdict, "all", 0);
1546 Error *local_err = NULL;
1547 BlockInfoList *block_list, *info;
1548 SocketAddress *addr;
1550 if (writable && !all) {
1551 error_setg(&local_err, "-w only valid together with -a");
1552 goto exit;
1555 /* First check if the address is valid and start the server. */
1556 addr = socket_parse(uri, &local_err);
1557 if (local_err != NULL) {
1558 goto exit;
1561 qmp_nbd_server_start(addr, &local_err);
1562 qapi_free_SocketAddress(addr);
1563 if (local_err != NULL) {
1564 goto exit;
1567 if (!all) {
1568 return;
1571 /* Then try adding all block devices. If one fails, close all and
1572 * exit.
1574 block_list = qmp_query_block(NULL);
1576 for (info = block_list; info; info = info->next) {
1577 if (!info->value->has_inserted) {
1578 continue;
1581 qmp_nbd_server_add(info->value->device, true, writable, &local_err);
1583 if (local_err != NULL) {
1584 qmp_nbd_server_stop(NULL);
1585 break;
1589 qapi_free_BlockInfoList(block_list);
1591 exit:
1592 hmp_handle_error(mon, &local_err);
1595 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
1597 const char *device = qdict_get_str(qdict, "device");
1598 int writable = qdict_get_try_bool(qdict, "writable", 0);
1599 Error *local_err = NULL;
1601 qmp_nbd_server_add(device, true, writable, &local_err);
1603 if (local_err != NULL) {
1604 hmp_handle_error(mon, &local_err);
1608 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
1610 Error *err = NULL;
1612 qmp_nbd_server_stop(&err);
1613 hmp_handle_error(mon, &err);
1616 void hmp_cpu_add(Monitor *mon, const QDict *qdict)
1618 int cpuid;
1619 Error *err = NULL;
1621 cpuid = qdict_get_int(qdict, "id");
1622 qmp_cpu_add(cpuid, &err);
1623 hmp_handle_error(mon, &err);
1626 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
1628 const char *args = qdict_get_str(qdict, "args");
1629 Error *err = NULL;
1630 QemuOpts *opts;
1632 opts = qemu_opts_parse(qemu_find_opts("chardev"), args, 1);
1633 if (opts == NULL) {
1634 error_setg(&err, "Parsing chardev args failed");
1635 } else {
1636 qemu_chr_new_from_opts(opts, NULL, &err);
1638 hmp_handle_error(mon, &err);
1641 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
1643 Error *local_err = NULL;
1645 qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
1646 hmp_handle_error(mon, &local_err);
1649 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
1651 BlockDriverState *bs;
1652 const char* device = qdict_get_str(qdict, "device");
1653 const char* command = qdict_get_str(qdict, "command");
1654 Error *err = NULL;
1656 bs = bdrv_find(device);
1657 if (bs) {
1658 qemuio_command(bs, command);
1659 } else {
1660 error_set(&err, QERR_DEVICE_NOT_FOUND, device);
1663 hmp_handle_error(mon, &err);
1666 void hmp_object_del(Monitor *mon, const QDict *qdict)
1668 const char *id = qdict_get_str(qdict, "id");
1669 Error *err = NULL;
1671 qmp_object_del(id, &err);
1672 hmp_handle_error(mon, &err);