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.
16 #include "qemu/osdep.h"
20 #include "sysemu/char.h"
21 #include "sysemu/block-backend.h"
22 #include "qemu/option.h"
23 #include "qemu/timer.h"
24 #include "qmp-commands.h"
25 #include "qemu/sockets.h"
26 #include "monitor/monitor.h"
27 #include "monitor/qdev.h"
28 #include "qapi/opts-visitor.h"
29 #include "qapi/qmp/qerror.h"
30 #include "qapi/string-output-visitor.h"
31 #include "qapi/util.h"
32 #include "qapi-visit.h"
33 #include "qom/object_interfaces.h"
34 #include "ui/console.h"
35 #include "block/qapi.h"
37 #include "qemu/cutils.h"
38 #include "qemu/error-report.h"
39 #include "hw/intc/intc.h"
42 #include <spice/enums.h>
45 static void hmp_handle_error(Monitor
*mon
, Error
**errp
)
49 error_report_err(*errp
);
53 void hmp_info_name(Monitor
*mon
, const QDict
*qdict
)
57 info
= qmp_query_name(NULL
);
59 monitor_printf(mon
, "%s\n", info
->name
);
61 qapi_free_NameInfo(info
);
64 void hmp_info_version(Monitor
*mon
, const QDict
*qdict
)
68 info
= qmp_query_version(NULL
);
70 monitor_printf(mon
, "%" PRId64
".%" PRId64
".%" PRId64
"%s\n",
71 info
->qemu
->major
, info
->qemu
->minor
, info
->qemu
->micro
,
74 qapi_free_VersionInfo(info
);
77 void hmp_info_kvm(Monitor
*mon
, const QDict
*qdict
)
81 info
= qmp_query_kvm(NULL
);
82 monitor_printf(mon
, "kvm support: ");
84 monitor_printf(mon
, "%s\n", info
->enabled
? "enabled" : "disabled");
86 monitor_printf(mon
, "not compiled\n");
89 qapi_free_KvmInfo(info
);
92 void hmp_info_status(Monitor
*mon
, const QDict
*qdict
)
96 info
= qmp_query_status(NULL
);
98 monitor_printf(mon
, "VM status: %s%s",
99 info
->running
? "running" : "paused",
100 info
->singlestep
? " (single step mode)" : "");
102 if (!info
->running
&& info
->status
!= RUN_STATE_PAUSED
) {
103 monitor_printf(mon
, " (%s)", RunState_lookup
[info
->status
]);
106 monitor_printf(mon
, "\n");
108 qapi_free_StatusInfo(info
);
111 void hmp_info_uuid(Monitor
*mon
, const QDict
*qdict
)
115 info
= qmp_query_uuid(NULL
);
116 monitor_printf(mon
, "%s\n", info
->UUID
);
117 qapi_free_UuidInfo(info
);
120 void hmp_info_chardev(Monitor
*mon
, const QDict
*qdict
)
122 ChardevInfoList
*char_info
, *info
;
124 char_info
= qmp_query_chardev(NULL
);
125 for (info
= char_info
; info
; info
= info
->next
) {
126 monitor_printf(mon
, "%s: filename=%s\n", info
->value
->label
,
127 info
->value
->filename
);
130 qapi_free_ChardevInfoList(char_info
);
133 void hmp_info_mice(Monitor
*mon
, const QDict
*qdict
)
135 MouseInfoList
*mice_list
, *mouse
;
137 mice_list
= qmp_query_mice(NULL
);
139 monitor_printf(mon
, "No mouse devices connected\n");
143 for (mouse
= mice_list
; mouse
; mouse
= mouse
->next
) {
144 monitor_printf(mon
, "%c Mouse #%" PRId64
": %s%s\n",
145 mouse
->value
->current
? '*' : ' ',
146 mouse
->value
->index
, mouse
->value
->name
,
147 mouse
->value
->absolute
? " (absolute)" : "");
150 qapi_free_MouseInfoList(mice_list
);
153 void hmp_info_migrate(Monitor
*mon
, const QDict
*qdict
)
156 MigrationCapabilityStatusList
*caps
, *cap
;
158 info
= qmp_query_migrate(NULL
);
159 caps
= qmp_query_migrate_capabilities(NULL
);
161 /* do not display parameters during setup */
162 if (info
->has_status
&& caps
) {
163 monitor_printf(mon
, "capabilities: ");
164 for (cap
= caps
; cap
; cap
= cap
->next
) {
165 monitor_printf(mon
, "%s: %s ",
166 MigrationCapability_lookup
[cap
->value
->capability
],
167 cap
->value
->state
? "on" : "off");
169 monitor_printf(mon
, "\n");
172 if (info
->has_status
) {
173 monitor_printf(mon
, "Migration status: %s",
174 MigrationStatus_lookup
[info
->status
]);
175 if (info
->status
== MIGRATION_STATUS_FAILED
&&
176 info
->has_error_desc
) {
177 monitor_printf(mon
, " (%s)\n", info
->error_desc
);
179 monitor_printf(mon
, "\n");
182 monitor_printf(mon
, "total time: %" PRIu64
" milliseconds\n",
184 if (info
->has_expected_downtime
) {
185 monitor_printf(mon
, "expected downtime: %" PRIu64
" milliseconds\n",
186 info
->expected_downtime
);
188 if (info
->has_downtime
) {
189 monitor_printf(mon
, "downtime: %" PRIu64
" milliseconds\n",
192 if (info
->has_setup_time
) {
193 monitor_printf(mon
, "setup: %" PRIu64
" milliseconds\n",
199 monitor_printf(mon
, "transferred ram: %" PRIu64
" kbytes\n",
200 info
->ram
->transferred
>> 10);
201 monitor_printf(mon
, "throughput: %0.2f mbps\n",
203 monitor_printf(mon
, "remaining ram: %" PRIu64
" kbytes\n",
204 info
->ram
->remaining
>> 10);
205 monitor_printf(mon
, "total ram: %" PRIu64
" kbytes\n",
206 info
->ram
->total
>> 10);
207 monitor_printf(mon
, "duplicate: %" PRIu64
" pages\n",
208 info
->ram
->duplicate
);
209 monitor_printf(mon
, "skipped: %" PRIu64
" pages\n",
211 monitor_printf(mon
, "normal: %" PRIu64
" pages\n",
213 monitor_printf(mon
, "normal bytes: %" PRIu64
" kbytes\n",
214 info
->ram
->normal_bytes
>> 10);
215 monitor_printf(mon
, "dirty sync count: %" PRIu64
"\n",
216 info
->ram
->dirty_sync_count
);
217 if (info
->ram
->dirty_pages_rate
) {
218 monitor_printf(mon
, "dirty pages rate: %" PRIu64
" pages\n",
219 info
->ram
->dirty_pages_rate
);
221 if (info
->ram
->postcopy_requests
) {
222 monitor_printf(mon
, "postcopy request count: %" PRIu64
"\n",
223 info
->ram
->postcopy_requests
);
227 if (info
->has_disk
) {
228 monitor_printf(mon
, "transferred disk: %" PRIu64
" kbytes\n",
229 info
->disk
->transferred
>> 10);
230 monitor_printf(mon
, "remaining disk: %" PRIu64
" kbytes\n",
231 info
->disk
->remaining
>> 10);
232 monitor_printf(mon
, "total disk: %" PRIu64
" kbytes\n",
233 info
->disk
->total
>> 10);
236 if (info
->has_xbzrle_cache
) {
237 monitor_printf(mon
, "cache size: %" PRIu64
" bytes\n",
238 info
->xbzrle_cache
->cache_size
);
239 monitor_printf(mon
, "xbzrle transferred: %" PRIu64
" kbytes\n",
240 info
->xbzrle_cache
->bytes
>> 10);
241 monitor_printf(mon
, "xbzrle pages: %" PRIu64
" pages\n",
242 info
->xbzrle_cache
->pages
);
243 monitor_printf(mon
, "xbzrle cache miss: %" PRIu64
"\n",
244 info
->xbzrle_cache
->cache_miss
);
245 monitor_printf(mon
, "xbzrle cache miss rate: %0.2f\n",
246 info
->xbzrle_cache
->cache_miss_rate
);
247 monitor_printf(mon
, "xbzrle overflow : %" PRIu64
"\n",
248 info
->xbzrle_cache
->overflow
);
251 if (info
->has_cpu_throttle_percentage
) {
252 monitor_printf(mon
, "cpu throttle percentage: %" PRIu64
"\n",
253 info
->cpu_throttle_percentage
);
256 qapi_free_MigrationInfo(info
);
257 qapi_free_MigrationCapabilityStatusList(caps
);
260 void hmp_info_migrate_capabilities(Monitor
*mon
, const QDict
*qdict
)
262 MigrationCapabilityStatusList
*caps
, *cap
;
264 caps
= qmp_query_migrate_capabilities(NULL
);
267 monitor_printf(mon
, "capabilities: ");
268 for (cap
= caps
; cap
; cap
= cap
->next
) {
269 monitor_printf(mon
, "%s: %s ",
270 MigrationCapability_lookup
[cap
->value
->capability
],
271 cap
->value
->state
? "on" : "off");
273 monitor_printf(mon
, "\n");
276 qapi_free_MigrationCapabilityStatusList(caps
);
279 void hmp_info_migrate_parameters(Monitor
*mon
, const QDict
*qdict
)
281 MigrationParameters
*params
;
283 params
= qmp_query_migrate_parameters(NULL
);
286 monitor_printf(mon
, "parameters:");
287 assert(params
->has_compress_level
);
288 monitor_printf(mon
, " %s: %" PRId64
,
289 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_LEVEL
],
290 params
->compress_level
);
291 assert(params
->has_compress_threads
);
292 monitor_printf(mon
, " %s: %" PRId64
,
293 MigrationParameter_lookup
[MIGRATION_PARAMETER_COMPRESS_THREADS
],
294 params
->compress_threads
);
295 assert(params
->has_decompress_threads
);
296 monitor_printf(mon
, " %s: %" PRId64
,
297 MigrationParameter_lookup
[MIGRATION_PARAMETER_DECOMPRESS_THREADS
],
298 params
->decompress_threads
);
299 assert(params
->has_cpu_throttle_initial
);
300 monitor_printf(mon
, " %s: %" PRId64
,
301 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
],
302 params
->cpu_throttle_initial
);
303 assert(params
->has_cpu_throttle_increment
);
304 monitor_printf(mon
, " %s: %" PRId64
,
305 MigrationParameter_lookup
[MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
],
306 params
->cpu_throttle_increment
);
307 monitor_printf(mon
, " %s: '%s'",
308 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_CREDS
],
309 params
->has_tls_creds
? params
->tls_creds
: "");
310 monitor_printf(mon
, " %s: '%s'",
311 MigrationParameter_lookup
[MIGRATION_PARAMETER_TLS_HOSTNAME
],
312 params
->has_tls_hostname
? params
->tls_hostname
: "");
313 assert(params
->has_max_bandwidth
);
314 monitor_printf(mon
, " %s: %" PRId64
" bytes/second",
315 MigrationParameter_lookup
[MIGRATION_PARAMETER_MAX_BANDWIDTH
],
316 params
->max_bandwidth
);
317 assert(params
->has_downtime_limit
);
318 monitor_printf(mon
, " %s: %" PRId64
" milliseconds",
319 MigrationParameter_lookup
[MIGRATION_PARAMETER_DOWNTIME_LIMIT
],
320 params
->downtime_limit
);
321 monitor_printf(mon
, "\n");
324 qapi_free_MigrationParameters(params
);
327 void hmp_info_migrate_cache_size(Monitor
*mon
, const QDict
*qdict
)
329 monitor_printf(mon
, "xbzrel cache size: %" PRId64
" kbytes\n",
330 qmp_query_migrate_cache_size(NULL
) >> 10);
333 void hmp_info_cpus(Monitor
*mon
, const QDict
*qdict
)
335 CpuInfoList
*cpu_list
, *cpu
;
337 cpu_list
= qmp_query_cpus(NULL
);
339 for (cpu
= cpu_list
; cpu
; cpu
= cpu
->next
) {
342 if (cpu
->value
->CPU
== monitor_get_cpu_index()) {
346 monitor_printf(mon
, "%c CPU #%" PRId64
":", active
, cpu
->value
->CPU
);
348 switch (cpu
->value
->arch
) {
349 case CPU_INFO_ARCH_X86
:
350 monitor_printf(mon
, " pc=0x%016" PRIx64
, cpu
->value
->u
.x86
.pc
);
352 case CPU_INFO_ARCH_PPC
:
353 monitor_printf(mon
, " nip=0x%016" PRIx64
, cpu
->value
->u
.ppc
.nip
);
355 case CPU_INFO_ARCH_SPARC
:
356 monitor_printf(mon
, " pc=0x%016" PRIx64
,
357 cpu
->value
->u
.q_sparc
.pc
);
358 monitor_printf(mon
, " npc=0x%016" PRIx64
,
359 cpu
->value
->u
.q_sparc
.npc
);
361 case CPU_INFO_ARCH_MIPS
:
362 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.q_mips
.PC
);
364 case CPU_INFO_ARCH_TRICORE
:
365 monitor_printf(mon
, " PC=0x%016" PRIx64
, cpu
->value
->u
.tricore
.PC
);
371 if (cpu
->value
->halted
) {
372 monitor_printf(mon
, " (halted)");
375 monitor_printf(mon
, " thread_id=%" PRId64
"\n", cpu
->value
->thread_id
);
378 qapi_free_CpuInfoList(cpu_list
);
381 static void print_block_info(Monitor
*mon
, BlockInfo
*info
,
382 BlockDeviceInfo
*inserted
, bool verbose
)
384 ImageInfo
*image_info
;
386 assert(!info
|| !info
->has_inserted
|| info
->inserted
== inserted
);
389 monitor_printf(mon
, "%s", info
->device
);
390 if (inserted
&& inserted
->has_node_name
) {
391 monitor_printf(mon
, " (%s)", inserted
->node_name
);
395 monitor_printf(mon
, "%s",
396 inserted
->has_node_name
397 ? inserted
->node_name
402 monitor_printf(mon
, ": %s (%s%s%s)\n",
405 inserted
->ro
? ", read-only" : "",
406 inserted
->encrypted
? ", encrypted" : "");
408 monitor_printf(mon
, ": [not inserted]\n");
412 if (info
->has_io_status
&& info
->io_status
!= BLOCK_DEVICE_IO_STATUS_OK
) {
413 monitor_printf(mon
, " I/O status: %s\n",
414 BlockDeviceIoStatus_lookup
[info
->io_status
]);
417 if (info
->removable
) {
418 monitor_printf(mon
, " Removable device: %slocked, tray %s\n",
419 info
->locked
? "" : "not ",
420 info
->tray_open
? "open" : "closed");
429 monitor_printf(mon
, " Cache mode: %s%s%s\n",
430 inserted
->cache
->writeback
? "writeback" : "writethrough",
431 inserted
->cache
->direct
? ", direct" : "",
432 inserted
->cache
->no_flush
? ", ignore flushes" : "");
434 if (inserted
->has_backing_file
) {
437 "(chain depth: %" PRId64
")\n",
438 inserted
->backing_file
,
439 inserted
->backing_file_depth
);
442 if (inserted
->detect_zeroes
!= BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF
) {
443 monitor_printf(mon
, " Detect zeroes: %s\n",
444 BlockdevDetectZeroesOptions_lookup
[inserted
->detect_zeroes
]);
447 if (inserted
->bps
|| inserted
->bps_rd
|| inserted
->bps_wr
||
448 inserted
->iops
|| inserted
->iops_rd
|| inserted
->iops_wr
)
450 monitor_printf(mon
, " I/O throttling: bps=%" PRId64
451 " bps_rd=%" PRId64
" bps_wr=%" PRId64
453 " bps_rd_max=%" PRId64
454 " bps_wr_max=%" PRId64
455 " iops=%" PRId64
" iops_rd=%" PRId64
458 " iops_rd_max=%" PRId64
459 " iops_wr_max=%" PRId64
460 " iops_size=%" PRId64
466 inserted
->bps_rd_max
,
467 inserted
->bps_wr_max
,
472 inserted
->iops_rd_max
,
473 inserted
->iops_wr_max
,
479 monitor_printf(mon
, "\nImages:\n");
480 image_info
= inserted
->image
;
482 bdrv_image_info_dump((fprintf_function
)monitor_printf
,
484 if (image_info
->has_backing_image
) {
485 image_info
= image_info
->backing_image
;
493 void hmp_info_block(Monitor
*mon
, const QDict
*qdict
)
495 BlockInfoList
*block_list
, *info
;
496 BlockDeviceInfoList
*blockdev_list
, *blockdev
;
497 const char *device
= qdict_get_try_str(qdict
, "device");
498 bool verbose
= qdict_get_try_bool(qdict
, "verbose", false);
499 bool nodes
= qdict_get_try_bool(qdict
, "nodes", false);
500 bool printed
= false;
502 /* Print BlockBackend information */
504 block_list
= qmp_query_block(NULL
);
509 for (info
= block_list
; info
; info
= info
->next
) {
510 if (device
&& strcmp(device
, info
->value
->device
)) {
514 if (info
!= block_list
) {
515 monitor_printf(mon
, "\n");
518 print_block_info(mon
, info
->value
, info
->value
->has_inserted
519 ? info
->value
->inserted
: NULL
,
524 qapi_free_BlockInfoList(block_list
);
526 if ((!device
&& !nodes
) || printed
) {
530 /* Print node information */
531 blockdev_list
= qmp_query_named_block_nodes(NULL
);
532 for (blockdev
= blockdev_list
; blockdev
; blockdev
= blockdev
->next
) {
533 assert(blockdev
->value
->has_node_name
);
534 if (device
&& strcmp(device
, blockdev
->value
->node_name
)) {
538 if (blockdev
!= blockdev_list
) {
539 monitor_printf(mon
, "\n");
542 print_block_info(mon
, NULL
, blockdev
->value
, verbose
);
544 qapi_free_BlockDeviceInfoList(blockdev_list
);
547 void hmp_info_blockstats(Monitor
*mon
, const QDict
*qdict
)
549 BlockStatsList
*stats_list
, *stats
;
551 stats_list
= qmp_query_blockstats(false, false, NULL
);
553 for (stats
= stats_list
; stats
; stats
= stats
->next
) {
554 if (!stats
->value
->has_device
) {
558 monitor_printf(mon
, "%s:", stats
->value
->device
);
559 monitor_printf(mon
, " rd_bytes=%" PRId64
561 " rd_operations=%" PRId64
562 " wr_operations=%" PRId64
563 " flush_operations=%" PRId64
564 " wr_total_time_ns=%" PRId64
565 " rd_total_time_ns=%" PRId64
566 " flush_total_time_ns=%" PRId64
567 " rd_merged=%" PRId64
568 " wr_merged=%" PRId64
569 " idle_time_ns=%" PRId64
571 stats
->value
->stats
->rd_bytes
,
572 stats
->value
->stats
->wr_bytes
,
573 stats
->value
->stats
->rd_operations
,
574 stats
->value
->stats
->wr_operations
,
575 stats
->value
->stats
->flush_operations
,
576 stats
->value
->stats
->wr_total_time_ns
,
577 stats
->value
->stats
->rd_total_time_ns
,
578 stats
->value
->stats
->flush_total_time_ns
,
579 stats
->value
->stats
->rd_merged
,
580 stats
->value
->stats
->wr_merged
,
581 stats
->value
->stats
->idle_time_ns
);
584 qapi_free_BlockStatsList(stats_list
);
587 void hmp_info_vnc(Monitor
*mon
, const QDict
*qdict
)
591 VncClientInfoList
*client
;
593 info
= qmp_query_vnc(&err
);
595 error_report_err(err
);
599 if (!info
->enabled
) {
600 monitor_printf(mon
, "Server: disabled\n");
604 monitor_printf(mon
, "Server:\n");
605 if (info
->has_host
&& info
->has_service
) {
606 monitor_printf(mon
, " address: %s:%s\n", info
->host
, info
->service
);
608 if (info
->has_auth
) {
609 monitor_printf(mon
, " auth: %s\n", info
->auth
);
612 if (!info
->has_clients
|| info
->clients
== NULL
) {
613 monitor_printf(mon
, "Client: none\n");
615 for (client
= info
->clients
; client
; client
= client
->next
) {
616 monitor_printf(mon
, "Client:\n");
617 monitor_printf(mon
, " address: %s:%s\n",
619 client
->value
->service
);
620 monitor_printf(mon
, " x509_dname: %s\n",
621 client
->value
->x509_dname
?
622 client
->value
->x509_dname
: "none");
623 monitor_printf(mon
, " username: %s\n",
624 client
->value
->has_sasl_username
?
625 client
->value
->sasl_username
: "none");
630 qapi_free_VncInfo(info
);
634 void hmp_info_spice(Monitor
*mon
, const QDict
*qdict
)
636 SpiceChannelList
*chan
;
638 const char *channel_name
;
639 const char * const channel_names
[] = {
640 [SPICE_CHANNEL_MAIN
] = "main",
641 [SPICE_CHANNEL_DISPLAY
] = "display",
642 [SPICE_CHANNEL_INPUTS
] = "inputs",
643 [SPICE_CHANNEL_CURSOR
] = "cursor",
644 [SPICE_CHANNEL_PLAYBACK
] = "playback",
645 [SPICE_CHANNEL_RECORD
] = "record",
646 [SPICE_CHANNEL_TUNNEL
] = "tunnel",
647 [SPICE_CHANNEL_SMARTCARD
] = "smartcard",
648 [SPICE_CHANNEL_USBREDIR
] = "usbredir",
649 [SPICE_CHANNEL_PORT
] = "port",
651 /* minimum spice-protocol is 0.12.3, webdav was added in 0.12.7,
652 * no easy way to #ifdef (SPICE_CHANNEL_* is a enum). Disable
653 * as quick fix for build failures with older versions. */
654 [SPICE_CHANNEL_WEBDAV
] = "webdav",
658 info
= qmp_query_spice(NULL
);
660 if (!info
->enabled
) {
661 monitor_printf(mon
, "Server: disabled\n");
665 monitor_printf(mon
, "Server:\n");
666 if (info
->has_port
) {
667 monitor_printf(mon
, " address: %s:%" PRId64
"\n",
668 info
->host
, info
->port
);
670 if (info
->has_tls_port
) {
671 monitor_printf(mon
, " address: %s:%" PRId64
" [tls]\n",
672 info
->host
, info
->tls_port
);
674 monitor_printf(mon
, " migrated: %s\n",
675 info
->migrated
? "true" : "false");
676 monitor_printf(mon
, " auth: %s\n", info
->auth
);
677 monitor_printf(mon
, " compiled: %s\n", info
->compiled_version
);
678 monitor_printf(mon
, " mouse-mode: %s\n",
679 SpiceQueryMouseMode_lookup
[info
->mouse_mode
]);
681 if (!info
->has_channels
|| info
->channels
== NULL
) {
682 monitor_printf(mon
, "Channels: none\n");
684 for (chan
= info
->channels
; chan
; chan
= chan
->next
) {
685 monitor_printf(mon
, "Channel:\n");
686 monitor_printf(mon
, " address: %s:%s%s\n",
687 chan
->value
->host
, chan
->value
->port
,
688 chan
->value
->tls
? " [tls]" : "");
689 monitor_printf(mon
, " session: %" PRId64
"\n",
690 chan
->value
->connection_id
);
691 monitor_printf(mon
, " channel: %" PRId64
":%" PRId64
"\n",
692 chan
->value
->channel_type
, chan
->value
->channel_id
);
694 channel_name
= "unknown";
695 if (chan
->value
->channel_type
> 0 &&
696 chan
->value
->channel_type
< ARRAY_SIZE(channel_names
) &&
697 channel_names
[chan
->value
->channel_type
]) {
698 channel_name
= channel_names
[chan
->value
->channel_type
];
701 monitor_printf(mon
, " channel name: %s\n", channel_name
);
706 qapi_free_SpiceInfo(info
);
710 void hmp_info_balloon(Monitor
*mon
, const QDict
*qdict
)
715 info
= qmp_query_balloon(&err
);
717 error_report_err(err
);
721 monitor_printf(mon
, "balloon: actual=%" PRId64
"\n", info
->actual
>> 20);
723 qapi_free_BalloonInfo(info
);
726 static void hmp_info_pci_device(Monitor
*mon
, const PciDeviceInfo
*dev
)
728 PciMemoryRegionList
*region
;
730 monitor_printf(mon
, " Bus %2" PRId64
", ", dev
->bus
);
731 monitor_printf(mon
, "device %3" PRId64
", function %" PRId64
":\n",
732 dev
->slot
, dev
->function
);
733 monitor_printf(mon
, " ");
735 if (dev
->class_info
->has_desc
) {
736 monitor_printf(mon
, "%s", dev
->class_info
->desc
);
738 monitor_printf(mon
, "Class %04" PRId64
, dev
->class_info
->q_class
);
741 monitor_printf(mon
, ": PCI device %04" PRIx64
":%04" PRIx64
"\n",
742 dev
->id
->vendor
, dev
->id
->device
);
745 monitor_printf(mon
, " IRQ %" PRId64
".\n", dev
->irq
);
748 if (dev
->has_pci_bridge
) {
749 monitor_printf(mon
, " BUS %" PRId64
".\n",
750 dev
->pci_bridge
->bus
->number
);
751 monitor_printf(mon
, " secondary bus %" PRId64
".\n",
752 dev
->pci_bridge
->bus
->secondary
);
753 monitor_printf(mon
, " subordinate bus %" PRId64
".\n",
754 dev
->pci_bridge
->bus
->subordinate
);
756 monitor_printf(mon
, " IO range [0x%04"PRIx64
", 0x%04"PRIx64
"]\n",
757 dev
->pci_bridge
->bus
->io_range
->base
,
758 dev
->pci_bridge
->bus
->io_range
->limit
);
761 " memory range [0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
762 dev
->pci_bridge
->bus
->memory_range
->base
,
763 dev
->pci_bridge
->bus
->memory_range
->limit
);
765 monitor_printf(mon
, " prefetchable memory range "
766 "[0x%08"PRIx64
", 0x%08"PRIx64
"]\n",
767 dev
->pci_bridge
->bus
->prefetchable_range
->base
,
768 dev
->pci_bridge
->bus
->prefetchable_range
->limit
);
771 for (region
= dev
->regions
; region
; region
= region
->next
) {
774 addr
= region
->value
->address
;
775 size
= region
->value
->size
;
777 monitor_printf(mon
, " BAR%" PRId64
": ", region
->value
->bar
);
779 if (!strcmp(region
->value
->type
, "io")) {
780 monitor_printf(mon
, "I/O at 0x%04" PRIx64
781 " [0x%04" PRIx64
"].\n",
782 addr
, addr
+ size
- 1);
784 monitor_printf(mon
, "%d bit%s memory at 0x%08" PRIx64
785 " [0x%08" PRIx64
"].\n",
786 region
->value
->mem_type_64
? 64 : 32,
787 region
->value
->prefetch
? " prefetchable" : "",
788 addr
, addr
+ size
- 1);
792 monitor_printf(mon
, " id \"%s\"\n", dev
->qdev_id
);
794 if (dev
->has_pci_bridge
) {
795 if (dev
->pci_bridge
->has_devices
) {
796 PciDeviceInfoList
*cdev
;
797 for (cdev
= dev
->pci_bridge
->devices
; cdev
; cdev
= cdev
->next
) {
798 hmp_info_pci_device(mon
, cdev
->value
);
804 static int hmp_info_irq_foreach(Object
*obj
, void *opaque
)
806 InterruptStatsProvider
*intc
;
807 InterruptStatsProviderClass
*k
;
808 Monitor
*mon
= opaque
;
810 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
811 intc
= INTERRUPT_STATS_PROVIDER(obj
);
812 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
813 uint64_t *irq_counts
;
814 unsigned int nb_irqs
, i
;
815 if (k
->get_statistics
&&
816 k
->get_statistics(intc
, &irq_counts
, &nb_irqs
)) {
818 monitor_printf(mon
, "IRQ statistics for %s:\n",
819 object_get_typename(obj
));
820 for (i
= 0; i
< nb_irqs
; i
++) {
821 if (irq_counts
[i
] > 0) {
822 monitor_printf(mon
, "%2d: %" PRId64
"\n", i
,
828 monitor_printf(mon
, "IRQ statistics not available for %s.\n",
829 object_get_typename(obj
));
836 void hmp_info_irq(Monitor
*mon
, const QDict
*qdict
)
838 object_child_foreach_recursive(object_get_root(),
839 hmp_info_irq_foreach
, mon
);
842 static int hmp_info_pic_foreach(Object
*obj
, void *opaque
)
844 InterruptStatsProvider
*intc
;
845 InterruptStatsProviderClass
*k
;
846 Monitor
*mon
= opaque
;
848 if (object_dynamic_cast(obj
, TYPE_INTERRUPT_STATS_PROVIDER
)) {
849 intc
= INTERRUPT_STATS_PROVIDER(obj
);
850 k
= INTERRUPT_STATS_PROVIDER_GET_CLASS(obj
);
852 k
->print_info(intc
, mon
);
854 monitor_printf(mon
, "Interrupt controller information not available for %s.\n",
855 object_get_typename(obj
));
862 void hmp_info_pic(Monitor
*mon
, const QDict
*qdict
)
864 object_child_foreach_recursive(object_get_root(),
865 hmp_info_pic_foreach
, mon
);
868 void hmp_info_pci(Monitor
*mon
, const QDict
*qdict
)
870 PciInfoList
*info_list
, *info
;
873 info_list
= qmp_query_pci(&err
);
875 monitor_printf(mon
, "PCI devices not supported\n");
880 for (info
= info_list
; info
; info
= info
->next
) {
881 PciDeviceInfoList
*dev
;
883 for (dev
= info
->value
->devices
; dev
; dev
= dev
->next
) {
884 hmp_info_pci_device(mon
, dev
->value
);
888 qapi_free_PciInfoList(info_list
);
891 void hmp_info_block_jobs(Monitor
*mon
, const QDict
*qdict
)
893 BlockJobInfoList
*list
;
896 list
= qmp_query_block_jobs(&err
);
900 monitor_printf(mon
, "No active jobs\n");
905 if (strcmp(list
->value
->type
, "stream") == 0) {
906 monitor_printf(mon
, "Streaming device %s: Completed %" PRId64
907 " of %" PRId64
" bytes, speed limit %" PRId64
914 monitor_printf(mon
, "Type %s, device %s: Completed %" PRId64
915 " of %" PRId64
" bytes, speed limit %" PRId64
926 qapi_free_BlockJobInfoList(list
);
929 void hmp_info_tpm(Monitor
*mon
, const QDict
*qdict
)
931 TPMInfoList
*info_list
, *info
;
934 TPMPassthroughOptions
*tpo
;
936 info_list
= qmp_query_tpm(&err
);
938 monitor_printf(mon
, "TPM device not supported\n");
944 monitor_printf(mon
, "TPM device:\n");
947 for (info
= info_list
; info
; info
= info
->next
) {
948 TPMInfo
*ti
= info
->value
;
949 monitor_printf(mon
, " tpm%d: model=%s\n",
950 c
, TpmModel_lookup
[ti
->model
]);
952 monitor_printf(mon
, " \\ %s: type=%s",
953 ti
->id
, TpmTypeOptionsKind_lookup
[ti
->options
->type
]);
955 switch (ti
->options
->type
) {
956 case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH
:
957 tpo
= ti
->options
->u
.passthrough
.data
;
958 monitor_printf(mon
, "%s%s%s%s",
959 tpo
->has_path
? ",path=" : "",
960 tpo
->has_path
? tpo
->path
: "",
961 tpo
->has_cancel_path
? ",cancel-path=" : "",
962 tpo
->has_cancel_path
? tpo
->cancel_path
: "");
964 case TPM_TYPE_OPTIONS_KIND__MAX
:
967 monitor_printf(mon
, "\n");
970 qapi_free_TPMInfoList(info_list
);
973 void hmp_quit(Monitor
*mon
, const QDict
*qdict
)
975 monitor_suspend(mon
);
979 void hmp_stop(Monitor
*mon
, const QDict
*qdict
)
984 void hmp_system_reset(Monitor
*mon
, const QDict
*qdict
)
986 qmp_system_reset(NULL
);
989 void hmp_system_powerdown(Monitor
*mon
, const QDict
*qdict
)
991 qmp_system_powerdown(NULL
);
994 void hmp_cpu(Monitor
*mon
, const QDict
*qdict
)
998 /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
999 use it are converted to the QAPI */
1000 cpu_index
= qdict_get_int(qdict
, "index");
1001 if (monitor_set_cpu(cpu_index
) < 0) {
1002 monitor_printf(mon
, "invalid CPU index\n");
1006 void hmp_memsave(Monitor
*mon
, const QDict
*qdict
)
1008 uint32_t size
= qdict_get_int(qdict
, "size");
1009 const char *filename
= qdict_get_str(qdict
, "filename");
1010 uint64_t addr
= qdict_get_int(qdict
, "val");
1013 qmp_memsave(addr
, size
, filename
, true, monitor_get_cpu_index(), &err
);
1014 hmp_handle_error(mon
, &err
);
1017 void hmp_pmemsave(Monitor
*mon
, const QDict
*qdict
)
1019 uint32_t size
= qdict_get_int(qdict
, "size");
1020 const char *filename
= qdict_get_str(qdict
, "filename");
1021 uint64_t addr
= qdict_get_int(qdict
, "val");
1024 qmp_pmemsave(addr
, size
, filename
, &err
);
1025 hmp_handle_error(mon
, &err
);
1028 void hmp_ringbuf_write(Monitor
*mon
, const QDict
*qdict
)
1030 const char *chardev
= qdict_get_str(qdict
, "device");
1031 const char *data
= qdict_get_str(qdict
, "data");
1034 qmp_ringbuf_write(chardev
, data
, false, 0, &err
);
1036 hmp_handle_error(mon
, &err
);
1039 void hmp_ringbuf_read(Monitor
*mon
, const QDict
*qdict
)
1041 uint32_t size
= qdict_get_int(qdict
, "size");
1042 const char *chardev
= qdict_get_str(qdict
, "device");
1047 data
= qmp_ringbuf_read(chardev
, size
, false, 0, &err
);
1049 error_report_err(err
);
1053 for (i
= 0; data
[i
]; i
++) {
1054 unsigned char ch
= data
[i
];
1057 monitor_printf(mon
, "\\\\");
1058 } else if ((ch
< 0x20 && ch
!= '\n' && ch
!= '\t') || ch
== 0x7F) {
1059 monitor_printf(mon
, "\\u%04X", ch
);
1061 monitor_printf(mon
, "%c", ch
);
1065 monitor_printf(mon
, "\n");
1069 static void hmp_cont_cb(void *opaque
, int err
)
1076 static bool key_is_missing(const BlockInfo
*bdev
)
1078 return (bdev
->inserted
&& bdev
->inserted
->encryption_key_missing
);
1081 void hmp_cont(Monitor
*mon
, const QDict
*qdict
)
1083 BlockInfoList
*bdev_list
, *bdev
;
1086 bdev_list
= qmp_query_block(NULL
);
1087 for (bdev
= bdev_list
; bdev
; bdev
= bdev
->next
) {
1088 if (key_is_missing(bdev
->value
)) {
1089 monitor_read_block_device_key(mon
, bdev
->value
->device
,
1096 hmp_handle_error(mon
, &err
);
1099 qapi_free_BlockInfoList(bdev_list
);
1102 void hmp_system_wakeup(Monitor
*mon
, const QDict
*qdict
)
1104 qmp_system_wakeup(NULL
);
1107 void hmp_nmi(Monitor
*mon
, const QDict
*qdict
)
1111 qmp_inject_nmi(&err
);
1112 hmp_handle_error(mon
, &err
);
1115 void hmp_set_link(Monitor
*mon
, const QDict
*qdict
)
1117 const char *name
= qdict_get_str(qdict
, "name");
1118 bool up
= qdict_get_bool(qdict
, "up");
1121 qmp_set_link(name
, up
, &err
);
1122 hmp_handle_error(mon
, &err
);
1125 void hmp_block_passwd(Monitor
*mon
, const QDict
*qdict
)
1127 const char *device
= qdict_get_str(qdict
, "device");
1128 const char *password
= qdict_get_str(qdict
, "password");
1131 qmp_block_passwd(true, device
, false, NULL
, password
, &err
);
1132 hmp_handle_error(mon
, &err
);
1135 void hmp_balloon(Monitor
*mon
, const QDict
*qdict
)
1137 int64_t value
= qdict_get_int(qdict
, "value");
1140 qmp_balloon(value
, &err
);
1142 error_report_err(err
);
1146 void hmp_block_resize(Monitor
*mon
, const QDict
*qdict
)
1148 const char *device
= qdict_get_str(qdict
, "device");
1149 int64_t size
= qdict_get_int(qdict
, "size");
1152 qmp_block_resize(true, device
, false, NULL
, size
, &err
);
1153 hmp_handle_error(mon
, &err
);
1156 void hmp_drive_mirror(Monitor
*mon
, const QDict
*qdict
)
1158 const char *filename
= qdict_get_str(qdict
, "target");
1159 const char *format
= qdict_get_try_str(qdict
, "format");
1160 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1161 bool full
= qdict_get_try_bool(qdict
, "full", false);
1163 DriveMirror mirror
= {
1164 .device
= (char *)qdict_get_str(qdict
, "device"),
1165 .target
= (char *)filename
,
1166 .has_format
= !!format
,
1167 .format
= (char *)format
,
1168 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1170 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1175 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1176 hmp_handle_error(mon
, &err
);
1179 qmp_drive_mirror(&mirror
, &err
);
1180 hmp_handle_error(mon
, &err
);
1183 void hmp_drive_backup(Monitor
*mon
, const QDict
*qdict
)
1185 const char *device
= qdict_get_str(qdict
, "device");
1186 const char *filename
= qdict_get_str(qdict
, "target");
1187 const char *format
= qdict_get_try_str(qdict
, "format");
1188 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1189 bool full
= qdict_get_try_bool(qdict
, "full", false);
1190 bool compress
= qdict_get_try_bool(qdict
, "compress", false);
1192 DriveBackup backup
= {
1193 .device
= (char *)device
,
1194 .target
= (char *)filename
,
1195 .has_format
= !!format
,
1196 .format
= (char *)format
,
1197 .sync
= full
? MIRROR_SYNC_MODE_FULL
: MIRROR_SYNC_MODE_TOP
,
1199 .mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
,
1200 .has_compress
= !!compress
,
1201 .compress
= compress
,
1205 error_setg(&err
, QERR_MISSING_PARAMETER
, "target");
1206 hmp_handle_error(mon
, &err
);
1210 qmp_drive_backup(&backup
, &err
);
1211 hmp_handle_error(mon
, &err
);
1214 void hmp_snapshot_blkdev(Monitor
*mon
, const QDict
*qdict
)
1216 const char *device
= qdict_get_str(qdict
, "device");
1217 const char *filename
= qdict_get_try_str(qdict
, "snapshot-file");
1218 const char *format
= qdict_get_try_str(qdict
, "format");
1219 bool reuse
= qdict_get_try_bool(qdict
, "reuse", false);
1220 enum NewImageMode mode
;
1224 /* In the future, if 'snapshot-file' is not specified, the snapshot
1225 will be taken internally. Today it's actually required. */
1226 error_setg(&err
, QERR_MISSING_PARAMETER
, "snapshot-file");
1227 hmp_handle_error(mon
, &err
);
1231 mode
= reuse
? NEW_IMAGE_MODE_EXISTING
: NEW_IMAGE_MODE_ABSOLUTE_PATHS
;
1232 qmp_blockdev_snapshot_sync(true, device
, false, NULL
,
1233 filename
, false, NULL
,
1236 hmp_handle_error(mon
, &err
);
1239 void hmp_snapshot_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1241 const char *device
= qdict_get_str(qdict
, "device");
1242 const char *name
= qdict_get_str(qdict
, "name");
1245 qmp_blockdev_snapshot_internal_sync(device
, name
, &err
);
1246 hmp_handle_error(mon
, &err
);
1249 void hmp_snapshot_delete_blkdev_internal(Monitor
*mon
, const QDict
*qdict
)
1251 const char *device
= qdict_get_str(qdict
, "device");
1252 const char *name
= qdict_get_str(qdict
, "name");
1253 const char *id
= qdict_get_try_str(qdict
, "id");
1256 qmp_blockdev_snapshot_delete_internal_sync(device
, !!id
, id
,
1258 hmp_handle_error(mon
, &err
);
1261 void hmp_migrate_cancel(Monitor
*mon
, const QDict
*qdict
)
1263 qmp_migrate_cancel(NULL
);
1266 void hmp_migrate_incoming(Monitor
*mon
, const QDict
*qdict
)
1269 const char *uri
= qdict_get_str(qdict
, "uri");
1271 qmp_migrate_incoming(uri
, &err
);
1273 hmp_handle_error(mon
, &err
);
1276 /* Kept for backwards compatibility */
1277 void hmp_migrate_set_downtime(Monitor
*mon
, const QDict
*qdict
)
1279 double value
= qdict_get_double(qdict
, "value");
1280 qmp_migrate_set_downtime(value
, NULL
);
1283 void hmp_migrate_set_cache_size(Monitor
*mon
, const QDict
*qdict
)
1285 int64_t value
= qdict_get_int(qdict
, "value");
1288 qmp_migrate_set_cache_size(value
, &err
);
1290 error_report_err(err
);
1295 /* Kept for backwards compatibility */
1296 void hmp_migrate_set_speed(Monitor
*mon
, const QDict
*qdict
)
1298 int64_t value
= qdict_get_int(qdict
, "value");
1299 qmp_migrate_set_speed(value
, NULL
);
1302 void hmp_migrate_set_capability(Monitor
*mon
, const QDict
*qdict
)
1304 const char *cap
= qdict_get_str(qdict
, "capability");
1305 bool state
= qdict_get_bool(qdict
, "state");
1307 MigrationCapabilityStatusList
*caps
= g_malloc0(sizeof(*caps
));
1310 for (i
= 0; i
< MIGRATION_CAPABILITY__MAX
; i
++) {
1311 if (strcmp(cap
, MigrationCapability_lookup
[i
]) == 0) {
1312 caps
->value
= g_malloc0(sizeof(*caps
->value
));
1313 caps
->value
->capability
= i
;
1314 caps
->value
->state
= state
;
1316 qmp_migrate_set_capabilities(caps
, &err
);
1321 if (i
== MIGRATION_CAPABILITY__MAX
) {
1322 error_setg(&err
, QERR_INVALID_PARAMETER
, cap
);
1325 qapi_free_MigrationCapabilityStatusList(caps
);
1328 error_report_err(err
);
1332 void hmp_migrate_set_parameter(Monitor
*mon
, const QDict
*qdict
)
1334 const char *param
= qdict_get_str(qdict
, "parameter");
1335 const char *valuestr
= qdict_get_str(qdict
, "value");
1336 int64_t valuebw
= 0;
1340 bool use_int_value
= false;
1343 for (i
= 0; i
< MIGRATION_PARAMETER__MAX
; i
++) {
1344 if (strcmp(param
, MigrationParameter_lookup
[i
]) == 0) {
1345 MigrationParameters p
= { 0 };
1347 case MIGRATION_PARAMETER_COMPRESS_LEVEL
:
1348 p
.has_compress_level
= true;
1349 use_int_value
= true;
1351 case MIGRATION_PARAMETER_COMPRESS_THREADS
:
1352 p
.has_compress_threads
= true;
1353 use_int_value
= true;
1355 case MIGRATION_PARAMETER_DECOMPRESS_THREADS
:
1356 p
.has_decompress_threads
= true;
1357 use_int_value
= true;
1359 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL
:
1360 p
.has_cpu_throttle_initial
= true;
1361 use_int_value
= true;
1363 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT
:
1364 p
.has_cpu_throttle_increment
= true;
1365 use_int_value
= true;
1367 case MIGRATION_PARAMETER_TLS_CREDS
:
1368 p
.has_tls_creds
= true;
1369 p
.tls_creds
= (char *) valuestr
;
1371 case MIGRATION_PARAMETER_TLS_HOSTNAME
:
1372 p
.has_tls_hostname
= true;
1373 p
.tls_hostname
= (char *) valuestr
;
1375 case MIGRATION_PARAMETER_MAX_BANDWIDTH
:
1376 p
.has_max_bandwidth
= true;
1377 valuebw
= qemu_strtosz(valuestr
, &endp
);
1378 if (valuebw
< 0 || (size_t)valuebw
!= valuebw
1380 error_setg(&err
, "Invalid size %s", valuestr
);
1383 p
.max_bandwidth
= valuebw
;
1385 case MIGRATION_PARAMETER_DOWNTIME_LIMIT
:
1386 p
.has_downtime_limit
= true;
1387 use_int_value
= true;
1391 if (use_int_value
) {
1392 if (qemu_strtol(valuestr
, NULL
, 10, &valueint
) < 0) {
1393 error_setg(&err
, "Unable to parse '%s' as an int",
1397 /* Set all integers; only one has_FOO will be set, and
1398 * the code ignores the remaining values */
1399 p
.compress_level
= valueint
;
1400 p
.compress_threads
= valueint
;
1401 p
.decompress_threads
= valueint
;
1402 p
.cpu_throttle_initial
= valueint
;
1403 p
.cpu_throttle_increment
= valueint
;
1404 p
.downtime_limit
= valueint
;
1407 qmp_migrate_set_parameters(&p
, &err
);
1412 if (i
== MIGRATION_PARAMETER__MAX
) {
1413 error_setg(&err
, QERR_INVALID_PARAMETER
, param
);
1418 error_report_err(err
);
1422 void hmp_client_migrate_info(Monitor
*mon
, const QDict
*qdict
)
1425 const char *protocol
= qdict_get_str(qdict
, "protocol");
1426 const char *hostname
= qdict_get_str(qdict
, "hostname");
1427 bool has_port
= qdict_haskey(qdict
, "port");
1428 int port
= qdict_get_try_int(qdict
, "port", -1);
1429 bool has_tls_port
= qdict_haskey(qdict
, "tls-port");
1430 int tls_port
= qdict_get_try_int(qdict
, "tls-port", -1);
1431 const char *cert_subject
= qdict_get_try_str(qdict
, "cert-subject");
1433 qmp_client_migrate_info(protocol
, hostname
,
1434 has_port
, port
, has_tls_port
, tls_port
,
1435 !!cert_subject
, cert_subject
, &err
);
1436 hmp_handle_error(mon
, &err
);
1439 void hmp_migrate_start_postcopy(Monitor
*mon
, const QDict
*qdict
)
1442 qmp_migrate_start_postcopy(&err
);
1443 hmp_handle_error(mon
, &err
);
1446 void hmp_set_password(Monitor
*mon
, const QDict
*qdict
)
1448 const char *protocol
= qdict_get_str(qdict
, "protocol");
1449 const char *password
= qdict_get_str(qdict
, "password");
1450 const char *connected
= qdict_get_try_str(qdict
, "connected");
1453 qmp_set_password(protocol
, password
, !!connected
, connected
, &err
);
1454 hmp_handle_error(mon
, &err
);
1457 void hmp_expire_password(Monitor
*mon
, const QDict
*qdict
)
1459 const char *protocol
= qdict_get_str(qdict
, "protocol");
1460 const char *whenstr
= qdict_get_str(qdict
, "time");
1463 qmp_expire_password(protocol
, whenstr
, &err
);
1464 hmp_handle_error(mon
, &err
);
1467 void hmp_eject(Monitor
*mon
, const QDict
*qdict
)
1469 bool force
= qdict_get_try_bool(qdict
, "force", false);
1470 const char *device
= qdict_get_str(qdict
, "device");
1473 qmp_eject(true, device
, false, NULL
, true, force
, &err
);
1474 hmp_handle_error(mon
, &err
);
1477 static void hmp_change_read_arg(void *opaque
, const char *password
,
1478 void *readline_opaque
)
1480 qmp_change_vnc_password(password
, NULL
);
1481 monitor_read_command(opaque
, 1);
1484 void hmp_change(Monitor
*mon
, const QDict
*qdict
)
1486 const char *device
= qdict_get_str(qdict
, "device");
1487 const char *target
= qdict_get_str(qdict
, "target");
1488 const char *arg
= qdict_get_try_str(qdict
, "arg");
1489 const char *read_only
= qdict_get_try_str(qdict
, "read-only-mode");
1490 BlockdevChangeReadOnlyMode read_only_mode
= 0;
1493 if (strcmp(device
, "vnc") == 0) {
1496 "Parameter 'read-only-mode' is invalid for VNC\n");
1499 if (strcmp(target
, "passwd") == 0 ||
1500 strcmp(target
, "password") == 0) {
1502 monitor_read_password(mon
, hmp_change_read_arg
, NULL
);
1506 qmp_change("vnc", target
, !!arg
, arg
, &err
);
1510 qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup
,
1511 read_only
, BLOCKDEV_CHANGE_READ_ONLY_MODE__MAX
,
1512 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN
, &err
);
1514 hmp_handle_error(mon
, &err
);
1519 qmp_blockdev_change_medium(true, device
, false, NULL
, target
,
1520 !!arg
, arg
, !!read_only
, read_only_mode
,
1523 error_get_class(err
) == ERROR_CLASS_DEVICE_ENCRYPTED
) {
1525 monitor_read_block_device_key(mon
, device
, NULL
, NULL
);
1530 hmp_handle_error(mon
, &err
);
1533 void hmp_block_set_io_throttle(Monitor
*mon
, const QDict
*qdict
)
1536 BlockIOThrottle throttle
= {
1537 .device
= (char *) qdict_get_str(qdict
, "device"),
1538 .bps
= qdict_get_int(qdict
, "bps"),
1539 .bps_rd
= qdict_get_int(qdict
, "bps_rd"),
1540 .bps_wr
= qdict_get_int(qdict
, "bps_wr"),
1541 .iops
= qdict_get_int(qdict
, "iops"),
1542 .iops_rd
= qdict_get_int(qdict
, "iops_rd"),
1543 .iops_wr
= qdict_get_int(qdict
, "iops_wr"),
1546 qmp_block_set_io_throttle(&throttle
, &err
);
1547 hmp_handle_error(mon
, &err
);
1550 void hmp_block_stream(Monitor
*mon
, const QDict
*qdict
)
1552 Error
*error
= NULL
;
1553 const char *device
= qdict_get_str(qdict
, "device");
1554 const char *base
= qdict_get_try_str(qdict
, "base");
1555 int64_t speed
= qdict_get_try_int(qdict
, "speed", 0);
1557 qmp_block_stream(false, NULL
, device
, base
!= NULL
, base
, false, NULL
,
1558 qdict_haskey(qdict
, "speed"), speed
,
1559 true, BLOCKDEV_ON_ERROR_REPORT
, &error
);
1561 hmp_handle_error(mon
, &error
);
1564 void hmp_block_job_set_speed(Monitor
*mon
, const QDict
*qdict
)
1566 Error
*error
= NULL
;
1567 const char *device
= qdict_get_str(qdict
, "device");
1568 int64_t value
= qdict_get_int(qdict
, "speed");
1570 qmp_block_job_set_speed(device
, value
, &error
);
1572 hmp_handle_error(mon
, &error
);
1575 void hmp_block_job_cancel(Monitor
*mon
, const QDict
*qdict
)
1577 Error
*error
= NULL
;
1578 const char *device
= qdict_get_str(qdict
, "device");
1579 bool force
= qdict_get_try_bool(qdict
, "force", false);
1581 qmp_block_job_cancel(device
, true, force
, &error
);
1583 hmp_handle_error(mon
, &error
);
1586 void hmp_block_job_pause(Monitor
*mon
, const QDict
*qdict
)
1588 Error
*error
= NULL
;
1589 const char *device
= qdict_get_str(qdict
, "device");
1591 qmp_block_job_pause(device
, &error
);
1593 hmp_handle_error(mon
, &error
);
1596 void hmp_block_job_resume(Monitor
*mon
, const QDict
*qdict
)
1598 Error
*error
= NULL
;
1599 const char *device
= qdict_get_str(qdict
, "device");
1601 qmp_block_job_resume(device
, &error
);
1603 hmp_handle_error(mon
, &error
);
1606 void hmp_block_job_complete(Monitor
*mon
, const QDict
*qdict
)
1608 Error
*error
= NULL
;
1609 const char *device
= qdict_get_str(qdict
, "device");
1611 qmp_block_job_complete(device
, &error
);
1613 hmp_handle_error(mon
, &error
);
1616 typedef struct HMPMigrationStatus
1620 bool is_block_migration
;
1621 } HMPMigrationStatus
;
1623 static void hmp_migrate_status_cb(void *opaque
)
1625 HMPMigrationStatus
*status
= opaque
;
1626 MigrationInfo
*info
;
1628 info
= qmp_query_migrate(NULL
);
1629 if (!info
->has_status
|| info
->status
== MIGRATION_STATUS_ACTIVE
||
1630 info
->status
== MIGRATION_STATUS_SETUP
) {
1631 if (info
->has_disk
) {
1634 if (info
->disk
->remaining
) {
1635 progress
= info
->disk
->transferred
* 100 / info
->disk
->total
;
1640 monitor_printf(status
->mon
, "Completed %d %%\r", progress
);
1641 monitor_flush(status
->mon
);
1644 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
) + 1000);
1646 if (status
->is_block_migration
) {
1647 monitor_printf(status
->mon
, "\n");
1649 if (info
->has_error_desc
) {
1650 error_report("%s", info
->error_desc
);
1652 monitor_resume(status
->mon
);
1653 timer_del(status
->timer
);
1657 qapi_free_MigrationInfo(info
);
1660 void hmp_migrate(Monitor
*mon
, const QDict
*qdict
)
1662 bool detach
= qdict_get_try_bool(qdict
, "detach", false);
1663 bool blk
= qdict_get_try_bool(qdict
, "blk", false);
1664 bool inc
= qdict_get_try_bool(qdict
, "inc", false);
1665 const char *uri
= qdict_get_str(qdict
, "uri");
1668 qmp_migrate(uri
, !!blk
, blk
, !!inc
, inc
, false, false, &err
);
1670 error_report_err(err
);
1675 HMPMigrationStatus
*status
;
1677 if (monitor_suspend(mon
) < 0) {
1678 monitor_printf(mon
, "terminal does not allow synchronous "
1679 "migration, continuing detached\n");
1683 status
= g_malloc0(sizeof(*status
));
1685 status
->is_block_migration
= blk
|| inc
;
1686 status
->timer
= timer_new_ms(QEMU_CLOCK_REALTIME
, hmp_migrate_status_cb
,
1688 timer_mod(status
->timer
, qemu_clock_get_ms(QEMU_CLOCK_REALTIME
));
1692 void hmp_device_add(Monitor
*mon
, const QDict
*qdict
)
1696 qmp_device_add((QDict
*)qdict
, NULL
, &err
);
1697 hmp_handle_error(mon
, &err
);
1700 void hmp_device_del(Monitor
*mon
, const QDict
*qdict
)
1702 const char *id
= qdict_get_str(qdict
, "id");
1705 qmp_device_del(id
, &err
);
1706 hmp_handle_error(mon
, &err
);
1709 void hmp_dump_guest_memory(Monitor
*mon
, const QDict
*qdict
)
1712 bool paging
= qdict_get_try_bool(qdict
, "paging", false);
1713 bool zlib
= qdict_get_try_bool(qdict
, "zlib", false);
1714 bool lzo
= qdict_get_try_bool(qdict
, "lzo", false);
1715 bool snappy
= qdict_get_try_bool(qdict
, "snappy", false);
1716 const char *file
= qdict_get_str(qdict
, "filename");
1717 bool has_begin
= qdict_haskey(qdict
, "begin");
1718 bool has_length
= qdict_haskey(qdict
, "length");
1719 bool has_detach
= qdict_haskey(qdict
, "detach");
1722 bool detach
= false;
1723 enum DumpGuestMemoryFormat dump_format
= DUMP_GUEST_MEMORY_FORMAT_ELF
;
1726 if (zlib
+ lzo
+ snappy
> 1) {
1727 error_setg(&err
, "only one of '-z|-l|-s' can be set");
1728 hmp_handle_error(mon
, &err
);
1733 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB
;
1737 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO
;
1741 dump_format
= DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY
;
1745 begin
= qdict_get_int(qdict
, "begin");
1748 length
= qdict_get_int(qdict
, "length");
1751 detach
= qdict_get_bool(qdict
, "detach");
1754 prot
= g_strconcat("file:", file
, NULL
);
1756 qmp_dump_guest_memory(paging
, prot
, true, detach
, has_begin
, begin
,
1757 has_length
, length
, true, dump_format
, &err
);
1758 hmp_handle_error(mon
, &err
);
1762 void hmp_netdev_add(Monitor
*mon
, const QDict
*qdict
)
1767 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
1772 netdev_add(opts
, &err
);
1774 qemu_opts_del(opts
);
1778 hmp_handle_error(mon
, &err
);
1781 void hmp_netdev_del(Monitor
*mon
, const QDict
*qdict
)
1783 const char *id
= qdict_get_str(qdict
, "id");
1786 qmp_netdev_del(id
, &err
);
1787 hmp_handle_error(mon
, &err
);
1790 void hmp_object_add(Monitor
*mon
, const QDict
*qdict
)
1797 opts
= qemu_opts_from_qdict(qemu_find_opts("object"), qdict
, &err
);
1799 hmp_handle_error(mon
, &err
);
1803 v
= opts_visitor_new(opts
);
1804 obj
= user_creatable_add(qdict
, v
, &err
);
1806 qemu_opts_del(opts
);
1809 hmp_handle_error(mon
, &err
);
1816 void hmp_getfd(Monitor
*mon
, const QDict
*qdict
)
1818 const char *fdname
= qdict_get_str(qdict
, "fdname");
1821 qmp_getfd(fdname
, &err
);
1822 hmp_handle_error(mon
, &err
);
1825 void hmp_closefd(Monitor
*mon
, const QDict
*qdict
)
1827 const char *fdname
= qdict_get_str(qdict
, "fdname");
1830 qmp_closefd(fdname
, &err
);
1831 hmp_handle_error(mon
, &err
);
1834 void hmp_sendkey(Monitor
*mon
, const QDict
*qdict
)
1836 const char *keys
= qdict_get_str(qdict
, "keys");
1837 KeyValueList
*keylist
, *head
= NULL
, *tmp
= NULL
;
1838 int has_hold_time
= qdict_haskey(qdict
, "hold-time");
1839 int hold_time
= qdict_get_try_int(qdict
, "hold-time", -1);
1845 separator
= strchr(keys
, '-');
1846 keyname_len
= separator
? separator
- keys
: strlen(keys
);
1848 /* Be compatible with old interface, convert user inputted "<" */
1849 if (keys
[0] == '<' && keyname_len
== 1) {
1854 keylist
= g_malloc0(sizeof(*keylist
));
1855 keylist
->value
= g_malloc0(sizeof(*keylist
->value
));
1861 tmp
->next
= keylist
;
1865 if (strstart(keys
, "0x", NULL
)) {
1867 int value
= strtoul(keys
, &endp
, 0);
1868 assert(endp
<= keys
+ keyname_len
);
1869 if (endp
!= keys
+ keyname_len
) {
1872 keylist
->value
->type
= KEY_VALUE_KIND_NUMBER
;
1873 keylist
->value
->u
.number
.data
= value
;
1875 int idx
= index_from_key(keys
, keyname_len
);
1876 if (idx
== Q_KEY_CODE__MAX
) {
1879 keylist
->value
->type
= KEY_VALUE_KIND_QCODE
;
1880 keylist
->value
->u
.qcode
.data
= idx
;
1886 keys
= separator
+ 1;
1889 qmp_send_key(head
, has_hold_time
, hold_time
, &err
);
1890 hmp_handle_error(mon
, &err
);
1893 qapi_free_KeyValueList(head
);
1897 monitor_printf(mon
, "invalid parameter: %.*s\n", keyname_len
, keys
);
1901 void hmp_screendump(Monitor
*mon
, const QDict
*qdict
)
1903 const char *filename
= qdict_get_str(qdict
, "filename");
1906 qmp_screendump(filename
, &err
);
1907 hmp_handle_error(mon
, &err
);
1910 void hmp_nbd_server_start(Monitor
*mon
, const QDict
*qdict
)
1912 const char *uri
= qdict_get_str(qdict
, "uri");
1913 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1914 bool all
= qdict_get_try_bool(qdict
, "all", false);
1915 Error
*local_err
= NULL
;
1916 BlockInfoList
*block_list
, *info
;
1917 SocketAddress
*addr
;
1919 if (writable
&& !all
) {
1920 error_setg(&local_err
, "-w only valid together with -a");
1924 /* First check if the address is valid and start the server. */
1925 addr
= socket_parse(uri
, &local_err
);
1926 if (local_err
!= NULL
) {
1930 qmp_nbd_server_start(addr
, false, NULL
, &local_err
);
1931 qapi_free_SocketAddress(addr
);
1932 if (local_err
!= NULL
) {
1940 /* Then try adding all block devices. If one fails, close all and
1943 block_list
= qmp_query_block(NULL
);
1945 for (info
= block_list
; info
; info
= info
->next
) {
1946 if (!info
->value
->has_inserted
) {
1950 qmp_nbd_server_add(info
->value
->device
, true, writable
, &local_err
);
1952 if (local_err
!= NULL
) {
1953 qmp_nbd_server_stop(NULL
);
1958 qapi_free_BlockInfoList(block_list
);
1961 hmp_handle_error(mon
, &local_err
);
1964 void hmp_nbd_server_add(Monitor
*mon
, const QDict
*qdict
)
1966 const char *device
= qdict_get_str(qdict
, "device");
1967 bool writable
= qdict_get_try_bool(qdict
, "writable", false);
1968 Error
*local_err
= NULL
;
1970 qmp_nbd_server_add(device
, true, writable
, &local_err
);
1972 if (local_err
!= NULL
) {
1973 hmp_handle_error(mon
, &local_err
);
1977 void hmp_nbd_server_stop(Monitor
*mon
, const QDict
*qdict
)
1981 qmp_nbd_server_stop(&err
);
1982 hmp_handle_error(mon
, &err
);
1985 void hmp_cpu_add(Monitor
*mon
, const QDict
*qdict
)
1990 cpuid
= qdict_get_int(qdict
, "id");
1991 qmp_cpu_add(cpuid
, &err
);
1992 hmp_handle_error(mon
, &err
);
1995 void hmp_chardev_add(Monitor
*mon
, const QDict
*qdict
)
1997 const char *args
= qdict_get_str(qdict
, "args");
2001 opts
= qemu_opts_parse_noisily(qemu_find_opts("chardev"), args
, true);
2003 error_setg(&err
, "Parsing chardev args failed");
2005 qemu_chr_new_from_opts(opts
, &err
);
2006 qemu_opts_del(opts
);
2008 hmp_handle_error(mon
, &err
);
2011 void hmp_chardev_remove(Monitor
*mon
, const QDict
*qdict
)
2013 Error
*local_err
= NULL
;
2015 qmp_chardev_remove(qdict_get_str(qdict
, "id"), &local_err
);
2016 hmp_handle_error(mon
, &local_err
);
2019 void hmp_qemu_io(Monitor
*mon
, const QDict
*qdict
)
2022 BlockBackend
*local_blk
= NULL
;
2023 AioContext
*aio_context
;
2024 const char* device
= qdict_get_str(qdict
, "device");
2025 const char* command
= qdict_get_str(qdict
, "command");
2028 blk
= blk_by_name(device
);
2030 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, device
, &err
);
2032 blk
= local_blk
= blk_new();
2033 blk_insert_bs(blk
, bs
);
2039 aio_context
= blk_get_aio_context(blk
);
2040 aio_context_acquire(aio_context
);
2042 qemuio_command(blk
, command
);
2044 aio_context_release(aio_context
);
2047 blk_unref(local_blk
);
2048 hmp_handle_error(mon
, &err
);
2051 void hmp_object_del(Monitor
*mon
, const QDict
*qdict
)
2053 const char *id
= qdict_get_str(qdict
, "id");
2056 user_creatable_del(id
, &err
);
2057 hmp_handle_error(mon
, &err
);
2060 void hmp_info_memdev(Monitor
*mon
, const QDict
*qdict
)
2063 MemdevList
*memdev_list
= qmp_query_memdev(&err
);
2064 MemdevList
*m
= memdev_list
;
2071 v
= string_output_visitor_new(false, &str
);
2072 visit_type_uint16List(v
, NULL
, &m
->value
->host_nodes
, NULL
);
2073 monitor_printf(mon
, "memory backend: %d\n", i
);
2074 monitor_printf(mon
, " size: %" PRId64
"\n", m
->value
->size
);
2075 monitor_printf(mon
, " merge: %s\n",
2076 m
->value
->merge
? "true" : "false");
2077 monitor_printf(mon
, " dump: %s\n",
2078 m
->value
->dump
? "true" : "false");
2079 monitor_printf(mon
, " prealloc: %s\n",
2080 m
->value
->prealloc
? "true" : "false");
2081 monitor_printf(mon
, " policy: %s\n",
2082 HostMemPolicy_lookup
[m
->value
->policy
]);
2083 visit_complete(v
, &str
);
2084 monitor_printf(mon
, " host nodes: %s\n", str
);
2092 monitor_printf(mon
, "\n");
2094 qapi_free_MemdevList(memdev_list
);
2097 void hmp_info_memory_devices(Monitor
*mon
, const QDict
*qdict
)
2100 MemoryDeviceInfoList
*info_list
= qmp_query_memory_devices(&err
);
2101 MemoryDeviceInfoList
*info
;
2102 MemoryDeviceInfo
*value
;
2103 PCDIMMDeviceInfo
*di
;
2105 for (info
= info_list
; info
; info
= info
->next
) {
2106 value
= info
->value
;
2109 switch (value
->type
) {
2110 case MEMORY_DEVICE_INFO_KIND_DIMM
:
2111 di
= value
->u
.dimm
.data
;
2113 monitor_printf(mon
, "Memory device [%s]: \"%s\"\n",
2114 MemoryDeviceInfoKind_lookup
[value
->type
],
2115 di
->id
? di
->id
: "");
2116 monitor_printf(mon
, " addr: 0x%" PRIx64
"\n", di
->addr
);
2117 monitor_printf(mon
, " slot: %" PRId64
"\n", di
->slot
);
2118 monitor_printf(mon
, " node: %" PRId64
"\n", di
->node
);
2119 monitor_printf(mon
, " size: %" PRIu64
"\n", di
->size
);
2120 monitor_printf(mon
, " memdev: %s\n", di
->memdev
);
2121 monitor_printf(mon
, " hotplugged: %s\n",
2122 di
->hotplugged
? "true" : "false");
2123 monitor_printf(mon
, " hotpluggable: %s\n",
2124 di
->hotpluggable
? "true" : "false");
2132 qapi_free_MemoryDeviceInfoList(info_list
);
2135 void hmp_info_iothreads(Monitor
*mon
, const QDict
*qdict
)
2137 IOThreadInfoList
*info_list
= qmp_query_iothreads(NULL
);
2138 IOThreadInfoList
*info
;
2140 for (info
= info_list
; info
; info
= info
->next
) {
2141 monitor_printf(mon
, "%s: thread_id=%" PRId64
"\n",
2142 info
->value
->id
, info
->value
->thread_id
);
2145 qapi_free_IOThreadInfoList(info_list
);
2148 void hmp_qom_list(Monitor
*mon
, const QDict
*qdict
)
2150 const char *path
= qdict_get_try_str(qdict
, "path");
2151 ObjectPropertyInfoList
*list
;
2155 monitor_printf(mon
, "/\n");
2159 list
= qmp_qom_list(path
, &err
);
2161 ObjectPropertyInfoList
*start
= list
;
2162 while (list
!= NULL
) {
2163 ObjectPropertyInfo
*value
= list
->value
;
2165 monitor_printf(mon
, "%s (%s)\n",
2166 value
->name
, value
->type
);
2169 qapi_free_ObjectPropertyInfoList(start
);
2171 hmp_handle_error(mon
, &err
);
2174 void hmp_qom_set(Monitor
*mon
, const QDict
*qdict
)
2176 const char *path
= qdict_get_str(qdict
, "path");
2177 const char *property
= qdict_get_str(qdict
, "property");
2178 const char *value
= qdict_get_str(qdict
, "value");
2180 bool ambiguous
= false;
2183 obj
= object_resolve_path(path
, &ambiguous
);
2185 error_set(&err
, ERROR_CLASS_DEVICE_NOT_FOUND
,
2186 "Device '%s' not found", path
);
2189 monitor_printf(mon
, "Warning: Path '%s' is ambiguous\n", path
);
2191 object_property_parse(obj
, value
, property
, &err
);
2193 hmp_handle_error(mon
, &err
);
2196 void hmp_rocker(Monitor
*mon
, const QDict
*qdict
)
2198 const char *name
= qdict_get_str(qdict
, "name");
2199 RockerSwitch
*rocker
;
2202 rocker
= qmp_query_rocker(name
, &err
);
2204 hmp_handle_error(mon
, &err
);
2208 monitor_printf(mon
, "name: %s\n", rocker
->name
);
2209 monitor_printf(mon
, "id: 0x%" PRIx64
"\n", rocker
->id
);
2210 monitor_printf(mon
, "ports: %d\n", rocker
->ports
);
2212 qapi_free_RockerSwitch(rocker
);
2215 void hmp_rocker_ports(Monitor
*mon
, const QDict
*qdict
)
2217 RockerPortList
*list
, *port
;
2218 const char *name
= qdict_get_str(qdict
, "name");
2221 list
= qmp_query_rocker_ports(name
, &err
);
2223 hmp_handle_error(mon
, &err
);
2227 monitor_printf(mon
, " ena/ speed/ auto\n");
2228 monitor_printf(mon
, " port link duplex neg?\n");
2230 for (port
= list
; port
; port
= port
->next
) {
2231 monitor_printf(mon
, "%10s %-4s %-3s %2s %-3s\n",
2233 port
->value
->enabled
? port
->value
->link_up
?
2234 "up" : "down" : "!ena",
2235 port
->value
->speed
== 10000 ? "10G" : "??",
2236 port
->value
->duplex
? "FD" : "HD",
2237 port
->value
->autoneg
? "Yes" : "No");
2240 qapi_free_RockerPortList(list
);
2243 void hmp_rocker_of_dpa_flows(Monitor
*mon
, const QDict
*qdict
)
2245 RockerOfDpaFlowList
*list
, *info
;
2246 const char *name
= qdict_get_str(qdict
, "name");
2247 uint32_t tbl_id
= qdict_get_try_int(qdict
, "tbl_id", -1);
2250 list
= qmp_query_rocker_of_dpa_flows(name
, tbl_id
!= -1, tbl_id
, &err
);
2252 hmp_handle_error(mon
, &err
);
2256 monitor_printf(mon
, "prio tbl hits key(mask) --> actions\n");
2258 for (info
= list
; info
; info
= info
->next
) {
2259 RockerOfDpaFlow
*flow
= info
->value
;
2260 RockerOfDpaFlowKey
*key
= flow
->key
;
2261 RockerOfDpaFlowMask
*mask
= flow
->mask
;
2262 RockerOfDpaFlowAction
*action
= flow
->action
;
2265 monitor_printf(mon
, "%-4d %-3d %-4" PRIu64
,
2266 key
->priority
, key
->tbl_id
, flow
->hits
);
2268 monitor_printf(mon
, "%-4d %-3d ",
2269 key
->priority
, key
->tbl_id
);
2272 if (key
->has_in_pport
) {
2273 monitor_printf(mon
, " pport %d", key
->in_pport
);
2274 if (mask
->has_in_pport
) {
2275 monitor_printf(mon
, "(0x%x)", mask
->in_pport
);
2279 if (key
->has_vlan_id
) {
2280 monitor_printf(mon
, " vlan %d",
2281 key
->vlan_id
& VLAN_VID_MASK
);
2282 if (mask
->has_vlan_id
) {
2283 monitor_printf(mon
, "(0x%x)", mask
->vlan_id
);
2287 if (key
->has_tunnel_id
) {
2288 monitor_printf(mon
, " tunnel %d", key
->tunnel_id
);
2289 if (mask
->has_tunnel_id
) {
2290 monitor_printf(mon
, "(0x%x)", mask
->tunnel_id
);
2294 if (key
->has_eth_type
) {
2295 switch (key
->eth_type
) {
2297 monitor_printf(mon
, " ARP");
2300 monitor_printf(mon
, " IP");
2303 monitor_printf(mon
, " IPv6");
2306 monitor_printf(mon
, " LACP");
2309 monitor_printf(mon
, " LLDP");
2312 monitor_printf(mon
, " eth type 0x%04x", key
->eth_type
);
2317 if (key
->has_eth_src
) {
2318 if ((strcmp(key
->eth_src
, "01:00:00:00:00:00") == 0) &&
2319 (mask
->has_eth_src
) &&
2320 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2321 monitor_printf(mon
, " src <any mcast/bcast>");
2322 } else if ((strcmp(key
->eth_src
, "00:00:00:00:00:00") == 0) &&
2323 (mask
->has_eth_src
) &&
2324 (strcmp(mask
->eth_src
, "01:00:00:00:00:00") == 0)) {
2325 monitor_printf(mon
, " src <any ucast>");
2327 monitor_printf(mon
, " src %s", key
->eth_src
);
2328 if (mask
->has_eth_src
) {
2329 monitor_printf(mon
, "(%s)", mask
->eth_src
);
2334 if (key
->has_eth_dst
) {
2335 if ((strcmp(key
->eth_dst
, "01:00:00:00:00:00") == 0) &&
2336 (mask
->has_eth_dst
) &&
2337 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2338 monitor_printf(mon
, " dst <any mcast/bcast>");
2339 } else if ((strcmp(key
->eth_dst
, "00:00:00:00:00:00") == 0) &&
2340 (mask
->has_eth_dst
) &&
2341 (strcmp(mask
->eth_dst
, "01:00:00:00:00:00") == 0)) {
2342 monitor_printf(mon
, " dst <any ucast>");
2344 monitor_printf(mon
, " dst %s", key
->eth_dst
);
2345 if (mask
->has_eth_dst
) {
2346 monitor_printf(mon
, "(%s)", mask
->eth_dst
);
2351 if (key
->has_ip_proto
) {
2352 monitor_printf(mon
, " proto %d", key
->ip_proto
);
2353 if (mask
->has_ip_proto
) {
2354 monitor_printf(mon
, "(0x%x)", mask
->ip_proto
);
2358 if (key
->has_ip_tos
) {
2359 monitor_printf(mon
, " TOS %d", key
->ip_tos
);
2360 if (mask
->has_ip_tos
) {
2361 monitor_printf(mon
, "(0x%x)", mask
->ip_tos
);
2365 if (key
->has_ip_dst
) {
2366 monitor_printf(mon
, " dst %s", key
->ip_dst
);
2369 if (action
->has_goto_tbl
|| action
->has_group_id
||
2370 action
->has_new_vlan_id
) {
2371 monitor_printf(mon
, " -->");
2374 if (action
->has_new_vlan_id
) {
2375 monitor_printf(mon
, " apply new vlan %d",
2376 ntohs(action
->new_vlan_id
));
2379 if (action
->has_group_id
) {
2380 monitor_printf(mon
, " write group 0x%08x", action
->group_id
);
2383 if (action
->has_goto_tbl
) {
2384 monitor_printf(mon
, " goto tbl %d", action
->goto_tbl
);
2387 monitor_printf(mon
, "\n");
2390 qapi_free_RockerOfDpaFlowList(list
);
2393 void hmp_rocker_of_dpa_groups(Monitor
*mon
, const QDict
*qdict
)
2395 RockerOfDpaGroupList
*list
, *g
;
2396 const char *name
= qdict_get_str(qdict
, "name");
2397 uint8_t type
= qdict_get_try_int(qdict
, "type", 9);
2401 list
= qmp_query_rocker_of_dpa_groups(name
, type
!= 9, type
, &err
);
2403 hmp_handle_error(mon
, &err
);
2407 monitor_printf(mon
, "id (decode) --> buckets\n");
2409 for (g
= list
; g
; g
= g
->next
) {
2410 RockerOfDpaGroup
*group
= g
->value
;
2412 monitor_printf(mon
, "0x%08x", group
->id
);
2414 monitor_printf(mon
, " (type %s", group
->type
== 0 ? "L2 interface" :
2415 group
->type
== 1 ? "L2 rewrite" :
2416 group
->type
== 2 ? "L3 unicast" :
2417 group
->type
== 3 ? "L2 multicast" :
2418 group
->type
== 4 ? "L2 flood" :
2419 group
->type
== 5 ? "L3 interface" :
2420 group
->type
== 6 ? "L3 multicast" :
2421 group
->type
== 7 ? "L3 ECMP" :
2422 group
->type
== 8 ? "L2 overlay" :
2425 if (group
->has_vlan_id
) {
2426 monitor_printf(mon
, " vlan %d", group
->vlan_id
);
2429 if (group
->has_pport
) {
2430 monitor_printf(mon
, " pport %d", group
->pport
);
2433 if (group
->has_index
) {
2434 monitor_printf(mon
, " index %d", group
->index
);
2437 monitor_printf(mon
, ") -->");
2439 if (group
->has_set_vlan_id
&& group
->set_vlan_id
) {
2441 monitor_printf(mon
, " set vlan %d",
2442 group
->set_vlan_id
& VLAN_VID_MASK
);
2445 if (group
->has_set_eth_src
) {
2448 monitor_printf(mon
, " set");
2450 monitor_printf(mon
, " src %s", group
->set_eth_src
);
2453 if (group
->has_set_eth_dst
) {
2456 monitor_printf(mon
, " set");
2458 monitor_printf(mon
, " dst %s", group
->set_eth_dst
);
2463 if (group
->has_ttl_check
&& group
->ttl_check
) {
2464 monitor_printf(mon
, " check TTL");
2467 if (group
->has_group_id
&& group
->group_id
) {
2468 monitor_printf(mon
, " group id 0x%08x", group
->group_id
);
2471 if (group
->has_pop_vlan
&& group
->pop_vlan
) {
2472 monitor_printf(mon
, " pop vlan");
2475 if (group
->has_out_pport
) {
2476 monitor_printf(mon
, " out pport %d", group
->out_pport
);
2479 if (group
->has_group_ids
) {
2480 struct uint32List
*id
;
2482 monitor_printf(mon
, " groups [");
2483 for (id
= group
->group_ids
; id
; id
= id
->next
) {
2484 monitor_printf(mon
, "0x%08x", id
->value
);
2486 monitor_printf(mon
, ",");
2489 monitor_printf(mon
, "]");
2492 monitor_printf(mon
, "\n");
2495 qapi_free_RockerOfDpaGroupList(list
);
2498 void hmp_info_dump(Monitor
*mon
, const QDict
*qdict
)
2500 DumpQueryResult
*result
= qmp_query_dump(NULL
);
2502 assert(result
&& result
->status
< DUMP_STATUS__MAX
);
2503 monitor_printf(mon
, "Status: %s\n", DumpStatus_lookup
[result
->status
]);
2505 if (result
->status
== DUMP_STATUS_ACTIVE
) {
2507 assert(result
->total
!= 0);
2508 percent
= 100.0 * result
->completed
/ result
->total
;
2509 monitor_printf(mon
, "Finished: %.2f %%\n", percent
);
2512 qapi_free_DumpQueryResult(result
);
2515 void hmp_hotpluggable_cpus(Monitor
*mon
, const QDict
*qdict
)
2518 HotpluggableCPUList
*l
= qmp_query_hotpluggable_cpus(&err
);
2519 HotpluggableCPUList
*saved
= l
;
2520 CpuInstanceProperties
*c
;
2523 hmp_handle_error(mon
, &err
);
2527 monitor_printf(mon
, "Hotpluggable CPUs:\n");
2529 monitor_printf(mon
, " type: \"%s\"\n", l
->value
->type
);
2530 monitor_printf(mon
, " vcpus_count: \"%" PRIu64
"\"\n",
2531 l
->value
->vcpus_count
);
2532 if (l
->value
->has_qom_path
) {
2533 monitor_printf(mon
, " qom_path: \"%s\"\n", l
->value
->qom_path
);
2536 c
= l
->value
->props
;
2537 monitor_printf(mon
, " CPUInstance Properties:\n");
2538 if (c
->has_node_id
) {
2539 monitor_printf(mon
, " node-id: \"%" PRIu64
"\"\n", c
->node_id
);
2541 if (c
->has_socket_id
) {
2542 monitor_printf(mon
, " socket-id: \"%" PRIu64
"\"\n", c
->socket_id
);
2544 if (c
->has_core_id
) {
2545 monitor_printf(mon
, " core-id: \"%" PRIu64
"\"\n", c
->core_id
);
2547 if (c
->has_thread_id
) {
2548 monitor_printf(mon
, " thread-id: \"%" PRIu64
"\"\n", c
->thread_id
);
2554 qapi_free_HotpluggableCPUList(saved
);