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.
15 #include "qmp-commands.h"
17 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
19 if (error_is_set(errp
)) {
20 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
25 void hmp_info_name(Monitor
*mon
)
29 info
= qmp_query_name(NULL
);
31 monitor_printf(mon
, "%s\n", info
->name
);
33 qapi_free_NameInfo(info
);
36 void hmp_info_version(Monitor
*mon
)
40 info
= qmp_query_version(NULL
);
42 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
43 info
->qemu
.major
, info
->qemu
.minor
, info
->qemu
.micro
,
46 qapi_free_VersionInfo(info
);
49 void hmp_info_kvm(Monitor
*mon
)
53 info
= qmp_query_kvm(NULL
);
54 monitor_printf(mon
, "kvm support: ");
56 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
58 monitor_printf(mon
, "not compiled\n");
61 qapi_free_KvmInfo(info
);
64 void hmp_info_status(Monitor
*mon
)
68 info
= qmp_query_status(NULL
);
70 monitor_printf(mon
, "VM status: %s%s",
71 info
->running
? "running" : "paused",
72 info
->singlestep
? " (single step mode)" : "");
74 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
75 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
78 monitor_printf(mon
, "\n");
80 qapi_free_StatusInfo(info
);
83 void hmp_info_uuid(Monitor
*mon
)
87 info
= qmp_query_uuid(NULL
);
88 monitor_printf(mon
, "%s\n", info
->UUID
);
89 qapi_free_UuidInfo(info
);
92 void hmp_info_chardev(Monitor
*mon
)
94 ChardevInfoList
*char_info
, *info
;
96 char_info
= qmp_query_chardev(NULL
);
97 for (info
= char_info
; info
; info
= info
->next
) {
98 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
99 info
->value
->filename
);
102 qapi_free_ChardevInfoList(char_info
);
105 void hmp_info_mice(Monitor
*mon
)
107 MouseInfoList
*mice_list
, *mouse
;
109 mice_list
= qmp_query_mice(NULL
);
111 monitor_printf(mon
, "No mouse devices connected\n");
115 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
116 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
117 mouse
->value
->current
? '*' : ' ',
118 mouse
->value
->index
, mouse
->value
->name
,
119 mouse
->value
->absolute
? " (absolute)" : "");
122 qapi_free_MouseInfoList(mice_list
);
125 void hmp_info_migrate(Monitor
*mon
)
129 info
= qmp_query_migrate(NULL
);
131 if (info
->has_status
) {
132 monitor_printf(mon
, "Migration status: %s\n", info
->status
);
136 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
137 info
->ram
->transferred
>> 10);
138 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
139 info
->ram
->remaining
>> 10);
140 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
141 info
->ram
->total
>> 10);
144 if (info
->has_disk
) {
145 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
146 info
->disk
->transferred
>> 10);
147 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
148 info
->disk
->remaining
>> 10);
149 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
150 info
->disk
->total
>> 10);
153 qapi_free_MigrationInfo(info
);
156 void hmp_info_cpus(Monitor
*mon
)
158 CpuInfoList
*cpu_list
, *cpu
;
160 cpu_list
= qmp_query_cpus(NULL
);
162 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
165 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
169 monitor_printf(mon
, "%c CPU #%" PRId64
": ", active
, cpu
->value
->CPU
);
171 if (cpu
->value
->has_pc
) {
172 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
174 if (cpu
->value
->has_nip
) {
175 monitor_printf(mon
, "nip=0x%016" PRIx64
, cpu
->value
->nip
);
177 if (cpu
->value
->has_npc
) {
178 monitor_printf(mon
, "pc=0x%016" PRIx64
, cpu
->value
->pc
);
179 monitor_printf(mon
, "npc=0x%016" PRIx64
, cpu
->value
->npc
);
181 if (cpu
->value
->has_PC
) {
182 monitor_printf(mon
, "PC=0x%016" PRIx64
, cpu
->value
->PC
);
185 if (cpu
->value
->halted
) {
186 monitor_printf(mon
, " (halted)");
189 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
192 qapi_free_CpuInfoList(cpu_list
);
195 void hmp_info_block(Monitor
*mon
)
197 BlockInfoList
*block_list
, *info
;
199 block_list
= qmp_query_block(NULL
);
201 for (info
= block_list
; info
; info
= info
->next
) {
202 monitor_printf(mon
, "%s: removable=%d",
203 info
->value
->device
, info
->value
->removable
);
205 if (info
->value
->removable
) {
206 monitor_printf(mon
, " locked=%d", info
->value
->locked
);
207 monitor_printf(mon
, " tray-open=%d", info
->value
->tray_open
);
210 if (info
->value
->has_io_status
) {
211 monitor_printf(mon
, " io-status=%s",
212 BlockDeviceIoStatus_lookup
[info
->value
->io_status
]);
215 if (info
->value
->has_inserted
) {
216 monitor_printf(mon
, " file=");
217 monitor_print_filename(mon
, info
->value
->inserted
->file
);
219 if (info
->value
->inserted
->has_backing_file
) {
220 monitor_printf(mon
, " backing_file=");
221 monitor_print_filename(mon
, info
->value
->inserted
->backing_file
);
223 monitor_printf(mon
, " ro=%d drv=%s encrypted=%d",
224 info
->value
->inserted
->ro
,
225 info
->value
->inserted
->drv
,
226 info
->value
->inserted
->encrypted
);
228 monitor_printf(mon
, " bps=%" PRId64
" bps_rd=%" PRId64
229 " bps_wr=%" PRId64
" iops=%" PRId64
230 " iops_rd=%" PRId64
" iops_wr=%" PRId64
,
231 info
->value
->inserted
->bps
,
232 info
->value
->inserted
->bps_rd
,
233 info
->value
->inserted
->bps_wr
,
234 info
->value
->inserted
->iops
,
235 info
->value
->inserted
->iops_rd
,
236 info
->value
->inserted
->iops_wr
);
238 monitor_printf(mon
, " [not inserted]");
241 monitor_printf(mon
, "\n");
244 qapi_free_BlockInfoList(block_list
);
247 void hmp_info_blockstats(Monitor
*mon
)
249 BlockStatsList
*stats_list
, *stats
;
251 stats_list
= qmp_query_blockstats(NULL
);
253 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
254 if (!stats
->value
->has_device
) {
258 monitor_printf(mon
, "%s:", stats
->value
->device
);
259 monitor_printf(mon
, " rd_bytes=%" PRId64
261 " rd_operations=%" PRId64
262 " wr_operations=%" PRId64
263 " flush_operations=%" PRId64
264 " wr_total_time_ns=%" PRId64
265 " rd_total_time_ns=%" PRId64
266 " flush_total_time_ns=%" PRId64
268 stats
->value
->stats
->rd_bytes
,
269 stats
->value
->stats
->wr_bytes
,
270 stats
->value
->stats
->rd_operations
,
271 stats
->value
->stats
->wr_operations
,
272 stats
->value
->stats
->flush_operations
,
273 stats
->value
->stats
->wr_total_time_ns
,
274 stats
->value
->stats
->rd_total_time_ns
,
275 stats
->value
->stats
->flush_total_time_ns
);
278 qapi_free_BlockStatsList(stats_list
);
281 void hmp_info_vnc(Monitor
*mon
)
285 VncClientInfoList
*client
;
287 info
= qmp_query_vnc(&err
);
289 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
294 if (!info
->enabled
) {
295 monitor_printf(mon
, "Server: disabled\n");
299 monitor_printf(mon
, "Server:\n");
300 if (info
->has_host
&& info
->has_service
) {
301 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
303 if (info
->has_auth
) {
304 monitor_printf(mon
, " auth: %s\n", info
->auth
);
307 if (!info
->has_clients
|| info
->clients
== NULL
) {
308 monitor_printf(mon
, "Client: none\n");
310 for (client
= info
->clients
; client
; client
= client
->next
) {
311 monitor_printf(mon
, "Client:\n");
312 monitor_printf(mon
, " address: %s:%s\n",
313 client
->value
->host
, client
->value
->service
);
314 monitor_printf(mon
, " x509_dname: %s\n",
315 client
->value
->x509_dname
?
316 client
->value
->x509_dname
: "none");
317 monitor_printf(mon
, " username: %s\n",
318 client
->value
->has_sasl_username
?
319 client
->value
->sasl_username
: "none");
324 qapi_free_VncInfo(info
);
327 void hmp_info_spice(Monitor
*mon
)
329 SpiceChannelList
*chan
;
332 info
= qmp_query_spice(NULL
);
334 if (!info
->enabled
) {
335 monitor_printf(mon
, "Server: disabled\n");
339 monitor_printf(mon
, "Server:\n");
340 if (info
->has_port
) {
341 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
342 info
->host
, info
->port
);
344 if (info
->has_tls_port
) {
345 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
346 info
->host
, info
->tls_port
);
348 monitor_printf(mon
, " auth: %s\n", info
->auth
);
349 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
351 if (!info
->has_channels
|| info
->channels
== NULL
) {
352 monitor_printf(mon
, "Channels: none\n");
354 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
355 monitor_printf(mon
, "Channel:\n");
356 monitor_printf(mon
, " address: %s:%s%s\n",
357 chan
->value
->host
, chan
->value
->port
,
358 chan
->value
->tls
? " [tls]" : "");
359 monitor_printf(mon
, " session: %" PRId64
"\n",
360 chan
->value
->connection_id
);
361 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
362 chan
->value
->channel_type
, chan
->value
->channel_id
);
367 qapi_free_SpiceInfo(info
);
370 void hmp_info_balloon(Monitor
*mon
)
375 info
= qmp_query_balloon(&err
);
377 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
382 monitor_printf(mon
, "balloon: actual=%" PRId64
, info
->actual
>> 20);
383 if (info
->has_mem_swapped_in
) {
384 monitor_printf(mon
, " mem_swapped_in=%" PRId64
, info
->mem_swapped_in
);
386 if (info
->has_mem_swapped_out
) {
387 monitor_printf(mon
, " mem_swapped_out=%" PRId64
, info
->mem_swapped_out
);
389 if (info
->has_major_page_faults
) {
390 monitor_printf(mon
, " major_page_faults=%" PRId64
,
391 info
->major_page_faults
);
393 if (info
->has_minor_page_faults
) {
394 monitor_printf(mon
, " minor_page_faults=%" PRId64
,
395 info
->minor_page_faults
);
397 if (info
->has_free_mem
) {
398 monitor_printf(mon
, " free_mem=%" PRId64
, info
->free_mem
);
400 if (info
->has_total_mem
) {
401 monitor_printf(mon
, " total_mem=%" PRId64
, info
->total_mem
);
404 monitor_printf(mon
, "\n");
406 qapi_free_BalloonInfo(info
);
409 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
411 PciMemoryRegionList
*region
;
413 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
414 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
415 dev
->slot
, dev
->function
);
416 monitor_printf(mon
, " ");
418 if (dev
->class_info
.has_desc
) {
419 monitor_printf(mon
, "%s", dev
->class_info
.desc
);
421 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
.class);
424 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
425 dev
->id
.vendor
, dev
->id
.device
);
428 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
431 if (dev
->has_pci_bridge
) {
432 monitor_printf(mon
, " BUS %" PRId64
".\n",
433 dev
->pci_bridge
->bus
.number
);
434 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
435 dev
->pci_bridge
->bus
.secondary
);
436 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
437 dev
->pci_bridge
->bus
.subordinate
);
439 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
440 dev
->pci_bridge
->bus
.io_range
->base
,
441 dev
->pci_bridge
->bus
.io_range
->limit
);
444 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
445 dev
->pci_bridge
->bus
.memory_range
->base
,
446 dev
->pci_bridge
->bus
.memory_range
->limit
);
448 monitor_printf(mon
, " prefetchable memory range "
449 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
450 dev
->pci_bridge
->bus
.prefetchable_range
->base
,
451 dev
->pci_bridge
->bus
.prefetchable_range
->limit
);
454 for (region
= dev
->regions
; region
; region
= region
->next
) {
457 addr
= region
->value
->address
;
458 size
= region
->value
->size
;
460 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
462 if (!strcmp(region
->value
->type
, "io")) {
463 monitor_printf(mon
, "I/O at 0x%04" PRIx64
464 " [0x%04" PRIx64
"].\n",
465 addr
, addr
+ size
- 1);
467 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
468 " [0x%08" PRIx64
"].\n",
469 region
->value
->mem_type_64
? 64 : 32,
470 region
->value
->prefetch
? " prefetchable" : "",
471 addr
, addr
+ size
- 1);
475 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
477 if (dev
->has_pci_bridge
) {
478 if (dev
->pci_bridge
->has_devices
) {
479 PciDeviceInfoList
*cdev
;
480 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
481 hmp_info_pci_device(mon
, cdev
->value
);
487 void hmp_info_pci(Monitor
*mon
)
492 info
= qmp_query_pci(&err
);
494 monitor_printf(mon
, "PCI devices not supported\n");
499 for (; info
; info
= info
->next
) {
500 PciDeviceInfoList
*dev
;
502 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
503 hmp_info_pci_device(mon
, dev
->value
);
507 qapi_free_PciInfoList(info
);
510 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
512 monitor_suspend(mon
);
516 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
521 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
523 qmp_system_reset(NULL
);
526 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
528 qmp_system_powerdown(NULL
);
531 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
535 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
536 use it are converted to the QAPI */
537 cpu_index
= qdict_get_int(qdict
, "index");
538 if (monitor_set_cpu(cpu_index
) < 0) {
539 monitor_printf(mon
, "invalid CPU index\n");
543 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
545 uint32_t size
= qdict_get_int(qdict
, "size");
546 const char *filename
= qdict_get_str(qdict
, "filename");
547 uint64_t addr
= qdict_get_int(qdict
, "val");
550 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &errp
);
551 hmp_handle_error(mon
, &errp
);
554 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
556 uint32_t size
= qdict_get_int(qdict
, "size");
557 const char *filename
= qdict_get_str(qdict
, "filename");
558 uint64_t addr
= qdict_get_int(qdict
, "val");
561 qmp_pmemsave(addr
, size
, filename
, &errp
);
562 hmp_handle_error(mon
, &errp
);
565 static void hmp_cont_cb(void *opaque
, int err
)
567 Monitor
*mon
= opaque
;
574 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
579 if (error_is_set(&errp
)) {
580 if (error_is_type(errp
, QERR_DEVICE_ENCRYPTED
)) {
583 /* The device is encrypted. Ask the user for the password
586 device
= error_get_field(errp
, "device");
587 assert(device
!= NULL
);
589 monitor_read_block_device_key(mon
, device
, hmp_cont_cb
, mon
);
593 hmp_handle_error(mon
, &errp
);
597 void hmp_inject_nmi(Monitor
*mon
, const QDict
*qdict
)
601 qmp_inject_nmi(&errp
);
602 hmp_handle_error(mon
, &errp
);
605 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
607 const char *name
= qdict_get_str(qdict
, "name");
608 int up
= qdict_get_bool(qdict
, "up");
611 qmp_set_link(name
, up
, &errp
);
612 hmp_handle_error(mon
, &errp
);
615 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
617 const char *device
= qdict_get_str(qdict
, "device");
618 const char *password
= qdict_get_str(qdict
, "password");
621 qmp_block_passwd(device
, password
, &errp
);
622 hmp_handle_error(mon
, &errp
);
625 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
627 int64_t value
= qdict_get_int(qdict
, "value");
630 qmp_balloon(value
, &errp
);
631 if (error_is_set(&errp
)) {
632 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(errp
));
637 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
639 const char *device
= qdict_get_str(qdict
, "device");
640 int64_t size
= qdict_get_int(qdict
, "size");
643 qmp_block_resize(device
, size
, &errp
);
644 hmp_handle_error(mon
, &errp
);
647 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
649 const char *device
= qdict_get_str(qdict
, "device");
650 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
651 const char *format
= qdict_get_try_str(qdict
, "format");
655 /* In the future, if 'snapshot-file' is not specified, the snapshot
656 will be taken internally. Today it's actually required. */
657 error_set(&errp
, QERR_MISSING_PARAMETER
, "snapshot-file");
658 hmp_handle_error(mon
, &errp
);
662 qmp_blockdev_snapshot_sync(device
, filename
, !!format
, format
, &errp
);
663 hmp_handle_error(mon
, &errp
);
666 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
668 qmp_migrate_cancel(NULL
);
671 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
673 double value
= qdict_get_double(qdict
, "value");
674 qmp_migrate_set_downtime(value
, NULL
);
677 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
679 int64_t value
= qdict_get_int(qdict
, "value");
680 qmp_migrate_set_speed(value
, NULL
);