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"
24 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
26 if (error_is_set(errp
)) {
27 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
32 void hmp_info_name(Monitor
*mon
)
36 info
= qmp_query_name(NULL
);
38 monitor_printf(mon
, "%s\n", info
->name
);
40 qapi_free_NameInfo(info
);
43 void hmp_info_version(Monitor
*mon
)
47 info
= qmp_query_version(NULL
);
49 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
50 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
53 qapi_free_VersionInfo(info
);
56 void hmp_info_kvm(Monitor
*mon
)
60 info
= qmp_query_kvm(NULL
);
61 monitor_printf(mon
, "kvm support: ");
63 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
65 monitor_printf(mon
, "not compiled\n");
68 qapi_free_KvmInfo(info
);
71 void hmp_info_status(Monitor
*mon
)
75 info
= qmp_query_status(NULL
);
77 monitor_printf(mon
, "VM status: %s%s",
78 info
->running
? "running" : "paused",
79 info
->singlestep
? " (single step mode)" : "");
81 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
82 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
85 monitor_printf(mon
, "\n");
87 qapi_free_StatusInfo(info
);
90 void hmp_info_uuid(Monitor
*mon
)
94 info
= qmp_query_uuid(NULL
);
95 monitor_printf(mon
, "%s\n", info
->UUID
);
96 qapi_free_UuidInfo(info
);
99 void hmp_info_chardev(Monitor
*mon
)
101 ChardevInfoList
*char_info
, *info
;
103 char_info
= qmp_query_chardev(NULL
);
104 for (info
= char_info
; info
; info
= info
->next
) {
105 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
106 info
->value
->filename
);
109 qapi_free_ChardevInfoList(char_info
);
112 void hmp_info_mice(Monitor
*mon
)
114 MouseInfoList
*mice_list
, *mouse
;
116 mice_list
= qmp_query_mice(NULL
);
118 monitor_printf(mon
, "No mouse devices connected\n");
122 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
123 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
124 mouse
->value
->current
? '*' : ' ',
125 mouse
->value
->index
, mouse
->value
->name
,
126 mouse
->value
->absolute
? " (absolute)" : "");
129 qapi_free_MouseInfoList(mice_list
);
132 void hmp_info_migrate(Monitor
*mon
)
135 MigrationCapabilityStatusList
*caps
, *cap
;
137 info
= qmp_query_migrate(NULL
);
138 caps
= qmp_query_migrate_capabilities(NULL
);
140 /* do not display parameters during setup */
141 if (info
->has_status
&& caps
) {
142 monitor_printf(mon
, "capabilities: ");
143 for (cap
= caps
; cap
; cap
= cap
->next
) {
144 monitor_printf(mon
, "%s: %s ",
145 MigrationCapability_lookup
[cap
->value
->capability
],
146 cap
->value
->state
? "on" : "off");
148 monitor_printf(mon
, "\n");
151 if (info
->has_status
) {
152 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
153 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
155 if (info
->has_downtime
) {
156 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
162 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
163 info
->ram
->transferred
>> 10);
164 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
165 info
->ram
->remaining
>> 10);
166 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
167 info
->ram
->total
>> 10);
168 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
169 info
->ram
->duplicate
);
170 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
172 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
173 info
->ram
->normal_bytes
>> 10);
176 if (info
->has_disk
) {
177 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
178 info
->disk
->transferred
>> 10);
179 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
180 info
->disk
->remaining
>> 10);
181 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
182 info
->disk
->total
>> 10);
185 if (info
->has_xbzrle_cache
) {
186 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
187 info
->xbzrle_cache
->cache_size
);
188 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
189 info
->xbzrle_cache
->bytes
>> 10);
190 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
191 info
->xbzrle_cache
->pages
);
192 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
193 info
->xbzrle_cache
->cache_miss
);
194 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
195 info
->xbzrle_cache
->overflow
);
198 qapi_free_MigrationInfo(info
);
199 qapi_free_MigrationCapabilityStatusList(caps
);
202 void hmp_info_migrate_capabilities(Monitor
*mon
)
204 MigrationCapabilityStatusList
*caps
, *cap
;
206 caps
= qmp_query_migrate_capabilities(NULL
);
209 monitor_printf(mon
, "capabilities: ");
210 for (cap
= caps
; cap
; cap
= cap
->next
) {
211 monitor_printf(mon
, "%s: %s ",
212 MigrationCapability_lookup
[cap
->value
->capability
],
213 cap
->value
->state
? "on" : "off");
215 monitor_printf(mon
, "\n");
218 qapi_free_MigrationCapabilityStatusList(caps
);
221 void hmp_info_migrate_cache_size(Monitor
*mon
)
223 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
224 qmp_query_migrate_cache_size(NULL
) >> 10);
227 void hmp_info_cpus(Monitor
*mon
)
229 CpuInfoList
*cpu_list
, *cpu
;
231 cpu_list
= qmp_query_cpus(NULL
);
233 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
236 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
240 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
242 if (cpu
->value
->has_pc
) {
243 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
245 if (cpu
->value
->has_nip
) {
246 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
248 if (cpu
->value
->has_npc
) {
249 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
250 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
252 if (cpu
->value
->has_PC
) {
253 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
256 if (cpu
->value
->halted
) {
257 monitor_printf(mon
, " (halted)");
260 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
263 qapi_free_CpuInfoList(cpu_list
);
266 void hmp_info_block(Monitor
*mon
)
268 BlockInfoList
*block_list
, *info
;
270 block_list
= qmp_query_block(NULL
);
272 for (info
= block_list
; info
; info
= info
->next
) {
273 monitor_printf(mon
, "%s: removable=%d",
274 info
->value
->device
, info
->value
->removable
);
276 if (info
->value
->removable
) {
277 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
278 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
281 if (info
->value
->has_io_status
) {
282 monitor_printf(mon
, " io-status=%s",
283 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
286 if (info
->value
->has_inserted
) {
287 monitor_printf(mon
, " file=");
288 monitor_print_filename(mon
, info
->value
->inserted
->file
);
290 if (info
->value
->inserted
->has_backing_file
) {
291 monitor_printf(mon
, " backing_file=");
292 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
293 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
294 info
->value
->inserted
->backing_file_depth
);
296 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
297 info
->value
->inserted
->ro
,
298 info
->value
->inserted
->drv
,
299 info
->value
->inserted
->encrypted
);
301 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
302 " bps_wr=%" PRId64
" iops=%" PRId64
303 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
304 info
->value
->inserted
->bps
,
305 info
->value
->inserted
->bps_rd
,
306 info
->value
->inserted
->bps_wr
,
307 info
->value
->inserted
->iops
,
308 info
->value
->inserted
->iops_rd
,
309 info
->value
->inserted
->iops_wr
);
311 monitor_printf(mon
, " [not inserted]");
314 monitor_printf(mon
, "\n");
317 qapi_free_BlockInfoList(block_list
);
320 void hmp_info_blockstats(Monitor
*mon
)
322 BlockStatsList
*stats_list
, *stats
;
324 stats_list
= qmp_query_blockstats(NULL
);
326 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
327 if (!stats
->value
->has_device
) {
331 monitor_printf(mon
, "%s:", stats
->value
->device
);
332 monitor_printf(mon
, " rd_bytes=%" PRId64
334 " rd_operations=%" PRId64
335 " wr_operations=%" PRId64
336 " flush_operations=%" PRId64
337 " wr_total_time_ns=%" PRId64
338 " rd_total_time_ns=%" PRId64
339 " flush_total_time_ns=%" PRId64
341 stats
->value
->stats
->rd_bytes
,
342 stats
->value
->stats
->wr_bytes
,
343 stats
->value
->stats
->rd_operations
,
344 stats
->value
->stats
->wr_operations
,
345 stats
->value
->stats
->flush_operations
,
346 stats
->value
->stats
->wr_total_time_ns
,
347 stats
->value
->stats
->rd_total_time_ns
,
348 stats
->value
->stats
->flush_total_time_ns
);
351 qapi_free_BlockStatsList(stats_list
);
354 void hmp_info_vnc(Monitor
*mon
)
358 VncClientInfoList
*client
;
360 info
= qmp_query_vnc(&err
);
362 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
367 if (!info
->enabled
) {
368 monitor_printf(mon
, "Server: disabled\n");
372 monitor_printf(mon
, "Server:\n");
373 if (info
->has_host
&& info
->has_service
) {
374 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
376 if (info
->has_auth
) {
377 monitor_printf(mon
, " auth: %s\n", info
->auth
);
380 if (!info
->has_clients
|| info
->clients
== NULL
) {
381 monitor_printf(mon
, "Client: none\n");
383 for (client
= info
->clients
; client
; client
= client
->next
) {
384 monitor_printf(mon
, "Client:\n");
385 monitor_printf(mon
, " address: %s:%s\n",
386 client
->value
->host
, client
->value
->service
);
387 monitor_printf(mon
, " x509_dname: %s\n",
388 client
->value
->x509_dname
?
389 client
->value
->x509_dname
: "none");
390 monitor_printf(mon
, " username: %s\n",
391 client
->value
->has_sasl_username
?
392 client
->value
->sasl_username
: "none");
397 qapi_free_VncInfo(info
);
400 void hmp_info_spice(Monitor
*mon
)
402 SpiceChannelList
*chan
;
405 info
= qmp_query_spice(NULL
);
407 if (!info
->enabled
) {
408 monitor_printf(mon
, "Server: disabled\n");
412 monitor_printf(mon
, "Server:\n");
413 if (info
->has_port
) {
414 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
415 info
->host
, info
->port
);
417 if (info
->has_tls_port
) {
418 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
419 info
->host
, info
->tls_port
);
421 monitor_printf(mon
, " migrated: %s\n",
422 info
->migrated
? "true" : "false");
423 monitor_printf(mon
, " auth: %s\n", info
->auth
);
424 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
425 monitor_printf(mon
, " mouse-mode: %s\n",
426 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
428 if (!info
->has_channels
|| info
->channels
== NULL
) {
429 monitor_printf(mon
, "Channels: none\n");
431 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
432 monitor_printf(mon
, "Channel:\n");
433 monitor_printf(mon
, " address: %s:%s%s\n",
434 chan
->value
->host
, chan
->value
->port
,
435 chan
->value
->tls
? " [tls]" : "");
436 monitor_printf(mon
, " session: %" PRId64
"\n",
437 chan
->value
->connection_id
);
438 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
439 chan
->value
->channel_type
, chan
->value
->channel_id
);
444 qapi_free_SpiceInfo(info
);
447 void hmp_info_balloon(Monitor
*mon
)
452 info
= qmp_query_balloon(&err
);
454 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
459 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
460 if (info
->has_mem_swapped_in
) {
461 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
463 if (info
->has_mem_swapped_out
) {
464 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
466 if (info
->has_major_page_faults
) {
467 monitor_printf(mon
, " major_page_faults=%" PRId64
,
468 info
->major_page_faults
);
470 if (info
->has_minor_page_faults
) {
471 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
472 info
->minor_page_faults
);
474 if (info
->has_free_mem
) {
475 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
477 if (info
->has_total_mem
) {
478 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
481 monitor_printf(mon
, "\n");
483 qapi_free_BalloonInfo(info
);
486 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
488 PciMemoryRegionList
*region
;
490 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
491 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
492 dev
->slot
, dev
->function
);
493 monitor_printf(mon
, " ");
495 if (dev
->class_info
.has_desc
) {
496 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
498 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
501 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
502 dev
->id
.vendor
, dev
->id
.device
);
505 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
508 if (dev
->has_pci_bridge
) {
509 monitor_printf(mon
, " BUS %" PRId64
".\n",
510 dev
->pci_bridge
->bus
.number
);
511 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
512 dev
->pci_bridge
->bus
.secondary
);
513 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
514 dev
->pci_bridge
->bus
.subordinate
);
516 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
517 dev
->pci_bridge
->bus
.io_range
->base
,
518 dev
->pci_bridge
->bus
.io_range
->limit
);
521 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
522 dev
->pci_bridge
->bus
.memory_range
->base
,
523 dev
->pci_bridge
->bus
.memory_range
->limit
);
525 monitor_printf(mon
, " prefetchable memory range "
526 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
527 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
528 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
531 for (region
= dev
->regions
; region
; region
= region
->next
) {
534 addr
= region
->value
->address
;
535 size
= region
->value
->size
;
537 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
539 if (!strcmp(region
->value
->type
, "io")) {
540 monitor_printf(mon
, "I/O at 0x%04" PRIx64
541 " [0x%04" PRIx64
"].\n",
542 addr
, addr
+ size
- 1);
544 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
545 " [0x%08" PRIx64
"].\n",
546 region
->value
->mem_type_64
? 64 : 32,
547 region
->value
->prefetch
? " prefetchable" : "",
548 addr
, addr
+ size
- 1);
552 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
554 if (dev
->has_pci_bridge
) {
555 if (dev
->pci_bridge
->has_devices
) {
556 PciDeviceInfoList
*cdev
;
557 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
558 hmp_info_pci_device(mon
, cdev
->value
);
564 void hmp_info_pci(Monitor
*mon
)
566 PciInfoList
*info_list
, *info
;
569 info_list
= qmp_query_pci(&err
);
571 monitor_printf(mon
, "PCI devices not supported\n");
576 for (info
= info_list
; info
; info
= info
->next
) {
577 PciDeviceInfoList
*dev
;
579 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
580 hmp_info_pci_device(mon
, dev
->value
);
584 qapi_free_PciInfoList(info_list
);
587 void hmp_info_block_jobs(Monitor
*mon
)
589 BlockJobInfoList
*list
;
592 list
= qmp_query_block_jobs(&err
);
596 monitor_printf(mon
, "No active jobs\n");
601 if (strcmp(list
->value
->type
, "stream") == 0) {
602 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
603 " of %" PRId64
" bytes, speed limit %" PRId64
610 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
611 " of %" PRId64
" bytes, speed limit %" PRId64
623 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
625 monitor_suspend(mon
);
629 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
634 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
636 qmp_system_reset(NULL
);
639 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
641 qmp_system_powerdown(NULL
);
644 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
648 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
649 use it are converted to the QAPI */
650 cpu_index
= qdict_get_int(qdict
, "index");
651 if (monitor_set_cpu(cpu_index
) < 0) {
652 monitor_printf(mon
, "invalid CPU index\n");
656 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
658 uint32_t size
= qdict_get_int(qdict
, "size");
659 const char *filename
= qdict_get_str(qdict
, "filename");
660 uint64_t addr
= qdict_get_int(qdict
, "val");
663 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
664 hmp_handle_error(mon
, &errp
);
667 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
669 uint32_t size
= qdict_get_int(qdict
, "size");
670 const char *filename
= qdict_get_str(qdict
, "filename");
671 uint64_t addr
= qdict_get_int(qdict
, "val");
674 qmp_pmemsave(addr
, size
, filename
, &errp
);
675 hmp_handle_error(mon
, &errp
);
678 static void hmp_cont_cb(void *opaque
, int err
)
685 static bool key_is_missing(const BlockInfo
*bdev
)
687 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
690 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
692 BlockInfoList
*bdev_list
, *bdev
;
695 bdev_list
= qmp_query_block(NULL
);
696 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
697 if (key_is_missing(bdev
->value
)) {
698 monitor_read_block_device_key(mon
, bdev
->value
->device
,
705 hmp_handle_error(mon
, &errp
);
708 qapi_free_BlockInfoList(bdev_list
);
711 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
713 qmp_system_wakeup(NULL
);
716 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
720 qmp_inject_nmi(&errp
);
721 hmp_handle_error(mon
, &errp
);
724 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
726 const char *name
= qdict_get_str(qdict
, "name");
727 int up
= qdict_get_bool(qdict
, "up");
730 qmp_set_link(name
, up
, &errp
);
731 hmp_handle_error(mon
, &errp
);
734 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
736 const char *device
= qdict_get_str(qdict
, "device");
737 const char *password
= qdict_get_str(qdict
, "password");
740 qmp_block_passwd(device
, password
, &errp
);
741 hmp_handle_error(mon
, &errp
);
744 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
746 int64_t value
= qdict_get_int(qdict
, "value");
749 qmp_balloon(value
, &errp
);
750 if (error_is_set(&errp
)) {
751 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
756 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
758 const char *device
= qdict_get_str(qdict
, "device");
759 int64_t size
= qdict_get_int(qdict
, "size");
762 qmp_block_resize(device
, size
, &errp
);
763 hmp_handle_error(mon
, &errp
);
766 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
768 const char *device
= qdict_get_str(qdict
, "device");
769 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
770 const char *format
= qdict_get_try_str(qdict
, "format");
771 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
772 enum NewImageMode mode
;
776 /* In the future, if 'snapshot-file' is not specified, the snapshot
777 will be taken internally. Today it's actually required. */
778 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
779 hmp_handle_error(mon
, &errp
);
783 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
784 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
786 hmp_handle_error(mon
, &errp
);
789 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
791 qmp_migrate_cancel(NULL
);
794 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
796 double value
= qdict_get_double(qdict
, "value");
797 qmp_migrate_set_downtime(value
, NULL
);
800 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
802 int64_t value
= qdict_get_int(qdict
, "value");
805 qmp_migrate_set_cache_size(value
, &err
);
807 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
813 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
815 int64_t value
= qdict_get_int(qdict
, "value");
816 qmp_migrate_set_speed(value
, NULL
);
819 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
821 const char *cap
= qdict_get_str(qdict
, "capability");
822 bool state
= qdict_get_bool(qdict
, "state");
824 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
827 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
828 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
829 caps
->value
= g_malloc0(sizeof(*caps
->value
));
830 caps
->value
->capability
= i
;
831 caps
->value
->state
= state
;
833 qmp_migrate_set_capabilities(caps
, &err
);
838 if (i
== MIGRATION_CAPABILITY_MAX
) {
839 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
842 qapi_free_MigrationCapabilityStatusList(caps
);
845 monitor_printf(mon
, "migrate_set_parameter: %s\n",
846 error_get_pretty(err
));
851 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
853 const char *protocol
= qdict_get_str(qdict
, "protocol");
854 const char *password
= qdict_get_str(qdict
, "password");
855 const char *connected
= qdict_get_try_str(qdict
, "connected");
858 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
859 hmp_handle_error(mon
, &err
);
862 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
864 const char *protocol
= qdict_get_str(qdict
, "protocol");
865 const char *whenstr
= qdict_get_str(qdict
, "time");
868 qmp_expire_password(protocol
, whenstr
, &err
);
869 hmp_handle_error(mon
, &err
);
872 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
874 int force
= qdict_get_try_bool(qdict
, "force", 0);
875 const char *device
= qdict_get_str(qdict
, "device");
878 qmp_eject(device
, true, force
, &err
);
879 hmp_handle_error(mon
, &err
);
882 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
885 qmp_change_vnc_password(password
, NULL
);
886 monitor_read_command(mon
, 1);
889 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
891 const char *device
= qdict_get_str(qdict
, "device");
892 const char *target
= qdict_get_str(qdict
, "target");
893 const char *arg
= qdict_get_try_str(qdict
, "arg");
896 if (strcmp(device
, "vnc") == 0 &&
897 (strcmp(target
, "passwd") == 0 ||
898 strcmp(target
, "password") == 0)) {
900 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
905 qmp_change(device
, target
, !!arg
, arg
, &err
);
906 if (error_is_set(&err
) &&
907 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
909 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
912 hmp_handle_error(mon
, &err
);
915 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
919 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
920 qdict_get_int(qdict
, "bps"),
921 qdict_get_int(qdict
, "bps_rd"),
922 qdict_get_int(qdict
, "bps_wr"),
923 qdict_get_int(qdict
, "iops"),
924 qdict_get_int(qdict
, "iops_rd"),
925 qdict_get_int(qdict
, "iops_wr"), &err
);
926 hmp_handle_error(mon
, &err
);
929 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
932 const char *device
= qdict_get_str(qdict
, "device");
933 const char *base
= qdict_get_try_str(qdict
, "base");
934 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
936 qmp_block_stream(device
, base
!= NULL
, base
,
937 qdict_haskey(qdict
, "speed"), speed
,
938 BLOCKDEV_ON_ERROR_REPORT
, true, &error
);
940 hmp_handle_error(mon
, &error
);
943 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
946 const char *device
= qdict_get_str(qdict
, "device");
947 int64_t value
= qdict_get_int(qdict
, "speed");
949 qmp_block_job_set_speed(device
, value
, &error
);
951 hmp_handle_error(mon
, &error
);
954 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
957 const char *device
= qdict_get_str(qdict
, "device");
958 bool force
= qdict_get_try_bool(qdict
, "force", 0);
960 qmp_block_job_cancel(device
, true, force
, &error
);
962 hmp_handle_error(mon
, &error
);
965 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
968 const char *device
= qdict_get_str(qdict
, "device");
970 qmp_block_job_pause(device
, &error
);
972 hmp_handle_error(mon
, &error
);
975 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
978 const char *device
= qdict_get_str(qdict
, "device");
980 qmp_block_job_resume(device
, &error
);
982 hmp_handle_error(mon
, &error
);
985 typedef struct MigrationStatus
989 bool is_block_migration
;
992 static void hmp_migrate_status_cb(void *opaque
)
994 MigrationStatus
*status
= opaque
;
997 info
= qmp_query_migrate(NULL
);
998 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
999 if (info
->has_disk
) {
1002 if (info
->disk
->remaining
) {
1003 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1008 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1009 monitor_flush(status
->mon
);
1012 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
1014 if (status
->is_block_migration
) {
1015 monitor_printf(status
->mon
, "\n");
1017 monitor_resume(status
->mon
);
1018 qemu_del_timer(status
->timer
);
1022 qapi_free_MigrationInfo(info
);
1025 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1027 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1028 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1029 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1030 const char *uri
= qdict_get_str(qdict
, "uri");
1033 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1035 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1041 MigrationStatus
*status
;
1043 if (monitor_suspend(mon
) < 0) {
1044 monitor_printf(mon
, "terminal does not allow synchronous "
1045 "migration, continuing detached\n");
1049 status
= g_malloc0(sizeof(*status
));
1051 status
->is_block_migration
= blk
|| inc
;
1052 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1054 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1058 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1060 const char *id
= qdict_get_str(qdict
, "id");
1063 qmp_device_del(id
, &err
);
1064 hmp_handle_error(mon
, &err
);
1067 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1070 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1071 const char *file
= qdict_get_str(qdict
, "filename");
1072 bool has_begin
= qdict_haskey(qdict
, "begin");
1073 bool has_length
= qdict_haskey(qdict
, "length");
1079 begin
= qdict_get_int(qdict
, "begin");
1082 length
= qdict_get_int(qdict
, "length");
1085 prot
= g_strconcat("file:", file
, NULL
);
1087 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1089 hmp_handle_error(mon
, &errp
);
1093 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1098 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1099 if (error_is_set(&err
)) {
1103 netdev_add(opts
, &err
);
1104 if (error_is_set(&err
)) {
1105 qemu_opts_del(opts
);
1109 hmp_handle_error(mon
, &err
);
1112 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1114 const char *id
= qdict_get_str(qdict
, "id");
1117 qmp_netdev_del(id
, &err
);
1118 hmp_handle_error(mon
, &err
);
1121 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1123 const char *fdname
= qdict_get_str(qdict
, "fdname");
1126 qmp_getfd(fdname
, &errp
);
1127 hmp_handle_error(mon
, &errp
);
1130 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1132 const char *fdname
= qdict_get_str(qdict
, "fdname");
1135 qmp_closefd(fdname
, &errp
);
1136 hmp_handle_error(mon
, &errp
);
1139 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1141 const char *keys
= qdict_get_str(qdict
, "keys");
1142 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1143 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1144 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1146 char keyname_buf
[16];
1151 separator
= strchr(keys
, '-');
1152 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1153 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1155 /* Be compatible with old interface, convert user inputted "<" */
1156 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1157 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1160 keyname_buf
[keyname_len
] = 0;
1162 keylist
= g_malloc0(sizeof(*keylist
));
1163 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1169 tmp
->next
= keylist
;
1173 if (strstart(keyname_buf
, "0x", NULL
)) {
1175 int value
= strtoul(keyname_buf
, &endp
, 0);
1176 if (*endp
!= '\0') {
1179 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1180 keylist
->value
->number
= value
;
1182 int idx
= index_from_key(keyname_buf
);
1183 if (idx
== Q_KEY_CODE_MAX
) {
1186 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1187 keylist
->value
->qcode
= idx
;
1193 keys
= separator
+ 1;
1196 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1197 hmp_handle_error(mon
, &err
);
1200 qapi_free_KeyValueList(head
);
1204 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1208 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1210 const char *filename
= qdict_get_str(qdict
, "filename");
1213 qmp_screendump(filename
, &err
);
1214 hmp_handle_error(mon
, &err
);