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 "sysemu/block-backend.h"
20 #include "qemu/option.h"
21 #include "qemu/timer.h"
22 #include "qmp-commands.h"
23 #include "qemu/sockets.h"
24 #include "monitor/monitor.h"
25 #include "monitor/qdev.h"
26 #include "qapi/opts-visitor.h"
27 #include "qapi/string-output-visitor.h"
28 #include "qapi-visit.h"
29 #include "ui/console.h"
30 #include "block/qapi.h"
34 #include <spice/enums.h>
37 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
41 monitor_printf(mon
, "%s\n", error_get_pretty(*errp
));
46 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
50 info
= qmp_query_name(NULL
);
52 monitor_printf(mon
, "%s\n", info
->name
);
54 qapi_free_NameInfo(info
);
57 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
61 info
= qmp_query_version(NULL
);
63 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
64 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
67 qapi_free_VersionInfo(info
);
70 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
74 info
= qmp_query_kvm(NULL
);
75 monitor_printf(mon
, "kvm support: ");
77 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
79 monitor_printf(mon
, "not compiled\n");
82 qapi_free_KvmInfo(info
);
85 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
89 info
= qmp_query_status(NULL
);
91 monitor_printf(mon
, "VM status: %s%s",
92 info
->running
? "running" : "paused",
93 info
->singlestep
? " (single step mode)" : "");
95 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
96 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
99 monitor_printf(mon
, "\n");
101 qapi_free_StatusInfo(info
);
104 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
108 info
= qmp_query_uuid(NULL
);
109 monitor_printf(mon
, "%s\n", info
->UUID
);
110 qapi_free_UuidInfo(info
);
113 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
115 ChardevInfoList
*char_info
, *info
;
117 char_info
= qmp_query_chardev(NULL
);
118 for (info
= char_info
; info
; info
= info
->next
) {
119 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
120 info
->value
->filename
);
123 qapi_free_ChardevInfoList(char_info
);
126 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
128 MouseInfoList
*mice_list
, *mouse
;
130 mice_list
= qmp_query_mice(NULL
);
132 monitor_printf(mon
, "No mouse devices connected\n");
136 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
137 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
138 mouse
->value
->current
? '*' : ' ',
139 mouse
->value
->index
, mouse
->value
->name
,
140 mouse
->value
->absolute
? " (absolute)" : "");
143 qapi_free_MouseInfoList(mice_list
);
146 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
149 MigrationCapabilityStatusList
*caps
, *cap
;
151 info
= qmp_query_migrate(NULL
);
152 caps
= qmp_query_migrate_capabilities(NULL
);
154 /* do not display parameters during setup */
155 if (info
->has_status
&& caps
) {
156 monitor_printf(mon
, "capabilities: ");
157 for (cap
= caps
; cap
; cap
= cap
->next
) {
158 monitor_printf(mon
, "%s: %s ",
159 MigrationCapability_lookup
[cap
->value
->capability
],
160 cap
->value
->state
? "on" : "off");
162 monitor_printf(mon
, "\n");
165 if (info
->has_status
) {
166 monitor_printf(mon
, "Migration status: %s\n",
167 MigrationStatus_lookup
[info
->status
]);
168 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
170 if (info
->has_expected_downtime
) {
171 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
172 info
->expected_downtime
);
174 if (info
->has_downtime
) {
175 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
178 if (info
->has_setup_time
) {
179 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
185 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
186 info
->ram
->transferred
>> 10);
187 monitor_printf(mon
, "throughput: %0.2f mbps\n",
189 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
190 info
->ram
->remaining
>> 10);
191 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
192 info
->ram
->total
>> 10);
193 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
194 info
->ram
->duplicate
);
195 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
197 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
199 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
200 info
->ram
->normal_bytes
>> 10);
201 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
202 info
->ram
->dirty_sync_count
);
203 if (info
->ram
->dirty_pages_rate
) {
204 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
205 info
->ram
->dirty_pages_rate
);
209 if (info
->has_disk
) {
210 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
211 info
->disk
->transferred
>> 10);
212 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
213 info
->disk
->remaining
>> 10);
214 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
215 info
->disk
->total
>> 10);
218 if (info
->has_xbzrle_cache
) {
219 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
220 info
->xbzrle_cache
->cache_size
);
221 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
222 info
->xbzrle_cache
->bytes
>> 10);
223 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
224 info
->xbzrle_cache
->pages
);
225 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
226 info
->xbzrle_cache
->cache_miss
);
227 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
228 info
->xbzrle_cache
->cache_miss_rate
);
229 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
230 info
->xbzrle_cache
->overflow
);
233 qapi_free_MigrationInfo(info
);
234 qapi_free_MigrationCapabilityStatusList(caps
);
237 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
239 MigrationCapabilityStatusList
*caps
, *cap
;
241 caps
= qmp_query_migrate_capabilities(NULL
);
244 monitor_printf(mon
, "capabilities: ");
245 for (cap
= caps
; cap
; cap
= cap
->next
) {
246 monitor_printf(mon
, "%s: %s ",
247 MigrationCapability_lookup
[cap
->value
->capability
],
248 cap
->value
->state
? "on" : "off");
250 monitor_printf(mon
, "\n");
253 qapi_free_MigrationCapabilityStatusList(caps
);
256 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
258 MigrationParameters
*params
;
260 params
= qmp_query_migrate_parameters(NULL
);
263 monitor_printf(mon
, "parameters:");
264 monitor_printf(mon
, " %s: %" PRId64
,
265 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
266 params
->compress_level
);
267 monitor_printf(mon
, " %s: %" PRId64
,
268 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
269 params
->compress_threads
);
270 monitor_printf(mon
, " %s: %" PRId64
,
271 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
272 params
->decompress_threads
);
273 monitor_printf(mon
, "\n");
276 qapi_free_MigrationParameters(params
);
279 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
281 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
282 qmp_query_migrate_cache_size(NULL
) >> 10);
285 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
287 CpuInfoList
*cpu_list
, *cpu
;
289 cpu_list
= qmp_query_cpus(NULL
);
291 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
294 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
298 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
300 if (cpu
->value
->has_pc
) {
301 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->pc
);
303 if (cpu
->value
->has_nip
) {
304 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->nip
);
306 if (cpu
->value
->has_npc
) {
307 monitor_printf(mon
, " npc=0x%016" PRIx64
, cpu
->value
->npc
);
309 if (cpu
->value
->has_PC
) {
310 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->PC
);
313 if (cpu
->value
->halted
) {
314 monitor_printf(mon
, " (halted)");
317 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
320 qapi_free_CpuInfoList(cpu_list
);
323 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
324 BlockDeviceInfo
*inserted
, bool verbose
)
326 ImageInfo
*image_info
;
328 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
331 monitor_printf(mon
, "%s", info
->device
);
332 if (inserted
&& inserted
->has_node_name
) {
333 monitor_printf(mon
, " (%s)", inserted
->node_name
);
337 monitor_printf(mon
, "%s",
338 inserted
->has_node_name
339 ? inserted
->node_name
344 monitor_printf(mon
, ": %s (%s%s%s)\n",
347 inserted
->ro
? ", read-only" : "",
348 inserted
->encrypted
? ", encrypted" : "");
350 monitor_printf(mon
, ": [not inserted]\n");
354 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
355 monitor_printf(mon
, " I/O status: %s\n",
356 BlockDeviceIoStatus_lookup
[info
->io_status
]);
359 if (info
->removable
) {
360 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
361 info
->locked
? "" : "not ",
362 info
->tray_open
? "open" : "closed");
371 monitor_printf(mon
, " Cache mode: %s%s%s\n",
372 inserted
->cache
->writeback
? "writeback" : "writethrough",
373 inserted
->cache
->direct
? ", direct" : "",
374 inserted
->cache
->no_flush
? ", ignore flushes" : "");
376 if (inserted
->has_backing_file
) {
379 "(chain depth: %" PRId64
")\n",
380 inserted
->backing_file
,
381 inserted
->backing_file_depth
);
384 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
385 monitor_printf(mon
, " Detect zeroes: %s\n",
386 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
389 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
390 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
392 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
393 " bps_rd=%" PRId64
" bps_wr=%" PRId64
395 " bps_rd_max=%" PRId64
396 " bps_wr_max=%" PRId64
397 " iops=%" PRId64
" iops_rd=%" PRId64
400 " iops_rd_max=%" PRId64
401 " iops_wr_max=%" PRId64
402 " iops_size=%" PRId64
408 inserted
->bps_rd_max
,
409 inserted
->bps_wr_max
,
414 inserted
->iops_rd_max
,
415 inserted
->iops_wr_max
,
421 monitor_printf(mon
, "\nImages:\n");
422 image_info
= inserted
->image
;
424 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
426 if (image_info
->has_backing_image
) {
427 image_info
= image_info
->backing_image
;
435 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
437 BlockInfoList
*block_list
, *info
;
438 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
439 const char *device
= qdict_get_try_str(qdict
, "device");
440 bool verbose
= qdict_get_try_bool(qdict
, "verbose", 0);
441 bool nodes
= qdict_get_try_bool(qdict
, "nodes", 0);
442 bool printed
= false;
444 /* Print BlockBackend information */
446 block_list
= qmp_query_block(NULL
);
451 for (info
= block_list
; info
; info
= info
->next
) {
452 if (device
&& strcmp(device
, info
->value
->device
)) {
456 if (info
!= block_list
) {
457 monitor_printf(mon
, "\n");
460 print_block_info(mon
, info
->value
, info
->value
->has_inserted
461 ? info
->value
->inserted
: NULL
,
466 qapi_free_BlockInfoList(block_list
);
468 if ((!device
&& !nodes
) || printed
) {
472 /* Print node information */
473 blockdev_list
= qmp_query_named_block_nodes(NULL
);
474 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
475 assert(blockdev
->value
->has_node_name
);
476 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
480 if (blockdev
!= blockdev_list
) {
481 monitor_printf(mon
, "\n");
484 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
486 qapi_free_BlockDeviceInfoList(blockdev_list
);
489 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
491 BlockStatsList
*stats_list
, *stats
;
493 stats_list
= qmp_query_blockstats(false, false, NULL
);
495 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
496 if (!stats
->value
->has_device
) {
500 monitor_printf(mon
, "%s:", stats
->value
->device
);
501 monitor_printf(mon
, " rd_bytes=%" PRId64
503 " rd_operations=%" PRId64
504 " wr_operations=%" PRId64
505 " flush_operations=%" PRId64
506 " wr_total_time_ns=%" PRId64
507 " rd_total_time_ns=%" PRId64
508 " flush_total_time_ns=%" PRId64
509 " rd_merged=%" PRId64
510 " wr_merged=%" PRId64
512 stats
->value
->stats
->rd_bytes
,
513 stats
->value
->stats
->wr_bytes
,
514 stats
->value
->stats
->rd_operations
,
515 stats
->value
->stats
->wr_operations
,
516 stats
->value
->stats
->flush_operations
,
517 stats
->value
->stats
->wr_total_time_ns
,
518 stats
->value
->stats
->rd_total_time_ns
,
519 stats
->value
->stats
->flush_total_time_ns
,
520 stats
->value
->stats
->rd_merged
,
521 stats
->value
->stats
->wr_merged
);
524 qapi_free_BlockStatsList(stats_list
);
527 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
531 VncClientInfoList
*client
;
533 info
= qmp_query_vnc(&err
);
535 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
540 if (!info
->enabled
) {
541 monitor_printf(mon
, "Server: disabled\n");
545 monitor_printf(mon
, "Server:\n");
546 if (info
->has_host
&& info
->has_service
) {
547 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
549 if (info
->has_auth
) {
550 monitor_printf(mon
, " auth: %s\n", info
->auth
);
553 if (!info
->has_clients
|| info
->clients
== NULL
) {
554 monitor_printf(mon
, "Client: none\n");
556 for (client
= info
->clients
; client
; client
= client
->next
) {
557 monitor_printf(mon
, "Client:\n");
558 monitor_printf(mon
, " address: %s:%s\n",
559 client
->value
->base
->host
,
560 client
->value
->base
->service
);
561 monitor_printf(mon
, " x509_dname: %s\n",
562 client
->value
->x509_dname
?
563 client
->value
->x509_dname
: "none");
564 monitor_printf(mon
, " username: %s\n",
565 client
->value
->has_sasl_username
?
566 client
->value
->sasl_username
: "none");
571 qapi_free_VncInfo(info
);
575 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
577 SpiceChannelList
*chan
;
579 const char *channel_name
;
580 const char * const channel_names
[] = {
581 [SPICE_CHANNEL_MAIN
] = "main",
582 [SPICE_CHANNEL_DISPLAY
] = "display",
583 [SPICE_CHANNEL_INPUTS
] = "inputs",
584 [SPICE_CHANNEL_CURSOR
] = "cursor",
585 [SPICE_CHANNEL_PLAYBACK
] = "playback",
586 [SPICE_CHANNEL_RECORD
] = "record",
587 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
588 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
589 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
590 [SPICE_CHANNEL_PORT
] = "port",
592 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
593 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
594 * as quick fix for build failures with older versions. */
595 [SPICE_CHANNEL_WEBDAV
] = "webdav",
599 info
= qmp_query_spice(NULL
);
601 if (!info
->enabled
) {
602 monitor_printf(mon
, "Server: disabled\n");
606 monitor_printf(mon
, "Server:\n");
607 if (info
->has_port
) {
608 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
609 info
->host
, info
->port
);
611 if (info
->has_tls_port
) {
612 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
613 info
->host
, info
->tls_port
);
615 monitor_printf(mon
, " migrated: %s\n",
616 info
->migrated
? "true" : "false");
617 monitor_printf(mon
, " auth: %s\n", info
->auth
);
618 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
619 monitor_printf(mon
, " mouse-mode: %s\n",
620 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
622 if (!info
->has_channels
|| info
->channels
== NULL
) {
623 monitor_printf(mon
, "Channels: none\n");
625 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
626 monitor_printf(mon
, "Channel:\n");
627 monitor_printf(mon
, " address: %s:%s%s\n",
628 chan
->value
->base
->host
, chan
->value
->base
->port
,
629 chan
->value
->tls
? " [tls]" : "");
630 monitor_printf(mon
, " session: %" PRId64
"\n",
631 chan
->value
->connection_id
);
632 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
633 chan
->value
->channel_type
, chan
->value
->channel_id
);
635 channel_name
= "unknown";
636 if (chan
->value
->channel_type
> 0 &&
637 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
638 channel_names
[chan
->value
->channel_type
]) {
639 channel_name
= channel_names
[chan
->value
->channel_type
];
642 monitor_printf(mon
, " channel name: %s\n", channel_name
);
647 qapi_free_SpiceInfo(info
);
651 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
656 info
= qmp_query_balloon(&err
);
658 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
663 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
665 qapi_free_BalloonInfo(info
);
668 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
670 PciMemoryRegionList
*region
;
672 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
673 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
674 dev
->slot
, dev
->function
);
675 monitor_printf(mon
, " ");
677 if (dev
->class_info
->has_desc
) {
678 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
680 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
683 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
684 dev
->id
->vendor
, dev
->id
->device
);
687 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
690 if (dev
->has_pci_bridge
) {
691 monitor_printf(mon
, " BUS %" PRId64
".\n",
692 dev
->pci_bridge
->bus
->number
);
693 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
694 dev
->pci_bridge
->bus
->secondary
);
695 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
696 dev
->pci_bridge
->bus
->subordinate
);
698 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
699 dev
->pci_bridge
->bus
->io_range
->base
,
700 dev
->pci_bridge
->bus
->io_range
->limit
);
703 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
704 dev
->pci_bridge
->bus
->memory_range
->base
,
705 dev
->pci_bridge
->bus
->memory_range
->limit
);
707 monitor_printf(mon
, " prefetchable memory range "
708 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
709 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
710 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
713 for (region
= dev
->regions
; region
; region
= region
->next
) {
716 addr
= region
->value
->address
;
717 size
= region
->value
->size
;
719 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
721 if (!strcmp(region
->value
->type
, "io")) {
722 monitor_printf(mon
, "I/O at 0x%04" PRIx64
723 " [0x%04" PRIx64
"].\n",
724 addr
, addr
+ size
- 1);
726 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
727 " [0x%08" PRIx64
"].\n",
728 region
->value
->mem_type_64
? 64 : 32,
729 region
->value
->prefetch
? " prefetchable" : "",
730 addr
, addr
+ size
- 1);
734 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
736 if (dev
->has_pci_bridge
) {
737 if (dev
->pci_bridge
->has_devices
) {
738 PciDeviceInfoList
*cdev
;
739 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
740 hmp_info_pci_device(mon
, cdev
->value
);
746 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
748 PciInfoList
*info_list
, *info
;
751 info_list
= qmp_query_pci(&err
);
753 monitor_printf(mon
, "PCI devices not supported\n");
758 for (info
= info_list
; info
; info
= info
->next
) {
759 PciDeviceInfoList
*dev
;
761 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
762 hmp_info_pci_device(mon
, dev
->value
);
766 qapi_free_PciInfoList(info_list
);
769 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
771 BlockJobInfoList
*list
;
774 list
= qmp_query_block_jobs(&err
);
778 monitor_printf(mon
, "No active jobs\n");
783 if (strcmp(list
->value
->type
, "stream") == 0) {
784 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
785 " of %" PRId64
" bytes, speed limit %" PRId64
792 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
793 " of %" PRId64
" bytes, speed limit %" PRId64
804 qapi_free_BlockJobInfoList(list
);
807 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
809 TPMInfoList
*info_list
, *info
;
812 TPMPassthroughOptions
*tpo
;
814 info_list
= qmp_query_tpm(&err
);
816 monitor_printf(mon
, "TPM device not supported\n");
822 monitor_printf(mon
, "TPM device:\n");
825 for (info
= info_list
; info
; info
= info
->next
) {
826 TPMInfo
*ti
= info
->value
;
827 monitor_printf(mon
, " tpm%d: model=%s\n",
828 c
, TpmModel_lookup
[ti
->model
]);
830 monitor_printf(mon
, " \\ %s: type=%s",
831 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->kind
]);
833 switch (ti
->options
->kind
) {
834 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
835 tpo
= ti
->options
->passthrough
;
836 monitor_printf(mon
, "%s%s%s%s",
837 tpo
->has_path
? ",path=" : "",
838 tpo
->has_path
? tpo
->path
: "",
839 tpo
->has_cancel_path
? ",cancel-path=" : "",
840 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
842 case TPM_TYPE_OPTIONS_KIND_MAX
:
845 monitor_printf(mon
, "\n");
848 qapi_free_TPMInfoList(info_list
);
851 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
853 monitor_suspend(mon
);
857 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
862 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
864 qmp_system_reset(NULL
);
867 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
869 qmp_system_powerdown(NULL
);
872 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
876 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
877 use it are converted to the QAPI */
878 cpu_index
= qdict_get_int(qdict
, "index");
879 if (monitor_set_cpu(cpu_index
) < 0) {
880 monitor_printf(mon
, "invalid CPU index\n");
884 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
886 uint32_t size
= qdict_get_int(qdict
, "size");
887 const char *filename
= qdict_get_str(qdict
, "filename");
888 uint64_t addr
= qdict_get_int(qdict
, "val");
891 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
892 hmp_handle_error(mon
, &err
);
895 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
897 uint32_t size
= qdict_get_int(qdict
, "size");
898 const char *filename
= qdict_get_str(qdict
, "filename");
899 uint64_t addr
= qdict_get_int(qdict
, "val");
902 qmp_pmemsave(addr
, size
, filename
, &err
);
903 hmp_handle_error(mon
, &err
);
906 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
908 const char *chardev
= qdict_get_str(qdict
, "device");
909 const char *data
= qdict_get_str(qdict
, "data");
912 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
914 hmp_handle_error(mon
, &err
);
917 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
919 uint32_t size
= qdict_get_int(qdict
, "size");
920 const char *chardev
= qdict_get_str(qdict
, "device");
925 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
927 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
932 for (i
= 0; data
[i
]; i
++) {
933 unsigned char ch
= data
[i
];
936 monitor_printf(mon
, "\\\\");
937 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
938 monitor_printf(mon
, "\\u%04X", ch
);
940 monitor_printf(mon
, "%c", ch
);
944 monitor_printf(mon
, "\n");
948 static void hmp_cont_cb(void *opaque
, int err
)
955 static bool key_is_missing(const BlockInfo
*bdev
)
957 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
960 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
962 BlockInfoList
*bdev_list
, *bdev
;
965 bdev_list
= qmp_query_block(NULL
);
966 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
967 if (key_is_missing(bdev
->value
)) {
968 monitor_read_block_device_key(mon
, bdev
->value
->device
,
975 hmp_handle_error(mon
, &err
);
978 qapi_free_BlockInfoList(bdev_list
);
981 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
983 qmp_system_wakeup(NULL
);
986 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
990 qmp_inject_nmi(&err
);
991 hmp_handle_error(mon
, &err
);
994 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
996 const char *name
= qdict_get_str(qdict
, "name");
997 int up
= qdict_get_bool(qdict
, "up");
1000 qmp_set_link(name
, up
, &err
);
1001 hmp_handle_error(mon
, &err
);
1004 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1006 const char *device
= qdict_get_str(qdict
, "device");
1007 const char *password
= qdict_get_str(qdict
, "password");
1010 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1011 hmp_handle_error(mon
, &err
);
1014 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1016 int64_t value
= qdict_get_int(qdict
, "value");
1019 qmp_balloon(value
, &err
);
1021 monitor_printf(mon
, "balloon: %s\n", error_get_pretty(err
));
1026 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1028 const char *device
= qdict_get_str(qdict
, "device");
1029 int64_t size
= qdict_get_int(qdict
, "size");
1032 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1033 hmp_handle_error(mon
, &err
);
1036 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1038 const char *device
= qdict_get_str(qdict
, "device");
1039 const char *filename
= qdict_get_str(qdict
, "target");
1040 const char *format
= qdict_get_try_str(qdict
, "format");
1041 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
1042 int full
= qdict_get_try_bool(qdict
, "full", 0);
1043 enum NewImageMode mode
;
1047 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
1048 hmp_handle_error(mon
, &err
);
1053 mode
= NEW_IMAGE_MODE_EXISTING
;
1055 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1058 qmp_drive_mirror(device
, filename
, !!format
, format
,
1059 false, NULL
, false, NULL
,
1060 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1061 true, mode
, false, 0, false, 0, false, 0,
1062 false, 0, false, 0, &err
);
1063 hmp_handle_error(mon
, &err
);
1066 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1068 const char *device
= qdict_get_str(qdict
, "device");
1069 const char *filename
= qdict_get_str(qdict
, "target");
1070 const char *format
= qdict_get_try_str(qdict
, "format");
1071 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
1072 int full
= qdict_get_try_bool(qdict
, "full", 0);
1073 enum NewImageMode mode
;
1077 error_set(&err
, QERR_MISSING_PARAMETER
, "target");
1078 hmp_handle_error(mon
, &err
);
1083 mode
= NEW_IMAGE_MODE_EXISTING
;
1085 mode
= NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1088 qmp_drive_backup(device
, filename
, !!format
, format
,
1089 full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1090 true, mode
, false, 0, false, NULL
,
1091 false, 0, false, 0, &err
);
1092 hmp_handle_error(mon
, &err
);
1095 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1097 const char *device
= qdict_get_str(qdict
, "device");
1098 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1099 const char *format
= qdict_get_try_str(qdict
, "format");
1100 int reuse
= qdict_get_try_bool(qdict
, "reuse", 0);
1101 enum NewImageMode mode
;
1105 /* In the future, if 'snapshot-file' is not specified, the snapshot
1106 will be taken internally. Today it's actually required. */
1107 error_set(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1108 hmp_handle_error(mon
, &err
);
1112 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1113 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1114 filename
, false, NULL
,
1117 hmp_handle_error(mon
, &err
);
1120 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1122 const char *device
= qdict_get_str(qdict
, "device");
1123 const char *name
= qdict_get_str(qdict
, "name");
1126 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1127 hmp_handle_error(mon
, &err
);
1130 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1132 const char *device
= qdict_get_str(qdict
, "device");
1133 const char *name
= qdict_get_str(qdict
, "name");
1134 const char *id
= qdict_get_try_str(qdict
, "id");
1137 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1139 hmp_handle_error(mon
, &err
);
1142 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1144 qmp_migrate_cancel(NULL
);
1147 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1150 const char *uri
= qdict_get_str(qdict
, "uri");
1152 qmp_migrate_incoming(uri
, &err
);
1154 hmp_handle_error(mon
, &err
);
1157 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1159 double value
= qdict_get_double(qdict
, "value");
1160 qmp_migrate_set_downtime(value
, NULL
);
1163 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1165 int64_t value
= qdict_get_int(qdict
, "value");
1168 qmp_migrate_set_cache_size(value
, &err
);
1170 monitor_printf(mon
, "%s\n", error_get_pretty(err
));
1176 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1178 int64_t value
= qdict_get_int(qdict
, "value");
1179 qmp_migrate_set_speed(value
, NULL
);
1182 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1184 const char *cap
= qdict_get_str(qdict
, "capability");
1185 bool state
= qdict_get_bool(qdict
, "state");
1187 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1190 for (i
= 0; i
< MIGRATION_CAPABILITY_MAX
; i
++) {
1191 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1192 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1193 caps
->value
->capability
= i
;
1194 caps
->value
->state
= state
;
1196 qmp_migrate_set_capabilities(caps
, &err
);
1201 if (i
== MIGRATION_CAPABILITY_MAX
) {
1202 error_set(&err
, QERR_INVALID_PARAMETER
, cap
);
1205 qapi_free_MigrationCapabilityStatusList(caps
);
1208 monitor_printf(mon
, "migrate_set_capability: %s\n",
1209 error_get_pretty(err
));
1214 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1216 const char *param
= qdict_get_str(qdict
, "parameter");
1217 int value
= qdict_get_int(qdict
, "value");
1219 bool has_compress_level
= false;
1220 bool has_compress_threads
= false;
1221 bool has_decompress_threads
= false;
1224 for (i
= 0; i
< MIGRATION_PARAMETER_MAX
; i
++) {
1225 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1227 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1228 has_compress_level
= true;
1230 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1231 has_compress_threads
= true;
1233 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1234 has_decompress_threads
= true;
1237 qmp_migrate_set_parameters(has_compress_level
, value
,
1238 has_compress_threads
, value
,
1239 has_decompress_threads
, value
,
1245 if (i
== MIGRATION_PARAMETER_MAX
) {
1246 error_set(&err
, QERR_INVALID_PARAMETER
, param
);
1250 monitor_printf(mon
, "migrate_set_parameter: %s\n",
1251 error_get_pretty(err
));
1256 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1259 const char *protocol
= qdict_get_str(qdict
, "protocol");
1260 const char *hostname
= qdict_get_str(qdict
, "hostname");
1261 bool has_port
= qdict_haskey(qdict
, "port");
1262 int port
= qdict_get_try_int(qdict
, "port", -1);
1263 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1264 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1265 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1267 qmp_client_migrate_info(protocol
, hostname
,
1268 has_port
, port
, has_tls_port
, tls_port
,
1269 !!cert_subject
, cert_subject
, &err
);
1270 hmp_handle_error(mon
, &err
);
1273 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1275 const char *protocol
= qdict_get_str(qdict
, "protocol");
1276 const char *password
= qdict_get_str(qdict
, "password");
1277 const char *connected
= qdict_get_try_str(qdict
, "connected");
1280 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1281 hmp_handle_error(mon
, &err
);
1284 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1286 const char *protocol
= qdict_get_str(qdict
, "protocol");
1287 const char *whenstr
= qdict_get_str(qdict
, "time");
1290 qmp_expire_password(protocol
, whenstr
, &err
);
1291 hmp_handle_error(mon
, &err
);
1294 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1296 int force
= qdict_get_try_bool(qdict
, "force", 0);
1297 const char *device
= qdict_get_str(qdict
, "device");
1300 qmp_eject(device
, true, force
, &err
);
1301 hmp_handle_error(mon
, &err
);
1304 static void hmp_change_read_arg(void *opaque
, const char *password
,
1305 void *readline_opaque
)
1307 qmp_change_vnc_password(password
, NULL
);
1308 monitor_read_command(opaque
, 1);
1311 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1313 const char *device
= qdict_get_str(qdict
, "device");
1314 const char *target
= qdict_get_str(qdict
, "target");
1315 const char *arg
= qdict_get_try_str(qdict
, "arg");
1318 if (strcmp(device
, "vnc") == 0 &&
1319 (strcmp(target
, "passwd") == 0 ||
1320 strcmp(target
, "password") == 0)) {
1322 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1327 qmp_change(device
, target
, !!arg
, arg
, &err
);
1329 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1331 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1334 hmp_handle_error(mon
, &err
);
1337 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1341 qmp_block_set_io_throttle(qdict_get_str(qdict
, "device"),
1342 qdict_get_int(qdict
, "bps"),
1343 qdict_get_int(qdict
, "bps_rd"),
1344 qdict_get_int(qdict
, "bps_wr"),
1345 qdict_get_int(qdict
, "iops"),
1346 qdict_get_int(qdict
, "iops_rd"),
1347 qdict_get_int(qdict
, "iops_wr"),
1348 false, /* no burst max via HMP */
1360 false, /* No default I/O size */
1364 hmp_handle_error(mon
, &err
);
1367 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1369 Error
*error
= NULL
;
1370 const char *device
= qdict_get_str(qdict
, "device");
1371 const char *base
= qdict_get_try_str(qdict
, "base");
1372 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1374 qmp_block_stream(device
, base
!= NULL
, base
, false, NULL
,
1375 qdict_haskey(qdict
, "speed"), speed
,
1376 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1378 hmp_handle_error(mon
, &error
);
1381 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1383 Error
*error
= NULL
;
1384 const char *device
= qdict_get_str(qdict
, "device");
1385 int64_t value
= qdict_get_int(qdict
, "speed");
1387 qmp_block_job_set_speed(device
, value
, &error
);
1389 hmp_handle_error(mon
, &error
);
1392 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1394 Error
*error
= NULL
;
1395 const char *device
= qdict_get_str(qdict
, "device");
1396 bool force
= qdict_get_try_bool(qdict
, "force", 0);
1398 qmp_block_job_cancel(device
, true, force
, &error
);
1400 hmp_handle_error(mon
, &error
);
1403 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1405 Error
*error
= NULL
;
1406 const char *device
= qdict_get_str(qdict
, "device");
1408 qmp_block_job_pause(device
, &error
);
1410 hmp_handle_error(mon
, &error
);
1413 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1415 Error
*error
= NULL
;
1416 const char *device
= qdict_get_str(qdict
, "device");
1418 qmp_block_job_resume(device
, &error
);
1420 hmp_handle_error(mon
, &error
);
1423 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1425 Error
*error
= NULL
;
1426 const char *device
= qdict_get_str(qdict
, "device");
1428 qmp_block_job_complete(device
, &error
);
1430 hmp_handle_error(mon
, &error
);
1433 typedef struct HMPMigrationStatus
1437 bool is_block_migration
;
1438 } HMPMigrationStatus
;
1440 static void hmp_migrate_status_cb(void *opaque
)
1442 HMPMigrationStatus
*status
= opaque
;
1443 MigrationInfo
*info
;
1445 info
= qmp_query_migrate(NULL
);
1446 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1447 info
->status
== MIGRATION_STATUS_SETUP
) {
1448 if (info
->has_disk
) {
1451 if (info
->disk
->remaining
) {
1452 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1457 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1458 monitor_flush(status
->mon
);
1461 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1463 if (status
->is_block_migration
) {
1464 monitor_printf(status
->mon
, "\n");
1466 monitor_resume(status
->mon
);
1467 timer_del(status
->timer
);
1471 qapi_free_MigrationInfo(info
);
1474 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1476 int detach
= qdict_get_try_bool(qdict
, "detach", 0);
1477 int blk
= qdict_get_try_bool(qdict
, "blk", 0);
1478 int inc
= qdict_get_try_bool(qdict
, "inc", 0);
1479 const char *uri
= qdict_get_str(qdict
, "uri");
1482 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1484 monitor_printf(mon
, "migrate: %s\n", error_get_pretty(err
));
1490 HMPMigrationStatus
*status
;
1492 if (monitor_suspend(mon
) < 0) {
1493 monitor_printf(mon
, "terminal does not allow synchronous "
1494 "migration, continuing detached\n");
1498 status
= g_malloc0(sizeof(*status
));
1500 status
->is_block_migration
= blk
|| inc
;
1501 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1503 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1507 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1509 do_device_add(mon
, qdict
, NULL
);
1512 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1514 const char *id
= qdict_get_str(qdict
, "id");
1517 qmp_device_del(id
, &err
);
1518 hmp_handle_error(mon
, &err
);
1521 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1524 int paging
= qdict_get_try_bool(qdict
, "paging", 0);
1525 int zlib
= qdict_get_try_bool(qdict
, "zlib", 0);
1526 int lzo
= qdict_get_try_bool(qdict
, "lzo", 0);
1527 int snappy
= qdict_get_try_bool(qdict
, "snappy", 0);
1528 const char *file
= qdict_get_str(qdict
, "filename");
1529 bool has_begin
= qdict_haskey(qdict
, "begin");
1530 bool has_length
= qdict_haskey(qdict
, "length");
1533 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1536 if (zlib
+ lzo
+ snappy
> 1) {
1537 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1538 hmp_handle_error(mon
, &err
);
1543 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1547 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1551 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1555 begin
= qdict_get_int(qdict
, "begin");
1558 length
= qdict_get_int(qdict
, "length");
1561 prot
= g_strconcat("file:", file
, NULL
);
1563 qmp_dump_guest_memory(paging
, prot
, has_begin
, begin
, has_length
, length
,
1564 true, dump_format
, &err
);
1565 hmp_handle_error(mon
, &err
);
1569 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1574 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1579 netdev_add(opts
, &err
);
1581 qemu_opts_del(opts
);
1585 hmp_handle_error(mon
, &err
);
1588 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1590 const char *id
= qdict_get_str(qdict
, "id");
1593 qmp_netdev_del(id
, &err
);
1594 hmp_handle_error(mon
, &err
);
1597 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1600 Error
*err_end
= NULL
;
1608 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1613 ov
= opts_visitor_new(opts
);
1614 pdict
= qdict_clone_shallow(qdict
);
1616 visit_start_struct(opts_get_visitor(ov
), &dummy
, NULL
, NULL
, 0, &err
);
1621 qdict_del(pdict
, "qom-type");
1622 visit_type_str(opts_get_visitor(ov
), &type
, "qom-type", &err
);
1627 qdict_del(pdict
, "id");
1628 visit_type_str(opts_get_visitor(ov
), &id
, "id", &err
);
1633 object_add(type
, id
, pdict
, opts_get_visitor(ov
), &err
);
1636 visit_end_struct(opts_get_visitor(ov
), &err_end
);
1637 if (!err
&& err_end
) {
1638 qmp_object_del(id
, NULL
);
1640 error_propagate(&err
, err_end
);
1642 opts_visitor_cleanup(ov
);
1645 qemu_opts_del(opts
);
1651 hmp_handle_error(mon
, &err
);
1654 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1656 const char *fdname
= qdict_get_str(qdict
, "fdname");
1659 qmp_getfd(fdname
, &err
);
1660 hmp_handle_error(mon
, &err
);
1663 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1665 const char *fdname
= qdict_get_str(qdict
, "fdname");
1668 qmp_closefd(fdname
, &err
);
1669 hmp_handle_error(mon
, &err
);
1672 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1674 const char *keys
= qdict_get_str(qdict
, "keys");
1675 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1676 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1677 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1679 char keyname_buf
[16];
1684 separator
= strchr(keys
, '-');
1685 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1686 pstrcpy(keyname_buf
, sizeof(keyname_buf
), keys
);
1688 /* Be compatible with old interface, convert user inputted "<" */
1689 if (!strncmp(keyname_buf
, "<", 1) && keyname_len
== 1) {
1690 pstrcpy(keyname_buf
, sizeof(keyname_buf
), "less");
1693 keyname_buf
[keyname_len
] = 0;
1695 keylist
= g_malloc0(sizeof(*keylist
));
1696 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1702 tmp
->next
= keylist
;
1706 if (strstart(keyname_buf
, "0x", NULL
)) {
1708 int value
= strtoul(keyname_buf
, &endp
, 0);
1709 if (*endp
!= '\0') {
1712 keylist
->value
->kind
= KEY_VALUE_KIND_NUMBER
;
1713 keylist
->value
->number
= value
;
1715 int idx
= index_from_key(keyname_buf
);
1716 if (idx
== Q_KEY_CODE_MAX
) {
1719 keylist
->value
->kind
= KEY_VALUE_KIND_QCODE
;
1720 keylist
->value
->qcode
= idx
;
1726 keys
= separator
+ 1;
1729 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1730 hmp_handle_error(mon
, &err
);
1733 qapi_free_KeyValueList(head
);
1737 monitor_printf(mon
, "invalid parameter: %s\n", keyname_buf
);
1741 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1743 const char *filename
= qdict_get_str(qdict
, "filename");
1746 qmp_screendump(filename
, &err
);
1747 hmp_handle_error(mon
, &err
);
1750 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1752 const char *uri
= qdict_get_str(qdict
, "uri");
1753 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1754 int all
= qdict_get_try_bool(qdict
, "all", 0);
1755 Error
*local_err
= NULL
;
1756 BlockInfoList
*block_list
, *info
;
1757 SocketAddress
*addr
;
1759 if (writable
&& !all
) {
1760 error_setg(&local_err
, "-w only valid together with -a");
1764 /* First check if the address is valid and start the server. */
1765 addr
= socket_parse(uri
, &local_err
);
1766 if (local_err
!= NULL
) {
1770 qmp_nbd_server_start(addr
, &local_err
);
1771 qapi_free_SocketAddress(addr
);
1772 if (local_err
!= NULL
) {
1780 /* Then try adding all block devices. If one fails, close all and
1783 block_list
= qmp_query_block(NULL
);
1785 for (info
= block_list
; info
; info
= info
->next
) {
1786 if (!info
->value
->has_inserted
) {
1790 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1792 if (local_err
!= NULL
) {
1793 qmp_nbd_server_stop(NULL
);
1798 qapi_free_BlockInfoList(block_list
);
1801 hmp_handle_error(mon
, &local_err
);
1804 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1806 const char *device
= qdict_get_str(qdict
, "device");
1807 int writable
= qdict_get_try_bool(qdict
, "writable", 0);
1808 Error
*local_err
= NULL
;
1810 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1812 if (local_err
!= NULL
) {
1813 hmp_handle_error(mon
, &local_err
);
1817 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1821 qmp_nbd_server_stop(&err
);
1822 hmp_handle_error(mon
, &err
);
1825 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1830 cpuid
= qdict_get_int(qdict
, "id");
1831 qmp_cpu_add(cpuid
, &err
);
1832 hmp_handle_error(mon
, &err
);
1835 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1837 const char *args
= qdict_get_str(qdict
, "args");
1841 opts
= qemu_opts_parse(qemu_find_opts("chardev"), args
, 1);
1843 error_setg(&err
, "Parsing chardev args failed");
1845 qemu_chr_new_from_opts(opts
, NULL
, &err
);
1847 hmp_handle_error(mon
, &err
);
1850 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
1852 Error
*local_err
= NULL
;
1854 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
1855 hmp_handle_error(mon
, &local_err
);
1858 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
1861 const char* device
= qdict_get_str(qdict
, "device");
1862 const char* command
= qdict_get_str(qdict
, "command");
1865 blk
= blk_by_name(device
);
1867 qemuio_command(blk
, command
);
1869 error_set(&err
, QERR_DEVICE_NOT_FOUND
, device
);
1872 hmp_handle_error(mon
, &err
);
1875 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
1877 const char *id
= qdict_get_str(qdict
, "id");
1880 qmp_object_del(id
, &err
);
1881 hmp_handle_error(mon
, &err
);
1884 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
1887 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
1888 MemdevList
*m
= memdev_list
;
1889 StringOutputVisitor
*ov
;
1895 ov
= string_output_visitor_new(false);
1896 visit_type_uint16List(string_output_get_visitor(ov
),
1897 &m
->value
->host_nodes
, NULL
, NULL
);
1898 monitor_printf(mon
, "memory backend: %d\n", i
);
1899 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
1900 monitor_printf(mon
, " merge: %s\n",
1901 m
->value
->merge
? "true" : "false");
1902 monitor_printf(mon
, " dump: %s\n",
1903 m
->value
->dump
? "true" : "false");
1904 monitor_printf(mon
, " prealloc: %s\n",
1905 m
->value
->prealloc
? "true" : "false");
1906 monitor_printf(mon
, " policy: %s\n",
1907 HostMemPolicy_lookup
[m
->value
->policy
]);
1908 str
= string_output_get_string(ov
);
1909 monitor_printf(mon
, " host nodes: %s\n", str
);
1912 string_output_visitor_cleanup(ov
);
1917 monitor_printf(mon
, "\n");
1919 qapi_free_MemdevList(memdev_list
);
1922 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
1925 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
1926 MemoryDeviceInfoList
*info
;
1927 MemoryDeviceInfo
*value
;
1928 PCDIMMDeviceInfo
*di
;
1930 for (info
= info_list
; info
; info
= info
->next
) {
1931 value
= info
->value
;
1934 switch (value
->kind
) {
1935 case MEMORY_DEVICE_INFO_KIND_DIMM
:
1938 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
1939 MemoryDeviceInfoKind_lookup
[value
->kind
],
1940 di
->id
? di
->id
: "");
1941 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
1942 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
1943 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
1944 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
1945 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
1946 monitor_printf(mon
, " hotplugged: %s\n",
1947 di
->hotplugged
? "true" : "false");
1948 monitor_printf(mon
, " hotpluggable: %s\n",
1949 di
->hotpluggable
? "true" : "false");
1957 qapi_free_MemoryDeviceInfoList(info_list
);
1960 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
1962 const char *path
= qdict_get_try_str(qdict
, "path");
1963 ObjectPropertyInfoList
*list
;
1967 monitor_printf(mon
, "/\n");
1971 list
= qmp_qom_list(path
, &err
);
1973 ObjectPropertyInfoList
*start
= list
;
1974 while (list
!= NULL
) {
1975 ObjectPropertyInfo
*value
= list
->value
;
1977 monitor_printf(mon
, "%s (%s)\n",
1978 value
->name
, value
->type
);
1981 qapi_free_ObjectPropertyInfoList(start
);
1983 hmp_handle_error(mon
, &err
);
1986 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
1988 const char *path
= qdict_get_str(qdict
, "path");
1989 const char *property
= qdict_get_str(qdict
, "property");
1990 const char *value
= qdict_get_str(qdict
, "value");
1992 bool ambiguous
= false;
1995 obj
= object_resolve_path(path
, &ambiguous
);
1997 error_set(&err
, QERR_DEVICE_NOT_FOUND
, path
);
2000 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2002 object_property_parse(obj
, value
, property
, &err
);
2004 hmp_handle_error(mon
, &err
);