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_expected_downtime
) {
156 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
157 info
->expected_downtime
);
159 if (info
->has_downtime
) {
160 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
166 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
167 info
->ram
->transferred
>> 10);
168 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
169 info
->ram
->remaining
>> 10);
170 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
171 info
->ram
->total
>> 10);
172 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
173 info
->ram
->duplicate
);
174 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
176 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
177 info
->ram
->normal_bytes
>> 10);
178 if (info
->ram
->dirty_pages_rate
) {
179 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
180 info
->ram
->dirty_pages_rate
);
184 if (info
->has_disk
) {
185 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
186 info
->disk
->transferred
>> 10);
187 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
188 info
->disk
->remaining
>> 10);
189 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
190 info
->disk
->total
>> 10);
193 if (info
->has_xbzrle_cache
) {
194 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
195 info
->xbzrle_cache
->cache_size
);
196 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
197 info
->xbzrle_cache
->bytes
>> 10);
198 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
199 info
->xbzrle_cache
->pages
);
200 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
201 info
->xbzrle_cache
->cache_miss
);
202 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
203 info
->xbzrle_cache
->overflow
);
206 qapi_free_MigrationInfo(info
);
207 qapi_free_MigrationCapabilityStatusList(caps
);
210 void hmp_info_migrate_capabilities(Monitor
*mon
)
212 MigrationCapabilityStatusList
*caps
, *cap
;
214 caps
= qmp_query_migrate_capabilities(NULL
);
217 monitor_printf(mon
, "capabilities: ");
218 for (cap
= caps
; cap
; cap
= cap
->next
) {
219 monitor_printf(mon
, "%s: %s ",
220 MigrationCapability_lookup
[cap
->value
->capability
],
221 cap
->value
->state
? "on" : "off");
223 monitor_printf(mon
, "\n");
226 qapi_free_MigrationCapabilityStatusList(caps
);
229 void hmp_info_migrate_cache_size(Monitor
*mon
)
231 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
232 qmp_query_migrate_cache_size(NULL
) >> 10);
235 void hmp_info_cpus(Monitor
*mon
)
237 CpuInfoList
*cpu_list
, *cpu
;
239 cpu_list
= qmp_query_cpus(NULL
);
241 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
244 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
248 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
250 if (cpu
->value
->has_pc
) {
251 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
253 if (cpu
->value
->has_nip
) {
254 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
256 if (cpu
->value
->has_npc
) {
257 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
259 if (cpu
->value
->has_PC
) {
260 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
263 if (cpu
->value
->halted
) {
264 monitor_printf(mon
, " (halted)");
267 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
270 qapi_free_CpuInfoList(cpu_list
);
273 void hmp_info_block(Monitor
*mon
)
275 BlockInfoList
*block_list
, *info
;
277 block_list
= qmp_query_block(NULL
);
279 for (info
= block_list
; info
; info
= info
->next
) {
280 monitor_printf(mon
, "%s: removable=%d",
281 info
->value
->device
, info
->value
->removable
);
283 if (info
->value
->removable
) {
284 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
285 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
288 if (info
->value
->has_io_status
) {
289 monitor_printf(mon
, " io-status=%s",
290 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
293 if (info
->value
->has_inserted
) {
294 monitor_printf(mon
, " file=");
295 monitor_print_filename(mon
, info
->value
->inserted
->file
);
297 if (info
->value
->inserted
->has_backing_file
) {
298 monitor_printf(mon
, " backing_file=");
299 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
300 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
301 info
->value
->inserted
->backing_file_depth
);
303 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
304 info
->value
->inserted
->ro
,
305 info
->value
->inserted
->drv
,
306 info
->value
->inserted
->encrypted
);
308 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
309 " bps_wr=%" PRId64
" iops=%" PRId64
310 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
311 info
->value
->inserted
->bps
,
312 info
->value
->inserted
->bps_rd
,
313 info
->value
->inserted
->bps_wr
,
314 info
->value
->inserted
->iops
,
315 info
->value
->inserted
->iops_rd
,
316 info
->value
->inserted
->iops_wr
);
318 monitor_printf(mon
, " [not inserted]");
321 monitor_printf(mon
, "\n");
324 qapi_free_BlockInfoList(block_list
);
327 void hmp_info_blockstats(Monitor
*mon
)
329 BlockStatsList
*stats_list
, *stats
;
331 stats_list
= qmp_query_blockstats(NULL
);
333 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
334 if (!stats
->value
->has_device
) {
338 monitor_printf(mon
, "%s:", stats
->value
->device
);
339 monitor_printf(mon
, " rd_bytes=%" PRId64
341 " rd_operations=%" PRId64
342 " wr_operations=%" PRId64
343 " flush_operations=%" PRId64
344 " wr_total_time_ns=%" PRId64
345 " rd_total_time_ns=%" PRId64
346 " flush_total_time_ns=%" PRId64
348 stats
->value
->stats
->rd_bytes
,
349 stats
->value
->stats
->wr_bytes
,
350 stats
->value
->stats
->rd_operations
,
351 stats
->value
->stats
->wr_operations
,
352 stats
->value
->stats
->flush_operations
,
353 stats
->value
->stats
->wr_total_time_ns
,
354 stats
->value
->stats
->rd_total_time_ns
,
355 stats
->value
->stats
->flush_total_time_ns
);
358 qapi_free_BlockStatsList(stats_list
);
361 void hmp_info_vnc(Monitor
*mon
)
365 VncClientInfoList
*client
;
367 info
= qmp_query_vnc(&err
);
369 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
374 if (!info
->enabled
) {
375 monitor_printf(mon
, "Server: disabled\n");
379 monitor_printf(mon
, "Server:\n");
380 if (info
->has_host
&& info
->has_service
) {
381 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
383 if (info
->has_auth
) {
384 monitor_printf(mon
, " auth: %s\n", info
->auth
);
387 if (!info
->has_clients
|| info
->clients
== NULL
) {
388 monitor_printf(mon
, "Client: none\n");
390 for (client
= info
->clients
; client
; client
= client
->next
) {
391 monitor_printf(mon
, "Client:\n");
392 monitor_printf(mon
, " address: %s:%s\n",
393 client
->value
->host
, client
->value
->service
);
394 monitor_printf(mon
, " x509_dname: %s\n",
395 client
->value
->x509_dname
?
396 client
->value
->x509_dname
: "none");
397 monitor_printf(mon
, " username: %s\n",
398 client
->value
->has_sasl_username
?
399 client
->value
->sasl_username
: "none");
404 qapi_free_VncInfo(info
);
407 void hmp_info_spice(Monitor
*mon
)
409 SpiceChannelList
*chan
;
412 info
= qmp_query_spice(NULL
);
414 if (!info
->enabled
) {
415 monitor_printf(mon
, "Server: disabled\n");
419 monitor_printf(mon
, "Server:\n");
420 if (info
->has_port
) {
421 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
422 info
->host
, info
->port
);
424 if (info
->has_tls_port
) {
425 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
426 info
->host
, info
->tls_port
);
428 monitor_printf(mon
, " migrated: %s\n",
429 info
->migrated
? "true" : "false");
430 monitor_printf(mon
, " auth: %s\n", info
->auth
);
431 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
432 monitor_printf(mon
, " mouse-mode: %s\n",
433 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
435 if (!info
->has_channels
|| info
->channels
== NULL
) {
436 monitor_printf(mon
, "Channels: none\n");
438 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
439 monitor_printf(mon
, "Channel:\n");
440 monitor_printf(mon
, " address: %s:%s%s\n",
441 chan
->value
->host
, chan
->value
->port
,
442 chan
->value
->tls
? " [tls]" : "");
443 monitor_printf(mon
, " session: %" PRId64
"\n",
444 chan
->value
->connection_id
);
445 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
446 chan
->value
->channel_type
, chan
->value
->channel_id
);
451 qapi_free_SpiceInfo(info
);
454 void hmp_info_balloon(Monitor
*mon
)
459 info
= qmp_query_balloon(&err
);
461 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
466 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
467 if (info
->has_mem_swapped_in
) {
468 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
470 if (info
->has_mem_swapped_out
) {
471 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
473 if (info
->has_major_page_faults
) {
474 monitor_printf(mon
, " major_page_faults=%" PRId64
,
475 info
->major_page_faults
);
477 if (info
->has_minor_page_faults
) {
478 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
479 info
->minor_page_faults
);
481 if (info
->has_free_mem
) {
482 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
484 if (info
->has_total_mem
) {
485 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
488 monitor_printf(mon
, "\n");
490 qapi_free_BalloonInfo(info
);
493 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
495 PciMemoryRegionList
*region
;
497 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
498 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
499 dev
->slot
, dev
->function
);
500 monitor_printf(mon
, " ");
502 if (dev
->class_info
.has_desc
) {
503 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
505 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
508 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
509 dev
->id
.vendor
, dev
->id
.device
);
512 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
515 if (dev
->has_pci_bridge
) {
516 monitor_printf(mon
, " BUS %" PRId64
".\n",
517 dev
->pci_bridge
->bus
.number
);
518 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
519 dev
->pci_bridge
->bus
.secondary
);
520 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
521 dev
->pci_bridge
->bus
.subordinate
);
523 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
524 dev
->pci_bridge
->bus
.io_range
->base
,
525 dev
->pci_bridge
->bus
.io_range
->limit
);
528 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
529 dev
->pci_bridge
->bus
.memory_range
->base
,
530 dev
->pci_bridge
->bus
.memory_range
->limit
);
532 monitor_printf(mon
, " prefetchable memory range "
533 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
534 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
535 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
538 for (region
= dev
->regions
; region
; region
= region
->next
) {
541 addr
= region
->value
->address
;
542 size
= region
->value
->size
;
544 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
546 if (!strcmp(region
->value
->type
, "io")) {
547 monitor_printf(mon
, "I/O at 0x%04" PRIx64
548 " [0x%04" PRIx64
"].\n",
549 addr
, addr
+ size
- 1);
551 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
552 " [0x%08" PRIx64
"].\n",
553 region
->value
->mem_type_64
? 64 : 32,
554 region
->value
->prefetch
? " prefetchable" : "",
555 addr
, addr
+ size
- 1);
559 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
561 if (dev
->has_pci_bridge
) {
562 if (dev
->pci_bridge
->has_devices
) {
563 PciDeviceInfoList
*cdev
;
564 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
565 hmp_info_pci_device(mon
, cdev
->value
);
571 void hmp_info_pci(Monitor
*mon
)
573 PciInfoList
*info_list
, *info
;
576 info_list
= qmp_query_pci(&err
);
578 monitor_printf(mon
, "PCI devices not supported\n");
583 for (info
= info_list
; info
; info
= info
->next
) {
584 PciDeviceInfoList
*dev
;
586 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
587 hmp_info_pci_device(mon
, dev
->value
);
591 qapi_free_PciInfoList(info_list
);
594 void hmp_info_block_jobs(Monitor
*mon
)
596 BlockJobInfoList
*list
;
599 list
= qmp_query_block_jobs(&err
);
603 monitor_printf(mon
, "No active jobs\n");
608 if (strcmp(list
->value
->type
, "stream") == 0) {
609 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
610 " of %" PRId64
" bytes, speed limit %" PRId64
617 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
618 " of %" PRId64
" bytes, speed limit %" PRId64
630 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
632 monitor_suspend(mon
);
636 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
641 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
643 qmp_system_reset(NULL
);
646 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
648 qmp_system_powerdown(NULL
);
651 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
655 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
656 use it are converted to the QAPI */
657 cpu_index
= qdict_get_int(qdict
, "index");
658 if (monitor_set_cpu(cpu_index
) < 0) {
659 monitor_printf(mon
, "invalid CPU index\n");
663 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
665 uint32_t size
= qdict_get_int(qdict
, "size");
666 const char *filename
= qdict_get_str(qdict
, "filename");
667 uint64_t addr
= qdict_get_int(qdict
, "val");
670 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
671 hmp_handle_error(mon
, &errp
);
674 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
676 uint32_t size
= qdict_get_int(qdict
, "size");
677 const char *filename
= qdict_get_str(qdict
, "filename");
678 uint64_t addr
= qdict_get_int(qdict
, "val");
681 qmp_pmemsave(addr
, size
, filename
, &errp
);
682 hmp_handle_error(mon
, &errp
);
685 static void hmp_cont_cb(void *opaque
, int err
)
692 static bool key_is_missing(const BlockInfo
*bdev
)
694 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
697 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
699 BlockInfoList
*bdev_list
, *bdev
;
702 bdev_list
= qmp_query_block(NULL
);
703 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
704 if (key_is_missing(bdev
->value
)) {
705 monitor_read_block_device_key(mon
, bdev
->value
->device
,
712 hmp_handle_error(mon
, &errp
);
715 qapi_free_BlockInfoList(bdev_list
);
718 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
720 qmp_system_wakeup(NULL
);
723 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
727 qmp_inject_nmi(&errp
);
728 hmp_handle_error(mon
, &errp
);
731 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
733 const char *name
= qdict_get_str(qdict
, "name");
734 int up
= qdict_get_bool(qdict
, "up");
737 qmp_set_link(name
, up
, &errp
);
738 hmp_handle_error(mon
, &errp
);
741 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
743 const char *device
= qdict_get_str(qdict
, "device");
744 const char *password
= qdict_get_str(qdict
, "password");
747 qmp_block_passwd(device
, password
, &errp
);
748 hmp_handle_error(mon
, &errp
);
751 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
753 int64_t value
= qdict_get_int(qdict
, "value");
756 qmp_balloon(value
, &errp
);
757 if (error_is_set(&errp
)) {
758 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
763 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
765 const char *device
= qdict_get_str(qdict
, "device");
766 int64_t size
= qdict_get_int(qdict
, "size");
769 qmp_block_resize(device
, size
, &errp
);
770 hmp_handle_error(mon
, &errp
);
773 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
775 const char *device
= qdict_get_str(qdict
, "device");
776 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
777 const char *format
= qdict_get_try_str(qdict
, "format");
778 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
779 enum NewImageMode mode
;
783 /* In the future, if 'snapshot-file' is not specified, the snapshot
784 will be taken internally. Today it's actually required. */
785 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
786 hmp_handle_error(mon
, &errp
);
790 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
791 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
793 hmp_handle_error(mon
, &errp
);
796 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
798 qmp_migrate_cancel(NULL
);
801 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
803 double value
= qdict_get_double(qdict
, "value");
804 qmp_migrate_set_downtime(value
, NULL
);
807 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
809 int64_t value
= qdict_get_int(qdict
, "value");
812 qmp_migrate_set_cache_size(value
, &err
);
814 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
820 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
822 int64_t value
= qdict_get_int(qdict
, "value");
823 qmp_migrate_set_speed(value
, NULL
);
826 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
828 const char *cap
= qdict_get_str(qdict
, "capability");
829 bool state
= qdict_get_bool(qdict
, "state");
831 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
834 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
835 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
836 caps
->value
= g_malloc0(sizeof(*caps
->value
));
837 caps
->value
->capability
= i
;
838 caps
->value
->state
= state
;
840 qmp_migrate_set_capabilities(caps
, &err
);
845 if (i
== MIGRATION_CAPABILITY_MAX
) {
846 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
849 qapi_free_MigrationCapabilityStatusList(caps
);
852 monitor_printf(mon
, "migrate_set_parameter: %s\n",
853 error_get_pretty(err
));
858 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
860 const char *protocol
= qdict_get_str(qdict
, "protocol");
861 const char *password
= qdict_get_str(qdict
, "password");
862 const char *connected
= qdict_get_try_str(qdict
, "connected");
865 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
866 hmp_handle_error(mon
, &err
);
869 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
871 const char *protocol
= qdict_get_str(qdict
, "protocol");
872 const char *whenstr
= qdict_get_str(qdict
, "time");
875 qmp_expire_password(protocol
, whenstr
, &err
);
876 hmp_handle_error(mon
, &err
);
879 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
881 int force
= qdict_get_try_bool(qdict
, "force", 0);
882 const char *device
= qdict_get_str(qdict
, "device");
885 qmp_eject(device
, true, force
, &err
);
886 hmp_handle_error(mon
, &err
);
889 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
892 qmp_change_vnc_password(password
, NULL
);
893 monitor_read_command(mon
, 1);
896 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
898 const char *device
= qdict_get_str(qdict
, "device");
899 const char *target
= qdict_get_str(qdict
, "target");
900 const char *arg
= qdict_get_try_str(qdict
, "arg");
903 if (strcmp(device
, "vnc") == 0 &&
904 (strcmp(target
, "passwd") == 0 ||
905 strcmp(target
, "password") == 0)) {
907 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
912 qmp_change(device
, target
, !!arg
, arg
, &err
);
913 if (error_is_set(&err
) &&
914 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
916 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
919 hmp_handle_error(mon
, &err
);
922 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
926 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
927 qdict_get_int(qdict
, "bps"),
928 qdict_get_int(qdict
, "bps_rd"),
929 qdict_get_int(qdict
, "bps_wr"),
930 qdict_get_int(qdict
, "iops"),
931 qdict_get_int(qdict
, "iops_rd"),
932 qdict_get_int(qdict
, "iops_wr"), &err
);
933 hmp_handle_error(mon
, &err
);
936 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
939 const char *device
= qdict_get_str(qdict
, "device");
940 const char *base
= qdict_get_try_str(qdict
, "base");
941 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
943 qmp_block_stream(device
, base
!= NULL
, base
,
944 qdict_haskey(qdict
, "speed"), speed
,
945 BLOCKDEV_ON_ERROR_REPORT
, true, &error
);
947 hmp_handle_error(mon
, &error
);
950 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
953 const char *device
= qdict_get_str(qdict
, "device");
954 int64_t value
= qdict_get_int(qdict
, "speed");
956 qmp_block_job_set_speed(device
, value
, &error
);
958 hmp_handle_error(mon
, &error
);
961 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
964 const char *device
= qdict_get_str(qdict
, "device");
965 bool force
= qdict_get_try_bool(qdict
, "force", 0);
967 qmp_block_job_cancel(device
, true, force
, &error
);
969 hmp_handle_error(mon
, &error
);
972 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
975 const char *device
= qdict_get_str(qdict
, "device");
977 qmp_block_job_pause(device
, &error
);
979 hmp_handle_error(mon
, &error
);
982 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
985 const char *device
= qdict_get_str(qdict
, "device");
987 qmp_block_job_resume(device
, &error
);
989 hmp_handle_error(mon
, &error
);
992 typedef struct MigrationStatus
996 bool is_block_migration
;
999 static void hmp_migrate_status_cb(void *opaque
)
1001 MigrationStatus
*status
= opaque
;
1002 MigrationInfo
*info
;
1004 info
= qmp_query_migrate(NULL
);
1005 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
1006 if (info
->has_disk
) {
1009 if (info
->disk
->remaining
) {
1010 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1015 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1016 monitor_flush(status
->mon
);
1019 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
1021 if (status
->is_block_migration
) {
1022 monitor_printf(status
->mon
, "\n");
1024 monitor_resume(status
->mon
);
1025 qemu_del_timer(status
->timer
);
1029 qapi_free_MigrationInfo(info
);
1032 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1034 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1035 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1036 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1037 const char *uri
= qdict_get_str(qdict
, "uri");
1040 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1042 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1048 MigrationStatus
*status
;
1050 if (monitor_suspend(mon
) < 0) {
1051 monitor_printf(mon
, "terminal does not allow synchronous "
1052 "migration, continuing detached\n");
1056 status
= g_malloc0(sizeof(*status
));
1058 status
->is_block_migration
= blk
|| inc
;
1059 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1061 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1065 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1067 const char *id
= qdict_get_str(qdict
, "id");
1070 qmp_device_del(id
, &err
);
1071 hmp_handle_error(mon
, &err
);
1074 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1077 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1078 const char *file
= qdict_get_str(qdict
, "filename");
1079 bool has_begin
= qdict_haskey(qdict
, "begin");
1080 bool has_length
= qdict_haskey(qdict
, "length");
1086 begin
= qdict_get_int(qdict
, "begin");
1089 length
= qdict_get_int(qdict
, "length");
1092 prot
= g_strconcat("file:", file
, NULL
);
1094 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1096 hmp_handle_error(mon
, &errp
);
1100 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1105 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1106 if (error_is_set(&err
)) {
1110 netdev_add(opts
, &err
);
1111 if (error_is_set(&err
)) {
1112 qemu_opts_del(opts
);
1116 hmp_handle_error(mon
, &err
);
1119 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1121 const char *id
= qdict_get_str(qdict
, "id");
1124 qmp_netdev_del(id
, &err
);
1125 hmp_handle_error(mon
, &err
);
1128 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1130 const char *fdname
= qdict_get_str(qdict
, "fdname");
1133 qmp_getfd(fdname
, &errp
);
1134 hmp_handle_error(mon
, &errp
);
1137 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1139 const char *fdname
= qdict_get_str(qdict
, "fdname");
1142 qmp_closefd(fdname
, &errp
);
1143 hmp_handle_error(mon
, &errp
);
1146 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1148 const char *keys
= qdict_get_str(qdict
, "keys");
1149 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1150 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1151 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1153 char keyname_buf
[16];
1158 separator
= strchr(keys
, '-');
1159 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1160 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1162 /* Be compatible with old interface, convert user inputted "<" */
1163 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1164 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1167 keyname_buf
[keyname_len
] = 0;
1169 keylist
= g_malloc0(sizeof(*keylist
));
1170 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1176 tmp
->next
= keylist
;
1180 if (strstart(keyname_buf
, "0x", NULL
)) {
1182 int value
= strtoul(keyname_buf
, &endp
, 0);
1183 if (*endp
!= '\0') {
1186 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1187 keylist
->value
->number
= value
;
1189 int idx
= index_from_key(keyname_buf
);
1190 if (idx
== Q_KEY_CODE_MAX
) {
1193 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1194 keylist
->value
->qcode
= idx
;
1200 keys
= separator
+ 1;
1203 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1204 hmp_handle_error(mon
, &err
);
1207 qapi_free_KeyValueList(head
);
1211 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1215 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1217 const char *filename
= qdict_get_str(qdict
, "filename");
1220 qmp_screendump(filename
, &err
);
1221 hmp_handle_error(mon
, &err
);