2 * Human Monitor Interface
4 * Copyright IBM, Corp. 2011
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.
17 #include "qemu-timer.h"
18 #include "qmp-commands.h"
20 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
22 if (error_is_set(errp
)) {
23 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
28 void hmp_info_name(Monitor
*mon
)
32 info
= qmp_query_name(NULL
);
34 monitor_printf(mon
, "%s\n", info
->name
);
36 qapi_free_NameInfo(info
);
39 void hmp_info_version(Monitor
*mon
)
43 info
= qmp_query_version(NULL
);
45 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
46 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
49 qapi_free_VersionInfo(info
);
52 void hmp_info_kvm(Monitor
*mon
)
56 info
= qmp_query_kvm(NULL
);
57 monitor_printf(mon
, "kvm support: ");
59 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
61 monitor_printf(mon
, "not compiled\n");
64 qapi_free_KvmInfo(info
);
67 void hmp_info_status(Monitor
*mon
)
71 info
= qmp_query_status(NULL
);
73 monitor_printf(mon
, "VM status: %s%s",
74 info
->running
? "running" : "paused",
75 info
->singlestep
? " (single step mode)" : "");
77 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
78 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
81 monitor_printf(mon
, "\n");
83 qapi_free_StatusInfo(info
);
86 void hmp_info_uuid(Monitor
*mon
)
90 info
= qmp_query_uuid(NULL
);
91 monitor_printf(mon
, "%s\n", info
->UUID
);
92 qapi_free_UuidInfo(info
);
95 void hmp_info_chardev(Monitor
*mon
)
97 ChardevInfoList
*char_info
, *info
;
99 char_info
= qmp_query_chardev(NULL
);
100 for (info
= char_info
; info
; info
= info
->next
) {
101 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
102 info
->value
->filename
);
105 qapi_free_ChardevInfoList(char_info
);
108 void hmp_info_mice(Monitor
*mon
)
110 MouseInfoList
*mice_list
, *mouse
;
112 mice_list
= qmp_query_mice(NULL
);
114 monitor_printf(mon
, "No mouse devices connected\n");
118 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
119 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
120 mouse
->value
->current
? '*' : ' ',
121 mouse
->value
->index
, mouse
->value
->name
,
122 mouse
->value
->absolute
? " (absolute)" : "");
125 qapi_free_MouseInfoList(mice_list
);
128 void hmp_info_migrate(Monitor
*mon
)
132 info
= qmp_query_migrate(NULL
);
134 if (info
->has_status
) {
135 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
139 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
140 info
->ram
->transferred
>> 10);
141 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
142 info
->ram
->remaining
>> 10);
143 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
144 info
->ram
->total
>> 10);
147 if (info
->has_disk
) {
148 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
149 info
->disk
->transferred
>> 10);
150 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
151 info
->disk
->remaining
>> 10);
152 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
153 info
->disk
->total
>> 10);
156 qapi_free_MigrationInfo(info
);
159 void hmp_info_cpus(Monitor
*mon
)
161 CpuInfoList
*cpu_list
, *cpu
;
163 cpu_list
= qmp_query_cpus(NULL
);
165 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
168 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
172 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
174 if (cpu
->value
->has_pc
) {
175 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
177 if (cpu
->value
->has_nip
) {
178 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
180 if (cpu
->value
->has_npc
) {
181 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
182 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
184 if (cpu
->value
->has_PC
) {
185 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
188 if (cpu
->value
->halted
) {
189 monitor_printf(mon
, " (halted)");
192 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
195 qapi_free_CpuInfoList(cpu_list
);
198 void hmp_info_block(Monitor
*mon
)
200 BlockInfoList
*block_list
, *info
;
202 block_list
= qmp_query_block(NULL
);
204 for (info
= block_list
; info
; info
= info
->next
) {
205 monitor_printf(mon
, "%s: removable=%d",
206 info
->value
->device
, info
->value
->removable
);
208 if (info
->value
->removable
) {
209 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
210 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
213 if (info
->value
->has_io_status
) {
214 monitor_printf(mon
, " io-status=%s",
215 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
218 if (info
->value
->has_inserted
) {
219 monitor_printf(mon
, " file=");
220 monitor_print_filename(mon
, info
->value
->inserted
->file
);
222 if (info
->value
->inserted
->has_backing_file
) {
223 monitor_printf(mon
, " backing_file=");
224 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
226 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
227 info
->value
->inserted
->ro
,
228 info
->value
->inserted
->drv
,
229 info
->value
->inserted
->encrypted
);
231 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
232 " bps_wr=%" PRId64
" iops=%" PRId64
233 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
234 info
->value
->inserted
->bps
,
235 info
->value
->inserted
->bps_rd
,
236 info
->value
->inserted
->bps_wr
,
237 info
->value
->inserted
->iops
,
238 info
->value
->inserted
->iops_rd
,
239 info
->value
->inserted
->iops_wr
);
241 monitor_printf(mon
, " [not inserted]");
244 monitor_printf(mon
, "\n");
247 qapi_free_BlockInfoList(block_list
);
250 void hmp_info_blockstats(Monitor
*mon
)
252 BlockStatsList
*stats_list
, *stats
;
254 stats_list
= qmp_query_blockstats(NULL
);
256 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
257 if (!stats
->value
->has_device
) {
261 monitor_printf(mon
, "%s:", stats
->value
->device
);
262 monitor_printf(mon
, " rd_bytes=%" PRId64
264 " rd_operations=%" PRId64
265 " wr_operations=%" PRId64
266 " flush_operations=%" PRId64
267 " wr_total_time_ns=%" PRId64
268 " rd_total_time_ns=%" PRId64
269 " flush_total_time_ns=%" PRId64
271 stats
->value
->stats
->rd_bytes
,
272 stats
->value
->stats
->wr_bytes
,
273 stats
->value
->stats
->rd_operations
,
274 stats
->value
->stats
->wr_operations
,
275 stats
->value
->stats
->flush_operations
,
276 stats
->value
->stats
->wr_total_time_ns
,
277 stats
->value
->stats
->rd_total_time_ns
,
278 stats
->value
->stats
->flush_total_time_ns
);
281 qapi_free_BlockStatsList(stats_list
);
284 void hmp_info_vnc(Monitor
*mon
)
288 VncClientInfoList
*client
;
290 info
= qmp_query_vnc(&err
);
292 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
297 if (!info
->enabled
) {
298 monitor_printf(mon
, "Server: disabled\n");
302 monitor_printf(mon
, "Server:\n");
303 if (info
->has_host
&& info
->has_service
) {
304 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
306 if (info
->has_auth
) {
307 monitor_printf(mon
, " auth: %s\n", info
->auth
);
310 if (!info
->has_clients
|| info
->clients
== NULL
) {
311 monitor_printf(mon
, "Client: none\n");
313 for (client
= info
->clients
; client
; client
= client
->next
) {
314 monitor_printf(mon
, "Client:\n");
315 monitor_printf(mon
, " address: %s:%s\n",
316 client
->value
->host
, client
->value
->service
);
317 monitor_printf(mon
, " x509_dname: %s\n",
318 client
->value
->x509_dname
?
319 client
->value
->x509_dname
: "none");
320 monitor_printf(mon
, " username: %s\n",
321 client
->value
->has_sasl_username
?
322 client
->value
->sasl_username
: "none");
327 qapi_free_VncInfo(info
);
330 void hmp_info_spice(Monitor
*mon
)
332 SpiceChannelList
*chan
;
335 info
= qmp_query_spice(NULL
);
337 if (!info
->enabled
) {
338 monitor_printf(mon
, "Server: disabled\n");
342 monitor_printf(mon
, "Server:\n");
343 if (info
->has_port
) {
344 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
345 info
->host
, info
->port
);
347 if (info
->has_tls_port
) {
348 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
349 info
->host
, info
->tls_port
);
351 monitor_printf(mon
, " auth: %s\n", info
->auth
);
352 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
354 if (!info
->has_channels
|| info
->channels
== NULL
) {
355 monitor_printf(mon
, "Channels: none\n");
357 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
358 monitor_printf(mon
, "Channel:\n");
359 monitor_printf(mon
, " address: %s:%s%s\n",
360 chan
->value
->host
, chan
->value
->port
,
361 chan
->value
->tls
? " [tls]" : "");
362 monitor_printf(mon
, " session: %" PRId64
"\n",
363 chan
->value
->connection_id
);
364 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
365 chan
->value
->channel_type
, chan
->value
->channel_id
);
370 qapi_free_SpiceInfo(info
);
373 void hmp_info_balloon(Monitor
*mon
)
378 info
= qmp_query_balloon(&err
);
380 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
385 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
386 if (info
->has_mem_swapped_in
) {
387 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
389 if (info
->has_mem_swapped_out
) {
390 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
392 if (info
->has_major_page_faults
) {
393 monitor_printf(mon
, " major_page_faults=%" PRId64
,
394 info
->major_page_faults
);
396 if (info
->has_minor_page_faults
) {
397 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
398 info
->minor_page_faults
);
400 if (info
->has_free_mem
) {
401 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
403 if (info
->has_total_mem
) {
404 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
407 monitor_printf(mon
, "\n");
409 qapi_free_BalloonInfo(info
);
412 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
414 PciMemoryRegionList
*region
;
416 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
417 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
418 dev
->slot
, dev
->function
);
419 monitor_printf(mon
, " ");
421 if (dev
->class_info
.has_desc
) {
422 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
424 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
427 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
428 dev
->id
.vendor
, dev
->id
.device
);
431 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
434 if (dev
->has_pci_bridge
) {
435 monitor_printf(mon
, " BUS %" PRId64
".\n",
436 dev
->pci_bridge
->bus
.number
);
437 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
438 dev
->pci_bridge
->bus
.secondary
);
439 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
440 dev
->pci_bridge
->bus
.subordinate
);
442 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
443 dev
->pci_bridge
->bus
.io_range
->base
,
444 dev
->pci_bridge
->bus
.io_range
->limit
);
447 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
448 dev
->pci_bridge
->bus
.memory_range
->base
,
449 dev
->pci_bridge
->bus
.memory_range
->limit
);
451 monitor_printf(mon
, " prefetchable memory range "
452 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
453 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
454 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
457 for (region
= dev
->regions
; region
; region
= region
->next
) {
460 addr
= region
->value
->address
;
461 size
= region
->value
->size
;
463 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
465 if (!strcmp(region
->value
->type
, "io")) {
466 monitor_printf(mon
, "I/O at 0x%04" PRIx64
467 " [0x%04" PRIx64
"].\n",
468 addr
, addr
+ size
- 1);
470 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
471 " [0x%08" PRIx64
"].\n",
472 region
->value
->mem_type_64
? 64 : 32,
473 region
->value
->prefetch
? " prefetchable" : "",
474 addr
, addr
+ size
- 1);
478 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
480 if (dev
->has_pci_bridge
) {
481 if (dev
->pci_bridge
->has_devices
) {
482 PciDeviceInfoList
*cdev
;
483 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
484 hmp_info_pci_device(mon
, cdev
->value
);
490 void hmp_info_pci(Monitor
*mon
)
492 PciInfoList
*info_list
, *info
;
495 info_list
= qmp_query_pci(&err
);
497 monitor_printf(mon
, "PCI devices not supported\n");
502 for (info
= info_list
; info
; info
= info
->next
) {
503 PciDeviceInfoList
*dev
;
505 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
506 hmp_info_pci_device(mon
, dev
->value
);
510 qapi_free_PciInfoList(info_list
);
513 void hmp_info_block_jobs(Monitor
*mon
)
515 BlockJobInfoList
*list
;
518 list
= qmp_query_block_jobs(&err
);
522 monitor_printf(mon
, "No active jobs\n");
527 if (strcmp(list
->value
->type
, "stream") == 0) {
528 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
529 " of %" PRId64
" bytes, speed limit %" PRId64
536 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
537 " of %" PRId64
" bytes, speed limit %" PRId64
549 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
551 monitor_suspend(mon
);
555 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
560 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
562 qmp_system_reset(NULL
);
565 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
567 qmp_system_powerdown(NULL
);
570 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
574 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
575 use it are converted to the QAPI */
576 cpu_index
= qdict_get_int(qdict
, "index");
577 if (monitor_set_cpu(cpu_index
) < 0) {
578 monitor_printf(mon
, "invalid CPU index\n");
582 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
584 uint32_t size
= qdict_get_int(qdict
, "size");
585 const char *filename
= qdict_get_str(qdict
, "filename");
586 uint64_t addr
= qdict_get_int(qdict
, "val");
589 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
590 hmp_handle_error(mon
, &errp
);
593 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
595 uint32_t size
= qdict_get_int(qdict
, "size");
596 const char *filename
= qdict_get_str(qdict
, "filename");
597 uint64_t addr
= qdict_get_int(qdict
, "val");
600 qmp_pmemsave(addr
, size
, filename
, &errp
);
601 hmp_handle_error(mon
, &errp
);
604 static void hmp_cont_cb(void *opaque
, int err
)
606 Monitor
*mon
= opaque
;
613 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
618 if (error_is_set(&errp
)) {
619 if (error_is_type(errp
, QERR_DEVICE_ENCRYPTED
)) {
622 /* The device is encrypted. Ask the user for the password
625 device
= error_get_field(errp
, "device");
626 assert(device
!= NULL
);
628 monitor_read_block_device_key(mon
, device
, hmp_cont_cb
, mon
);
632 hmp_handle_error(mon
, &errp
);
636 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
638 qmp_system_wakeup(NULL
);
641 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
645 qmp_inject_nmi(&errp
);
646 hmp_handle_error(mon
, &errp
);
649 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
651 const char *name
= qdict_get_str(qdict
, "name");
652 int up
= qdict_get_bool(qdict
, "up");
655 qmp_set_link(name
, up
, &errp
);
656 hmp_handle_error(mon
, &errp
);
659 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
661 const char *device
= qdict_get_str(qdict
, "device");
662 const char *password
= qdict_get_str(qdict
, "password");
665 qmp_block_passwd(device
, password
, &errp
);
666 hmp_handle_error(mon
, &errp
);
669 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
671 int64_t value
= qdict_get_int(qdict
, "value");
674 qmp_balloon(value
, &errp
);
675 if (error_is_set(&errp
)) {
676 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
681 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
683 const char *device
= qdict_get_str(qdict
, "device");
684 int64_t size
= qdict_get_int(qdict
, "size");
687 qmp_block_resize(device
, size
, &errp
);
688 hmp_handle_error(mon
, &errp
);
691 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
693 const char *device
= qdict_get_str(qdict
, "device");
694 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
695 const char *format
= qdict_get_try_str(qdict
, "format");
696 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
697 enum NewImageMode mode
;
701 /* In the future, if 'snapshot-file' is not specified, the snapshot
702 will be taken internally. Today it's actually required. */
703 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
704 hmp_handle_error(mon
, &errp
);
708 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
709 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
711 hmp_handle_error(mon
, &errp
);
714 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
716 qmp_migrate_cancel(NULL
);
719 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
721 double value
= qdict_get_double(qdict
, "value");
722 qmp_migrate_set_downtime(value
, NULL
);
725 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
727 int64_t value
= qdict_get_int(qdict
, "value");
728 qmp_migrate_set_speed(value
, NULL
);
731 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
733 const char *protocol
= qdict_get_str(qdict
, "protocol");
734 const char *password
= qdict_get_str(qdict
, "password");
735 const char *connected
= qdict_get_try_str(qdict
, "connected");
738 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
739 hmp_handle_error(mon
, &err
);
742 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
744 const char *protocol
= qdict_get_str(qdict
, "protocol");
745 const char *whenstr
= qdict_get_str(qdict
, "time");
748 qmp_expire_password(protocol
, whenstr
, &err
);
749 hmp_handle_error(mon
, &err
);
752 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
754 int force
= qdict_get_try_bool(qdict
, "force", 0);
755 const char *device
= qdict_get_str(qdict
, "device");
758 qmp_eject(device
, true, force
, &err
);
759 hmp_handle_error(mon
, &err
);
762 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
765 qmp_change_vnc_password(password
, NULL
);
766 monitor_read_command(mon
, 1);
769 static void cb_hmp_change_bdrv_pwd(Monitor
*mon
, const char *password
,
772 Error
*encryption_err
= opaque
;
776 device
= error_get_field(encryption_err
, "device");
778 qmp_block_passwd(device
, password
, &err
);
779 hmp_handle_error(mon
, &err
);
780 error_free(encryption_err
);
782 monitor_read_command(mon
, 1);
785 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
787 const char *device
= qdict_get_str(qdict
, "device");
788 const char *target
= qdict_get_str(qdict
, "target");
789 const char *arg
= qdict_get_try_str(qdict
, "arg");
792 if (strcmp(device
, "vnc") == 0 &&
793 (strcmp(target
, "passwd") == 0 ||
794 strcmp(target
, "password") == 0)) {
796 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
801 qmp_change(device
, target
, !!arg
, arg
, &err
);
802 if (error_is_type(err
, QERR_DEVICE_ENCRYPTED
)) {
803 monitor_printf(mon
, "%s (%s) is encrypted.\n",
804 error_get_field(err
, "device"),
805 error_get_field(err
, "filename"));
806 if (!monitor_get_rs(mon
)) {
808 "terminal does not support password prompting\n");
812 readline_start(monitor_get_rs(mon
), "Password: ", 1,
813 cb_hmp_change_bdrv_pwd
, err
);
816 hmp_handle_error(mon
, &err
);
819 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
823 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
824 qdict_get_int(qdict
, "bps"),
825 qdict_get_int(qdict
, "bps_rd"),
826 qdict_get_int(qdict
, "bps_wr"),
827 qdict_get_int(qdict
, "iops"),
828 qdict_get_int(qdict
, "iops_rd"),
829 qdict_get_int(qdict
, "iops_wr"), &err
);
830 hmp_handle_error(mon
, &err
);
833 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
836 const char *device
= qdict_get_str(qdict
, "device");
837 const char *base
= qdict_get_try_str(qdict
, "base");
839 qmp_block_stream(device
, base
!= NULL
, base
, &error
);
841 hmp_handle_error(mon
, &error
);
844 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
847 const char *device
= qdict_get_str(qdict
, "device");
848 int64_t value
= qdict_get_int(qdict
, "value");
850 qmp_block_job_set_speed(device
, value
, &error
);
852 hmp_handle_error(mon
, &error
);
855 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
858 const char *device
= qdict_get_str(qdict
, "device");
860 qmp_block_job_cancel(device
, &error
);
862 hmp_handle_error(mon
, &error
);
865 typedef struct MigrationStatus
869 bool is_block_migration
;
872 static void hmp_migrate_status_cb(void *opaque
)
874 MigrationStatus
*status
= opaque
;
877 info
= qmp_query_migrate(NULL
);
878 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
879 if (info
->has_disk
) {
882 if (info
->disk
->remaining
) {
883 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
888 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
889 monitor_flush(status
->mon
);
892 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
894 if (status
->is_block_migration
) {
895 monitor_printf(status
->mon
, "\n");
897 monitor_resume(status
->mon
);
898 qemu_del_timer(status
->timer
);
902 qapi_free_MigrationInfo(info
);
905 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
907 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
908 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
909 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
910 const char *uri
= qdict_get_str(qdict
, "uri");
913 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
915 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
921 MigrationStatus
*status
;
923 if (monitor_suspend(mon
) < 0) {
924 monitor_printf(mon
, "terminal does not allow synchronous "
925 "migration, continuing detached\n");
929 status
= g_malloc0(sizeof(*status
));
931 status
->is_block_migration
= blk
|| inc
;
932 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
934 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));