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 "sysemu/char.h"
19 #include "qemu/option.h"
20 #include "qemu/timer.h"
21 #include "qmp-commands.h"
22 #include "qemu/sockets.h"
23 #include "monitor/monitor.h"
24 #include "ui/console.h"
25 #include "block/qapi.h"
28 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
30 if (error_is_set(errp
)) {
31 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
36 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
40 info
= qmp_query_name(NULL
);
42 monitor_printf(mon
, "%s\n", info
->name
);
44 qapi_free_NameInfo(info
);
47 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
51 info
= qmp_query_version(NULL
);
53 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
54 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
57 qapi_free_VersionInfo(info
);
60 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
64 info
= qmp_query_kvm(NULL
);
65 monitor_printf(mon
, "kvm support: ");
67 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
69 monitor_printf(mon
, "not compiled\n");
72 qapi_free_KvmInfo(info
);
75 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
79 info
= qmp_query_status(NULL
);
81 monitor_printf(mon
, "VM status: %s%s",
82 info
->running
? "running" : "paused",
83 info
->singlestep
? " (single step mode)" : "");
85 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
86 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
89 monitor_printf(mon
, "\n");
91 qapi_free_StatusInfo(info
);
94 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
98 info
= qmp_query_uuid(NULL
);
99 monitor_printf(mon
, "%s\n", info
->UUID
);
100 qapi_free_UuidInfo(info
);
103 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
105 ChardevInfoList
*char_info
, *info
;
107 char_info
= qmp_query_chardev(NULL
);
108 for (info
= char_info
; info
; info
= info
->next
) {
109 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
110 info
->value
->filename
);
113 qapi_free_ChardevInfoList(char_info
);
116 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
118 MouseInfoList
*mice_list
, *mouse
;
120 mice_list
= qmp_query_mice(NULL
);
122 monitor_printf(mon
, "No mouse devices connected\n");
126 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
127 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
128 mouse
->value
->current
? '*' : ' ',
129 mouse
->value
->index
, mouse
->value
->name
,
130 mouse
->value
->absolute
? " (absolute)" : "");
133 qapi_free_MouseInfoList(mice_list
);
136 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
139 MigrationCapabilityStatusList
*caps
, *cap
;
141 info
= qmp_query_migrate(NULL
);
142 caps
= qmp_query_migrate_capabilities(NULL
);
144 /* do not display parameters during setup */
145 if (info
->has_status
&& caps
) {
146 monitor_printf(mon
, "capabilities: ");
147 for (cap
= caps
; cap
; cap
= cap
->next
) {
148 monitor_printf(mon
, "%s: %s ",
149 MigrationCapability_lookup
[cap
->value
->capability
],
150 cap
->value
->state
? "on" : "off");
152 monitor_printf(mon
, "\n");
155 if (info
->has_status
) {
156 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
157 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
159 if (info
->has_expected_downtime
) {
160 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
161 info
->expected_downtime
);
163 if (info
->has_downtime
) {
164 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
170 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
171 info
->ram
->transferred
>> 10);
172 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
173 info
->ram
->remaining
>> 10);
174 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
175 info
->ram
->total
>> 10);
176 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
177 info
->ram
->duplicate
);
178 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
180 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
182 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
183 info
->ram
->normal_bytes
>> 10);
184 if (info
->ram
->dirty_pages_rate
) {
185 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
186 info
->ram
->dirty_pages_rate
);
190 if (info
->has_disk
) {
191 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
192 info
->disk
->transferred
>> 10);
193 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
194 info
->disk
->remaining
>> 10);
195 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
196 info
->disk
->total
>> 10);
199 if (info
->has_xbzrle_cache
) {
200 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
201 info
->xbzrle_cache
->cache_size
);
202 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
203 info
->xbzrle_cache
->bytes
>> 10);
204 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
205 info
->xbzrle_cache
->pages
);
206 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
207 info
->xbzrle_cache
->cache_miss
);
208 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
209 info
->xbzrle_cache
->overflow
);
212 qapi_free_MigrationInfo(info
);
213 qapi_free_MigrationCapabilityStatusList(caps
);
216 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
218 MigrationCapabilityStatusList
*caps
, *cap
;
220 caps
= qmp_query_migrate_capabilities(NULL
);
223 monitor_printf(mon
, "capabilities: ");
224 for (cap
= caps
; cap
; cap
= cap
->next
) {
225 monitor_printf(mon
, "%s: %s ",
226 MigrationCapability_lookup
[cap
->value
->capability
],
227 cap
->value
->state
? "on" : "off");
229 monitor_printf(mon
, "\n");
232 qapi_free_MigrationCapabilityStatusList(caps
);
235 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
237 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
238 qmp_query_migrate_cache_size(NULL
) >> 10);
241 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
243 CpuInfoList
*cpu_list
, *cpu
;
245 cpu_list
= qmp_query_cpus(NULL
);
247 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
250 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
254 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
256 if (cpu
->value
->has_pc
) {
257 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
259 if (cpu
->value
->has_nip
) {
260 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
262 if (cpu
->value
->has_npc
) {
263 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
265 if (cpu
->value
->has_PC
) {
266 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
269 if (cpu
->value
->halted
) {
270 monitor_printf(mon
, " (halted)");
273 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
276 qapi_free_CpuInfoList(cpu_list
);
279 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
281 BlockInfoList
*block_list
, *info
;
282 ImageInfo
*image_info
;
284 block_list
= qmp_query_block(NULL
);
286 for (info
= block_list
; info
; info
= info
->next
) {
287 monitor_printf(mon
, "%s: removable=%d",
288 info
->value
->device
, info
->value
->removable
);
290 if (info
->value
->removable
) {
291 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
292 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
295 if (info
->value
->has_io_status
) {
296 monitor_printf(mon
, " io-status=%s",
297 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
300 if (info
->value
->has_inserted
) {
301 monitor_printf(mon
, " file=");
302 monitor_print_filename(mon
, info
->value
->inserted
->file
);
304 if (info
->value
->inserted
->has_backing_file
) {
305 monitor_printf(mon
, " backing_file=");
306 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
307 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
308 info
->value
->inserted
->backing_file_depth
);
310 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
311 info
->value
->inserted
->ro
,
312 info
->value
->inserted
->drv
,
313 info
->value
->inserted
->encrypted
);
315 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
316 " bps_wr=%" PRId64
" iops=%" PRId64
317 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
318 info
->value
->inserted
->bps
,
319 info
->value
->inserted
->bps_rd
,
320 info
->value
->inserted
->bps_wr
,
321 info
->value
->inserted
->iops
,
322 info
->value
->inserted
->iops_rd
,
323 info
->value
->inserted
->iops_wr
);
325 monitor_printf(mon
, " images:\n");
326 image_info
= info
->value
->inserted
->image
;
328 bdrv_image_info_dump((fprintf_function
)monitor_printf
, mon
,
330 if (image_info
->has_backing_image
) {
331 image_info
= image_info
->backing_image
;
337 monitor_printf(mon
, " [not inserted]");
340 monitor_printf(mon
, "\n");
343 qapi_free_BlockInfoList(block_list
);
346 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
348 BlockStatsList
*stats_list
, *stats
;
350 stats_list
= qmp_query_blockstats(NULL
);
352 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
353 if (!stats
->value
->has_device
) {
357 monitor_printf(mon
, "%s:", stats
->value
->device
);
358 monitor_printf(mon
, " rd_bytes=%" PRId64
360 " rd_operations=%" PRId64
361 " wr_operations=%" PRId64
362 " flush_operations=%" PRId64
363 " wr_total_time_ns=%" PRId64
364 " rd_total_time_ns=%" PRId64
365 " flush_total_time_ns=%" PRId64
367 stats
->value
->stats
->rd_bytes
,
368 stats
->value
->stats
->wr_bytes
,
369 stats
->value
->stats
->rd_operations
,
370 stats
->value
->stats
->wr_operations
,
371 stats
->value
->stats
->flush_operations
,
372 stats
->value
->stats
->wr_total_time_ns
,
373 stats
->value
->stats
->rd_total_time_ns
,
374 stats
->value
->stats
->flush_total_time_ns
);
377 qapi_free_BlockStatsList(stats_list
);
380 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
384 VncClientInfoList
*client
;
386 info
= qmp_query_vnc(&err
);
388 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
393 if (!info
->enabled
) {
394 monitor_printf(mon
, "Server: disabled\n");
398 monitor_printf(mon
, "Server:\n");
399 if (info
->has_host
&& info
->has_service
) {
400 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
402 if (info
->has_auth
) {
403 monitor_printf(mon
, " auth: %s\n", info
->auth
);
406 if (!info
->has_clients
|| info
->clients
== NULL
) {
407 monitor_printf(mon
, "Client: none\n");
409 for (client
= info
->clients
; client
; client
= client
->next
) {
410 monitor_printf(mon
, "Client:\n");
411 monitor_printf(mon
, " address: %s:%s\n",
412 client
->value
->host
, client
->value
->service
);
413 monitor_printf(mon
, " x509_dname: %s\n",
414 client
->value
->x509_dname
?
415 client
->value
->x509_dname
: "none");
416 monitor_printf(mon
, " username: %s\n",
417 client
->value
->has_sasl_username
?
418 client
->value
->sasl_username
: "none");
423 qapi_free_VncInfo(info
);
426 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
428 SpiceChannelList
*chan
;
431 info
= qmp_query_spice(NULL
);
433 if (!info
->enabled
) {
434 monitor_printf(mon
, "Server: disabled\n");
438 monitor_printf(mon
, "Server:\n");
439 if (info
->has_port
) {
440 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
441 info
->host
, info
->port
);
443 if (info
->has_tls_port
) {
444 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
445 info
->host
, info
->tls_port
);
447 monitor_printf(mon
, " migrated: %s\n",
448 info
->migrated
? "true" : "false");
449 monitor_printf(mon
, " auth: %s\n", info
->auth
);
450 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
451 monitor_printf(mon
, " mouse-mode: %s\n",
452 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
454 if (!info
->has_channels
|| info
->channels
== NULL
) {
455 monitor_printf(mon
, "Channels: none\n");
457 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
458 monitor_printf(mon
, "Channel:\n");
459 monitor_printf(mon
, " address: %s:%s%s\n",
460 chan
->value
->host
, chan
->value
->port
,
461 chan
->value
->tls
? " [tls]" : "");
462 monitor_printf(mon
, " session: %" PRId64
"\n",
463 chan
->value
->connection_id
);
464 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
465 chan
->value
->channel_type
, chan
->value
->channel_id
);
470 qapi_free_SpiceInfo(info
);
473 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
478 info
= qmp_query_balloon(&err
);
480 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
485 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
487 qapi_free_BalloonInfo(info
);
490 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
492 PciMemoryRegionList
*region
;
494 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
495 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
496 dev
->slot
, dev
->function
);
497 monitor_printf(mon
, " ");
499 if (dev
->class_info
.has_desc
) {
500 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
502 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
505 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
506 dev
->id
.vendor
, dev
->id
.device
);
509 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
512 if (dev
->has_pci_bridge
) {
513 monitor_printf(mon
, " BUS %" PRId64
".\n",
514 dev
->pci_bridge
->bus
.number
);
515 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
516 dev
->pci_bridge
->bus
.secondary
);
517 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
518 dev
->pci_bridge
->bus
.subordinate
);
520 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
521 dev
->pci_bridge
->bus
.io_range
->base
,
522 dev
->pci_bridge
->bus
.io_range
->limit
);
525 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
526 dev
->pci_bridge
->bus
.memory_range
->base
,
527 dev
->pci_bridge
->bus
.memory_range
->limit
);
529 monitor_printf(mon
, " prefetchable memory range "
530 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
531 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
532 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
535 for (region
= dev
->regions
; region
; region
= region
->next
) {
538 addr
= region
->value
->address
;
539 size
= region
->value
->size
;
541 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
543 if (!strcmp(region
->value
->type
, "io")) {
544 monitor_printf(mon
, "I/O at 0x%04" PRIx64
545 " [0x%04" PRIx64
"].\n",
546 addr
, addr
+ size
- 1);
548 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
549 " [0x%08" PRIx64
"].\n",
550 region
->value
->mem_type_64
? 64 : 32,
551 region
->value
->prefetch
? " prefetchable" : "",
552 addr
, addr
+ size
- 1);
556 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
558 if (dev
->has_pci_bridge
) {
559 if (dev
->pci_bridge
->has_devices
) {
560 PciDeviceInfoList
*cdev
;
561 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
562 hmp_info_pci_device(mon
, cdev
->value
);
568 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
570 PciInfoList
*info_list
, *info
;
573 info_list
= qmp_query_pci(&err
);
575 monitor_printf(mon
, "PCI devices not supported\n");
580 for (info
= info_list
; info
; info
= info
->next
) {
581 PciDeviceInfoList
*dev
;
583 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
584 hmp_info_pci_device(mon
, dev
->value
);
588 qapi_free_PciInfoList(info_list
);
591 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
593 BlockJobInfoList
*list
;
596 list
= qmp_query_block_jobs(&err
);
600 monitor_printf(mon
, "No active jobs\n");
605 if (strcmp(list
->value
->type
, "stream") == 0) {
606 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
607 " of %" PRId64
" bytes, speed limit %" PRId64
614 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
615 " of %" PRId64
" bytes, speed limit %" PRId64
627 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
629 TPMInfoList
*info_list
, *info
;
632 TPMPassthroughOptions
*tpo
;
634 info_list
= qmp_query_tpm(&err
);
636 monitor_printf(mon
, "TPM device not supported\n");
642 monitor_printf(mon
, "TPM device:\n");
645 for (info
= info_list
; info
; info
= info
->next
) {
646 TPMInfo
*ti
= info
->value
;
647 monitor_printf(mon
, " tpm%d: model=%s\n",
648 c
, TpmModel_lookup
[ti
->model
]);
650 monitor_printf(mon
, " \\ %s: type=%s",
651 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
653 switch (ti
->options
->kind
) {
654 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
655 tpo
= ti
->options
->passthrough
;
656 monitor_printf(mon
, "%s%s%s%s",
657 tpo
->has_path
? ",path=" : "",
658 tpo
->has_path
? tpo
->path
: "",
659 tpo
->has_cancel_path
? ",cancel-path=" : "",
660 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
662 case TPM_TYPE_OPTIONS_KIND_MAX
:
665 monitor_printf(mon
, "\n");
668 qapi_free_TPMInfoList(info_list
);
671 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
673 monitor_suspend(mon
);
677 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
682 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
684 qmp_system_reset(NULL
);
687 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
689 qmp_system_powerdown(NULL
);
692 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
696 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
697 use it are converted to the QAPI */
698 cpu_index
= qdict_get_int(qdict
, "index");
699 if (monitor_set_cpu(cpu_index
) < 0) {
700 monitor_printf(mon
, "invalid CPU index\n");
704 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
706 uint32_t size
= qdict_get_int(qdict
, "size");
707 const char *filename
= qdict_get_str(qdict
, "filename");
708 uint64_t addr
= qdict_get_int(qdict
, "val");
711 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
712 hmp_handle_error(mon
, &errp
);
715 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
717 uint32_t size
= qdict_get_int(qdict
, "size");
718 const char *filename
= qdict_get_str(qdict
, "filename");
719 uint64_t addr
= qdict_get_int(qdict
, "val");
722 qmp_pmemsave(addr
, size
, filename
, &errp
);
723 hmp_handle_error(mon
, &errp
);
726 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
728 const char *chardev
= qdict_get_str(qdict
, "device");
729 const char *data
= qdict_get_str(qdict
, "data");
732 qmp_ringbuf_write(chardev
, data
, false, 0, &errp
);
734 hmp_handle_error(mon
, &errp
);
737 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
739 uint32_t size
= qdict_get_int(qdict
, "size");
740 const char *chardev
= qdict_get_str(qdict
, "device");
745 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &errp
);
747 monitor_printf(mon
, "%s\n", error_get_pretty(errp
));
752 for (i
= 0; data
[i
]; i
++) {
753 unsigned char ch
= data
[i
];
756 monitor_printf(mon
, "\\\\");
757 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
758 monitor_printf(mon
, "\\u%04X", ch
);
760 monitor_printf(mon
, "%c", ch
);
764 monitor_printf(mon
, "\n");
768 static void hmp_cont_cb(void *opaque
, int err
)
775 static bool key_is_missing(const BlockInfo
*bdev
)
777 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
780 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
782 BlockInfoList
*bdev_list
, *bdev
;
785 bdev_list
= qmp_query_block(NULL
);
786 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
787 if (key_is_missing(bdev
->value
)) {
788 monitor_read_block_device_key(mon
, bdev
->value
->device
,
795 hmp_handle_error(mon
, &errp
);
798 qapi_free_BlockInfoList(bdev_list
);
801 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
803 qmp_system_wakeup(NULL
);
806 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
810 qmp_inject_nmi(&errp
);
811 hmp_handle_error(mon
, &errp
);
814 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
816 const char *name
= qdict_get_str(qdict
, "name");
817 int up
= qdict_get_bool(qdict
, "up");
820 qmp_set_link(name
, up
, &errp
);
821 hmp_handle_error(mon
, &errp
);
824 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
826 const char *device
= qdict_get_str(qdict
, "device");
827 const char *password
= qdict_get_str(qdict
, "password");
830 qmp_block_passwd(device
, password
, &errp
);
831 hmp_handle_error(mon
, &errp
);
834 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
836 int64_t value
= qdict_get_int(qdict
, "value");
839 qmp_balloon(value
, &errp
);
840 if (error_is_set(&errp
)) {
841 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
846 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
848 const char *device
= qdict_get_str(qdict
, "device");
849 int64_t size
= qdict_get_int(qdict
, "size");
852 qmp_block_resize(device
, size
, &errp
);
853 hmp_handle_error(mon
, &errp
);
856 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
858 const char *device
= qdict_get_str(qdict
, "device");
859 const char *filename
= qdict_get_str(qdict
, "target");
860 const char *format
= qdict_get_try_str(qdict
, "format");
861 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
862 int full
= qdict_get_try_bool(qdict
, "full", 0);
863 enum NewImageMode mode
;
867 error_set(&errp
, QERR_MISSING_PARAMETER
, "target");
868 hmp_handle_error(mon
, &errp
);
873 mode
= NEW_IMAGE_MODE_EXISTING
;
875 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
878 qmp_drive_mirror(device
, filename
, !!format
, format
,
879 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
880 true, mode
, false, 0, false, 0, false, 0,
881 false, 0, false, 0, &errp
);
882 hmp_handle_error(mon
, &errp
);
885 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
887 const char *device
= qdict_get_str(qdict
, "device");
888 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
889 const char *format
= qdict_get_try_str(qdict
, "format");
890 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
891 enum NewImageMode mode
;
895 /* In the future, if 'snapshot-file' is not specified, the snapshot
896 will be taken internally. Today it's actually required. */
897 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
898 hmp_handle_error(mon
, &errp
);
902 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
903 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
905 hmp_handle_error(mon
, &errp
);
908 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
910 qmp_migrate_cancel(NULL
);
913 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
915 double value
= qdict_get_double(qdict
, "value");
916 qmp_migrate_set_downtime(value
, NULL
);
919 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
921 int64_t value
= qdict_get_int(qdict
, "value");
924 qmp_migrate_set_cache_size(value
, &err
);
926 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
932 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
934 int64_t value
= qdict_get_int(qdict
, "value");
935 qmp_migrate_set_speed(value
, NULL
);
938 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
940 const char *cap
= qdict_get_str(qdict
, "capability");
941 bool state
= qdict_get_bool(qdict
, "state");
943 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
946 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
947 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
948 caps
->value
= g_malloc0(sizeof(*caps
->value
));
949 caps
->value
->capability
= i
;
950 caps
->value
->state
= state
;
952 qmp_migrate_set_capabilities(caps
, &err
);
957 if (i
== MIGRATION_CAPABILITY_MAX
) {
958 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
961 qapi_free_MigrationCapabilityStatusList(caps
);
964 monitor_printf(mon
, "migrate_set_capability: %s\n",
965 error_get_pretty(err
));
970 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
972 const char *protocol
= qdict_get_str(qdict
, "protocol");
973 const char *password
= qdict_get_str(qdict
, "password");
974 const char *connected
= qdict_get_try_str(qdict
, "connected");
977 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
978 hmp_handle_error(mon
, &err
);
981 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
983 const char *protocol
= qdict_get_str(qdict
, "protocol");
984 const char *whenstr
= qdict_get_str(qdict
, "time");
987 qmp_expire_password(protocol
, whenstr
, &err
);
988 hmp_handle_error(mon
, &err
);
991 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
993 int force
= qdict_get_try_bool(qdict
, "force", 0);
994 const char *device
= qdict_get_str(qdict
, "device");
997 qmp_eject(device
, true, force
, &err
);
998 hmp_handle_error(mon
, &err
);
1001 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
1004 qmp_change_vnc_password(password
, NULL
);
1005 monitor_read_command(mon
, 1);
1008 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1010 const char *device
= qdict_get_str(qdict
, "device");
1011 const char *target
= qdict_get_str(qdict
, "target");
1012 const char *arg
= qdict_get_try_str(qdict
, "arg");
1015 if (strcmp(device
, "vnc") == 0 &&
1016 (strcmp(target
, "passwd") == 0 ||
1017 strcmp(target
, "password") == 0)) {
1019 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1024 qmp_change(device
, target
, !!arg
, arg
, &err
);
1025 if (error_is_set(&err
) &&
1026 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1028 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1031 hmp_handle_error(mon
, &err
);
1034 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1038 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1039 qdict_get_int(qdict
, "bps"),
1040 qdict_get_int(qdict
, "bps_rd"),
1041 qdict_get_int(qdict
, "bps_wr"),
1042 qdict_get_int(qdict
, "iops"),
1043 qdict_get_int(qdict
, "iops_rd"),
1044 qdict_get_int(qdict
, "iops_wr"), &err
);
1045 hmp_handle_error(mon
, &err
);
1048 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1050 Error
*error
= NULL
;
1051 const char *device
= qdict_get_str(qdict
, "device");
1052 const char *base
= qdict_get_try_str(qdict
, "base");
1053 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1055 qmp_block_stream(device
, base
!= NULL
, base
,
1056 qdict_haskey(qdict
, "speed"), speed
,
1057 BLOCKDEV_ON_ERROR_REPORT
, true, &error
);
1059 hmp_handle_error(mon
, &error
);
1062 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1064 Error
*error
= NULL
;
1065 const char *device
= qdict_get_str(qdict
, "device");
1066 int64_t value
= qdict_get_int(qdict
, "speed");
1068 qmp_block_job_set_speed(device
, value
, &error
);
1070 hmp_handle_error(mon
, &error
);
1073 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1075 Error
*error
= NULL
;
1076 const char *device
= qdict_get_str(qdict
, "device");
1077 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1079 qmp_block_job_cancel(device
, true, force
, &error
);
1081 hmp_handle_error(mon
, &error
);
1084 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1086 Error
*error
= NULL
;
1087 const char *device
= qdict_get_str(qdict
, "device");
1089 qmp_block_job_pause(device
, &error
);
1091 hmp_handle_error(mon
, &error
);
1094 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1096 Error
*error
= NULL
;
1097 const char *device
= qdict_get_str(qdict
, "device");
1099 qmp_block_job_resume(device
, &error
);
1101 hmp_handle_error(mon
, &error
);
1104 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1106 Error
*error
= NULL
;
1107 const char *device
= qdict_get_str(qdict
, "device");
1109 qmp_block_job_complete(device
, &error
);
1111 hmp_handle_error(mon
, &error
);
1114 typedef struct MigrationStatus
1118 bool is_block_migration
;
1121 static void hmp_migrate_status_cb(void *opaque
)
1123 MigrationStatus
*status
= opaque
;
1124 MigrationInfo
*info
;
1126 info
= qmp_query_migrate(NULL
);
1127 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
1128 if (info
->has_disk
) {
1131 if (info
->disk
->remaining
) {
1132 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1137 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1138 monitor_flush(status
->mon
);
1141 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
1143 if (status
->is_block_migration
) {
1144 monitor_printf(status
->mon
, "\n");
1146 monitor_resume(status
->mon
);
1147 qemu_del_timer(status
->timer
);
1151 qapi_free_MigrationInfo(info
);
1154 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1156 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1157 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1158 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1159 const char *uri
= qdict_get_str(qdict
, "uri");
1162 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1164 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1170 MigrationStatus
*status
;
1172 if (monitor_suspend(mon
) < 0) {
1173 monitor_printf(mon
, "terminal does not allow synchronous "
1174 "migration, continuing detached\n");
1178 status
= g_malloc0(sizeof(*status
));
1180 status
->is_block_migration
= blk
|| inc
;
1181 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1183 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1187 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1189 const char *id
= qdict_get_str(qdict
, "id");
1192 qmp_device_del(id
, &err
);
1193 hmp_handle_error(mon
, &err
);
1196 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1199 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1200 const char *file
= qdict_get_str(qdict
, "filename");
1201 bool has_begin
= qdict_haskey(qdict
, "begin");
1202 bool has_length
= qdict_haskey(qdict
, "length");
1208 begin
= qdict_get_int(qdict
, "begin");
1211 length
= qdict_get_int(qdict
, "length");
1214 prot
= g_strconcat("file:", file
, NULL
);
1216 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1218 hmp_handle_error(mon
, &errp
);
1222 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1227 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1228 if (error_is_set(&err
)) {
1232 netdev_add(opts
, &err
);
1233 if (error_is_set(&err
)) {
1234 qemu_opts_del(opts
);
1238 hmp_handle_error(mon
, &err
);
1241 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1243 const char *id
= qdict_get_str(qdict
, "id");
1246 qmp_netdev_del(id
, &err
);
1247 hmp_handle_error(mon
, &err
);
1250 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1252 const char *fdname
= qdict_get_str(qdict
, "fdname");
1255 qmp_getfd(fdname
, &errp
);
1256 hmp_handle_error(mon
, &errp
);
1259 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1261 const char *fdname
= qdict_get_str(qdict
, "fdname");
1264 qmp_closefd(fdname
, &errp
);
1265 hmp_handle_error(mon
, &errp
);
1268 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1270 const char *keys
= qdict_get_str(qdict
, "keys");
1271 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1272 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1273 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1275 char keyname_buf
[16];
1280 separator
= strchr(keys
, '-');
1281 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1282 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1284 /* Be compatible with old interface, convert user inputted "<" */
1285 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1286 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1289 keyname_buf
[keyname_len
] = 0;
1291 keylist
= g_malloc0(sizeof(*keylist
));
1292 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1298 tmp
->next
= keylist
;
1302 if (strstart(keyname_buf
, "0x", NULL
)) {
1304 int value
= strtoul(keyname_buf
, &endp
, 0);
1305 if (*endp
!= '\0') {
1308 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1309 keylist
->value
->number
= value
;
1311 int idx
= index_from_key(keyname_buf
);
1312 if (idx
== Q_KEY_CODE_MAX
) {
1315 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1316 keylist
->value
->qcode
= idx
;
1322 keys
= separator
+ 1;
1325 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1326 hmp_handle_error(mon
, &err
);
1329 qapi_free_KeyValueList(head
);
1333 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1337 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1339 const char *filename
= qdict_get_str(qdict
, "filename");
1342 qmp_screendump(filename
, &err
);
1343 hmp_handle_error(mon
, &err
);
1346 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1348 const char *uri
= qdict_get_str(qdict
, "uri");
1349 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1350 int all
= qdict_get_try_bool(qdict
, "all", 0);
1351 Error
*local_err
= NULL
;
1352 BlockInfoList
*block_list
, *info
;
1353 SocketAddress
*addr
;
1355 if (writable
&& !all
) {
1356 error_setg(&local_err
, "-w only valid together with -a");
1360 /* First check if the address is valid and start the server. */
1361 addr
= socket_parse(uri
, &local_err
);
1362 if (local_err
!= NULL
) {
1366 qmp_nbd_server_start(addr
, &local_err
);
1367 qapi_free_SocketAddress(addr
);
1368 if (local_err
!= NULL
) {
1376 /* Then try adding all block devices. If one fails, close all and
1379 block_list
= qmp_query_block(NULL
);
1381 for (info
= block_list
; info
; info
= info
->next
) {
1382 if (!info
->value
->has_inserted
) {
1386 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1388 if (local_err
!= NULL
) {
1389 qmp_nbd_server_stop(NULL
);
1394 qapi_free_BlockInfoList(block_list
);
1397 hmp_handle_error(mon
, &local_err
);
1400 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1402 const char *device
= qdict_get_str(qdict
, "device");
1403 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1404 Error
*local_err
= NULL
;
1406 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1408 if (local_err
!= NULL
) {
1409 hmp_handle_error(mon
, &local_err
);
1413 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1417 qmp_nbd_server_stop(&errp
);
1418 hmp_handle_error(mon
, &errp
);
1421 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1423 const char *args
= qdict_get_str(qdict
, "args");
1427 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1429 error_setg(&err
, "Parsing chardev args failed");
1431 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1433 hmp_handle_error(mon
, &err
);
1436 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1438 Error
*local_err
= NULL
;
1440 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1441 hmp_handle_error(mon
, &local_err
);
1444 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1446 BlockDriverState
*bs
;
1447 const char* device
= qdict_get_str(qdict
, "device");
1448 const char* command
= qdict_get_str(qdict
, "command");
1451 bs
= bdrv_find(device
);
1453 qemuio_command(bs
, command
);
1455 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1458 hmp_handle_error(mon
, &err
);