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"
27 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
29 if (error_is_set(errp
)) {
30 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
35 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
39 info
= qmp_query_name(NULL
);
41 monitor_printf(mon
, "%s\n", info
->name
);
43 qapi_free_NameInfo(info
);
46 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
50 info
= qmp_query_version(NULL
);
52 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
53 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
56 qapi_free_VersionInfo(info
);
59 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
63 info
= qmp_query_kvm(NULL
);
64 monitor_printf(mon
, "kvm support: ");
66 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
68 monitor_printf(mon
, "not compiled\n");
71 qapi_free_KvmInfo(info
);
74 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
78 info
= qmp_query_status(NULL
);
80 monitor_printf(mon
, "VM status: %s%s",
81 info
->running
? "running" : "paused",
82 info
->singlestep
? " (single step mode)" : "");
84 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
85 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
88 monitor_printf(mon
, "\n");
90 qapi_free_StatusInfo(info
);
93 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
97 info
= qmp_query_uuid(NULL
);
98 monitor_printf(mon
, "%s\n", info
->UUID
);
99 qapi_free_UuidInfo(info
);
102 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
104 ChardevInfoList
*char_info
, *info
;
106 char_info
= qmp_query_chardev(NULL
);
107 for (info
= char_info
; info
; info
= info
->next
) {
108 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
109 info
->value
->filename
);
112 qapi_free_ChardevInfoList(char_info
);
115 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
117 MouseInfoList
*mice_list
, *mouse
;
119 mice_list
= qmp_query_mice(NULL
);
121 monitor_printf(mon
, "No mouse devices connected\n");
125 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
126 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
127 mouse
->value
->current
? '*' : ' ',
128 mouse
->value
->index
, mouse
->value
->name
,
129 mouse
->value
->absolute
? " (absolute)" : "");
132 qapi_free_MouseInfoList(mice_list
);
135 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
138 MigrationCapabilityStatusList
*caps
, *cap
;
140 info
= qmp_query_migrate(NULL
);
141 caps
= qmp_query_migrate_capabilities(NULL
);
143 /* do not display parameters during setup */
144 if (info
->has_status
&& caps
) {
145 monitor_printf(mon
, "capabilities: ");
146 for (cap
= caps
; cap
; cap
= cap
->next
) {
147 monitor_printf(mon
, "%s: %s ",
148 MigrationCapability_lookup
[cap
->value
->capability
],
149 cap
->value
->state
? "on" : "off");
151 monitor_printf(mon
, "\n");
154 if (info
->has_status
) {
155 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
156 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
158 if (info
->has_expected_downtime
) {
159 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
160 info
->expected_downtime
);
162 if (info
->has_downtime
) {
163 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
169 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
170 info
->ram
->transferred
>> 10);
171 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
172 info
->ram
->remaining
>> 10);
173 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
174 info
->ram
->total
>> 10);
175 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
176 info
->ram
->duplicate
);
177 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
179 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
181 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
182 info
->ram
->normal_bytes
>> 10);
183 if (info
->ram
->dirty_pages_rate
) {
184 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
185 info
->ram
->dirty_pages_rate
);
189 if (info
->has_disk
) {
190 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
191 info
->disk
->transferred
>> 10);
192 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
193 info
->disk
->remaining
>> 10);
194 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
195 info
->disk
->total
>> 10);
198 if (info
->has_xbzrle_cache
) {
199 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
200 info
->xbzrle_cache
->cache_size
);
201 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
202 info
->xbzrle_cache
->bytes
>> 10);
203 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
204 info
->xbzrle_cache
->pages
);
205 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
206 info
->xbzrle_cache
->cache_miss
);
207 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
208 info
->xbzrle_cache
->overflow
);
211 qapi_free_MigrationInfo(info
);
212 qapi_free_MigrationCapabilityStatusList(caps
);
215 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
217 MigrationCapabilityStatusList
*caps
, *cap
;
219 caps
= qmp_query_migrate_capabilities(NULL
);
222 monitor_printf(mon
, "capabilities: ");
223 for (cap
= caps
; cap
; cap
= cap
->next
) {
224 monitor_printf(mon
, "%s: %s ",
225 MigrationCapability_lookup
[cap
->value
->capability
],
226 cap
->value
->state
? "on" : "off");
228 monitor_printf(mon
, "\n");
231 qapi_free_MigrationCapabilityStatusList(caps
);
234 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
236 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
237 qmp_query_migrate_cache_size(NULL
) >> 10);
240 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
242 CpuInfoList
*cpu_list
, *cpu
;
244 cpu_list
= qmp_query_cpus(NULL
);
246 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
249 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
253 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
255 if (cpu
->value
->has_pc
) {
256 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
258 if (cpu
->value
->has_nip
) {
259 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
261 if (cpu
->value
->has_npc
) {
262 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
264 if (cpu
->value
->has_PC
) {
265 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
268 if (cpu
->value
->halted
) {
269 monitor_printf(mon
, " (halted)");
272 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
275 qapi_free_CpuInfoList(cpu_list
);
278 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
280 BlockInfoList
*block_list
, *info
;
282 block_list
= qmp_query_block(NULL
);
284 for (info
= block_list
; info
; info
= info
->next
) {
285 monitor_printf(mon
, "%s: removable=%d",
286 info
->value
->device
, info
->value
->removable
);
288 if (info
->value
->removable
) {
289 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
290 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
293 if (info
->value
->has_io_status
) {
294 monitor_printf(mon
, " io-status=%s",
295 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
298 if (info
->value
->has_inserted
) {
299 monitor_printf(mon
, " file=");
300 monitor_print_filename(mon
, info
->value
->inserted
->file
);
302 if (info
->value
->inserted
->has_backing_file
) {
303 monitor_printf(mon
, " backing_file=");
304 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
305 monitor_printf(mon
, " backing_file_depth=%" PRId64
,
306 info
->value
->inserted
->backing_file_depth
);
308 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
309 info
->value
->inserted
->ro
,
310 info
->value
->inserted
->drv
,
311 info
->value
->inserted
->encrypted
);
313 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
314 " bps_wr=%" PRId64
" iops=%" PRId64
315 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
316 info
->value
->inserted
->bps
,
317 info
->value
->inserted
->bps_rd
,
318 info
->value
->inserted
->bps_wr
,
319 info
->value
->inserted
->iops
,
320 info
->value
->inserted
->iops_rd
,
321 info
->value
->inserted
->iops_wr
);
323 monitor_printf(mon
, " [not inserted]");
326 monitor_printf(mon
, "\n");
329 qapi_free_BlockInfoList(block_list
);
332 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
334 BlockStatsList
*stats_list
, *stats
;
336 stats_list
= qmp_query_blockstats(NULL
);
338 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
339 if (!stats
->value
->has_device
) {
343 monitor_printf(mon
, "%s:", stats
->value
->device
);
344 monitor_printf(mon
, " rd_bytes=%" PRId64
346 " rd_operations=%" PRId64
347 " wr_operations=%" PRId64
348 " flush_operations=%" PRId64
349 " wr_total_time_ns=%" PRId64
350 " rd_total_time_ns=%" PRId64
351 " flush_total_time_ns=%" PRId64
353 stats
->value
->stats
->rd_bytes
,
354 stats
->value
->stats
->wr_bytes
,
355 stats
->value
->stats
->rd_operations
,
356 stats
->value
->stats
->wr_operations
,
357 stats
->value
->stats
->flush_operations
,
358 stats
->value
->stats
->wr_total_time_ns
,
359 stats
->value
->stats
->rd_total_time_ns
,
360 stats
->value
->stats
->flush_total_time_ns
);
363 qapi_free_BlockStatsList(stats_list
);
366 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
370 VncClientInfoList
*client
;
372 info
= qmp_query_vnc(&err
);
374 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
379 if (!info
->enabled
) {
380 monitor_printf(mon
, "Server: disabled\n");
384 monitor_printf(mon
, "Server:\n");
385 if (info
->has_host
&& info
->has_service
) {
386 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
388 if (info
->has_auth
) {
389 monitor_printf(mon
, " auth: %s\n", info
->auth
);
392 if (!info
->has_clients
|| info
->clients
== NULL
) {
393 monitor_printf(mon
, "Client: none\n");
395 for (client
= info
->clients
; client
; client
= client
->next
) {
396 monitor_printf(mon
, "Client:\n");
397 monitor_printf(mon
, " address: %s:%s\n",
398 client
->value
->host
, client
->value
->service
);
399 monitor_printf(mon
, " x509_dname: %s\n",
400 client
->value
->x509_dname
?
401 client
->value
->x509_dname
: "none");
402 monitor_printf(mon
, " username: %s\n",
403 client
->value
->has_sasl_username
?
404 client
->value
->sasl_username
: "none");
409 qapi_free_VncInfo(info
);
412 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
414 SpiceChannelList
*chan
;
417 info
= qmp_query_spice(NULL
);
419 if (!info
->enabled
) {
420 monitor_printf(mon
, "Server: disabled\n");
424 monitor_printf(mon
, "Server:\n");
425 if (info
->has_port
) {
426 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
427 info
->host
, info
->port
);
429 if (info
->has_tls_port
) {
430 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
431 info
->host
, info
->tls_port
);
433 monitor_printf(mon
, " migrated: %s\n",
434 info
->migrated
? "true" : "false");
435 monitor_printf(mon
, " auth: %s\n", info
->auth
);
436 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
437 monitor_printf(mon
, " mouse-mode: %s\n",
438 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
440 if (!info
->has_channels
|| info
->channels
== NULL
) {
441 monitor_printf(mon
, "Channels: none\n");
443 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
444 monitor_printf(mon
, "Channel:\n");
445 monitor_printf(mon
, " address: %s:%s%s\n",
446 chan
->value
->host
, chan
->value
->port
,
447 chan
->value
->tls
? " [tls]" : "");
448 monitor_printf(mon
, " session: %" PRId64
"\n",
449 chan
->value
->connection_id
);
450 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
451 chan
->value
->channel_type
, chan
->value
->channel_id
);
456 qapi_free_SpiceInfo(info
);
459 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
464 info
= qmp_query_balloon(&err
);
466 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
471 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
473 qapi_free_BalloonInfo(info
);
476 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
478 PciMemoryRegionList
*region
;
480 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
481 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
482 dev
->slot
, dev
->function
);
483 monitor_printf(mon
, " ");
485 if (dev
->class_info
.has_desc
) {
486 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
488 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
491 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
492 dev
->id
.vendor
, dev
->id
.device
);
495 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
498 if (dev
->has_pci_bridge
) {
499 monitor_printf(mon
, " BUS %" PRId64
".\n",
500 dev
->pci_bridge
->bus
.number
);
501 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
502 dev
->pci_bridge
->bus
.secondary
);
503 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
504 dev
->pci_bridge
->bus
.subordinate
);
506 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
507 dev
->pci_bridge
->bus
.io_range
->base
,
508 dev
->pci_bridge
->bus
.io_range
->limit
);
511 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
512 dev
->pci_bridge
->bus
.memory_range
->base
,
513 dev
->pci_bridge
->bus
.memory_range
->limit
);
515 monitor_printf(mon
, " prefetchable memory range "
516 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
517 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
518 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
521 for (region
= dev
->regions
; region
; region
= region
->next
) {
524 addr
= region
->value
->address
;
525 size
= region
->value
->size
;
527 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
529 if (!strcmp(region
->value
->type
, "io")) {
530 monitor_printf(mon
, "I/O at 0x%04" PRIx64
531 " [0x%04" PRIx64
"].\n",
532 addr
, addr
+ size
- 1);
534 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
535 " [0x%08" PRIx64
"].\n",
536 region
->value
->mem_type_64
? 64 : 32,
537 region
->value
->prefetch
? " prefetchable" : "",
538 addr
, addr
+ size
- 1);
542 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
544 if (dev
->has_pci_bridge
) {
545 if (dev
->pci_bridge
->has_devices
) {
546 PciDeviceInfoList
*cdev
;
547 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
548 hmp_info_pci_device(mon
, cdev
->value
);
554 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
556 PciInfoList
*info_list
, *info
;
559 info_list
= qmp_query_pci(&err
);
561 monitor_printf(mon
, "PCI devices not supported\n");
566 for (info
= info_list
; info
; info
= info
->next
) {
567 PciDeviceInfoList
*dev
;
569 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
570 hmp_info_pci_device(mon
, dev
->value
);
574 qapi_free_PciInfoList(info_list
);
577 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
579 BlockJobInfoList
*list
;
582 list
= qmp_query_block_jobs(&err
);
586 monitor_printf(mon
, "No active jobs\n");
591 if (strcmp(list
->value
->type
, "stream") == 0) {
592 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
593 " of %" PRId64
" bytes, speed limit %" PRId64
600 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
601 " of %" PRId64
" bytes, speed limit %" PRId64
613 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
615 TPMInfoList
*info_list
, *info
;
618 TPMPassthroughOptions
*tpo
;
620 info_list
= qmp_query_tpm(&err
);
622 monitor_printf(mon
, "TPM device not supported\n");
628 monitor_printf(mon
, "TPM device:\n");
631 for (info
= info_list
; info
; info
= info
->next
) {
632 TPMInfo
*ti
= info
->value
;
633 monitor_printf(mon
, " tpm%d: model=%s\n",
634 c
, TpmModel_lookup
[ti
->model
]);
636 monitor_printf(mon
, " \\ %s: type=%s",
637 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
639 switch (ti
->options
->kind
) {
640 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
641 tpo
= ti
->options
->passthrough
;
642 monitor_printf(mon
, "%s%s%s%s",
643 tpo
->has_path
? ",path=" : "",
644 tpo
->has_path
? tpo
->path
: "",
645 tpo
->has_cancel_path
? ",cancel-path=" : "",
646 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
648 case TPM_TYPE_OPTIONS_KIND_MAX
:
651 monitor_printf(mon
, "\n");
654 qapi_free_TPMInfoList(info_list
);
657 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
659 monitor_suspend(mon
);
663 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
668 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
670 qmp_system_reset(NULL
);
673 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
675 qmp_system_powerdown(NULL
);
678 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
682 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
683 use it are converted to the QAPI */
684 cpu_index
= qdict_get_int(qdict
, "index");
685 if (monitor_set_cpu(cpu_index
) < 0) {
686 monitor_printf(mon
, "invalid CPU index\n");
690 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
692 uint32_t size
= qdict_get_int(qdict
, "size");
693 const char *filename
= qdict_get_str(qdict
, "filename");
694 uint64_t addr
= qdict_get_int(qdict
, "val");
697 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
698 hmp_handle_error(mon
, &errp
);
701 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
703 uint32_t size
= qdict_get_int(qdict
, "size");
704 const char *filename
= qdict_get_str(qdict
, "filename");
705 uint64_t addr
= qdict_get_int(qdict
, "val");
708 qmp_pmemsave(addr
, size
, filename
, &errp
);
709 hmp_handle_error(mon
, &errp
);
712 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
714 const char *chardev
= qdict_get_str(qdict
, "device");
715 const char *data
= qdict_get_str(qdict
, "data");
718 qmp_ringbuf_write(chardev
, data
, false, 0, &errp
);
720 hmp_handle_error(mon
, &errp
);
723 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
725 uint32_t size
= qdict_get_int(qdict
, "size");
726 const char *chardev
= qdict_get_str(qdict
, "device");
731 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &errp
);
733 monitor_printf(mon
, "%s\n", error_get_pretty(errp
));
738 for (i
= 0; data
[i
]; i
++) {
739 unsigned char ch
= data
[i
];
742 monitor_printf(mon
, "\\\\");
743 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
744 monitor_printf(mon
, "\\u%04X", ch
);
746 monitor_printf(mon
, "%c", ch
);
750 monitor_printf(mon
, "\n");
754 static void hmp_cont_cb(void *opaque
, int err
)
761 static bool key_is_missing(const BlockInfo
*bdev
)
763 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
766 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
768 BlockInfoList
*bdev_list
, *bdev
;
771 bdev_list
= qmp_query_block(NULL
);
772 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
773 if (key_is_missing(bdev
->value
)) {
774 monitor_read_block_device_key(mon
, bdev
->value
->device
,
781 hmp_handle_error(mon
, &errp
);
784 qapi_free_BlockInfoList(bdev_list
);
787 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
789 qmp_system_wakeup(NULL
);
792 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
796 qmp_inject_nmi(&errp
);
797 hmp_handle_error(mon
, &errp
);
800 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
802 const char *name
= qdict_get_str(qdict
, "name");
803 int up
= qdict_get_bool(qdict
, "up");
806 qmp_set_link(name
, up
, &errp
);
807 hmp_handle_error(mon
, &errp
);
810 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
812 const char *device
= qdict_get_str(qdict
, "device");
813 const char *password
= qdict_get_str(qdict
, "password");
816 qmp_block_passwd(device
, password
, &errp
);
817 hmp_handle_error(mon
, &errp
);
820 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
822 int64_t value
= qdict_get_int(qdict
, "value");
825 qmp_balloon(value
, &errp
);
826 if (error_is_set(&errp
)) {
827 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
832 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
834 const char *device
= qdict_get_str(qdict
, "device");
835 int64_t size
= qdict_get_int(qdict
, "size");
838 qmp_block_resize(device
, size
, &errp
);
839 hmp_handle_error(mon
, &errp
);
842 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
844 const char *device
= qdict_get_str(qdict
, "device");
845 const char *filename
= qdict_get_str(qdict
, "target");
846 const char *format
= qdict_get_try_str(qdict
, "format");
847 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
848 int full
= qdict_get_try_bool(qdict
, "full", 0);
849 enum NewImageMode mode
;
853 error_set(&errp
, QERR_MISSING_PARAMETER
, "target");
854 hmp_handle_error(mon
, &errp
);
859 mode
= NEW_IMAGE_MODE_EXISTING
;
861 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
864 qmp_drive_mirror(device
, filename
, !!format
, format
,
865 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
866 true, mode
, false, 0, false, 0, false, 0,
867 false, 0, false, 0, &errp
);
868 hmp_handle_error(mon
, &errp
);
871 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
873 const char *device
= qdict_get_str(qdict
, "device");
874 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
875 const char *format
= qdict_get_try_str(qdict
, "format");
876 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
877 enum NewImageMode mode
;
881 /* In the future, if 'snapshot-file' is not specified, the snapshot
882 will be taken internally. Today it's actually required. */
883 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
884 hmp_handle_error(mon
, &errp
);
888 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
889 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
,
891 hmp_handle_error(mon
, &errp
);
894 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
896 qmp_migrate_cancel(NULL
);
899 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
901 double value
= qdict_get_double(qdict
, "value");
902 qmp_migrate_set_downtime(value
, NULL
);
905 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
907 int64_t value
= qdict_get_int(qdict
, "value");
910 qmp_migrate_set_cache_size(value
, &err
);
912 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
918 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
920 int64_t value
= qdict_get_int(qdict
, "value");
921 qmp_migrate_set_speed(value
, NULL
);
924 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
926 const char *cap
= qdict_get_str(qdict
, "capability");
927 bool state
= qdict_get_bool(qdict
, "state");
929 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
932 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
933 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
934 caps
->value
= g_malloc0(sizeof(*caps
->value
));
935 caps
->value
->capability
= i
;
936 caps
->value
->state
= state
;
938 qmp_migrate_set_capabilities(caps
, &err
);
943 if (i
== MIGRATION_CAPABILITY_MAX
) {
944 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
947 qapi_free_MigrationCapabilityStatusList(caps
);
950 monitor_printf(mon
, "migrate_set_capability: %s\n",
951 error_get_pretty(err
));
956 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
958 const char *protocol
= qdict_get_str(qdict
, "protocol");
959 const char *password
= qdict_get_str(qdict
, "password");
960 const char *connected
= qdict_get_try_str(qdict
, "connected");
963 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
964 hmp_handle_error(mon
, &err
);
967 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
969 const char *protocol
= qdict_get_str(qdict
, "protocol");
970 const char *whenstr
= qdict_get_str(qdict
, "time");
973 qmp_expire_password(protocol
, whenstr
, &err
);
974 hmp_handle_error(mon
, &err
);
977 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
979 int force
= qdict_get_try_bool(qdict
, "force", 0);
980 const char *device
= qdict_get_str(qdict
, "device");
983 qmp_eject(device
, true, force
, &err
);
984 hmp_handle_error(mon
, &err
);
987 static void hmp_change_read_arg(Monitor
*mon
, const char *password
,
990 qmp_change_vnc_password(password
, NULL
);
991 monitor_read_command(mon
, 1);
994 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
996 const char *device
= qdict_get_str(qdict
, "device");
997 const char *target
= qdict_get_str(qdict
, "target");
998 const char *arg
= qdict_get_try_str(qdict
, "arg");
1001 if (strcmp(device
, "vnc") == 0 &&
1002 (strcmp(target
, "passwd") == 0 ||
1003 strcmp(target
, "password") == 0)) {
1005 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1010 qmp_change(device
, target
, !!arg
, arg
, &err
);
1011 if (error_is_set(&err
) &&
1012 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1014 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1017 hmp_handle_error(mon
, &err
);
1020 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1024 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1025 qdict_get_int(qdict
, "bps"),
1026 qdict_get_int(qdict
, "bps_rd"),
1027 qdict_get_int(qdict
, "bps_wr"),
1028 qdict_get_int(qdict
, "iops"),
1029 qdict_get_int(qdict
, "iops_rd"),
1030 qdict_get_int(qdict
, "iops_wr"), &err
);
1031 hmp_handle_error(mon
, &err
);
1034 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1036 Error
*error
= NULL
;
1037 const char *device
= qdict_get_str(qdict
, "device");
1038 const char *base
= qdict_get_try_str(qdict
, "base");
1039 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1041 qmp_block_stream(device
, base
!= NULL
, base
,
1042 qdict_haskey(qdict
, "speed"), speed
,
1043 BLOCKDEV_ON_ERROR_REPORT
, true, &error
);
1045 hmp_handle_error(mon
, &error
);
1048 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1050 Error
*error
= NULL
;
1051 const char *device
= qdict_get_str(qdict
, "device");
1052 int64_t value
= qdict_get_int(qdict
, "speed");
1054 qmp_block_job_set_speed(device
, value
, &error
);
1056 hmp_handle_error(mon
, &error
);
1059 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1061 Error
*error
= NULL
;
1062 const char *device
= qdict_get_str(qdict
, "device");
1063 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1065 qmp_block_job_cancel(device
, true, force
, &error
);
1067 hmp_handle_error(mon
, &error
);
1070 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1072 Error
*error
= NULL
;
1073 const char *device
= qdict_get_str(qdict
, "device");
1075 qmp_block_job_pause(device
, &error
);
1077 hmp_handle_error(mon
, &error
);
1080 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1082 Error
*error
= NULL
;
1083 const char *device
= qdict_get_str(qdict
, "device");
1085 qmp_block_job_resume(device
, &error
);
1087 hmp_handle_error(mon
, &error
);
1090 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1092 Error
*error
= NULL
;
1093 const char *device
= qdict_get_str(qdict
, "device");
1095 qmp_block_job_complete(device
, &error
);
1097 hmp_handle_error(mon
, &error
);
1100 typedef struct MigrationStatus
1104 bool is_block_migration
;
1107 static void hmp_migrate_status_cb(void *opaque
)
1109 MigrationStatus
*status
= opaque
;
1110 MigrationInfo
*info
;
1112 info
= qmp_query_migrate(NULL
);
1113 if (!info
->has_status
|| strcmp(info
->status
, "active") == 0) {
1114 if (info
->has_disk
) {
1117 if (info
->disk
->remaining
) {
1118 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1123 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1124 monitor_flush(status
->mon
);
1127 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
) + 1000);
1129 if (status
->is_block_migration
) {
1130 monitor_printf(status
->mon
, "\n");
1132 monitor_resume(status
->mon
);
1133 qemu_del_timer(status
->timer
);
1137 qapi_free_MigrationInfo(info
);
1140 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1142 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1143 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1144 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1145 const char *uri
= qdict_get_str(qdict
, "uri");
1148 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1150 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1156 MigrationStatus
*status
;
1158 if (monitor_suspend(mon
) < 0) {
1159 monitor_printf(mon
, "terminal does not allow synchronous "
1160 "migration, continuing detached\n");
1164 status
= g_malloc0(sizeof(*status
));
1166 status
->is_block_migration
= blk
|| inc
;
1167 status
->timer
= qemu_new_timer_ms(rt_clock
, hmp_migrate_status_cb
,
1169 qemu_mod_timer(status
->timer
, qemu_get_clock_ms(rt_clock
));
1173 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1175 const char *id
= qdict_get_str(qdict
, "id");
1178 qmp_device_del(id
, &err
);
1179 hmp_handle_error(mon
, &err
);
1182 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1185 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1186 const char *file
= qdict_get_str(qdict
, "filename");
1187 bool has_begin
= qdict_haskey(qdict
, "begin");
1188 bool has_length
= qdict_haskey(qdict
, "length");
1194 begin
= qdict_get_int(qdict
, "begin");
1197 length
= qdict_get_int(qdict
, "length");
1200 prot
= g_strconcat("file:", file
, NULL
);
1202 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1204 hmp_handle_error(mon
, &errp
);
1208 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1213 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1214 if (error_is_set(&err
)) {
1218 netdev_add(opts
, &err
);
1219 if (error_is_set(&err
)) {
1220 qemu_opts_del(opts
);
1224 hmp_handle_error(mon
, &err
);
1227 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1229 const char *id
= qdict_get_str(qdict
, "id");
1232 qmp_netdev_del(id
, &err
);
1233 hmp_handle_error(mon
, &err
);
1236 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1238 const char *fdname
= qdict_get_str(qdict
, "fdname");
1241 qmp_getfd(fdname
, &errp
);
1242 hmp_handle_error(mon
, &errp
);
1245 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1247 const char *fdname
= qdict_get_str(qdict
, "fdname");
1250 qmp_closefd(fdname
, &errp
);
1251 hmp_handle_error(mon
, &errp
);
1254 void hmp_send_key(Monitor
*mon
, const QDict
*qdict
)
1256 const char *keys
= qdict_get_str(qdict
, "keys");
1257 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1258 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1259 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1261 char keyname_buf
[16];
1266 separator
= strchr(keys
, '-');
1267 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1268 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1270 /* Be compatible with old interface, convert user inputted "<" */
1271 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1272 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1275 keyname_buf
[keyname_len
] = 0;
1277 keylist
= g_malloc0(sizeof(*keylist
));
1278 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1284 tmp
->next
= keylist
;
1288 if (strstart(keyname_buf
, "0x", NULL
)) {
1290 int value
= strtoul(keyname_buf
, &endp
, 0);
1291 if (*endp
!= '\0') {
1294 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1295 keylist
->value
->number
= value
;
1297 int idx
= index_from_key(keyname_buf
);
1298 if (idx
== Q_KEY_CODE_MAX
) {
1301 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1302 keylist
->value
->qcode
= idx
;
1308 keys
= separator
+ 1;
1311 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1312 hmp_handle_error(mon
, &err
);
1315 qapi_free_KeyValueList(head
);
1319 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1323 void hmp_screen_dump(Monitor
*mon
, const QDict
*qdict
)
1325 const char *filename
= qdict_get_str(qdict
, "filename");
1328 qmp_screendump(filename
, &err
);
1329 hmp_handle_error(mon
, &err
);
1332 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1334 const char *uri
= qdict_get_str(qdict
, "uri");
1335 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1336 int all
= qdict_get_try_bool(qdict
, "all", 0);
1337 Error
*local_err
= NULL
;
1338 BlockInfoList
*block_list
, *info
;
1339 SocketAddress
*addr
;
1341 if (writable
&& !all
) {
1342 error_setg(&local_err
, "-w only valid together with -a");
1346 /* First check if the address is valid and start the server. */
1347 addr
= socket_parse(uri
, &local_err
);
1348 if (local_err
!= NULL
) {
1352 qmp_nbd_server_start(addr
, &local_err
);
1353 qapi_free_SocketAddress(addr
);
1354 if (local_err
!= NULL
) {
1362 /* Then try adding all block devices. If one fails, close all and
1365 block_list
= qmp_query_block(NULL
);
1367 for (info
= block_list
; info
; info
= info
->next
) {
1368 if (!info
->value
->has_inserted
) {
1372 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1374 if (local_err
!= NULL
) {
1375 qmp_nbd_server_stop(NULL
);
1380 qapi_free_BlockInfoList(block_list
);
1383 hmp_handle_error(mon
, &local_err
);
1386 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1388 const char *device
= qdict_get_str(qdict
, "device");
1389 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1390 Error
*local_err
= NULL
;
1392 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1394 if (local_err
!= NULL
) {
1395 hmp_handle_error(mon
, &local_err
);
1399 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1403 qmp_nbd_server_stop(&errp
);
1404 hmp_handle_error(mon
, &errp
);
1407 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1409 const char *args
= qdict_get_str(qdict
, "args");
1413 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1415 error_setg(&err
, "Parsing chardev args failed");
1417 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1419 hmp_handle_error(mon
, &err
);
1422 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1424 Error
*local_err
= NULL
;
1426 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1427 hmp_handle_error(mon
, &local_err
);
1430 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1432 BlockDriverState
*bs
;
1433 const char* device
= qdict_get_str(qdict
, "device");
1434 const char* command
= qdict_get_str(qdict
, "command");
1437 bs
= bdrv_find(device
);
1439 qemuio_command(bs
, command
);
1441 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1444 hmp_handle_error(mon
, &err
);