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",
167 if (info
->has_setup_time
) {
168 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
174 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
175 info
->ram
->transferred
>> 10);
176 monitor_printf(mon
, "throughput: %0.2f mbps\n",
178 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
179 info
->ram
->remaining
>> 10);
180 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
181 info
->ram
->total
>> 10);
182 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
183 info
->ram
->duplicate
);
184 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
186 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
188 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
189 info
->ram
->normal_bytes
>> 10);
190 if (info
->ram
->dirty_pages_rate
) {
191 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
192 info
->ram
->dirty_pages_rate
);
196 if (info
->has_disk
) {
197 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
198 info
->disk
->transferred
>> 10);
199 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
200 info
->disk
->remaining
>> 10);
201 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
202 info
->disk
->total
>> 10);
205 if (info
->has_xbzrle_cache
) {
206 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
207 info
->xbzrle_cache
->cache_size
);
208 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
209 info
->xbzrle_cache
->bytes
>> 10);
210 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
211 info
->xbzrle_cache
->pages
);
212 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
213 info
->xbzrle_cache
->cache_miss
);
214 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
215 info
->xbzrle_cache
->overflow
);
218 qapi_free_MigrationInfo(info
);
219 qapi_free_MigrationCapabilityStatusList(caps
);
222 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
224 MigrationCapabilityStatusList
*caps
, *cap
;
226 caps
= qmp_query_migrate_capabilities(NULL
);
229 monitor_printf(mon
, "capabilities: ");
230 for (cap
= caps
; cap
; cap
= cap
->next
) {
231 monitor_printf(mon
, "%s: %s ",
232 MigrationCapability_lookup
[cap
->value
->capability
],
233 cap
->value
->state
? "on" : "off");
235 monitor_printf(mon
, "\n");
238 qapi_free_MigrationCapabilityStatusList(caps
);
241 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
243 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
244 qmp_query_migrate_cache_size(NULL
) >> 10);
247 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
249 CpuInfoList
*cpu_list
, *cpu
;
251 cpu_list
= qmp_query_cpus(NULL
);
253 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
256 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
260 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
262 if (cpu
->value
->has_pc
) {
263 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
265 if (cpu
->value
->has_nip
) {
266 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
268 if (cpu
->value
->has_npc
) {
269 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
271 if (cpu
->value
->has_PC
) {
272 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
275 if (cpu
->value
->halted
) {
276 monitor_printf(mon
, " (halted)");
279 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
282 qapi_free_CpuInfoList(cpu_list
);
285 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
287 BlockInfoList
*block_list
, *info
;
288 ImageInfo
*image_info
;
289 const char *device
= qdict_get_try_str(qdict
, "device");
290 bool verbose
= qdict_get_try_bool(qdict
, "verbose", 0);
292 block_list
= qmp_query_block(NULL
);
294 for (info
= block_list
; info
; info
= info
->next
) {
295 if (device
&& strcmp(device
, info
->value
->device
)) {
299 if (info
!= block_list
) {
300 monitor_printf(mon
, "\n");
303 monitor_printf(mon
, "%s", info
->value
->device
);
304 if (info
->value
->has_inserted
) {
305 monitor_printf(mon
, ": %s (%s%s%s)\n",
306 info
->value
->inserted
->file
,
307 info
->value
->inserted
->drv
,
308 info
->value
->inserted
->ro
? ", read-only" : "",
309 info
->value
->inserted
->encrypted
? ", encrypted" : "");
311 monitor_printf(mon
, ": [not inserted]\n");
314 if (info
->value
->has_io_status
&& info
->value
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
315 monitor_printf(mon
, " I/O status: %s\n",
316 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
319 if (info
->value
->removable
) {
320 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
321 info
->value
->locked
? "" : "not ",
322 info
->value
->tray_open
? "open" : "closed");
326 if (!info
->value
->has_inserted
) {
330 if (info
->value
->inserted
->has_backing_file
) {
333 "(chain depth: %" PRId64
")\n",
334 info
->value
->inserted
->backing_file
,
335 info
->value
->inserted
->backing_file_depth
);
338 if (info
->value
->inserted
->bps
339 || info
->value
->inserted
->bps_rd
340 || info
->value
->inserted
->bps_wr
341 || info
->value
->inserted
->iops
342 || info
->value
->inserted
->iops_rd
343 || info
->value
->inserted
->iops_wr
)
345 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
346 " bps_rd=%" PRId64
" bps_wr=%" PRId64
348 " bps_rd_max=%" PRId64
349 " bps_wr_max=%" PRId64
350 " iops=%" PRId64
" iops_rd=%" PRId64
353 " iops_rd_max=%" PRId64
354 " iops_wr_max=%" PRId64
355 " iops_size=%" PRId64
"\n",
356 info
->value
->inserted
->bps
,
357 info
->value
->inserted
->bps_rd
,
358 info
->value
->inserted
->bps_wr
,
359 info
->value
->inserted
->bps_max
,
360 info
->value
->inserted
->bps_rd_max
,
361 info
->value
->inserted
->bps_wr_max
,
362 info
->value
->inserted
->iops
,
363 info
->value
->inserted
->iops_rd
,
364 info
->value
->inserted
->iops_wr
,
365 info
->value
->inserted
->iops_max
,
366 info
->value
->inserted
->iops_rd_max
,
367 info
->value
->inserted
->iops_wr_max
,
368 info
->value
->inserted
->iops_size
);
370 monitor_printf(mon
, " [not inserted]");
374 monitor_printf(mon
, "\nImages:\n");
375 image_info
= info
->value
->inserted
->image
;
377 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
379 if (image_info
->has_backing_image
) {
380 image_info
= image_info
->backing_image
;
388 qapi_free_BlockInfoList(block_list
);
391 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
393 BlockStatsList
*stats_list
, *stats
;
395 stats_list
= qmp_query_blockstats(NULL
);
397 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
398 if (!stats
->value
->has_device
) {
402 monitor_printf(mon
, "%s:", stats
->value
->device
);
403 monitor_printf(mon
, " rd_bytes=%" PRId64
405 " rd_operations=%" PRId64
406 " wr_operations=%" PRId64
407 " flush_operations=%" PRId64
408 " wr_total_time_ns=%" PRId64
409 " rd_total_time_ns=%" PRId64
410 " flush_total_time_ns=%" PRId64
412 stats
->value
->stats
->rd_bytes
,
413 stats
->value
->stats
->wr_bytes
,
414 stats
->value
->stats
->rd_operations
,
415 stats
->value
->stats
->wr_operations
,
416 stats
->value
->stats
->flush_operations
,
417 stats
->value
->stats
->wr_total_time_ns
,
418 stats
->value
->stats
->rd_total_time_ns
,
419 stats
->value
->stats
->flush_total_time_ns
);
422 qapi_free_BlockStatsList(stats_list
);
425 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
429 VncClientInfoList
*client
;
431 info
= qmp_query_vnc(&err
);
433 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
438 if (!info
->enabled
) {
439 monitor_printf(mon
, "Server: disabled\n");
443 monitor_printf(mon
, "Server:\n");
444 if (info
->has_host
&& info
->has_service
) {
445 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
447 if (info
->has_auth
) {
448 monitor_printf(mon
, " auth: %s\n", info
->auth
);
451 if (!info
->has_clients
|| info
->clients
== NULL
) {
452 monitor_printf(mon
, "Client: none\n");
454 for (client
= info
->clients
; client
; client
= client
->next
) {
455 monitor_printf(mon
, "Client:\n");
456 monitor_printf(mon
, " address: %s:%s\n",
457 client
->value
->host
, client
->value
->service
);
458 monitor_printf(mon
, " x509_dname: %s\n",
459 client
->value
->x509_dname
?
460 client
->value
->x509_dname
: "none");
461 monitor_printf(mon
, " username: %s\n",
462 client
->value
->has_sasl_username
?
463 client
->value
->sasl_username
: "none");
468 qapi_free_VncInfo(info
);
471 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
473 SpiceChannelList
*chan
;
476 info
= qmp_query_spice(NULL
);
478 if (!info
->enabled
) {
479 monitor_printf(mon
, "Server: disabled\n");
483 monitor_printf(mon
, "Server:\n");
484 if (info
->has_port
) {
485 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
486 info
->host
, info
->port
);
488 if (info
->has_tls_port
) {
489 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
490 info
->host
, info
->tls_port
);
492 monitor_printf(mon
, " migrated: %s\n",
493 info
->migrated
? "true" : "false");
494 monitor_printf(mon
, " auth: %s\n", info
->auth
);
495 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
496 monitor_printf(mon
, " mouse-mode: %s\n",
497 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
499 if (!info
->has_channels
|| info
->channels
== NULL
) {
500 monitor_printf(mon
, "Channels: none\n");
502 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
503 monitor_printf(mon
, "Channel:\n");
504 monitor_printf(mon
, " address: %s:%s%s\n",
505 chan
->value
->host
, chan
->value
->port
,
506 chan
->value
->tls
? " [tls]" : "");
507 monitor_printf(mon
, " session: %" PRId64
"\n",
508 chan
->value
->connection_id
);
509 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
510 chan
->value
->channel_type
, chan
->value
->channel_id
);
515 qapi_free_SpiceInfo(info
);
518 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
523 info
= qmp_query_balloon(&err
);
525 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
530 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
532 qapi_free_BalloonInfo(info
);
535 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
537 PciMemoryRegionList
*region
;
539 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
540 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
541 dev
->slot
, dev
->function
);
542 monitor_printf(mon
, " ");
544 if (dev
->class_info
.has_desc
) {
545 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
547 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.q_class
);
550 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
551 dev
->id
.vendor
, dev
->id
.device
);
554 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
557 if (dev
->has_pci_bridge
) {
558 monitor_printf(mon
, " BUS %" PRId64
".\n",
559 dev
->pci_bridge
->bus
.number
);
560 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
561 dev
->pci_bridge
->bus
.secondary
);
562 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
563 dev
->pci_bridge
->bus
.subordinate
);
565 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
566 dev
->pci_bridge
->bus
.io_range
->base
,
567 dev
->pci_bridge
->bus
.io_range
->limit
);
570 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
571 dev
->pci_bridge
->bus
.memory_range
->base
,
572 dev
->pci_bridge
->bus
.memory_range
->limit
);
574 monitor_printf(mon
, " prefetchable memory range "
575 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
576 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
577 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
580 for (region
= dev
->regions
; region
; region
= region
->next
) {
583 addr
= region
->value
->address
;
584 size
= region
->value
->size
;
586 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
588 if (!strcmp(region
->value
->type
, "io")) {
589 monitor_printf(mon
, "I/O at 0x%04" PRIx64
590 " [0x%04" PRIx64
"].\n",
591 addr
, addr
+ size
- 1);
593 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
594 " [0x%08" PRIx64
"].\n",
595 region
->value
->mem_type_64
? 64 : 32,
596 region
->value
->prefetch
? " prefetchable" : "",
597 addr
, addr
+ size
- 1);
601 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
603 if (dev
->has_pci_bridge
) {
604 if (dev
->pci_bridge
->has_devices
) {
605 PciDeviceInfoList
*cdev
;
606 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
607 hmp_info_pci_device(mon
, cdev
->value
);
613 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
615 PciInfoList
*info_list
, *info
;
618 info_list
= qmp_query_pci(&err
);
620 monitor_printf(mon
, "PCI devices not supported\n");
625 for (info
= info_list
; info
; info
= info
->next
) {
626 PciDeviceInfoList
*dev
;
628 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
629 hmp_info_pci_device(mon
, dev
->value
);
633 qapi_free_PciInfoList(info_list
);
636 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
638 BlockJobInfoList
*list
;
641 list
= qmp_query_block_jobs(&err
);
645 monitor_printf(mon
, "No active jobs\n");
650 if (strcmp(list
->value
->type
, "stream") == 0) {
651 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
652 " of %" PRId64
" bytes, speed limit %" PRId64
659 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
660 " of %" PRId64
" bytes, speed limit %" PRId64
672 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
674 TPMInfoList
*info_list
, *info
;
677 TPMPassthroughOptions
*tpo
;
679 info_list
= qmp_query_tpm(&err
);
681 monitor_printf(mon
, "TPM device not supported\n");
687 monitor_printf(mon
, "TPM device:\n");
690 for (info
= info_list
; info
; info
= info
->next
) {
691 TPMInfo
*ti
= info
->value
;
692 monitor_printf(mon
, " tpm%d: model=%s\n",
693 c
, TpmModel_lookup
[ti
->model
]);
695 monitor_printf(mon
, " \\ %s: type=%s",
696 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
698 switch (ti
->options
->kind
) {
699 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
700 tpo
= ti
->options
->passthrough
;
701 monitor_printf(mon
, "%s%s%s%s",
702 tpo
->has_path
? ",path=" : "",
703 tpo
->has_path
? tpo
->path
: "",
704 tpo
->has_cancel_path
? ",cancel-path=" : "",
705 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
707 case TPM_TYPE_OPTIONS_KIND_MAX
:
710 monitor_printf(mon
, "\n");
713 qapi_free_TPMInfoList(info_list
);
716 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
718 monitor_suspend(mon
);
722 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
727 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
729 qmp_system_reset(NULL
);
732 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
734 qmp_system_powerdown(NULL
);
737 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
741 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
742 use it are converted to the QAPI */
743 cpu_index
= qdict_get_int(qdict
, "index");
744 if (monitor_set_cpu(cpu_index
) < 0) {
745 monitor_printf(mon
, "invalid CPU index\n");
749 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
751 uint32_t size
= qdict_get_int(qdict
, "size");
752 const char *filename
= qdict_get_str(qdict
, "filename");
753 uint64_t addr
= qdict_get_int(qdict
, "val");
756 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
757 hmp_handle_error(mon
, &errp
);
760 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
762 uint32_t size
= qdict_get_int(qdict
, "size");
763 const char *filename
= qdict_get_str(qdict
, "filename");
764 uint64_t addr
= qdict_get_int(qdict
, "val");
767 qmp_pmemsave(addr
, size
, filename
, &errp
);
768 hmp_handle_error(mon
, &errp
);
771 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
773 const char *chardev
= qdict_get_str(qdict
, "device");
774 const char *data
= qdict_get_str(qdict
, "data");
777 qmp_ringbuf_write(chardev
, data
, false, 0, &errp
);
779 hmp_handle_error(mon
, &errp
);
782 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
784 uint32_t size
= qdict_get_int(qdict
, "size");
785 const char *chardev
= qdict_get_str(qdict
, "device");
790 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &errp
);
792 monitor_printf(mon
, "%s\n", error_get_pretty(errp
));
797 for (i
= 0; data
[i
]; i
++) {
798 unsigned char ch
= data
[i
];
801 monitor_printf(mon
, "\\\\");
802 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
803 monitor_printf(mon
, "\\u%04X", ch
);
805 monitor_printf(mon
, "%c", ch
);
809 monitor_printf(mon
, "\n");
813 static void hmp_cont_cb(void *opaque
, int err
)
820 static bool key_is_missing(const BlockInfo
*bdev
)
822 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
825 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
827 BlockInfoList
*bdev_list
, *bdev
;
830 bdev_list
= qmp_query_block(NULL
);
831 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
832 if (key_is_missing(bdev
->value
)) {
833 monitor_read_block_device_key(mon
, bdev
->value
->device
,
840 hmp_handle_error(mon
, &errp
);
843 qapi_free_BlockInfoList(bdev_list
);
846 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
848 qmp_system_wakeup(NULL
);
851 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
855 qmp_inject_nmi(&errp
);
856 hmp_handle_error(mon
, &errp
);
859 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
861 const char *name
= qdict_get_str(qdict
, "name");
862 int up
= qdict_get_bool(qdict
, "up");
865 qmp_set_link(name
, up
, &errp
);
866 hmp_handle_error(mon
, &errp
);
869 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
871 const char *device
= qdict_get_str(qdict
, "device");
872 const char *password
= qdict_get_str(qdict
, "password");
875 qmp_block_passwd(device
, password
, &errp
);
876 hmp_handle_error(mon
, &errp
);
879 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
881 int64_t value
= qdict_get_int(qdict
, "value");
884 qmp_balloon(value
, &errp
);
885 if (error_is_set(&errp
)) {
886 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
891 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
893 const char *device
= qdict_get_str(qdict
, "device");
894 int64_t size
= qdict_get_int(qdict
, "size");
897 qmp_block_resize(device
, size
, &errp
);
898 hmp_handle_error(mon
, &errp
);
901 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
903 const char *device
= qdict_get_str(qdict
, "device");
904 const char *filename
= qdict_get_str(qdict
, "target");
905 const char *format
= qdict_get_try_str(qdict
, "format");
906 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
907 int full
= qdict_get_try_bool(qdict
, "full", 0);
908 enum NewImageMode mode
;
912 error_set(&errp
, QERR_MISSING_PARAMETER
, "target");
913 hmp_handle_error(mon
, &errp
);
918 mode
= NEW_IMAGE_MODE_EXISTING
;
920 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
923 qmp_drive_mirror(device
, filename
, !!format
, format
,
924 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
925 true, mode
, false, 0, false, 0, false, 0,
926 false, 0, false, 0, &errp
);
927 hmp_handle_error(mon
, &errp
);
930 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
932 const char *device
= qdict_get_str(qdict
, "device");
933 const char *filename
= qdict_get_str(qdict
, "target");
934 const char *format
= qdict_get_try_str(qdict
, "format");
935 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
936 int full
= qdict_get_try_bool(qdict
, "full", 0);
937 enum NewImageMode mode
;
941 error_set(&errp
, QERR_MISSING_PARAMETER
, "target");
942 hmp_handle_error(mon
, &errp
);
947 mode
= NEW_IMAGE_MODE_EXISTING
;
949 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
952 qmp_drive_backup(device
, filename
, !!format
, format
,
953 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
954 true, mode
, false, 0, false, 0, false, 0, &errp
);
955 hmp_handle_error(mon
, &errp
);
958 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
960 const char *device
= qdict_get_str(qdict
, "device");
961 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
962 const char *format
= qdict_get_try_str(qdict
, "format");
963 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
964 enum NewImageMode mode
;
968 /* In the future, if 'snapshot-file' is not specified, the snapshot
969 will be taken internally. Today it's actually required. */
970 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
971 hmp_handle_error(mon
, &errp
);
975 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
976 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
978 hmp_handle_error(mon
, &errp
);
981 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
983 const char *device
= qdict_get_str(qdict
, "device");
984 const char *name
= qdict_get_str(qdict
, "name");
987 qmp_blockdev_snapshot_internal_sync(device
, name
, &errp
);
988 hmp_handle_error(mon
, &errp
);
991 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
993 const char *device
= qdict_get_str(qdict
, "device");
994 const char *name
= qdict_get_str(qdict
, "name");
995 const char *id
= qdict_get_try_str(qdict
, "id");
998 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1000 hmp_handle_error(mon
, &errp
);
1003 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1005 qmp_migrate_cancel(NULL
);
1008 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1010 double value
= qdict_get_double(qdict
, "value");
1011 qmp_migrate_set_downtime(value
, NULL
);
1014 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1016 int64_t value
= qdict_get_int(qdict
, "value");
1019 qmp_migrate_set_cache_size(value
, &err
);
1021 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1027 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1029 int64_t value
= qdict_get_int(qdict
, "value");
1030 qmp_migrate_set_speed(value
, NULL
);
1033 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1035 const char *cap
= qdict_get_str(qdict
, "capability");
1036 bool state
= qdict_get_bool(qdict
, "state");
1038 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1041 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1042 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1043 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1044 caps
->value
->capability
= i
;
1045 caps
->value
->state
= state
;
1047 qmp_migrate_set_capabilities(caps
, &err
);
1052 if (i
== MIGRATION_CAPABILITY_MAX
) {
1053 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
1056 qapi_free_MigrationCapabilityStatusList(caps
);
1059 monitor_printf(mon
, "migrate_set_capability: %s\n",
1060 error_get_pretty(err
));
1065 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1067 const char *protocol
= qdict_get_str(qdict
, "protocol");
1068 const char *password
= qdict_get_str(qdict
, "password");
1069 const char *connected
= qdict_get_try_str(qdict
, "connected");
1072 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1073 hmp_handle_error(mon
, &err
);
1076 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1078 const char *protocol
= qdict_get_str(qdict
, "protocol");
1079 const char *whenstr
= qdict_get_str(qdict
, "time");
1082 qmp_expire_password(protocol
, whenstr
, &err
);
1083 hmp_handle_error(mon
, &err
);
1086 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1088 int force
= qdict_get_try_bool(qdict
, "force", 0);
1089 const char *device
= qdict_get_str(qdict
, "device");
1092 qmp_eject(device
, true, force
, &err
);
1093 hmp_handle_error(mon
, &err
);
1096 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
1099 qmp_change_vnc_password(password
, NULL
);
1100 monitor_read_command(mon
, 1);
1103 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1105 const char *device
= qdict_get_str(qdict
, "device");
1106 const char *target
= qdict_get_str(qdict
, "target");
1107 const char *arg
= qdict_get_try_str(qdict
, "arg");
1110 if (strcmp(device
, "vnc") == 0 &&
1111 (strcmp(target
, "passwd") == 0 ||
1112 strcmp(target
, "password") == 0)) {
1114 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1119 qmp_change(device
, target
, !!arg
, arg
, &err
);
1120 if (error_is_set(&err
) &&
1121 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1123 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1126 hmp_handle_error(mon
, &err
);
1129 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1133 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1134 qdict_get_int(qdict
, "bps"),
1135 qdict_get_int(qdict
, "bps_rd"),
1136 qdict_get_int(qdict
, "bps_wr"),
1137 qdict_get_int(qdict
, "iops"),
1138 qdict_get_int(qdict
, "iops_rd"),
1139 qdict_get_int(qdict
, "iops_wr"),
1140 false, /* no burst max via HMP */
1152 false, /* No default I/O size */
1154 hmp_handle_error(mon
, &err
);
1157 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1159 Error
*error
= NULL
;
1160 const char *device
= qdict_get_str(qdict
, "device");
1161 const char *base
= qdict_get_try_str(qdict
, "base");
1162 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1164 qmp_block_stream(device
, base
!= NULL
, base
,
1165 qdict_haskey(qdict
, "speed"), speed
,
1166 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1168 hmp_handle_error(mon
, &error
);
1171 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1173 Error
*error
= NULL
;
1174 const char *device
= qdict_get_str(qdict
, "device");
1175 int64_t value
= qdict_get_int(qdict
, "speed");
1177 qmp_block_job_set_speed(device
, value
, &error
);
1179 hmp_handle_error(mon
, &error
);
1182 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1184 Error
*error
= NULL
;
1185 const char *device
= qdict_get_str(qdict
, "device");
1186 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1188 qmp_block_job_cancel(device
, true, force
, &error
);
1190 hmp_handle_error(mon
, &error
);
1193 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1195 Error
*error
= NULL
;
1196 const char *device
= qdict_get_str(qdict
, "device");
1198 qmp_block_job_pause(device
, &error
);
1200 hmp_handle_error(mon
, &error
);
1203 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1205 Error
*error
= NULL
;
1206 const char *device
= qdict_get_str(qdict
, "device");
1208 qmp_block_job_resume(device
, &error
);
1210 hmp_handle_error(mon
, &error
);
1213 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1215 Error
*error
= NULL
;
1216 const char *device
= qdict_get_str(qdict
, "device");
1218 qmp_block_job_complete(device
, &error
);
1220 hmp_handle_error(mon
, &error
);
1223 typedef struct MigrationStatus
1227 bool is_block_migration
;
1230 static void hmp_migrate_status_cb(void *opaque
)
1232 MigrationStatus
*status
= opaque
;
1233 MigrationInfo
*info
;
1235 info
= qmp_query_migrate(NULL
);
1236 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
1237 if (info
->has_disk
) {
1240 if (info
->disk
->remaining
) {
1241 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1246 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1247 monitor_flush(status
->mon
);
1250 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1252 if (status
->is_block_migration
) {
1253 monitor_printf(status
->mon
, "\n");
1255 monitor_resume(status
->mon
);
1256 timer_del(status
->timer
);
1260 qapi_free_MigrationInfo(info
);
1263 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1265 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1266 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1267 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1268 const char *uri
= qdict_get_str(qdict
, "uri");
1271 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1273 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1279 MigrationStatus
*status
;
1281 if (monitor_suspend(mon
) < 0) {
1282 monitor_printf(mon
, "terminal does not allow synchronous "
1283 "migration, continuing detached\n");
1287 status
= g_malloc0(sizeof(*status
));
1289 status
->is_block_migration
= blk
|| inc
;
1290 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1292 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1296 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1298 const char *id
= qdict_get_str(qdict
, "id");
1301 qmp_device_del(id
, &err
);
1302 hmp_handle_error(mon
, &err
);
1305 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1308 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1309 const char *file
= qdict_get_str(qdict
, "filename");
1310 bool has_begin
= qdict_haskey(qdict
, "begin");
1311 bool has_length
= qdict_haskey(qdict
, "length");
1317 begin
= qdict_get_int(qdict
, "begin");
1320 length
= qdict_get_int(qdict
, "length");
1323 prot
= g_strconcat("file:", file
, NULL
);
1325 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1327 hmp_handle_error(mon
, &errp
);
1331 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1336 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1337 if (error_is_set(&err
)) {
1341 netdev_add(opts
, &err
);
1342 if (error_is_set(&err
)) {
1343 qemu_opts_del(opts
);
1347 hmp_handle_error(mon
, &err
);
1350 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1352 const char *id
= qdict_get_str(qdict
, "id");
1355 qmp_netdev_del(id
, &err
);
1356 hmp_handle_error(mon
, &err
);
1359 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1361 const char *fdname
= qdict_get_str(qdict
, "fdname");
1364 qmp_getfd(fdname
, &errp
);
1365 hmp_handle_error(mon
, &errp
);
1368 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1370 const char *fdname
= qdict_get_str(qdict
, "fdname");
1373 qmp_closefd(fdname
, &errp
);
1374 hmp_handle_error(mon
, &errp
);
1377 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1379 const char *keys
= qdict_get_str(qdict
, "keys");
1380 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1381 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1382 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1384 char keyname_buf
[16];
1389 separator
= strchr(keys
, '-');
1390 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1391 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1393 /* Be compatible with old interface, convert user inputted "<" */
1394 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1395 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1398 keyname_buf
[keyname_len
] = 0;
1400 keylist
= g_malloc0(sizeof(*keylist
));
1401 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1407 tmp
->next
= keylist
;
1411 if (strstart(keyname_buf
, "0x", NULL
)) {
1413 int value
= strtoul(keyname_buf
, &endp
, 0);
1414 if (*endp
!= '\0') {
1417 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1418 keylist
->value
->number
= value
;
1420 int idx
= index_from_key(keyname_buf
);
1421 if (idx
== Q_KEY_CODE_MAX
) {
1424 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1425 keylist
->value
->qcode
= idx
;
1431 keys
= separator
+ 1;
1434 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1435 hmp_handle_error(mon
, &err
);
1438 qapi_free_KeyValueList(head
);
1442 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1446 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1448 const char *filename
= qdict_get_str(qdict
, "filename");
1451 qmp_screendump(filename
, &err
);
1452 hmp_handle_error(mon
, &err
);
1455 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1457 const char *uri
= qdict_get_str(qdict
, "uri");
1458 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1459 int all
= qdict_get_try_bool(qdict
, "all", 0);
1460 Error
*local_err
= NULL
;
1461 BlockInfoList
*block_list
, *info
;
1462 SocketAddress
*addr
;
1464 if (writable
&& !all
) {
1465 error_setg(&local_err
, "-w only valid together with -a");
1469 /* First check if the address is valid and start the server. */
1470 addr
= socket_parse(uri
, &local_err
);
1471 if (local_err
!= NULL
) {
1475 qmp_nbd_server_start(addr
, &local_err
);
1476 qapi_free_SocketAddress(addr
);
1477 if (local_err
!= NULL
) {
1485 /* Then try adding all block devices. If one fails, close all and
1488 block_list
= qmp_query_block(NULL
);
1490 for (info
= block_list
; info
; info
= info
->next
) {
1491 if (!info
->value
->has_inserted
) {
1495 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1497 if (local_err
!= NULL
) {
1498 qmp_nbd_server_stop(NULL
);
1503 qapi_free_BlockInfoList(block_list
);
1506 hmp_handle_error(mon
, &local_err
);
1509 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1511 const char *device
= qdict_get_str(qdict
, "device");
1512 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1513 Error
*local_err
= NULL
;
1515 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1517 if (local_err
!= NULL
) {
1518 hmp_handle_error(mon
, &local_err
);
1522 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1526 qmp_nbd_server_stop(&errp
);
1527 hmp_handle_error(mon
, &errp
);
1530 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1532 const char *args
= qdict_get_str(qdict
, "args");
1536 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1538 error_setg(&err
, "Parsing chardev args failed");
1540 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1542 hmp_handle_error(mon
, &err
);
1545 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1547 Error
*local_err
= NULL
;
1549 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1550 hmp_handle_error(mon
, &local_err
);
1553 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1555 BlockDriverState
*bs
;
1556 const char* device
= qdict_get_str(qdict
, "device");
1557 const char* command
= qdict_get_str(qdict
, "command");
1560 bs
= bdrv_find(device
);
1562 qemuio_command(bs
, command
);
1564 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1567 hmp_handle_error(mon
, &err
);