pseries: Correctly create ibm,segment-page-sizes property
[qemu.git] / hmp.c
blobb9cec1dafbe1fb2c55f6f8eb4722ddc6b8d38ec4
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.h"
18 #include "qemu-option.h"
19 #include "qemu-timer.h"
20 #include "qmp-commands.h"
21 #include "monitor.h"
23 static void hmp_handle_error(Monitor *mon, Error **errp)
25 if (error_is_set(errp)) {
26 monitor_printf(mon, "%s\n", error_get_pretty(*errp));
27 error_free(*errp);
31 void hmp_info_name(Monitor *mon)
33 NameInfo *info;
35 info = qmp_query_name(NULL);
36 if (info->has_name) {
37 monitor_printf(mon, "%s\n", info->name);
39 qapi_free_NameInfo(info);
42 void hmp_info_version(Monitor *mon)
44 VersionInfo *info;
46 info = qmp_query_version(NULL);
48 monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
49 info->qemu.major, info->qemu.minor, info->qemu.micro,
50 info->package);
52 qapi_free_VersionInfo(info);
55 void hmp_info_kvm(Monitor *mon)
57 KvmInfo *info;
59 info = qmp_query_kvm(NULL);
60 monitor_printf(mon, "kvm support: ");
61 if (info->present) {
62 monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
63 } else {
64 monitor_printf(mon, "not compiled\n");
67 qapi_free_KvmInfo(info);
70 void hmp_info_status(Monitor *mon)
72 StatusInfo *info;
74 info = qmp_query_status(NULL);
76 monitor_printf(mon, "VM status: %s%s",
77 info->running ? "running" : "paused",
78 info->singlestep ? " (single step mode)" : "");
80 if (!info->running && info->status != RUN_STATE_PAUSED) {
81 monitor_printf(mon, " (%s)", RunState_lookup[info->status]);
84 monitor_printf(mon, "\n");
86 qapi_free_StatusInfo(info);
89 void hmp_info_uuid(Monitor *mon)
91 UuidInfo *info;
93 info = qmp_query_uuid(NULL);
94 monitor_printf(mon, "%s\n", info->UUID);
95 qapi_free_UuidInfo(info);
98 void hmp_info_chardev(Monitor *mon)
100 ChardevInfoList *char_info, *info;
102 char_info = qmp_query_chardev(NULL);
103 for (info = char_info; info; info = info->next) {
104 monitor_printf(mon, "%s: filename=%s\n", info->value->label,
105 info->value->filename);
108 qapi_free_ChardevInfoList(char_info);
111 void hmp_info_mice(Monitor *mon)
113 MouseInfoList *mice_list, *mouse;
115 mice_list = qmp_query_mice(NULL);
116 if (!mice_list) {
117 monitor_printf(mon, "No mouse devices connected\n");
118 return;
121 for (mouse = mice_list; mouse; mouse = mouse->next) {
122 monitor_printf(mon, "%c Mouse #%" PRId64 ": %s%s\n",
123 mouse->value->current ? '*' : ' ',
124 mouse->value->index, mouse->value->name,
125 mouse->value->absolute ? " (absolute)" : "");
128 qapi_free_MouseInfoList(mice_list);
131 void hmp_info_migrate(Monitor *mon)
133 MigrationInfo *info;
135 info = qmp_query_migrate(NULL);
137 if (info->has_status) {
138 monitor_printf(mon, "Migration status: %s\n", info->status);
141 if (info->has_ram) {
142 monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
143 info->ram->transferred >> 10);
144 monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
145 info->ram->remaining >> 10);
146 monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
147 info->ram->total >> 10);
150 if (info->has_disk) {
151 monitor_printf(mon, "transferred disk: %" PRIu64 " kbytes\n",
152 info->disk->transferred >> 10);
153 monitor_printf(mon, "remaining disk: %" PRIu64 " kbytes\n",
154 info->disk->remaining >> 10);
155 monitor_printf(mon, "total disk: %" PRIu64 " kbytes\n",
156 info->disk->total >> 10);
159 qapi_free_MigrationInfo(info);
162 void hmp_info_cpus(Monitor *mon)
164 CpuInfoList *cpu_list, *cpu;
166 cpu_list = qmp_query_cpus(NULL);
168 for (cpu = cpu_list; cpu; cpu = cpu->next) {
169 int active = ' ';
171 if (cpu->value->CPU == monitor_get_cpu_index()) {
172 active = '*';
175 monitor_printf(mon, "%c CPU #%" PRId64 ": ", active, cpu->value->CPU);
177 if (cpu->value->has_pc) {
178 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
180 if (cpu->value->has_nip) {
181 monitor_printf(mon, "nip=0x%016" PRIx64, cpu->value->nip);
183 if (cpu->value->has_npc) {
184 monitor_printf(mon, "pc=0x%016" PRIx64, cpu->value->pc);
185 monitor_printf(mon, "npc=0x%016" PRIx64, cpu->value->npc);
187 if (cpu->value->has_PC) {
188 monitor_printf(mon, "PC=0x%016" PRIx64, cpu->value->PC);
191 if (cpu->value->halted) {
192 monitor_printf(mon, " (halted)");
195 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
198 qapi_free_CpuInfoList(cpu_list);
201 void hmp_info_block(Monitor *mon)
203 BlockInfoList *block_list, *info;
205 block_list = qmp_query_block(NULL);
207 for (info = block_list; info; info = info->next) {
208 monitor_printf(mon, "%s: removable=%d",
209 info->value->device, info->value->removable);
211 if (info->value->removable) {
212 monitor_printf(mon, " locked=%d", info->value->locked);
213 monitor_printf(mon, " tray-open=%d", info->value->tray_open);
216 if (info->value->has_io_status) {
217 monitor_printf(mon, " io-status=%s",
218 BlockDeviceIoStatus_lookup[info->value->io_status]);
221 if (info->value->has_inserted) {
222 monitor_printf(mon, " file=");
223 monitor_print_filename(mon, info->value->inserted->file);
225 if (info->value->inserted->has_backing_file) {
226 monitor_printf(mon, " backing_file=");
227 monitor_print_filename(mon, info->value->inserted->backing_file);
229 monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
230 info->value->inserted->ro,
231 info->value->inserted->drv,
232 info->value->inserted->encrypted);
234 monitor_printf(mon, " bps=%" PRId64 " bps_rd=%" PRId64
235 " bps_wr=%" PRId64 " iops=%" PRId64
236 " iops_rd=%" PRId64 " iops_wr=%" PRId64,
237 info->value->inserted->bps,
238 info->value->inserted->bps_rd,
239 info->value->inserted->bps_wr,
240 info->value->inserted->iops,
241 info->value->inserted->iops_rd,
242 info->value->inserted->iops_wr);
243 } else {
244 monitor_printf(mon, " [not inserted]");
247 monitor_printf(mon, "\n");
250 qapi_free_BlockInfoList(block_list);
253 void hmp_info_blockstats(Monitor *mon)
255 BlockStatsList *stats_list, *stats;
257 stats_list = qmp_query_blockstats(NULL);
259 for (stats = stats_list; stats; stats = stats->next) {
260 if (!stats->value->has_device) {
261 continue;
264 monitor_printf(mon, "%s:", stats->value->device);
265 monitor_printf(mon, " rd_bytes=%" PRId64
266 " wr_bytes=%" PRId64
267 " rd_operations=%" PRId64
268 " wr_operations=%" PRId64
269 " flush_operations=%" PRId64
270 " wr_total_time_ns=%" PRId64
271 " rd_total_time_ns=%" PRId64
272 " flush_total_time_ns=%" PRId64
273 "\n",
274 stats->value->stats->rd_bytes,
275 stats->value->stats->wr_bytes,
276 stats->value->stats->rd_operations,
277 stats->value->stats->wr_operations,
278 stats->value->stats->flush_operations,
279 stats->value->stats->wr_total_time_ns,
280 stats->value->stats->rd_total_time_ns,
281 stats->value->stats->flush_total_time_ns);
284 qapi_free_BlockStatsList(stats_list);
287 void hmp_info_vnc(Monitor *mon)
289 VncInfo *info;
290 Error *err = NULL;
291 VncClientInfoList *client;
293 info = qmp_query_vnc(&err);
294 if (err) {
295 monitor_printf(mon, "%s\n", error_get_pretty(err));
296 error_free(err);
297 return;
300 if (!info->enabled) {
301 monitor_printf(mon, "Server: disabled\n");
302 goto out;
305 monitor_printf(mon, "Server:\n");
306 if (info->has_host && info->has_service) {
307 monitor_printf(mon, " address: %s:%s\n", info->host, info->service);
309 if (info->has_auth) {
310 monitor_printf(mon, " auth: %s\n", info->auth);
313 if (!info->has_clients || info->clients == NULL) {
314 monitor_printf(mon, "Client: none\n");
315 } else {
316 for (client = info->clients; client; client = client->next) {
317 monitor_printf(mon, "Client:\n");
318 monitor_printf(mon, " address: %s:%s\n",
319 client->value->host, client->value->service);
320 monitor_printf(mon, " x509_dname: %s\n",
321 client->value->x509_dname ?
322 client->value->x509_dname : "none");
323 monitor_printf(mon, " username: %s\n",
324 client->value->has_sasl_username ?
325 client->value->sasl_username : "none");
329 out:
330 qapi_free_VncInfo(info);
333 void hmp_info_spice(Monitor *mon)
335 SpiceChannelList *chan;
336 SpiceInfo *info;
338 info = qmp_query_spice(NULL);
340 if (!info->enabled) {
341 monitor_printf(mon, "Server: disabled\n");
342 goto out;
345 monitor_printf(mon, "Server:\n");
346 if (info->has_port) {
347 monitor_printf(mon, " address: %s:%" PRId64 "\n",
348 info->host, info->port);
350 if (info->has_tls_port) {
351 monitor_printf(mon, " address: %s:%" PRId64 " [tls]\n",
352 info->host, info->tls_port);
354 monitor_printf(mon, " auth: %s\n", info->auth);
355 monitor_printf(mon, " compiled: %s\n", info->compiled_version);
356 monitor_printf(mon, " mouse-mode: %s\n",
357 SpiceQueryMouseMode_lookup[info->mouse_mode]);
359 if (!info->has_channels || info->channels == NULL) {
360 monitor_printf(mon, "Channels: none\n");
361 } else {
362 for (chan = info->channels; chan; chan = chan->next) {
363 monitor_printf(mon, "Channel:\n");
364 monitor_printf(mon, " address: %s:%s%s\n",
365 chan->value->host, chan->value->port,
366 chan->value->tls ? " [tls]" : "");
367 monitor_printf(mon, " session: %" PRId64 "\n",
368 chan->value->connection_id);
369 monitor_printf(mon, " channel: %" PRId64 ":%" PRId64 "\n",
370 chan->value->channel_type, chan->value->channel_id);
374 out:
375 qapi_free_SpiceInfo(info);
378 void hmp_info_balloon(Monitor *mon)
380 BalloonInfo *info;
381 Error *err = NULL;
383 info = qmp_query_balloon(&err);
384 if (err) {
385 monitor_printf(mon, "%s\n", error_get_pretty(err));
386 error_free(err);
387 return;
390 monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
391 if (info->has_mem_swapped_in) {
392 monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
394 if (info->has_mem_swapped_out) {
395 monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
397 if (info->has_major_page_faults) {
398 monitor_printf(mon, " major_page_faults=%" PRId64,
399 info->major_page_faults);
401 if (info->has_minor_page_faults) {
402 monitor_printf(mon, " minor_page_faults=%" PRId64,
403 info->minor_page_faults);
405 if (info->has_free_mem) {
406 monitor_printf(mon, " free_mem=%" PRId64, info->free_mem);
408 if (info->has_total_mem) {
409 monitor_printf(mon, " total_mem=%" PRId64, info->total_mem);
412 monitor_printf(mon, "\n");
414 qapi_free_BalloonInfo(info);
417 static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
419 PciMemoryRegionList *region;
421 monitor_printf(mon, " Bus %2" PRId64 ", ", dev->bus);
422 monitor_printf(mon, "device %3" PRId64 ", function %" PRId64 ":\n",
423 dev->slot, dev->function);
424 monitor_printf(mon, " ");
426 if (dev->class_info.has_desc) {
427 monitor_printf(mon, "%s", dev->class_info.desc);
428 } else {
429 monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
432 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
433 dev->id.vendor, dev->id.device);
435 if (dev->has_irq) {
436 monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
439 if (dev->has_pci_bridge) {
440 monitor_printf(mon, " BUS %" PRId64 ".\n",
441 dev->pci_bridge->bus.number);
442 monitor_printf(mon, " secondary bus %" PRId64 ".\n",
443 dev->pci_bridge->bus.secondary);
444 monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
445 dev->pci_bridge->bus.subordinate);
447 monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
448 dev->pci_bridge->bus.io_range->base,
449 dev->pci_bridge->bus.io_range->limit);
451 monitor_printf(mon,
452 " memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
453 dev->pci_bridge->bus.memory_range->base,
454 dev->pci_bridge->bus.memory_range->limit);
456 monitor_printf(mon, " prefetchable memory range "
457 "[0x%08"PRIx64", 0x%08"PRIx64"]\n",
458 dev->pci_bridge->bus.prefetchable_range->base,
459 dev->pci_bridge->bus.prefetchable_range->limit);
462 for (region = dev->regions; region; region = region->next) {
463 uint64_t addr, size;
465 addr = region->value->address;
466 size = region->value->size;
468 monitor_printf(mon, " BAR%" PRId64 ": ", region->value->bar);
470 if (!strcmp(region->value->type, "io")) {
471 monitor_printf(mon, "I/O at 0x%04" PRIx64
472 " [0x%04" PRIx64 "].\n",
473 addr, addr + size - 1);
474 } else {
475 monitor_printf(mon, "%d bit%s memory at 0x%08" PRIx64
476 " [0x%08" PRIx64 "].\n",
477 region->value->mem_type_64 ? 64 : 32,
478 region->value->prefetch ? " prefetchable" : "",
479 addr, addr + size - 1);
483 monitor_printf(mon, " id \"%s\"\n", dev->qdev_id);
485 if (dev->has_pci_bridge) {
486 if (dev->pci_bridge->has_devices) {
487 PciDeviceInfoList *cdev;
488 for (cdev = dev->pci_bridge->devices; cdev; cdev = cdev->next) {
489 hmp_info_pci_device(mon, cdev->value);
495 void hmp_info_pci(Monitor *mon)
497 PciInfoList *info_list, *info;
498 Error *err = NULL;
500 info_list = qmp_query_pci(&err);
501 if (err) {
502 monitor_printf(mon, "PCI devices not supported\n");
503 error_free(err);
504 return;
507 for (info = info_list; info; info = info->next) {
508 PciDeviceInfoList *dev;
510 for (dev = info->value->devices; dev; dev = dev->next) {
511 hmp_info_pci_device(mon, dev->value);
515 qapi_free_PciInfoList(info_list);
518 void hmp_info_block_jobs(Monitor *mon)
520 BlockJobInfoList *list;
521 Error *err = NULL;
523 list = qmp_query_block_jobs(&err);
524 assert(!err);
526 if (!list) {
527 monitor_printf(mon, "No active jobs\n");
528 return;
531 while (list) {
532 if (strcmp(list->value->type, "stream") == 0) {
533 monitor_printf(mon, "Streaming device %s: Completed %" PRId64
534 " of %" PRId64 " bytes, speed limit %" PRId64
535 " bytes/s\n",
536 list->value->device,
537 list->value->offset,
538 list->value->len,
539 list->value->speed);
540 } else {
541 monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
542 " of %" PRId64 " bytes, speed limit %" PRId64
543 " bytes/s\n",
544 list->value->type,
545 list->value->device,
546 list->value->offset,
547 list->value->len,
548 list->value->speed);
550 list = list->next;
554 void hmp_quit(Monitor *mon, const QDict *qdict)
556 monitor_suspend(mon);
557 qmp_quit(NULL);
560 void hmp_stop(Monitor *mon, const QDict *qdict)
562 qmp_stop(NULL);
565 void hmp_system_reset(Monitor *mon, const QDict *qdict)
567 qmp_system_reset(NULL);
570 void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
572 qmp_system_powerdown(NULL);
575 void hmp_cpu(Monitor *mon, const QDict *qdict)
577 int64_t cpu_index;
579 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
580 use it are converted to the QAPI */
581 cpu_index = qdict_get_int(qdict, "index");
582 if (monitor_set_cpu(cpu_index) < 0) {
583 monitor_printf(mon, "invalid CPU index\n");
587 void hmp_memsave(Monitor *mon, const QDict *qdict)
589 uint32_t size = qdict_get_int(qdict, "size");
590 const char *filename = qdict_get_str(qdict, "filename");
591 uint64_t addr = qdict_get_int(qdict, "val");
592 Error *errp = NULL;
594 qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
595 hmp_handle_error(mon, &errp);
598 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
600 uint32_t size = qdict_get_int(qdict, "size");
601 const char *filename = qdict_get_str(qdict, "filename");
602 uint64_t addr = qdict_get_int(qdict, "val");
603 Error *errp = NULL;
605 qmp_pmemsave(addr, size, filename, &errp);
606 hmp_handle_error(mon, &errp);
609 static void hmp_cont_cb(void *opaque, int err)
611 Monitor *mon = opaque;
613 if (!err) {
614 hmp_cont(mon, NULL);
618 void hmp_cont(Monitor *mon, const QDict *qdict)
620 Error *errp = NULL;
622 qmp_cont(&errp);
623 if (error_is_set(&errp)) {
624 if (error_is_type(errp, QERR_DEVICE_ENCRYPTED)) {
625 const char *device;
627 /* The device is encrypted. Ask the user for the password
628 and retry */
630 device = error_get_field(errp, "device");
631 assert(device != NULL);
633 monitor_read_block_device_key(mon, device, hmp_cont_cb, mon);
634 error_free(errp);
635 return;
637 hmp_handle_error(mon, &errp);
641 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
643 qmp_system_wakeup(NULL);
646 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
648 Error *errp = NULL;
650 qmp_inject_nmi(&errp);
651 hmp_handle_error(mon, &errp);
654 void hmp_set_link(Monitor *mon, const QDict *qdict)
656 const char *name = qdict_get_str(qdict, "name");
657 int up = qdict_get_bool(qdict, "up");
658 Error *errp = NULL;
660 qmp_set_link(name, up, &errp);
661 hmp_handle_error(mon, &errp);
664 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
666 const char *device = qdict_get_str(qdict, "device");
667 const char *password = qdict_get_str(qdict, "password");
668 Error *errp = NULL;
670 qmp_block_passwd(device, password, &errp);
671 hmp_handle_error(mon, &errp);
674 void hmp_balloon(Monitor *mon, const QDict *qdict)
676 int64_t value = qdict_get_int(qdict, "value");
677 Error *errp = NULL;
679 qmp_balloon(value, &errp);
680 if (error_is_set(&errp)) {
681 monitor_printf(mon, "balloon: %s\n", error_get_pretty(errp));
682 error_free(errp);
686 void hmp_block_resize(Monitor *mon, const QDict *qdict)
688 const char *device = qdict_get_str(qdict, "device");
689 int64_t size = qdict_get_int(qdict, "size");
690 Error *errp = NULL;
692 qmp_block_resize(device, size, &errp);
693 hmp_handle_error(mon, &errp);
696 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
698 const char *device = qdict_get_str(qdict, "device");
699 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
700 const char *format = qdict_get_try_str(qdict, "format");
701 int reuse = qdict_get_try_bool(qdict, "reuse", 0);
702 enum NewImageMode mode;
703 Error *errp = NULL;
705 if (!filename) {
706 /* In the future, if 'snapshot-file' is not specified, the snapshot
707 will be taken internally. Today it's actually required. */
708 error_set(&errp, QERR_MISSING_PARAMETER, "snapshot-file");
709 hmp_handle_error(mon, &errp);
710 return;
713 mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
714 qmp_blockdev_snapshot_sync(device, filename, !!format, format,
715 true, mode, &errp);
716 hmp_handle_error(mon, &errp);
719 void hmp_migrate_cancel(Monitor *mon, const QDict *qdict)
721 qmp_migrate_cancel(NULL);
724 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict)
726 double value = qdict_get_double(qdict, "value");
727 qmp_migrate_set_downtime(value, NULL);
730 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
732 int64_t value = qdict_get_int(qdict, "value");
733 qmp_migrate_set_speed(value, NULL);
736 void hmp_set_password(Monitor *mon, const QDict *qdict)
738 const char *protocol = qdict_get_str(qdict, "protocol");
739 const char *password = qdict_get_str(qdict, "password");
740 const char *connected = qdict_get_try_str(qdict, "connected");
741 Error *err = NULL;
743 qmp_set_password(protocol, password, !!connected, connected, &err);
744 hmp_handle_error(mon, &err);
747 void hmp_expire_password(Monitor *mon, const QDict *qdict)
749 const char *protocol = qdict_get_str(qdict, "protocol");
750 const char *whenstr = qdict_get_str(qdict, "time");
751 Error *err = NULL;
753 qmp_expire_password(protocol, whenstr, &err);
754 hmp_handle_error(mon, &err);
757 void hmp_eject(Monitor *mon, const QDict *qdict)
759 int force = qdict_get_try_bool(qdict, "force", 0);
760 const char *device = qdict_get_str(qdict, "device");
761 Error *err = NULL;
763 qmp_eject(device, true, force, &err);
764 hmp_handle_error(mon, &err);
767 static void hmp_change_read_arg(Monitor *mon, const char *password,
768 void *opaque)
770 qmp_change_vnc_password(password, NULL);
771 monitor_read_command(mon, 1);
774 static void cb_hmp_change_bdrv_pwd(Monitor *mon, const char *password,
775 void *opaque)
777 Error *encryption_err = opaque;
778 Error *err = NULL;
779 const char *device;
781 device = error_get_field(encryption_err, "device");
783 qmp_block_passwd(device, password, &err);
784 hmp_handle_error(mon, &err);
785 error_free(encryption_err);
787 monitor_read_command(mon, 1);
790 void hmp_change(Monitor *mon, const QDict *qdict)
792 const char *device = qdict_get_str(qdict, "device");
793 const char *target = qdict_get_str(qdict, "target");
794 const char *arg = qdict_get_try_str(qdict, "arg");
795 Error *err = NULL;
797 if (strcmp(device, "vnc") == 0 &&
798 (strcmp(target, "passwd") == 0 ||
799 strcmp(target, "password") == 0)) {
800 if (!arg) {
801 monitor_read_password(mon, hmp_change_read_arg, NULL);
802 return;
806 qmp_change(device, target, !!arg, arg, &err);
807 if (error_is_type(err, QERR_DEVICE_ENCRYPTED)) {
808 monitor_printf(mon, "%s (%s) is encrypted.\n",
809 error_get_field(err, "device"),
810 error_get_field(err, "filename"));
811 if (!monitor_get_rs(mon)) {
812 monitor_printf(mon,
813 "terminal does not support password prompting\n");
814 error_free(err);
815 return;
817 readline_start(monitor_get_rs(mon), "Password: ", 1,
818 cb_hmp_change_bdrv_pwd, err);
819 return;
821 hmp_handle_error(mon, &err);
824 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
826 Error *err = NULL;
828 qmp_block_set_io_throttle(qdict_get_str(qdict, "device"),
829 qdict_get_int(qdict, "bps"),
830 qdict_get_int(qdict, "bps_rd"),
831 qdict_get_int(qdict, "bps_wr"),
832 qdict_get_int(qdict, "iops"),
833 qdict_get_int(qdict, "iops_rd"),
834 qdict_get_int(qdict, "iops_wr"), &err);
835 hmp_handle_error(mon, &err);
838 void hmp_block_stream(Monitor *mon, const QDict *qdict)
840 Error *error = NULL;
841 const char *device = qdict_get_str(qdict, "device");
842 const char *base = qdict_get_try_str(qdict, "base");
843 int64_t speed = qdict_get_try_int(qdict, "speed", 0);
845 qmp_block_stream(device, base != NULL, base,
846 qdict_haskey(qdict, "speed"), speed, &error);
848 hmp_handle_error(mon, &error);
851 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
853 Error *error = NULL;
854 const char *device = qdict_get_str(qdict, "device");
855 int64_t value = qdict_get_int(qdict, "speed");
857 qmp_block_job_set_speed(device, value, &error);
859 hmp_handle_error(mon, &error);
862 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
864 Error *error = NULL;
865 const char *device = qdict_get_str(qdict, "device");
867 qmp_block_job_cancel(device, &error);
869 hmp_handle_error(mon, &error);
872 typedef struct MigrationStatus
874 QEMUTimer *timer;
875 Monitor *mon;
876 bool is_block_migration;
877 } MigrationStatus;
879 static void hmp_migrate_status_cb(void *opaque)
881 MigrationStatus *status = opaque;
882 MigrationInfo *info;
884 info = qmp_query_migrate(NULL);
885 if (!info->has_status || strcmp(info->status, "active") == 0) {
886 if (info->has_disk) {
887 int progress;
889 if (info->disk->remaining) {
890 progress = info->disk->transferred * 100 / info->disk->total;
891 } else {
892 progress = 100;
895 monitor_printf(status->mon, "Completed %d %%\r", progress);
896 monitor_flush(status->mon);
899 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock) + 1000);
900 } else {
901 if (status->is_block_migration) {
902 monitor_printf(status->mon, "\n");
904 monitor_resume(status->mon);
905 qemu_del_timer(status->timer);
906 g_free(status);
909 qapi_free_MigrationInfo(info);
912 void hmp_migrate(Monitor *mon, const QDict *qdict)
914 int detach = qdict_get_try_bool(qdict, "detach", 0);
915 int blk = qdict_get_try_bool(qdict, "blk", 0);
916 int inc = qdict_get_try_bool(qdict, "inc", 0);
917 const char *uri = qdict_get_str(qdict, "uri");
918 Error *err = NULL;
920 qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, &err);
921 if (err) {
922 monitor_printf(mon, "migrate: %s\n", error_get_pretty(err));
923 error_free(err);
924 return;
927 if (!detach) {
928 MigrationStatus *status;
930 if (monitor_suspend(mon) < 0) {
931 monitor_printf(mon, "terminal does not allow synchronous "
932 "migration, continuing detached\n");
933 return;
936 status = g_malloc0(sizeof(*status));
937 status->mon = mon;
938 status->is_block_migration = blk || inc;
939 status->timer = qemu_new_timer_ms(rt_clock, hmp_migrate_status_cb,
940 status);
941 qemu_mod_timer(status->timer, qemu_get_clock_ms(rt_clock));
945 void hmp_device_del(Monitor *mon, const QDict *qdict)
947 const char *id = qdict_get_str(qdict, "id");
948 Error *err = NULL;
950 qmp_device_del(id, &err);
951 hmp_handle_error(mon, &err);
954 void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
956 Error *errp = NULL;
957 int paging = qdict_get_try_bool(qdict, "paging", 0);
958 const char *file = qdict_get_str(qdict, "protocol");
959 bool has_begin = qdict_haskey(qdict, "begin");
960 bool has_length = qdict_haskey(qdict, "length");
961 int64_t begin = 0;
962 int64_t length = 0;
964 if (has_begin) {
965 begin = qdict_get_int(qdict, "begin");
967 if (has_length) {
968 length = qdict_get_int(qdict, "length");
971 qmp_dump_guest_memory(paging, file, has_begin, begin, has_length, length,
972 &errp);
973 hmp_handle_error(mon, &errp);
976 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
978 Error *err = NULL;
979 QemuOpts *opts;
981 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
982 if (error_is_set(&err)) {
983 goto out;
986 netdev_add(opts, &err);
987 if (error_is_set(&err)) {
988 qemu_opts_del(opts);
991 out:
992 hmp_handle_error(mon, &err);
995 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
997 const char *id = qdict_get_str(qdict, "id");
998 Error *err = NULL;
1000 qmp_netdev_del(id, &err);
1001 hmp_handle_error(mon, &err);