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.
18 #include "qemu-option.h"
19 #include "qemu-timer.h"
20 #include "qmp-commands.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
));
31 void hmp_info_name(Monitor
*mon
)
35 info
= qmp_query_name(NULL
);
37 monitor_printf(mon
, "%s\n", info
->name
);
39 qapi_free_NameInfo(info
);
42 void hmp_info_version(Monitor
*mon
)
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
,
52 qapi_free_VersionInfo(info
);
55 void hmp_info_kvm(Monitor
*mon
)
59 info
= qmp_query_kvm(NULL
);
60 monitor_printf(mon
, "kvm support: ");
62 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
64 monitor_printf(mon
, "not compiled\n");
67 qapi_free_KvmInfo(info
);
70 void hmp_info_status(Monitor
*mon
)
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
)
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
);
117 monitor_printf(mon
, "No mouse devices connected\n");
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
)
134 MigrationCapabilityStatusList
*caps
, *cap
;
136 info
= qmp_query_migrate(NULL
);
137 caps
= qmp_query_migrate_capabilities(NULL
);
139 /* do not display parameters during setup */
140 if (info
->has_status
&& caps
) {
141 monitor_printf(mon
, "capabilities: ");
142 for (cap
= caps
; cap
; cap
= cap
->next
) {
143 monitor_printf(mon
, "%s: %s ",
144 MigrationCapability_lookup
[cap
->value
->capability
],
145 cap
->value
->state
? "on" : "off");
147 monitor_printf(mon
, "\n");
150 if (info
->has_status
) {
151 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
155 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
156 info
->ram
->transferred
>> 10);
157 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
158 info
->ram
->remaining
>> 10);
159 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
160 info
->ram
->total
>> 10);
161 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
162 info
->ram
->total_time
);
163 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
164 info
->ram
->duplicate
);
165 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
167 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
168 info
->ram
->normal_bytes
>> 10);
171 if (info
->has_disk
) {
172 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
173 info
->disk
->transferred
>> 10);
174 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
175 info
->disk
->remaining
>> 10);
176 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
177 info
->disk
->total
>> 10);
180 if (info
->has_xbzrle_cache
) {
181 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
182 info
->xbzrle_cache
->cache_size
);
183 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
184 info
->xbzrle_cache
->bytes
>> 10);
185 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
186 info
->xbzrle_cache
->pages
);
187 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
188 info
->xbzrle_cache
->cache_miss
);
189 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
190 info
->xbzrle_cache
->overflow
);
193 qapi_free_MigrationInfo(info
);
194 qapi_free_MigrationCapabilityStatusList(caps
);
197 void hmp_info_migrate_capabilities(Monitor
*mon
)
199 MigrationCapabilityStatusList
*caps
, *cap
;
201 caps
= qmp_query_migrate_capabilities(NULL
);
204 monitor_printf(mon
, "capabilities: ");
205 for (cap
= caps
; cap
; cap
= cap
->next
) {
206 monitor_printf(mon
, "%s: %s ",
207 MigrationCapability_lookup
[cap
->value
->capability
],
208 cap
->value
->state
? "on" : "off");
210 monitor_printf(mon
, "\n");
213 qapi_free_MigrationCapabilityStatusList(caps
);
216 void hmp_info_migrate_cache_size(Monitor
*mon
)
218 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
219 qmp_query_migrate_cache_size(NULL
) >> 10);
222 void hmp_info_cpus(Monitor
*mon
)
224 CpuInfoList
*cpu_list
, *cpu
;
226 cpu_list
= qmp_query_cpus(NULL
);
228 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
231 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
235 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
237 if (cpu
->value
->has_pc
) {
238 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
240 if (cpu
->value
->has_nip
) {
241 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
243 if (cpu
->value
->has_npc
) {
244 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
245 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
247 if (cpu
->value
->has_PC
) {
248 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
251 if (cpu
->value
->halted
) {
252 monitor_printf(mon
, " (halted)");
255 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
258 qapi_free_CpuInfoList(cpu_list
);
261 void hmp_info_block(Monitor
*mon
)
263 BlockInfoList
*block_list
, *info
;
265 block_list
= qmp_query_block(NULL
);
267 for (info
= block_list
; info
; info
= info
->next
) {
268 monitor_printf(mon
, "%s: removable=%d",
269 info
->value
->device
, info
->value
->removable
);
271 if (info
->value
->removable
) {
272 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
273 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
276 if (info
->value
->has_io_status
) {
277 monitor_printf(mon
, " io-status=%s",
278 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
281 if (info
->value
->has_inserted
) {
282 monitor_printf(mon
, " file=");
283 monitor_print_filename(mon
, info
->value
->inserted
->file
);
285 if (info
->value
->inserted
->has_backing_file
) {
286 monitor_printf(mon
, " backing_file=");
287 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
288 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
289 info
->value
->inserted
->backing_file_depth
);
291 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
292 info
->value
->inserted
->ro
,
293 info
->value
->inserted
->drv
,
294 info
->value
->inserted
->encrypted
);
296 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
297 " bps_wr=%" PRId64
" iops=%" PRId64
298 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
299 info
->value
->inserted
->bps
,
300 info
->value
->inserted
->bps_rd
,
301 info
->value
->inserted
->bps_wr
,
302 info
->value
->inserted
->iops
,
303 info
->value
->inserted
->iops_rd
,
304 info
->value
->inserted
->iops_wr
);
306 monitor_printf(mon
, " [not inserted]");
309 monitor_printf(mon
, "\n");
312 qapi_free_BlockInfoList(block_list
);
315 void hmp_info_blockstats(Monitor
*mon
)
317 BlockStatsList
*stats_list
, *stats
;
319 stats_list
= qmp_query_blockstats(NULL
);
321 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
322 if (!stats
->value
->has_device
) {
326 monitor_printf(mon
, "%s:", stats
->value
->device
);
327 monitor_printf(mon
, " rd_bytes=%" PRId64
329 " rd_operations=%" PRId64
330 " wr_operations=%" PRId64
331 " flush_operations=%" PRId64
332 " wr_total_time_ns=%" PRId64
333 " rd_total_time_ns=%" PRId64
334 " flush_total_time_ns=%" PRId64
336 stats
->value
->stats
->rd_bytes
,
337 stats
->value
->stats
->wr_bytes
,
338 stats
->value
->stats
->rd_operations
,
339 stats
->value
->stats
->wr_operations
,
340 stats
->value
->stats
->flush_operations
,
341 stats
->value
->stats
->wr_total_time_ns
,
342 stats
->value
->stats
->rd_total_time_ns
,
343 stats
->value
->stats
->flush_total_time_ns
);
346 qapi_free_BlockStatsList(stats_list
);
349 void hmp_info_vnc(Monitor
*mon
)
353 VncClientInfoList
*client
;
355 info
= qmp_query_vnc(&err
);
357 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
362 if (!info
->enabled
) {
363 monitor_printf(mon
, "Server: disabled\n");
367 monitor_printf(mon
, "Server:\n");
368 if (info
->has_host
&& info
->has_service
) {
369 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
371 if (info
->has_auth
) {
372 monitor_printf(mon
, " auth: %s\n", info
->auth
);
375 if (!info
->has_clients
|| info
->clients
== NULL
) {
376 monitor_printf(mon
, "Client: none\n");
378 for (client
= info
->clients
; client
; client
= client
->next
) {
379 monitor_printf(mon
, "Client:\n");
380 monitor_printf(mon
, " address: %s:%s\n",
381 client
->value
->host
, client
->value
->service
);
382 monitor_printf(mon
, " x509_dname: %s\n",
383 client
->value
->x509_dname
?
384 client
->value
->x509_dname
: "none");
385 monitor_printf(mon
, " username: %s\n",
386 client
->value
->has_sasl_username
?
387 client
->value
->sasl_username
: "none");
392 qapi_free_VncInfo(info
);
395 void hmp_info_spice(Monitor
*mon
)
397 SpiceChannelList
*chan
;
400 info
= qmp_query_spice(NULL
);
402 if (!info
->enabled
) {
403 monitor_printf(mon
, "Server: disabled\n");
407 monitor_printf(mon
, "Server:\n");
408 if (info
->has_port
) {
409 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
410 info
->host
, info
->port
);
412 if (info
->has_tls_port
) {
413 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
414 info
->host
, info
->tls_port
);
416 monitor_printf(mon
, " auth: %s\n", info
->auth
);
417 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
418 monitor_printf(mon
, " mouse-mode: %s\n",
419 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
421 if (!info
->has_channels
|| info
->channels
== NULL
) {
422 monitor_printf(mon
, "Channels: none\n");
424 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
425 monitor_printf(mon
, "Channel:\n");
426 monitor_printf(mon
, " address: %s:%s%s\n",
427 chan
->value
->host
, chan
->value
->port
,
428 chan
->value
->tls
? " [tls]" : "");
429 monitor_printf(mon
, " session: %" PRId64
"\n",
430 chan
->value
->connection_id
);
431 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
432 chan
->value
->channel_type
, chan
->value
->channel_id
);
437 qapi_free_SpiceInfo(info
);
440 void hmp_info_balloon(Monitor
*mon
)
445 info
= qmp_query_balloon(&err
);
447 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
452 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
453 if (info
->has_mem_swapped_in
) {
454 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
456 if (info
->has_mem_swapped_out
) {
457 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
459 if (info
->has_major_page_faults
) {
460 monitor_printf(mon
, " major_page_faults=%" PRId64
,
461 info
->major_page_faults
);
463 if (info
->has_minor_page_faults
) {
464 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
465 info
->minor_page_faults
);
467 if (info
->has_free_mem
) {
468 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
470 if (info
->has_total_mem
) {
471 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
474 monitor_printf(mon
, "\n");
476 qapi_free_BalloonInfo(info
);
479 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
481 PciMemoryRegionList
*region
;
483 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
484 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
485 dev
->slot
, dev
->function
);
486 monitor_printf(mon
, " ");
488 if (dev
->class_info
.has_desc
) {
489 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
491 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
494 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
495 dev
->id
.vendor
, dev
->id
.device
);
498 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
501 if (dev
->has_pci_bridge
) {
502 monitor_printf(mon
, " BUS %" PRId64
".\n",
503 dev
->pci_bridge
->bus
.number
);
504 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
505 dev
->pci_bridge
->bus
.secondary
);
506 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
507 dev
->pci_bridge
->bus
.subordinate
);
509 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
510 dev
->pci_bridge
->bus
.io_range
->base
,
511 dev
->pci_bridge
->bus
.io_range
->limit
);
514 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
515 dev
->pci_bridge
->bus
.memory_range
->base
,
516 dev
->pci_bridge
->bus
.memory_range
->limit
);
518 monitor_printf(mon
, " prefetchable memory range "
519 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
520 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
521 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
524 for (region
= dev
->regions
; region
; region
= region
->next
) {
527 addr
= region
->value
->address
;
528 size
= region
->value
->size
;
530 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
532 if (!strcmp(region
->value
->type
, "io")) {
533 monitor_printf(mon
, "I/O at 0x%04" PRIx64
534 " [0x%04" PRIx64
"].\n",
535 addr
, addr
+ size
- 1);
537 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
538 " [0x%08" PRIx64
"].\n",
539 region
->value
->mem_type_64
? 64 : 32,
540 region
->value
->prefetch
? " prefetchable" : "",
541 addr
, addr
+ size
- 1);
545 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
547 if (dev
->has_pci_bridge
) {
548 if (dev
->pci_bridge
->has_devices
) {
549 PciDeviceInfoList
*cdev
;
550 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
551 hmp_info_pci_device(mon
, cdev
->value
);
557 void hmp_info_pci(Monitor
*mon
)
559 PciInfoList
*info_list
, *info
;
562 info_list
= qmp_query_pci(&err
);
564 monitor_printf(mon
, "PCI devices not supported\n");
569 for (info
= info_list
; info
; info
= info
->next
) {
570 PciDeviceInfoList
*dev
;
572 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
573 hmp_info_pci_device(mon
, dev
->value
);
577 qapi_free_PciInfoList(info_list
);
580 void hmp_info_block_jobs(Monitor
*mon
)
582 BlockJobInfoList
*list
;
585 list
= qmp_query_block_jobs(&err
);
589 monitor_printf(mon
, "No active jobs\n");
594 if (strcmp(list
->value
->type
, "stream") == 0) {
595 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
596 " of %" PRId64
" bytes, speed limit %" PRId64
603 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
604 " of %" PRId64
" bytes, speed limit %" PRId64
616 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
618 monitor_suspend(mon
);
622 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
627 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
629 qmp_system_reset(NULL
);
632 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
634 qmp_system_powerdown(NULL
);
637 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
641 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
642 use it are converted to the QAPI */
643 cpu_index
= qdict_get_int(qdict
, "index");
644 if (monitor_set_cpu(cpu_index
) < 0) {
645 monitor_printf(mon
, "invalid CPU index\n");
649 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
651 uint32_t size
= qdict_get_int(qdict
, "size");
652 const char *filename
= qdict_get_str(qdict
, "filename");
653 uint64_t addr
= qdict_get_int(qdict
, "val");
656 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
657 hmp_handle_error(mon
, &errp
);
660 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
662 uint32_t size
= qdict_get_int(qdict
, "size");
663 const char *filename
= qdict_get_str(qdict
, "filename");
664 uint64_t addr
= qdict_get_int(qdict
, "val");
667 qmp_pmemsave(addr
, size
, filename
, &errp
);
668 hmp_handle_error(mon
, &errp
);
671 static void hmp_cont_cb(void *opaque
, int err
)
673 Monitor
*mon
= opaque
;
680 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
685 if (error_is_set(&errp
)) {
686 if (error_is_type(errp
, QERR_DEVICE_ENCRYPTED
)) {
689 /* The device is encrypted. Ask the user for the password
692 device
= error_get_field(errp
, "device");
693 assert(device
!= NULL
);
695 monitor_read_block_device_key(mon
, device
, hmp_cont_cb
, mon
);
699 hmp_handle_error(mon
, &errp
);
703 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
705 qmp_system_wakeup(NULL
);
708 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
712 qmp_inject_nmi(&errp
);
713 hmp_handle_error(mon
, &errp
);
716 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
718 const char *name
= qdict_get_str(qdict
, "name");
719 int up
= qdict_get_bool(qdict
, "up");
722 qmp_set_link(name
, up
, &errp
);
723 hmp_handle_error(mon
, &errp
);
726 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
728 const char *device
= qdict_get_str(qdict
, "device");
729 const char *password
= qdict_get_str(qdict
, "password");
732 qmp_block_passwd(device
, password
, &errp
);
733 hmp_handle_error(mon
, &errp
);
736 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
738 int64_t value
= qdict_get_int(qdict
, "value");
741 qmp_balloon(value
, &errp
);
742 if (error_is_set(&errp
)) {
743 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
748 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
750 const char *device
= qdict_get_str(qdict
, "device");
751 int64_t size
= qdict_get_int(qdict
, "size");
754 qmp_block_resize(device
, size
, &errp
);
755 hmp_handle_error(mon
, &errp
);
758 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
760 const char *device
= qdict_get_str(qdict
, "device");
761 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
762 const char *format
= qdict_get_try_str(qdict
, "format");
763 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
764 enum NewImageMode mode
;
768 /* In the future, if 'snapshot-file' is not specified, the snapshot
769 will be taken internally. Today it's actually required. */
770 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
771 hmp_handle_error(mon
, &errp
);
775 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
776 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
778 hmp_handle_error(mon
, &errp
);
781 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
783 qmp_migrate_cancel(NULL
);
786 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
788 double value
= qdict_get_double(qdict
, "value");
789 qmp_migrate_set_downtime(value
, NULL
);
792 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
794 int64_t value
= qdict_get_int(qdict
, "value");
797 qmp_migrate_set_cache_size(value
, &err
);
799 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
805 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
807 int64_t value
= qdict_get_int(qdict
, "value");
808 qmp_migrate_set_speed(value
, NULL
);
811 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
813 const char *cap
= qdict_get_str(qdict
, "capability");
814 bool state
= qdict_get_bool(qdict
, "state");
816 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
819 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
820 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
821 caps
->value
= g_malloc0(sizeof(*caps
->value
));
822 caps
->value
->capability
= i
;
823 caps
->value
->state
= state
;
825 qmp_migrate_set_capabilities(caps
, &err
);
830 if (i
== MIGRATION_CAPABILITY_MAX
) {
831 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
834 qapi_free_MigrationCapabilityStatusList(caps
);
837 monitor_printf(mon
, "migrate_set_parameter: %s\n",
838 error_get_pretty(err
));
843 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
845 const char *protocol
= qdict_get_str(qdict
, "protocol");
846 const char *password
= qdict_get_str(qdict
, "password");
847 const char *connected
= qdict_get_try_str(qdict
, "connected");
850 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
851 hmp_handle_error(mon
, &err
);
854 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
856 const char *protocol
= qdict_get_str(qdict
, "protocol");
857 const char *whenstr
= qdict_get_str(qdict
, "time");
860 qmp_expire_password(protocol
, whenstr
, &err
);
861 hmp_handle_error(mon
, &err
);
864 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
866 int force
= qdict_get_try_bool(qdict
, "force", 0);
867 const char *device
= qdict_get_str(qdict
, "device");
870 qmp_eject(device
, true, force
, &err
);
871 hmp_handle_error(mon
, &err
);
874 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
877 qmp_change_vnc_password(password
, NULL
);
878 monitor_read_command(mon
, 1);
881 static void cb_hmp_change_bdrv_pwd(Monitor
*mon
, const char *password
,
884 Error
*encryption_err
= opaque
;
888 device
= error_get_field(encryption_err
, "device");
890 qmp_block_passwd(device
, password
, &err
);
891 hmp_handle_error(mon
, &err
);
892 error_free(encryption_err
);
894 monitor_read_command(mon
, 1);
897 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
899 const char *device
= qdict_get_str(qdict
, "device");
900 const char *target
= qdict_get_str(qdict
, "target");
901 const char *arg
= qdict_get_try_str(qdict
, "arg");
904 if (strcmp(device
, "vnc") == 0 &&
905 (strcmp(target
, "passwd") == 0 ||
906 strcmp(target
, "password") == 0)) {
908 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
913 qmp_change(device
, target
, !!arg
, arg
, &err
);
914 if (error_is_type(err
, QERR_DEVICE_ENCRYPTED
)) {
915 monitor_printf(mon
, "%s (%s) is encrypted.\n",
916 error_get_field(err
, "device"),
917 error_get_field(err
, "filename"));
918 if (!monitor_get_rs(mon
)) {
920 "terminal does not support password prompting\n");
924 readline_start(monitor_get_rs(mon
), "Password: ", 1,
925 cb_hmp_change_bdrv_pwd
, err
);
928 hmp_handle_error(mon
, &err
);
931 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
935 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
936 qdict_get_int(qdict
, "bps"),
937 qdict_get_int(qdict
, "bps_rd"),
938 qdict_get_int(qdict
, "bps_wr"),
939 qdict_get_int(qdict
, "iops"),
940 qdict_get_int(qdict
, "iops_rd"),
941 qdict_get_int(qdict
, "iops_wr"), &err
);
942 hmp_handle_error(mon
, &err
);
945 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
948 const char *device
= qdict_get_str(qdict
, "device");
949 const char *base
= qdict_get_try_str(qdict
, "base");
950 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
952 qmp_block_stream(device
, base
!= NULL
, base
,
953 qdict_haskey(qdict
, "speed"), speed
, &error
);
955 hmp_handle_error(mon
, &error
);
958 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
961 const char *device
= qdict_get_str(qdict
, "device");
962 int64_t value
= qdict_get_int(qdict
, "speed");
964 qmp_block_job_set_speed(device
, value
, &error
);
966 hmp_handle_error(mon
, &error
);
969 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
972 const char *device
= qdict_get_str(qdict
, "device");
974 qmp_block_job_cancel(device
, &error
);
976 hmp_handle_error(mon
, &error
);
979 typedef struct MigrationStatus
983 bool is_block_migration
;
986 static void hmp_migrate_status_cb(void *opaque
)
988 MigrationStatus
*status
= opaque
;
991 info
= qmp_query_migrate(NULL
);
992 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
993 if (info
->has_disk
) {
996 if (info
->disk
->remaining
) {
997 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1002 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1003 monitor_flush(status
->mon
);
1006 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
1008 if (status
->is_block_migration
) {
1009 monitor_printf(status
->mon
, "\n");
1011 monitor_resume(status
->mon
);
1012 qemu_del_timer(status
->timer
);
1016 qapi_free_MigrationInfo(info
);
1019 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1021 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1022 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1023 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1024 const char *uri
= qdict_get_str(qdict
, "uri");
1027 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1029 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1035 MigrationStatus
*status
;
1037 if (monitor_suspend(mon
) < 0) {
1038 monitor_printf(mon
, "terminal does not allow synchronous "
1039 "migration, continuing detached\n");
1043 status
= g_malloc0(sizeof(*status
));
1045 status
->is_block_migration
= blk
|| inc
;
1046 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1048 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1052 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1054 const char *id
= qdict_get_str(qdict
, "id");
1057 qmp_device_del(id
, &err
);
1058 hmp_handle_error(mon
, &err
);
1061 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1064 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1065 const char *file
= qdict_get_str(qdict
, "protocol");
1066 bool has_begin
= qdict_haskey(qdict
, "begin");
1067 bool has_length
= qdict_haskey(qdict
, "length");
1072 begin
= qdict_get_int(qdict
, "begin");
1075 length
= qdict_get_int(qdict
, "length");
1078 qmp_dump_guest_memory(paging
, file
, has_begin
, begin
, has_length
, length
,
1080 hmp_handle_error(mon
, &errp
);
1083 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1088 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1089 if (error_is_set(&err
)) {
1093 netdev_add(opts
, &err
);
1094 if (error_is_set(&err
)) {
1095 qemu_opts_del(opts
);
1099 hmp_handle_error(mon
, &err
);
1102 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1104 const char *id
= qdict_get_str(qdict
, "id");
1107 qmp_netdev_del(id
, &err
);
1108 hmp_handle_error(mon
, &err
);
1111 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1113 const char *fdname
= qdict_get_str(qdict
, "fdname");
1116 qmp_getfd(fdname
, &errp
);
1117 hmp_handle_error(mon
, &errp
);
1120 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1122 const char *fdname
= qdict_get_str(qdict
, "fdname");
1125 qmp_closefd(fdname
, &errp
);
1126 hmp_handle_error(mon
, &errp
);